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