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