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