Refactor ZOOM SRU stuff to separate source
[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 facet_term_p {
172     char *term;
173     int frequency;
174 };
175
176 struct ZOOM_facet_field_p {
177     char *facet_name;
178     int num_terms;
179     struct facet_term_p *facet_terms;
180 };
181
182 struct ZOOM_scanset_p {
183     int refcount;
184     ODR odr;
185     ZOOM_options options;
186     ZOOM_connection connection;
187     ZOOM_query query;
188     Z_ScanResponse *scan_response;
189     Z_SRW_scanResponse *srw_scan_response;
190
191     char **databaseNames;
192     int num_databaseNames;
193 };
194
195 struct ZOOM_package_p {
196     int refcount;
197     ODR odr_out;
198     ZOOM_options options;
199     ZOOM_connection connection;
200     char *buf_out;
201     int len_out;
202 };
203
204 struct ZOOM_task_p {
205     int running;
206     int which;
207     union {
208 #define ZOOM_TASK_SEARCH 1
209         struct {
210             int count;
211             int start;
212             ZOOM_resultset resultset;
213             char *syntax;
214             char *elementSetName;
215             int recv_search_fired;
216         } search;
217 #define ZOOM_TASK_RETRIEVE 2
218         struct {
219             int start;
220             ZOOM_resultset resultset;
221             int count;
222             char *syntax;
223             char *elementSetName;
224         } retrieve;
225 #define ZOOM_TASK_CONNECT 3
226 #define ZOOM_TASK_SCAN 4
227         struct {
228             ZOOM_scanset scan;
229         } scan;
230 #define ZOOM_TASK_PACKAGE 5
231         ZOOM_package package;
232 #define ZOOM_TASK_SORT 6
233         struct {
234             ZOOM_resultset resultset;
235             ZOOM_query q;
236         } sort;
237     } u;
238     ZOOM_task next;
239 };
240
241 struct ZOOM_Event_p {
242     int kind;
243     ZOOM_Event next;
244     ZOOM_Event prev;
245 };
246
247 typedef enum {
248     zoom_pending,
249     zoom_complete
250 } zoom_ret;
251
252 void ZOOM_options_addref (ZOOM_options opt);
253
254 void ZOOM_handle_Z3950_apdu(ZOOM_connection c, Z_APDU *apdu);
255
256 void ZOOM_set_dset_error(ZOOM_connection c, int error,
257                          const char *dset,
258                          const char *addinfo, const char *addinfo2);
259
260 void ZOOM_set_error(ZOOM_connection c, int error, const char *addinfo);
261
262 ZOOM_Event ZOOM_Event_create(int kind);
263 void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event);
264
265 zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c);
266 zoom_ret send_Z3950_present(ZOOM_connection c);
267 zoom_ret ZOOM_connection_Z3950_send_scan(ZOOM_connection c);
268 zoom_ret ZOOM_send_buf(ZOOM_connection c);
269 zoom_ret send_Z3950_sort(ZOOM_connection c, ZOOM_resultset resultset);
270 char **ZOOM_connection_get_databases(ZOOM_connection con, ZOOM_options options,
271                                      int *num, ODR odr);
272 zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c);
273
274 ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which);
275 void ZOOM_connection_remove_task(ZOOM_connection c);
276 int ZOOM_test_reconnect(ZOOM_connection c);
277
278 ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
279                                      const char *syntax,
280                                      const char *elementSetName);
281 void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, 
282                            int pos,
283                            const char *syntax, const char *elementSetName,
284                            const char *schema,
285                            Z_SRW_diagnostic *diag);
286
287 Z_Query *ZOOM_query_get_Z_Query(ZOOM_query s);
288 Z_SortKeySpecList *ZOOM_query_get_sortspec(ZOOM_query s);
289 char *ZOOM_query_get_query_string(ZOOM_query s);
290
291 int ZOOM_uri_to_code(const char *uri);
292
293 zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c);
294 zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c);
295
296 int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
297                     zoom_ret *cret);
298
299 void ZOOM_set_HTTP_error(ZOOM_connection c, int error,
300                          const char *addinfo, const char *addinfo2);
301
302 /*
303  * Local variables:
304  * c-basic-offset: 4
305  * c-file-style: "Stroustrup"
306  * indent-tabs-mode: nil
307  * End:
308  * vim: shiftwidth=4 tabstop=8 expandtab
309  */
310