Use shared WRBUF for returned record strings
[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/sortspec.h>
37 #include <yaz/srw.h>
38 #include <yaz/mutex.h>
39
40 #define SHPTR 1
41
42 typedef struct ZOOM_Event_p *ZOOM_Event;
43
44 struct ZOOM_query_p {
45     Z_Query *z_query;
46     Z_SortKeySpecList *sort_spec;
47     int refcount;
48     ODR odr;
49     char *query_string;
50 };
51
52 typedef enum {
53     zoom_sru_error,
54     zoom_sru_soap,
55     zoom_sru_get,
56     zoom_sru_post
57 } zoom_sru_mode;
58     
59
60 typedef struct ZOOM_task_p *ZOOM_task;
61
62 #define STATE_IDLE 0
63 #define STATE_CONNECTING 1
64 #define STATE_ESTABLISHED 2
65
66 typedef struct ZOOM_resultsets_p *ZOOM_resultsets;
67
68 struct ZOOM_connection_p {
69     enum oid_proto proto;
70     COMSTACK cs;
71     char *host_port;
72     char *path;
73     int error;
74     char *addinfo;
75     char *diagset;
76     int state;
77     int mask;
78     int reconnect_ok;
79     ODR odr_in;
80     ODR odr_out;
81     ODR odr_print;
82     char *buf_in;
83     int len_in;
84     char *buf_out;
85     int len_out;
86     char *proxy;
87     char *charset;
88     char *lang;
89     char *cookie_out;
90     char *cookie_in;
91     char *client_IP;
92     char *sru_version;
93
94     char *user;
95     char *group;
96     char *password;
97
98     int async;
99     int support_named_resultsets;
100     int last_event;
101
102     int maximum_record_size;
103     int preferred_message_size;
104
105     ZOOM_task tasks;
106     ZOOM_options options;
107     ZOOM_resultsets resultsets;
108     ZOOM_Event m_queue_front;
109     ZOOM_Event m_queue_back;
110     zoom_sru_mode sru_mode;
111     int no_redirects; /* 0 for no redirects. >0 for number of redirects */
112 };
113
114 struct ZOOM_resultsets_p {
115     ZOOM_resultset resultset;
116     ZOOM_resultsets next;
117 };
118
119
120 struct ZOOM_options_entry {
121     char *name;
122     char *value;
123     int len;                  /* of `value', which may contain NULs */
124     struct ZOOM_options_entry *next;
125 };
126
127 struct ZOOM_options_p {
128     int refcount;
129     void *callback_handle;
130     ZOOM_options_callback callback_func;
131     struct ZOOM_options_entry *entries;
132     ZOOM_options parent1;
133     ZOOM_options parent2;
134 };
135
136
137 typedef struct ZOOM_record_cache_p *ZOOM_record_cache;
138
139 #define RECORD_HASH_SIZE  131
140
141 struct ZOOM_resultset_p {
142     Z_SortKeySpecList *r_sort_spec;
143     ZOOM_query query;
144     int refcount;
145     Odr_int size;
146     int step;
147     int piggyback;
148     char *setname;
149     char *schema;
150     ODR odr;
151     ZOOM_record_cache record_hash[RECORD_HASH_SIZE];
152     ZOOM_options options;
153     ZOOM_connection connection;
154     char **databaseNames;
155     int num_databaseNames;
156     YAZ_MUTEX mutex;
157 #if SHPTR
158     struct WRBUF_shptr *record_wrbuf;
159 #endif
160 };
161
162 struct ZOOM_record_p {
163     ODR odr;
164 #if SHPTR
165     struct WRBUF_shptr *record_wrbuf;
166 #else
167     WRBUF wrbuf;
168 #endif
169
170     Z_NamePlusRecord *npr;
171     const char *schema;
172
173 #if YAZ_HAVE_XML2
174     xmlChar *xml_mem;
175     int xml_size;
176 #endif
177
178     const char *diag_uri;
179     const char *diag_message;
180     const char *diag_details;
181     const char *diag_set;
182 };
183
184 struct ZOOM_record_cache_p {
185     struct ZOOM_record_p rec;
186     char *elementSetName;
187     char *syntax;
188     char *schema;
189     int pos;
190     ZOOM_record_cache next;
191 };
192
193 struct ZOOM_scanset_p {
194     int refcount;
195     ODR odr;
196     ZOOM_options options;
197     ZOOM_connection connection;
198     ZOOM_query query;
199     Z_ScanResponse *scan_response;
200     Z_SRW_scanResponse *srw_scan_response;
201
202     char **databaseNames;
203     int num_databaseNames;
204 };
205
206 struct ZOOM_package_p {
207     int refcount;
208     ODR odr_out;
209     ZOOM_options options;
210     ZOOM_connection connection;
211     char *buf_out;
212     int len_out;
213 };
214
215 struct ZOOM_task_p {
216     int running;
217     int which;
218     union {
219 #define ZOOM_TASK_SEARCH 1
220         struct {
221             int count;
222             int start;
223             ZOOM_resultset resultset;
224             char *syntax;
225             char *elementSetName;
226             int recv_search_fired;
227         } search;
228 #define ZOOM_TASK_RETRIEVE 2
229         struct {
230             int start;
231             ZOOM_resultset resultset;
232             int count;
233             char *syntax;
234             char *elementSetName;
235         } retrieve;
236 #define ZOOM_TASK_CONNECT 3
237 #define ZOOM_TASK_SCAN 4
238         struct {
239             ZOOM_scanset scan;
240         } scan;
241 #define ZOOM_TASK_PACKAGE 5
242         ZOOM_package package;
243 #define ZOOM_TASK_SORT 6
244         struct {
245             ZOOM_resultset resultset;
246             ZOOM_query q;
247         } sort;
248     } u;
249     ZOOM_task next;
250 };
251
252 struct ZOOM_Event_p {
253     int kind;
254     ZOOM_Event next;
255     ZOOM_Event prev;
256 };
257
258 void ZOOM_options_addref (ZOOM_options opt);
259
260 /*
261  * Local variables:
262  * c-basic-offset: 4
263  * c-file-style: "Stroustrup"
264  * indent-tabs-mode: nil
265  * End:
266  * vim: shiftwidth=4 tabstop=8 expandtab
267  */
268