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