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