pazpar2  1.14.1
client.c
Go to the documentation of this file.
1 /* This file is part of Pazpar2.
2  Copyright (C) Index Data
3 
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
24 #if HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #if HAVE_SYS_TIME_H
31 #include <sys/time.h>
32 #endif
33 #if HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36 #ifdef WIN32
37 #include <windows.h>
38 #endif
39 #include <signal.h>
40 #include <assert.h>
41 
42 #include <yaz/marcdisp.h>
43 #include <yaz/comstack.h>
44 #include <yaz/tcpip.h>
45 #include <yaz/proto.h>
46 #include <yaz/readconf.h>
47 #include <yaz/pquery.h>
48 #include <yaz/otherinfo.h>
49 #include <yaz/yaz-util.h>
50 #include <yaz/nmem.h>
51 #include <yaz/query-charset.h>
52 #include <yaz/querytowrbuf.h>
53 #include <yaz/oid_db.h>
54 #include <yaz/diagbib1.h>
55 #include <yaz/snprintf.h>
56 #include <yaz/rpn2cql.h>
57 #include <yaz/rpn2solr.h>
58 #include <yaz/gettimeofday.h>
59 
60 #define USE_TIMING 0
61 #if USE_TIMING
62 #include <yaz/timing.h>
63 #endif
64 
65 #include "ppmutex.h"
66 #include "session.h"
67 #include "parameters.h"
68 #include "client.h"
69 #include "connection.h"
70 #include "settings.h"
71 #include "relevance.h"
72 #include "incref.h"
73 
74 #define XDOC_CACHE_SIZE 100
75 
76 static YAZ_MUTEX g_mutex = 0;
77 static int no_clients = 0;
78 
79 static int client_use(int delta)
80 {
81  int clients;
82  if (!g_mutex)
83  yaz_mutex_create(&g_mutex);
84  yaz_mutex_enter(g_mutex);
85  no_clients += delta;
86  clients = no_clients;
87  yaz_mutex_leave(g_mutex);
88  yaz_log(YLOG_DEBUG, "%s clients=%d",
89  delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), clients);
90  return clients;
91 }
92 
94 {
95  return client_use(0);
96 }
97 
99 struct client {
102  struct session *session;
103  char *pquery; // Current search
104  char *cqlquery; // used for SRU targets only
105  char *addinfo; // diagnostic info for most resent error
106  Odr_int hits;
109  int filtered; /* number of records ignored for local filtering */
110  int ingest_failures; /* number of records where XSLT/other failed */
111  int record_failures; /* number of records where ZOOM reported error */
112  int maxrecs;
115  char *message;
118  enum client_state state;
120  ZOOM_resultset resultset;
121  YAZ_MUTEX mutex;
123  char *id;
128  xmlDoc **xdoc;
129 };
130 
131 struct suggestions {
132  NMEM nmem;
133  int num;
134  char **misspelled;
135  char **suggest;
136  char *passthrough;
137 };
138 
139 struct show_raw {
140  int active; // whether this request has been sent to the server
141  int position;
142  int binary;
143  char *syntax;
144  char *esn;
146  void (*error_handler)(void *data, const char *addinfo);
147  void (*record_handler)(void *data, const char *buf, size_t sz);
148  void *data;
149  struct show_raw *next;
150 };
151 
152 static const char *client_states[] = {
153  "Client_Connecting",
154  "Client_Idle",
155  "Client_Working",
156  "Client_Error",
157  "Client_Failed",
158  "Client_Disconnected"
159 };
160 
161 const char *client_get_state_str(struct client *cl)
162 {
163  return client_states[cl->state];
164 }
165 
166 enum client_state client_get_state(struct client *cl)
167 {
168  return cl->state;
169 }
170 
171 void client_set_state_nb(struct client *cl, enum client_state st)
172 {
173  cl->state = st;
174 }
175 
176 void client_set_state(struct client *cl, enum client_state st)
177 {
178  int was_active = 0;
179  if (client_is_active(cl))
180  was_active = 1;
181  cl->state = st;
182  /* If client is going from being active to inactive and all clients
183  are now idle we fire a watch for the session . The assumption is
184  that session is not mutex locked if client is already active */
185  if (was_active && !client_is_active(cl) && cl->session)
186  {
187 
188  int no_active = session_active_clients(cl->session);
189  yaz_log(YLOG_DEBUG, "%s: releasing watches on zero active: %d",
190  client_get_id(cl), no_active);
191  if (no_active == 0) {
196  }
197  }
198 }
199 
200 static void client_init_xdoc(struct client *cl)
201 {
202  int i;
203 
204  cl->xdoc = xmalloc(sizeof(*cl->xdoc) * XDOC_CACHE_SIZE);
205  for (i = 0; i < XDOC_CACHE_SIZE; i++)
206  cl->xdoc[i] = 0;
207 }
208 
209 static void client_destroy_xdoc(struct client *cl)
210 {
211  int i;
212 
213  assert(cl->xdoc);
214  for (i = 0; i < XDOC_CACHE_SIZE; i++)
215  if (cl->xdoc[i])
216  xmlFreeDoc(cl->xdoc[i]);
217  xfree(cl->xdoc);
218 }
219 
220 xmlDoc *client_get_xdoc(struct client *cl, int record_no)
221 {
222  assert(cl->xdoc);
223  if (record_no >= 0 && record_no < XDOC_CACHE_SIZE)
224  return cl->xdoc[record_no];
225  return 0;
226 }
227 
228 void client_store_xdoc(struct client *cl, int record_no, xmlDoc *xdoc)
229 {
230  assert(cl->xdoc);
231  if (record_no >= 0 && record_no < XDOC_CACHE_SIZE)
232  {
233  if (cl->xdoc[record_no])
234  xmlFreeDoc(cl->xdoc[record_no]);
235  cl->xdoc[record_no] = xdoc;
236  }
237  else
238  {
239  xmlFreeDoc(xdoc);
240  }
241 }
242 
243 
244 static void client_show_raw_error(struct client *cl, const char *addinfo);
245 
247 {
248  return cl->connection;
249 }
250 
252 {
253  return cl->database;
254 }
255 
256 struct session *client_get_session(struct client *cl)
257 {
258  return cl->session;
259 }
260 
261 static void client_send_raw_present(struct client *cl);
262 static int nativesyntax_to_type(const char *s, char *type, ZOOM_record rec);
263 
265  ZOOM_resultset resultset, struct session_database *sdb, int position,
266  void *data,
267  void (*error_handler)(void *data, const char *addinfo),
268  void (*record_handler)(void *data, const char *buf, size_t sz),
269  int binary,
270  const char *nativesyntax)
271 {
272  ZOOM_record rec = 0;
273  char type[80];
274  const char *buf;
275  int len;
276 
277  if (!resultset)
278  {
279  error_handler(data, "no resultset");
280  return;
281  }
282  rec = ZOOM_resultset_record_immediate(resultset, position-1);
283  if (!rec)
284  {
285  error_handler(data, "no record");
286  return;
287  }
288  nativesyntax_to_type(nativesyntax, type, rec);
289  buf = ZOOM_record_get(rec, type, &len);
290  if (!buf)
291  {
292  error_handler(data, "no record");
293  return;
294  }
295  record_handler(data, buf, len);
296 }
297 
298 
299 int client_show_raw_begin(struct client *cl, int position,
300  const char *syntax, const char *esn,
301  void *data,
302  void (*error_handler)(void *data, const char *addinfo),
303  void (*record_handler)(void *data, const char *buf,
304  size_t sz),
305  int binary,
306  const char *nativesyntax)
307 {
308  if (!nativesyntax)
309  {
310  if (binary)
311  nativesyntax = "raw";
312  else
313  {
314  struct session_database *sdb = client_get_database(cl);
315  nativesyntax = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
316  }
317  }
318 
319  if (syntax == 0 && esn == 0)
321  position, data,
322  error_handler, record_handler,
323  binary, nativesyntax);
324  else
325  {
326  struct show_raw *rr, **rrp;
327 
328  if (!cl->connection)
329  return -1;
330 
331 
332  rr = xmalloc(sizeof(*rr));
333  rr->position = position;
334  rr->active = 0;
335  rr->data = data;
338  rr->binary = binary;
339  if (syntax)
340  rr->syntax = xstrdup(syntax);
341  else
342  rr->syntax = 0;
343  if (esn)
344  rr->esn = xstrdup(esn);
345  else
346  rr->esn = 0;
347 
348  assert(nativesyntax);
349  rr->nativesyntax = xstrdup(nativesyntax);
350 
351  rr->next = 0;
352 
353  for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
354  ;
355  *rrp = rr;
356 
357  if (cl->state == Client_Failed)
358  {
359  client_show_raw_error(cl, "client failed");
360  }
361  else if (cl->state == Client_Disconnected)
362  {
363  client_show_raw_error(cl, "client disconnected");
364  }
365  else
366  {
368  }
369  }
370  return 0;
371 }
372 
373 static void client_show_raw_delete(struct show_raw *r)
374 {
375  xfree(r->syntax);
376  xfree(r->esn);
377  xfree(r->nativesyntax);
378  xfree(r);
379 }
380 
381 void client_show_raw_remove(struct client *cl, void *data)
382 {
383  struct show_raw *rr = data;
384  struct show_raw **rrp = &cl->show_raw;
385  while (*rrp != rr)
386  rrp = &(*rrp)->next;
387  if (*rrp)
388  {
389  *rrp = rr->next;
391  }
392 }
393 
394 static void client_show_raw_dequeue(struct client *cl)
395 {
396  struct show_raw *rr = cl->show_raw;
397 
398  cl->show_raw = rr->next;
400 }
401 
402 static void client_show_raw_error(struct client *cl, const char *addinfo)
403 {
404  while (cl->show_raw)
405  {
406  cl->show_raw->error_handler(cl->show_raw->data, addinfo);
408  }
409 }
410 
411 static void client_send_raw_present(struct client *cl)
412 {
413  struct session_database *sdb = client_get_database(cl);
414  struct connection *co = client_get_connection(cl);
415  ZOOM_resultset set = cl->resultset;
416 
417  int offset = cl->show_raw->position;
418  const char *syntax = 0;
419  const char *elements = 0;
420 
421  assert(cl->show_raw);
422  assert(set);
423 
424  yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
425  client_get_id(cl), 1, offset);
426 
427  if (cl->show_raw->syntax)
428  syntax = cl->show_raw->syntax;
429  else
431  ZOOM_resultset_option_set(set, "preferredRecordSyntax", syntax);
432 
433  if (cl->show_raw->esn)
434  elements = cl->show_raw->esn;
435  else
436  elements = session_setting_oneval(sdb, PZ_ELEMENTS);
437  if (elements && *elements)
438  ZOOM_resultset_option_set(set, "elementSetName", elements);
439 
440  ZOOM_resultset_records(set, 0, offset-1, 1);
441  cl->show_raw->active = 1;
442 
444 }
445 
446 static int nativesyntax_to_type(const char *s, char *type,
447  ZOOM_record rec)
448 {
449  if (s && *s)
450  {
451  if (!strncmp(s, "iso2709", 7))
452  {
453  const char *cp = strchr(s, ';');
454  yaz_snprintf(type, 80, "xml; charset=%s", cp ? cp+1 : "marc-8s");
455  }
456  else if (!strncmp(s, "txml", 4))
457  {
458  const char *cp = strchr(s, ';');
459  yaz_snprintf(type, 80, "txml; charset=%s", cp ? cp+1 : "marc-8s");
460  }
461  else /* pass verbatim to ZOOM - including "xml" */
462  strcpy(type, s);
463  return 0;
464  }
465  else /* attempt to deduce structure */
466  {
467  const char *syntax = ZOOM_record_get(rec, "syntax", NULL);
468  if (syntax)
469  {
470  if (!strcmp(syntax, "XML"))
471  {
472  strcpy(type, "xml");
473  return 0;
474  }
475  else if (!strcmp(syntax, "USmarc") || !strcmp(syntax, "MARC21"))
476  {
477  strcpy(type, "xml; charset=marc8-s");
478  return 0;
479  }
480  else return -1;
481  }
482  else return -1;
483  }
484 }
485 
490 static void client_report_facets(struct client *cl, ZOOM_resultset rs)
491 {
492  struct session_database *sdb = client_get_database(cl);
493  ZOOM_facet_field *facets = ZOOM_resultset_facets(rs);
494 
495  if (sdb && facets)
496  {
497  struct session *se = client_get_session(cl);
498  int facet_num = ZOOM_resultset_facets_size(rs);
499  struct setting *s;
500 
501  for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next)
502  {
503  const char *p = strchr(s->name + 3, ':');
504  if (p && p[1] && s->value && s->value[0])
505  {
506  int facet_idx;
507  p++; /* p now holds logical facet name */
508  for (facet_idx = 0; facet_idx < facet_num; facet_idx++)
509  {
510  const char *native_name =
511  ZOOM_facet_field_name(facets[facet_idx]);
512  if (native_name && !strcmp(s->value, native_name))
513  {
514  size_t term_idx;
515  size_t term_num =
516  ZOOM_facet_field_term_count(facets[facet_idx]);
517  for (term_idx = 0; term_idx < term_num; term_idx++ )
518  {
519  int freq;
520  const char *term =
521  ZOOM_facet_field_get_term(facets[facet_idx],
522  term_idx, &freq);
523  if (term)
524  add_facet(se, p, term, freq, cl);
525  }
526  break;
527  }
528  }
529  }
530  }
531  }
532 }
533 
534 static void ingest_raw_record(struct client *cl, ZOOM_record rec)
535 {
536  const char *buf;
537  int len;
538  char type[80];
539 
540  nativesyntax_to_type(cl->show_raw->nativesyntax, type, rec);
541  buf = ZOOM_record_get(rec, type, &len);
542  cl->show_raw->record_handler(cl->show_raw->data, buf, len);
544 }
545 
546 struct suggestions* client_suggestions_create(const char* suggestions_string);
547 static void client_suggestions_destroy(struct client *cl);
548 
550 {
551  struct connection *co = cl->connection;
552  ZOOM_connection link = connection_get_link(co);
553  ZOOM_resultset resultset = cl->resultset;
554  struct session *se = client_get_session(cl);
555 
556  const char *error, *addinfo = 0;
557 
558  if (ZOOM_connection_error(link, &error, &addinfo))
559  {
560  cl->hits = 0;
561  session_log(se, YLOG_WARN, "%s: Error %s (%s)",
562  client_get_id(cl), error, addinfo);
564  }
565  else
566  {
567  client_report_facets(cl, resultset);
568  cl->record_offset = cl->startrecs;
569  cl->hits = ZOOM_resultset_size(resultset);
570  session_log(se, YLOG_LOG, "%s: hits: " ODR_INT_PRINTF,
571  client_get_id(cl), cl->hits);
572  if (cl->suggestions)
574  cl->suggestions =
575  client_suggestions_create(ZOOM_resultset_option_get(
576  resultset, "suggestions"));
577  }
578 }
579 
580 void client_got_records(struct client *cl)
581 {
582  struct session *se = cl->session;
583  if (se)
584  {
585  client_unlock(cl);
586  /* TODO possible threading issue. Session can have been destroyed */
589  client_lock(cl);
590  if (reclist_get_num_records(se->reclist) > 0)
591  {
592  client_unlock(cl);
597  client_lock(cl);
598  }
599  }
600 }
601 
602 static void client_record_ingest(struct client *cl)
603 {
604  const char *msg, *addinfo;
605  ZOOM_record rec = 0;
606  ZOOM_resultset resultset = cl->resultset;
607  struct session *se = client_get_session(cl);
608  xmlDoc *xdoc;
609  int offset = cl->record_offset + 1; /* 0 versus 1 numbered offsets */
610 
611  xdoc = client_get_xdoc(cl, offset);
612  if (xdoc)
613  {
614  if (cl->session)
615  {
616  NMEM nmem = nmem_create();
617  int rc = ingest_xml_record(cl, xdoc, offset, nmem, 1);
618  if (rc == -1)
619  {
620  session_log(se, YLOG_WARN,
621  "%s: #%d: failed to ingest xdoc",
622  client_get_id(cl), offset);
623  cl->ingest_failures++;
624  }
625  else if (rc == -2)
626  cl->filtered++;
627  nmem_destroy(nmem);
628  }
629  }
630  else if ((rec = ZOOM_resultset_record_immediate(resultset,
631  cl->record_offset)))
632  {
633  if (cl->session == 0)
634  ; /* no operation */
635  else if (ZOOM_record_error(rec, &msg, &addinfo, 0))
636  {
637  session_log(se, YLOG_WARN, "Record error %s (%s): %s #%d",
638  msg, addinfo, client_get_id(cl), offset);
639  cl->record_failures++;
640  }
641  else
642  {
643  struct session_database *sdb = client_get_database(cl);
644  NMEM nmem = nmem_create();
645  const char *xmlrec;
646  char type[80];
647 
648  const char *s = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
649  if (nativesyntax_to_type(s, type, rec))
650  session_log(se, YLOG_WARN, "Failed to determine record type");
651  xmlrec = ZOOM_record_get(rec, type, NULL);
652  if (!xmlrec)
653  {
654  const char *rec_syn = ZOOM_record_get(rec, "syntax", NULL);
655  session_log(se, YLOG_WARN, "%s: #%d: ZOOM_record_get failed",
656  client_get_id(cl), offset);
657  session_log(se, YLOG_LOG, "pz:nativesyntax=%s . "
658  "ZOOM record type=%s . Actual record syntax=%s",
659  s ? s : "null", type,
660  rec_syn ? rec_syn : "null");
661  cl->ingest_failures++;
662  }
663  else
664  {
665  /* OK = 0, -1 = failure, -2 = Filtered */
666  int rc = ingest_record(cl, xmlrec, offset, nmem);
667  if (rc == -1)
668  {
669  const char *rec_syn = ZOOM_record_get(rec, "syntax", NULL);
670  session_log(se, YLOG_WARN,
671  "%s: #%d: failed to ingest record",
672  client_get_id(cl), offset);
673  session_log(se, YLOG_LOG, "pz:nativesyntax=%s . "
674  "ZOOM record type=%s . Actual record syntax=%s",
675  s ? s : "null", type,
676  rec_syn ? rec_syn : "null");
677  cl->ingest_failures++;
678  }
679  else if (rc == -2)
680  cl->filtered++;
681  }
682  nmem_destroy(nmem);
683  }
684  }
685  else
686  {
687  session_log(se, YLOG_WARN, "Got NULL record from %s #%d",
688  client_get_id(cl), offset);
689  }
690  cl->record_offset++;
691 }
692 
693 void client_record_response(struct client *cl, int *got_records)
694 {
695  struct connection *co = cl->connection;
696  ZOOM_connection link = connection_get_link(co);
697  ZOOM_resultset resultset = cl->resultset;
698  const char *error, *addinfo;
699 
700  if (ZOOM_connection_error(link, &error, &addinfo))
701  {
702  struct session *se = client_get_session(cl);
703  session_log(se, YLOG_WARN, "%s: Error %s (%s)",
704  client_get_id(cl), error, addinfo);
706  }
707  else
708  {
709  if (cl->show_raw && cl->show_raw->active)
710  {
711  ZOOM_record rec = 0;
712  if ((rec = ZOOM_resultset_record_immediate(
713  resultset, cl->show_raw->position-1)))
714  {
715  cl->show_raw->active = 0;
716  ingest_raw_record(cl, rec);
717  }
718  else
719  {
720  yaz_log(YLOG_WARN, "Expected record, but got NULL, offset=%d",
721  cl->show_raw->position-1);
722  }
723  }
724  else
725  {
727  *got_records = 1;
728  }
729  }
730 }
731 
732 int client_reingest(struct client *cl)
733 {
734  int i = cl->startrecs;
735  int to = cl->record_offset;
736  cl->record_failures = cl->ingest_failures = cl->filtered = 0;
737 
738  cl->record_offset = i;
739  for (; i < to; i++)
741  return 0;
742 }
743 
744 static void client_set_facets_request(struct client *cl, ZOOM_connection link)
745 {
746  struct session_database *sdb = client_get_database(cl);
747 
748  WRBUF w = wrbuf_alloc();
749 
750  struct setting *s;
751 
752  for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next)
753  {
754  const char *p = strchr(s->name + 3, ':');
755  if (!p)
756  {
757  yaz_log(YLOG_WARN, "Malformed facetmap name: %s", s->name);
758  }
759  else if (s->value && s->value[0])
760  {
761  wrbuf_puts(w, "@attr 1=");
762  yaz_encode_pqf_term(w, s->value, strlen(s->value));
763  if (s->next)
764  wrbuf_puts(w, ",");
765  }
766  }
767  yaz_log(YLOG_DEBUG, "using facets str: %s", wrbuf_cstr(w));
768  ZOOM_connection_option_set(link, "facets",
769  wrbuf_len(w) ? wrbuf_cstr(w) : 0);
770  wrbuf_destroy(w);
771 }
772 
773 int client_has_facet(struct client *cl, const char *name)
774 {
775  struct session_database *sdb = client_get_database(cl);
776  struct setting *s;
777 
778  for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next)
779  {
780  const char *p = strchr(s->name + 3, ':');
781  if ( !strncmp(p, ":split:", 7) )
782  p += 6; // PAZ-1009
783  if (p && !strcmp(name, p + 1))
784  return 1;
785  }
786  return 0;
787 }
788 
789 static const char *get_strategy_plus_sort(struct client *l, const char *field)
790 {
791  struct session_database *sdb = client_get_database(l);
792  struct setting *s;
793 
794  const char *strategy_plus_sort = 0;
795 
796  for (s = sdb->settings[PZ_SORTMAP]; s; s = s->next)
797  {
798  char *p = strchr(s->name + 3, ':');
799  if (!p)
800  {
801  yaz_log(YLOG_WARN, "Malformed sortmap name: %s", s->name);
802  continue;
803  }
804  p++;
805  if (!strcmp(p, field))
806  {
807  strategy_plus_sort = s->value;
808  break;
809  }
810  }
811  return strategy_plus_sort;
812 }
813 
814 void client_update_show_stat(struct client *cl, int cmd)
815 {
816  if (cmd == 0)
817  cl->show_stat_no = 0;
818  else if (cmd == 1)
819  cl->show_stat_no++;
820 }
821 
822 int client_fetch_more(struct client *cl)
823 {
824  struct session_database *sdb = client_get_database(cl);
825  const char *str;
826  int extend_recs = 0;
827  int number = cl->hits - cl->record_offset;
828  struct connection *co = client_get_connection(cl);
829 
831  if (!str || !*str)
832  return 0;
833 
834  extend_recs = atoi(str);
835 
836  yaz_log(YLOG_DEBUG, "cl=%s show_stat_no=%d got=%d",
838  if (cl->show_stat_no + cl->ingest_failures + cl->record_failures
839  < cl->record_offset)
840  return 0;
841  yaz_log(YLOG_DEBUG, "cl=%s Trying to fetch more", client_get_id(cl));
842 
843  if (number > extend_recs)
844  number = extend_recs;
845  if (number <= 0)
846  yaz_log(YLOG_DEBUG, "cl=%s. OK no more in total set", client_get_id(cl));
847  else if (!co)
848  yaz_log(YLOG_DEBUG, "cl=%s. No connection", client_get_id(cl));
849  else
850  {
851  ZOOM_resultset set = cl->resultset;
852 
854  ZOOM_resultset_option_set(set, "preferredRecordSyntax", str);
856  if (str && *str)
857  ZOOM_resultset_option_set(set, "elementSetName", str);
858 
859  ZOOM_resultset_records(set, 0, cl->record_offset, number);
862  return 1;
863  }
864  return 0;
865 }
866 
867 int client_parse_init(struct client *cl, int same_search)
868 {
869  cl->same_search = same_search;
870  return 0;
871 }
872 
873 /*
874  * TODO consider how to extend the range
875  * */
876 int client_parse_range(struct client *cl, const char *startrecs,
877  const char *maxrecs)
878 {
879  if (maxrecs && atoi(maxrecs) != cl->maxrecs)
880  {
881  cl->same_search = 0;
882  cl->maxrecs = atoi(maxrecs);
883  }
884 
885  if (startrecs && atoi(startrecs) != cl->startrecs)
886  {
887  cl->same_search = 0;
888  cl->startrecs = atoi(startrecs);
889  }
890 
891  return 0;
892 }
893 
894 const char *client_get_query(struct client *cl, const char **type, NMEM nmem)
895 {
896  if (cl->pquery)
897  {
898  *type = "pqf";
899  return nmem_strdup(nmem, cl->pquery);
900  }
901  if (cl->cqlquery)
902  {
903  *type = "cql";
904  return nmem_strdup(nmem, cl->cqlquery);
905  }
906  *type = 0;
907  return 0;
908 }
909 
911 {
912  struct session_database *sdb = client_get_database(cl);
913  struct connection *co = 0;
914  ZOOM_connection link = 0;
915  struct session *se = client_get_session(cl);
916  ZOOM_resultset rs;
917  const char *opt_piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
918  const char *opt_queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
919  const char *opt_elements = session_setting_oneval(sdb, PZ_ELEMENTS);
920  const char *opt_requestsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
921  const char *opt_maxrecs = session_setting_oneval(sdb, PZ_MAXRECS);
922  const char *opt_sru = session_setting_oneval(sdb, PZ_SRU);
923  const char *opt_sort = session_setting_oneval(sdb, PZ_SORT);
924  const char *opt_preferred = session_setting_oneval(sdb, PZ_PREFERRED);
925  const char *extra_args = session_setting_oneval(sdb, PZ_EXTRA_ARGS);
926  const char *opt_present_chunk = session_setting_oneval(sdb, PZ_PRESENT_CHUNK);
927  const char *opt_timeout = session_setting_oneval(sdb, PZ_TIMEOUT);
928  ZOOM_query query;
929  char maxrecs_str[24], startrecs_str[24], present_chunk_str[24];
930  struct timeval tval;
931  int present_chunk = 20; // Default chunk size
932  int rc_prep_connection;
933  int operation_timeout = se->service->z3950_operation_timeout;
934 
935  cl->diagnostic = 0;
936  cl->record_failures = cl->ingest_failures = cl->filtered = 0;
937 
938  yaz_gettimeofday(&tval);
939  tval.tv_sec += 5;
940 
941  if (opt_timeout && *opt_timeout)
942  operation_timeout = atoi(opt_timeout);
943 
944  if (opt_present_chunk && strcmp(opt_present_chunk,"")) {
945  present_chunk = atoi(opt_present_chunk);
946  yaz_log(YLOG_DEBUG, "Present chunk set to %d", present_chunk);
947  }
948  rc_prep_connection =
949  client_prep_connection(cl, operation_timeout,
951  se->service->server->iochan_man,
952  &tval);
953  /* Nothing has changed and we already have a result */
954  if (cl->same_search == 1 && rc_prep_connection == 2)
955  {
956  session_log(se, YLOG_LOG, "%s: reuse result", client_get_id(cl));
958  return client_reingest(cl);
959  }
960  else if (!rc_prep_connection)
961  {
962  return -1; /* error */
963  }
964  co = client_get_connection(cl);
965  assert(cl);
966  link = connection_get_link(co);
967  assert(link);
968 
970  client_init_xdoc(cl);
971 
972  if (extra_args && *extra_args)
973  ZOOM_connection_option_set(link, "extraArgs", extra_args);
974 
975  if (opt_preferred) {
976  cl->preferred = atoi(opt_preferred);
977  if (cl->preferred)
978  yaz_log(YLOG_LOG, "Target %s has preferred status: %d",
979  client_get_id(cl), cl->preferred);
980  }
981 
982  if (*opt_piggyback)
983  ZOOM_connection_option_set(link, "piggyback", opt_piggyback);
984  else
985  ZOOM_connection_option_set(link, "piggyback", "1");
986  if (*opt_queryenc)
987  ZOOM_connection_option_set(link, "rpnCharset", opt_queryenc);
988  if (*opt_sru && *opt_elements)
989  ZOOM_connection_option_set(link, "schema", opt_elements);
990  else if (*opt_elements)
991  ZOOM_connection_option_set(link, "elementSetName", opt_elements);
992  if (*opt_requestsyn)
993  ZOOM_connection_option_set(link, "preferredRecordSyntax", opt_requestsyn);
994 
995  if (opt_maxrecs && *opt_maxrecs)
996  {
997  cl->maxrecs = atoi(opt_maxrecs);
998  }
999 
1000  /* convert back to string representation used in ZOOM API */
1001  sprintf(maxrecs_str, "%d", cl->maxrecs);
1002  ZOOM_connection_option_set(link, "count", maxrecs_str);
1003 
1004  /* A present_chunk less than 1 will disable chunking. */
1005  if (present_chunk > 0 && cl->maxrecs > present_chunk) {
1006  sprintf(present_chunk_str, "%d", present_chunk);
1007  ZOOM_connection_option_set(link, "presentChunk", present_chunk_str);
1008  yaz_log(YLOG_DEBUG, "Present chunk set to %s", present_chunk_str);
1009  }
1010  else {
1011  ZOOM_connection_option_set(link, "presentChunk", maxrecs_str);
1012  yaz_log(YLOG_DEBUG, "Present chunk set to %s (maxrecs)", maxrecs_str);
1013  }
1014  sprintf(startrecs_str, "%d", cl->startrecs);
1015  ZOOM_connection_option_set(link, "start", startrecs_str);
1016 
1017  /* TODO Verify does it break something for CQL targets(non-SOLR) ? */
1018  /* facets definition is in PQF */
1019  client_set_facets_request(cl, link);
1020 
1021  query = ZOOM_query_create();
1022  if (cl->cqlquery)
1023  {
1024  session_log(se, YLOG_LOG, "%s: Search CQL: %s", client_get_id(cl),
1025  cl->cqlquery);
1026  ZOOM_query_cql(query, cl->cqlquery);
1027  if (*opt_sort)
1028  ZOOM_query_sortby(query, opt_sort);
1029  }
1030  else
1031  {
1032  session_log(se, YLOG_LOG, "%s: Search PQF: %s", client_get_id(cl),
1033  cl->pquery);
1034  ZOOM_query_prefix(query, cl->pquery);
1035  }
1036  if (cl->sort_strategy && cl->sort_criteria) {
1037  yaz_log(YLOG_LOG, "Client %s: "
1038  "Set ZOOM sort strategy and criteria: %s %s",
1039  client_get_id(cl), cl->sort_strategy, cl->sort_criteria);
1040  ZOOM_query_sortby2(query, cl->sort_strategy, cl->sort_criteria);
1041  }
1042 
1043  yaz_log(YLOG_DEBUG,"Client %s: Starting search", client_get_id(cl));
1045  cl->hits = 0;
1046  cl->record_offset = 0;
1047  rs = ZOOM_connection_search(link, query);
1048  ZOOM_query_destroy(query);
1049  ZOOM_resultset_destroy(cl->resultset);
1050  cl->resultset = rs;
1051  connection_continue(co);
1052  return 0;
1053 }
1054 
1055 struct client *client_create(const char *id)
1056 {
1057  struct client *cl = xmalloc(sizeof(*cl));
1058  cl->maxrecs = 100;
1059  cl->startrecs = 0;
1060  cl->pquery = 0;
1061  cl->cqlquery = 0;
1062  cl->addinfo = 0;
1063  cl->message = 0;
1064  cl->database = 0;
1065  cl->connection = 0;
1066  cl->session = 0;
1067  cl->hits = 0;
1068  cl->record_offset = 0;
1069  cl->filtered = 0;
1070  cl->diagnostic = 0;
1071  cl->state = Client_Disconnected;
1072  cl->show_raw = 0;
1073  cl->resultset = 0;
1074  cl->suggestions = 0;
1075  cl->mutex = 0;
1076  pazpar2_mutex_create(&cl->mutex, "client");
1077  cl->preferred = 0;
1078  cl->ref_count = 1;
1079  cl->facet_limits = 0;
1080  cl->sort_strategy = 0;
1081  cl->sort_criteria = 0;
1082  assert(id);
1083  cl->id = xstrdup(id);
1084  client_init_xdoc(cl);
1085  client_use(1);
1086 
1087  yaz_log(YLOG_DEBUG, "client_create c=%p %s", cl, id);
1088  return cl;
1089 }
1090 
1091 void client_lock(struct client *c)
1092 {
1093  yaz_mutex_enter(c->mutex);
1094 }
1095 
1096 void client_unlock(struct client *c)
1097 {
1098  yaz_mutex_leave(c->mutex);
1099 }
1100 
1101 void client_incref(struct client *c)
1102 {
1103  pazpar2_incref(&c->ref_count, c->mutex);
1104  yaz_log(YLOG_DEBUG, "client_incref c=%p %s cnt=%d",
1105  c, client_get_id(c), c->ref_count);
1106 }
1107 
1108 int client_destroy(struct client *c)
1109 {
1110  if (c)
1111  {
1112  yaz_log(YLOG_DEBUG, "client_destroy c=%p %s cnt=%d",
1113  c, client_get_id(c), c->ref_count);
1114  if (!pazpar2_decref(&c->ref_count, c->mutex))
1115  {
1116  xfree(c->pquery);
1117  c->pquery = 0;
1118  xfree(c->cqlquery);
1119  c->cqlquery = 0;
1120  xfree(c->addinfo);
1121  c->addinfo = 0;
1122  xfree(c->message);
1123  c->message = 0;
1124  xfree(c->id);
1125  xfree(c->sort_strategy);
1126  xfree(c->sort_criteria);
1127  assert(!c->connection);
1129 
1131  if (c->resultset)
1132  {
1133  ZOOM_resultset_destroy(c->resultset);
1134  }
1135  yaz_mutex_destroy(&c->mutex);
1136  xfree(c);
1137  client_use(-1);
1138  return 1;
1139  }
1140  }
1141  return 0;
1142 }
1143 
1144 void client_set_connection(struct client *cl, struct connection *con)
1145 {
1146  if (cl->resultset)
1147  ZOOM_resultset_release(cl->resultset);
1148  if (con)
1149  {
1150  assert(cl->connection == 0);
1151  cl->connection = con;
1152  client_incref(cl);
1153  }
1154  else
1155  {
1156  client_lock(cl);
1157  cl->connection = con;
1158  client_unlock(cl);
1159  client_destroy(cl);
1160  }
1161 }
1162 
1163 void client_disconnect(struct client *cl)
1164 {
1165  if (cl->state != Client_Idle)
1167  client_set_connection(cl, 0);
1168 }
1169 
1170 void client_mark_dead(struct client *cl)
1171 {
1172  if (cl->connection)
1174 }
1175 
1176 void client_stop(struct client *cl)
1177 {
1178  client_lock(cl);
1179  if (cl->state == Client_Working || cl->state == Client_Connecting)
1180  {
1181  yaz_log(YLOG_LOG, "client_stop: %s release", client_get_id(cl));
1182  if (cl->connection)
1183  {
1185  assert(cl->ref_count > 1);
1186  cl->ref_count--;
1187  cl->connection = 0;
1188  }
1189  cl->state = Client_Disconnected;
1190  }
1191  else
1192  yaz_log(YLOG_LOG, "client_stop: %s ignore", client_get_id(cl));
1193  client_unlock(cl);
1194 }
1195 
1196 // Initialize CCL map for a target
1197 static CCL_bibset prepare_cclmap(struct client *cl, CCL_bibset base_bibset)
1198 {
1199  struct session_database *sdb = client_get_database(cl);
1200  struct setting *s;
1201  CCL_bibset res;
1202 
1203  if (!sdb->settings)
1204  return 0;
1205  if (base_bibset)
1206  res = ccl_qual_dup(base_bibset);
1207  else
1208  res = ccl_qual_mk();
1209  for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
1210  {
1211  const char *addinfo = 0;
1212  char *p = strchr(s->name + 3, ':');
1213  if (!p)
1214  {
1215  WRBUF w = wrbuf_alloc();
1216  wrbuf_printf(w, "Malformed cclmap. name=%s", s->name);
1217  yaz_log(YLOG_WARN, "%s: %s", client_get_id(cl), wrbuf_cstr(w));
1218  client_set_diagnostic(cl, ZOOM_ERROR_CCL_CONFIG,
1219  ZOOM_diag_str(ZOOM_ERROR_CCL_CONFIG),
1220  wrbuf_cstr(w));
1222  ccl_qual_rm(&res);
1223  wrbuf_destroy(w);
1224  return 0;
1225  }
1226  p++;
1227  if (ccl_qual_fitem2(res, s->value, p, &addinfo))
1228  {
1229  WRBUF w = wrbuf_alloc();
1230 
1231  wrbuf_printf(w, "Malformed cclmap. name=%s: value=%s (%s)",
1232  s->name, p, addinfo);
1233  yaz_log(YLOG_WARN, "%s: %s", client_get_id(cl), wrbuf_cstr(w));
1234  client_set_diagnostic(cl, ZOOM_ERROR_CCL_CONFIG,
1235  ZOOM_diag_str(ZOOM_ERROR_CCL_CONFIG),
1236  wrbuf_cstr(w));
1238  ccl_qual_rm(&res);
1239  wrbuf_destroy(w);
1240  return 0;
1241  }
1242  }
1243  return res;
1244 }
1245 
1246 // returns a xmalloced CQL query corresponding to the pquery in client
1247 static char *make_cqlquery(struct client *cl, Z_RPNQuery *zquery)
1248 {
1249  cql_transform_t cqlt = cql_transform_create();
1250  char *r = 0;
1251  WRBUF wrb = wrbuf_alloc();
1252  int status;
1253 
1254  if ((status = cql_transform_rpn2cql_wrbuf(cqlt, wrb, zquery)))
1255  {
1256  yaz_log(YLOG_WARN, "Failed to generate CQL query, code=%d", status);
1257  }
1258  else
1259  {
1260  r = xstrdup(wrbuf_cstr(wrb));
1261  }
1262  wrbuf_destroy(wrb);
1263  cql_transform_close(cqlt);
1264  return r;
1265 }
1266 
1267 // returns a xmalloced SOLR query corresponding to the pquery in client
1268 // TODO Could prob. be merge with the similar make_cqlquery
1269 static char *make_solrquery(struct client *cl, Z_RPNQuery *zquery)
1270 {
1271  solr_transform_t sqlt = solr_transform_create();
1272  char *r = 0;
1273  WRBUF wrb = wrbuf_alloc();
1274  int status;
1275 
1276  if ((status = solr_transform_rpn2solr_wrbuf(sqlt, wrb, zquery)))
1277  {
1278  yaz_log(YLOG_WARN, "Failed to generate SOLR query, code=%d", status);
1279  }
1280  else
1281  {
1282  r = xstrdup(wrbuf_cstr(wrb));
1283  }
1284  wrbuf_destroy(wrb);
1285  solr_transform_close(sqlt);
1286  return r;
1287 }
1288 
1289 const char *client_get_facet_limit_local(struct client *cl,
1290  struct session_database *sdb,
1291  int *l,
1292  NMEM nmem, int *num, char ***values)
1293 {
1294  const char *name = 0;
1295  const char *value = 0;
1296  for (; (name = facet_limits_get(cl->facet_limits, *l, &value)); (*l)++)
1297  {
1298  struct setting *s = 0;
1299 
1300  for (s = sdb->settings[PZ_LIMITMAP]; s; s = s->next)
1301  {
1302  const char *p = strchr(s->name + 3, ':');
1303  if (p && !strcmp(p + 1, name) && s->value)
1304  {
1305  int j, cnum;
1306  char **cvalues;
1307  nmem_strsplit_escape2(nmem, ",", s->value, &cvalues,
1308  &cnum, 1, '\\', 1);
1309  for (j = 0; j < cnum; j++)
1310  {
1311  const char *cvalue = cvalues[j];
1312  while (*cvalue == ' ')
1313  cvalue++;
1314  if (!strncmp(cvalue, "local:", 6))
1315  {
1316  const char *cp = cvalue + 6;
1317  while (*cp == ' ')
1318  cp++;
1319  nmem_strsplit_escape2(nmem, "|", value, values,
1320  num, 1, '\\', 1);
1321  (*l)++;
1322  return *cp ? cp : name;
1323  }
1324  }
1325  }
1326  }
1327  }
1328  return 0;
1329 }
1330 
1331 static void ccl_quote_map_term(CCL_bibset ccl_map, WRBUF w,
1332  const char *term)
1333 {
1334  int quote_it = 0;
1335  const char *cp;
1336  for (cp = term; *cp; cp++)
1337  if ((*cp >= '0' && *cp <= '9') || strchr(" +-", *cp))
1338  ;
1339  else
1340  quote_it = 1;
1341  if (!quote_it)
1342  wrbuf_puts(w, term);
1343  else
1344  {
1345  wrbuf_putc(w, '\"');
1346  for (cp = term; *cp; cp++)
1347  {
1348  if (strchr( "\\\"", *cp))
1349  wrbuf_putc(w, '\\');
1350  wrbuf_putc(w, *cp);
1351  }
1352  wrbuf_putc(w, '\"');
1353  }
1354 }
1355 
1356 static int apply_limit(struct client *cl,
1358  WRBUF w_pqf, CCL_bibset ccl_map,
1359  struct conf_service *service)
1360 {
1361  int ret = 0;
1362  int i = 0;
1363  const char *name;
1364  const char *value;
1365  struct session_database *sdb = client_get_database(cl);
1366 
1367  NMEM nmem_tmp = nmem_create();
1368  for (i = 0; (name = facet_limits_get(facet_limits, i, &value)); i++)
1369  {
1370  struct setting *s = 0;
1371  nmem_reset(nmem_tmp);
1372  /* name="pz:limitmap:author" value="rpn:@attr 1=4|local:other" */
1373  for (s = sdb->settings[PZ_LIMITMAP]; s; s = s->next)
1374  {
1375  const char *p = strchr(s->name + 3, ':');
1376  if (p && !strcmp(p + 1, name) && s->value)
1377  {
1378  char **values = 0;
1379  int i, num = 0;
1380  char **cvalues = 0;
1381  int j, cnum = 0;
1382  nmem_strsplit_escape2(nmem_tmp, "|", value, &values,
1383  &num, 1, '\\', 1);
1384 
1385  for (i = 0; i < num; i++)
1386  {
1387  const char *id = session_lookup_id_facet(cl->session,
1388  cl, name,
1389  values[i]);
1390  if (id)
1391  {
1392  if ( *id )
1393  {
1394  values[i] = nmem_strdup(nmem_tmp, id);
1395  yaz_log(YLOG_DEBUG,
1396  "apply_limit: s='%s' found id '%s'",s->name,id );
1397  }
1398  else
1399  {
1400  yaz_log(YLOG_DEBUG,
1401  "apply_limit: %s: term '%s' not found, failing client",
1402  s->name, values[i] );
1403  ret = -1;
1404  }
1405  }
1406  }
1407  nmem_strsplit_escape2(nmem_tmp, ",", s->value, &cvalues,
1408  &cnum, 1, '\\', 1);
1409 
1410  for (j = 0; ret == 0 && j < cnum; j++)
1411  {
1412  const char *cvalue = cvalues[j];
1413  while (*cvalue == ' ')
1414  cvalue++;
1415  if (!strncmp(cvalue, "rpn:", 4))
1416  {
1417  const char *pqf = cvalue + 4;
1418  wrbuf_puts(w_pqf, "@and ");
1419  wrbuf_puts(w_pqf, pqf);
1420  wrbuf_puts(w_pqf, " ");
1421  for (i = 0; i < num; i++)
1422  {
1423  if (i < num - 1)
1424  wrbuf_puts(w_pqf, "@or ");
1425  yaz_encode_pqf_term(w_pqf, values[i],
1426  strlen(values[i]));
1427  }
1428  }
1429  else if (!strncmp(cvalue, "ccl:", 4))
1430  {
1431  const char *ccl = cvalue + 4;
1432  WRBUF ccl_w = wrbuf_alloc();
1433  for (i = 0; i < num; i++)
1434  {
1435  int cerror, cpos;
1436  struct ccl_rpn_node *cn;
1437  wrbuf_rewind(ccl_w);
1438  wrbuf_puts(ccl_w, ccl);
1439  wrbuf_putc(ccl_w, '=');
1440  ccl_quote_map_term(ccl_map, ccl_w, values[i]);
1441  cn = ccl_find_str(ccl_map, wrbuf_cstr(ccl_w),
1442  &cerror, &cpos);
1443  if (cn)
1444  {
1445  if (i == 0)
1446  wrbuf_printf(w_pqf, "@and ");
1447 
1448  /* or multiple values.. could be bad if last
1449  CCL parse fails, but this is unlikely to
1450  happen */
1451  if (i < num - 1)
1452  wrbuf_printf(w_pqf, "@or ");
1453  ccl_pquery(w_pqf, cn);
1454  ccl_rpn_delete(cn);
1455  }
1456  }
1457  wrbuf_destroy(ccl_w);
1458  }
1459  else if (!strncmp(cvalue, "local:", 6)) {
1460  /* no operation */
1461  }
1462  else
1463  {
1464  yaz_log(YLOG_WARN, "Target %s: Bad limitmap '%s'",
1465  sdb->database->id, cvalue);
1466  ret = -1; /* bad limitmap */
1467  }
1468  }
1469  break;
1470  }
1471  }
1472  if (!s)
1473  {
1474  int i;
1475  for (i = 0; i < service->num_metadata; i++)
1476  {
1477  struct conf_metadata *md = service->metadata + i;
1478  if (!strcmp(md->name, name) && md->limitcluster)
1479  {
1480  yaz_log(YLOG_LOG, "limitcluster in use for %s",
1481  md->name);
1482  break;
1483  }
1484  }
1485  if (i == service->num_metadata)
1486  {
1487  yaz_log(YLOG_WARN, "Target %s: limit %s used, but no limitmap defined",
1488  (sdb->database ? sdb->database->id : "<no id>"), name);
1489  }
1490  }
1491  }
1492  nmem_destroy(nmem_tmp);
1493  return ret;
1494 }
1495 
1496 // Parse the query given the settings specific to this client
1497 // client variable same_search is set as below as well as returned:
1498 // 0 if query is OK but different from before
1499 // 1 if query is OK but same as before
1500 // return -1 on query error
1501 // return -2 on limit error
1502 int client_parse_query(struct client *cl, const char *query,
1503  facet_limits_t facet_limits, const char **error_msg)
1504 {
1505  struct session *se = client_get_session(cl);
1506  struct conf_service *service = se->service;
1507  struct session_database *sdb = client_get_database(cl);
1508  struct ccl_rpn_node *cn;
1509  int cerror, cpos;
1510  ODR odr_out;
1511  CCL_bibset ccl_map = prepare_cclmap(cl, service->ccl_bibset);
1512  const char *sru = session_setting_oneval(sdb, PZ_SRU);
1513  const char *pqf_prefix = session_setting_oneval(sdb, PZ_PQF_PREFIX);
1514  const char *pqf_strftime = session_setting_oneval(sdb, PZ_PQF_STRFTIME);
1515  const char *query_syntax = session_setting_oneval(sdb, PZ_QUERY_SYNTAX);
1516  WRBUF w_ccl, w_pqf;
1517  int ret_value = 1;
1518  Z_RPNQuery *zquery;
1519 
1520  if (!ccl_map)
1521  return -3;
1522 
1523  xfree(cl->cqlquery);
1524  cl->cqlquery = 0;
1525 
1526  w_ccl = wrbuf_alloc();
1527  wrbuf_puts(w_ccl, query);
1528 
1529  w_pqf = wrbuf_alloc();
1530  if (*pqf_prefix)
1531  {
1532  wrbuf_puts(w_pqf, pqf_prefix);
1533  wrbuf_puts(w_pqf, " ");
1534  }
1535 
1536  if (apply_limit(cl, facet_limits, w_pqf, ccl_map, service))
1537  {
1539  ccl_qual_rm(&ccl_map);
1540 
1541  wrbuf_destroy(w_ccl);
1542  wrbuf_destroy(w_pqf);
1543 
1544  xfree(cl->pquery);
1545  cl->pquery = 0;
1546 
1547  return -2;
1548  }
1549 
1552 
1553  cn = ccl_find_str(ccl_map, wrbuf_cstr(w_ccl), &cerror, &cpos);
1554  ccl_qual_rm(&ccl_map);
1555  if (!cn)
1556  {
1557  if (error_msg)
1558  *error_msg = ccl_err_msg(cerror);
1560  session_log(se, YLOG_WARN, "Client %s: Failed to parse CCL query '%s'",
1561  client_get_id(cl),
1562  wrbuf_cstr(w_ccl));
1563  wrbuf_destroy(w_ccl);
1564  wrbuf_destroy(w_pqf);
1565 
1566  xfree(cl->pquery);
1567  cl->pquery = 0;
1568 
1569  return -1;
1570  }
1571  wrbuf_destroy(w_ccl);
1572 
1573  if (!pqf_strftime || !*pqf_strftime)
1574  ccl_pquery(w_pqf, cn);
1575  else
1576  {
1577  time_t cur_time = time(0);
1578  struct tm *tm = localtime(&cur_time);
1579  char tmp_str[300];
1580  const char *cp = tmp_str;
1581 
1582  /* see man strftime(3) for things .. In particular %% gets converted
1583  to %.. And That's our original query .. */
1584  strftime(tmp_str, sizeof(tmp_str)-1, pqf_strftime, tm);
1585  for (; *cp; cp++)
1586  {
1587  if (cp[0] == '%')
1588  ccl_pquery(w_pqf, cn);
1589  else
1590  wrbuf_putc(w_pqf, cp[0]);
1591  }
1592  }
1593 
1594  /* Compares query and limit with old one. If different we need to research */
1595  if (!cl->pquery || strcmp(cl->pquery, wrbuf_cstr(w_pqf)))
1596  {
1597  if (cl->pquery)
1598  session_log(se, YLOG_LOG, "Client %s: "
1599  "Re-search due query/limit change: %s to %s",
1600  client_get_id(cl), cl->pquery, wrbuf_cstr(w_pqf));
1601  xfree(cl->pquery);
1602  cl->pquery = xstrdup(wrbuf_cstr(w_pqf));
1603  // return value is no longer used.
1604  ret_value = 0;
1605  // Need to (re)search
1606  cl->same_search= 0;
1607  }
1608  wrbuf_destroy(w_pqf);
1609 
1610  odr_out = odr_createmem(ODR_ENCODE);
1611  zquery = p_query_rpn(odr_out, cl->pquery);
1612  if (!zquery)
1613  {
1614  session_log(se, YLOG_WARN, "Invalid PQF query for Client %s: %s",
1615  client_get_id(cl), cl->pquery);
1616  ret_value = -1;
1617  *error_msg = "Invalid PQF after CCL to PQF conversion";
1618  }
1619  else
1620  {
1621  /* Support for PQF on SRU targets. */
1622  if (strcmp(query_syntax, "pqf") != 0 && *sru)
1623  {
1624  if (!strcmp(sru, "solr"))
1625  cl->cqlquery = make_solrquery(cl, zquery);
1626  else
1627  cl->cqlquery = make_cqlquery(cl, zquery);
1628  if (!cl->cqlquery)
1629  {
1630  *error_msg = "Cannot convert PQF to Solr/CQL";
1631  ret_value = -1;
1632  }
1633  else
1634  session_log(se, YLOG_LOG, "Client %s native query: %s (%s)",
1635  client_get_id(cl), cl->cqlquery, sru);
1636  }
1637  }
1638  odr_destroy(odr_out);
1639 
1640  /* TODO FIX Not thread safe */
1641  if (!se->relevance)
1642  {
1643  // Initialize relevance structure with query terms
1645  se->service->rank_cluster,
1646  se->service->rank_follow,
1647  se->service->rank_lead,
1648  se->service->rank_length);
1649  }
1650  ccl_rpn_delete(cn);
1651  return ret_value;
1652 }
1653 
1654 int client_parse_sort(struct client *cl, struct reclist_sortparms *sp,
1655  int *has_sortmap)
1656 {
1657  if (has_sortmap)
1658  *has_sortmap = 0;
1659  if (sp)
1660  {
1661  const char *sort_strategy_and_spec =
1662  get_strategy_plus_sort(cl, sp->name);
1663  int increasing = sp->increasing;
1664  if (!strcmp(sp->name, "relevance"))
1665  increasing = 1;
1666  if (sort_strategy_and_spec && strlen(sort_strategy_and_spec) < 40)
1667  {
1668  char strategy[50], *p;
1669  strcpy(strategy, sort_strategy_and_spec);
1670  p = strchr(strategy, ':');
1671  if (p)
1672  {
1673  // Split the string in two
1674  *p++ = 0;
1675  while (*p == ' ')
1676  p++;
1677  if (increasing)
1678  strcat(p, " <");
1679  else
1680  strcat(p, " >");
1681  yaz_log(YLOG_LOG, "Client %s: "
1682  "applying sorting %s %s", client_get_id(cl),
1683  strategy, p);
1684  if (!cl->sort_strategy || strcmp(cl->sort_strategy, strategy))
1685  cl->same_search = 0;
1686  if (!cl->sort_criteria || strcmp(cl->sort_criteria, p))
1687  cl->same_search = 0;
1688  if (cl->same_search == 0) {
1689  xfree(cl->sort_strategy);
1690  cl->sort_strategy = xstrdup(strategy);
1691  xfree(cl->sort_criteria);
1692  cl->sort_criteria = xstrdup(p);
1693  }
1694  if (has_sortmap)
1695  (*has_sortmap)++;
1696  }
1697  else {
1698  yaz_log(YLOG_LOG, "Client %s: "
1699  "Invalid sort strategy and spec found %s",
1700  client_get_id(cl), sort_strategy_and_spec);
1701  xfree(cl->sort_strategy);
1702  cl->sort_strategy = 0;
1703  xfree(cl->sort_criteria);
1704  cl->sort_criteria = 0;
1705  }
1706  }
1707  else
1708  {
1709  yaz_log(YLOG_DEBUG, "Client %s: "
1710  "No sort strategy and spec found.", client_get_id(cl));
1711  xfree(cl->sort_strategy);
1712  cl->sort_strategy = 0;
1713  xfree(cl->sort_criteria);
1714  cl->sort_criteria = 0;
1715  }
1716 
1717  }
1718  return !cl->same_search;
1719 }
1720 
1721 void client_set_session(struct client *cl, struct session *se)
1722 {
1723  cl->session = se;
1724 }
1725 
1726 int client_is_active(struct client *cl)
1727 {
1728  if (cl->connection && (cl->state == Client_Connecting ||
1729  cl->state == Client_Working))
1730  return 1;
1731  return 0;
1732 }
1733 
1735 {
1736  /* only count if this is a preferred target. */
1737  if (!cl->preferred)
1738  return 0;
1739  /* TODO No sure this the condition that Seb wants */
1740  if (cl->connection && (cl->state == Client_Connecting ||
1741  cl->state == Client_Working))
1742  return 1;
1743  return 0;
1744 }
1745 
1746 Odr_int client_get_hits(struct client *cl)
1747 {
1748  return cl->hits;
1749 }
1750 
1752 {
1753  if (cl->record_offset > 0)
1754  {
1755  Odr_int approx = ((10 * cl->hits * (cl->record_offset - cl->filtered))
1756  / cl->record_offset + 5) /10;
1757  yaz_log(YLOG_DEBUG, "%s: Approx: %lld * %d / %d = %lld ",
1758  client_get_id(cl), cl->hits,
1759  cl->record_offset - cl->filtered, cl->record_offset, approx);
1760  return approx;
1761  }
1762  return cl->hits;
1763 }
1764 
1765 int client_get_num_records(struct client *cl, int *filtered, int *ingest,
1766  int *failed)
1767 {
1768  if (filtered)
1769  *filtered = cl->filtered;
1770  if (ingest)
1771  *ingest = cl->ingest_failures;
1772  if (failed)
1773  *failed = cl->record_failures;
1774  return cl->record_offset;
1775 }
1776 
1777 void client_set_diagnostic(struct client *cl, int diagnostic,
1778  const char *message, const char *addinfo)
1779 {
1780  cl->diagnostic = diagnostic;
1781  xfree(cl->message);
1782  cl->message = xstrdup(message);
1783  xfree(cl->addinfo);
1784  cl->addinfo = 0;
1785  if (addinfo)
1786  cl->addinfo = xstrdup(addinfo);
1787 }
1788 
1789 int client_get_diagnostic(struct client *cl, const char **message,
1790  const char **addinfo)
1791 {
1792  if (message)
1793  *message = cl->message;
1794  if (addinfo)
1795  *addinfo = cl->addinfo;
1796  return cl->diagnostic;
1797 }
1798 
1799 const char *client_get_suggestions_xml(struct client *cl, WRBUF wrbuf)
1800 {
1801  /* int idx; */
1802  struct suggestions *suggestions = cl->suggestions;
1803 
1804  if (!suggestions)
1805  return "";
1806  if (suggestions->passthrough)
1807  {
1808  yaz_log(YLOG_DEBUG, "Passthrough Suggestions: \n%s\n",
1810  return suggestions->passthrough;
1811  }
1812  if (suggestions->num == 0)
1813  return "";
1814  /*
1815  for (idx = 0; idx < suggestions->num; idx++) {
1816  wrbuf_printf(wrbuf, "<suggest term=\"%s\"", suggestions->suggest[idx]);
1817  if (suggestions->misspelled[idx] && suggestions->misspelled[idx]) {
1818  wrbuf_puts(wrbuf, suggestions->misspelled[idx]);
1819  wrbuf_puts(wrbuf, "</suggest>\n");
1820  }
1821  else
1822  wrbuf_puts(wrbuf, "/>\n");
1823  }
1824  */
1825  return wrbuf_cstr(wrbuf);
1826 }
1827 
1828 void client_set_database(struct client *cl, struct session_database *db)
1829 {
1830  cl->database = db;
1831 }
1832 
1833 const char *client_get_id(struct client *cl)
1834 {
1835  return cl->id;
1836 }
1837 
1839 {
1840  return cl->maxrecs;
1841 }
1842 
1843 void client_set_preferred(struct client *cl, int v)
1844 {
1845  cl->preferred = v;
1846 }
1847 
1848 
1849 struct suggestions* client_suggestions_create(const char* suggestions_string)
1850 {
1851  int i;
1852  NMEM nmem;
1853  struct suggestions *suggestions;
1854  if (suggestions_string == 0 || suggestions_string[0] == 0 )
1855  return 0;
1856  nmem = nmem_create();
1857  suggestions = nmem_malloc(nmem, sizeof(*suggestions));
1858  yaz_log(YLOG_DEBUG, "client target suggestions: %s.", suggestions_string);
1859 
1860  suggestions->nmem = nmem;
1861  suggestions->num = 0;
1862  suggestions->misspelled = 0;
1863  suggestions->suggest = 0;
1864  suggestions->passthrough = nmem_strdup_null(nmem, suggestions_string);
1865 
1866  if (suggestions_string)
1867  nmem_strsplit_escape2(suggestions->nmem, "\n", suggestions_string, &suggestions->suggest,
1868  &suggestions->num, 1, '\\', 0);
1869  /* Set up misspelled array */
1870  suggestions->misspelled = (char **)
1871  nmem_malloc(nmem, suggestions->num * sizeof(*suggestions->misspelled));
1872  /* replace = with \0 .. for each item */
1873  for (i = 0; i < suggestions->num; i++)
1874  {
1875  char *cp = strchr(suggestions->suggest[i], '=');
1876  if (cp) {
1877  *cp = '\0';
1878  suggestions->misspelled[i] = cp+1;
1879  }
1880  }
1881  return suggestions;
1882 }
1883 
1884 static void client_suggestions_destroy(struct client *cl)
1885 {
1886  NMEM nmem = cl->suggestions->nmem;
1887  cl->suggestions = 0;
1888  nmem_destroy(nmem);
1889 }
1890 
1891 /*
1892  * Local variables:
1893  * c-basic-offset: 4
1894  * c-file-style: "Stroustrup"
1895  * indent-tabs-mode: nil
1896  * End:
1897  * vim: shiftwidth=4 tabstop=8 expandtab
1898  */
1899 
int client_get_diagnostic(struct client *cl, const char **message, const char **addinfo)
Definition: client.c:1789
static void client_show_raw_error(struct client *cl, const char *addinfo)
Definition: client.c:402
void client_got_records(struct client *cl)
Definition: client.c:580
void client_unlock(struct client *c)
Definition: client.c:1096
void client_store_xdoc(struct client *cl, int record_no, xmlDoc *xdoc)
Definition: client.c:228
int clients_get_count(void)
Definition: client.c:93
int client_parse_query(struct client *cl, const char *query, facet_limits_t facet_limits, const char **error_msg)
Definition: client.c:1502
static int nativesyntax_to_type(const char *s, char *type, ZOOM_record rec)
Definition: client.c:446
static int no_clients
Definition: client.c:77
void client_set_database(struct client *cl, struct session_database *db)
Definition: client.c:1828
void client_update_show_stat(struct client *cl, int cmd)
Definition: client.c:814
void client_set_connection(struct client *cl, struct connection *con)
Definition: client.c:1144
static const char * get_strategy_plus_sort(struct client *l, const char *field)
Definition: client.c:789
static void client_show_raw_delete(struct show_raw *r)
Definition: client.c:373
void client_stop(struct client *cl)
Definition: client.c:1176
int client_parse_sort(struct client *cl, struct reclist_sortparms *sp, int *has_sortmap)
Definition: client.c:1654
void client_set_state_nb(struct client *cl, enum client_state st)
Definition: client.c:171
static void client_show_immediate(ZOOM_resultset resultset, struct session_database *sdb, int position, void *data, void(*error_handler)(void *data, const char *addinfo), void(*record_handler)(void *data, const char *buf, size_t sz), int binary, const char *nativesyntax)
Definition: client.c:264
static int client_use(int delta)
Definition: client.c:79
Odr_int client_get_hits(struct client *cl)
Definition: client.c:1746
void client_set_diagnostic(struct client *cl, int diagnostic, const char *message, const char *addinfo)
Definition: client.c:1777
static YAZ_MUTEX g_mutex
Definition: client.c:76
int client_fetch_more(struct client *cl)
Definition: client.c:822
static char * make_solrquery(struct client *cl, Z_RPNQuery *zquery)
Definition: client.c:1269
const char * client_get_state_str(struct client *cl)
Definition: client.c:161
void client_search_response(struct client *cl)
Definition: client.c:549
#define XDOC_CACHE_SIZE
Definition: client.c:74
struct suggestions * client_suggestions_create(const char *suggestions_string)
Definition: client.c:1849
void client_incref(struct client *c)
Definition: client.c:1101
int client_is_active_preferred(struct client *cl)
Definition: client.c:1734
void client_lock(struct client *c)
Definition: client.c:1091
const char * client_get_id(struct client *cl)
Definition: client.c:1833
static void client_init_xdoc(struct client *cl)
Definition: client.c:200
const char * client_get_facet_limit_local(struct client *cl, struct session_database *sdb, int *l, NMEM nmem, int *num, char ***values)
Definition: client.c:1289
int client_show_raw_begin(struct client *cl, int position, const char *syntax, const char *esn, void *data, void(*error_handler)(void *data, const char *addinfo), void(*record_handler)(void *data, const char *buf, size_t sz), int binary, const char *nativesyntax)
Definition: client.c:299
Odr_int client_get_approximation(struct client *cl)
Definition: client.c:1751
static void ccl_quote_map_term(CCL_bibset ccl_map, WRBUF w, const char *term)
Definition: client.c:1331
void client_set_state(struct client *cl, enum client_state st)
Definition: client.c:176
struct connection * client_get_connection(struct client *cl)
Definition: client.c:246
void client_set_session(struct client *cl, struct session *se)
Definition: client.c:1721
static CCL_bibset prepare_cclmap(struct client *cl, CCL_bibset base_bibset)
Definition: client.c:1197
int client_reingest(struct client *cl)
Definition: client.c:732
struct client * client_create(const char *id)
Definition: client.c:1055
static void client_destroy_xdoc(struct client *cl)
Definition: client.c:209
int client_start_search(struct client *cl)
Definition: client.c:910
static void client_report_facets(struct client *cl, ZOOM_resultset rs)
Definition: client.c:490
struct session * client_get_session(struct client *cl)
Definition: client.c:256
static const char * client_states[]
Definition: client.c:152
int client_get_maxrecs(struct client *cl)
Definition: client.c:1838
int client_has_facet(struct client *cl, const char *name)
Definition: client.c:773
void client_show_raw_remove(struct client *cl, void *data)
Definition: client.c:381
int client_parse_range(struct client *cl, const char *startrecs, const char *maxrecs)
Definition: client.c:876
void client_mark_dead(struct client *cl)
Definition: client.c:1170
static void client_send_raw_present(struct client *cl)
Definition: client.c:411
xmlDoc * client_get_xdoc(struct client *cl, int record_no)
Definition: client.c:220
static char * make_cqlquery(struct client *cl, Z_RPNQuery *zquery)
Definition: client.c:1247
enum client_state client_get_state(struct client *cl)
Definition: client.c:166
static void ingest_raw_record(struct client *cl, ZOOM_record rec)
Definition: client.c:534
static int apply_limit(struct client *cl, facet_limits_t facet_limits, WRBUF w_pqf, CCL_bibset ccl_map, struct conf_service *service)
Definition: client.c:1356
static void client_record_ingest(struct client *cl)
Definition: client.c:602
int client_is_active(struct client *cl)
Definition: client.c:1726
int client_parse_init(struct client *cl, int same_search)
Definition: client.c:867
const char * client_get_suggestions_xml(struct client *cl, WRBUF wrbuf)
Definition: client.c:1799
int client_destroy(struct client *c)
Definition: client.c:1108
static void client_suggestions_destroy(struct client *cl)
Definition: client.c:1884
static void client_set_facets_request(struct client *cl, ZOOM_connection link)
Definition: client.c:744
void client_record_response(struct client *cl, int *got_records)
Definition: client.c:693
const char * client_get_query(struct client *cl, const char **type, NMEM nmem)
Definition: client.c:894
struct session_database * client_get_database(struct client *cl)
Definition: client.c:251
int client_get_num_records(struct client *cl, int *filtered, int *ingest, int *failed)
Definition: client.c:1765
void client_disconnect(struct client *cl)
Definition: client.c:1163
void client_set_preferred(struct client *cl, int v)
Definition: client.c:1843
static void client_show_raw_dequeue(struct client *cl)
Definition: client.c:394
Z39.50 client.
client_state
Definition: client.h:34
@ Client_Disconnected
Definition: client.h:40
@ Client_Working
Definition: client.h:37
@ Client_Idle
Definition: client.h:36
@ Client_Failed
Definition: client.h:39
@ Client_Error
Definition: client.h:38
@ Client_Connecting
Definition: client.h:35
int client_prep_connection(struct client *cl, int operation_timeout, int session_timeout, iochan_man_t iochan, const struct timeval *abstime)
Definition: connection.c:471
ZOOM_connection connection_get_link(struct connection *co)
Definition: connection.c:106
void connection_continue(struct connection *co)
Definition: connection.c:266
void connection_mark_dead(struct connection *co)
Definition: connection.c:111
void connection_release2(struct connection *co)
Definition: connection.c:323
Z39.50 connection (low-level client)
const char * facet_limits_get(facet_limits_t fl, int idx, const char **value)
Definition: facet_limit.c:94
void facet_limits_destroy(facet_limits_t fl)
Definition: facet_limit.c:102
facet_limits_t facet_limits_dup(facet_limits_t fl)
Definition: facet_limit.c:42
char * name
static void error(struct http_response *rs, enum pazpar2_error_code code, const char *addinfo)
Definition: http_command.c:273
int pazpar2_decref(int *ref, YAZ_MUTEX mutex)
Definition: incref.c:38
void pazpar2_incref(int *ref, YAZ_MUTEX mutex)
Definition: incref.c:30
MUTEX protect ref counts.
void pazpar2_mutex_create(YAZ_MUTEX *p, const char *name)
Definition: ppmutex.c:39
control MUTEX debugging
int reclist_get_num_records(struct reclist *l)
Definition: reclists.c:400
struct relevance * relevance_create_ccl(pp2_charset_fact_t pft, struct ccl_rpn_node *query, int rank_cluster, double follow_factor, double lead_decay, int length_divide)
Definition: relevance.c:540
const char * session_setting_oneval(struct session_database *db, int offset)
Definition: session.c:433
void session_alert_watch(struct session *s, int what)
Definition: session.c:521
int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem)
ingest XML record
Definition: session.c:1874
int ingest_xml_record(struct client *cl, xmlDoc *xdoc, int record_no, NMEM nmem, int cached_copy)
Definition: session.c:1886
void add_facet(struct session *s, const char *type, const char *value, int count, struct client *cl)
Definition: session.c:254
void session_log(struct session *s, int level, const char *fmt,...)
Definition: session.c:2509
int session_active_clients(struct session *s)
Definition: session.c:637
const char * session_lookup_id_facet(struct session *s, struct client *cl, const char *type, const char *term)
Definition: session.c:234
int session_is_preferred_clients_ready(struct session *s)
Definition: session.c:649
#define SESSION_WATCH_BYTARGET
Definition: session.h:71
#define SESSION_WATCH_TERMLIST
Definition: session.h:70
#define SESSION_WATCH_SHOW
Definition: session.h:67
#define SESSION_WATCH_SHOW_PREF
Definition: session.h:69
#define SESSION_WATCH_RECORD
Definition: session.h:68
#define PZ_NATIVESYNTAX
Definition: settings.h:28
#define PZ_SORTMAP
Definition: settings.h:54
#define PZ_QUERY_SYNTAX
Definition: settings.h:50
#define PZ_FACETMAP
Definition: settings.h:51
#define PZ_PQF_PREFIX
Definition: settings.h:39
#define PZ_PQF_STRFTIME
Definition: settings.h:42
#define PZ_REQUESTSYNTAX
Definition: settings.h:25
#define PZ_LIMITMAP
Definition: settings.h:52
#define PZ_EXTENDRECS
Definition: settings.h:57
#define PZ_MAXRECS
Definition: settings.h:31
#define PZ_TIMEOUT
Definition: settings.h:62
#define PZ_PIGGYBACK
Definition: settings.h:23
#define PZ_SRU
Definition: settings.h:37
#define PZ_PRESENT_CHUNK
Definition: settings.h:55
#define PZ_EXTRA_ARGS
Definition: settings.h:49
#define PZ_CCLMAP
Definition: settings.h:26
#define PZ_ELEMENTS
Definition: settings.h:24
#define PZ_QUERYENCODING
Definition: settings.h:34
#define PZ_PREFERRED
Definition: settings.h:48
#define PZ_SORT
Definition: settings.h:40
Represents client state for a connection to one search target.
Definition: client.c:99
YAZ_MUTEX mutex
Definition: client.c:121
int diagnostic
Definition: client.c:114
int preferred
Definition: client.c:116
int filtered
Definition: client.c:109
ZOOM_resultset resultset
Definition: client.c:120
int same_search
Definition: client.c:125
int maxrecs
Definition: client.c:112
char * pquery
Definition: client.c:103
char * sort_strategy
Definition: client.c:126
char * cqlquery
Definition: client.c:104
struct show_raw * show_raw
Definition: client.c:119
facet_limits_t facet_limits
Definition: client.c:124
int ingest_failures
Definition: client.c:110
struct session_database * database
Definition: client.c:100
char * message
Definition: client.c:115
struct session * session
Definition: client.c:102
struct suggestions * suggestions
Definition: client.c:117
int startrecs
Definition: client.c:113
char * addinfo
Definition: client.c:105
xmlDoc ** xdoc
Definition: client.c:128
char * id
Definition: client.c:123
char * sort_criteria
Definition: client.c:127
int ref_count
Definition: client.c:122
int show_stat_no
Definition: client.c:108
struct connection * connection
Definition: client.c:101
Odr_int hits
Definition: client.c:106
int record_failures
Definition: client.c:111
int record_offset
Definition: client.c:107
enum client_state state
Definition: client.c:118
char * limitcluster
iochan_man_t iochan_man
int z3950_operation_timeout
pp2_charset_fact_t charsets
double rank_follow
struct conf_server * server
int z3950_session_timeout
struct conf_metadata * metadata
CCL_bibset ccl_bibset
Represents a physical, reusable connection to a remote Z39.50 host.
Definition: connection.c:88
ZOOM_connection link
Definition: connection.c:90
char * id
Definition: settings.h:76
struct database * database
Definition: session.h:60
struct setting ** settings
Definition: session.h:62
NMEM nmem
Definition: session.h:98
struct reclist * reclist
Definition: session.h:101
struct conf_service * service
Definition: session.h:93
struct relevance * relevance
Definition: session.h:100
const char * name
Definition: settings.h:69
const char * value
Definition: settings.h:70
struct setting * next
Definition: settings.h:71
char * syntax
Definition: client.c:143
char * nativesyntax
Definition: client.c:145
char * esn
Definition: client.c:144
int binary
Definition: client.c:142
struct show_raw * next
Definition: client.c:149
void * data
Definition: client.c:148
void(* error_handler)(void *data, const char *addinfo)
Definition: client.c:146
int position
Definition: client.c:141
void(* record_handler)(void *data, const char *buf, size_t sz)
Definition: client.c:147
int active
Definition: client.c:140
char * passthrough
Definition: client.c:136
char ** misspelled
Definition: client.c:134
NMEM nmem
Definition: client.c:132
char ** suggest
Definition: client.c:135
int num
Definition: client.c:133