e321fd0230b15be739e6cd78914dffc5ca7d8a7d
[yaz-moved-to-github.git] / include / yaz / zoom.h
1 /*
2  * Public header for ZOOM C.
3  * $Id: zoom.h,v 1.8 2001-12-30 22:21:11 adam Exp $
4  */
5
6 #include <yaz/yconfig.h>
7
8 #define ZOOM_EXPORT YAZ_EXPORT
9 #define ZOOM_BEGIN_CDECL YAZ_BEGIN_CDECL
10 #define ZOOM_END_CDECL YAZ_END_CDECL
11
12 ZOOM_BEGIN_CDECL
13
14 /* ----------------------------------------------------------- */
15 /* the types we use */
16
17 typedef struct ZOOM_options_p *ZOOM_options;
18 typedef struct ZOOM_query_p *ZOOM_query;
19 typedef struct ZOOM_connection_p *ZOOM_connection;
20 typedef struct ZOOM_resultset_p *ZOOM_resultset;
21 typedef struct ZOOM_task_p *ZOOM_task;
22 typedef struct ZOOM_record_p *ZOOM_record;
23 typedef struct ZOOM_scanset_p *ZOOM_scanset;
24
25 /* ----------------------------------------------------------- */
26 /* connections */
27
28 /* create connection, connect to host, if portnum is 0, then port is
29 read from host string (e.g. myhost:9821) */
30 ZOOM_EXPORT
31 ZOOM_connection ZOOM_connection_new (const char *host, int portnum);
32
33 /* create connection, don't connect, apply options */
34 ZOOM_EXPORT
35 ZOOM_connection ZOOM_connection_create (ZOOM_options options);
36
37 /* connect given existing connection */
38 ZOOM_EXPORT
39 void ZOOM_connection_connect(ZOOM_connection c, const char *host,
40                               int portnum);
41
42 /* destroy connection (close connection also) */
43 ZOOM_EXPORT
44 void ZOOM_connection_destroy (ZOOM_connection c);
45
46 /* get/set option for connection */
47 ZOOM_EXPORT
48 const char *ZOOM_connection_option_get (ZOOM_connection c, const char *key);
49
50 ZOOM_EXPORT
51 void ZOOM_connection_option_set (ZOOM_connection c, const char *key,
52                                   const char *val);
53
54 /* return error code (0 == success, failure otherwise). cp
55    holds error string on failure, addinfo holds addititional info (if any)
56 */
57 ZOOM_EXPORT
58 int ZOOM_connection_error (ZOOM_connection c, const char **cp,
59                             const char **addinfo);
60
61 /* returns error code */
62 ZOOM_EXPORT
63 int ZOOM_connection_errcode (ZOOM_connection c);
64 /* returns error message */
65 ZOOM_EXPORT
66 const char *ZOOM_connection_errmsg (ZOOM_connection c);
67 /* returns additional info */
68 ZOOM_EXPORT
69 const char *ZOOM_connection_addinfo (ZOOM_connection c);
70
71 #define ZOOM_ERROR_NONE 0
72 #define ZOOM_ERROR_CONNECT 10000
73 #define ZOOM_ERROR_MEMORY  10001
74 #define ZOOM_ERROR_ENCODE  10002
75 #define ZOOM_ERROR_DECODE  10003
76 #define ZOOM_ERROR_CONNECTION_LOST 10004
77 #define ZOOM_ERROR_INIT 10005
78 #define ZOOM_ERROR_INTERNAL 10006
79 #define ZOOM_ERROR_TIMEOUT 10007
80
81 ZOOM_EXPORT
82 int ZOOM_connection_last_event(ZOOM_connection cs);
83
84 #define ZOOM_EVENT_NONE 0
85 #define ZOOM_EVENT_CONNECT 1
86 #define ZOOM_EVENT_SEND_DATA  2
87 #define ZOOM_EVENT_RECV_DATA 3
88 #define ZOOM_EVENT_TIMEOUT 4
89 #define ZOOM_EVENT_UNKNOWN 5
90 #define ZOOM_EVENT_SEND_APDU 6
91 #define ZOOM_EVENT_RECV_APDU 7
92
93 /* ----------------------------------------------------------- */
94 /* result sets */
95
96 /* create result set given a search */
97 ZOOM_EXPORT
98 ZOOM_resultset ZOOM_connection_search(ZOOM_connection, ZOOM_query q);
99 /* create result set given PQF query */
100 ZOOM_EXPORT
101 ZOOM_resultset ZOOM_connection_search_pqf(ZOOM_connection c, const char *q);
102
103 /* destroy result set */
104 ZOOM_EXPORT
105 void ZOOM_resultset_destroy(ZOOM_resultset r);
106
107 /* result set option */
108 ZOOM_EXPORT
109 const char *ZOOM_resultset_option_get (ZOOM_resultset r, const char *key);
110 ZOOM_EXPORT
111 void ZOOM_resultset_option_set (ZOOM_resultset r, const char *key, const char *val);
112
113 /* return size of result set (alias hit count AKA result count) */
114 ZOOM_EXPORT
115 size_t ZOOM_resultset_size (ZOOM_resultset r);
116
117 /* retrieve records */
118 ZOOM_EXPORT
119 void ZOOM_resultset_records (ZOOM_resultset r, ZOOM_record *recs,
120                              size_t start, size_t count);
121
122 /* return record object at pos. Returns 0 if unavailable */
123 ZOOM_EXPORT
124 ZOOM_record ZOOM_resultset_record (ZOOM_resultset s, size_t pos);
125
126 /* like ZOOM_resultset_record - but never blocks .. */
127 ZOOM_EXPORT
128 ZOOM_record ZOOM_resultset_record_immediate (ZOOM_resultset s, size_t pos);
129
130 /* ----------------------------------------------------------- */
131 /* records */
132
133 /* get record information, in a form given by type */
134 ZOOM_EXPORT
135 void *ZOOM_record_get (ZOOM_record rec, const char *type, size_t *len);
136
137 /* destroy record */
138 ZOOM_EXPORT
139 void ZOOM_record_destroy (ZOOM_record rec);
140
141 /* return copy of record */
142 ZOOM_EXPORT
143 ZOOM_record ZOOM_record_clone (ZOOM_record srec);
144
145 /* ----------------------------------------------------------- */
146 /* queries */
147
148 /* create search object */
149 ZOOM_EXPORT
150 ZOOM_query ZOOM_query_create(void);
151 /* destroy it */
152 ZOOM_EXPORT
153 void ZOOM_query_destroy(ZOOM_query s);
154 /* specify prefix query for search */
155 ZOOM_EXPORT
156 int ZOOM_query_prefix(ZOOM_query s, const char *str);
157 /* specify sort criteria for search */
158 ZOOM_EXPORT
159 int ZOOM_query_sortby(ZOOM_query s, const char *criteria);
160
161 /* ----------------------------------------------------------- */
162 /* scan */
163 ZOOM_EXPORT
164 ZOOM_scanset ZOOM_connection_scan (ZOOM_connection c, const char *startterm);
165
166 ZOOM_EXPORT
167 const char * ZOOM_scanset_term(ZOOM_scanset scan, size_t no, int *occ, size_t *len);
168
169 ZOOM_EXPORT
170 size_t ZOOM_scanset_size(ZOOM_scanset scan);
171
172 ZOOM_EXPORT
173 void ZOOM_scanset_destroy (ZOOM_scanset scan);
174 /* ----------------------------------------------------------- */
175 /* options */
176 typedef const char *(*ZOOM_options_callback)(void *handle, const char *name);
177
178 ZOOM_EXPORT
179 ZOOM_options_callback ZOOM_options_set_callback (ZOOM_options opt,
180                                                    ZOOM_options_callback c,
181                                                    void *handle);
182 ZOOM_EXPORT
183 ZOOM_options ZOOM_options_create (void);
184
185 ZOOM_EXPORT
186 ZOOM_options ZOOM_options_create_with_parent (ZOOM_options parent);
187
188 ZOOM_EXPORT
189 const char *ZOOM_options_get (ZOOM_options opt, const char *name);
190
191 ZOOM_EXPORT
192 void ZOOM_options_set (ZOOM_options opt, const char *name, const char *v);
193
194 ZOOM_EXPORT
195 void ZOOM_options_destroy (ZOOM_options opt);
196
197 ZOOM_EXPORT
198 int ZOOM_options_get_bool (ZOOM_options opt, const char *name, int defa);
199
200 ZOOM_EXPORT
201 int ZOOM_options_get_int (ZOOM_options opt, const char *name, int defa);
202
203 ZOOM_EXPORT
204 void ZOOM_options_addref (ZOOM_options opt);
205
206 /* ----------------------------------------------------------- */
207 /* events */
208 /* poll for events on a number of connections. Returns positive
209    integer if event occurred ; zero if none occurred and no more
210    events are pending. The positive integer specifies the
211    connection for which the event occurred. */
212 ZOOM_EXPORT
213 int ZOOM_event (int no, ZOOM_connection *cs);
214
215 ZOOM_END_CDECL