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 */ 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/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 { 51 zoom_sru_error, 52 zoom_sru_soap, 53 zoom_sru_get, 54 zoom_sru_post, 55 zoom_sru_solr 56 } zoom_sru_mode; 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 65 struct ZOOM_connection_p { 66 enum oid_proto proto; 67 COMSTACK cs; 68 char *host_port; 69 int error; 70 char *addinfo; 71 char *diagset; 72 int state; 73 int mask; 74 int reconnect_ok; 75 ODR odr_in; 76 ODR odr_out; 77 ODR odr_print; 78 ODR odr_save; 79 80 char *buf_in; 81 int len_in; 82 char *buf_out; 83 int len_out; 84 char *proxy; 85 char *tproxy; 86 int proxy_mode; 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; 97 int url_authentication; 98 99 int async; 100 int support_named_resultsets; 101 int last_event; 102 103 int maximum_record_size; 104 int preferred_message_size; 105 106 ZOOM_task tasks; 107 ZOOM_options options; 108 ZOOM_resultset resultsets; 109 ZOOM_Event m_queue_front; 110 ZOOM_Event m_queue_back; 111 zoom_sru_mode sru_mode; 112 int no_redirects; /* 0 for no redirects. >0 for number of redirects */ 113 yaz_cookies_t cookies; 114 char *location; 115 116 int log_details; 117 int log_api; 118 WRBUF saveAPDU_wrbuf; 119 #if HAVE_LIBMEMCACHED 120 memcached_st *mc_st; 121 #endif 122 #if HAVE_HIREDIS 123 redisContext *redis_c; 124 #endif 125 int expire_search; 126 int expire_record; 127 }; 128 129 typedef struct ZOOM_record_cache_p *ZOOM_record_cache; 130 131 #define RECORD_HASH_SIZE 131 132 133 struct ZOOM_resultset_p { 134 Z_SortKeySpecList *r_sort_spec; 135 ZOOM_query query; 136 int refcount; 137 Odr_int size; 138 int step; 139 int piggyback; 140 char *setname; 141 ODR odr; 142 ZOOM_record_cache record_hash[RECORD_HASH_SIZE]; 143 ZOOM_options options; 144 ZOOM_connection connection; 145 char **databaseNames; 146 int num_databaseNames; 147 YAZ_MUTEX mutex; 148 #if SHPTR 149 struct WRBUF_shptr *record_wrbuf; 150 #endif 151 ZOOM_resultset next; 152 char *req_facets; 153 ZOOM_facet_field *res_facets; 154 int num_res_facets; 155 char **facets_names; /* redundant. For ZOOM_resultset_facets_names only */ 156 WRBUF mc_key; 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; 162 int frequency; 163 }; 164 165 struct ZOOM_facet_field_p { 166 char *facet_name; 167 int num_terms; 168 struct facet_term_p *facet_terms; 169 }; 170 171 struct ZOOM_scanset_p { 172 int refcount; 173 ODR odr; 174 ZOOM_options options; 175 ZOOM_connection connection; 176 ZOOM_query query; 177 Z_ScanResponse *scan_response; 178 Z_SRW_scanResponse *srw_scan_response; 179 180 char **databaseNames; 181 int num_databaseNames; 182 }; 183 184 struct ZOOM_package_p { 185 int refcount; 186 ODR odr_out; 187 ZOOM_options options; 188 ZOOM_connection connection; 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; 201 ZOOM_resultset resultset; 202 char *syntax; 203 char *elementSetName; 204 char *schema; 205 } search; 206 #define ZOOM_TASK_CONNECT 3 207 #define ZOOM_TASK_SCAN 4 208 struct { 209 ZOOM_scanset scan; 210 } scan; 211 #define ZOOM_TASK_PACKAGE 5 212 ZOOM_package package; 213 #define ZOOM_TASK_SORT 6 214 struct { 215 ZOOM_resultset resultset; 216 ZOOM_query q; 217 } sort; 218 } u; 219 ZOOM_task next; 220 }; 221 222 typedef enum { 223 zoom_pending, 224 zoom_complete 225 } zoom_ret; 226 227 void ZOOM_options_addref (ZOOM_options opt); 228 229 void ZOOM_handle_Z3950_apdu(ZOOM_connection c, Z_APDU *apdu); 230 231 void ZOOM_set_dset_error(ZOOM_connection c, int error, 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 240 zoom_ret ZOOM_connection_Z3950_search(ZOOM_connection c); 241 zoom_ret ZOOM_connection_Z3950_send_scan(ZOOM_connection c); 242 zoom_ret ZOOM_send_buf(ZOOM_connection c); 243 zoom_ret send_Z3950_sort(ZOOM_connection c, ZOOM_resultset resultset); 244 char **ZOOM_connection_get_databases(ZOOM_connection con, ZOOM_options options, 245 int *num, ODR odr); 246 zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c); 247 248 ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which); 249 void ZOOM_connection_remove_task(ZOOM_connection c); 250 void ZOOM_connection_remove_tasks(ZOOM_connection c); 251 int ZOOM_test_reconnect(ZOOM_connection c); 252 253 ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos, 254 const char *syntax, 255 const char *elementSetName, 256 const char *schema); 257 void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, 258 int pos, 259 const char *syntax, const char *elementSetName, 260 const char *schema, 261 Z_SRW_diagnostic *diag); 262 263 Z_Query *ZOOM_query_get_Z_Query(ZOOM_query s); 264 Z_SortKeySpecList *ZOOM_query_get_sortspec(ZOOM_query s); 265 const char *ZOOM_query_get_query_string(ZOOM_query s); 266 const char *ZOOM_query_get_sru11(ZOOM_query s); 267 void ZOOM_query_get_hash(ZOOM_query s, WRBUF w); 268 269 int ZOOM_uri_to_code(const char *uri); 270 271 zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c); 272 zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c); 273 274 int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, 275 zoom_ret *cret, char **addinfo); 276 277 void ZOOM_set_HTTP_error(ZOOM_connection c, int error, 278 const char *addinfo, const char *addinfo2); 279 280 ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c); 281 void ZOOM_connection_remove_events(ZOOM_connection c); 282 void ZOOM_Event_destroy(ZOOM_Event event); 283 zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu); 284 void ZOOM_handle_facet_list(ZOOM_resultset r, Z_FacetList *fl); 285 286 void ZOOM_memcached_init(ZOOM_connection c); 287 int ZOOM_memcached_configure(ZOOM_connection c); 288 void ZOOM_memcached_destroy(ZOOM_connection c); 289 void ZOOM_memcached_resultset(ZOOM_resultset r, ZOOM_query q); 290 void ZOOM_memcached_search(ZOOM_connection c, ZOOM_resultset r); 291 void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset result, 292 Z_OtherInformation *oi, const char *precision); 293 void ZOOM_memcached_add(ZOOM_resultset r, Z_NamePlusRecord *npr, 294 int pos, 295 const char *syntax, const char *elementSetName, 296 const char *schema, 297 Z_SRW_diagnostic *diag); 298 Z_NamePlusRecord *ZOOM_memcached_lookup(ZOOM_resultset r, int pos, 299 const char *syntax, 300 const char *elementSetName, 301 const char *schema); 302 ZOOM_record ZOOM_record_cache_lookup_i(ZOOM_resultset r, int pos, 303 const char *syntax, 304 const char *elementSetName, 305 const char *schema); 306 void ZOOM_handle_facet_result(ZOOM_connection c, ZOOM_resultset r, 307 Z_OtherInformation *o); 308 void ZOOM_handle_search_result(ZOOM_connection c, ZOOM_resultset resultset, 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 320