3be459165f8e867c2a0dfb641e7b4fc2e42b8e86
[yaz-moved-to-github.git] / src / zoom-p.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2013 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_solr
50 } zoom_sru_mode;
51
52
53 typedef struct ZOOM_task_p *ZOOM_task;
54
55 #define STATE_IDLE 0
56 #define STATE_CONNECTING 1
57 #define STATE_ESTABLISHED 2
58
59 #if ZOOM_RESULT_LISTS
60 typedef struct ZOOM_resultsets_p *ZOOM_resultsets;
61 #endif
62
63 struct ZOOM_connection_p {
64     enum oid_proto proto;
65     COMSTACK cs;
66     char *host_port;
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     ODR odr_save;
77
78     char *buf_in;
79     int len_in;
80     char *buf_out;
81     int len_out;
82     char *proxy;
83     char *tproxy;
84     char *charset;
85     char *lang;
86     char *cookie_out;
87     char *cookie_in;
88     char *client_IP;
89     char *sru_version;
90
91     char *user;
92     char *group;
93     char *password;
94     int url_authentication;
95
96     int async;
97     int support_named_resultsets;
98     int last_event;
99
100     int maximum_record_size;
101     int preferred_message_size;
102
103     ZOOM_task tasks;
104     ZOOM_options options;
105 #if ZOOM_RESULT_LISTS
106     ZOOM_resultsets resultsets;
107 #else
108     ZOOM_resultset resultsets;
109 #endif
110     ZOOM_Event m_queue_front;
111     ZOOM_Event m_queue_back;
112     zoom_sru_mode sru_mode;
113     int no_redirects; /* 0 for no redirects. >0 for number of redirects */
114
115     int log_details;
116     int log_api;
117     WRBUF saveAPDU_wrbuf;
118 };
119
120 #if ZOOM_RESULT_LISTS
121 struct ZOOM_resultsets_p {
122     ZOOM_resultset resultset;
123     ZOOM_resultsets next;
124 };
125 #endif
126
127 typedef struct ZOOM_record_cache_p *ZOOM_record_cache;
128
129 #define RECORD_HASH_SIZE  131
130
131 struct ZOOM_resultset_p {
132     Z_SortKeySpecList *r_sort_spec;
133     ZOOM_query query;
134     int refcount;
135     Odr_int size;
136     int step;
137     int piggyback;
138     char *setname;
139     ODR odr;
140     ZOOM_record_cache record_hash[RECORD_HASH_SIZE];
141     ZOOM_options options;
142     ZOOM_connection connection;
143     char **databaseNames;
144     int num_databaseNames;
145     YAZ_MUTEX mutex;
146 #if SHPTR
147     struct WRBUF_shptr *record_wrbuf;
148 #endif
149 #if ZOOM_RESULT_LISTS
150 #else
151     ZOOM_resultset next;
152 #endif
153     ZOOM_facet_field *facets;
154     int num_facets;
155     char **facets_names;
156 };
157
158 struct facet_term_p {
159     char *term;
160     int frequency;
161 };
162
163 struct ZOOM_facet_field_p {
164     char *facet_name;
165     int num_terms;
166     struct facet_term_p *facet_terms;
167 };
168
169 struct ZOOM_scanset_p {
170     int refcount;
171     ODR odr;
172     ZOOM_options options;
173     ZOOM_connection connection;
174     ZOOM_query query;
175     Z_ScanResponse *scan_response;
176     Z_SRW_scanResponse *srw_scan_response;
177
178     char **databaseNames;
179     int num_databaseNames;
180 };
181
182 struct ZOOM_package_p {
183     int refcount;
184     ODR odr_out;
185     ZOOM_options options;
186     ZOOM_connection connection;
187     char *buf_out;
188     int len_out;
189 };
190
191 struct ZOOM_task_p {
192     int running;
193     int which;
194     union {
195 #define ZOOM_TASK_SEARCH 1
196         struct {
197             int count;
198             int start;
199             ZOOM_resultset resultset;
200             char *syntax;
201             char *elementSetName;
202             char *schema;
203             int recv_search_fired;
204         } search;
205 #define ZOOM_TASK_RETRIEVE 2
206         struct {
207             int start;
208             ZOOM_resultset resultset;
209             int count;
210             char *syntax;
211             char *elementSetName;
212             char *schema;
213         } retrieve;
214 #define ZOOM_TASK_CONNECT 3
215 #define ZOOM_TASK_SCAN 4
216         struct {
217             ZOOM_scanset scan;
218         } scan;
219 #define ZOOM_TASK_PACKAGE 5
220         ZOOM_package package;
221 #define ZOOM_TASK_SORT 6
222         struct {
223             ZOOM_resultset resultset;
224             ZOOM_query q;
225         } sort;
226     } u;
227     ZOOM_task next;
228 };
229
230 typedef enum {
231     zoom_pending,
232     zoom_complete
233 } zoom_ret;
234
235 void ZOOM_options_addref (ZOOM_options opt);
236
237 void ZOOM_handle_Z3950_apdu(ZOOM_connection c, Z_APDU *apdu);
238
239 void ZOOM_set_dset_error(ZOOM_connection c, int error,
240                          const char *dset,
241                          const char *addinfo, const char *addinfo2);
242
243 void ZOOM_set_error(ZOOM_connection c, int error, const char *addinfo);
244
245 ZOOM_Event ZOOM_Event_create(int kind);
246 void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event);
247
248 zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c);
249 zoom_ret send_Z3950_present(ZOOM_connection c);
250 zoom_ret ZOOM_connection_Z3950_send_scan(ZOOM_connection c);
251 zoom_ret ZOOM_send_buf(ZOOM_connection c);
252 zoom_ret send_Z3950_sort(ZOOM_connection c, ZOOM_resultset resultset);
253 char **ZOOM_connection_get_databases(ZOOM_connection con, ZOOM_options options,
254                                      int *num, ODR odr);
255 zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c);
256
257 ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which);
258 void ZOOM_connection_remove_task(ZOOM_connection c);
259 int ZOOM_test_reconnect(ZOOM_connection c);
260
261 ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
262                                      const char *syntax,
263                                      const char *elementSetName,
264                                      const char *schema);
265 void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
266                            int pos,
267                            const char *syntax, const char *elementSetName,
268                            const char *schema,
269                            Z_SRW_diagnostic *diag);
270
271 Z_Query *ZOOM_query_get_Z_Query(ZOOM_query s);
272 Z_SortKeySpecList *ZOOM_query_get_sortspec(ZOOM_query s);
273 const char *ZOOM_query_get_query_string(ZOOM_query s);
274 const char *ZOOM_query_get_sru11(ZOOM_query s);
275
276 int ZOOM_uri_to_code(const char *uri);
277
278 zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c);
279 zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c);
280
281 int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
282                     zoom_ret *cret, char **addinfo);
283
284 void ZOOM_set_HTTP_error(ZOOM_connection c, int error,
285                          const char *addinfo, const char *addinfo2);
286
287 ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c);
288 void ZOOM_connection_remove_events(ZOOM_connection c);
289 void ZOOM_Event_destroy(ZOOM_Event event);
290 zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu);
291 void ZOOM_handle_facet_list(ZOOM_resultset r, Z_FacetList *fl);
292
293 /*
294  * Local variables:
295  * c-basic-offset: 4
296  * c-file-style: "Stroustrup"
297  * indent-tabs-mode: nil
298  * End:
299  * vim: shiftwidth=4 tabstop=8 expandtab
300  */
301