6a95040b03999205049d600c9fd2bb33f2c4a756
[yaz-moved-to-github.git] / src / zoom-p.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2010 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 /**
28  * \file zoom-p.h
29  * \brief Internal header for ZOOM implementation
30  */
31 #include <yaz/proto.h>
32 #include <yaz/oid_db.h>
33 #include <yaz/comstack.h>
34 #include <yaz/wrbuf.h>
35 #include <yaz/zoom.h>
36 #include <yaz/sortspec.h>
37 #include <yaz/srw.h>
38 #include <yaz/mutex.h>
39
40 #define SHPTR 1
41 #define ZOOM_RESULT_LISTS 0
42
43 typedef struct ZOOM_Event_p *ZOOM_Event;
44
45 struct ZOOM_query_p {
46     Z_Query *z_query;
47     Z_SortKeySpecList *sort_spec;
48     int refcount;
49     ODR odr;
50     char *query_string;
51 };
52
53 typedef enum {
54     zoom_sru_error,
55     zoom_sru_soap,
56     zoom_sru_get,
57     zoom_sru_post
58 } zoom_sru_mode;
59     
60
61 typedef struct ZOOM_task_p *ZOOM_task;
62
63 #define STATE_IDLE 0
64 #define STATE_CONNECTING 1
65 #define STATE_ESTABLISHED 2
66
67 #if ZOOM_RESULT_LISTS
68 typedef struct ZOOM_resultsets_p *ZOOM_resultsets;
69 #endif
70
71 struct ZOOM_connection_p {
72     enum oid_proto proto;
73     COMSTACK cs;
74     char *host_port;
75     char *path;
76     int error;
77     char *addinfo;
78     char *diagset;
79     int state;
80     int mask;
81     int reconnect_ok;
82     ODR odr_in;
83     ODR odr_out;
84     ODR odr_print;
85     char *buf_in;
86     int len_in;
87     char *buf_out;
88     int len_out;
89     char *proxy;
90     char *charset;
91     char *lang;
92     char *cookie_out;
93     char *cookie_in;
94     char *client_IP;
95     char *sru_version;
96
97     char *user;
98     char *group;
99     char *password;
100
101     int async;
102     int support_named_resultsets;
103     int last_event;
104
105     int maximum_record_size;
106     int preferred_message_size;
107
108     ZOOM_task tasks;
109     ZOOM_options options;
110 #if ZOOM_RESULT_LISTS
111     ZOOM_resultsets resultsets;
112 #else
113     ZOOM_resultset resultsets;
114 #endif
115     ZOOM_Event m_queue_front;
116     ZOOM_Event m_queue_back;
117     zoom_sru_mode sru_mode;
118     int no_redirects; /* 0 for no redirects. >0 for number of redirects */
119
120     int log_details;
121     int log_api;
122 };
123
124 #if ZOOM_RESULT_LISTS
125 struct ZOOM_resultsets_p {
126     ZOOM_resultset resultset;
127     ZOOM_resultsets next;
128 };
129 #endif
130
131 struct ZOOM_options_entry {
132     char *name;
133     char *value;
134     int len;                  /* of `value', which may contain NULs */
135     struct ZOOM_options_entry *next;
136 };
137
138 struct ZOOM_options_p {
139     int refcount;
140     void *callback_handle;
141     ZOOM_options_callback callback_func;
142     struct ZOOM_options_entry *entries;
143     ZOOM_options parent1;
144     ZOOM_options parent2;
145 };
146
147
148 typedef struct ZOOM_record_cache_p *ZOOM_record_cache;
149
150 #define RECORD_HASH_SIZE  131
151
152 struct ZOOM_resultset_p {
153     Z_SortKeySpecList *r_sort_spec;
154     ZOOM_query query;
155     int refcount;
156     Odr_int size;
157     int step;
158     int piggyback;
159     char *setname;
160     char *schema;
161     ODR odr;
162     ZOOM_record_cache record_hash[RECORD_HASH_SIZE];
163     ZOOM_options options;
164     ZOOM_connection connection;
165     char **databaseNames;
166     int num_databaseNames;
167     YAZ_MUTEX mutex;
168 #if SHPTR
169     struct WRBUF_shptr *record_wrbuf;
170 #endif
171 #if ZOOM_RESULT_LISTS
172 #else
173     ZOOM_resultset next;
174 #endif
175     ZOOM_facet_field *facets;
176     int num_facets;
177     char **facets_names;
178 };
179
180 struct ZOOM_record_p {
181     ODR odr;
182 #if SHPTR
183     struct WRBUF_shptr *record_wrbuf;
184 #else
185     WRBUF wrbuf;
186 #endif
187
188     Z_NamePlusRecord *npr;
189     const char *schema;
190
191     const char *diag_uri;
192     const char *diag_message;
193     const char *diag_details;
194     const char *diag_set;
195 };
196
197 struct facet_term_p {
198     char *term;
199     int frequency;
200 };
201
202 struct ZOOM_facet_field_p {
203     char *facet_name;
204     int num_terms;
205     struct facet_term_p *facet_terms;
206 };
207
208
209 struct ZOOM_record_cache_p {
210     struct ZOOM_record_p rec;
211     char *elementSetName;
212     char *syntax;
213     char *schema;
214     int pos;
215     ZOOM_record_cache next;
216 };
217
218 struct ZOOM_scanset_p {
219     int refcount;
220     ODR odr;
221     ZOOM_options options;
222     ZOOM_connection connection;
223     ZOOM_query query;
224     Z_ScanResponse *scan_response;
225     Z_SRW_scanResponse *srw_scan_response;
226
227     char **databaseNames;
228     int num_databaseNames;
229 };
230
231 struct ZOOM_package_p {
232     int refcount;
233     ODR odr_out;
234     ZOOM_options options;
235     ZOOM_connection connection;
236     char *buf_out;
237     int len_out;
238 };
239
240 struct ZOOM_task_p {
241     int running;
242     int which;
243     union {
244 #define ZOOM_TASK_SEARCH 1
245         struct {
246             int count;
247             int start;
248             ZOOM_resultset resultset;
249             char *syntax;
250             char *elementSetName;
251             int recv_search_fired;
252         } search;
253 #define ZOOM_TASK_RETRIEVE 2
254         struct {
255             int start;
256             ZOOM_resultset resultset;
257             int count;
258             char *syntax;
259             char *elementSetName;
260         } retrieve;
261 #define ZOOM_TASK_CONNECT 3
262 #define ZOOM_TASK_SCAN 4
263         struct {
264             ZOOM_scanset scan;
265         } scan;
266 #define ZOOM_TASK_PACKAGE 5
267         ZOOM_package package;
268 #define ZOOM_TASK_SORT 6
269         struct {
270             ZOOM_resultset resultset;
271             ZOOM_query q;
272         } sort;
273     } u;
274     ZOOM_task next;
275 };
276
277 struct ZOOM_Event_p {
278     int kind;
279     ZOOM_Event next;
280     ZOOM_Event prev;
281 };
282
283 typedef enum {
284     zoom_pending,
285     zoom_complete
286 } zoom_ret;
287
288 void ZOOM_options_addref (ZOOM_options opt);
289
290 void ZOOM_handle_Z3950_apdu(ZOOM_connection c, Z_APDU *apdu);
291
292 void ZOOM_set_dset_error(ZOOM_connection c, int error,
293                          const char *dset,
294                          const char *addinfo, const char *addinfo2);
295
296 void ZOOM_set_error(ZOOM_connection c, int error, const char *addinfo);
297
298 ZOOM_Event ZOOM_Event_create(int kind);
299 void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event);
300
301 zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c);
302 zoom_ret send_Z3950_present(ZOOM_connection c);
303 zoom_ret ZOOM_connection_Z3950_send_scan(ZOOM_connection c);
304 zoom_ret ZOOM_send_buf(ZOOM_connection c);
305 zoom_ret send_Z3950_sort(ZOOM_connection c, ZOOM_resultset resultset);
306 char **ZOOM_connection_get_databases(ZOOM_connection con, ZOOM_options options,
307                                      int *num, ODR odr);
308 zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c);
309
310 ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which);
311 void ZOOM_connection_remove_task(ZOOM_connection c);
312 int ZOOM_test_reconnect(ZOOM_connection c);
313
314 ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
315                                      const char *syntax,
316                                      const char *elementSetName);
317 void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, 
318                            int pos,
319                            const char *syntax, const char *elementSetName,
320                            const char *schema,
321                            Z_SRW_diagnostic *diag);
322
323
324 /*
325  * Local variables:
326  * c-basic-offset: 4
327  * c-file-style: "Stroustrup"
328  * indent-tabs-mode: nil
329  * End:
330  * vim: shiftwidth=4 tabstop=8 expandtab
331  */
332