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