Change wording ot YAZ license the 'Revised BSD License'. YAZ has used a
[yaz-moved-to-github.git] / include / yaz / zoom.h
1 /*
2  * Copyright (c) 1995-2006, Index Data
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
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.
15  *
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.
26  */
27 /* $Id: zoom.h,v 1.38 2006-10-09 21:02:41 adam Exp $ */
28
29 /*
30  * Copyright (C) 1995-2005, Index Data ApS
31  * See the file LICENSE for details.
32  *
33  * $Id: zoom.h,v 1.38 2006-10-09 21:02:41 adam Exp $
34  */
35 /**
36  * \file zoom.h
37  * \brief Header for ZOOM
38  */
39
40 #include <stdlib.h>
41 #include <yaz/yconfig.h>
42
43 #define ZOOM_BEGIN_CDECL YAZ_BEGIN_CDECL
44 #define ZOOM_END_CDECL YAZ_END_CDECL
45
46 #ifdef WIN32
47 #  define ZOOM_API(x) __declspec(dllexport) x __stdcall
48 #else
49 #  define ZOOM_API(x) x
50 # endif
51
52 ZOOM_BEGIN_CDECL
53
54 /* ----------------------------------------------------------- */
55 /* the types we use */
56
57 typedef struct ZOOM_options_p *ZOOM_options;
58 typedef struct ZOOM_query_p *ZOOM_query;
59 typedef struct ZOOM_connection_p *ZOOM_connection;
60 typedef struct ZOOM_resultset_p *ZOOM_resultset;
61 typedef struct ZOOM_record_p *ZOOM_record;
62 typedef struct ZOOM_scanset_p *ZOOM_scanset;
63 typedef struct ZOOM_package_p *ZOOM_package;
64
65 typedef const char *(*ZOOM_options_callback)(void *handle, const char *name);
66
67 /* ----------------------------------------------------------- */
68 /* connections */
69
70 /* create connection, connect to host, if portnum is 0, then port is
71 read from host string (e.g. myhost:9821) */
72 ZOOM_API(ZOOM_connection)
73 ZOOM_connection_new (const char *host, int portnum);
74
75 /* create connection, don't connect, apply options */
76 ZOOM_API(ZOOM_connection)
77 ZOOM_connection_create (ZOOM_options options);
78
79 /* connect given existing connection */
80 ZOOM_API(void)
81 ZOOM_connection_connect(ZOOM_connection c, const char *host,
82                               int portnum);
83
84 /* destroy connection (close connection also) */
85 ZOOM_API(void)
86 ZOOM_connection_destroy (ZOOM_connection c);
87
88 /* get/set option for connection */
89 ZOOM_API(const char *)
90 ZOOM_connection_option_get (ZOOM_connection c, const char *key);
91
92 ZOOM_API(const char *)
93 ZOOM_connection_option_getl (ZOOM_connection c, const char *key, int *lenp);
94
95 ZOOM_API(void)
96 ZOOM_connection_option_set (ZOOM_connection c, const char *key,
97                             const char *val);
98
99 ZOOM_API(void)
100 ZOOM_connection_option_setl (ZOOM_connection c, const char *key,
101                              const char *val, int len);
102
103 /* return error code (0 == success, failure otherwise). cp
104    holds error string on failure, addinfo holds addititional info (if any)
105 */
106 ZOOM_API(int)
107 ZOOM_connection_error (ZOOM_connection c, const char **cp,
108                             const char **addinfo);
109
110 ZOOM_API(int)
111 ZOOM_connection_error_x (ZOOM_connection c, const char **cp,
112                          const char **addinfo, const char **diagset);
113
114 /* returns error code */
115 ZOOM_API(int)
116 ZOOM_connection_errcode (ZOOM_connection c);
117 /* returns error message */
118 ZOOM_API(const char *)
119 ZOOM_connection_errmsg (ZOOM_connection c);
120 /* returns additional info */
121 ZOOM_API(const char *)
122 ZOOM_connection_addinfo (ZOOM_connection c);
123 /* returns diagnostic set */
124 ZOOM_API(const char *)
125 ZOOM_connection_diagset (ZOOM_connection c);
126 /* translates error code into human-readable string */
127 ZOOM_API(const char *)
128 ZOOM_diag_str (int error);
129
130 #define ZOOM_ERROR_NONE 0
131 #define ZOOM_ERROR_CONNECT 10000
132 #define ZOOM_ERROR_MEMORY  10001
133 #define ZOOM_ERROR_ENCODE  10002
134 #define ZOOM_ERROR_DECODE  10003
135 #define ZOOM_ERROR_CONNECTION_LOST 10004
136 #define ZOOM_ERROR_INIT 10005
137 #define ZOOM_ERROR_INTERNAL 10006
138 #define ZOOM_ERROR_TIMEOUT 10007
139 #define ZOOM_ERROR_UNSUPPORTED_PROTOCOL 10008
140 #define ZOOM_ERROR_UNSUPPORTED_QUERY 10009
141 #define ZOOM_ERROR_INVALID_QUERY 10010
142 #define ZOOM_ERROR_CQL_PARSE 10011
143 #define ZOOM_ERROR_CQL_TRANSFORM 10012
144 #define ZOOM_ERROR_CCL_CONFIG 10013
145 #define ZOOM_ERROR_CCL_PARSE 10014
146
147 ZOOM_API(int)
148 ZOOM_connection_last_event(ZOOM_connection cs);
149
150 #define ZOOM_EVENT_NONE 0
151 #define ZOOM_EVENT_CONNECT 1
152 #define ZOOM_EVENT_SEND_DATA  2
153 #define ZOOM_EVENT_RECV_DATA 3
154 #define ZOOM_EVENT_TIMEOUT 4
155 #define ZOOM_EVENT_UNKNOWN 5
156 #define ZOOM_EVENT_SEND_APDU 6
157 #define ZOOM_EVENT_RECV_APDU 7
158 #define ZOOM_EVENT_RECV_RECORD 8
159 #define ZOOM_EVENT_RECV_SEARCH 9
160 #define ZOOM_EVENT_END 10
161
162 /* ----------------------------------------------------------- */
163 /* result sets */
164
165 /* create result set given a search */
166 ZOOM_API(ZOOM_resultset)
167 ZOOM_connection_search(ZOOM_connection, ZOOM_query q);
168 /* create result set given PQF query */
169 ZOOM_API(ZOOM_resultset)
170 ZOOM_connection_search_pqf(ZOOM_connection c, const char *q);
171
172 /* destroy result set */
173 ZOOM_API(void)
174 ZOOM_resultset_destroy(ZOOM_resultset r);
175
176 /* result set option */
177 ZOOM_API(const char *)
178 ZOOM_resultset_option_get (ZOOM_resultset r, const char *key);
179 ZOOM_API(void)
180 ZOOM_resultset_option_set (ZOOM_resultset r, const char *key, const char *val);
181
182 /* return size of result set (alias hit count AKA result count) */
183 ZOOM_API(size_t)
184 ZOOM_resultset_size (ZOOM_resultset r);
185
186 /* retrieve records */
187 ZOOM_API(void)
188 ZOOM_resultset_records (ZOOM_resultset r, ZOOM_record *recs,
189                         size_t start, size_t count);
190
191 /* return record object at pos. Returns 0 if unavailable */
192 ZOOM_API(ZOOM_record)
193 ZOOM_resultset_record (ZOOM_resultset s, size_t pos);
194
195 /* like ZOOM_resultset_record - but never blocks .. */
196 ZOOM_API(ZOOM_record)
197 ZOOM_resultset_record_immediate (ZOOM_resultset s, size_t pos);
198
199 /* reset record cache for result set */
200 ZOOM_API(void)
201 ZOOM_resultset_cache_reset(ZOOM_resultset r);
202
203 /* ----------------------------------------------------------- */
204 /* records */
205
206 /* get record information, in a form given by type */
207 ZOOM_API(const char *)
208 ZOOM_record_get (ZOOM_record rec, const char *type, int *len);
209
210 /* destroy record */
211 ZOOM_API(void)
212 ZOOM_record_destroy (ZOOM_record rec);
213
214 /* return copy of record */
215 ZOOM_API(ZOOM_record)
216 ZOOM_record_clone (ZOOM_record srec);
217
218 /* ----------------------------------------------------------- */
219 /* queries */
220
221 /* create search object */
222 ZOOM_API(ZOOM_query)
223 ZOOM_query_create(void);
224 /* destroy it */
225 ZOOM_API(void)
226 ZOOM_query_destroy(ZOOM_query s);
227 /* CQL */
228 ZOOM_API(int)
229 ZOOM_query_cql(ZOOM_query s, const char *str);
230 /* CQL translated client-side into RPN: `conn' is optional for diagnostics */
231 ZOOM_API(int)
232 ZOOM_query_cql2rpn(ZOOM_query s, const char *str, ZOOM_connection conn);
233 /* CCL translated client-side into RPN: `conn' is optional for diagnostics */
234 ZOOM_API(int)
235 ZOOM_query_ccl2rpn(ZOOM_query s, const char *query_str,
236                    const char *config, 
237                    int *ccl_error, const char **error_string, int *error_pos);
238 /* PQF */
239 ZOOM_API(int)
240 ZOOM_query_prefix(ZOOM_query s, const char *str);
241 /* specify sort criteria for search */
242 ZOOM_API(int)
243 ZOOM_query_sortby(ZOOM_query s, const char *criteria);
244
245 /* ----------------------------------------------------------- */
246 /* scan */
247 ZOOM_API(ZOOM_scanset)
248 ZOOM_connection_scan (ZOOM_connection c, const char *startterm);
249
250 ZOOM_API(ZOOM_scanset)
251 ZOOM_connection_scan1 (ZOOM_connection c, ZOOM_query startterm);
252
253 ZOOM_API(const char *)
254 ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
255                   int *occ, int *len);
256
257 ZOOM_API(const char *)
258 ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
259                           int *occ, int *len);
260
261 ZOOM_API(size_t)
262 ZOOM_scanset_size(ZOOM_scanset scan);
263
264 ZOOM_API(void)
265 ZOOM_scanset_destroy (ZOOM_scanset scan);
266
267 ZOOM_API(const char *)
268     ZOOM_scanset_option_get (ZOOM_scanset scan, const char *key);
269
270 ZOOM_API(void)
271     ZOOM_scanset_option_set (ZOOM_scanset scan, const char *key,
272                              const char *val);
273 /* ----------------------------------------------------------- */
274 /* Extended Services Packages */
275
276 ZOOM_API(ZOOM_package)
277     ZOOM_connection_package (ZOOM_connection c, ZOOM_options options);
278
279 ZOOM_API(void)
280     ZOOM_package_destroy(ZOOM_package p);
281
282 ZOOM_API(void)
283     ZOOM_package_send (ZOOM_package p, const char *type);
284
285 ZOOM_API(const char *)
286     ZOOM_package_option_get (ZOOM_package p, const char *key);
287
288 ZOOM_API(void)
289     ZOOM_package_option_set (ZOOM_package p, const char *key,
290                              const char *val);
291
292 /* ----------------------------------------------------------- */
293 /* Sort.  First function is deprecated, use second instead */
294 ZOOM_API(void)
295     ZOOM_resultset_sort(ZOOM_resultset r,
296                         const char *sort_type, const char *sort_spec);
297 ZOOM_API(int)
298     ZOOM_resultset_sort1(ZOOM_resultset r,
299                         const char *sort_type, const char *sort_spec);
300
301 /* ----------------------------------------------------------- */
302 /* options */
303
304 ZOOM_API(ZOOM_options_callback)
305     ZOOM_options_set_callback (ZOOM_options opt,
306                                ZOOM_options_callback c,
307                                void *handle);
308 ZOOM_API(ZOOM_options)
309 ZOOM_options_create (void);
310
311 ZOOM_API(ZOOM_options)
312 ZOOM_options_create_with_parent (ZOOM_options parent);
313
314 ZOOM_API(ZOOM_options)
315     ZOOM_options_create_with_parent2 (ZOOM_options parent1,
316                                       ZOOM_options parent2);
317
318 ZOOM_API(const char *)
319 ZOOM_options_get (ZOOM_options opt, const char *name);
320
321 ZOOM_API(const char *)
322 ZOOM_options_getl (ZOOM_options opt, const char *name, int *lenp);
323
324 ZOOM_API(void)
325 ZOOM_options_set (ZOOM_options opt, const char *name, const char *v);
326
327 ZOOM_API(void)
328 ZOOM_options_setl (ZOOM_options opt, const char *name, const char *value,
329                    int len);
330
331 ZOOM_API(void)
332 ZOOM_options_destroy (ZOOM_options opt);
333
334 ZOOM_API(int)
335 ZOOM_options_get_bool (ZOOM_options opt, const char *name, int defa);
336
337 ZOOM_API(int)
338 ZOOM_options_get_int (ZOOM_options opt, const char *name, int defa);
339
340 ZOOM_API(void)
341 ZOOM_options_set_int(ZOOM_options opt, const char *name, int value);
342
343 /* ----------------------------------------------------------- */
344 /* events */
345 /* poll for events on a number of connections. Returns positive
346    integer if event occurred ; zero if none occurred and no more
347    events are pending. The positive integer specifies the
348    connection for which the event occurred. */
349 ZOOM_API(int)
350 ZOOM_event (int no, ZOOM_connection *cs);
351
352 ZOOM_API(int)
353 ZOOM_connection_is_idle(ZOOM_connection cs);
354
355 ZOOM_END_CDECL
356 /*
357  * Local variables:
358  * c-basic-offset: 4
359  * indent-tabs-mode: nil
360  * End:
361  * vim: shiftwidth=4 tabstop=8 expandtab
362  */
363