YAZ  5.23.1
zoom-p.h
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 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  */
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/srw.h>
37 #include <yaz/cookie.h>
38 #include <yaz/mutex.h>
39 #if HAVE_LIBMEMCACHED
40 #include <libmemcached/memcached.h>
41 #endif
42 #if HAVE_HIREDIS
43 #include <hiredis/hiredis.h>
44 #endif
45 
46 #define SHPTR 1
47 
48 typedef struct ZOOM_Event_p *ZOOM_Event;
49 
50 typedef enum {
57 
58 
59 typedef struct ZOOM_task_p *ZOOM_task;
60 
61 #define STATE_IDLE 0
62 #define STATE_CONNECTING 1
63 #define STATE_ESTABLISHED 2
64 
68  char *host_port;
69  int error;
70  char *addinfo;
71  char *diagset;
72  int state;
73  int mask;
79 
80  char *buf_in;
81  int len_in;
82  char *buf_out;
83  int len_out;
84  char *proxy;
85  char *tproxy;
87  char *charset;
88  char *lang;
89  char *cookie_out;
90  char *cookie_in;
91  char *client_IP;
92  char *sru_version;
93 
94  char *user;
95  char *group;
96  char *password;
98 
99  int async;
102 
105 
106  ZOOM_task tasks;
109  ZOOM_Event m_queue_front;
110  ZOOM_Event m_queue_back;
112  int no_redirects; /* 0 for no redirects. >0 for number of redirects */
114  char *location;
115 
117  int log_api;
119 #if HAVE_LIBMEMCACHED
120  memcached_st *mc_st;
121 #endif
122 #if HAVE_HIREDIS
123  redisContext *redis_c;
124 #endif
127 };
128 
130 
131 #define RECORD_HASH_SIZE 131
132 
136  int refcount;
138  int step;
140  char *setname;
142  ZOOM_record_cache record_hash[RECORD_HASH_SIZE];
148 #if SHPTR
149  struct WRBUF_shptr *record_wrbuf;
150 #endif
152  char *req_facets;
155  char **facets_names; /* redundant. For ZOOM_resultset_facets_names only */
157  int live_set; /* 0=no hit count, 1=cached hit, 2=hits + real set */
158 };
159 
160 struct facet_term_p {
161  char *term;
163 };
164 
166  char *facet_name;
169 };
170 
172  int refcount;
179 
182 };
183 
185  int refcount;
189  char *buf_out;
190  int len_out;
191 };
192 
193 struct ZOOM_task_p {
194  int running;
195  int which;
196  union {
197 #define ZOOM_TASK_SEARCH 1
198  struct {
199  int count;
200  int start;
202  char *syntax;
204  char *schema;
205  } search;
206 #define ZOOM_TASK_CONNECT 3
207 #define ZOOM_TASK_SCAN 4
208  struct {
210  } scan;
211 #define ZOOM_TASK_PACKAGE 5
213 #define ZOOM_TASK_SORT 6
214  struct {
215  ZOOM_resultset resultset;
217  } sort;
218  } u;
219  ZOOM_task next;
220 };
221 
222 typedef enum {
225 } zoom_ret;
226 
228 
230 
232  const char *dset,
233  const char *addinfo, const char *addinfo2);
234 
235 void ZOOM_set_error(ZOOM_connection c, int error, const char *addinfo);
236 
237 ZOOM_Event ZOOM_Event_create(int kind);
238 void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event);
239 
245  int *num, ODR odr);
247 
248 ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which);
252 
254  const char *syntax,
255  const char *elementSetName,
256  const char *schema);
258  int pos,
259  const char *syntax, const char *elementSetName,
260  const char *schema,
261  Z_SRW_diagnostic *diag);
262 
266 const char *ZOOM_query_get_sru11(ZOOM_query s);
268 
269 int ZOOM_uri_to_code(const char *uri);
270 
273 
275  zoom_ret *cret, char **addinfo);
276 
278  const char *addinfo, const char *addinfo2);
279 
282 void ZOOM_Event_destroy(ZOOM_Event event);
285 
292  Z_OtherInformation *oi, const char *precision);
294  int pos,
295  const char *syntax, const char *elementSetName,
296  const char *schema,
297  Z_SRW_diagnostic *diag);
299  const char *syntax,
300  const char *elementSetName,
301  const char *schema);
303  const char *syntax,
304  const char *elementSetName,
305  const char *schema);
307  Z_OtherInformation *o);
309  Z_OtherInformation *o);
310 
311 /*
312  * Local variables:
313  * c-basic-offset: 4
314  * c-file-style: "Stroustrup"
315  * indent-tabs-mode: nil
316  * End:
317  * vim: shiftwidth=4 tabstop=8 expandtab
318  */
319 
ZOOM_resultset resultsets
Definition: zoom-p.h:108
ZOOM_query q
Definition: zoom-p.h:216
ZOOM_options options
Definition: zoom-p.h:174
YAZ_MUTEX mutex
Definition: zoom-p.h:147
void ZOOM_options_addref(ZOOM_options opt)
Definition: zoom-opt.c:113
int running
Definition: zoom-p.h:194
Z_Query * ZOOM_query_get_Z_Query(ZOOM_query s)
Definition: zoom-query.c:129
Header for ZOOM.
ZOOM_query query
Definition: zoom-p.h:135
void ZOOM_connection_remove_task(ZOOM_connection c)
Definition: zoom-c.c:183
int num_databaseNames
Definition: zoom-p.h:146
char * facet_name
Definition: zoom-p.h:166
void ZOOM_set_dset_error(ZOOM_connection c, int error, const char *dset, const char *addinfo, const char *addinfo2)
Definition: zoom-c.c:54
struct ZOOM_task_p * ZOOM_task
Definition: zoom-p.h:59
int start
Definition: zoom-p.h:200
Z_ScanResponse * scan_response
Definition: zoom-p.h:177
Header for WRBUF (growing buffer)
struct ZOOM_record_cache_p * ZOOM_record_cache
Definition: zoom-p.h:129
const char * ZOOM_query_get_query_string(ZOOM_query s)
Definition: zoom-query.c:139
void ZOOM_set_HTTP_error(ZOOM_connection c, int error, const char *addinfo, const char *addinfo2)
Definition: zoom-c.c:1546
ZOOM_connection connection
Definition: zoom-p.h:144
zoom_sru_mode
Definition: zoom-p.h:50
char ** ZOOM_connection_get_databases(ZOOM_connection con, ZOOM_options options, int *num, ODR odr)
Definition: zoom-c.c:322
ZOOM_options options
Definition: zoom-p.h:107
void ZOOM_handle_search_result(ZOOM_connection c, ZOOM_resultset resultset, Z_OtherInformation *o)
Definition: zoom-z3950.c:1198
int num_res_facets
Definition: zoom-p.h:154
void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event)
Definition: zoom-event.c:73
int ZOOM_uri_to_code(const char *uri)
Definition: zoom-c.c:89
int support_named_resultsets
Definition: zoom-p.h:100
ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos, const char *syntax, const char *elementSetName, const char *schema)
Header for SRW/SRU.
int url_authentication
Definition: zoom-p.h:97
void ZOOM_handle_Z3950_apdu(ZOOM_connection c, Z_APDU *apdu)
Definition: zoom-z3950.c:1627
Z_NamePlusRecord * ZOOM_memcached_lookup(ZOOM_resultset r, int pos, const char *syntax, const char *elementSetName, const char *schema)
zoom_ret ZOOM_connection_Z3950_send_scan(ZOOM_connection c)
Definition: zoom-z3950.c:808
char * proxy
Definition: zoom-p.h:84
nmem_int_t Odr_int
Definition: odr.h:47
WRBUF saveAPDU_wrbuf
Definition: zoom-p.h:118
string buffer
Definition: wrbuf.h:42
zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c)
Definition: zoom-sru.c:145
char * charset
Definition: zoom-p.h:87
ZOOM_Event m_queue_back
Definition: zoom-p.h:110
ZOOM_options options
Definition: zoom-p.h:187
zoom_ret send_Z3950_sort(ZOOM_connection c, ZOOM_resultset resultset)
Definition: zoom-z3950.c:1445
zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c)
Definition: zoom-z3950.c:559
void ZOOM_handle_facet_result(ZOOM_connection c, ZOOM_resultset r, Z_OtherInformation *o)
Definition: zoom-z3950.c:1143
oid_proto
Definition: oid_util.h:44
Z_SRW_scanResponse * srw_scan_response
Definition: zoom-p.h:178
ZOOM_connection connection
Definition: zoom-p.h:188
ZOOM_scanset scan
Definition: zoom-p.h:209
ZOOM_task tasks
Definition: zoom-p.h:106
Header for OID database.
ZOOM_Event m_queue_front
Definition: zoom-p.h:109
void ZOOM_memcached_add(ZOOM_resultset r, Z_NamePlusRecord *npr, int pos, const char *syntax, const char *elementSetName, const char *schema, Z_SRW_diagnostic *diag)
void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset result, Z_OtherInformation *oi, const char *precision)
void ZOOM_memcached_destroy(ZOOM_connection c)
char * sru_version
Definition: zoom-p.h:92
enum oid_proto proto
Definition: zoom-p.h:66
void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, int pos, const char *syntax, const char *elementSetName, const char *schema, Z_SRW_diagnostic *diag)
int num_databaseNames
Definition: zoom-p.h:181
struct facet_term_p * facet_terms
Definition: zoom-p.h:168
char * cookie_out
Definition: zoom-p.h:89
char * setname
Definition: zoom-p.h:140
char * client_IP
Definition: zoom-p.h:91
int refcount
Definition: zoom-p.h:172
const char * ZOOM_query_get_sru11(ZOOM_query s)
Definition: zoom-query.c:122
WRBUF mc_key
Definition: zoom-p.h:156
ZOOM_facet_field * res_facets
Definition: zoom-p.h:153
COMSTACK cs
Definition: zoom-p.h:67
char * tproxy
Definition: zoom-p.h:85
ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c)
Definition: zoom-event.c:52
ZOOM_package package
Definition: zoom-p.h:212
char * buf_out
Definition: zoom-p.h:82
struct ZOOM_Event_p * ZOOM_Event
Definition: zoom-p.h:48
int refcount
Definition: zoom-p.h:185
zoom_ret
Definition: zoom-p.h:222
Odr_int size
Definition: zoom-p.h:137
ZOOM_task next
Definition: zoom-p.h:219
Header for COMSTACK.
char ** databaseNames
Definition: zoom-p.h:180
char * syntax
Definition: zoom-p.h:202
int which
Definition: zoom-p.h:195
Header for Z39.50 Protocol.
char * addinfo
Definition: zoom-p.h:70
char * buf_out
Definition: zoom-p.h:189
void ZOOM_handle_facet_list(ZOOM_resultset r, Z_FacetList *fl)
Definition: zoom-z3950.c:1122
ZOOM_connection connection
Definition: zoom-p.h:175
Z_SortKeySpecList * r_sort_spec
Definition: zoom-p.h:134
typedefZOOM_BEGIN_CDECL struct ZOOM_options_p * ZOOM_options
Definition: zoom.h:50
char ** databaseNames
Definition: zoom-p.h:145
int preferred_message_size
Definition: zoom-p.h:104
char * password
Definition: zoom-p.h:96
char * group
Definition: zoom-p.h:95
void ZOOM_memcached_resultset(ZOOM_resultset r, ZOOM_query q)
int maximum_record_size
Definition: zoom-p.h:103
void ZOOM_memcached_init(ZOOM_connection c)
char * schema
Definition: zoom-p.h:204
void ZOOM_query_get_hash(ZOOM_query s, WRBUF w)
Definition: zoom-query.c:144
ZOOM_Event ZOOM_Event_create(int kind)
Definition: zoom-event.c:42
Definition: odr.h:124
Z_SortKeySpecList * ZOOM_query_get_sortspec(ZOOM_query s)
Definition: zoom-query.c:134
Header for Mutex functions.
#define RECORD_HASH_SIZE
Definition: zoom-p.h:131
char * host_port
Definition: zoom-p.h:68
ZOOM_options options
Definition: zoom-p.h:143
char * cookie_in
Definition: zoom-p.h:90
zoom_ret ZOOM_connection_Z3950_search(ZOOM_connection c)
Definition: zoom-z3950.c:1555
static size_t record_hash(int pos)
int opt
Definition: initopt.c:19
char * user
Definition: zoom-p.h:94
int count
Definition: zoom-p.h:199
zoom_ret ZOOM_send_buf(ZOOM_connection c)
Definition: zoom-c.c:1763
char * elementSetName
Definition: zoom-p.h:203
char * location
Definition: zoom-p.h:114
zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu)
Definition: zoom-c.c:1526
ZOOM_resultset resultset
Definition: zoom-p.h:201
zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c)
Definition: zoom-sru.c:92
void ZOOM_Event_destroy(ZOOM_Event event)
Definition: zoom-event.c:90
char * lang
Definition: zoom-p.h:88
ZOOM_query query
Definition: zoom-p.h:176
ZOOM_resultset next
Definition: zoom-p.h:151
void ZOOM_connection_remove_events(ZOOM_connection c)
Definition: zoom-event.c:95
int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, zoom_ret *cret, char **addinfo)
Definition: zoom-sru.c:417
Definition: z-core.h:321
int reconnect_ok
Definition: zoom-p.h:74
Definition: zgdu.h:68
void ZOOM_memcached_search(ZOOM_connection c, ZOOM_resultset r)
yaz_cookies_t cookies
Definition: zoom-p.h:113
char * term
Definition: zoom-p.h:161
char ** facets_names
Definition: zoom-p.h:155
void ZOOM_set_error(ZOOM_connection c, int error, const char *addinfo)
Definition: zoom-c.c:98
int frequency
Definition: zoom-p.h:162
int ZOOM_memcached_configure(ZOOM_connection c)
void ZOOM_connection_remove_tasks(ZOOM_connection c)
Definition: zoom-c.c:223
int ZOOM_test_reconnect(ZOOM_connection c)
Definition: zoom-c.c:904
char * diagset
Definition: zoom-p.h:71
ZOOM_record ZOOM_record_cache_lookup_i(ZOOM_resultset r, int pos, const char *syntax, const char *elementSetName, const char *schema)
ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which)
Definition: zoom-c.c:153
zoom_sru_mode sru_mode
Definition: zoom-p.h:111
struct WRBUF_shptr * record_wrbuf
Definition: zoom-p.h:149
char * buf_in
Definition: zoom-p.h:80
char * req_facets
Definition: zoom-p.h:152