YAZ  5.27.0
zoom-z3950.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <assert.h>
14 #include <string.h>
15 #include <errno.h>
16 #include "zoom-p.h"
17 
18 #include <yaz/yaz-util.h>
19 #include <yaz/xmalloc.h>
20 #include <yaz/otherinfo.h>
21 #include <yaz/log.h>
22 #include <yaz/pquery.h>
23 #include <yaz/marcdisp.h>
24 #include <yaz/diagbib1.h>
25 #include <yaz/charneg.h>
26 #include <yaz/ill.h>
27 #include <yaz/query-charset.h>
28 #include <yaz/copy_types.h>
29 #include <yaz/snprintf.h>
30 #include <yaz/facet.h>
31 
32 #include <yaz/shptr.h>
33 
34 /*
35  * This wrapper is just for logging failed lookups. It would be nicer
36  * if it could cause failure when a lookup fails, but that's hard.
37  */
39  oid_class oid_class, const char *str)
40 {
41  Odr_oid *res = yaz_string_to_oid_odr(yaz_oid_std(), oid_class, str,
42  c->odr_out);
43  if (res == 0)
44  yaz_log(YLOG_WARN, "%p OID lookup (%d, '%s') failed",
45  c, (int) oid_class, str);
46  return res;
47 }
48 
50 {
51  const char *str;
54 
55  str = ZOOM_options_get(p->options, "package-name");
56  if (str && *str)
57  req->packageName = odr_strdup(p->odr_out, str);
58 
59  str = ZOOM_options_get(p->options, "user-id");
60  if (str)
61  req->userId = odr_strdup_null(p->odr_out, str);
62 
63  req->packageType = odr_oiddup(p->odr_out, oid);
64 
65  str = ZOOM_options_get(p->options, "function");
66  if (str)
67  {
68  if (!strcmp (str, "create"))
70  if (!strcmp (str, "delete"))
72  if (!strcmp (str, "modify"))
74  }
75 
76  str = ZOOM_options_get(p->options, "waitAction");
77  if (str)
78  {
79  if (!strcmp (str, "wait"))
81  if (!strcmp (str, "waitIfPossible"))
83  if (!strcmp (str, "dontWait"))
85  if (!strcmp (str, "dontReturnPackage"))
87  }
88  return apdu;
89 }
90 
91 static const char *ill_array_lookup(void *clientData, const char *idx)
92 {
93  ZOOM_package p = (ZOOM_package) clientData;
94  return ZOOM_options_get(p->options, idx+4);
95 }
96 
98 {
99  ODR out = p->odr_out;
100  ILL_Request *req;
101  Z_External *r = 0;
102  struct ill_get_ctl ctl;
103 
104  ctl.odr = p->odr_out;
105  ctl.clientData = p;
106  ctl.f = ill_array_lookup;
107 
108  req = ill_get_ILLRequest(&ctl, "ill", 0);
109 
110  if (!ill_Request(out, &req, 0, 0))
111  {
112  int ill_request_size;
113  char *ill_request_buf = odr_getbuf(out, &ill_request_size, 0);
114  if (ill_request_buf)
115  odr_setbuf(out, ill_request_buf, ill_request_size, 1);
116  return 0;
117  }
118  else
119  {
120  int illRequest_size = 0;
121  char *illRequest_buf = odr_getbuf(out, &illRequest_size, 0);
122 
123  r = (Z_External *) odr_malloc(out, sizeof(*r));
125  r->indirect_reference = 0;
126  r->descriptor = 0;
128 
129  r->u.single_ASN1_type =
130  odr_create_Odr_oct(out, illRequest_buf, illRequest_size);
131  }
132  return r;
133 }
134 
136 {
137  Z_ItemOrder *req = (Z_ItemOrder *) odr_malloc(p->odr_out, sizeof(*req));
138  const char *str;
139  int len;
140 
142  req->u.esRequest = (Z_IORequest *)
143  odr_malloc(p->odr_out,sizeof(Z_IORequest));
144 
145  /* to keep part ... */
148  req->u.esRequest->toKeep->supplDescription = 0;
149  req->u.esRequest->toKeep->contact = (Z_IOContact *)
150  odr_malloc(p->odr_out, sizeof(*req->u.esRequest->toKeep->contact));
151 
152  str = ZOOM_options_get(p->options, "contact-name");
153  req->u.esRequest->toKeep->contact->name =
154  odr_strdup_null(p->odr_out, str);
155 
156  str = ZOOM_options_get(p->options, "contact-phone");
157  req->u.esRequest->toKeep->contact->phone =
158  odr_strdup_null(p->odr_out, str);
159 
160  str = ZOOM_options_get(p->options, "contact-email");
161  req->u.esRequest->toKeep->contact->email =
162  odr_strdup_null(p->odr_out, str);
163 
164  req->u.esRequest->toKeep->addlBilling = 0;
165 
166  /* not to keep part ... */
169 
170  str = ZOOM_options_get(p->options, "itemorder-setname");
171  if (!str)
172  str = "default";
173 
174  if (!*str)
175  req->u.esRequest->notToKeep->resultSetItem = 0;
176  else
177  {
179  odr_malloc(p->odr_out, sizeof(Z_IOResultSetItem));
180 
182  odr_strdup(p->odr_out, str);
184  odr_intdup(p->odr_out, 0);
185 
186  str = ZOOM_options_get(p->options, "itemorder-item");
188  (str ? atoi(str) : 1);
189  }
190 
191  str = ZOOM_options_getl(p->options, "doc", &len);
192  if (str)
193  {
195  z_ext_record_xml(p->odr_out, str, len);
196  }
197  else
199 
200  return req;
201 }
202 
204  Z_ESAdminOriginPartToKeep **toKeepP,
205  Z_ESAdminOriginPartNotToKeep **notToKeepP)
206 {
208  if (apdu)
209  {
211  Z_ESAdminOriginPartNotToKeep *notToKeep;
212  Z_External *r = (Z_External *) odr_malloc(p->odr_out, sizeof(*r));
213  const char *first_db = "Default";
214  int num_db;
216  p->options, &num_db,
217  p->odr_out);
218  if (num_db > 0)
219  first_db = db[0];
220 
222  r->descriptor = 0;
223  r->indirect_reference = 0;
225 
226  r->u.adminService = (Z_Admin *)
227  odr_malloc(p->odr_out, sizeof(*r->u.adminService));
230  odr_malloc(p->odr_out, sizeof(*r->u.adminService->u.esRequest));
231 
232  toKeep = r->u.adminService->u.esRequest->toKeep =
234  odr_malloc(p->odr_out, sizeof(*r->u.adminService->u.esRequest->toKeep));
235  toKeep->which = type;
236  toKeep->databaseName = odr_strdup(p->odr_out, first_db);
237  toKeep->u.create = odr_nullval();
239 
240  r->u.adminService->u.esRequest->notToKeep = notToKeep =
242  odr_malloc(p->odr_out,
243  sizeof(*r->u.adminService->u.esRequest->notToKeep));
245  notToKeep->u.recordsWillFollow = odr_nullval();
246  if (toKeepP)
247  *toKeepP = toKeep;
248  if (notToKeepP)
249  *notToKeepP = notToKeep;
250  }
251  return apdu;
252 }
253 
255 {
258  Z_External *ext = (Z_External *) odr_malloc(p->odr_out, sizeof(*ext));
259  int len;
260  const char *doc = ZOOM_options_getl(p->options, "doc", &len);
261 
262  if (!doc)
263  {
264  doc = "";
265  len = 0;
266  }
267 
268  req->taskSpecificParameters = ext;
269  ext->direct_reference = req->packageType;
270  ext->descriptor = 0;
271  ext->indirect_reference = 0;
272 
273  ext->which = Z_External_octet;
274  ext->u.single_ASN1_type = odr_create_Odr_oct(p->odr_out, doc, len);
275  return apdu;
276 }
277 
279 {
280  Z_APDU *apdu = 0;
281  const char *first_db = "Default";
282  int num_db;
284  &num_db, p->odr_out);
285  const char *action = ZOOM_options_get(p->options, "action");
286  int recordIdOpaque_len;
287  const char *recordIdOpaque = ZOOM_options_getl(p->options, "recordIdOpaque",
288  &recordIdOpaque_len);
289  const char *recordIdNumber = ZOOM_options_get(p->options, "recordIdNumber");
290  const char *recordIdString = ZOOM_options_get(p->options, "recordIdString");
291  int record_len;
292  const char *record_buf = ZOOM_options_getl(p->options, "record",
293  &record_len);
294  int recordOpaque_len;
295  const char *recordOpaque_buf = ZOOM_options_getl(p->options, "recordOpaque",
296  &recordOpaque_len);
297  const char *syntax_str = ZOOM_options_get(p->options, "syntax");
298  const char *version = ZOOM_options_get(p->options, "updateVersion");
299 
300  const char *correlationInfo_note =
301  ZOOM_options_get(p->options, "correlationInfo.note");
302  const char *correlationInfo_id =
303  ZOOM_options_get(p->options, "correlationInfo.id");
304  int action_no = -1;
305  Odr_oid *syntax_oid = 0;
306  const Odr_oid *package_oid = yaz_oid_extserv_database_update;
307 
308  if (!version)
309  version = "3";
310  if (!syntax_str)
311  syntax_str = "xml";
312  if (!record_buf && !recordOpaque_buf)
313  {
314  record_buf = "void";
315  record_len = 4;
316  syntax_str = "SUTRS";
317  }
318 
319  if (syntax_str)
320  {
321  syntax_oid = yaz_string_to_oid_odr(yaz_oid_std(),
322  CLASS_RECSYN, syntax_str,
323  p->odr_out);
324  }
325  if (!syntax_oid)
326  {
328  return 0;
329  }
330 
331  if (num_db > 0)
332  first_db = db[0];
333 
334  switch (*version)
335  {
336  case '1':
338  /* old update does not support specialUpdate */
339  if (!action)
340  action = "recordInsert";
341  break;
342  case '2':
343  if (!action)
344  action = "specialUpdate";
346  break;
347  case '3':
348  if (!action)
349  action = "specialUpdate";
350  package_oid = yaz_oid_extserv_database_update;
351  break;
352  default:
354  return 0;
355  }
356 
357  if (!strcmp(action, "recordInsert"))
359  else if (!strcmp(action, "recordReplace"))
361  else if (!strcmp(action, "recordDelete"))
363  else if (!strcmp(action, "elementUpdate"))
365  else if (!strcmp(action, "specialUpdate"))
367  else
368  {
370  return 0;
371  }
372 
373  apdu = create_es_package(p, package_oid);
374  if (apdu)
375  {
376  Z_IUOriginPartToKeep *toKeep;
377  Z_IUSuppliedRecords *notToKeep;
378  Z_External *r = (Z_External *)
379  odr_malloc(p->odr_out, sizeof(*r));
380  const char *elementSetName =
381  ZOOM_options_get(p->options, "elementSetName");
382 
384 
385  r->direct_reference = odr_oiddup(p->odr_out, package_oid);
386  r->descriptor = 0;
388  r->indirect_reference = 0;
389  r->u.update = (Z_IUUpdate *)
390  odr_malloc(p->odr_out, sizeof(*r->u.update));
391 
394  odr_malloc(p->odr_out, sizeof(*r->u.update->u.esRequest));
395  toKeep = r->u.update->u.esRequest->toKeep =
397  odr_malloc(p->odr_out, sizeof(*toKeep));
398 
399  toKeep->databaseName = odr_strdup(p->odr_out, first_db);
400  toKeep->schema = 0;
401 
402  toKeep->elementSetName = odr_strdup_null(p->odr_out, elementSetName);
403 
404  toKeep->actionQualifier = 0;
405  toKeep->action = odr_intdup(p->odr_out, action_no);
406 
407  notToKeep = r->u.update->u.esRequest->notToKeep =
409  odr_malloc(p->odr_out, sizeof(*notToKeep));
410  notToKeep->num = 1;
411  notToKeep->elements = (Z_IUSuppliedRecords_elem **)
412  odr_malloc(p->odr_out, sizeof(*notToKeep->elements));
413  notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
414  odr_malloc(p->odr_out, sizeof(**notToKeep->elements));
416  if (recordIdOpaque)
417  {
418  notToKeep->elements[0]->u.opaque =
419  odr_create_Odr_oct(p->odr_out, recordIdOpaque,
420  recordIdOpaque_len);
421  }
422  else if (recordIdNumber)
423  {
425 
426  notToKeep->elements[0]->u.number =
427  odr_intdup(p->odr_out, atoi(recordIdNumber));
428  }
429  else if (recordIdString)
430  {
432  notToKeep->elements[0]->u.string = odr_strdup(p->odr_out,
433  recordIdString);
434  }
435  else
436  notToKeep->elements[0]->u.opaque = 0;
437  notToKeep->elements[0]->supplementalId = 0;
438  if (correlationInfo_note || correlationInfo_id)
439  {
441  ci = notToKeep->elements[0]->correlationInfo =
442  (Z_IUCorrelationInfo *) odr_malloc(p->odr_out, sizeof(*ci));
443  ci->note = odr_strdup_null(p->odr_out, correlationInfo_note);
444  ci->id = correlationInfo_id ?
445  odr_intdup(p->odr_out, atoi(correlationInfo_id)) : 0;
446  }
447  else
448  notToKeep->elements[0]->correlationInfo = 0;
449  if (recordOpaque_buf)
450  {
451  notToKeep->elements[0]->record =
452  z_ext_record_oid_any(p->odr_out, syntax_oid,
453  recordOpaque_buf, recordOpaque_len);
454  }
455  else
456  {
457  notToKeep->elements[0]->record =
458  z_ext_record_oid(p->odr_out, syntax_oid,
459  record_buf, record_len);
460  }
461  }
462  if (0 && apdu)
463  {
464  ODR print = odr_createmem(ODR_PRINT);
465 
466  z_APDU(print, &apdu, 0, 0);
467  odr_destroy(print);
468  }
469  return apdu;
470 }
471 
472 
474 {
475  int i;
476  for (i = 0; i < 200; i++)
477  {
478  size_t len;
479  Odr_oid *oid;
480  Z_OtherInformation **oi;
481  char buf[80];
482  const char *val;
483  const char *cp;
484 
485  sprintf(buf, "otherInfo%d", i);
486  val = ZOOM_options_get(c->options, buf);
487  if (!val)
488  break;
489  cp = strchr(val, ':');
490  if (!cp)
491  continue;
492  len = cp - val;
493  if (len >= sizeof(buf))
494  len = sizeof(buf)-1;
495  memcpy(buf, val, len);
496  buf[len] = '\0';
497 
499  buf, out);
500  if (!oid)
501  continue;
502 
503  yaz_oi_APDU(a, &oi);
504  yaz_oi_set_string_oid(oi, out, oid, 1, cp+1);
505  }
506 }
507 
508 
509 
510 static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out)
511 {
512  assert(a);
513  if (c->cookie_out)
514  {
515  Z_OtherInformation **oi;
516  yaz_oi_APDU(a, &oi);
518  1, c->cookie_out);
519  }
520  if (c->client_IP && a->which == Z_APDU_initRequest)
521  {
522  Z_OtherInformation **oi;
523  yaz_oi_APDU(a, &oi);
525  1, c->client_IP);
526  }
527  otherInfo_attach(c, a, out);
528  if (!z_APDU(out, &a, 0, 0))
529  {
530  FILE *outf = fopen("/tmp/apdu.txt", "a");
531  if (a && outf)
532  {
533  ODR odr_pr = odr_createmem(ODR_PRINT);
534  fprintf(outf, "a=%p\n", a);
535  odr_setprint(odr_pr, outf);
536  z_APDU(odr_pr, &a, 0, 0);
537  odr_destroy(odr_pr);
538  }
539  yaz_log(c->log_api, "%p encoding_APDU: encoding failed", c);
541  odr_reset(out);
542  return -1;
543  }
544  if (c->odr_print)
545  z_APDU(c->odr_print, &a, 0, 0);
546  if (c->odr_save)
547  z_APDU(c->odr_save, &a, 0, 0);
548  yaz_log(c->log_details, "%p encoding_APDU encoding OK", c);
549  return 0;
550 }
551 
553 {
554  ZOOM_Event event;
555  assert(a);
556  if (encode_APDU(c, a, c->odr_out))
557  return zoom_complete;
558  yaz_log(c->log_details, "%p send APDU type=%d", c, a->which);
559  c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
561  ZOOM_connection_put_event(c, event);
562  odr_reset(c->odr_out);
563  return ZOOM_send_buf(c);
564 }
565 
567 {
569  Z_InitRequest *ireq = apdu->u.initRequest;
571  odr_malloc(c->odr_out, sizeof(*auth));
572 
579 
583 
584  ireq->implementationId =
585  odr_prepend(c->odr_out,
586  ZOOM_options_get(c->options, "implementationId"),
587  ireq->implementationId);
588 
589  ireq->implementationName =
590  odr_prepend(c->odr_out,
591  ZOOM_options_get(c->options, "implementationName"),
592  odr_prepend(c->odr_out, "ZOOM-C",
593  ireq->implementationName));
594 
595  ireq->implementationVersion =
596  odr_prepend(c->odr_out,
597  ZOOM_options_get(c->options, "implementationVersion"),
598  ireq->implementationVersion);
599 
602 
603  if (c->group || c->password)
604  {
605  Z_IdPass *pass = (Z_IdPass *) odr_malloc(c->odr_out, sizeof(*pass));
606  pass->groupId = odr_strdup_null(c->odr_out, c->group);
607  pass->userId = odr_strdup_null(c->odr_out, c->user);
608  pass->password = odr_strdup_null(c->odr_out, c->password);
610  auth->u.idPass = pass;
611  ireq->idAuthentication = auth;
612  }
613  else if (c->user)
614  {
616  auth->u.open = odr_strdup(c->odr_out, c->user);
617  ireq->idAuthentication = auth;
618  }
619  if (c->proxy_mode)
620  {
623  }
624  if (c->charset || c->lang)
625  {
626  Z_OtherInformation **oi;
627  Z_OtherInformationUnit *oi_unit;
628 
629  yaz_oi_APDU(apdu, &oi);
630 
631  if ((oi_unit = yaz_oi_update(oi, c->odr_out, NULL, 0, 0)))
632  {
637  c->charset, c->lang, 1);
638  }
639  }
640  assert(apdu);
641  return send_APDU(c, apdu);
642 }
643 
645 {
646  ZOOM_resultset r;
647  int lslb, ssub, mspn;
648  const char *syntax;
649  const char *schema;
650  Z_APDU *apdu;
651  Z_SearchRequest *search_req;
652  const char *elementSetName;
653  const char *smallSetElementSetName;
654  const char *mediumSetElementSetName;
655 
656  assert(c->tasks);
657  assert(c->tasks->which == ZOOM_TASK_SEARCH);
658  r = c->tasks->u.search.resultset;
659 
661  search_req = apdu->u.searchRequest;
662 
663  yaz_log(c->log_details, "%p Z3950_send_search set=%p", c, r);
664 
665  elementSetName = c->tasks->u.search.elementSetName;
666  smallSetElementSetName =
667  ZOOM_options_get(r->options, "smallSetElementSetName");
668  mediumSetElementSetName =
669  ZOOM_options_get(r->options, "mediumSetElementSetName");
670 
671  if (!smallSetElementSetName)
672  smallSetElementSetName = elementSetName;
673 
674  if (!mediumSetElementSetName)
675  mediumSetElementSetName = elementSetName;
676 
677  if (r->req_facets)
678  {
679  Z_FacetList *facet_list =
681  if (facet_list)
682  {
683  Z_OtherInformation **oi = &search_req->additionalSearchInfo;
684  yaz_oi_set_facetlist(oi, c->odr_out, facet_list);
685  }
686  else
687  yaz_log(YLOG_WARN, "Unable to parse facets: %s", r->req_facets);
688  }
689 
690  assert(r);
691  assert(r->query);
692 
693  /* prepare query for the search request */
694  search_req->query = ZOOM_query_get_Z_Query(r->query);
695  if (!search_req->query)
696  {
698  return zoom_complete;
699  }
700  if (search_req->query->which == Z_Query_type_1 ||
701  search_req->query->which == Z_Query_type_101)
702  {
703  const char *cp = ZOOM_options_get(r->options, "rpnCharset");
704  if (cp)
705  {
706  yaz_iconv_t cd = yaz_iconv_open(cp, "UTF-8");
707  if (cd)
708  {
709  int r;
710  search_req->query = yaz_copy_Z_Query(search_req->query,
711  c->odr_out);
712 
714  search_req->query->u.type_1,
715  c->odr_out, cd);
716  yaz_iconv_close(cd);
717  if (r)
718  { /* query could not be char converted */
720  return zoom_complete;
721  }
722  }
723  }
724  }
725  search_req->databaseNames = r->databaseNames;
726  search_req->num_databaseNames = r->num_databaseNames;
727 
728  /* get syntax (no need to provide unless piggyback is in effect) */
729  syntax = c->tasks->u.search.syntax;
730 
731  schema = c->tasks->u.search.schema;
732 
733  lslb = ZOOM_options_get_int(r->options, "largeSetLowerBound", -1);
734  ssub = ZOOM_options_get_int(r->options, "smallSetUpperBound", -1);
735  mspn = ZOOM_options_get_int(r->options, "mediumSetPresentNumber", -1);
736  if (lslb != -1 && ssub != -1 && mspn != -1)
737  {
738  /* So're a Z39.50 expert? Let's hope you don't do sort */
739  *search_req->largeSetLowerBound = lslb;
740  *search_req->smallSetUpperBound = ssub;
741  *search_req->mediumSetPresentNumber = mspn;
742  }
743  else if (c->tasks->u.search.start == 0 && c->tasks->u.search.count > 0
744  && r->piggyback && !r->r_sort_spec && !schema)
745  {
746  /* Regular piggyback - do it unless we're going to do sort */
747  *search_req->largeSetLowerBound = 2000000000;
748  *search_req->smallSetUpperBound = 1;
749  *search_req->mediumSetPresentNumber =
750  r->step>0 ? r->step : c->tasks->u.search.count;
751  }
752  else
753  {
754  /* non-piggyback. Need not provide elementsets or syntaxes .. */
755  smallSetElementSetName = 0;
756  mediumSetElementSetName = 0;
757  syntax = 0;
758  }
759  if (smallSetElementSetName && *smallSetElementSetName)
760  {
762  odr_malloc(c->odr_out, sizeof(*esn));
763 
765  esn->u.generic = odr_strdup(c->odr_out, smallSetElementSetName);
766  search_req->smallSetElementSetNames = esn;
767  }
768  if (mediumSetElementSetName && *mediumSetElementSetName)
769  {
771  odr_malloc(c->odr_out, sizeof(*esn));
772 
774  esn->u.generic = odr_strdup(c->odr_out, mediumSetElementSetName);
775  search_req->mediumSetElementSetNames = esn;
776  }
777  if (syntax)
778  search_req->preferredRecordSyntax =
780 
781  if (!r->setname)
782  {
784  {
785  char setname[14];
786  int ord;
787  /* find the lowest unused ordinal so that we re-use
788  result sets on the server. */
789  for (ord = 1; ; ord++)
790  {
791  ZOOM_resultset rp;
792  sprintf(setname, "%d", ord);
793  for (rp = c->resultsets; rp; rp = rp->next)
794  if (rp->setname && !strcmp(rp->setname, setname))
795  break;
796  if (!rp)
797  break;
798  }
799  r->setname = odr_strdup(r->odr, setname);
800  yaz_log(c->log_details, "%p ZOOM_connection_send_search: "
801  "allocating set %s", c, r->setname);
802  }
803  else
804  {
805  yaz_log(c->log_details, "%p ZOOM_connection_send_search: using "
806  "default set", c);
807  r->setname = odr_strdup(r->odr, "default");
808  }
809  ZOOM_options_set(r->options, "setname", r->setname);
810  }
811  search_req->resultSetName = odr_strdup(c->odr_out, r->setname);
812  return send_APDU(c, apdu);
813 }
814 
816 {
817  ZOOM_scanset scan;
819  Z_ScanRequest *req = apdu->u.scanRequest;
820  Z_Query *z_query;
821 
822  yaz_log(c->log_details, "%p send_scan", c);
823  if (!c->tasks)
824  return zoom_complete;
825  assert (c->tasks->which == ZOOM_TASK_SCAN);
826  scan = c->tasks->u.scan.scan;
827 
828  z_query = ZOOM_query_get_Z_Query(scan->query);
829 
830  /* Z39.50 scan can only carry RPN */
831  if (z_query->which == Z_Query_type_1 ||
832  z_query->which == Z_Query_type_101)
833  {
834  Z_RPNQuery *rpn = z_query->u.type_1;
835  const char *cp = ZOOM_options_get(scan->options, "rpnCharset");
836  if (cp)
837  {
838  yaz_iconv_t cd = yaz_iconv_open(cp, "UTF-8");
839  if (cd)
840  {
841  rpn = yaz_copy_z_RPNQuery(rpn, c->odr_out);
842 
844  rpn, c->odr_out, cd);
845  yaz_iconv_close(cd);
846  }
847  }
848  req->attributeSet = rpn->attributeSetId;
849  if (!req->attributeSet)
853  {
854  req->termListAndStartPoint =
856  }
857  else
858  {
860  return zoom_complete;
861  }
862  }
863  else
864  {
866  return zoom_complete;
867  }
868 
869  *req->numberOfTermsRequested =
870  ZOOM_options_get_int(scan->options, "number", 20);
871 
873  odr_intdup(c->odr_out,
874  ZOOM_options_get_int(scan->options, "position", 1));
875 
876  req->stepSize =
877  odr_intdup(c->odr_out,
878  ZOOM_options_get_int(scan->options, "stepSize", 0));
879 
880  req->databaseNames = scan->databaseNames;
882 
883  return send_APDU(c, apdu);
884 }
885 
886 ZOOM_API(void)
888 {
889  Z_APDU *apdu = 0;
890  ZOOM_connection c;
891  if (!p)
892  return;
893  c = p->connection;
894  odr_reset(p->odr_out);
895  xfree(p->buf_out);
896  p->buf_out = 0;
897  if (!strcmp(type, "itemorder"))
898  {
900  if (apdu)
901  {
902  Z_External *r = (Z_External *) odr_malloc(p->odr_out, sizeof(*r));
903 
904  r->direct_reference =
906  r->descriptor = 0;
908  r->indirect_reference = 0;
909  r->u.itemOrder = encode_item_order(p);
910 
912  }
913  }
914  else if (!strcmp(type, "create")) /* create database */
915  {
917  0, 0);
918  }
919  else if (!strcmp(type, "drop")) /* drop database */
920  {
922  0, 0);
923  }
924  else if (!strcmp(type, "commit")) /* commit changes */
925  {
927  0, 0);
928  }
929  else if (!strcmp(type, "update")) /* update record(s) */
930  {
931  apdu = create_update_package(p);
932  }
933  else if (!strcmp(type, "xmlupdate"))
934  {
935  apdu = create_xmlupdate_package(p);
936  }
937  if (apdu)
938  {
939  if (encode_APDU(p->connection, apdu, p->odr_out) == 0)
940  {
941  char *buf;
942 
944  task->u.package = p;
945  buf = odr_getbuf(p->odr_out, &p->len_out, 0);
946  p->buf_out = (char *) xmalloc(p->len_out);
947  memcpy(p->buf_out, buf, p->len_out);
948 
949  (p->refcount)++;
950  if (!c->async)
951  {
952  while (ZOOM_event(1, &c))
953  ;
954  }
955  }
956  }
957 }
958 
960  int present_phase);
961 
963 {
964  char oid_name_buf[OID_STR_MAX];
965  const char *oid_name;
966  char *addinfo = 0;
967 
968  oid_name = yaz_oid_to_string_buf(r->diagnosticSetId, 0, oid_name_buf);
969  switch (r->which)
970  {
972  addinfo = r->u.v2Addinfo;
973  break;
975  addinfo = r->u.v3Addinfo;
976  break;
977  }
978  xfree(c->addinfo);
979  c->addinfo = 0;
980  ZOOM_set_dset_error(c, *r->condition, oid_name, addinfo, 0);
981 }
982 
984 {
985  if (p->which != Z_DiagRec_defaultFormat)
987  else
989 }
990 
993 {
994  if (utp && utp->targetPart)
995  {
996  Z_IUTargetPart *targetPart = utp->targetPart;
997  switch (*targetPart->updateStatus)
998  {
1001  "updateStatus", "success");
1002  break;
1005  "updateStatus", "partial");
1006  break;
1009  "updateStatus", "failure");
1010  if (targetPart->globalDiagnostics &&
1011  targetPart->num_globalDiagnostics > 0)
1012  response_diag(c, targetPart->globalDiagnostics[0]);
1013  break;
1014  }
1015  /* NOTE: Individual record status, surrogate diagnostics, and supplemental diagnostics ARE NOT REPORTED. */
1016  }
1017  return 1;
1018 }
1019 
1022 {
1023  if (utp && utp->targetPart)
1024  {
1025  Z_IU0TargetPart *targetPart = utp->targetPart;
1026  switch (*targetPart->updateStatus)
1027  {
1030  "updateStatus", "success");
1031  break;
1034  "updateStatus", "partial");
1035  break;
1038  "updateStatus", "failure");
1039  if (targetPart->globalDiagnostics &&
1040  targetPart->num_globalDiagnostics > 0)
1041  response_diag(c, targetPart->globalDiagnostics[0]);
1042  break;
1043  }
1044  /* NOTE: Individual record status, surrogate diagnostics, and supplemental diagnostics ARE NOT REPORTED. */
1045  }
1046  return 1;
1047 }
1048 
1050  Z_TaskPackage *taskPackage)
1051 {
1052  Odr_oct *id = taskPackage->targetReference;
1053  if (id)
1055  "targetReference", (char*) id->buf, id->len);
1056  switch (*taskPackage->taskStatus)
1057  {
1058  case Z_TaskPackage_pending:
1060  "taskStatus", "pending");
1061  break;
1062  case Z_TaskPackage_active:
1064  "taskStatus", "active");
1065  break;
1068  "taskStatus", "complete");
1069  break;
1070  case Z_TaskPackage_aborted:
1072  "taskStatus", "aborted");
1073  if (taskPackage->num_packageDiagnostics &&
1074  taskPackage->packageDiagnostics )
1075  response_diag(c, taskPackage->packageDiagnostics[0]);
1076  break;
1077  }
1078  /* NOTE: Only Update/Update0 implemented, no others. */
1079  if (taskPackage->taskSpecificParameters->which == Z_External_update)
1080  {
1081  Z_IUUpdateTaskPackage *utp =
1082  taskPackage->taskSpecificParameters->u.update->u.taskPackage;
1084  }
1085  if (taskPackage->taskSpecificParameters->which == Z_External_update0)
1086  {
1087  Z_IU0UpdateTaskPackage *utp =
1088  taskPackage->taskSpecificParameters->u.update0->u.taskPackage;
1090  }
1091  return 1;
1092 }
1093 
1096 {
1097  const char *opStatus = 0;
1098  if (!c->tasks)
1099  return;
1100  assert(c->tasks->which == ZOOM_TASK_PACKAGE);
1101 
1102  /* store any diagnostics in esError / esAddinfo */
1103  if (res->diagnostics && res->num_diagnostics > 0)
1104  {
1105  response_diag(c, res->diagnostics[0]);
1106  if (c->error)
1107  {
1109  "esError", c->error);
1111  "esAddinfo", c->addinfo);
1112  /* treat only diagnostics as error when operationStatus = failure */
1115  }
1116  }
1117  switch (*res->operationStatus)
1118  {
1120  opStatus = "done";
1121  break;
1123  opStatus = "accepted";
1124  break;
1126  opStatus = "failure";
1127  break;
1128  }
1129  if (opStatus)
1130  ZOOM_options_set(c->tasks->u.package->options, "operationStatus",
1131  opStatus);
1132  if (res->taskPackage &&
1134  {
1135  Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1136  es_response_taskpackage(c, taskPackage);
1137  }
1138  if (res->taskPackage &&
1140  {
1141  Odr_oct *doc = res->taskPackage->u.octet_aligned;
1143  "xmlUpdateDoc", (char*) doc->buf, doc->len);
1144  }
1145 }
1146 
1147 static char *get_term_cstr(ODR odr, Z_Term *term)
1148 {
1149  switch (term->which)
1150  {
1151  case Z_Term_general:
1152  return odr_strdupn(odr, term->u.general->buf, term->u.general->len);
1153  break;
1155  return odr_strdup(odr, term->u.characterString);
1156  }
1157  return 0;
1158 }
1159 
1161 {
1162  int i;
1163  struct yaz_facet_attr attr_values;
1164  ZOOM_facet_field facet_field = odr_malloc(odr, sizeof(*facet_field));
1165  yaz_facet_attr_init(&attr_values);
1166  yaz_facet_attr_get_z_attributes(facet->attributes, &attr_values);
1167  facet_field->facet_name = odr_strdup(odr, attr_values.useattr);
1168  facet_field->num_terms = facet->num_terms;
1169  yaz_log(YLOG_DEBUG, "ZOOM_facet_field %s %d terms %d",
1170  attr_values.useattr, attr_values.limit, facet->num_terms);
1171  facet_field->facet_terms =
1172  odr_malloc(odr, facet->num_terms * sizeof(*facet_field->facet_terms));
1173  for (i = 0 ; i < facet->num_terms; i++)
1174  {
1175  Z_FacetTerm *facetTerm = facet->terms[i];
1176  facet_field->facet_terms[i].frequency = *facetTerm->count;
1177  facet_field->facet_terms[i].term = get_term_cstr(odr, facetTerm->term);
1178  yaz_log(YLOG_DEBUG, " term[%d] %s %d",
1179  i, facet_field->facet_terms[i].term,
1180  facet_field->facet_terms[i].frequency);
1181  }
1182  return facet_field;
1183 }
1184 
1185 /* Can be share with SOLR/SRU/SRW requests */
1187 {
1188  int j;
1189  r->num_res_facets = fl->num;
1190  yaz_log(YLOG_DEBUG, "Facets found: %d", fl->num);
1191  r->res_facets = odr_malloc(r->odr, fl->num * sizeof(*r->res_facets));
1192  r->facets_names = odr_malloc(r->odr, fl->num * sizeof(*r->facets_names));
1193  for (j = 0; j < fl->num; j++)
1194  {
1195  r->res_facets[j] = get_zoom_facet_field(r->odr, fl->elements[j]);
1196  if (!r->res_facets[j])
1197  {
1198  r->facets_names[j] = 0;
1199  yaz_log(YLOG_DEBUG, "Facet field missing on index %d !", j);
1200  }
1201  else
1202  r->facets_names[j] = (char *)
1204  }
1205 }
1206 
1208  Z_OtherInformation *o)
1209 {
1210  int i;
1211  for (i = 0; o && i < o->num_elements; i++)
1212  {
1214  {
1216  if (ext->which == Z_External_userFacets)
1217  {
1219  }
1220  }
1221  }
1222 }
1223 
1225  Z_Term *term)
1226 {
1227  switch (term->which)
1228  {
1229  case Z_Term_general:
1230  ZOOM_options_setl(opt, name,
1231  term->u.general->buf, term->u.general->len);
1232  break;
1234  ZOOM_options_set(opt, name, term->u.characterString);
1235  break;
1236  case Z_Term_numeric:
1237  ZOOM_options_set_int(opt, name, *term->u.numeric);
1238  break;
1239  }
1240 }
1241 
1242 static void handle_queryExpression(ZOOM_options opt, const char *name,
1243  Z_QueryExpression *exp)
1244 {
1245  char opt_name[80];
1246 
1247  switch (exp->which)
1248  {
1250  if (exp->u.term && exp->u.term->queryTerm)
1251  {
1252  sprintf(opt_name, "%s.term", name);
1253  handle_queryExpressionTerm(opt, opt_name, exp->u.term->queryTerm);
1254  }
1255  break;
1257  break;
1258  }
1259 }
1260 
1261 
1263  Z_OtherInformation *o)
1264 {
1265  int i;
1266  for (i = 0; o && i < o->num_elements; i++)
1267  {
1269  {
1271 
1272  if (ext->which == Z_External_searchResult1)
1273  {
1274  int j;
1275  Z_SearchInfoReport *sr = ext->u.searchResult1;
1276 
1277  if (sr->num)
1279  resultset->options, "searchresult.size", sr->num);
1280 
1281  for (j = 0; j < sr->num; j++)
1282  {
1283  Z_SearchInfoReport_s *ent =
1284  ext->u.searchResult1->elements[j];
1285  char pref[80];
1286 
1287  sprintf(pref, "searchresult.%d", j);
1288 
1289  if (ent->subqueryId)
1290  {
1291  char opt_name[80];
1292  sprintf(opt_name, "%s.id", pref);
1293  ZOOM_options_set(resultset->options, opt_name,
1294  ent->subqueryId);
1295  }
1296  if (ent->subqueryExpression)
1297  {
1298  char opt_name[80];
1299  sprintf(opt_name, "%s.subquery", pref);
1300  handle_queryExpression(resultset->options, opt_name,
1301  ent->subqueryExpression);
1302  }
1303  if (ent->subqueryInterpretation)
1304  {
1305  char opt_name[80];
1306  sprintf(opt_name, "%s.interpretation", pref);
1307  handle_queryExpression(resultset->options, opt_name,
1308  ent->subqueryInterpretation);
1309  }
1310  if (ent->subqueryRecommendation)
1311  {
1312  char opt_name[80];
1313  sprintf(opt_name, "%s.recommendation", pref);
1314  handle_queryExpression(resultset->options, opt_name,
1315  ent->subqueryRecommendation);
1316  }
1317  if (ent->subqueryCount)
1318  {
1319  char opt_name[80];
1320  sprintf(opt_name, "%s.count", pref);
1321  ZOOM_options_set_int(resultset->options, opt_name,
1322  *ent->subqueryCount);
1323  }
1324  }
1325  }
1326  }
1327  }
1328 }
1329 
1331  Z_SearchResponse *sr)
1332 {
1333  ZOOM_resultset resultset;
1334  ZOOM_Event event;
1335  const char *resultCountPrecision = "exact";
1336 
1337  if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
1338  return;
1339 
1340  resultset = c->tasks->u.search.resultset;
1341 
1342  if (resultset->live_set == 0)
1343  {
1345  ZOOM_connection_put_event(c, event);
1346  }
1347  if (sr->resultSetStatus)
1348  {
1350  resultCountPrecision = "estimate";
1351  ZOOM_options_set_int(resultset->options, "resultSetStatus",
1352  *sr->resultSetStatus);
1353  }
1354  if (sr->presentStatus)
1355  {
1356  ZOOM_options_set_int(resultset->options, "presentStatus",
1357  *sr->presentStatus);
1358  }
1359  ZOOM_options_set(resultset->options, "resultCountPrecision",
1360  resultCountPrecision);
1362 
1364 
1365  resultset->size = *sr->resultCount;
1366 
1368  resultCountPrecision);
1369  resultset->live_set = 2;
1370  handle_Z3950_records(c, sr->records, 0);
1371 }
1372 
1374 {
1375  if (res->diagnostics && res->num_diagnostics > 0)
1376  {
1377  response_diag(c, res->diagnostics[0]);
1379  }
1380 }
1381 
1383 {
1384  NMEM nmem = odr_extract_mem(c->odr_in);
1385  ZOOM_scanset scan;
1386 
1387  if (!c->tasks || c->tasks->which != ZOOM_TASK_SCAN)
1388  return;
1389  scan = c->tasks->u.scan.scan;
1390 
1391  if (res->entries && res->entries->nonsurrogateDiagnostics)
1393  scan->scan_response = res;
1394  scan->srw_scan_response = 0;
1395  nmem_transfer(odr_getmem(scan->odr), nmem);
1396  if (res->stepSize)
1397  ZOOM_options_set_int(scan->options, "stepSize", *res->stepSize);
1398  if (res->positionOfTerm)
1399  ZOOM_options_set_int(scan->options, "position", *res->positionOfTerm);
1400  if (res->scanStatus)
1401  ZOOM_options_set_int(scan->options, "scanStatus", *res->scanStatus);
1402  if (res->numberOfEntriesReturned)
1403  ZOOM_options_set_int(scan->options, "number",
1404  *res->numberOfEntriesReturned);
1405  nmem_destroy(nmem);
1406 }
1407 
1409  int present_phase)
1410 {
1411  ZOOM_resultset resultset;
1412  int *start, *count;
1413  const char *syntax = 0, *elementSetName = 0, *schema = 0;
1414 
1415  if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
1416  return ;
1417 
1418  resultset = c->tasks->u.search.resultset;
1419  start = &c->tasks->u.search.start;
1420  count = &c->tasks->u.search.count;
1421  syntax = c->tasks->u.search.syntax;
1422  elementSetName = c->tasks->u.search.elementSetName;
1423  schema = c->tasks->u.search.schema;
1424 
1425  if (sr && sr->which == Z_Records_NSD)
1426  {
1429  }
1430  else if (sr && sr->which == Z_Records_multipleNSD)
1431  {
1434  else
1437  }
1438  else
1439  {
1440  if (*count + *start > resultset->size)
1441  *count = resultset->size - *start;
1442  if (*count < 0)
1443  *count = 0;
1444  if (sr && sr->which == Z_Records_DBOSD)
1445  {
1446  int i;
1447  NMEM nmem = odr_extract_mem(c->odr_in);
1450  for (i = 0; i < p->num_records; i++)
1451  {
1452  ZOOM_record_cache_add(resultset, p->records[i], i + *start,
1453  syntax, elementSetName, schema, 0);
1454  }
1455  *count -= i;
1456  if (*count < 0)
1457  *count = 0;
1458  *start += i;
1459  yaz_log(c->log_details,
1460  "handle_records resultset=%p start=%d count=%d",
1461  resultset, *start, *count);
1462 
1463  /* transfer our response to search_nmem .. we need it later */
1464  nmem_transfer(odr_getmem(resultset->odr), nmem);
1465  nmem_destroy(nmem);
1466  if (present_phase && p->num_records == 0)
1467  {
1468  /* present response and we didn't get any records! */
1469  Z_NamePlusRecord *myrec =
1471  resultset->odr, 0,
1473  "ZOOM C generated. Present phase and no records");
1474  ZOOM_record_cache_add(resultset, myrec, *start,
1475  syntax, elementSetName, schema, 0);
1476  *count = 0;
1477  }
1478  }
1479  else if (present_phase)
1480  {
1481  /* present response and we didn't get any records! */
1482  Z_NamePlusRecord *myrec =
1484  resultset->odr, 0,
1486  "ZOOM C generated: Present response and no records");
1487  ZOOM_record_cache_add(resultset, myrec, *start,
1488  syntax, elementSetName, schema, 0);
1489  *count = 0;
1490  }
1491  }
1492 }
1493 
1495  Z_PresentResponse *pr)
1496 {
1497  handle_Z3950_records(c, pr->records, 1);
1498 }
1499 
1500 static void set_init_option(const char *name, void *clientData)
1501 {
1502  ZOOM_connection c = (ZOOM_connection) clientData;
1503  char buf[80];
1504 
1505  sprintf(buf, "init_opt_%.70s", name);
1506  ZOOM_connection_option_set(c, buf, "1");
1507 }
1508 
1510 {
1511  if (c->error)
1512  resultset->r_sort_spec = 0;
1513  if (resultset->r_sort_spec)
1514  {
1516  Z_SortRequest *req = apdu->u.sortRequest;
1517 
1518  yaz_log(c->log_details, "%p send_Z3950_sort set=%p", c, resultset);
1519 
1520  req->num_inputResultSetNames = 1;
1522  odr_malloc(c->odr_out, sizeof(*req->inputResultSetNames));
1523  req->inputResultSetNames[0] =
1524  odr_strdup(c->odr_out, resultset->setname);
1525  req->sortedResultSetName = odr_strdup(c->odr_out, resultset->setname);
1526  req->sortSequence = resultset->r_sort_spec;
1527  resultset->r_sort_spec = 0;
1528  return send_APDU(c, apdu);
1529  }
1530  return zoom_complete;
1531 }
1532 
1534 {
1536  Z_PresentRequest *req = apdu->u.presentRequest;
1537  ZOOM_resultset resultset = c->tasks->u.search.resultset;
1538  const char *syntax = c->tasks->u.search.syntax;
1539  const char *elementSetName = c->tasks->u.search.elementSetName;
1540  const char *schema = c->tasks->u.search.schema;
1541 
1542  yaz_log(c->log_details, "%p Z3950_send_present", c);
1543 
1544  *req->resultSetStartPoint = c->tasks->u.search.start + 1;
1545 
1546  if (resultset->step > 0 && resultset->step < c->tasks->u.search.count)
1547  *req->numberOfRecordsRequested = resultset->step;
1548  else
1549  *req->numberOfRecordsRequested = c->tasks->u.search.count;
1550 
1551  if (*req->numberOfRecordsRequested + c->tasks->u.search.start > resultset->size)
1552  *req->numberOfRecordsRequested = resultset->size - c->tasks->u.search.start;
1553  assert(*req->numberOfRecordsRequested > 0);
1554 
1555  if (syntax && *syntax)
1556  req->preferredRecordSyntax =
1558 
1559  if (schema && *schema)
1560  {
1562  odr_malloc(c->odr_out, sizeof(*compo));
1563 
1564  req->recordComposition = compo;
1565  compo->which = Z_RecordComp_complex;
1566  compo->u.complex = (Z_CompSpec *)
1567  odr_malloc(c->odr_out, sizeof(*compo->u.complex));
1568  compo->u.complex->selectAlternativeSyntax = (bool_t *)
1569  odr_malloc(c->odr_out, sizeof(bool_t));
1570  *compo->u.complex->selectAlternativeSyntax = 0;
1571 
1572  compo->u.complex->generic = (Z_Specification *)
1573  odr_malloc(c->odr_out, sizeof(*compo->u.complex->generic));
1574 
1575  compo->u.complex->generic->which = Z_Schema_oid;
1576  compo->u.complex->generic->schema.oid = (Odr_oid *)
1578 
1579  if (!compo->u.complex->generic->schema.oid)
1580  {
1581  /* OID wasn't a schema! Try record syntax instead. */
1582 
1583  compo->u.complex->generic->schema.oid = (Odr_oid *)
1585  }
1586  if (elementSetName && *elementSetName)
1587  {
1588  compo->u.complex->generic->elementSpec = (Z_ElementSpec *)
1589  odr_malloc(c->odr_out, sizeof(Z_ElementSpec));
1590  compo->u.complex->generic->elementSpec->which =
1593  odr_strdup(c->odr_out, elementSetName);
1594  }
1595  else
1596  compo->u.complex->generic->elementSpec = 0;
1597  compo->u.complex->num_dbSpecific = 0;
1598  compo->u.complex->dbSpecific = 0;
1599  compo->u.complex->num_recordSyntax = 0;
1600  compo->u.complex->recordSyntax = 0;
1601  }
1602  else if (elementSetName && *elementSetName)
1603  {
1605  odr_malloc(c->odr_out, sizeof(*esn));
1607  odr_malloc(c->odr_out, sizeof(*compo));
1608 
1610  esn->u.generic = odr_strdup(c->odr_out, elementSetName);
1611  compo->which = Z_RecordComp_simple;
1612  compo->u.simple = esn;
1613  req->recordComposition = compo;
1614  }
1615  req->resultSetId = odr_strdup(c->odr_out, resultset->setname);
1616  return send_APDU(c, apdu);
1617 }
1618 
1620 {
1621  int i = 0;
1622  const char *syntax = 0;
1623  const char *elementSetName = 0;
1624  const char *schema = 0;
1625  ZOOM_resultset resultset;
1626  int *start, *count;
1627 
1628  if (!c->tasks || c->tasks->which == ZOOM_TASK_SORT)
1629  return zoom_complete;
1630  assert(c->tasks->which == ZOOM_TASK_SEARCH);
1631  resultset = c->tasks->u.search.resultset;
1632  start = &c->tasks->u.search.start;
1633  count = &c->tasks->u.search.count;
1634  syntax = c->tasks->u.search.syntax;
1635  elementSetName = c->tasks->u.search.elementSetName;
1636  schema = c->tasks->u.search.schema;
1637 
1638  yaz_log(c->log_details, "%p ZOOM_connection_Z3950_search start=%d count=%d",
1639  c, *start, *count);
1640 
1641  ZOOM_memcached_search(c, resultset);
1642 
1643  if (*start < 0 || *count < 0)
1644  {
1646  "start/count < 0", 0);
1647  }
1648 
1649  if (resultset->live_set)
1650  {
1651  if (*start >= resultset->size)
1652  *count = 0;
1653  else if (*start + *count >= resultset->size)
1654  *count = resultset->size - *start;
1655  }
1656 
1657  if (c->error) /* don't continue on error */
1658  return zoom_complete;
1659 
1660  for (i = 0; i < *count; i++)
1661  {
1662  ZOOM_record rec =
1663  ZOOM_record_cache_lookup(resultset, i + *start,
1664  syntax, elementSetName, schema);
1665  if (!rec)
1666  break;
1667  }
1668  *start += i;
1669  *count -= i;
1670 
1671  if (*count == 0 && resultset->live_set)
1672  return zoom_complete;
1673 
1674  if (resultset->live_set == 2)
1675  return Z3950_send_present(c);
1676  else
1677  return Z3950_send_search(c);
1678 }
1679 
1681 {
1682  zoom_ret r = zoom_complete;
1683 
1684  if (c->tasks && c->tasks->which == ZOOM_TASK_SEARCH)
1685  r = send_Z3950_sort(c, c->tasks->u.search.resultset);
1686  if (r == zoom_complete)
1688  return r;
1689 }
1690 
1692 {
1693  Z_InitResponse *initrs;
1694 
1696  yaz_log(c->log_details, "%p handle_Z3950_apdu apdu->which=%d",
1697  c, apdu->which);
1698  switch (apdu->which)
1699  {
1700  case Z_APDU_initResponse:
1701  yaz_log(c->log_api, "%p handle_Z3950_apdu: Received Init response", c);
1702  initrs = apdu->u.initResponse;
1703  ZOOM_connection_option_set(c, "serverImplementationId",
1704  initrs->implementationId ?
1705  initrs->implementationId : "");
1706  ZOOM_connection_option_set(c, "serverImplementationName",
1707  initrs->implementationName ?
1708  initrs->implementationName : "");
1709  ZOOM_connection_option_set(c, "serverImplementationVersion",
1710  initrs->implementationVersion ?
1711  initrs->implementationVersion : "");
1712  /* Set the three old options too, for old applications */
1713  ZOOM_connection_option_set(c, "targetImplementationId",
1714  initrs->implementationId ?
1715  initrs->implementationId : "");
1716  ZOOM_connection_option_set(c, "targetImplementationName",
1717  initrs->implementationName ?
1718  initrs->implementationName : "");
1719  ZOOM_connection_option_set(c, "targetImplementationVersion",
1720  initrs->implementationVersion ?
1721  initrs->implementationVersion : "");
1722 
1723  /* Make initrs->options available as ZOOM-level options */
1724  yaz_init_opt_decode(initrs->options, set_init_option, (void*) c);
1725 
1726  if (!*initrs->result)
1727  {
1728  Z_DefaultDiagFormat *df = yaz_decode_init_diag(0, initrs);
1729  if (df)
1730  response_default_diag(c, df);
1731  else
1732  ZOOM_set_error(c, ZOOM_ERROR_INIT, 0); /* default error */
1733  }
1734  else
1735  {
1736  char *cookie =
1738  yaz_oid_userinfo_cookie, 1, 0);
1739  xfree(c->cookie_in);
1740  c->cookie_in = 0;
1741  if (cookie)
1742  c->cookie_in = xstrdup(cookie);
1745  c->support_named_resultsets = 1;
1746  if (c->tasks)
1747  {
1748  assert(c->tasks->which == ZOOM_TASK_CONNECT);
1750  }
1752  }
1754  {
1755  NMEM tmpmem = nmem_create();
1758 
1759  if (p)
1760  {
1761  char *charset = NULL, *lang = NULL;
1762  int sel;
1763 
1764  yaz_get_response_charneg(tmpmem, p, &charset, &lang, &sel);
1765  yaz_log(c->log_details, "%p handle_Z3950_apdu target accepted: "
1766  "charset %s, language %s, select %d",
1767  c,
1768  charset ? charset : "none", lang ? lang : "none", sel);
1769  if (charset)
1770  ZOOM_connection_option_set(c, "negotiation-charset",
1771  charset);
1772  if (lang)
1773  ZOOM_connection_option_set(c, "negotiation-lang",
1774  lang);
1775 
1777  c, "negotiation-charset-in-effect-for-records",
1778  (sel != 0) ? "1" : "0");
1779  nmem_destroy(tmpmem);
1780  }
1781  }
1782  break;
1783  case Z_APDU_searchResponse:
1784  yaz_log(c->log_api, "%p handle_Z3950_apdu Search response", c);
1788  break;
1790  yaz_log(c->log_api, "%p handle_Z3950_apdu Present response", c);
1794  break;
1795  case Z_APDU_sortResponse:
1796  yaz_log(c->log_api, "%p handle_Z3950_apdu Sort response", c);
1800  break;
1801  case Z_APDU_scanResponse:
1802  yaz_log(c->log_api, "%p handle_Z3950_apdu Scan response", c);
1805  break;
1807  yaz_log(c->log_api, "%p handle_Z3950_apdu Extended Services response", c);
1810  break;
1811  case Z_APDU_close:
1812  yaz_log(c->log_api, "%p handle_Z3950_apdu Close PDU", c);
1813  if (!ZOOM_test_reconnect(c))
1814  {
1817  }
1818  break;
1819  default:
1820  yaz_log(c->log_api, "%p Received unknown PDU", c);
1823  }
1824 }
1825 
1826 /*
1827  * Local variables:
1828  * c-basic-offset: 4
1829  * c-file-style: "Stroustrup"
1830  * indent-tabs-mode: nil
1831  * End:
1832  * vim: shiftwidth=4 tabstop=8 expandtab
1833  */
1834 
Z_Operand * simple
Definition: z-core.h:502
#define Z_APDU_scanResponse
Definition: z-core.h:365
static void handle_queryExpression(ZOOM_options opt, const char *name, Z_QueryExpression *exp)
Definition: zoom-z3950.c:1242
ZOOM_options_get_int(ZOOM_options opt, const char *name, int defa)
Definition: zoom-opt.c:235
union Z_Records::@56 u
Odr_int * resultCount
Definition: z-core.h:625
Z_AttributesPlusTerm * termListAndStartPoint
Definition: z-core.h:949
#define Z_ExtendedServicesResponse_failure
Definition: z-core.h:1145
Odr_int * condition
Definition: z-core.h:743
Shared pointer macros.
union Z_ElementSetNames::@61 u
int num_globalDiagnostics
Definition: zes-update.h:97
char Z_InternationalString
Definition: z-core.h:301
MARC conversion.
int which
Definition: z-core.h:510
char * buf
Definition: odr.h:101
ZOOM_resultset resultsets
Definition: zoom-p.h:108
#define Z_APDU_searchResponse
Definition: z-core.h:352
ZOOM_connection_close(ZOOM_connection c)
#define ODR_MASK_GET(mask, num)
Definition: odr.h:211
Odr_oid ** recordSyntax
Definition: z-core.h:796
ZOOM_options options
Definition: zoom-p.h:174
#define Z_SearchResponse_estimate
Definition: z-core.h:632
Odr_int * resultSetStatus
Definition: z-core.h:633
int num_diagRecs
Definition: z-core.h:688
Z_IUOriginPartToKeep * toKeep
Definition: zes-update.h:58
Z_InternationalString * groupId
Definition: z-core.h:392
#define Z_DefaultDiagFormat_v3Addinfo
Definition: z-core.h:749
struct ZOOM_connection_p * ZOOM_connection
Definition: zoom.h:52
Z_AttributeList * attributes
Definition: z-facet-1.h:36
Z_InternationalString * subqueryId
Definition: z-uifr1.h:43
Z_ItemOrder * itemOrder
Definition: prt-ext.h:118
static void handle_Z3950_present_response(ZOOM_connection c, Z_PresentResponse *pr)
Definition: zoom-z3950.c:1494
Z_Query * ZOOM_query_get_Z_Query(ZOOM_query s)
Definition: zoom-query.c:129
#define YLOG_DEBUG
log level: debugging
Definition: log.h:44
#define Z_Schema_oid
Definition: z-core.h:814
void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, struct yaz_facet_attr *av)
Definition: facet.c:147
Odr_int * stepSize
Definition: z-core.h:950
Z_InternationalString * elementSetName
Definition: zes-update.h:86
ZOOM_query query
Definition: zoom-p.h:135
#define Z_Term_general
Definition: z-core.h:547
Z_IUUpdateTaskPackage * taskPackage
Definition: zes-update.h:71
Z_ElementSetNames * smallSetElementSetNames
Definition: z-core.h:460
static zoom_ret Z3950_send_search(ZOOM_connection c)
Definition: zoom-z3950.c:644
Z_InternationalString * implementationName
Definition: z-core.h:419
int num_diagnostics
Definition: z-core.h:1055
int num_databaseNames
Definition: zoom-p.h:146
#define ODR_PRINT
Definition: odr.h:97
#define Z_IUOriginPartToKeep_recordInsert
Definition: zes-update.h:78
#define ZOOM_TASK_PACKAGE
Definition: zoom-p.h:211
#define Z_IUOriginPartToKeep_elementUpdate
Definition: zes-update.h:81
union Z_ESAdminOriginPartNotToKeep::@112 u
Z_ScanResponse * scan_response
Definition: zoom-p.h:177
#define Z_IUTargetPart_partial
Definition: zes-update.h:94
char * odr_strdup(ODR o, const char *str)
Definition: odr_mem.c:36
Z_InternationalString * implementationVersion
Definition: z-core.h:386
#define Z_IUUpdate_esRequest
Definition: zes-update.h:72
static zoom_ret send_Z3950_sort_present(ZOOM_connection c)
Definition: zoom-z3950.c:1680
Header for errno utilities.
#define Z_ExtendedServicesRequest_delete
Definition: z-core.h:1122
Z_InternationalString * resultSetName
Definition: z-core.h:457
#define ZOOM_TASK_CONNECT
Definition: zoom-p.h:206
Odr_oid * preferredRecordSyntax
Definition: z-core.h:658
ZOOM_options_getl(ZOOM_options opt, const char *name, int *lenp)
Definition: zoom-opt.c:186
Z_QueryExpression * subqueryRecommendation
Definition: z-uifr1.h:47
Z_InternationalString * note
Definition: zes-update.h:136
#define Z_ExtendedServicesRequest_dontWait
Definition: z-core.h:1134
#define Z_APDU_searchRequest
Definition: z-core.h:351
#define Z_Query_type_1
Definition: z-core.h:479
#define ZOOM_ERROR_NONE
Definition: zoom.h:127
static int es_response_taskpackage(ZOOM_connection c, Z_TaskPackage *taskPackage)
Definition: zoom-z3950.c:1049
struct ZOOM_task_p::@6::@7 search
union Z_IU0Update::@131 u
Z_InternationalString * generic
Definition: z-core.h:771
#define Z_IUSuppliedRecords_elem_string
Definition: zes-update.h:122
int num_inputResultSetNames
Definition: z-core.h:1037
int yaz_query_charset_convert_rpnquery_check(Z_RPNQuery *q, ODR o, yaz_iconv_t cd)
Definition: query-charset.c:96
char * odr_getbuf(ODR o, int *len, int *size)
Definition: odr.c:277
Z_IU0TargetPart * targetPart
Definition: zes-update0.h:61
Z_Records * records
Definition: z-core.h:678
int start
Definition: facet.h:62
#define ZOOM_ERROR_DECODE
Definition: zoom.h:131
Z_Query * query
Definition: z-core.h:463
ZOOM_options options
Definition: zoom-p.h:107
void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset, Z_OtherInformation *oi, const char *precision)
void ZOOM_set_dset_error(ZOOM_connection c, int error, const char *dset, const char *addinfo, const char *addinfo2)
Definition: zoom-c.c:54
Internal header for ZOOM implementation.
#define Z_DiagRec_defaultFormat
Definition: z-core.h:736
void nmem_destroy(NMEM n)
destroys NMEM handle and memory associated with it
Definition: nmem.c:204
const char * yaz_oid_to_string_buf(const Odr_oid *oid, oid_class *oclass, char *buf)
maps any OID to string (named or dot-notation)
Definition: oid_db.c:99
Z_PresentRequest * presentRequest
Definition: z-core.h:328
int num_res_facets
Definition: zoom-p.h:154
Odr_oid * direct_reference
Definition: prt-ext.h:60
Odr_int * item
Definition: zes-order.h:113
Z_ProtocolVersion * protocolVersion
Definition: z-core.h:413
Z_Records * records
Definition: z-core.h:635
#define Z_DefaultDiagFormat_v2Addinfo
Definition: z-core.h:748
int which
Definition: z-core.h:322
#define Z_ElementSetNames_generic
Definition: z-core.h:773
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)
ILL Package utilities.
Z_NamePlusRecord ** records
Definition: z-core.h:684
yaz_iconv_t yaz_iconv_open(const char *tocode, const char *fromcode)
just like iconv_open(3)
Definition: siconv.c:95
static zoom_ret send_APDU(ZOOM_connection c, Z_APDU *a)
Definition: zoom-z3950.c:552
Z_OtherInformation * otherInfo
Definition: z-core.h:388
#define Z_Options_present
Definition: z-core.h:430
void yaz_get_response_charneg(NMEM mem, Z_CharSetandLanguageNegotiation *p, char **charset, char **lang, int *selected)
Definition: charneg.c:387
char * name
Definition: initopt.c:18
Odr_int * mediumSetPresentNumber
Definition: z-core.h:455
static Z_ItemOrder * encode_item_order(ZOOM_package p)
Definition: zoom-z3950.c:135
union Z_IUSuppliedRecords_elem::@129 u
zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c)
Definition: zoom-z3950.c:566
Z_QueryExpressionTerm * term
Definition: z-uifr1.h:88
Header for PQF parsing.
Z_Admin * adminService
Definition: prt-ext.h:128
#define Z_ESAdminOriginPartToKeep_create
Definition: zes-admin.h:77
Z_SearchInfoReport_s ** elements
Definition: z-uifr1.h:55
Header for common YAZ utilities.
Z_InternationalString * email
Definition: zes-order.h:74
#define Z_External_searchResult1
Definition: prt-ext.h:81
Z_Close * close
Definition: z-core.h:346
#define Z_ExtendedServicesRequest_waitIfPossible
Definition: z-core.h:1133
Copies various Z39.50 types.
Z_InitRequest * initRequest
Definition: z-core.h:324
Z_RPNStructure * RPNStructure
Definition: z-core.h:490
Z_ExtendedServicesResponse * extendedServicesResponse
Definition: z-core.h:345
void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
Definition: otherinfo.c:18
Z_OtherInformation * otherInfo
Definition: z-core.h:422
ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which)
Definition: zoom-c.c:153
#define Z_APDU_initResponse
Definition: z-core.h:350
ZOOM_package_send(ZOOM_package p, const char *type)
Definition: zoom-z3950.c:887
#define Z_External_update0
Definition: prt-ext.h:86
const Odr_oid yaz_oid_extserv_item_order[]
Definition: oid_std.c:101
zoom_ret ZOOM_connection_Z3950_search(ZOOM_connection c)
Definition: zoom-z3950.c:1619
Odr_int * numberOfTermsRequested
Definition: z-core.h:951
Z_OtherInformation * additionalSearchInfo
Definition: z-core.h:636
#define xstrdup(s)
utility macro which calls xstrdup_f
Definition: xmalloc.h:55
static Z_APDU * create_xmlupdate_package(ZOOM_package p)
Definition: zoom-z3950.c:254
short Odr_oid
Definition: oid_util.h:42
#define ZOOM_ERROR_INIT
Definition: zoom.h:133
void ZOOM_connection_remove_tasks(ZOOM_connection c)
Definition: zoom-c.c:223
const Odr_oid yaz_oid_extserv_database_update[]
Definition: oid_std.c:104
void odr_setprint(ODR o, FILE *file)
Definition: odr.c:164
#define Z_Query_type_101
Definition: z-core.h:482
union Z_Specification::@63 schema
#define Z_IUOriginPartToKeep_recordReplace
Definition: zes-update.h:79
Z_InternationalString * resultSetId
Definition: zes-order.h:112
Z_InternationalString * password
Definition: z-core.h:394
Z_ElementSpec * elementSpec
Definition: z-core.h:817
#define Z_ExtendedServicesRequest_create
Definition: z-core.h:1121
static Z_APDU * create_es_package(ZOOM_package p, const Odr_oid *oid)
Definition: zoom-z3950.c:49
Odr_oid * oid
Definition: z-core.h:812
Z_InternationalString * databaseName
Definition: zes-admin.h:84
Z_IUOriginPartNotToKeep * notToKeep
Definition: zes-update.h:59
char * charset
Definition: zoom-p.h:87
#define ODR_MASK_SET(mask, num)
Definition: odr.h:204
Z_InternationalString * packageName
Definition: z-core.h:1126
ZOOM_options options
Definition: zoom-p.h:187
Z_SortResponse * sortResponse
Definition: z-core.h:342
Z_DiagRec ** globalDiagnostics
Definition: zes-update0.h:93
Z_AttributesPlusTerm * attributesPlusTerm
Definition: z-core.h:512
#define Z_IU0TargetPart_success
Definition: zes-update0.h:88
static void response_diag(ZOOM_connection c, Z_DiagRec *p)
Definition: zoom-z3950.c:983
void * clientData
Definition: ill.h:43
#define Z_External_userFacets
Definition: prt-ext.h:100
#define Z_Options_scan
Definition: z-core.h:436
Z_IU0UpdateTaskPackage * taskPackage
Definition: zes-update0.h:68
Odr_int * updateStatus
Definition: zes-update0.h:91
Z_SRW_scanResponse * srw_scan_response
Definition: zoom-p.h:178
void * odr_malloc(ODR o, size_t size)
Definition: odr_mem.c:31
#define Z_RecordComp_simple
Definition: z-core.h:645
Z_RPNQuery * type_1
Definition: z-core.h:472
Z_RPNQuery * yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out)
int num_terms
Definition: z-facet-1.h:37
static Z_External * encode_ill_request(ZOOM_package p)
Definition: zoom-z3950.c:97
void yaz_oi_set_facetlist(Z_OtherInformation **otherInformation, ODR odr, Z_FacetList *facet_list)
Definition: facet.c:23
ZOOM_connection connection
Definition: zoom-p.h:188
Odr_oct * general
Definition: z-core.h:539
ZOOM_scanset scan
Definition: zoom-p.h:209
ZOOM_task tasks
Definition: zoom-p.h:106
Odr_int * taskStatus
Definition: z-estask.h:37
zoom_ret ZOOM_connection_Z3950_send_scan(ZOOM_connection c)
Definition: zoom-z3950.c:815
Z_NamePlusRecordList * databaseOrSurDiagnostics
Definition: z-core.h:695
union Z_External::@30 u
const Odr_oid yaz_oid_extserv_xml_es[]
Definition: oid_std.c:149
Z_IUSuppliedRecords_elem ** elements
Definition: zes-update.h:132
Z_InternationalString ** inputResultSetNames
Definition: z-core.h:1038
int which
Definition: prt-ext.h:63
Odr_oid * yaz_string_to_oid_odr(yaz_oid_db_t oid_list, oid_class oclass, const char *name, ODR o)
creates ODR malloc&#39;ed OID from string
Definition: oid_db.c:72
Z_InternationalString * implementationName
Definition: z-core.h:385
#define Z_Options_namedResultSets
Definition: z-core.h:442
#define Z_TaskPackage_pending
Definition: z-estask.h:33
#define ZOOM_EVENT_RECV_SEARCH
Definition: zoom.h:160
Z_External * yaz_set_proposal_charneg_list(ODR o, const char *delim, const char *charset_list, const char *lang_list, int selected)
Definition: charneg.c:174
#define Z_Options_extendedServices
Definition: z-core.h:438
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)
#define Z_External_extendedService
Definition: prt-ext.h:75
Odr_int * numeric
Definition: z-core.h:540
Z_IUUpdate * update
Definition: prt-ext.h:125
int ill_Request(ODR o, ILL_Request **p, int opt, const char *name)
Definition: ill-core.c:66
int num_databaseNames
Definition: zoom-p.h:181
const Odr_oid yaz_oid_extserv_admin[]
Definition: oid_std.c:107
Odr_int * numberOfEntriesReturned
Definition: z-core.h:967
int yaz_iconv_close(yaz_iconv_t cd)
just like iconv_close(3)
Definition: siconv.c:284
char * cookie_out
Definition: zoom-p.h:89
#define Z_RecordComp_complex
Definition: z-core.h:646
char * setname
Definition: zoom-p.h:140
int which
Definition: z-core.h:537
Z_Query * yaz_copy_Z_Query(Z_Query *q, ODR out)
Definition: copy_types.c:70
Z_IU0Update * update0
Definition: prt-ext.h:130
#define Z_Records_multipleNSD
Definition: z-core.h:700
char * client_IP
Definition: zoom-p.h:91
Header for Z39.50 OtherInfo utilities.
Z_DiagRec ** diagRecs
Definition: z-core.h:689
Z_IOOriginPartNotToKeep * notToKeep
Definition: zes-order.h:53
int ZOOM_test_reconnect(ZOOM_connection c)
Definition: zoom-c.c:904
ZOOM_options_get(ZOOM_options opt, const char *name)
Definition: zoom-opt.c:216
Z_SortKeySpecList * sortSequence
Definition: z-core.h:1040
const Odr_oid yaz_oid_extserv_database_update_first_version[]
Definition: oid_std.c:102
Z_PresentResponse * presentResponse
Definition: z-core.h:329
Z_QueryExpression * subqueryInterpretation
Definition: z-uifr1.h:46
#define Z_IUTargetPart_failure
Definition: zes-update.h:95
Odr_null * odr_nullval(void)
Definition: odr.c:30
#define Z_Term_numeric
Definition: z-core.h:548
NMEM odr_extract_mem(ODR o)
Definition: odr_mem.c:23
Odr_int * resultSetStartPoint
Definition: z-core.h:653
zoom_ret ZOOM_send_buf(ZOOM_connection c)
Definition: zoom-c.c:1763
Definition: z-core.h:536
#define YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS
Definition: diagbib1.h:24
static void handle_Z3950_sort_response(ZOOM_connection c, Z_SortResponse *res)
Definition: zoom-z3950.c:1373
union Z_DefaultDiagFormat::@60 u
ZOOM_connection_set_mask(ZOOM_connection c, int mask)
set socket mask for connection (DO NOT call outside zoom)
Z_IdPass * idPass
Definition: z-core.h:401
void odr_setbuf(ODR o, char *buf, int len, int can_grow)
Definition: odr.c:267
ZOOM_facet_field * res_facets
Definition: zoom-p.h:153
Query to WRBUF (to strings)
union Z_DiagRec::@59 u
#define Z_Admin_esRequest
Definition: zes-admin.h:57
#define YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE
Definition: diagbib1.h:23
Z_Specification * generic
Definition: z-core.h:792
#define Z_TaskPackage_active
Definition: z-estask.h:34
Z_External * supplDescription
Definition: zes-order.h:100
Z_DefaultDiagFormat * yaz_decode_init_diag(int no, Z_InitResponse *initrs)
returns diagnostics from an init response
Definition: init_diag.c:32
Z_IdAuthentication * idAuthentication
Definition: z-core.h:383
int num_globalDiagnostics
Definition: zes-update0.h:92
Odr_int * stepSize
Definition: z-core.h:958
static char * get_term_cstr(ODR odr, Z_Term *term)
Definition: zoom-z3950.c:1147
void odr_reset(ODR o)
Definition: odr.c:226
Z_IUSuppliedRecordsId * supplementalId
Definition: zes-update.h:125
yaz_oid_db_t yaz_oid_std(void)
returns standard OID database
Definition: oid_db.c:33
Z_IUUpdateEsRequest * esRequest
Definition: zes-update.h:70
#define Z_QueryExpression_query
Definition: z-uifr1.h:91
Odr_int * subqueryCount
Definition: z-uifr1.h:48
int which
Definition: z-core.h:469
#define Z_Records_NSD
Definition: z-core.h:699
Z_ElementSetNames * mediumSetElementSetNames
Definition: z-core.h:461
ZOOM_package package
Definition: zoom-p.h:212
Z_ExtendedServicesRequest * extendedServicesRequest
Definition: z-core.h:344
#define xfree(x)
utility macro which calls xfree_f
Definition: xmalloc.h:53
#define Z_Options_negotiationModel
Definition: z-core.h:445
Z_APDU * create_admin_package(ZOOM_package p, int type, Z_ESAdminOriginPartToKeep **toKeepP, Z_ESAdminOriginPartNotToKeep **notToKeepP)
Definition: zoom-z3950.c:203
static Odr_oid * zoom_yaz_str_to_z3950oid(ZOOM_connection c, oid_class oid_class, const char *str)
Definition: zoom-z3950.c:38
enum l_file_type type
Definition: log.c:45
Z_APDU * zget_APDU(ODR o, int which)
Definition: zget.c:410
Z_PresentStatus * presentStatus
Definition: z-core.h:634
#define Z_ProtocolVersion_3
Definition: z-core.h:427
Z_External * itemRequest
Definition: zes-order.h:118
Z_DiagRec ** diagnostics
Definition: z-core.h:1148
#define ZOOM_EVENT_SEND_APDU
Definition: zoom.h:157
struct ZOOM_package_p * ZOOM_package
Definition: zoom.h:57
Odr_any * single_ASN1_type
Definition: prt-ext.h:104
Z_FacetList * yaz_pqf_parse_facet_list(ODR o, const char *qbuf)
Definition: pquery.c:882
char * buf_out
Definition: zoom-p.h:82
void ZOOM_handle_facet_list(ZOOM_resultset r, Z_FacetList *fl)
Definition: zoom-z3950.c:1186
ZOOM_Event ZOOM_Event_create(int kind)
Definition: zoom-event.c:42
static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out)
Definition: zoom-z3950.c:510
Odr_bool * result
Definition: z-core.h:417
Z_External * z_ext_record_xml(ODR o, const char *buf, int len)
encodes EXTERNAL XML record
Definition: prt-ext.c:368
#define Z_APDU_extendedServicesRequest
Definition: z-core.h:369
int which
Definition: z-core.h:732
zoom_ret
Definition: zoom-p.h:222
Odr_int size
Definition: zoom-p.h:137
Z_InternationalString * implementationId
Definition: z-core.h:384
#define ZOOM_ERROR_UNSUPPORTED_QUERY
Definition: zoom.h:137
char * v2Addinfo
Definition: z-core.h:746
void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event)
Definition: zoom-event.c:73
static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr, int present_phase)
Definition: zoom-z3950.c:1408
Z_External * externallyDefinedInfo
Definition: z-core.h:1285
Z_External * z_ext_record_oid_any(ODR o, const Odr_oid *oid, const char *buf, int len)
encodes EXTERNAL record as ANY
Definition: prt-ext.c:344
#define Z_External_ESAdmin
Definition: prt-ext.h:85
char * descriptor
Definition: prt-ext.h:62
Z_InternationalString * v3Addinfo
Definition: z-core.h:747
#define Z_TaskPackage_complete
Definition: z-estask.h:35
Z_DiagRecs * multipleNonSurDiagnostics
Definition: z-core.h:697
#define Z_ProtocolVersion_1
Definition: z-core.h:425
Z_IORequest * esRequest
Definition: zes-order.h:64
union Z_Query::@48 u
char ** databaseNames
Definition: zoom-p.h:180
static void handle_Z3950_es_response(ZOOM_connection c, Z_ExtendedServicesResponse *res)
Definition: zoom-z3950.c:1094
int which
Definition: zoom-p.h:195
ZOOM_connection_exec_task(ZOOM_connection c)
executes non-blocking tasks for connection
Definition: zoom-c.c:1435
Z_AdminEsRequest * esRequest
Definition: zes-admin.h:55
const Odr_oid yaz_oid_userinfo_proxy[]
Definition: oid_std.c:114
#define Z_IU0TargetPart_failure
Definition: zes-update0.h:90
static int es_response_taskpackage_update0(ZOOM_connection c, Z_IU0UpdateTaskPackage *utp)
Definition: zoom-z3950.c:1020
char * addinfo
Definition: zoom-p.h:70
Odr_oct * targetReference
Definition: z-estask.h:31
Definition: odr.h:99
const Odr_oid yaz_oid_userinfo_client_ip[]
Definition: oid_std.c:116
#define ZOOM_API(x)
Definition: zoom.h:42
char ** ZOOM_connection_get_databases(ZOOM_connection con, ZOOM_options options, int *num, ODR odr)
Definition: zoom-c.c:322
static void set_init_option(const char *name, void *clientData)
Definition: zoom-z3950.c:1500
Header for the facet utilities.
static int es_response_taskpackage_update(ZOOM_connection c, Z_IUUpdateTaskPackage *utp)
Definition: zoom-z3950.c:991
#define Z_External_single
Definition: prt-ext.h:65
Z_ResultSetId * resultSetId
Definition: z-core.h:652
#define OID_STR_MAX
Definition: oid_util.h:40
#define Z_ESAdminOriginPartToKeep_commit
Definition: zes-admin.h:80
void yaz_init_opt_decode(Z_Options *opt, void(*pr)(const char *name, void *clientData), void *clientData)
Decodes Z39.50 Init Options - for printing.
Definition: initopt.c:84
#define Z_ExtendedServicesRequest_wait
Definition: z-core.h:1132
Z_DatabaseName ** databaseNames
Definition: z-core.h:459
Odr_int * updateStatus
Definition: zes-update.h:96
Z_Options * options
Definition: z-core.h:380
Z_OtherInformationUnit * yaz_oi_update(Z_OtherInformation **otherInformationP, ODR odr, const Odr_oid *oid, int categoryValue, int delete_flag)
Definition: otherinfo.c:76
ODR odr
Definition: ill.h:42
Odr_int * indirect_reference
Definition: prt-ext.h:61
#define Z_ElementSpec_elementSetName
Definition: z-core.h:804
Z_InternationalString * userId
Definition: z-core.h:393
Z_DatabaseName ** databaseNames
Definition: z-core.h:947
int z_APDU(ODR o, Z_APDU **p, int opt, const char *name)
Definition: z-core.c:12
Odr_int * preferredPositionInResponse
Definition: z-core.h:952
Z_SortKeySpecList * r_sort_spec
Definition: zoom-p.h:134
typedefZOOM_BEGIN_CDECL struct ZOOM_options_p * ZOOM_options
Definition: zoom.h:50
Z_ElementSetNames * simple
Definition: z-core.h:643
char ** databaseNames
Definition: zoom-p.h:145
int preferred_message_size
Definition: zoom-p.h:104
Z_OtherInformation * additionalSearchInfo
Definition: z-core.h:464
static void handle_Z3950_scan_response(ZOOM_connection c, Z_ScanResponse *res)
Definition: zoom-z3950.c:1382
Z_DiagRec ** globalDiagnostics
Definition: zes-update.h:98
char * password
Definition: zoom-p.h:96
char * group
Definition: zoom-p.h:95
#define Z_IOItemOrder_esRequest
Definition: zes-order.h:66
void ZOOM_memcached_search(ZOOM_connection c, ZOOM_resultset resultset)
Z_InternationalString * databaseName
Definition: zes-update.h:84
Z_SearchResponse * searchResponse
Definition: z-core.h:327
int maximum_record_size
Definition: zoom-p.h:103
#define ZOOM_ERROR_ENCODE
Definition: zoom.h:130
Odr_int * odr_intdup(ODR o, Odr_int v)
Definition: odr_mem.c:51
void odr_destroy(ODR o)
Definition: odr.c:253
union Z_APDU::@46 u
union Z_ESAdminOriginPartToKeep::@111 u
Definition: odr.h:124
int num_databaseNames
Definition: z-core.h:946
ZOOM_facet_field_name(ZOOM_facet_field field)
Definition: zoom-c.c:1034
Odr_int * positionOfTerm
Definition: z-core.h:968
#define Z_ExtendedServicesResponse_done
Definition: z-core.h:1143
Z_FacetList * facetList
Definition: prt-ext.h:146
Z_InternationalString * diagnosticInformation
Definition: z-core.h:1172
#define Z_APDU_extendedServicesResponse
Definition: z-core.h:370
void ZOOM_connection_remove_task(ZOOM_connection c)
Definition: zoom-c.c:183
Z_InternationalString * sortedResultSetName
Definition: z-core.h:1039
#define Z_Records_DBOSD
Definition: z-core.h:698
union Z_IdAuthentication::@47 u
Z_DbSpecific ** dbSpecific
Definition: z-core.h:794
static ZOOM_facet_field get_zoom_facet_field(ODR odr, Z_FacetField *facet)
Definition: zoom-z3950.c:1160
char * yaz_oi_get_string_oid(Z_OtherInformation **otherInformation, const Odr_oid *oid, int categoryValue, int delete_flag)
Definition: otherinfo.c:172
const char * useattr
Definition: facet.h:56
#define Z_Operand_APT
Definition: z-core.h:515
char * host_port
Definition: zoom-p.h:68
oid_class
Definition: oid_db.h:45
Z_QueryExpression * subqueryExpression
Definition: z-uifr1.h:45
#define ZOOM_TASK_SCAN
Definition: zoom-p.h:207
ZOOM_options options
Definition: zoom-p.h:143
#define Z_IUOriginPartToKeep_recordDelete
Definition: zes-update.h:80
Z_ESAdminOriginPartNotToKeep * notToKeep
Definition: zes-admin.h:44
Z_TaskPackage * extendedService
Definition: prt-ext.h:116
Z_InitResponse * initResponse
Definition: z-core.h:325
char * odr_prepend(ODR o, const char *prefix, const char *old)
Definition: odr_util.c:103
void yaz_facet_attr_init(struct yaz_facet_attr *attr_values)
Definition: facet.c:68
Z_DiagRec ** diagnostics
Definition: z-core.h:1056
Odr_int * smallSetUpperBound
Definition: z-core.h:453
Z_InternationalString * name
Definition: zes-order.h:72
Z_ScanRequest * scanRequest
Definition: z-core.h:339
int opt
Definition: initopt.c:19
union Z_RPNStructure::@49 u
Z_DiagRec ** packageDiagnostics
Definition: z-estask.h:39
char * user
Definition: zoom-p.h:94
union Z_QueryExpression::@108 u
#define xmalloc(x)
utility macro which calls malloc_f
Definition: xmalloc.h:49
Odr_oid * odr_oiddup(ODR odr, const Odr_oid *o)
Definition: odr_util.c:60
Z_FacetField ** elements
Definition: z-facet-1.h:32
Z_InternationalString * string
Definition: zes-update.h:119
zoom_ret send_Z3950_sort(ZOOM_connection c, ZOOM_resultset resultset)
Definition: zoom-z3950.c:1509
static void response_default_diag(ZOOM_connection c, Z_DefaultDiagFormat *r)
Definition: zoom-z3950.c:962
Z_AttributeSetId * attributeSet
Definition: z-core.h:948
Z_DefaultDiagFormat * defaultFormat
Definition: z-core.h:734
Z_IUCorrelationInfo * correlationInfo
Definition: zes-update.h:126
#define Z_External_octet
Definition: prt-ext.h:66
Z_NamePlusRecord * zget_surrogateDiagRec(ODR o, const char *dbname, int error, const char *addinfo)
Creates Surrogate Diagnostic Records.
Definition: zget.c:529
Z_InternationalString * userId
Definition: z-core.h:1127
#define Z_APDU_sortRequest
Definition: z-core.h:366
#define Z_APDU_close
Definition: z-core.h:371
Header for memory handling functions.
Z_InternationalString * implementationId
Definition: z-core.h:418
int num_packageDiagnostics
Definition: z-estask.h:38
union ZOOM_task_p::@6 u
void ZOOM_handle_facet_result(ZOOM_connection c, ZOOM_resultset r, Z_OtherInformation *o)
Definition: zoom-z3950.c:1207
Z_RecordComposition * recordComposition
Definition: z-core.h:657
Z_InternationalString * implementationVersion
Definition: z-core.h:420
Z_SearchInfoReport * searchResult1
Definition: prt-ext.h:124
#define ZOOM_TASK_SEARCH
Definition: zoom-p.h:197
#define Z_IdAuthentication_open
Definition: z-core.h:404
Z_ProtocolVersion * protocolVersion
Definition: z-core.h:379
Z_External * taskSpecificParameters
Definition: z-estask.h:40
#define Z_Term_characterString
Definition: z-core.h:549
#define Z_QueryExpression_term
Definition: z-uifr1.h:90
static void otherInfo_attach(ZOOM_connection c, Z_APDU *a, ODR out)
Definition: zoom-z3950.c:473
Odr_int * preferredMessageSize
Definition: z-core.h:381
NMEM nmem_create(void)
returns new NMEM handle
Definition: nmem.c:181
union Z_OtherInformationUnit::@74 information
char * lang
Definition: zoom-p.h:88
ZOOM_query query
Definition: zoom-p.h:176
#define YLOG_WARN
log level: warning
Definition: log.h:46
structure for all known EXTERNALs
Definition: prt-ext.h:58
#define odr_getmem(o)
Definition: odr.h:216
#define ZOOM_ERROR_ES_INVALID_SYNTAX
Definition: zoom.h:145
Odr_int * count
Definition: z-facet-1.h:43
Definition: cookie.c:16
static void handle_queryExpressionTerm(ZOOM_options opt, const char *name, Z_Term *term)
Definition: zoom-z3950.c:1224
#define Z_IdAuthentication_idPass
Definition: z-core.h:405
#define Z_OtherInfo_externallyDefinedInfo
Definition: z-core.h:1289
Z_SortRequest * sortRequest
Definition: z-core.h:341
ZOOM_resultset next
Definition: zoom-p.h:151
static const char * ill_array_lookup(void *clientData, const char *idx)
Definition: zoom-z3950.c:91
union Z_IUUpdate::@127 u
void yaz_log(int level, const char *fmt,...)
Writes log message.
Definition: log.c:485
Z_InternationalString * phone
Definition: zes-order.h:73
#define Z_APDU_sortResponse
Definition: z-core.h:367
ZOOM_options_set_int(ZOOM_options opt, const char *name, int value)
Definition: zoom-opt.c:245
static void handle_Z3950_search_response(ZOOM_connection c, Z_SearchResponse *sr)
Definition: zoom-z3950.c:1330
void ZOOM_set_error(ZOOM_connection c, int error, const char *addinfo)
Definition: zoom-c.c:98
int which
Definition: z-core.h:693
const Odr_oid yaz_oid_attset_bib_1[]
Definition: oid_std.c:13
Odr_oid * preferredRecordSyntax
Definition: z-core.h:462
union Z_IOItemOrder::@118 u
ZOOM_options_setl(ZOOM_options opt, const char *name, const char *value, int len)
Definition: zoom-opt.c:160
#define Z_ExtendedServicesResponse_accepted
Definition: z-core.h:1144
#define ZOOM_ERROR_CONNECTION_LOST
Definition: zoom.h:132
int num_databaseNames
Definition: z-core.h:458
void nmem_transfer(NMEM dst, NMEM src)
transfers memory from one NMEM handle to another
Definition: nmem.c:216
Z_External * actionQualifier
Definition: zes-update.h:87
Odr_oid * diagnosticSetId
Definition: z-core.h:742
int which
Definition: zes-admin.h:53
Odr_int * scanStatus
Definition: z-core.h:966
#define Z_IUSuppliedRecords_elem_number
Definition: zes-update.h:121
#define Z_IUSuppliedRecords_elem_opaque
Definition: zes-update.h:123
Definition: z-core.h:321
Z_Options * options
Definition: z-core.h:414
Odr_int * maximumRecordSize
Definition: z-core.h:382
int num_recordSyntax
Definition: z-core.h:795
const Odr_oid yaz_oid_general_isoill_1[]
Definition: oid_std.c:10
const Odr_oid yaz_oid_extserv_database_update_second_version[]
Definition: oid_std.c:103
ODR odr_createmem(int direction)
Definition: odr.c:200
Odr_int * numberOfRecordsRequested
Definition: z-core.h:654
#define Z_Options_sort
Definition: z-core.h:437
void yaz_query_charset_convert_rpnquery(Z_RPNQuery *q, ODR o, yaz_iconv_t cd)
#define Z_ESAdminOriginPartToKeep_drop
Definition: zes-admin.h:76
#define ZOOM_ERROR_ES_INVALID_VERSION
Definition: zoom.h:144
#define Z_RPNStructure_simple
Definition: z-core.h:504
union Z_Operand::@50 u
Z_Term * queryTerm
Definition: z-uifr1.h:81
#define Z_ExtendedServicesRequest_modify
Definition: z-core.h:1123
ZOOM_event(int no, ZOOM_connection *cs)
wait for events on connection(s) (BLOCKING)
Definition: zoom-socket.c:99
union Z_Admin::@110 u
ILL_Request * ill_get_ILLRequest(struct ill_get_ctl *gc, const char *name, const char *sub)
Definition: ill-get.c:477
char ** facets_names
Definition: zoom-p.h:155
Z_DiagRec ** nonsurrogateDiagnostics
Definition: z-core.h:978
#define Z_TaskPackage_aborted
Definition: z-estask.h:36
#define bool_t
Definition: odr.h:52
Z_ESAdminOriginPartToKeep * toKeep
Definition: zes-admin.h:43
union Z_ElementSpec::@62 u
#define Z_APDU_scanRequest
Definition: z-core.h:364
Logging utility.
Z_InternationalString * elementSetName
Definition: z-core.h:802
char * odr_strdup_null(ODR o, const char *str)
Definition: odr_mem.c:41
#define ZOOM_ERROR_ES_INVALID_ACTION
Definition: zoom.h:143
Z_External * taskPackage
Definition: z-core.h:1149
Z_SearchRequest * searchRequest
Definition: z-core.h:326
Z_IUTargetPart * targetPart
Definition: zes-update.h:64
Z_CharSetandLanguageNegotiation * yaz_get_charneg_record(Z_OtherInformation *p)
Definition: charneg.c:260
Z_External * taskSpecificParameters
Definition: z-core.h:1131
Odr_bool * selectAlternativeSyntax
Definition: z-core.h:791
ZOOM_options_set(ZOOM_options opt, const char *name, const char *value)
Definition: zoom-opt.c:180
#define Z_External_itemOrder
Definition: prt-ext.h:76
union Z_RecordComposition::@55 u
void ZOOM_handle_search_result(ZOOM_connection c, ZOOM_resultset resultset, Z_OtherInformation *o)
Definition: zoom-z3950.c:1262
Z_ListEntries * entries
Definition: z-core.h:969
Odr_int * largeSetLowerBound
Definition: z-core.h:454
Z_OtherInformationUnit ** list
Definition: z-core.h:1296
ZOOM_connection_option_set(ZOOM_connection c, const char *key, const char *val)
Definition: zoom-c.c:1801
#define Z_APDU_initRequest
Definition: z-core.h:349
#define ZOOM_TASK_SORT
Definition: zoom-p.h:213
Header for Z39.50 Charset negotiation utilities.
Z_InternationalString * characterString
Definition: z-core.h:541
Z_ScanResponse * scanResponse
Definition: z-core.h:340
#define Z_IUOriginPartToKeep_specialUpdate
Definition: zes-update.h:82
Odr_oct * odr_create_Odr_oct(ODR o, const char *buf, int sz)
Definition: odr_mem.c:66
const Odr_oid yaz_oid_userinfo_cookie[]
Definition: oid_std.c:115
char * odr_strdupn(ODR o, const char *str, size_t n)
Definition: odr_mem.c:46
const char *(* f)(void *clientData, const char *element)
Definition: ill.h:44
Odr_oct * octet_aligned
Definition: prt-ext.h:105
int limit
Definition: facet.h:61
Z_External * z_ext_record_oid(ODR o, const Odr_oid *oid, const char *buf, int len)
encodes EXTERNAL record based on OID (NULL if not known)
Definition: prt-ext.c:338
void ZOOM_handle_Z3950_apdu(ZOOM_connection c, Z_APDU *apdu)
Definition: zoom-z3950.c:1691
static Z_APDU * create_update_package(ZOOM_package p)
Definition: zoom-z3950.c:278
#define Z_APDU_presentResponse
Definition: z-core.h:354
Z_IOContact * contact
Definition: zes-order.h:101
#define Z_ESAdminOriginPartNotToKeep_recordsWillFollow
Definition: zes-admin.h:93
#define Z_ExtendedServicesRequest_dontReturnPackage
Definition: z-core.h:1135
void yaz_oi_set_string_oid(Z_OtherInformation **otherInformation, ODR odr, const Odr_oid *oid, int categoryValue, const char *str)
Definition: otherinfo.c:159
Z_AttributeSetId * attributeSetId
Definition: z-core.h:489
char * req_facets
Definition: zoom-p.h:152
Z_IOOriginPartToKeep * toKeep
Definition: zes-order.h:52
static zoom_ret Z3950_send_present(ZOOM_connection c)
Definition: zoom-z3950.c:1533
Z_IOResultSetItem * resultSetItem
Definition: zes-order.h:117
Header for config file reading utilities.
#define Z_IUTargetPart_success
Definition: zes-update.h:93
int num_dbSpecific
Definition: z-core.h:793
Z_CompSpec * complex
Definition: z-core.h:644
#define Z_Options_search
Definition: z-core.h:429
Diagnostics: Generated by csvtodiag.tcl from ./bib1.csv.
#define Z_ProtocolVersion_2
Definition: z-core.h:426
#define Z_IU0TargetPart_partial
Definition: zes-update0.h:89
union Z_Term::@51 u
#define ZOOM_ERROR_INVALID_QUERY
Definition: zoom.h:138
Z_DefaultDiagFormat * nonSurrogateDiagnostic
Definition: z-core.h:696
Z_Term * term
Definition: z-facet-1.h:42
#define Z_External_update
Definition: prt-ext.h:82
Z_FacetTerm ** terms
Definition: z-facet-1.h:38
int len
Definition: odr.h:102
Z_IOBilling * addlBilling
Definition: zes-order.h:102
#define Z_APDU_presentRequest
Definition: z-core.h:353