c2125a19ca5d6ae2e101f2b549d63ab0c49e1c7a
[yaz-moved-to-github.git] / src / zoom-p.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 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     char *buf_in;
77     int len_in;
78     char *buf_out;
79     int len_out;
80     char *proxy;
81     char *charset;
82     char *lang;
83     char *cookie_out;
84     char *cookie_in;
85     char *client_IP;
86     char *sru_version;
87
88     char *user;
89     char *group;
90     char *password;
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 };
106
107 struct ZOOM_options_entry {
108     char *name;
109     char *value;
110     int len;                  /* of `value', which may contain NULs */
111     struct ZOOM_options_entry *next;
112 };
113
114 struct ZOOM_options_p {
115     int refcount;
116     void *callback_handle;
117     ZOOM_options_callback callback_func;
118     struct ZOOM_options_entry *entries;
119     ZOOM_options parent1;
120     ZOOM_options parent2;
121 };
122
123
124 typedef struct ZOOM_record_cache_p *ZOOM_record_cache;
125
126 #define RECORD_HASH_SIZE  131
127
128 struct ZOOM_resultset_p {
129     Z_SortKeySpecList *r_sort_spec;
130     ZOOM_query query;
131     int refcount;
132     int size;
133     int step;
134     int piggyback;
135     char *setname;
136     char *schema;
137     ODR odr;
138     ZOOM_record_cache record_hash[RECORD_HASH_SIZE];
139     ZOOM_options options;
140     ZOOM_connection connection;
141     ZOOM_resultset next;
142     char **databaseNames;
143     int num_databaseNames;
144 };
145
146 struct ZOOM_record_p {
147     ODR odr;
148     WRBUF wrbuf_marc;
149     WRBUF wrbuf_iconv;
150     WRBUF wrbuf_opac;
151     Z_NamePlusRecord *npr;
152     const char *schema;
153
154     const char *diag_uri;
155     const char *diag_message;
156     const char *diag_details;
157     const char *diag_set;
158 };
159
160 struct ZOOM_record_cache_p {
161     struct ZOOM_record_p rec;
162     char *elementSetName;
163     char *syntax;
164     char *schema;
165     int pos;
166     ZOOM_record_cache next;
167 };
168
169 struct ZOOM_scanset_p {
170     int refcount;
171     ODR odr;
172     ZOOM_options options;
173     ZOOM_connection connection;
174     ZOOM_query query;
175     Z_ScanResponse *scan_response;
176     Z_SRW_scanResponse *srw_scan_response;
177
178     char **databaseNames;
179     int num_databaseNames;
180 };
181
182 struct ZOOM_package_p {
183     int refcount;
184     ODR odr_out;
185     ZOOM_options options;
186     ZOOM_connection connection;
187     char *buf_out;
188     int len_out;
189 };
190
191 struct ZOOM_task_p {
192     int running;
193     int which;
194     union {
195 #define ZOOM_TASK_SEARCH 1
196         struct {
197             int count;
198             int start;
199             ZOOM_resultset resultset;
200             char *syntax;
201             char *elementSetName;
202         } search;
203 #define ZOOM_TASK_RETRIEVE 2
204         struct {
205             int start;
206             ZOOM_resultset resultset;
207             int count;
208             char *syntax;
209             char *elementSetName;
210         } retrieve;
211 #define ZOOM_TASK_CONNECT 3
212 #define ZOOM_TASK_SCAN 4
213         struct {
214             ZOOM_scanset scan;
215         } scan;
216 #define ZOOM_TASK_PACKAGE 5
217         ZOOM_package package;
218 #define ZOOM_TASK_SORT 6
219         struct {
220             ZOOM_resultset resultset;
221             ZOOM_query q;
222         } sort;
223     } u;
224     ZOOM_task next;
225 };
226
227 struct ZOOM_Event_p {
228     int kind;
229     ZOOM_Event next;
230     ZOOM_Event prev;
231 };
232
233 void ZOOM_options_addref (ZOOM_options opt);
234
235 /*
236  * Local variables:
237  * c-basic-offset: 4
238  * indent-tabs-mode: nil
239  * End:
240  * vim: shiftwidth=4 tabstop=8 expandtab
241  */
242