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