1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * \brief Header for ZOOM
34 #include <yaz/yconfig.h>
36 #define ZOOM_BEGIN_CDECL YAZ_BEGIN_CDECL
37 #define ZOOM_END_CDECL YAZ_END_CDECL
40 # define ZOOM_API(x) __declspec(dllexport) x __stdcall
42 # define ZOOM_API(x) x
47 /* ----------------------------------------------------------- */
48 /* the types we use */
50 typedef struct ZOOM_options_p *ZOOM_options;
51 typedef struct ZOOM_query_p *ZOOM_query;
52 typedef struct ZOOM_connection_p *ZOOM_connection;
53 typedef struct ZOOM_resultset_p *ZOOM_resultset;
54 typedef struct ZOOM_record_p *ZOOM_record;
55 typedef struct ZOOM_facet_field_p *ZOOM_facet_field;
56 typedef struct ZOOM_scanset_p *ZOOM_scanset;
57 typedef struct ZOOM_package_p *ZOOM_package;
59 typedef const char *(*ZOOM_options_callback)(void *handle, const char *name);
61 /* ----------------------------------------------------------- */
64 /* create connection, connect to host, if portnum is 0, then port is
65 read from host string (e.g. myhost:9821) */
66 ZOOM_API(ZOOM_connection)
67 ZOOM_connection_new(const char *host, int portnum);
69 /* create connection, don't connect, apply options */
70 ZOOM_API(ZOOM_connection)
71 ZOOM_connection_create(ZOOM_options options);
73 /* connect given existing connection */
75 ZOOM_connection_connect(ZOOM_connection c, const char *host,
79 ZOOM_connection_close(ZOOM_connection c);
81 /* destroy connection (close connection also) */
83 ZOOM_connection_destroy(ZOOM_connection c);
85 /* get/set option for connection */
86 ZOOM_API(const char *)
87 ZOOM_connection_option_get(ZOOM_connection c, const char *key);
89 ZOOM_API(const char *)
90 ZOOM_connection_option_getl(ZOOM_connection c, const char *key, int *lenp);
93 ZOOM_connection_option_set(ZOOM_connection c, const char *key,
97 ZOOM_connection_option_setl(ZOOM_connection c, const char *key,
98 const char *val, int len);
100 /* return error code (0 == success, failure otherwise). cp
101 holds error string on failure, addinfo holds addititional info (if any)
104 ZOOM_connection_error(ZOOM_connection c, const char **cp,
105 const char **addinfo);
108 ZOOM_connection_error_x(ZOOM_connection c, const char **cp,
109 const char **addinfo, const char **diagset);
111 /* returns error code */
113 ZOOM_connection_errcode(ZOOM_connection c);
114 /* returns error message */
115 ZOOM_API(const char *)
116 ZOOM_connection_errmsg(ZOOM_connection c);
117 /* returns additional info */
118 ZOOM_API(const char *)
119 ZOOM_connection_addinfo(ZOOM_connection c);
120 /* returns diagnostic set */
121 ZOOM_API(const char *)
122 ZOOM_connection_diagset(ZOOM_connection c);
123 /* translates error code into human-readable string */
124 ZOOM_API(const char *)
125 ZOOM_diag_str (int error);
127 #define ZOOM_ERROR_NONE 0
128 #define ZOOM_ERROR_CONNECT 10000
129 #define ZOOM_ERROR_MEMORY 10001
130 #define ZOOM_ERROR_ENCODE 10002
131 #define ZOOM_ERROR_DECODE 10003
132 #define ZOOM_ERROR_CONNECTION_LOST 10004
133 #define ZOOM_ERROR_INIT 10005
134 #define ZOOM_ERROR_INTERNAL 10006
135 #define ZOOM_ERROR_TIMEOUT 10007
136 #define ZOOM_ERROR_UNSUPPORTED_PROTOCOL 10008
137 #define ZOOM_ERROR_UNSUPPORTED_QUERY 10009
138 #define ZOOM_ERROR_INVALID_QUERY 10010
139 #define ZOOM_ERROR_CQL_PARSE 10011
140 #define ZOOM_ERROR_CQL_TRANSFORM 10012
141 #define ZOOM_ERROR_CCL_CONFIG 10013
142 #define ZOOM_ERROR_CCL_PARSE 10014
145 ZOOM_connection_last_event(ZOOM_connection cs);
147 #define ZOOM_EVENT_NONE 0
148 #define ZOOM_EVENT_CONNECT 1
149 #define ZOOM_EVENT_SEND_DATA 2
150 #define ZOOM_EVENT_RECV_DATA 3
151 #define ZOOM_EVENT_TIMEOUT 4
152 #define ZOOM_EVENT_UNKNOWN 5
153 #define ZOOM_EVENT_SEND_APDU 6
154 #define ZOOM_EVENT_RECV_APDU 7
155 #define ZOOM_EVENT_RECV_RECORD 8
156 #define ZOOM_EVENT_RECV_SEARCH 9
157 #define ZOOM_EVENT_END 10
158 #define ZOOM_EVENT_MAX 10
160 /* ----------------------------------------------------------- */
163 /* create result set given a search */
164 ZOOM_API(ZOOM_resultset)
165 ZOOM_connection_search(ZOOM_connection, ZOOM_query q);
166 /* create result set given PQF query */
167 ZOOM_API(ZOOM_resultset)
168 ZOOM_connection_search_pqf(ZOOM_connection c, const char *q);
170 /* destroy result set */
172 ZOOM_resultset_destroy(ZOOM_resultset r);
174 /** release result set from connection.
176 The result will will no longer be able to perform retrievals
177 from the connection from which it was created.
180 ZOOM_resultset_release(ZOOM_resultset r);
182 /* result set option */
183 ZOOM_API(const char *)
184 ZOOM_resultset_option_get(ZOOM_resultset r, const char *key);
186 ZOOM_resultset_option_set(ZOOM_resultset r, const char *key, const char *val);
188 /* return size of result set (alias hit count AKA result count) */
190 ZOOM_resultset_size(ZOOM_resultset r);
192 /* retrieve records */
194 ZOOM_resultset_records(ZOOM_resultset r, ZOOM_record *recs,
195 size_t start, size_t count);
197 /* return record object at pos. Returns 0 if unavailable */
198 ZOOM_API(ZOOM_record)
199 ZOOM_resultset_record(ZOOM_resultset s, size_t pos);
201 /* like ZOOM_resultset_record - but never blocks .. */
202 ZOOM_API(ZOOM_record)
203 ZOOM_resultset_record_immediate(ZOOM_resultset s, size_t pos);
205 /* reset record cache for result set */
207 ZOOM_resultset_cache_reset(ZOOM_resultset r);
210 /* retrieve facet field */
211 ZOOM_API(ZOOM_facet_field)
212 ZOOM_resultset_get_facet_field(ZOOM_resultset r, const char *facet_name);
214 /* retrieve facet field at position. Returns 0 if unavailable */
215 ZOOM_API(ZOOM_facet_field)
216 ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r, int pos);
218 /* return number of facets available */
220 ZOOM_resultset_facets_size(ZOOM_resultset r);
222 /* retrieve (array of pointers to) facet fields */
223 ZOOM_API(ZOOM_facet_field *)
224 ZOOM_resultset_facets(ZOOM_resultset r);
226 /* retrieve (array of pointers to) facet fields */
227 ZOOM_API(const char **)
228 ZOOM_resultset_facets_names(ZOOM_resultset r);
232 /* ----------------------------------------------------------- */
235 /* get record information, in a form given by type */
236 ZOOM_API(const char *)
237 ZOOM_record_get(ZOOM_record rec, const char *type, int *len);
241 ZOOM_record_destroy(ZOOM_record rec);
243 /* return copy of record */
244 ZOOM_API(ZOOM_record)
245 ZOOM_record_clone(ZOOM_record srec);
247 /* return error info (surrogate diagnostic) for record */
249 ZOOM_record_error(ZOOM_record rec, const char **msg,
250 const char **addinfo, const char **diagset);
252 /* ----------------------------------------------------------- */
256 ZOOM_API(const char *)
257 ZOOM_facet_field_name(ZOOM_facet_field facet_field);
259 /* get terms count on facet */
261 ZOOM_facet_field_term_count(ZOOM_facet_field facet_field);
263 /* get facet information, term and frequency, at a position. Returns 0 if out of bounds */
264 ZOOM_API(const char *)
265 ZOOM_facet_field_get_term(ZOOM_facet_field facet_field, size_t idx, int *freq);
267 /* ----------------------------------------------------------- */
272 /* create search object */
274 ZOOM_query_create(void);
277 ZOOM_query_destroy(ZOOM_query s);
280 ZOOM_query_cql(ZOOM_query s, const char *str);
281 /* CQL translated client-side into RPN: `conn' is optional for diagnostics */
283 ZOOM_query_cql2rpn(ZOOM_query s, const char *str, ZOOM_connection conn);
284 /* CCL translated client-side into RPN: `conn' is optional for diagnostics */
286 ZOOM_query_ccl2rpn(ZOOM_query s, const char *query_str,
288 int *ccl_error, const char **error_string, int *error_pos);
291 ZOOM_query_prefix(ZOOM_query s, const char *str);
292 /* specify sort criteria for search */
294 ZOOM_query_sortby(ZOOM_query s, const char *criteria);
296 /* ----------------------------------------------------------- */
298 ZOOM_API(ZOOM_scanset)
299 ZOOM_connection_scan(ZOOM_connection c, const char *startterm);
301 ZOOM_API(ZOOM_scanset)
302 ZOOM_connection_scan1(ZOOM_connection c, ZOOM_query startterm);
304 ZOOM_API(const char *)
305 ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
306 size_t *occ, size_t *len);
308 ZOOM_API(const char *)
309 ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
310 size_t *occ, size_t *len);
313 ZOOM_scanset_size(ZOOM_scanset scan);
316 ZOOM_scanset_destroy(ZOOM_scanset scan);
318 ZOOM_API(const char *)
319 ZOOM_scanset_option_get(ZOOM_scanset scan, const char *key);
322 ZOOM_scanset_option_set(ZOOM_scanset scan, const char *key,
324 /* ----------------------------------------------------------- */
325 /* Extended Services Packages */
327 ZOOM_API(ZOOM_package)
328 ZOOM_connection_package(ZOOM_connection c, ZOOM_options options);
331 ZOOM_package_destroy(ZOOM_package p);
334 ZOOM_package_send(ZOOM_package p, const char *type);
336 ZOOM_API(const char *)
337 ZOOM_package_option_get(ZOOM_package p, const char *key);
339 ZOOM_API(const char *)
340 ZOOM_package_option_getl(ZOOM_package p, const char *key, int *lenp);
343 ZOOM_package_option_set(ZOOM_package p, const char *key,
347 ZOOM_package_option_setl(ZOOM_package p, const char *key,
348 const char *val, int len);
350 /* ----------------------------------------------------------- */
351 /* Sort. First function is deprecated, use second instead */
353 ZOOM_resultset_sort(ZOOM_resultset r,
354 const char *sort_type, const char *sort_spec);
356 ZOOM_resultset_sort1(ZOOM_resultset r,
357 const char *sort_type, const char *sort_spec);
359 /* ----------------------------------------------------------- */
362 ZOOM_API(ZOOM_options_callback)
363 ZOOM_options_set_callback(ZOOM_options opt,
364 ZOOM_options_callback c, void *handle);
365 ZOOM_API(ZOOM_options)
366 ZOOM_options_create(void);
368 ZOOM_API(ZOOM_options)
369 ZOOM_options_create_with_parent(ZOOM_options parent);
371 ZOOM_API(ZOOM_options)
372 ZOOM_options_create_with_parent2(ZOOM_options parent1,
373 ZOOM_options parent2);
375 ZOOM_API(ZOOM_options)
376 ZOOM_options_dup(ZOOM_options src);
378 ZOOM_API(const char *)
379 ZOOM_options_get(ZOOM_options opt, const char *name);
381 ZOOM_API(const char *)
382 ZOOM_options_getl(ZOOM_options opt, const char *name, int *lenp);
385 ZOOM_options_set(ZOOM_options opt, const char *name, const char *v);
388 ZOOM_options_setl(ZOOM_options opt, const char *name, const char *value,
392 ZOOM_options_destroy(ZOOM_options opt);
395 ZOOM_options_get_bool(ZOOM_options opt, const char *name, int defa);
398 ZOOM_options_get_int(ZOOM_options opt, const char *name, int defa);
401 ZOOM_options_set_int(ZOOM_options opt, const char *name, int value);
403 /** \brief select/poll socket mask: read */
404 #define ZOOM_SELECT_READ 1
405 /** \brief select/poll socket mask: write */
406 #define ZOOM_SELECT_WRITE 2
407 /** \brief select/poll socket mask: except */
408 #define ZOOM_SELECT_EXCEPT 4
410 /** \brief wait for events on connection(s) (BLOCKING)
411 \param no number of connections (size of cs)
412 \param cs connection array
413 \retval 0 no event was fired
414 \retval >0 event was fired for connection at (retval-1)
416 blocking poll for events on a number of connections. Returns positive
417 integer if event occurred ; zero if none occurred and no more
418 events are pending. The positive integer specifies the
419 connection for which the event occurred.
422 ZOOM_event(int no, ZOOM_connection *cs);
425 /** \brief determines if connection is idle (no active or pending work)
428 \retval 0 is non-idle (active)
431 ZOOM_connection_is_idle(ZOOM_connection c);
434 /** \brief process one event for one of connections given
435 \param no number of connections (size of cs)
436 \param cs connection array
437 \retval 0 no event was processed
438 \retval >0 event was processed for connection at (retval-1)
440 This function attemps to deal with outstandings events in a non-blocking
441 mode. If no events was processed (return value of 0), then the system
442 should attempt to deal with sockets in blocking mode using socket
443 select/poll which means calling the following functions:
444 ZOOM_connection_get_socket, ZOOM_connection_get_mask,
445 ZOOM_connection_get_timeout.
448 ZOOM_event_nonblock(int no, ZOOM_connection *cs);
451 /** \brief process one event for connection
453 \retval 0 no event was processed
454 \retval 1 event was processed for connection
456 This function attemps to deal with outstandings events in
457 a non-blocking fashion. If no event was processed (return value of 0),
458 then the system should attempt to deal with sockets in blocking mode
459 using socket select/poll which means calling the following functions:
460 ZOOM_connection_get_socket, ZOOM_connection_get_mask,
461 ZOOM_connection_get_timeout. If an event was processed call this
465 ZOOM_connection_process(ZOOM_connection c);
468 /** \brief executes non-blocking tasks for connection
470 \retval 0 no task was executed
471 \retval 1 task was executed (but probably not completed)
473 This function, unlike, ZOOM_connection_process, does not try to
474 return any events (and remove them). But events may be generated
475 from it. These are saved and may later be retrieved with
476 ZOOM_connection_process and ZOOM_connection_last_event .
479 ZOOM_connection_exec_task(ZOOM_connection c);
482 /** \brief get socket fd for ZOOM connection
484 \retval -1 no socket assigned for connection
485 \retval >=0 socket for connection
487 Use this function when preparing for socket/poll and
488 in conjunction with ZOOM_connection_get_mask.
491 ZOOM_connection_get_socket(ZOOM_connection c);
494 /** \brief get socket mask for connection
496 \returns mask for connection (possibly 0)
498 Use this function when preparing for socket select/poll and
499 in conjunction with ZOOM_connection_get_socket.
502 ZOOM_connection_get_mask(ZOOM_connection c);
505 /** \brief set socket mask for connection (DO NOT call outside zoom) */
507 ZOOM_connection_set_mask(ZOOM_connection c, int mask);
510 /** \brief get timeout in seconds for ZOOM connection
512 \returns timeout value in seconds
514 Use this function when preparing for socket/poll and
515 in conjunction with ZOOM_connection_get_socket.
518 ZOOM_connection_get_timeout(ZOOM_connection c);
521 /** \brief fire socket event timeout
523 \retval 0 event was fired OK
524 \retval -1 event was not fired
526 Call this function when a timeout occurs - for example in the
527 case of select(2) returning 0.
530 ZOOM_connection_fire_event_timeout(ZOOM_connection c);
533 /** \brief fire socket event activity (read,write,except)
535 \param mask or'ed mask of ZOOM_SELECT_.. values
536 \retval 0 event was fired OK
537 \retval -1 event was not fired
540 ZOOM_connection_fire_event_socket(ZOOM_connection c, int mask);
543 /** \brief peek at next event
545 \returns ZOOM_EVENT_NONE (for no events in queue), ZOOM_EVENT_CONNECT, ..
547 Does not actually remove the event from the event queue. ZOOM_event and
548 ZOOM_process_event removes one event.
552 ZOOM_connection_peek_event(ZOOM_connection c);
554 ZOOM_API(const char *)
555 ZOOM_get_event_str(int event);
562 * c-file-style: "Stroustrup"
563 * indent-tabs-mode: nil
565 * vim: shiftwidth=4 tabstop=8 expandtab