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