YAZ  5.34.0
seshigh.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  */
28 #if HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <limits.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <assert.h>
36 
37 #if HAVE_SYS_TYPES_H
38 #include <sys/types.h>
39 #endif
40 #if HAVE_SYS_STAT_H
41 #include <sys/stat.h>
42 #endif
43 #ifdef WIN32
44 #include <io.h>
45 #include <sys/stat.h>
46 #define S_ISREG(x) (x & _S_IFREG)
47 #include <process.h>
48 #endif
49 
50 #if HAVE_UNISTD_H
51 #include <unistd.h>
52 #endif
53 
54 #if YAZ_HAVE_XML2
55 #include <libxml/parser.h>
56 #include <libxml/tree.h>
57 #endif
58 
59 #include <yaz/facet.h>
60 #include <yaz/xmalloc.h>
61 #include <yaz/comstack.h>
62 #include "eventl.h"
63 #include "session.h"
64 #include "mime.h"
65 #include <yaz/proto.h>
66 #include <yaz/oid_db.h>
67 #include <yaz/log.h>
68 #include <yaz/logrpn.h>
69 #include <yaz/querytowrbuf.h>
70 #include <yaz/statserv.h>
71 #include <yaz/diagbib1.h>
72 #include <yaz/charneg.h>
73 #include <yaz/otherinfo.h>
74 #include <yaz/yaz-util.h>
75 #include <yaz/pquery.h>
76 #include <yaz/oid_db.h>
77 #include <yaz/query-charset.h>
78 #include <yaz/srw.h>
79 #include <yaz/backend.h>
80 #include <yaz/yaz-ccl.h>
81 
82 static void process_gdu_request(association *assoc, request *req);
83 static int process_z_request(association *assoc, request *req, char **msg);
84 static int process_gdu_response(association *assoc, request *req, Z_GDU *res);
85 static int process_z_response(association *assoc, request *req, Z_APDU *res);
86 static Z_APDU *process_initRequest(association *assoc, request *reqb);
87 static Z_External *init_diagnostics(ODR odr, int errcode,
88  const char *errstring);
89 static Z_APDU *process_searchRequest(association *assoc, request *reqb);
90 static Z_APDU *response_searchRequest(association *assoc, request *reqb,
91  bend_search_rr *bsrr);
92 static Z_APDU *process_presentRequest(association *assoc, request *reqb);
93 static Z_APDU *process_scanRequest(association *assoc, request *reqb);
94 static Z_APDU *process_sortRequest(association *assoc, request *reqb);
95 static void process_close(association *assoc, request *reqb);
96 static Z_APDU *process_deleteRequest(association *assoc, request *reqb);
97 static Z_APDU *process_segmentRequest(association *assoc, request *reqb);
98 static Z_APDU *process_ESRequest(association *assoc, request *reqb);
99 
100 /* dynamic logging levels */
101 static int logbits_set = 0;
102 static int log_session = 0; /* one-line logs for session */
103 static int log_sessiondetail = 0; /* more detailed stuff */
104 static int log_request = 0; /* one-line logs for requests */
105 static int log_requestdetail = 0; /* more detailed stuff */
106 
108 static void get_logbits(void)
109 { /* needs to be called after parsing cmd-line args that can set loglevels!*/
110  if (!logbits_set)
111  {
112  logbits_set = 1;
113  log_session = yaz_log_module_level("session");
114  log_sessiondetail = yaz_log_module_level("sessiondetail");
115  log_request = yaz_log_module_level("request");
116  log_requestdetail = yaz_log_module_level("requestdetail");
117  }
118 }
119 
120 static void wr_diag(WRBUF w, int error, const char *addinfo)
121 {
122  wrbuf_printf(w, "ERROR %d+", error);
123  wrbuf_puts_replace_char(w, diagbib1_str(error), ' ', '_');
124  if (addinfo)
125  {
126  wrbuf_puts(w, "+");
127  wrbuf_puts_replace_char(w, addinfo, ' ', '_');
128  }
129  wrbuf_puts(w, " ");
130 }
131 
132 static int odr_int_to_int(Odr_int v)
133 {
134  if (v >= INT_MAX)
135  return INT_MAX;
136  else if (v <= INT_MIN)
137  return INT_MIN;
138  else
139  return (int) v;
140 }
141 
142 /*
143  * Create and initialize a new association-handle.
144  * channel : iochannel for the current line.
145  * link : communications channel.
146  * Returns: 0 or a new association handle.
147  */
149  const char *apdufile)
150 {
151  association *anew;
152 
153  if (!logbits_set)
154  get_logbits();
155  if (!(anew = (association *)xmalloc(sizeof(*anew))))
156  return 0;
157  anew->init = 0;
158  anew->version = 0;
159  anew->last_control = 0;
160  anew->client_chan = channel;
161  anew->client_link = link;
162  anew->cs_get_mask = 0;
163  anew->cs_put_mask = 0;
164  anew->cs_accept_mask = 0;
165  if (!(anew->decode = odr_createmem(ODR_DECODE)) ||
166  !(anew->encode = odr_createmem(ODR_ENCODE)))
167  return 0;
168  if (apdufile && *apdufile)
169  {
170  FILE *f;
171 
172  if (!(anew->print = odr_createmem(ODR_PRINT)))
173  return 0;
174  if (*apdufile == '@')
175  {
176  odr_setprint(anew->print, yaz_log_file());
177  }
178  else if (*apdufile != '-')
179  {
180  char filename[256];
181  sprintf(filename, "%.200s.%ld", apdufile, (long)getpid());
182  if (!(f = fopen(filename, "w")))
183  {
184  yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", filename);
185  return 0;
186  }
187  setvbuf(f, 0, _IONBF, 0);
188  odr_setprint(anew->print, f);
189  }
190  }
191  else
192  anew->print = 0;
193  anew->input_buffer = 0;
194  anew->input_buffer_len = 0;
195  anew->backend = 0;
196  anew->state = ASSOC_NEW;
197  request_initq(&anew->incoming);
198  request_initq(&anew->outgoing);
199  anew->proto = cs_getproto(link);
200  anew->server = 0;
201  return anew;
202 }
203 
204 /*
205  * Free association and release resources.
206  */
208 {
210  request *req;
211 
212  xfree(h->init);
213  odr_destroy(h->decode);
214  odr_destroy(h->encode);
215  if (h->print)
216  odr_destroy(h->print);
217  if (h->input_buffer)
218  xfree(h->input_buffer);
219  if (h->backend)
220  (*cb->bend_close)(h->backend);
221  while ((req = request_deq(&h->incoming)))
222  request_release(req);
223  while ((req = request_deq(&h->outgoing)))
224  request_release(req);
225  request_delq(&h->incoming);
226  request_delq(&h->outgoing);
227  xfree(h);
228  xmalloc_trav("session closed");
229 }
230 
231 static void do_close_req(association *a, int reason, char *message,
232  request *req)
233 {
234  Z_APDU *apdu = zget_APDU(a->encode, Z_APDU_close);
235  Z_Close *cls = apdu->u.close;
236 
237  /* Purge request queue */
238  while (request_deq(&a->incoming));
239  while (request_deq(&a->outgoing));
240  if (a->version >= 3)
241  {
242  yaz_log(log_requestdetail, "Sending Close PDU, reason=%d, message=%s",
243  reason, message ? message : "none");
244  *cls->closeReason = reason;
245  cls->diagnosticInformation = message;
246  process_z_response(a, req, apdu);
248  }
249  else
250  {
251  request_release(req);
252  yaz_log(log_requestdetail, "v2 client. No Close PDU");
253  iochan_setevent(a->client_chan, EVENT_TIMEOUT); /* force imm close */
254  a->cs_put_mask = 0;
255  }
256  a->state = ASSOC_DEAD;
257 }
258 
259 static void do_close(association *a, int reason, char *message)
260 {
261  request *req = request_get(&a->outgoing);
262  do_close_req(a, reason, message, req);
263 }
264 
265 
266 int ir_read(IOCHAN h, int event)
267 {
268  association *assoc = (association *)iochan_getdata(h);
269  COMSTACK conn = assoc->client_link;
270  request *req;
271 
272  if ((assoc->cs_put_mask & EVENT_INPUT) == 0 && (event & assoc->cs_get_mask))
273  {
274  /* We aren't speaking to this fellow */
275  if (assoc->state == ASSOC_DEAD)
276  {
277  yaz_log(log_session, "Connection closed - end of session");
278  cs_close(conn);
279  destroy_association(assoc);
280  iochan_destroy(h);
281  return 0;
282  }
283  assoc->cs_get_mask = EVENT_INPUT;
284 
285  do
286  {
287  int res = cs_get(conn, &assoc->input_buffer,
288  &assoc->input_buffer_len);
289  if (res < 0 && cs_errno(conn) == CSBUFSIZE)
290  {
291  yaz_log(log_session, "Connection error: %s res=%d",
292  cs_errmsg(cs_errno(conn)), res);
293  req = request_get(&assoc->incoming); /* get a new request */
295  "Incoming package too large", req);
296  return 0;
297  }
298  else if (res <= 0)
299  {
300  assoc->state = ASSOC_DEAD;
301  yaz_log(log_session, "Connection closed by client");
302  return 0;
303  }
304  else if (res == 1) /* incomplete read - wait for more */
305  {
306  if (conn->io_pending & CS_WANT_WRITE)
307  assoc->cs_get_mask |= EVENT_OUTPUT;
308  iochan_setflag(h, assoc->cs_get_mask);
309  return 0;
310  }
311  /* we got a complete PDU. Let's decode it */
312  yaz_log(YLOG_DEBUG, "Got PDU, %d bytes: lead=%02X %02X %02X", res,
313  assoc->input_buffer[0] & 0xff,
314  assoc->input_buffer[1] & 0xff,
315  assoc->input_buffer[2] & 0xff);
316  req = request_get(&assoc->incoming); /* get a new request */
317  odr_reset(assoc->decode);
318  odr_setbuf(assoc->decode, assoc->input_buffer, res, 0);
319  if (!z_GDU(assoc->decode, &req->gdu_request, 0, 0))
320  {
321  yaz_log(YLOG_WARN, "ODR error on incoming PDU: %s [element %s] "
322  "[near byte %ld] ",
323  odr_errmsg(odr_geterror(assoc->decode)),
324  odr_getelement(assoc->decode),
325  (long) odr_offset(assoc->decode));
326  if (assoc->decode->error != OHTTP)
327  {
328  yaz_log(YLOG_WARN, "PDU dump:");
329  odr_dumpBER(yaz_log_file(), assoc->input_buffer, res);
330  request_release(req);
331  do_close(assoc, Z_Close_protocolError, "Malformed package");
332  }
333  else
334  {
335  Z_GDU *p = z_get_HTTP_Response(assoc->encode, 400);
336  assoc->state = ASSOC_DEAD;
337  process_gdu_response(assoc, req, p);
338  }
339  return 0;
340  }
341  req->request_mem = odr_extract_mem(assoc->decode);
342  if (assoc->print)
343  {
344  if (!z_GDU(assoc->print, &req->gdu_request, 0, 0))
345  yaz_log(YLOG_WARN, "ODR print error: %s",
346  odr_errmsg(odr_geterror(assoc->print)));
347  odr_reset(assoc->print);
348  }
349  request_enq(&assoc->incoming, req);
350  }
351  while (cs_more(conn));
352  }
353  return 1;
354 }
355 
356 /*
357  * This is where PDUs from the client are read and the further
358  * processing is initiated. Flow of control moves down through the
359  * various process_* functions below, until the encoded result comes back up
360  * to the output handler in here.
361  *
362  * h : the I/O channel that has an outstanding event.
363  * event : the current outstanding event.
364  */
365 void ir_session(IOCHAN h, int event)
366 {
367  int res;
368  association *assoc = (association *)iochan_getdata(h);
369  COMSTACK conn = assoc->client_link;
370  request *req;
371 
372  assert(h && conn && assoc);
373  if (event == EVENT_TIMEOUT)
374  {
375  if (assoc->state != ASSOC_UP)
376  {
377  yaz_log(log_session, "Timeout. Closing connection");
378  /* do we need to lod this at all */
379  cs_close(conn);
380  destroy_association(assoc);
381  iochan_destroy(h);
382  }
383  else
384  {
385  yaz_log(log_sessiondetail, "Timeout. Sending Z39.50 Close");
386  do_close(assoc, Z_Close_lackOfActivity, 0);
387  }
388  return;
389  }
390  if (event & assoc->cs_accept_mask)
391  {
392  if (!cs_accept(conn))
393  {
394  yaz_log(YLOG_WARN, "accept failed");
395  destroy_association(assoc);
396  iochan_destroy(h);
397  return;
398  }
400  if (conn->io_pending)
401  { /* cs_accept didn't complete */
402  assoc->cs_accept_mask =
403  ((conn->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) |
404  ((conn->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0);
405 
406  iochan_setflag(h, assoc->cs_accept_mask);
407  }
408  else
409  { /* cs_accept completed. Prepare for reading (cs_get) */
410  assoc->cs_accept_mask = 0;
411  assoc->cs_get_mask = EVENT_INPUT;
412  iochan_setflag(h, assoc->cs_get_mask);
413  }
414  return;
415  }
416  if (event & assoc->cs_get_mask) /* input */
417  {
418  if (!ir_read(h, event))
419  return;
420  req = request_head(&assoc->incoming);
421  if (req->state == REQUEST_IDLE)
422  {
423  request_deq(&assoc->incoming);
424  process_gdu_request(assoc, req);
425  }
426  }
427  if (event & assoc->cs_put_mask)
428  {
429  request *req = request_head(&assoc->outgoing);
430 
431  assoc->cs_put_mask = 0;
432  yaz_log(YLOG_DEBUG, "ir_session (output)");
433  req->state = REQUEST_PENDING;
434  switch (res = cs_put(conn, req->response, req->len_response))
435  {
436  case -1:
437  yaz_log(log_sessiondetail, "Connection closed by client");
438  cs_close(conn);
439  destroy_association(assoc);
440  iochan_destroy(h);
441  break;
442  case 0: /* all sent - release the request structure */
443  yaz_log(YLOG_DEBUG, "Wrote PDU, %d bytes", req->len_response);
444 #if 0
445  yaz_log(YLOG_DEBUG, "HTTP out:\n%.*s", req->len_response,
446  req->response);
447 #endif
448  request_deq(&assoc->outgoing);
449  request_release(req);
450  if (!request_head(&assoc->outgoing))
451  { /* restore mask for cs_get operation ... */
453  iochan_setflag(h, assoc->cs_get_mask);
454  if (assoc->state == ASSOC_DEAD)
456  }
457  else
458  {
459  assoc->cs_put_mask = EVENT_OUTPUT;
460  }
461  break;
462  default:
463  if (conn->io_pending & CS_WANT_WRITE)
464  assoc->cs_put_mask |= EVENT_OUTPUT;
465  if (conn->io_pending & CS_WANT_READ)
466  assoc->cs_put_mask |= EVENT_INPUT;
467  iochan_setflag(h, assoc->cs_put_mask);
468  }
469  }
470  if (event & EVENT_EXCEPT)
471  {
472  if (assoc->state != ASSOC_DEAD)
473  yaz_log(YLOG_WARN, "ir_session (exception)");
474  cs_close(conn);
475  destroy_association(assoc);
476  iochan_destroy(h);
477  }
478 }
479 
480 static int process_z_request(association *assoc, request *req, char **msg);
481 
482 
483 static void assoc_init_reset(association *assoc, const char *peer_name1)
484 {
485  const char *peer_name2 = cs_addrstr(assoc->client_link);
486 
487  xfree(assoc->init);
488  assoc->init = (bend_initrequest *) xmalloc(sizeof(*assoc->init));
489 
490  assoc->init->stream = assoc->encode;
491  assoc->init->print = assoc->print;
492  assoc->init->auth = 0;
493  assoc->init->referenceId = 0;
494  assoc->init->implementation_version = 0;
495  assoc->init->implementation_id = 0;
496  assoc->init->implementation_name = 0;
497  assoc->init->query_charset = 0;
498  assoc->init->records_in_same_charset = 0;
499  assoc->init->bend_sort = NULL;
500  assoc->init->bend_search = NULL;
501  assoc->init->bend_present = NULL;
502  assoc->init->bend_esrequest = NULL;
503  assoc->init->bend_delete = NULL;
504  assoc->init->bend_scan = NULL;
505  assoc->init->bend_segment = NULL;
506  assoc->init->bend_fetch = NULL;
507  assoc->init->bend_explain = NULL;
508  assoc->init->bend_srw_scan = NULL;
509  assoc->init->bend_srw_update = NULL;
510  assoc->init->named_result_sets = 0;
511 
512  assoc->init->charneg_request = NULL;
513  assoc->init->charneg_response = NULL;
514 
515  assoc->init->decode = assoc->decode;
516 
517  assoc->init->peer_name = (char *)
518  odr_malloc(assoc->encode,
519  (peer_name1 ? strlen(peer_name1) : 0)
520  + 4 + strlen(peer_name2));
521  strcpy(assoc->init->peer_name, "");
522  if (peer_name1)
523  {
524  strcat(assoc->init->peer_name, peer_name1);
525  strcat(assoc->init->peer_name, ", ");
526  }
527  strcat(assoc->init->peer_name, peer_name2);
528 
529  yaz_log(log_requestdetail, "peer %s", assoc->init->peer_name);
530 }
531 
532 static int srw_bend_init(association *assoc, Z_HTTP_Header *headers,
533  Z_SRW_diagnostic **d, int *num, Z_SRW_PDU *sr)
534 {
536  if (!assoc->init)
537  {
538  const char *encoding = "UTF-8";
539  Z_External *ce;
540  bend_initresult *binitres;
541 
542  yaz_log(log_requestdetail, "srw_bend_init config=%s", cb->configname);
543  assoc_init_reset(assoc, z_HTTP_header_lookup(headers, "X-Forwarded-For"));
544 
545  if (sr->username)
546  {
548  odr_malloc(assoc->decode, sizeof(*auth));
549  size_t len;
550 
551  len = strlen(sr->username) + 1;
552  if (sr->password)
553  len += strlen(sr->password) + 2;
554  yaz_log(log_requestdetail, "username=%s password-len=%ld",
555  sr->username, (long)
556  (sr->password ? strlen(sr->password) : 0));
558  auth->u.open = (char *) odr_malloc(assoc->decode, len);
559  strcpy(auth->u.open, sr->username);
560  if (sr->password && *sr->password)
561  {
562  strcat(auth->u.open, "/");
563  strcat(auth->u.open, sr->password);
564  }
565  assoc->init->auth = auth;
566  }
567 
568 #if 1
569  ce = yaz_set_proposal_charneg(assoc->decode, &encoding, 1, 0, 0, 1);
570  assoc->init->charneg_request = ce->u.charNeg3;
571 #endif
572  assoc->backend = 0;
573  if (!(binitres = (*cb->bend_init)(assoc->init)))
574  {
575  assoc->state = ASSOC_DEAD;
576  yaz_add_srw_diagnostic(assoc->encode, d, num,
578  return 0;
579  }
580  assoc->backend = binitres->handle;
581  assoc->init->auth = 0;
582  if (binitres->errcode)
583  {
584  int srw_code = yaz_diag_bib1_to_srw(binitres->errcode);
585  assoc->state = ASSOC_DEAD;
586  yaz_add_srw_diagnostic(assoc->encode, d, num, srw_code,
587  binitres->errstring);
588  return 0;
589  }
590  return 1;
591  }
592  return 1;
593 }
594 
595 static int retrieve_fetch(association *assoc, bend_fetch_rr *rr)
596 {
597 #if YAZ_HAVE_XML2
598  yaz_record_conv_t rc = 0;
599  const char *match_schema = 0;
600  Odr_oid *match_syntax = 0;
601 
602  if (assoc->server)
603  {
604  int r;
605  const char *input_schema = yaz_get_esn(rr->comp);
606  Odr_oid *input_syntax_raw = rr->request_format;
607 
608  const char *backend_schema = 0;
609  Odr_oid *backend_syntax = 0;
610 
612  input_schema,
613  input_syntax_raw,
614  &match_schema,
615  &match_syntax,
616  &rc,
617  &backend_schema,
618  &backend_syntax);
619  if (r == -1) /* error ? */
620  {
621  const char *details = yaz_retrieval_get_error(
622  assoc->server->retrieval);
623 
625  if (details)
626  rr->errstring = odr_strdup(rr->stream, details);
627  return -1;
628  }
629  else if (r == 1 || r == 3)
630  {
631  const char *details = input_schema;
632  rr->errcode =
634  if (details)
635  rr->errstring = odr_strdup(rr->stream, details);
636  return -1;
637  }
638  else if (r == 2)
639  {
641  if (input_syntax_raw)
642  {
643  char oidbuf[OID_STR_MAX];
644  oid_oid_to_dotstring(input_syntax_raw, oidbuf);
645  rr->errstring = odr_strdup(rr->stream, oidbuf);
646  }
647  return -1;
648  }
649  if (backend_schema)
650  {
651  yaz_set_esn(&rr->comp, backend_schema, odr_getmem(rr->stream));
652  }
653  if (backend_syntax)
654  rr->request_format = backend_syntax;
655  }
656  (*assoc->init->bend_fetch)(assoc->backend, rr);
657  if (rc && rr->record && rr->errcode == 0)
658  { /* post conversion must take place .. */
659  WRBUF output_record = wrbuf_alloc();
660  int r = 1;
661  const char *details = 0;
662  if (rr->len > 0)
663  {
664  r = yaz_record_conv_record(rc, rr->record, rr->len, output_record);
665  if (r)
666  details = yaz_record_conv_get_error(rc);
667  }
668  else if (rr->len == -1 && rr->output_format &&
670  {
672  rc, (Z_OPACRecord *) rr->record, output_record);
673  if (r)
674  details = yaz_record_conv_get_error(rc);
675  }
676  if (r == 0 && match_syntax &&
677  !oid_oidcmp(match_syntax, yaz_oid_recsyn_opac))
678  {
679  yaz_iconv_t cd = 0;
681  Z_OPACRecord *opac = 0;
682 
683  const char *output_charset = yaz_record_get_output_charset(rc);
684  if (output_charset)
685  cd = yaz_iconv_open(output_charset, "utf-8");
686  if (yaz_xml_to_opac(mt, wrbuf_buf(output_record),
687  wrbuf_len(output_record),
688  &opac, cd, rr->stream->mem, 0)
689  && opac)
690  {
691  rr->len = -1;
692  rr->record = (char *) opac;
693  }
694  else
695  {
696  details = "XML to OPAC conversion failed";
697  r = 1;
698  }
699  yaz_marc_destroy(mt);
700  }
701  else if (r == 0)
702  {
703  rr->len = wrbuf_len(output_record);
704  rr->record = (char *) odr_malloc(rr->stream, rr->len);
705  memcpy(rr->record, wrbuf_buf(output_record), rr->len);
706  }
707  if (r)
708  {
710  rr->surrogate_flag = 1;
711  if (details)
712  rr->errstring = odr_strdup(rr->stream, details);
713  }
714  wrbuf_destroy(output_record);
715  }
716  if (match_syntax)
717  rr->output_format = match_syntax;
718  if (match_schema)
719  rr->schema = odr_strdup(rr->stream, match_schema);
720 #else
721  (*assoc->init->bend_fetch)(assoc->backend, rr);
722 #endif
723  return 0;
724 }
725 
726 static int srw_bend_fetch(association *assoc, int pos,
728  Z_SRW_record *record,
729  const char **addinfo, int *last_in_set)
730 {
731  bend_fetch_rr rr;
732  ODR o = assoc->encode;
733 
734  rr.setname = "default";
735  rr.number = pos;
736  rr.referenceId = 0;
738 
739  rr.comp = (Z_RecordComposition *)
740  odr_malloc(assoc->decode, sizeof(*rr.comp));
742  rr.comp->u.complex = (Z_CompSpec *)
743  odr_malloc(assoc->decode, sizeof(Z_CompSpec));
745  odr_malloc(assoc->encode, sizeof(bool_t));
747  rr.comp->u.complex->num_dbSpecific = 0;
748  rr.comp->u.complex->dbSpecific = 0;
749  rr.comp->u.complex->num_recordSyntax = 0;
750  rr.comp->u.complex->recordSyntax = 0;
751 
753  odr_malloc(assoc->decode, sizeof(Z_Specification));
754 
755  /* schema uri = recordSchema (or NULL if recordSchema is not given) */
757  rr.comp->u.complex->generic->schema.uri = srw_req->recordSchema;
758 
759  /* ESN = recordSchema if recordSchema is present */
760  rr.comp->u.complex->generic->elementSpec = 0;
761  if (srw_req->recordSchema)
762  {
764  (Z_ElementSpec *) odr_malloc(assoc->encode, sizeof(Z_ElementSpec));
768  srw_req->recordSchema;
769  }
770 
771  rr.stream = assoc->encode;
772  rr.print = assoc->print;
773 
774  rr.basename = 0;
775  rr.len = 0;
776  rr.record = 0;
777  rr.last_in_set = 0;
778  rr.errcode = 0;
779  rr.errstring = 0;
780  rr.surrogate_flag = 0;
781  rr.schema = srw_req->recordSchema;
782 
783  if (!assoc->init->bend_fetch)
784  return 1;
785 
786  retrieve_fetch(assoc, &rr);
787 
788  *last_in_set = rr.last_in_set;
789 
790  if (rr.errcode && rr.surrogate_flag)
791  {
792  int code = yaz_diag_bib1_to_srw(rr.errcode);
793  yaz_mk_sru_surrogate(o, record, pos, code, rr.errstring);
794  return 0;
795  }
796  else if (rr.len >= 0)
797  {
798  record->recordData_buf = rr.record;
799  record->recordData_len = rr.len;
800  record->recordPosition = odr_intdup(o, pos);
801  record->recordSchema = odr_strdup_null(
802  o, rr.schema ? rr.schema : srw_req->recordSchema);
803  }
804  if (rr.errcode)
805  {
806  *addinfo = rr.errstring;
807  return rr.errcode;
808  }
809  return 0;
810 }
811 
812 static int cql2pqf(ODR odr, const char *cql, cql_transform_t ct,
813  Z_Query *query_result, char **sortkeys_p)
814 {
815  /* have a CQL query and CQL to PQF transform .. */
817  int r;
818  int srw_errcode = 0;
819  const char *add = 0;
820  WRBUF rpn_buf = wrbuf_alloc();
821 
822  *sortkeys_p = 0;
823  r = cql_parser_string(cp, cql);
824  if (r)
825  {
826  srw_errcode = YAZ_SRW_QUERY_SYNTAX_ERROR;
827  }
828  if (!r)
829  {
830  struct cql_node *cn = cql_parser_result(cp);
831 
832  /* Syntax OK */
833  r = cql_transform(ct, cn, wrbuf_vp_puts, rpn_buf);
834  if (r)
835  srw_errcode = cql_transform_error(ct, &add);
836  else
837  {
838  char out[100];
839  int r = cql_sortby_to_sortkeys_buf(cn, out, sizeof(out)-1);
840 
841  if (r == 0)
842  {
843  if (*out)
844  yaz_log(log_requestdetail, "srw_sortKeys '%s'", out);
845  *sortkeys_p = odr_strdup(odr, out);
846  }
847  else
848  {
849  yaz_log(log_requestdetail, "failed to create srw_sortKeys");
850  srw_errcode = YAZ_SRW_UNSUPP_SORT_TYPE;
851  }
852  }
853  }
854  if (!r)
855  {
856  /* Syntax & transform OK. */
857  /* Convert PQF string to Z39.50 to RPN query struct */
859  Z_RPNQuery *rpnquery = yaz_pqf_parse(pp, odr, wrbuf_cstr(rpn_buf));
860  if (!rpnquery)
861  {
862  size_t off;
863  const char *pqf_msg;
864  int code = yaz_pqf_error(pp, &pqf_msg, &off);
865  yaz_log(YLOG_WARN, "PQF Parser Error %s (code %d)",
866  pqf_msg, code);
867  srw_errcode = YAZ_SRW_QUERY_SYNTAX_ERROR;
868  }
869  else
870  {
871  query_result->which = Z_Query_type_1;
872  query_result->u.type_1 = rpnquery;
873  }
874  yaz_pqf_destroy(pp);
875  }
876  cql_parser_destroy(cp);
877  wrbuf_destroy(rpn_buf);
878  return srw_errcode;
879 }
880 
881 static int cql2pqf_scan(ODR odr, const char *cql, cql_transform_t ct,
882  Z_AttributesPlusTerm *result)
883 {
884  Z_Query query;
885  Z_RPNQuery *rpn;
886  char *sortkeys = 0;
887  int srw_error = cql2pqf(odr, cql, ct, &query, &sortkeys);
888  if (srw_error)
889  return srw_error;
890  if (query.which != Z_Query_type_1 && query.which != Z_Query_type_101)
891  return YAZ_SRW_QUERY_SYNTAX_ERROR; /* bad query type */
892  rpn = query.u.type_1;
893  if (!rpn->RPNStructure)
894  return YAZ_SRW_QUERY_SYNTAX_ERROR; /* must be structure */
896  return YAZ_SRW_QUERY_SYNTAX_ERROR; /* must be simple */
897  if (rpn->RPNStructure->u.simple->which != Z_Operand_APT)
898  return YAZ_SRW_QUERY_SYNTAX_ERROR; /* must be be attributes + term */
899  memcpy(result, rpn->RPNStructure->u.simple->u.attributesPlusTerm,
900  sizeof(*result));
901  return 0;
902 }
903 
904 
905 static int ccl2pqf(ODR odr, const Odr_oct *ccl, CCL_bibset bibset,
906  bend_search_rr *bsrr)
907 {
908  char *ccl0;
909  struct ccl_rpn_node *node;
910  int errcode, pos;
911 
912  ccl0 = odr_strdupn(odr, (char*) ccl->buf, ccl->len);
913  if ((node = ccl_find_str(bibset, ccl0, &errcode, &pos)) == 0)
914  {
915  bsrr->errstring = (char*) ccl_err_msg(errcode);
916  return YAZ_SRW_QUERY_SYNTAX_ERROR; /* Query syntax error */
917  }
918 
919  bsrr->query->which = Z_Query_type_1;
920  bsrr->query->u.type_1 = ccl_rpn_query(odr, node);
921  return 0;
922 }
923 
924 static void srw_bend_search(association *assoc,
925  Z_HTTP_Header *headers,
926  Z_SRW_PDU *sr,
927  Z_SRW_PDU *res,
928  int *http_code)
929 {
930  Z_SRW_searchRetrieveResponse *srw_res = res->u.response;
931  int srw_error = 0;
932  Z_External *ext;
933  Z_SRW_searchRetrieveRequest *srw_req = sr->u.request;
934 
935  *http_code = 200;
936  yaz_log(log_requestdetail, "Got SRW SearchRetrieveRequest");
937  srw_bend_init(assoc, headers,
938  &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
939  if (srw_res->num_diagnostics == 0 && assoc->init)
940  {
941  bend_search_rr rr;
942  rr.setname = "default";
943  rr.replace_set = 1;
944  rr.num_bases = 1;
945  rr.basenames = &srw_req->database;
946  rr.referenceId = 0;
947  rr.srw_sortKeys = 0;
948  rr.srw_setname = 0;
949  rr.srw_setnameIdleTime = 0;
950  rr.estimated_hit_count = 0;
951  rr.partial_resultset = 0;
952  rr.query = (Z_Query *) odr_malloc(assoc->decode, sizeof(*rr.query));
953  rr.query->u.type_1 = 0;
954  rr.extra_args = sr->extra_args;
955  rr.extra_response_data = 0;
956  rr.present_number = srw_req->maximumRecords ?
957  *srw_req->maximumRecords : 0;
958 
959  if (!srw_req->queryType || !strcmp(srw_req->queryType, "cql"))
960  {
961  if (assoc->server && assoc->server->cql_transform)
962  {
963  int srw_errcode = cql2pqf(assoc->encode, srw_req->query,
964  assoc->server->cql_transform,
965  rr.query,
966  &rr.srw_sortKeys);
967 
968  if (srw_errcode)
969  {
971  &srw_res->diagnostics,
972  &srw_res->num_diagnostics,
973  srw_errcode, 0);
974  }
975  }
976  else
977  {
978  /* CQL query to backend. Wrap it - Z39.50 style */
979  ext = (Z_External *) odr_malloc(assoc->decode, sizeof(*ext));
981  "1.2.840.10003.16.2");
982  ext->indirect_reference = 0;
983  ext->descriptor = 0;
984  ext->which = Z_External_CQL;
985  ext->u.cql = srw_req->query;
986 
988  rr.query->u.type_104 = ext;
989  }
990  }
991  else if (!strcmp(srw_req->queryType, "pqf"))
992  {
993  Z_RPNQuery *RPNquery;
994  YAZ_PQF_Parser pqf_parser;
995 
996  pqf_parser = yaz_pqf_create();
997 
998  RPNquery = yaz_pqf_parse(pqf_parser, assoc->decode, srw_req->query);
999  if (!RPNquery)
1000  {
1001  const char *pqf_msg;
1002  size_t off;
1003  int code = yaz_pqf_error(pqf_parser, &pqf_msg, &off);
1004  yaz_log(log_requestdetail, "Parse error %d %s near offset %ld",
1005  code, pqf_msg, (long) off);
1006  srw_error = YAZ_SRW_QUERY_SYNTAX_ERROR;
1007  }
1008 
1009  rr.query->which = Z_Query_type_1;
1010  rr.query->u.type_1 = RPNquery;
1011 
1012  yaz_pqf_destroy(pqf_parser);
1013  }
1014  else
1015  {
1016  yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1017  &srw_res->num_diagnostics,
1019  }
1020  if (rr.query->u.type_1)
1021  {
1022  rr.stream = assoc->encode;
1023  rr.decode = assoc->decode;
1024  rr.print = assoc->print;
1025  if (srw_req->sort.sortKeys)
1026  rr.srw_sortKeys = odr_strdup(assoc->encode,
1027  srw_req->sort.sortKeys);
1028  rr.association = assoc;
1029  rr.hits = 0;
1030  rr.errcode = 0;
1031  rr.errstring = 0;
1032  rr.search_info = 0;
1033  rr.search_input = 0;
1034 
1035  if (srw_req->facetList)
1037  srw_req->facetList);
1038 
1040 
1041  (assoc->init->bend_search)(assoc->backend, &rr);
1042  if (rr.errcode)
1043  {
1045  {
1046  *http_code = 404;
1047  }
1048  else
1049  {
1050  srw_error = yaz_diag_bib1_to_srw(rr.errcode);
1052  &srw_res->diagnostics,
1053  &srw_res->num_diagnostics,
1054  srw_error, rr.errstring);
1055  }
1056  }
1057  else
1058  {
1059  int number = srw_req->maximumRecords ?
1060  odr_int_to_int(*srw_req->maximumRecords) : 0;
1061  int start = srw_req->startRecord ?
1062  odr_int_to_int(*srw_req->startRecord) : 1;
1063 
1064  yaz_log(log_requestdetail, "Request to pack %d+%d out of "
1066  start, number, rr.hits);
1067 
1068  srw_res->numberOfRecords = odr_intdup(assoc->encode, rr.hits);
1069  if (rr.srw_setname)
1070  {
1071  srw_res->resultSetId =
1072  odr_strdup(assoc->encode, rr.srw_setname );
1073  srw_res->resultSetIdleTime =
1074  odr_intdup(assoc->encode, *rr.srw_setnameIdleTime );
1075  }
1076 
1077  srw_res->facetList = yaz_oi_get_facetlist(&rr.search_info);
1078  if (start > rr.hits || start < 1)
1079  {
1080  /* if hits<=0 and start=1 we don't return a diagnostic */
1081  if (start != 1)
1083  assoc->encode,
1084  &srw_res->diagnostics, &srw_res->num_diagnostics,
1086  }
1087  else if (number > 0)
1088  {
1089  int i;
1090  int ok = 1;
1091  if (start + number > rr.hits)
1092  number = odr_int_to_int(rr.hits) - start + 1;
1093 
1094  /* Call bend_present if defined */
1095  if (assoc->init->bend_present)
1096  {
1097  bend_present_rr *bprr = (bend_present_rr*)
1098  odr_malloc(assoc->decode, sizeof(*bprr));
1099  bprr->setname = "default";
1100  bprr->start = start;
1101  bprr->number = number;
1102  if (srw_req->recordSchema)
1103  {
1104  bprr->comp = (Z_RecordComposition *) odr_malloc(assoc->decode,
1105  sizeof(*bprr->comp));
1106  bprr->comp->which = Z_RecordComp_simple;
1107  bprr->comp->u.simple = (Z_ElementSetNames *)
1108  odr_malloc(assoc->decode, sizeof(Z_ElementSetNames));
1110  bprr->comp->u.simple->u.generic = srw_req->recordSchema;
1111  }
1112  else
1113  {
1114  bprr->comp = 0;
1115  }
1116  bprr->stream = assoc->encode;
1117  bprr->referenceId = 0;
1118  bprr->print = assoc->print;
1119  bprr->association = assoc;
1120  bprr->errcode = 0;
1121  bprr->errstring = NULL;
1122  (*assoc->init->bend_present)(assoc->backend, bprr);
1123 
1124  if (bprr->errcode)
1125  {
1126  srw_error = yaz_diag_bib1_to_srw(bprr->errcode);
1128  &srw_res->diagnostics,
1129  &srw_res->num_diagnostics,
1130  srw_error, bprr->errstring);
1131  ok = 0;
1132  }
1133  }
1134 
1135  if (ok)
1136  {
1137  int j = 0;
1138  int packing = Z_SRW_recordPacking_string;
1139  if (srw_req->recordPacking)
1140  {
1141  packing =
1143  if (packing == -1)
1144  packing = Z_SRW_recordPacking_string;
1145  }
1146  srw_res->records = (Z_SRW_record *)
1147  odr_malloc(assoc->encode,
1148  number * sizeof(*srw_res->records));
1149 
1150  srw_res->extra_records = (Z_SRW_extra_record **)
1151  odr_malloc(assoc->encode,
1152  number*sizeof(*srw_res->extra_records));
1153 
1154  for (i = 0; i<number; i++)
1155  {
1156  int errcode;
1157  int last_in_set = 0;
1158  const char *addinfo = 0;
1159 
1160  srw_res->records[j].recordPacking = packing;
1161  srw_res->records[j].recordData_buf = 0;
1162  srw_res->extra_records[j] = 0;
1163  yaz_log(YLOG_DEBUG, "srw_bend_fetch %d", i+start);
1164  errcode = srw_bend_fetch(assoc, i+start, srw_req,
1165  srw_res->records + j,
1166  &addinfo, &last_in_set);
1167  if (errcode)
1168  {
1170  &srw_res->diagnostics,
1171  &srw_res->num_diagnostics,
1172  yaz_diag_bib1_to_srw(errcode),
1173  addinfo);
1174 
1175  break;
1176  }
1177  if (srw_res->records[j].recordData_buf)
1178  j++;
1179  if (last_in_set)
1180  break;
1181  }
1182  srw_res->num_records = j;
1183  if (!j)
1184  srw_res->records = 0;
1185  }
1186  }
1187  if (rr.extra_response_data)
1188  {
1190  res->extraResponseData_len = strlen(rr.extra_response_data);
1191  }
1192  if (strcmp(res->srw_version, "2.") > 0)
1193  {
1194  if (rr.estimated_hit_count)
1195  srw_res->resultCountPrecision =
1196  odr_strdup(assoc->encode, "estimate");
1197  else if (rr.partial_resultset)
1198  srw_res->resultCountPrecision =
1199  odr_strdup(assoc->encode, "minimum");
1200  else
1201  srw_res->resultCountPrecision =
1202  odr_strdup(assoc->encode, "exact");
1203  }
1204  else if (rr.estimated_hit_count || rr.partial_resultset)
1205  {
1207  assoc->encode,
1208  &srw_res->diagnostics,
1209  &srw_res->num_diagnostics,
1211  0);
1212  }
1213  }
1214  }
1215  }
1216  if (log_request)
1217  {
1218  WRBUF wr = wrbuf_alloc();
1219 
1220  wrbuf_printf(wr, "SRWSearch %s ", srw_req->database);
1221  if (srw_res->num_diagnostics)
1222  wrbuf_printf(wr, "ERROR %s", srw_res->diagnostics[0].uri);
1223  else if (*http_code != 200)
1224  wrbuf_printf(wr, "ERROR info:http/%d", *http_code);
1225  else if (srw_res->numberOfRecords)
1226  {
1227  wrbuf_printf(wr, "OK " ODR_INT_PRINTF,
1228  (srw_res->numberOfRecords ?
1229  *srw_res->numberOfRecords : 0));
1230  }
1231  wrbuf_printf(wr, " %s " ODR_INT_PRINTF "+%d",
1232  (srw_res->resultSetId ?
1233  srw_res->resultSetId : "-"),
1234  (srw_req->startRecord ? *srw_req->startRecord : 1),
1235  srw_res->num_records);
1236  yaz_log(log_request, "%s %s: %s", wrbuf_cstr(wr), srw_req->queryType,
1237  srw_req->query);
1238  wrbuf_destroy(wr);
1239  }
1240 }
1241 
1243 {
1244 #if YAZ_HAVE_XML2
1245  xmlNodePtr ptr = (xmlNode *) rr->server_node_ptr;
1246  if (!ptr)
1247  return 0;
1248  for (ptr = ptr->children; ptr; ptr = ptr->next)
1249  {
1250  if (ptr->type != XML_ELEMENT_NODE)
1251  continue;
1252  if (!strcmp((const char *) ptr->name, "explain"))
1253  {
1254  int len;
1255  xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
1256  xmlChar *buf_out;
1257  char *content;
1258 
1259  ptr = xmlCopyNode(ptr, 1);
1260 
1261  xmlDocSetRootElement(doc, ptr);
1262 
1263  xmlDocDumpMemory(doc, &buf_out, &len);
1264  content = (char*) odr_malloc(rr->stream, 1+len);
1265  memcpy(content, buf_out, len);
1266  content[len] = '\0';
1267 
1268  xmlFree(buf_out);
1269  xmlFreeDoc(doc);
1270  rr->explain_buf = content;
1271  return 0;
1272  }
1273  }
1274 #endif
1275  return 0;
1276 }
1277 
1278 static void srw_bend_explain(association *assoc,
1279  Z_HTTP_Header *headers,
1280  Z_SRW_PDU *sr,
1281  Z_SRW_explainResponse *srw_res,
1282  int *http_code)
1283 {
1284  Z_SRW_explainRequest *srw_req = sr->u.explain_request;
1285  yaz_log(log_requestdetail, "Got SRW ExplainRequest");
1286  srw_bend_init(assoc, headers,
1287  &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
1288  if (!assoc->init && srw_res->num_diagnostics == 0)
1289  *http_code = 404;
1290  if (assoc->init)
1291  {
1292  bend_explain_rr rr;
1293 
1294  rr.stream = assoc->encode;
1295  rr.decode = assoc->decode;
1296  rr.print = assoc->print;
1297  rr.explain_buf = 0;
1298  rr.database = srw_req->database;
1299  if (assoc->server)
1300  rr.server_node_ptr = assoc->server->server_node_ptr;
1301  else
1302  rr.server_node_ptr = 0;
1303  rr.schema = "http://explain.z3950.org/dtd/2.0/";
1304  if (assoc->init->bend_explain)
1305  (*assoc->init->bend_explain)(assoc->backend, &rr);
1306  else
1308 
1309  if (rr.explain_buf)
1310  {
1311  int packing = Z_SRW_recordPacking_string;
1312  if (srw_req->recordPacking)
1313  {
1314  packing =
1316  if (packing == -1)
1317  packing = Z_SRW_recordPacking_string;
1318  }
1319  srw_res->record.recordSchema = rr.schema;
1320  srw_res->record.recordPacking = packing;
1321  srw_res->record.recordData_buf = rr.explain_buf;
1322  srw_res->record.recordData_len = strlen(rr.explain_buf);
1323  srw_res->record.recordPosition = 0;
1324  *http_code = 200;
1325  }
1326  }
1327 }
1328 
1329 static void srw_bend_scan(association *assoc,
1330  Z_HTTP_Header *headers,
1331  Z_SRW_PDU *sr,
1332  Z_SRW_PDU *res,
1333  int *http_code)
1334 {
1335  Z_SRW_scanRequest *srw_req = sr->u.scan_request;
1336  Z_SRW_scanResponse *srw_res = res->u.scan_response;
1337  yaz_log(log_requestdetail, "Got SRW ScanRequest");
1338 
1339  *http_code = 200;
1340  srw_bend_init(assoc, headers,
1341  &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
1342  if (srw_res->num_diagnostics == 0 && assoc->init)
1343  {
1344  int step_size = 0;
1345  struct scan_entry *save_entries;
1346 
1347  bend_scan_rr *bsrr = (bend_scan_rr *)
1348  odr_malloc(assoc->encode, sizeof(*bsrr));
1349  bsrr->num_bases = 1;
1350  bsrr->basenames = &srw_req->database;
1351 
1352  bsrr->num_entries = srw_req->maximumTerms ?
1353  odr_int_to_int(*srw_req->maximumTerms) : 10;
1354  bsrr->term_position = srw_req->responsePosition ?
1355  odr_int_to_int(*srw_req->responsePosition) : 1;
1356 
1357  bsrr->errcode = 0;
1358  bsrr->errstring = 0;
1359  bsrr->referenceId = 0;
1360  bsrr->stream = assoc->encode;
1361  bsrr->print = assoc->print;
1362  bsrr->step_size = &step_size;
1363  bsrr->entries = 0;
1364  bsrr->setname = 0;
1365  bsrr->extra_args = sr->extra_args;
1366  bsrr->extra_response_data = 0;
1367 
1368  if (bsrr->num_entries > 0)
1369  {
1370  int i;
1371  bsrr->entries = (struct scan_entry *)
1372  odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
1373  bsrr->num_entries);
1374  for (i = 0; i<bsrr->num_entries; i++)
1375  {
1376  bsrr->entries[i].term = 0;
1377  bsrr->entries[i].occurrences = 0;
1378  bsrr->entries[i].errcode = 0;
1379  bsrr->entries[i].errstring = 0;
1380  bsrr->entries[i].display_term = 0;
1381  }
1382  }
1383  save_entries = bsrr->entries; /* save it so we can compare later */
1384 
1385  if (srw_req->queryType && !strcmp(srw_req->queryType, "pqf") &&
1386  assoc->init->bend_scan)
1387  {
1388  YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
1389 
1390  bsrr->term = yaz_pqf_scan(pqf_parser, assoc->decode,
1391  &bsrr->attributeset,
1392  srw_req->scanClause);
1393  yaz_pqf_destroy(pqf_parser);
1394  bsrr->scanClause = 0;
1395  ((int (*)(void *, bend_scan_rr *))
1396  (*assoc->init->bend_scan))(assoc->backend, bsrr);
1397  }
1398  else if ((!srw_req->queryType || !strcmp(srw_req->queryType, "cql"))
1399  && assoc->init->bend_scan && assoc->server
1400  && assoc->server->cql_transform)
1401  {
1402  int srw_error;
1403  bsrr->scanClause = 0;
1404  bsrr->attributeset = 0;
1405  bsrr->term = (Z_AttributesPlusTerm *)
1406  odr_malloc(assoc->decode, sizeof(*bsrr->term));
1407  srw_error = cql2pqf_scan(assoc->encode,
1408  srw_req->scanClause,
1409  assoc->server->cql_transform,
1410  bsrr->term);
1411  if (srw_error)
1412  yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1413  &srw_res->num_diagnostics,
1414  srw_error, 0);
1415  else
1416  {
1417  ((int (*)(void *, bend_scan_rr *))
1418  (*assoc->init->bend_scan))(assoc->backend, bsrr);
1419  }
1420  }
1421  else if ((!srw_req->queryType || !strcmp(srw_req->queryType, "cql"))
1422  && assoc->init->bend_srw_scan)
1423  {
1424  bsrr->term = 0;
1425  bsrr->attributeset = 0;
1426  bsrr->scanClause = srw_req->scanClause;
1427  ((int (*)(void *, bend_scan_rr *))
1428  (*assoc->init->bend_srw_scan))(assoc->backend, bsrr);
1429  }
1430  else
1431  {
1432  yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1433  &srw_res->num_diagnostics,
1434  YAZ_SRW_UNSUPP_OPERATION, "scan");
1435  }
1436  if (bsrr->extra_response_data)
1437  {
1439  res->extraResponseData_len = strlen(bsrr->extra_response_data);
1440  }
1441  if (bsrr->errcode)
1442  {
1443  int srw_error;
1445  {
1446  *http_code = 404;
1447  return;
1448  }
1449  srw_error = yaz_diag_bib1_to_srw(bsrr->errcode);
1450 
1451  yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1452  &srw_res->num_diagnostics,
1453  srw_error, bsrr->errstring);
1454  }
1455  else if (srw_res->num_diagnostics == 0 && bsrr->num_entries)
1456  {
1457  int i;
1458  srw_res->terms = (Z_SRW_scanTerm*)
1459  odr_malloc(assoc->encode, sizeof(*srw_res->terms) *
1460  bsrr->num_entries);
1461 
1462  srw_res->num_terms = bsrr->num_entries;
1463  for (i = 0; i<bsrr->num_entries; i++)
1464  {
1465  Z_SRW_scanTerm *t = srw_res->terms + i;
1466  t->value = odr_strdup(assoc->encode, bsrr->entries[i].term);
1467  t->numberOfRecords =
1468  odr_intdup(assoc->encode, bsrr->entries[i].occurrences);
1469  t->displayTerm = 0;
1470  if (save_entries == bsrr->entries &&
1471  bsrr->entries[i].display_term)
1472  {
1473  /* the entries was _not_ set by the handler. So it's
1474  safe to test for new member display_term. It is
1475  NULL'ed by us.
1476  */
1477  t->displayTerm = odr_strdup(assoc->encode,
1478  bsrr->entries[i].display_term);
1479  }
1480  t->whereInList = 0;
1481  }
1482  }
1483  }
1484  if (log_request)
1485  {
1486  WRBUF wr = wrbuf_alloc();
1487  wrbuf_printf(wr, "SRWScan %s ", srw_req->database);
1488 
1489  if (srw_res->num_diagnostics)
1490  wrbuf_printf(wr, "ERROR %s - ", srw_res->diagnostics[0].uri);
1491  else if (srw_res->num_terms)
1492  wrbuf_printf(wr, "OK %d - ", srw_res->num_terms);
1493  else
1494  wrbuf_printf(wr, "OK - - ");
1495 
1497  (srw_req->responsePosition ?
1498  *srw_req->responsePosition : 1),
1499  (srw_req->maximumTerms ?
1500  *srw_req->maximumTerms : 1));
1501  /* there is no step size in SRU/W ??? */
1502  wrbuf_printf(wr, "%s: %s ", srw_req->queryType, srw_req->scanClause);
1503  yaz_log(log_request, "%s ", wrbuf_cstr(wr) );
1504  wrbuf_destroy(wr);
1505  }
1506 
1507 }
1508 
1509 static void srw_bend_update(association *assoc,
1510  Z_HTTP_Header *headers,
1511  Z_SRW_PDU *sr,
1512  Z_SRW_updateResponse *srw_res,
1513  int *http_code)
1514 {
1515  Z_SRW_updateRequest *srw_req = sr->u.update_request;
1516  yaz_log(log_session, "SRWUpdate action=%s", srw_req->operation);
1517  yaz_log(YLOG_DEBUG, "num_diag = %d", srw_res->num_diagnostics );
1518  srw_bend_init(assoc, headers,
1519  &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
1520  if (!assoc->init && srw_res->num_diagnostics == 0)
1521  *http_code = 404;
1522  if (assoc->init)
1523  {
1524  bend_update_rr rr;
1525  Z_SRW_extra_record *extra = srw_req->extra_record;
1526 
1527  rr.stream = assoc->encode;
1528  rr.print = assoc->print;
1529  rr.num_bases = 1;
1530  rr.basenames = &srw_req->database;
1531  rr.operation = srw_req->operation;
1532  rr.operation_status = "failed";
1533  rr.record_id = 0;
1534  rr.record_versions = 0;
1535  rr.num_versions = 0;
1536  rr.record_packing = "string";
1537  rr.record_schema = 0;
1538  rr.record_data = 0;
1539  rr.extra_record_data = 0;
1540  rr.extra_request_data = 0;
1541  rr.extra_response_data = 0;
1542  rr.uri = 0;
1543  rr.message = 0;
1544  rr.details = 0;
1545 
1546  *http_code = 200;
1547  if (rr.operation == 0)
1548  {
1550  assoc->encode, &srw_res->diagnostics,
1551  &srw_res->num_diagnostics,
1553  "action" );
1554  return;
1555  }
1556  yaz_log(YLOG_DEBUG, "basename = %s", rr.basenames[0] );
1557  yaz_log(YLOG_DEBUG, "Operation = %s", rr.operation );
1558  if (!strcmp( rr.operation, "delete"))
1559  {
1560  if (srw_req->record && !srw_req->record->recordSchema)
1561  {
1563  assoc->encode,
1564  srw_req->record->recordSchema);
1565  }
1566  if (srw_req->record)
1567  {
1568  rr.record_data = odr_strdupn(
1569  assoc->encode,
1570  srw_req->record->recordData_buf,
1571  srw_req->record->recordData_len );
1572  }
1573  if (extra && extra->extraRecordData_len)
1574  {
1576  assoc->encode,
1577  extra->extraRecordData_buf,
1578  extra->extraRecordData_len );
1579  }
1580  if (srw_req->recordId)
1581  rr.record_id = srw_req->recordId;
1582  else if (extra && extra->recordIdentifier)
1583  rr.record_id = extra->recordIdentifier;
1584  }
1585  else if (!strcmp(rr.operation, "replace"))
1586  {
1587  if (srw_req->recordId)
1588  rr.record_id = srw_req->recordId;
1589  else if (extra && extra->recordIdentifier)
1590  rr.record_id = extra->recordIdentifier;
1591  else
1592  {
1594  assoc->encode, &srw_res->diagnostics,
1595  &srw_res->num_diagnostics,
1597  "recordIdentifier");
1598  }
1599  if (!srw_req->record)
1600  {
1602  assoc->encode, &srw_res->diagnostics,
1603  &srw_res->num_diagnostics,
1605  "record");
1606  }
1607  else
1608  {
1609  if (srw_req->record->recordSchema)
1611  assoc->encode, srw_req->record->recordSchema);
1612  if (srw_req->record->recordData_len )
1613  {
1614  rr.record_data = odr_strdupn(assoc->encode,
1615  srw_req->record->recordData_buf,
1616  srw_req->record->recordData_len );
1617  }
1618  else
1619  {
1621  assoc->encode, &srw_res->diagnostics,
1622  &srw_res->num_diagnostics,
1624  "recordData" );
1625  }
1626  }
1627  if (extra && extra->extraRecordData_len)
1628  {
1630  assoc->encode,
1631  extra->extraRecordData_buf,
1632  extra->extraRecordData_len );
1633  }
1634  }
1635  else if (!strcmp(rr.operation, "insert"))
1636  {
1637  if (srw_req->recordId)
1638  rr.record_id = srw_req->recordId;
1639  else if (extra)
1640  rr.record_id = extra->recordIdentifier;
1641 
1642  if (srw_req->record)
1643  {
1644  if (srw_req->record->recordSchema)
1646  assoc->encode, srw_req->record->recordSchema);
1647 
1648  if (srw_req->record->recordData_len)
1649  rr.record_data = odr_strdupn(
1650  assoc->encode,
1651  srw_req->record->recordData_buf,
1652  srw_req->record->recordData_len );
1653  }
1654  if (extra && extra->extraRecordData_len)
1655  {
1657  assoc->encode,
1658  extra->extraRecordData_buf,
1659  extra->extraRecordData_len );
1660  }
1661  }
1662  else
1664  &srw_res->num_diagnostics,
1666  rr.operation );
1667 
1668  if (srw_req->record)
1669  {
1670  const char *pack_str =
1672  if (pack_str)
1673  rr.record_packing = odr_strdup(assoc->encode, pack_str);
1674  }
1675 
1676  if (srw_req->num_recordVersions)
1677  {
1678  rr.record_versions = srw_req->recordVersions;
1679  rr.num_versions = srw_req->num_recordVersions;
1680  }
1681  if (srw_req->extraRequestData_len)
1682  {
1684  srw_req->extraRequestData_buf,
1685  srw_req->extraRequestData_len );
1686  }
1687  if (srw_res->num_diagnostics == 0)
1688  {
1689  if ( assoc->init->bend_srw_update)
1690  (*assoc->init->bend_srw_update)(assoc->backend, &rr);
1691  else
1693  assoc->encode, &srw_res->diagnostics,
1694  &srw_res->num_diagnostics,
1696  "No Update backend handler");
1697  }
1698 
1699  if (rr.uri)
1701  &srw_res->diagnostics,
1702  &srw_res->num_diagnostics,
1703  rr.uri,
1704  rr.message,
1705  rr.details);
1706  srw_res->recordId = rr.record_id;
1707  srw_res->operationStatus = rr.operation_status;
1708  srw_res->recordVersions = rr.record_versions;
1709  srw_res->num_recordVersions = rr.num_versions;
1710  if (srw_res->extraResponseData_len)
1711  {
1713  srw_res->extraResponseData_len = strlen(rr.extra_response_data);
1714  }
1715  if (srw_res->num_diagnostics == 0 && rr.record_data)
1716  {
1717  srw_res->record = yaz_srw_get_record(assoc->encode);
1718  srw_res->record->recordSchema = rr.record_schema;
1719  if (rr.record_packing)
1720  {
1721  int pack = yaz_srw_str_to_pack(rr.record_packing);
1722 
1723  if (pack == -1)
1724  {
1726  yaz_log(YLOG_WARN, "Back packing %s from backend",
1727  rr.record_packing);
1728  }
1729  srw_res->record->recordPacking = pack;
1730  }
1731  srw_res->record->recordData_buf = rr.record_data;
1732  srw_res->record->recordData_len = strlen(rr.record_data);
1733  if (rr.extra_record_data)
1734  {
1735  Z_SRW_extra_record *ex =
1737  srw_res->extra_record = ex;
1739  ex->extraRecordData_len = strlen(rr.extra_record_data);
1740  }
1741  }
1742  }
1743 }
1744 
1745 /* check if path is OK (1); BAD (0) */
1746 static int check_path(const char *path)
1747 {
1748  if (*path != '/')
1749  return 0;
1750  if (strstr(path, ".."))
1751  return 0;
1752  return 1;
1753 }
1754 
1755 static char *read_file(const char *fname, ODR o, long *sz)
1756 {
1757  struct stat stat_buf;
1758  FILE *inf;
1759  char *buf = 0;
1760 
1761  if (stat(fname, &stat_buf) == -1)
1762  {
1763  yaz_log(YLOG_LOG|YLOG_ERRNO, "stat %s", fname);
1764  return 0;
1765  }
1766  if (!S_ISREG(stat_buf.st_mode))
1767  {
1768  yaz_log(YLOG_LOG, "Is not a regular file: %s", fname);
1769  return 0;
1770  }
1771  inf = fopen(fname, "rb");
1772  if (!inf)
1773  {
1774  yaz_log(YLOG_LOG|YLOG_ERRNO, "fopen %s", fname);
1775  return 0;
1776  }
1777  if (fseek(inf, 0L, SEEK_END) < 0)
1778  yaz_log(YLOG_LOG|YLOG_ERRNO, "fseek %s", fname);
1779  else if ((*sz = ftell(inf)) == -1L)
1780  yaz_log(YLOG_LOG|YLOG_ERRNO, "ftell %s", fname);
1781  else
1782  {
1783  rewind(inf);
1784  buf = (char *) odr_malloc(o, *sz);
1785  if (fread(buf, 1, *sz, inf) != *sz)
1786  yaz_log(YLOG_WARN|YLOG_ERRNO, "short read %s", fname);
1787  }
1788  fclose(inf);
1789  return buf;
1790 }
1791 
1792 static void process_http_request(association *assoc, request *req)
1793 {
1794  Z_HTTP_Request *hreq = req->gdu_request->u.HTTP_Request;
1795  ODR o = assoc->encode;
1796  int r = 2; /* 2=NOT TAKEN, 1=TAKEN, 0=SOAP TAKEN */
1797  Z_SRW_PDU *sr = 0;
1798  Z_SOAP *soap_package = 0;
1799  Z_GDU *p = 0;
1800  char *charset = 0;
1801  Z_HTTP_Response *hres = 0;
1802  int keepalive = 1;
1803  const char *stylesheet = 0; /* for now .. set later */
1804  Z_SRW_diagnostic *diagnostic = 0;
1805  int num_diagnostic = 0;
1806  const char *host = z_HTTP_header_lookup(hreq->headers, "Host");
1807 
1808  yaz_log(log_request, "%s %s HTTP/%s", hreq->method, hreq->path, hreq->version);
1809  if (!control_association(assoc, host, 0))
1810  {
1811  p = z_get_HTTP_Response(o, 404);
1812  r = 1;
1813  }
1814  if (r == 2 && assoc->server && assoc->server->docpath
1815  && hreq->path[0] == '/'
1816  &&
1817  /* check if path is a proper prefix of documentroot */
1818  strncmp(hreq->path+1, assoc->server->docpath,
1819  strlen(assoc->server->docpath))
1820  == 0)
1821  {
1822  if (!check_path(hreq->path))
1823  {
1824  yaz_log(YLOG_LOG, "File %s access forbidden", hreq->path+1);
1825  p = z_get_HTTP_Response(o, 403);
1826  }
1827  else
1828  {
1829  long content_size = 0;
1830  char *content_buf = read_file(hreq->path+1, o, &content_size);
1831  if (!content_buf)
1832  {
1833  p = z_get_HTTP_Response(o, 404);
1834  }
1835  else
1836  {
1837  const char *ctype = 0;
1839 
1840  yaz_mime_types_add(types, "xsl", "application/xml");
1841  yaz_mime_types_add(types, "xml", "application/xml");
1842  yaz_mime_types_add(types, "css", "text/css");
1843  yaz_mime_types_add(types, "html", "text/html");
1844  yaz_mime_types_add(types, "htm", "text/html");
1845  yaz_mime_types_add(types, "txt", "text/plain");
1846  yaz_mime_types_add(types, "js", "application/x-javascript");
1847 
1848  yaz_mime_types_add(types, "gif", "image/gif");
1849  yaz_mime_types_add(types, "png", "image/png");
1850  yaz_mime_types_add(types, "jpg", "image/jpeg");
1851  yaz_mime_types_add(types, "jpeg", "image/jpeg");
1852 
1853  ctype = yaz_mime_lookup_fname(types, hreq->path);
1854  if (!ctype)
1855  {
1856  yaz_log(YLOG_LOG, "No mime type for %s", hreq->path+1);
1857  p = z_get_HTTP_Response(o, 404);
1858  }
1859  else
1860  {
1861  p = z_get_HTTP_Response(o, 200);
1862  hres = p->u.HTTP_Response;
1863  hres->content_buf = content_buf;
1864  hres->content_len = content_size;
1865  z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype);
1866  }
1867  yaz_mime_types_destroy(types);
1868  }
1869  }
1870  r = 1;
1871  }
1872 
1873  if (r == 2)
1874  {
1875  r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset);
1876  yaz_log(YLOG_DEBUG, "yaz_srw_decode returned %d", r);
1877  }
1878  if (r == 2) /* not taken */
1879  {
1880  r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset,
1881  &diagnostic, &num_diagnostic);
1882  yaz_log(YLOG_DEBUG, "yaz_sru_decode returned %d", r);
1883  }
1884  if (r == 0) /* decode SRW/SRU OK .. */
1885  {
1886  int http_code = 200;
1888  {
1889  Z_SRW_PDU *res =
1891  sr);
1892  stylesheet = sr->u.request->stylesheet;
1893  if (num_diagnostic)
1894  {
1895  res->u.response->diagnostics = diagnostic;
1896  res->u.response->num_diagnostics = num_diagnostic;
1897  }
1898  else
1899  {
1900  srw_bend_search(assoc, hreq->headers, sr, res, &http_code);
1901  }
1902  if (http_code == 200)
1903  soap_package->u.generic->p = res;
1904  }
1905  else if (sr->which == Z_SRW_explain_request)
1906  {
1908  stylesheet = sr->u.explain_request->stylesheet;
1909  if (num_diagnostic)
1910  {
1911  res->u.explain_response->diagnostics = diagnostic;
1912  res->u.explain_response->num_diagnostics = num_diagnostic;
1913  }
1914  srw_bend_explain(assoc, hreq->headers,
1915  sr, res->u.explain_response, &http_code);
1916  if (http_code == 200)
1917  soap_package->u.generic->p = res;
1918  }
1919  else if (sr->which == Z_SRW_scan_request)
1920  {
1922  stylesheet = sr->u.scan_request->stylesheet;
1923  if (num_diagnostic)
1924  {
1925  res->u.scan_response->diagnostics = diagnostic;
1926  res->u.scan_response->num_diagnostics = num_diagnostic;
1927  }
1928  srw_bend_scan(assoc, hreq->headers, sr, res, &http_code);
1929  if (http_code == 200)
1930  soap_package->u.generic->p = res;
1931  }
1932  else if (sr->which == Z_SRW_update_request)
1933  {
1935  sr->srw_version);
1936  yaz_log(YLOG_DEBUG, "handling SRW UpdateRequest");
1937  if (num_diagnostic)
1938  {
1939  res->u.update_response->diagnostics = diagnostic;
1940  res->u.update_response->num_diagnostics = num_diagnostic;
1941  }
1942  yaz_log(YLOG_DEBUG, "num_diag = %d", res->u.update_response->num_diagnostics );
1943  srw_bend_update(assoc, hreq->headers,
1944  sr, res->u.update_response, &http_code);
1945  if (http_code == 200)
1946  soap_package->u.generic->p = res;
1947  }
1948  else
1949  {
1950  yaz_log(log_request, "SOAP ERROR");
1951  /* FIXME - what error, what query */
1952  http_code = 500;
1953  z_soap_error(assoc->encode, soap_package,
1954  "SOAP-ENV:Client", "Bad method", 0);
1955  }
1956  if (http_code == 200 || http_code == 500)
1957  {
1958  static Z_SOAP_Handler soap_handlers[4] = {
1959 #if YAZ_HAVE_XML2
1963 #endif
1964  {0, 0, 0}
1965  };
1966  char ctype[80];
1967  p = z_get_HTTP_Response(o, 200);
1968  hres = p->u.HTTP_Response;
1969 
1970  if (!stylesheet && assoc->server)
1971  stylesheet = assoc->server->stylesheet;
1972 
1973  /* empty stylesheet means NO stylesheet */
1974  if (stylesheet && *stylesheet == '\0')
1975  stylesheet = 0;
1976 
1977  z_soap_codec_enc_xsl(assoc->encode, &soap_package,
1978  &hres->content_buf, &hres->content_len,
1979  soap_handlers, charset, stylesheet);
1980  hres->code = http_code;
1981 
1982  strcpy(ctype, "text/xml");
1983  z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype);
1984  }
1985  else
1986  p = z_get_HTTP_Response(o, http_code);
1987  }
1988 
1989  if (p == 0)
1990  p = z_get_HTTP_Response(o, 500);
1991  hres = p->u.HTTP_Response;
1992  if (!strcmp(hreq->version, "1.0"))
1993  {
1994  const char *v = z_HTTP_header_lookup(hreq->headers, "Connection");
1995  if (v && !strcmp(v, "Keep-Alive"))
1996  keepalive = 1;
1997  else
1998  keepalive = 0;
1999  hres->version = "1.0";
2000  }
2001  else
2002  {
2003  const char *v = z_HTTP_header_lookup(hreq->headers, "Connection");
2004  if (v && !strcmp(v, "close"))
2005  keepalive = 0;
2006  else
2007  keepalive = 1;
2008  hres->version = "1.1";
2009  }
2010  if (!keepalive || !assoc->last_control->keepalive)
2011  {
2012  z_HTTP_header_add(o, &hres->headers, "Connection", "close");
2013  assoc->state = ASSOC_DEAD;
2014  assoc->cs_get_mask = 0;
2015  }
2016  else
2017  {
2018  int t;
2019  const char *alive = z_HTTP_header_lookup(hreq->headers, "Keep-Alive");
2020 
2021  if (alive && yaz_isdigit(*(const unsigned char *) alive))
2022  t = atoi(alive);
2023  else
2024  t = 15;
2025  if (t < 0 || t > 3600)
2026  t = 3600;
2027  iochan_settimeout(assoc->client_chan,t);
2028  z_HTTP_header_add(o, &hres->headers, "Connection", "Keep-Alive");
2029  }
2030  process_gdu_response(assoc, req, p);
2031 }
2032 
2033 static void process_gdu_request(association *assoc, request *req)
2034 {
2035  if (req->gdu_request->which == Z_GDU_Z3950)
2036  {
2037  char *msg = 0;
2038  req->apdu_request = req->gdu_request->u.z3950;
2039  if (process_z_request(assoc, req, &msg) < 0)
2040  do_close_req(assoc, Z_Close_systemProblem, msg, req);
2041  }
2042  else if (req->gdu_request->which == Z_GDU_HTTP_Request)
2043  process_http_request(assoc, req);
2044  else
2045  {
2046  do_close_req(assoc, Z_Close_systemProblem, "bad protocol packet", req);
2047  }
2048 }
2049 
2050 /*
2051  * Initiate request processing.
2052  */
2053 static int process_z_request(association *assoc, request *req, char **msg)
2054 {
2055  Z_APDU *res;
2056  int retval;
2057 
2058  *msg = "Unknown Error";
2059  assert(req && req->state == REQUEST_IDLE);
2060  if (req->apdu_request->which != Z_APDU_initRequest && !assoc->init)
2061  {
2062  *msg = "Missing InitRequest";
2063  return -1;
2064  }
2065  switch (req->apdu_request->which)
2066  {
2067  case Z_APDU_initRequest:
2068  res = process_initRequest(assoc, req); break;
2069  case Z_APDU_searchRequest:
2070  res = process_searchRequest(assoc, req); break;
2071  case Z_APDU_presentRequest:
2072  res = process_presentRequest(assoc, req); break;
2073  case Z_APDU_scanRequest:
2074  if (assoc->init->bend_scan)
2075  res = process_scanRequest(assoc, req);
2076  else
2077  {
2078  *msg = "Cannot handle Scan APDU";
2079  return -1;
2080  }
2081  break;
2083  if (assoc->init->bend_esrequest)
2084  res = process_ESRequest(assoc, req);
2085  else
2086  {
2087  *msg = "Cannot handle Extended Services APDU";
2088  return -1;
2089  }
2090  break;
2091  case Z_APDU_sortRequest:
2092  if (assoc->init->bend_sort)
2093  res = process_sortRequest(assoc, req);
2094  else
2095  {
2096  *msg = "Cannot handle Sort APDU";
2097  return -1;
2098  }
2099  break;
2100  case Z_APDU_close:
2101  process_close(assoc, req);
2102  return 0;
2104  if (assoc->init->bend_delete)
2105  res = process_deleteRequest(assoc, req);
2106  else
2107  {
2108  *msg = "Cannot handle Delete APDU";
2109  return -1;
2110  }
2111  break;
2112  case Z_APDU_segmentRequest:
2113  if (assoc->init->bend_segment)
2114  {
2115  res = process_segmentRequest(assoc, req);
2116  }
2117  else
2118  {
2119  *msg = "Cannot handle Segment APDU";
2120  return -1;
2121  }
2122  break;
2124  return 0;
2125  default:
2126  *msg = "Bad APDU received";
2127  return -1;
2128  }
2129  if (res)
2130  {
2131  yaz_log(YLOG_DEBUG, " result immediately available");
2132  retval = process_z_response(assoc, req, res);
2133  }
2134  else
2135  {
2136  yaz_log(YLOG_DEBUG, " result unavailable");
2137  retval = -1;
2138  }
2139  return retval;
2140 }
2141 
2142 /*
2143  * Encode response, and transfer the request structure to the outgoing queue.
2144  */
2145 static int process_gdu_response(association *assoc, request *req, Z_GDU *res)
2146 {
2147  odr_setbuf(assoc->encode, req->response, req->size_response, 1);
2148 
2149  if (assoc->print)
2150  {
2151  if (!z_GDU(assoc->print, &res, 0, 0))
2152  yaz_log(YLOG_WARN, "ODR print error: %s",
2153  odr_errmsg(odr_geterror(assoc->print)));
2154  odr_reset(assoc->print);
2155  }
2156  if (!z_GDU(assoc->encode, &res, 0, 0))
2157  {
2158  yaz_log(YLOG_WARN, "ODR error when encoding PDU: %s [element %s]",
2159  odr_errmsg(odr_geterror(assoc->decode)),
2160  odr_getelement(assoc->decode));
2161  return -1;
2162  }
2163  req->response = odr_getbuf(assoc->encode, &req->len_response,
2164  &req->size_response);
2165  odr_setbuf(assoc->encode, 0, 0, 0); /* don'txfree if we abort later */
2166  odr_reset(assoc->encode);
2167  req->state = REQUEST_IDLE;
2168  request_enq(&assoc->outgoing, req);
2169  /* turn the work over to the ir_session handler */
2171  assoc->cs_put_mask = EVENT_OUTPUT;
2172  /* Is there more work to be done? give that to the input handler too */
2173  for (;;)
2174  {
2175  req = request_head(&assoc->incoming);
2176  if (req && req->state == REQUEST_IDLE)
2177  {
2178  request_deq(&assoc->incoming);
2179  process_gdu_request(assoc, req);
2180  }
2181  else
2182  break;
2183  }
2184  return 0;
2185 }
2186 
2187 /*
2188  * Encode response, and transfer the request structure to the outgoing queue.
2189  */
2190 static int process_z_response(association *assoc, request *req, Z_APDU *res)
2191 {
2192  Z_GDU *gres = (Z_GDU *) odr_malloc(assoc->encode, sizeof(*gres));
2193  gres->which = Z_GDU_Z3950;
2194  gres->u.z3950 = res;
2195 
2196  return process_gdu_response(assoc, req, gres);
2197 }
2198 
2199 static char *get_vhost(Z_OtherInformation *otherInfo)
2200 {
2201  return yaz_oi_get_string_oid(&otherInfo, yaz_oid_userinfo_proxy, 1, 0);
2202 }
2203 
2204 /*
2205  * Handle init request.
2206  * At the moment, we don't check the options
2207  * anywhere else in the code - we just try not to do anything that would
2208  * break a naive client. We'll toss 'em into the association block when
2209  * we need them there.
2210  */
2212 {
2213  Z_InitRequest *req = reqb->apdu_request->u.initRequest;
2214  Z_APDU *apdu = zget_APDU(assoc->encode, Z_APDU_initResponse);
2215  Z_InitResponse *resp = apdu->u.initResponse;
2216  bend_initresult *binitres;
2217  char options[140];
2218  statserv_options_block *cb = 0; /* by default no control for backend */
2219 
2220  if (control_association(assoc, get_vhost(req->otherInfo), 1))
2221  cb = statserv_getcontrol(); /* got control block for backend */
2222 
2223  if (cb && assoc->backend)
2224  (*cb->bend_close)(assoc->backend);
2225 
2226  yaz_log(log_requestdetail, "Got initRequest");
2227  if (req->implementationId)
2228  yaz_log(log_requestdetail, "Id: %s",
2229  req->implementationId);
2230  if (req->implementationName)
2231  yaz_log(log_requestdetail, "Name: %s",
2232  req->implementationName);
2233  if (req->implementationVersion)
2234  yaz_log(log_requestdetail, "Version: %s",
2235  req->implementationVersion);
2236 
2237  assoc_init_reset(assoc,
2240  assoc->init->auth = req->idAuthentication;
2241  assoc->init->referenceId = req->referenceId;
2242 
2244  {
2245  Z_CharSetandLanguageNegotiation *negotiation =
2247  if (negotiation &&
2249  assoc->init->charneg_request = negotiation;
2250  }
2251 
2252  /* by default named_result_sets is 0 .. Enable it if client asks for it. */
2254  assoc->init->named_result_sets = 1;
2255 
2256  assoc->backend = 0;
2257  if (cb)
2258  {
2259  if (req->implementationVersion)
2260  yaz_log(log_requestdetail, "Config: %s",
2261  cb->configname);
2262 
2264 
2265  /* we have a backend control block, so call that init function */
2266  if (!(binitres = (*cb->bend_init)(assoc->init)))
2267  {
2268  yaz_log(YLOG_WARN, "Bad response from backend.");
2269  return 0;
2270  }
2271  assoc->backend = binitres->handle;
2272  }
2273  else
2274  {
2275  /* no backend. return error */
2276  binitres = (bend_initresult *)
2277  odr_malloc(assoc->encode, sizeof(*binitres));
2278  binitres->errstring = 0;
2280  iochan_settimeout(assoc->client_chan, 10);
2281  }
2282  if ((assoc->init->bend_sort))
2283  yaz_log(YLOG_DEBUG, "Sort handler installed");
2284  if ((assoc->init->bend_search))
2285  yaz_log(YLOG_DEBUG, "Search handler installed");
2286  if ((assoc->init->bend_present))
2287  yaz_log(YLOG_DEBUG, "Present handler installed");
2288  if ((assoc->init->bend_esrequest))
2289  yaz_log(YLOG_DEBUG, "ESRequest handler installed");
2290  if ((assoc->init->bend_delete))
2291  yaz_log(YLOG_DEBUG, "Delete handler installed");
2292  if ((assoc->init->bend_scan))
2293  yaz_log(YLOG_DEBUG, "Scan handler installed");
2294  if ((assoc->init->bend_segment))
2295  yaz_log(YLOG_DEBUG, "Segment handler installed");
2296 
2297  resp->referenceId = req->referenceId;
2298  *options = '\0';
2299  /* let's tell the client what we can do */
2301  {
2303  strcat(options, "srch");
2304  }
2306  {
2308  strcat(options, " prst");
2309  }
2310  if (ODR_MASK_GET(req->options, Z_Options_delSet) &&
2311  assoc->init->bend_delete)
2312  {
2314  strcat(options, " del");
2315  }
2317  assoc->init->bend_esrequest)
2318  {
2320  strcat(options, " extendedServices");
2321  }
2323  && assoc->init->named_result_sets)
2324  {
2326  strcat(options, " namedresults");
2327  }
2328  if (ODR_MASK_GET(req->options, Z_Options_scan) && assoc->init->bend_scan)
2329  {
2331  strcat(options, " scan");
2332  }
2334  {
2336  strcat(options, " concurrop");
2337  }
2338  if (ODR_MASK_GET(req->options, Z_Options_sort) && assoc->init->bend_sort)
2339  {
2341  strcat(options, " sort");
2342  }
2343 
2345  {
2347 
2348  if (!assoc->init->charneg_response)
2349  {
2350  if (assoc->init->query_charset)
2351  {
2353  assoc->encode, assoc->init->query_charset, 0,
2354  assoc->init->records_in_same_charset);
2355  }
2356  else
2357  {
2358  yaz_log(YLOG_WARN, "default query_charset not defined by backend");
2359  }
2360  }
2361  if (assoc->init->charneg_response
2362  && (p0=yaz_oi_update(&resp->otherInfo, assoc->encode, NULL, 0, 0)))
2363  {
2366  assoc->init->charneg_response;
2368  strcat(options, " negotiation");
2369  }
2370  }
2373 
2375  {
2377  assoc->version = 1; /* 1 & 2 are equivalent */
2378  }
2380  {
2382  assoc->version = 2;
2383  }
2385  {
2387  assoc->version = 3;
2388  }
2389 
2390  yaz_log(log_requestdetail, "Negotiated to v%d: %s", assoc->version, options);
2391 
2392  if (*req->maximumRecordSize < assoc->maximumRecordSize)
2394 
2395  if (*req->preferredMessageSize < assoc->preferredMessageSize)
2397 
2398  resp->preferredMessageSize =
2399  odr_intdup(assoc->encode, assoc->preferredMessageSize);
2400  resp->maximumRecordSize =
2401  odr_intdup(assoc->encode, assoc->maximumRecordSize);
2402 
2403  resp->implementationId = odr_prepend(assoc->encode,
2404  assoc->init->implementation_id,
2405  resp->implementationId);
2406 
2407  resp->implementationVersion = odr_prepend(assoc->encode,
2408  assoc->init->implementation_version,
2409  resp->implementationVersion);
2410 
2411  resp->implementationName = odr_prepend(assoc->encode,
2412  assoc->init->implementation_name,
2413  odr_prepend(assoc->encode, "GFS", resp->implementationName));
2414 
2415  if (binitres->errcode)
2416  {
2417  assoc->state = ASSOC_DEAD;
2418  resp->userInformationField =
2419  init_diagnostics(assoc->encode, binitres->errcode,
2420  binitres->errstring);
2421  *resp->result = 0;
2422  }
2423  else
2424  assoc->state = ASSOC_UP;
2425 
2426  if (log_request)
2427  {
2428  if (!req->idAuthentication)
2429  yaz_log(log_request, "Auth none");
2431  {
2432  const char *open = req->idAuthentication->u.open;
2433  const char *slash = strchr(open, '/');
2434  int len;
2435  if (slash)
2436  len = slash - open;
2437  else
2438  len = strlen(open);
2439  yaz_log(log_request, "Auth open %.*s", len, open);
2440  }
2442  {
2443  const char *user = req->idAuthentication->u.idPass->userId;
2444  const char *group = req->idAuthentication->u.idPass->groupId;
2445  yaz_log(log_request, "Auth idPass %s %s",
2446  user ? user : "-", group ? group : "-");
2447  }
2448  else if (req->idAuthentication->which
2450  {
2451  yaz_log(log_request, "Auth anonymous");
2452  }
2453  else
2454  {
2455  yaz_log(log_request, "Auth other");
2456  }
2457  }
2458  if (log_request)
2459  {
2460  WRBUF wr = wrbuf_alloc();
2461  wrbuf_printf(wr, "Init ");
2462  if (binitres->errcode)
2463  wrbuf_printf(wr, "ERROR %d", binitres->errcode);
2464  else
2465  wrbuf_printf(wr, "OK -");
2466  wrbuf_printf(wr, " ID:%s Name:%s Version:%s",
2467  (req->implementationId ? req->implementationId :"-"),
2468  (req->implementationName ?
2469  req->implementationName : "-"),
2470  (req->implementationVersion ?
2471  req->implementationVersion : "-")
2472  );
2473  yaz_log(log_request, "%s", wrbuf_cstr(wr));
2474  wrbuf_destroy(wr);
2475  }
2476  return apdu;
2477 }
2478 
2479 /*
2480  * Set the specified `errcode' and `errstring' into a UserInfo-1
2481  * external to be returned to the client in accordance with Z35.90
2482  * Implementor Agreement 5 (Returning diagnostics in an InitResponse):
2483  * http://www.loc.gov/z3950/agency/agree/initdiag.html
2484  */
2485 static Z_External *init_diagnostics(ODR odr, int error, const char *addinfo)
2486 {
2487  yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
2488  addinfo ? " -- " : "", addinfo ? addinfo : "");
2489  return zget_init_diagnostics(odr, error, addinfo);
2490 }
2491 
2492 /*
2493  * nonsurrogate diagnostic record.
2494  */
2495 static Z_Records *diagrec(association *assoc, int error, char *addinfo)
2496 {
2497  Z_Records *rec = (Z_Records *) odr_malloc(assoc->encode, sizeof(*rec));
2498 
2499  yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
2500  addinfo ? " -- " : "", addinfo ? addinfo : "");
2501 
2502  rec->which = Z_Records_NSD;
2504  error, addinfo);
2505  return rec;
2506 }
2507 
2508 /*
2509  * surrogate diagnostic.
2510  */
2512  const char *dbname,
2513  int error, const char *addinfo)
2514 {
2515  yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
2516  addinfo ? " -- " : "", addinfo ? addinfo : "");
2517  return zget_surrogateDiagRec(assoc->encode, dbname, error, addinfo);
2518 }
2519 
2520 static Z_Records *pack_records(association *a, char *setname, Odr_int start,
2521  Odr_int *num, Z_RecordComposition *comp,
2522  Odr_int *next, Odr_int *pres,
2523  Z_ReferenceId *referenceId,
2524  Odr_oid *oid, int *errcode)
2525 {
2526  int recno;
2527  Odr_int dumped_records = 0;
2528  int toget = odr_int_to_int(*num);
2529  Z_Records *records =
2530  (Z_Records *) odr_malloc(a->encode, sizeof(*records));
2531  Z_NamePlusRecordList *reclist =
2532  (Z_NamePlusRecordList *) odr_malloc(a->encode, sizeof(*reclist));
2533 
2534  records->which = Z_Records_DBOSD;
2535  records->u.databaseOrSurDiagnostics = reclist;
2536  reclist->num_records = 0;
2537 
2538  if (toget < 0)
2540  else if (toget == 0)
2541  reclist->records = odr_nullval();
2542  else
2543  reclist->records = (Z_NamePlusRecord **)
2544  odr_malloc(a->encode, sizeof(*reclist->records) * toget);
2545 
2546  *pres = Z_PresentStatus_success;
2547  *num = 0;
2548  *next = 0;
2549 
2550  yaz_log(log_requestdetail, "Request to pack " ODR_INT_PRINTF "+%d %s", start, toget, setname);
2551  yaz_log(log_requestdetail, "pms=%d, mrs=%d", a->preferredMessageSize,
2552  a->maximumRecordSize);
2553  for (recno = odr_int_to_int(start); reclist->num_records < toget; recno++)
2554  {
2555  bend_fetch_rr freq;
2556  Z_NamePlusRecord *thisrec;
2557  Odr_int this_length = 0;
2558  /*
2559  * we get the number of bytes allocated on the stream before any
2560  * allocation done by the backend - this should give us a reasonable
2561  * idea of the total size of the data so far.
2562  */
2563  Odr_int total_length = odr_total(a->encode) - dumped_records;
2564  freq.errcode = 0;
2565  freq.errstring = 0;
2566  freq.basename = 0;
2567  freq.len = 0;
2568  freq.record = 0;
2569  freq.last_in_set = 0;
2570  freq.setname = setname;
2571  freq.surrogate_flag = 0;
2572  freq.number = recno;
2573  freq.comp = comp;
2574  freq.request_format = oid;
2575  freq.output_format = 0;
2576  freq.stream = a->encode;
2577  freq.print = a->print;
2578  freq.referenceId = referenceId;
2579  freq.schema = 0;
2580 
2581  retrieve_fetch(a, &freq);
2582 
2583  *next = freq.last_in_set ? 0 : recno + 1;
2584 
2585  if (freq.errcode)
2586  {
2587  if (!freq.surrogate_flag) /* non-surrogate diagnostic i.e. global */
2588  {
2589  char s[20];
2590  *pres = Z_PresentStatus_failure;
2591  /* for 'present request out of range',
2592  set addinfo to record position if not set */
2594  freq.errstring == 0)
2595  {
2596  sprintf(s, "%d", recno);
2597  freq.errstring = s;
2598  }
2599  if (errcode)
2600  *errcode = freq.errcode;
2601  return diagrec(a, freq.errcode, freq.errstring);
2602  }
2603  reclist->records[reclist->num_records] =
2604  surrogatediagrec(a, freq.basename, freq.errcode,
2605  freq.errstring);
2606  reclist->num_records++;
2607  continue;
2608  }
2609  if (freq.record == 0) /* no error and no record ? */
2610  {
2611  *pres = Z_PresentStatus_partial_4;
2612  *next = 0; /* signal end-of-set and stop */
2613  break;
2614  }
2615  if (freq.len >= 0)
2616  this_length = freq.len;
2617  else
2618  this_length = odr_total(a->encode) - total_length - dumped_records;
2619  yaz_log(log_requestdetail, " fetched record, len=" ODR_INT_PRINTF
2620  " total=" ODR_INT_PRINTF " dumped=" ODR_INT_PRINTF,
2621  this_length, total_length, dumped_records);
2622  if (a->preferredMessageSize > 0 &&
2623  this_length + total_length > a->preferredMessageSize)
2624  {
2625  /* record is small enough, really */
2626  if (this_length <= a->preferredMessageSize && recno > start)
2627  {
2628  yaz_log(log_requestdetail, " Dropped last normal-sized record");
2629  *pres = Z_PresentStatus_partial_2;
2630  if (*next > 0)
2631  (*next)--;
2632  break;
2633  }
2634  /* record can only be fetched by itself */
2635  if (this_length < a->maximumRecordSize)
2636  {
2637  yaz_log(log_requestdetail, " Record > prefmsgsz");
2638  if (toget > 1)
2639  {
2640  yaz_log(YLOG_DEBUG, " Dropped it");
2641  reclist->records[reclist->num_records] =
2643  a, freq.basename,
2645  reclist->num_records++;
2646  dumped_records += this_length;
2647  continue;
2648  }
2649  }
2650  else /* too big entirely */
2651  {
2652  yaz_log(log_requestdetail, "Record > maxrcdsz "
2653  "this=" ODR_INT_PRINTF " max=%d",
2654  this_length, a->maximumRecordSize);
2655  reclist->records[reclist->num_records] =
2657  a, freq.basename,
2659  reclist->num_records++;
2660  dumped_records += this_length;
2661  continue;
2662  }
2663  }
2664 
2665  if (!(thisrec = (Z_NamePlusRecord *)
2666  odr_malloc(a->encode, sizeof(*thisrec))))
2667  return 0;
2668  thisrec->databaseName = odr_strdup_null(a->encode, freq.basename);
2670 
2671  if (!freq.output_format)
2672  {
2673  yaz_log(YLOG_WARN, "bend_fetch output_format not set");
2674  return 0;
2675  }
2676  thisrec->u.databaseRecord = z_ext_record_oid(
2677  a->encode, freq.output_format, freq.record, freq.len);
2678  if (!thisrec->u.databaseRecord)
2679  return 0;
2680  reclist->records[reclist->num_records] = thisrec;
2681  reclist->num_records++;
2682  if (freq.last_in_set)
2683  break;
2684  }
2685  *num = reclist->num_records;
2686  return records;
2687 }
2688 
2690 {
2692  bend_search_rr *bsrr =
2693  (bend_search_rr *)nmem_malloc(reqb->request_mem, sizeof(*bsrr));
2694 
2695  yaz_log(log_requestdetail, "Got SearchRequest.");
2696  bsrr->association = assoc;
2697  bsrr->referenceId = req->referenceId;
2698  bsrr->srw_sortKeys = 0;
2699  bsrr->srw_setname = 0;
2700  bsrr->srw_setnameIdleTime = 0;
2701  bsrr->estimated_hit_count = 0;
2702  bsrr->partial_resultset = 0;
2703  bsrr->extra_args = 0;
2704  bsrr->extra_response_data = 0;
2705 
2706  yaz_log(log_requestdetail, "ResultSet '%s'", req->resultSetName);
2707  if (req->databaseNames)
2708  {
2709  int i;
2710  for (i = 0; i < req->num_databaseNames; i++)
2711  yaz_log(log_requestdetail, "Database '%s'", req->databaseNames[i]);
2712  }
2713 
2715 
2716  if (assoc->init->bend_search)
2717  {
2718  bsrr->setname = req->resultSetName;
2719  bsrr->replace_set = *req->replaceIndicator;
2720  bsrr->num_bases = req->num_databaseNames;
2721  bsrr->basenames = req->databaseNames;
2722  bsrr->query = req->query;
2723  bsrr->stream = assoc->encode;
2724  nmem_transfer(odr_getmem(bsrr->stream), reqb->request_mem);
2725  bsrr->decode = assoc->decode;
2726  bsrr->print = assoc->print;
2727  bsrr->hits = 0;
2728  bsrr->errcode = 0;
2729  bsrr->errstring = NULL;
2730  bsrr->search_info = NULL;
2731  bsrr->search_input = req->additionalSearchInfo;
2732  if (!bsrr->search_input)
2733  bsrr->search_input = req->otherInfo;
2734  bsrr->present_number = *req->mediumSetPresentNumber;
2735 
2736  if (assoc->server && assoc->server->client_query_charset &&
2737  req->query->which == Z_Query_type_1)
2738  {
2739  yaz_iconv_t cd =
2740  yaz_iconv_open("UTF-8", assoc->server->client_query_charset);
2741  if (cd)
2742  {
2744  assoc->decode, cd);
2745  yaz_iconv_close(cd);
2746  }
2747  }
2748 
2749  if (assoc->server && assoc->server->cql_transform
2750  && req->query->which == Z_Query_type_104
2751  && req->query->u.type_104->which == Z_External_CQL)
2752  {
2753  /* have a CQL query and a CQL to PQF transform .. */
2754  int srw_errcode =
2755  cql2pqf(bsrr->stream, req->query->u.type_104->u.cql,
2756  assoc->server->cql_transform, bsrr->query,
2757  &bsrr->srw_sortKeys);
2758  if (srw_errcode)
2759  bsrr->errcode = yaz_diag_srw_to_bib1(srw_errcode);
2760  }
2761 
2762  if (assoc->server && assoc->server->ccl_transform
2763  && req->query->which == Z_Query_type_2) /*CCL*/
2764  {
2765  /* have a CCL query and a CCL to PQF transform .. */
2766  int srw_errcode =
2767  ccl2pqf(bsrr->stream, req->query->u.type_2,
2768  assoc->server->ccl_transform, bsrr);
2769  if (srw_errcode)
2770  bsrr->errcode = yaz_diag_srw_to_bib1(srw_errcode);
2771  }
2772 
2773  if (!bsrr->errcode)
2774  (assoc->init->bend_search)(assoc->backend, bsrr);
2775  }
2776  else
2777  {
2778  /* FIXME - make a diagnostic for it */
2779  yaz_log(YLOG_WARN,"Search not supported ?!?!");
2780  }
2781  return response_searchRequest(assoc, reqb, bsrr);
2782 }
2783 
2784 /*
2785  * Prepare a searchresponse based on the backend results. We probably want
2786  * to look at making the fetching of records nonblocking as well, but
2787  * so far, we'll keep things simple.
2788  * If bsrt is null, that means we're called in response to a communications
2789  * event, and we'll have to get the response for ourselves.
2790  */
2792  bend_search_rr *bsrt)
2793 {
2795  Z_APDU *apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu));
2797  odr_malloc(assoc->encode, sizeof(*resp));
2798  Odr_int *nulint = odr_intdup(assoc->encode, 0);
2799  Odr_int *next = odr_intdup(assoc->encode, 0);
2801  Odr_int returnedrecs = 0;
2802 
2803  apdu->which = Z_APDU_searchResponse;
2804  apdu->u.searchResponse = resp;
2805  resp->referenceId = req->referenceId;
2806  resp->additionalSearchInfo = 0;
2807  resp->otherInfo = 0;
2808  if (!bsrt)
2809  {
2810  yaz_log(YLOG_FATAL, "Bad result from backend");
2811  return 0;
2812  }
2813  else if (bsrt->errcode)
2814  {
2815  resp->records = diagrec(assoc, bsrt->errcode, bsrt->errstring);
2816  resp->resultCount = nulint;
2817  resp->numberOfRecordsReturned = nulint;
2818  resp->nextResultSetPosition = nulint;
2819  resp->searchStatus = odr_booldup(assoc->encode, 0);
2820  resp->resultSetStatus = none;
2821  resp->presentStatus = 0;
2822  }
2823  else
2824  {
2825  bool_t *sr = odr_booldup(assoc->encode, 1);
2826  Odr_int *toget = odr_intdup(assoc->encode, 0);
2827  Z_RecordComposition comp, *compp = 0;
2828 
2829  yaz_log(log_requestdetail, "resultCount: " ODR_INT_PRINTF, bsrt->hits);
2830 
2831  resp->records = 0;
2832  resp->resultCount = &bsrt->hits;
2833 
2834  comp.which = Z_RecordComp_simple;
2835  /* how many records does the user agent want, then? */
2836  if (bsrt->hits < 0)
2837  *toget = 0;
2838  else if (bsrt->hits <= *req->smallSetUpperBound)
2839  {
2840  *toget = bsrt->hits;
2841  if ((comp.u.simple = req->smallSetElementSetNames))
2842  compp = &comp;
2843  }
2844  else if (bsrt->hits < *req->largeSetLowerBound)
2845  {
2846  *toget = *req->mediumSetPresentNumber;
2847  if (*toget > bsrt->hits)
2848  *toget = bsrt->hits;
2849  if ((comp.u.simple = req->mediumSetElementSetNames))
2850  compp = &comp;
2851  }
2852  else
2853  *toget = 0;
2854 
2855  if (*toget && !resp->records)
2856  {
2857  Odr_int *presst = odr_intdup(assoc->encode, 0);
2858  /* Call bend_present if defined */
2859  if (assoc->init->bend_present)
2860  {
2861  bend_present_rr *bprr = (bend_present_rr *)
2862  nmem_malloc(reqb->request_mem, sizeof(*bprr));
2863  bprr->setname = req->resultSetName;
2864  bprr->start = 1;
2865  bprr->number = odr_int_to_int(*toget);
2866  bprr->format = req->preferredRecordSyntax;
2867  bprr->comp = compp;
2868  bprr->referenceId = req->referenceId;
2869  bprr->stream = assoc->encode;
2870  bprr->print = assoc->print;
2871  bprr->association = assoc;
2872  bprr->errcode = 0;
2873  bprr->errstring = NULL;
2874  (*assoc->init->bend_present)(assoc->backend, bprr);
2875 
2876  if (bprr->errcode)
2877  {
2878  resp->records = diagrec(assoc, bprr->errcode, bprr->errstring);
2880  }
2881  }
2882 
2883  if (!resp->records)
2884  resp->records = pack_records(
2885  assoc, req->resultSetName, 1,
2886  toget, compp, next, presst, req->referenceId,
2887  req->preferredRecordSyntax, NULL);
2888  if (!resp->records)
2889  return 0;
2890  resp->numberOfRecordsReturned = toget;
2891  returnedrecs = *toget;
2892  resp->presentStatus = presst;
2893  }
2894  else
2895  {
2896  if (*resp->resultCount)
2897  *next = 1;
2898  resp->numberOfRecordsReturned = nulint;
2899  resp->presentStatus = 0;
2900  }
2901  resp->nextResultSetPosition = next;
2902  resp->searchStatus = sr;
2903  resp->resultSetStatus = 0;
2904  if (bsrt->estimated_hit_count)
2905  {
2906  resp->resultSetStatus = odr_intdup(assoc->encode,
2908  }
2909  else if (bsrt->partial_resultset)
2910  {
2911  resp->resultSetStatus = odr_intdup(assoc->encode,
2913  }
2914  }
2915  resp->additionalSearchInfo = bsrt->search_info;
2916 
2917  if (log_request)
2918  {
2919  int i;
2920  WRBUF wr = wrbuf_alloc();
2921 
2922  for (i = 0 ; i < req->num_databaseNames; i++)
2923  {
2924  if (i)
2925  wrbuf_printf(wr, "+");
2926  wrbuf_puts(wr, req->databaseNames[i]);
2927  }
2928  wrbuf_printf(wr, " ");
2929 
2930  if (bsrt->errcode)
2931  wrbuf_printf(wr, "ERROR %d", bsrt->errcode);
2932  else
2933  wrbuf_printf(wr, "OK " ODR_INT_PRINTF, bsrt->hits);
2934  wrbuf_printf(wr, " %s 1+" ODR_INT_PRINTF " ",
2935  req->resultSetName, returnedrecs);
2936  yaz_query_to_wrbuf(wr, req->query);
2937 
2938  yaz_log(log_request, "Search %s", wrbuf_cstr(wr));
2939  wrbuf_destroy(wr);
2940  }
2941  return apdu;
2942 }
2943 
2944 /*
2945  * Maybe we got a little over-friendly when we designed bend_fetch to
2946  * get only one record at a time. Some backends can optimise multiple-record
2947  * fetches, and at any rate, there is some overhead involved in
2948  * all that selecting and hopping around. Problem is, of course, that the
2949  * frontend can't know ahead of time how many records it'll need to
2950  * fill the negotiated PDU size. Annoying. Segmentation or not, Z/SR
2951  * is downright lousy as a bulk data transfer protocol.
2952  *
2953  * To start with, we'll do the fetching of records from the backend
2954  * in one operation: To save some trips in and out of the event-handler,
2955  * and to simplify the interface to pack_records. At any rate, asynch
2956  * operation is more fun in operations that have an unpredictable execution
2957  * speed - which is normally more true for search than for present.
2958  */
2960 {
2962  Z_APDU *apdu;
2963  Z_PresentResponse *resp;
2964  Odr_int *next;
2965  Odr_int *num;
2966  int errcode = 0;
2967 
2968  yaz_log(log_requestdetail, "Got PresentRequest.");
2969 
2970  resp = (Z_PresentResponse *)odr_malloc(assoc->encode, sizeof(*resp));
2971  resp->records = 0;
2972  resp->presentStatus = odr_intdup(assoc->encode, 0);
2973  if (assoc->init->bend_present)
2974  {
2975  bend_present_rr *bprr = (bend_present_rr *)
2976  nmem_malloc(reqb->request_mem, sizeof(*bprr));
2977  bprr->setname = req->resultSetId;
2978  bprr->start = odr_int_to_int(*req->resultSetStartPoint);
2980  bprr->format = req->preferredRecordSyntax;
2981  bprr->comp = req->recordComposition;
2982  bprr->referenceId = req->referenceId;
2983  bprr->stream = assoc->encode;
2984  bprr->print = assoc->print;
2985  bprr->association = assoc;
2986  bprr->errcode = 0;
2987  bprr->errstring = NULL;
2988  (*assoc->init->bend_present)(assoc->backend, bprr);
2989 
2990  if (bprr->errcode)
2991  {
2992  resp->records = diagrec(assoc, bprr->errcode, bprr->errstring);
2994  errcode = bprr->errcode;
2995  }
2996  }
2997  apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu));
2998  next = odr_intdup(assoc->encode, 0);
2999  num = odr_intdup(assoc->encode, 0);
3000 
3001  apdu->which = Z_APDU_presentResponse;
3002  apdu->u.presentResponse = resp;
3003  resp->referenceId = req->referenceId;
3004  resp->otherInfo = 0;
3005 
3006  if (!resp->records)
3007  {
3008  *num = *req->numberOfRecordsRequested;
3009  resp->records =
3010  pack_records(assoc, req->resultSetId, *req->resultSetStartPoint,
3011  num, req->recordComposition, next,
3012  resp->presentStatus,
3014  &errcode);
3015  }
3016  if (log_request)
3017  {
3018  WRBUF wr = wrbuf_alloc();
3019  wrbuf_printf(wr, "Present ");
3020 
3021  if (*resp->presentStatus == Z_PresentStatus_failure)
3022  wrbuf_printf(wr, "ERROR %d ", errcode);
3023  else if (*resp->presentStatus == Z_PresentStatus_success)
3024  wrbuf_printf(wr, "OK - ");
3025  else
3026  wrbuf_printf(wr, "Partial " ODR_INT_PRINTF " - ",
3027  *resp->presentStatus);
3028 
3029  wrbuf_printf(wr, " %s " ODR_INT_PRINTF "+" ODR_INT_PRINTF " ",
3030  req->resultSetId, *req->resultSetStartPoint,
3031  *req->numberOfRecordsRequested);
3032  yaz_log(log_request, "%s", wrbuf_cstr(wr) );
3033  wrbuf_destroy(wr);
3034  }
3035  if (!resp->records)
3036  return 0;
3037  resp->numberOfRecordsReturned = num;
3038  resp->nextResultSetPosition = next;
3039 
3040  return apdu;
3041 }
3042 
3043 /*
3044  * Scan was implemented rather in a hurry, and with support for only the basic
3045  * elements of the service in the backend API. Suggestions are welcome.
3046  */
3048 {
3049  Z_ScanRequest *req = reqb->apdu_request->u.scanRequest;
3050  Z_APDU *apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu));
3051  Z_ScanResponse *res = (Z_ScanResponse *)
3052  odr_malloc(assoc->encode, sizeof(*res));
3053  Odr_int *scanStatus = odr_intdup(assoc->encode, Z_Scan_failure);
3054  Odr_int *numberOfEntriesReturned = odr_intdup(assoc->encode, 0);
3055  Z_ListEntries *ents = (Z_ListEntries *)
3056  odr_malloc(assoc->encode, sizeof(*ents));
3057  Z_DiagRecs *diagrecs_p = NULL;
3058  bend_scan_rr *bsrr = (bend_scan_rr *)
3059  odr_malloc(assoc->encode, sizeof(*bsrr));
3060  struct scan_entry *save_entries;
3061  int step_size = 0;
3062 
3063  yaz_log(log_requestdetail, "Got ScanRequest");
3064 
3065  apdu->which = Z_APDU_scanResponse;
3066  apdu->u.scanResponse = res;
3067  res->referenceId = req->referenceId;
3068 
3069  /* if step is absent, set it to 0 */
3070  if (req->stepSize)
3071  step_size = odr_int_to_int(*req->stepSize);
3072 
3073  res->stepSize = 0;
3074  res->scanStatus = scanStatus;
3075  res->numberOfEntriesReturned = numberOfEntriesReturned;
3076  res->positionOfTerm = 0;
3077  res->entries = ents;
3078  ents->num_entries = 0;
3079  ents->entries = NULL;
3080  ents->num_nonsurrogateDiagnostics = 0;
3081  ents->nonsurrogateDiagnostics = NULL;
3082  res->attributeSet = 0;
3083  res->otherInfo = 0;
3084 
3085  if (req->databaseNames)
3086  {
3087  int i;
3088  for (i = 0; i < req->num_databaseNames; i++)
3089  yaz_log(log_requestdetail, "Database '%s'", req->databaseNames[i]);
3090  }
3091  bsrr->scanClause = 0;
3092  bsrr->errcode = 0;
3093  bsrr->errstring = 0;
3094  bsrr->num_bases = req->num_databaseNames;
3095  bsrr->basenames = req->databaseNames;
3097  bsrr->term = req->termListAndStartPoint;
3098  bsrr->referenceId = req->referenceId;
3099  bsrr->stream = assoc->encode;
3100  bsrr->print = assoc->print;
3101  bsrr->step_size = &step_size;
3102  bsrr->setname = yaz_oi_get_string_oid(&req->otherInfo,
3104  bsrr->entries = 0;
3105  bsrr->extra_args = 0;
3106  bsrr->extra_response_data = 0;
3107  /* For YAZ 2.0 and earlier it was the backend handler that
3108  initialized entries (member display_term did not exist)
3109  YAZ 2.0 and later sets 'entries' and initialize all members
3110  including 'display_term'. If YAZ 2.0 or later sees that
3111  entries was modified - we assume that it is an old handler and
3112  that 'display_term' is _not_ set.
3113  */
3114  if (bsrr->num_entries > 0)
3115  {
3116  int i;
3117  bsrr->entries = (struct scan_entry *)
3118  odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
3119  bsrr->num_entries);
3120  for (i = 0; i<bsrr->num_entries; i++)
3121  {
3122  bsrr->entries[i].term = 0;
3123  bsrr->entries[i].occurrences = 0;
3124  bsrr->entries[i].errcode = 0;
3125  bsrr->entries[i].errstring = 0;
3126  bsrr->entries[i].display_term = 0;
3127  }
3128  }
3129  save_entries = bsrr->entries; /* save it so we can compare later */
3130 
3131  bsrr->attributeset = req->attributeSet;
3133  bsrr->attributeset);
3136 
3137  ((int (*)(void *, bend_scan_rr *))
3138  (*assoc->init->bend_scan))(assoc->backend, bsrr);
3139 
3140  if (bsrr->errcode)
3141  diagrecs_p = zget_DiagRecs(assoc->encode,
3142  bsrr->errcode, bsrr->errstring);
3143  else
3144  {
3145  int i;
3146  Z_Entry **tab = (Z_Entry **)
3147  odr_malloc(assoc->encode, sizeof(*tab) * bsrr->num_entries);
3148 
3149  if (bsrr->status == BEND_SCAN_PARTIAL)
3150  *scanStatus = Z_Scan_partial_5;
3151  else
3152  *scanStatus = Z_Scan_success;
3153  res->stepSize = odr_intdup(assoc->encode, step_size);
3154  ents->entries = tab;
3155  ents->num_entries = bsrr->num_entries;
3157  ents->num_entries);
3158  res->positionOfTerm = odr_intdup(assoc->encode, bsrr->term_position);
3159  for (i = 0; i < bsrr->num_entries; i++)
3160  {
3161  Z_Entry *e;
3162  Z_TermInfo *t;
3163 
3164  tab[i] = e = (Z_Entry *)odr_malloc(assoc->encode, sizeof(*e));
3165  if (bsrr->entries[i].occurrences >= 0)
3166  {
3167  e->which = Z_Entry_termInfo;
3168  e->u.termInfo = t = (Z_TermInfo *)
3169  odr_malloc(assoc->encode, sizeof(*t));
3170  t->suggestedAttributes = 0;
3171  t->displayTerm = 0;
3172  if (save_entries == bsrr->entries &&
3173  bsrr->entries[i].display_term)
3174  {
3175  /* the entries was _not_ set by the handler. So it's
3176  safe to test for new member display_term. It is
3177  NULL'ed by us.
3178  */
3179  t->displayTerm = odr_strdup(assoc->encode,
3180  bsrr->entries[i].display_term);
3181  }
3182  t->alternativeTerm = 0;
3183  t->byAttributes = 0;
3184  t->otherTermInfo = 0;
3185  t->globalOccurrences = &bsrr->entries[i].occurrences;
3186  t->term = (Z_Term *)
3187  odr_malloc(assoc->encode, sizeof(*t->term));
3188  t->term->which = Z_Term_general;
3189  t->term->u.general =
3190  odr_create_Odr_oct(assoc->encode,
3191  bsrr->entries[i].term,
3192  strlen(bsrr->entries[i].term));
3193  yaz_log(YLOG_DEBUG, " term #%d: '%s' (" ODR_INT_PRINTF ")", i,
3194  bsrr->entries[i].term, bsrr->entries[i].occurrences);
3195  }
3196  else
3197  {
3198  Z_DiagRecs *drecs = zget_DiagRecs(assoc->encode,
3199  bsrr->entries[i].errcode,
3200  bsrr->entries[i].errstring);
3201  assert(drecs->num_diagRecs == 1);
3203  assert(drecs->diagRecs[0]);
3204  e->u.surrogateDiagnostic = drecs->diagRecs[0];
3205  }
3206  }
3207  }
3208  if (diagrecs_p)
3209  {
3210  ents->num_nonsurrogateDiagnostics = diagrecs_p->num_diagRecs;
3211  ents->nonsurrogateDiagnostics = diagrecs_p->diagRecs;
3212  }
3213  if (log_request)
3214  {
3215  int i;
3216  WRBUF wr = wrbuf_alloc();
3217  wrbuf_printf(wr, "Scan ");
3218  for (i = 0 ; i < req->num_databaseNames; i++)
3219  {
3220  if (i)
3221  wrbuf_printf(wr, "+");
3222  wrbuf_puts(wr, req->databaseNames[i]);
3223  }
3224 
3225  wrbuf_printf(wr, " ");
3226 
3227  if (bsrr->errcode)
3228  wr_diag(wr, bsrr->errcode, bsrr->errstring);
3229  else
3230  wrbuf_printf(wr, "OK");
3231 
3232  wrbuf_printf(wr, " " ODR_INT_PRINTF " - " ODR_INT_PRINTF "+"
3235  *res->numberOfEntriesReturned : 0,
3237  *req->preferredPositionInResponse : 1),
3238  *req->numberOfTermsRequested,
3239  (res->stepSize ? *res->stepSize : 1));
3240 
3241  if (bsrr->setname)
3242  wrbuf_printf(wr, "+%s", bsrr->setname);
3243 
3244  wrbuf_printf(wr, " ");
3246  bsrr->attributeset);
3247  yaz_log(log_request, "%s", wrbuf_cstr(wr) );
3248  wrbuf_destroy(wr);
3249  }
3250  return apdu;
3251 }
3252 
3254 {
3255  int i;
3256  Z_SortRequest *req = reqb->apdu_request->u.sortRequest;
3257  Z_SortResponse *res = (Z_SortResponse *)
3258  odr_malloc(assoc->encode, sizeof(*res));
3259  bend_sort_rr *bsrr = (bend_sort_rr *)
3260  odr_malloc(assoc->encode, sizeof(*bsrr));
3261 
3262  Z_APDU *apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu));
3263 
3264  yaz_log(log_requestdetail, "Got SortRequest.");
3265 
3267  for (i=0;i<req->num_inputResultSetNames;i++)
3268  yaz_log(log_requestdetail, "Input resultset: '%s'",
3269  req->inputResultSetNames[i]);
3270  bsrr->input_setnames = req->inputResultSetNames;
3271  bsrr->referenceId = req->referenceId;
3272  bsrr->output_setname = req->sortedResultSetName;
3273  yaz_log(log_requestdetail, "Output resultset: '%s'",
3274  req->sortedResultSetName);
3275  bsrr->sort_sequence = req->sortSequence;
3276  /*FIXME - dump those sequences too */
3277  bsrr->stream = assoc->encode;
3278  bsrr->print = assoc->print;
3279 
3281  bsrr->errcode = 0;
3282  bsrr->errstring = 0;
3283 
3284  (*assoc->init->bend_sort)(assoc->backend, bsrr);
3285 
3286  res->referenceId = bsrr->referenceId;
3287  res->sortStatus = odr_intdup(assoc->encode, bsrr->sort_status);
3288  res->resultSetStatus = 0;
3289  if (bsrr->errcode)
3290  {
3291  Z_DiagRecs *dr = zget_DiagRecs(assoc->encode,
3292  bsrr->errcode, bsrr->errstring);
3293  res->diagnostics = dr->diagRecs;
3294  res->num_diagnostics = dr->num_diagRecs;
3295  }
3296  else
3297  {
3298  res->num_diagnostics = 0;
3299  res->diagnostics = 0;
3300  }
3301  res->resultCount = 0;
3302  res->otherInfo = 0;
3303 
3304  apdu->which = Z_APDU_sortResponse;
3305  apdu->u.sortResponse = res;
3306  if (log_request)
3307  {
3308  WRBUF wr = wrbuf_alloc();
3309  wrbuf_printf(wr, "Sort ");
3310  if (bsrr->errcode)
3311  wrbuf_printf(wr, " ERROR %d", bsrr->errcode);
3312  else
3313  wrbuf_printf(wr, "OK -");
3314  wrbuf_printf(wr, " (");
3315  for (i = 0; i<req->num_inputResultSetNames; i++)
3316  {
3317  if (i)
3318  wrbuf_printf(wr, "+");
3319  wrbuf_puts(wr, req->inputResultSetNames[i]);
3320  }
3321  wrbuf_printf(wr, ")->%s ",req->sortedResultSetName);
3322 
3323  yaz_log(log_request, "%s", wrbuf_cstr(wr) );
3324  wrbuf_destroy(wr);
3325  }
3326  return apdu;
3327 }
3328 
3330 {
3331  int i;
3335  odr_malloc(assoc->encode, sizeof(*res));
3336  bend_delete_rr *bdrr = (bend_delete_rr *)
3337  odr_malloc(assoc->encode, sizeof(*bdrr));
3338  Z_APDU *apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu));
3339 
3340  yaz_log(log_requestdetail, "Got DeleteRequest.");
3341 
3342  bdrr->num_setnames = req->num_resultSetList;
3343  bdrr->setnames = req->resultSetList;
3344  for (i = 0; i<req->num_resultSetList; i++)
3345  yaz_log(log_requestdetail, "resultset: '%s'",
3346  req->resultSetList[i]);
3347  bdrr->stream = assoc->encode;
3348  bdrr->print = assoc->print;
3349  bdrr->function = odr_int_to_int(*req->deleteFunction);
3350  bdrr->referenceId = req->referenceId;
3351  bdrr->statuses = 0;
3352  if (bdrr->num_setnames > 0)
3353  {
3354  bdrr->statuses = (int*)
3355  odr_malloc(assoc->encode, sizeof(*bdrr->statuses) *
3356  bdrr->num_setnames);
3357  for (i = 0; i < bdrr->num_setnames; i++)
3358  bdrr->statuses[i] = 0;
3359  }
3360  (*assoc->init->bend_delete)(assoc->backend, bdrr);
3361 
3362  res->referenceId = req->referenceId;
3363 
3365 
3366  res->deleteListStatuses = 0;
3367  if (bdrr->num_setnames > 0)
3368  {
3369  int i;
3371  odr_malloc(assoc->encode, sizeof(*res->deleteListStatuses));
3372  res->deleteListStatuses->num = bdrr->num_setnames;
3374  (Z_ListStatus **)
3375  odr_malloc(assoc->encode,
3376  sizeof(*res->deleteListStatuses->elements) *
3377  bdrr->num_setnames);
3378  for (i = 0; i<bdrr->num_setnames; i++)
3379  {
3380  res->deleteListStatuses->elements[i] =
3381  (Z_ListStatus *)
3382  odr_malloc(assoc->encode,
3383  sizeof(**res->deleteListStatuses->elements));
3384  res->deleteListStatuses->elements[i]->status =
3385  odr_intdup(assoc->encode, bdrr->statuses[i]);
3386  res->deleteListStatuses->elements[i]->id =
3387  odr_strdup(assoc->encode, bdrr->setnames[i]);
3388  }
3389  }
3390  res->numberNotDeleted = 0;
3391  res->bulkStatuses = 0;
3392  res->deleteMessage = 0;
3393  res->otherInfo = 0;
3394 
3396  apdu->u.deleteResultSetResponse = res;
3397  if (log_request)
3398  {
3399  WRBUF wr = wrbuf_alloc();
3400  wrbuf_printf(wr, "Delete ");
3401  if (bdrr->delete_status)
3402  wrbuf_printf(wr, "ERROR %d", bdrr->delete_status);
3403  else
3404  wrbuf_printf(wr, "OK -");
3405  for (i = 0; i<req->num_resultSetList; i++)
3406  wrbuf_printf(wr, " %s ", req->resultSetList[i]);
3407  yaz_log(log_request, "%s", wrbuf_cstr(wr) );
3408  wrbuf_destroy(wr);
3409  }
3410  return apdu;
3411 }
3412 
3413 static void process_close(association *assoc, request *reqb)
3414 {
3415  Z_Close *req = reqb->apdu_request->u.close;
3416  static char *reasons[] =
3417  {
3418  "finished",
3419  "shutdown",
3420  "systemProblem",
3421  "costLimit",
3422  "resources",
3423  "securityViolation",
3424  "protocolError",
3425  "lackOfActivity",
3426  "peerAbort",
3427  "unspecified"
3428  };
3429 
3430  yaz_log(log_requestdetail, "Got Close, reason %s, message %s",
3431  reasons[*req->closeReason], req->diagnosticInformation ?
3432  req->diagnosticInformation : "NULL");
3433  if (assoc->version < 3) /* to make do_force respond with close */
3434  assoc->version = 3;
3436  "Association terminated by client", reqb);
3437  yaz_log(log_request,"Close OK");
3438 }
3439 
3441 {
3442  bend_segment_rr req;
3443 
3444  req.segment = reqb->apdu_request->u.segmentRequest;
3445  req.stream = assoc->encode;
3446  req.decode = assoc->decode;
3447  req.print = assoc->print;
3448  req.association = assoc;
3449 
3450  (*assoc->init->bend_segment)(assoc->backend, &req);
3451 
3452  return 0;
3453 }
3454 
3456 {
3457  bend_esrequest_rr esrequest;
3458  char oidname_buf[OID_STR_MAX];
3459  const char *ext_name = "unknown";
3460 
3463  Z_External *ext =
3466 
3468 
3469  esrequest.esr = reqb->apdu_request->u.extendedServicesRequest;
3470  esrequest.stream = assoc->encode;
3471  esrequest.decode = assoc->decode;
3472  esrequest.print = assoc->print;
3473  esrequest.errcode = 0;
3474  esrequest.errstring = NULL;
3475  esrequest.association = assoc;
3476  esrequest.taskPackage = 0;
3477  esrequest.taskPackageExt = 0;
3478  esrequest.referenceId = req->referenceId;
3479 
3480  if (ext)
3481  {
3482  oid_class oclass;
3483  ext_name = yaz_oid_to_string_buf(ext->direct_reference, &oclass,
3484  oidname_buf);
3485  }
3486 
3487  (*assoc->init->bend_esrequest)(assoc->backend, &esrequest);
3488 
3489  resp->referenceId = req->referenceId;
3490 
3491  if (esrequest.errcode == -1)
3492  {
3493  /* Backend service indicates request will be processed */
3494  yaz_log(log_request, "Extended Service: %s (accepted)", ext_name);
3496  }
3497  else if (esrequest.errcode == 0)
3498  {
3499  /* Backend service indicates request will be processed */
3500  yaz_log(log_request, "Extended Service: %s (done)", ext_name);
3502  }
3503  else if (esrequest.errcode == -2)
3504  {
3505  Z_DiagRecs *diagRecs =
3506  zget_DiagRecs(assoc->encode, 401, esrequest.errstring);
3507  yaz_log(log_request, "Extended Service: %s (401)", ext_name);
3509  resp->num_diagnostics = diagRecs->num_diagRecs;
3510  resp->diagnostics = diagRecs->diagRecs;
3511  if (log_request)
3512  {
3513  WRBUF wr = wrbuf_alloc();
3514  wrbuf_diags(wr, resp->num_diagnostics, resp->diagnostics);
3515  yaz_log(log_request, "EsRequest %s", wrbuf_cstr(wr) );
3516  wrbuf_destroy(wr);
3517  }
3518  }
3519  else
3520  {
3521  Z_DiagRecs *diagRecs =
3522  zget_DiagRecs(assoc->encode, esrequest.errcode,
3523  esrequest.errstring);
3524  /* Backend indicates error, request will not be processed */
3525  yaz_log(log_request, "Extended Service: %s (failed)", ext_name);
3527  resp->num_diagnostics = diagRecs->num_diagRecs;
3528  resp->diagnostics = diagRecs->diagRecs;
3529  if (log_request)
3530  {
3531  WRBUF wr = wrbuf_alloc();
3532  wrbuf_diags(wr, resp->num_diagnostics, resp->diagnostics);
3533  yaz_log(log_request, "EsRequest %s", wrbuf_cstr(wr) );
3534  wrbuf_destroy(wr);
3535  }
3536 
3537  }
3538  /* Do something with the members of bend_extendedservice */
3539  resp->taskPackage = esrequest.taskPackageExt;
3540  if (esrequest.taskPackage)
3541  {
3542  resp->taskPackage = z_ext_record_oid(
3544  (const char *) esrequest.taskPackage, -1);
3545  }
3546  yaz_log(YLOG_DEBUG,"Send the result apdu");
3547  return apdu;
3548 }
3549 
3551 {
3552  if (assoc->state == ASSOC_DEAD)
3553  return 0; /* already marked as dead. Don't check I/O chan anymore */
3554 
3555  return iochan_is_alive(assoc->client_chan);
3556 }
3557 
3558 
3559 /*
3560  * Local variables:
3561  * c-basic-offset: 4
3562  * c-file-style: "Stroustrup"
3563  * indent-tabs-mode: nil
3564  * End:
3565  * vim: shiftwidth=4 tabstop=8 expandtab
3566  */
3567 
Header for GFS.
@ BEND_SCAN_PARTIAL
Definition: backend.h:129
const char * ccl_err_msg(int ccl_errno)
Definition: cclerrms.c:36
struct ccl_rpn_node * ccl_find_str(CCL_bibset bibset, const char *str, int *error, int *pos)
parse CCL find string using CCL profile return RPN tree
Definition: cclfind.c:1310
Z_External * yaz_set_proposal_charneg(ODR o, const char **charsets, int num_charsets, const char **langs, int num_langs, int selected)
Definition: charneg.c:152
Z_External * yaz_set_response_charneg(ODR o, const char *charset, const char *lang, int selected)
Definition: charneg.c:241
Z_CharSetandLanguageNegotiation * yaz_get_charneg_record(Z_OtherInformation *p)
Definition: charneg.c:260
Header for Z39.50 Charset negotiation utilities.
const char * cs_errmsg(int n)
Definition: comstack.c:36
Header for COMSTACK.
#define cs_addrstr(handle)
Definition: comstack.h:108
#define cs_close(handle)
Definition: comstack.h:99
#define cs_accept(handle)
Definition: comstack.h:98
#define cs_errno(handle)
Definition: comstack.h:106
#define cs_put(handle, buf, size)
Definition: comstack.h:90
#define cs_more(handle)
Definition: comstack.h:92
#define CS_WANT_READ
Definition: comstack.h:114
#define cs_get(handle, buf, size)
Definition: comstack.h:91
#define cs_getproto(handle)
Definition: comstack.h:107
#define CSBUFSIZE
Definition: comstack.h:162
#define CS_WANT_WRITE
Definition: comstack.h:115
static int node(struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
Definition: cql2ccl.c:86
struct cql_node * cql_parser_result(CQL_parser cp)
returns the parse tree of the most recently parsed CQL query.
Definition: cql.c:1902
void cql_parser_destroy(CQL_parser cp)
destroys a CQL parser.
Definition: cql.c:1895
CQL_parser cql_parser_create(void)
creates a CQL parser.
Definition: cql.c:1880
int cql_sortby_to_sortkeys_buf(struct cql_node *cn, char *out, int max)
converts CQL sortby to sortkeys ..
Definition: cql_sortkeys.c:120
int cql_parser_string(CQL_parser cp, const char *str)
parses a CQL query (string)
Definition: cqlstring.c:35
int cql_transform(cql_transform_t ct, struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
tranforms PQF given a CQL tree (NOT re-entrant)
Definition: cqltransform.c:987
int cql_transform_error(cql_transform_t ct, const char **addinfo)
returns additional information for last transform
int yaz_diag_bib1_to_srw(int code)
Definition: diag_map.c:203
int yaz_diag_srw_to_bib1(int code)
Definition: diag_map.c:215
const char * diagbib1_str(int code)
Definition: diagbib1.c:192
Diagnostics: Generated by csvtodiag.tcl from ./bib1.csv.
#define YAZ_BIB1_DATABASE_UNAVAILABLE
Definition: diagbib1.h:53
#define YAZ_BIB1_PERMANENT_SYSTEM_ERROR
Definition: diagbib1.h:11
#define YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_
Definition: diagbib1.h:35
#define YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE
Definition: diagbib1.h:23
#define YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS
Definition: diagbib1.h:24
#define YAZ_BIB1_RECORD_EXCEEDS_PREFERRED_MESSAGE_SIZE
Definition: diagbib1.h:26
#define YAZ_BIB1_RECORD_SYNTAX_UNSUPP
Definition: diagbib1.h:114
#define YAZ_BIB1_RECORD_EXCEEDS_MAXIMUM_RECORD_SIZE
Definition: diagbib1.h:27
#define YAZ_SRU_UPDATE_MISSING_MANDATORY_ELEMENT_RECORD_REJECTED
#define YAZ_SRU_UPDATE_UNSPECIFIED_DATABASE_ERROR
#define YAZ_SRU_UPDATE_INVALID_ACTION
#define YAZ_SRW_FIRST_RECORD_POSITION_OUT_OF_RANGE
Definition: diagsrw.h:69
#define YAZ_SRW_UNSUPP_SORT_TYPE
Definition: diagsrw.h:84
#define YAZ_SRW_UNSUPP_OPERATION
Definition: diagsrw.h:13
#define YAZ_SRW_UNSUPP_QUERY_TYPE
Definition: diagsrw.h:19
#define YAZ_SRW_AUTHENTICATION_ERROR
Definition: diagsrw.h:12
#define YAZ_SRW_QUERY_SYNTAX_ERROR
Definition: diagsrw.h:18
#define YAZ_SRW_RESULT_SET_CREATED_WITH_VALID_PARTIAL_RESULTS_AVAILABLE
Definition: diagsrw.h:67
int odr_dumpBER(FILE *f, const char *buf, int len)
Definition: dumpber.c:129
void yaz_set_esn(Z_RecordComposition **comp_p, const char *esn, NMEM nmem)
set element set name in RecordComposition struct
Definition: elementset.c:32
const char * yaz_get_esn(Z_RecordComposition *comp)
get element set name from RecordComposition
Definition: elementset.c:16
int iochan_is_alive(IOCHAN chan)
Definition: eventl.c:66
Definitions for event loop handling for GFS.
#define iochan_settimeout(i, t)
Definition: eventl.h:78
#define EVENT_TIMEOUT
Definition: eventl.h:52
#define EVENT_INPUT
Definition: eventl.h:49
#define iochan_getdata(i)
Definition: eventl.h:67
#define iochan_setevent(i, e)
Definition: eventl.h:76
#define iochan_destroy(i)
Definition: eventl.h:64
#define EVENT_OUTPUT
Definition: eventl.h:50
#define iochan_setflag(i, d)
Definition: eventl.h:71
#define EVENT_EXCEPT
Definition: eventl.h:51
#define iochan_clearflag(i, d)
Definition: eventl.h:72
Z_FacetList * yaz_oi_get_facetlist(Z_OtherInformation **otherInformation)
Definition: facet.c:44
void yaz_oi_set_facetlist(Z_OtherInformation **otherInformation, ODR odr, Z_FacetList *facet_list)
Definition: facet.c:23
Header for the facet utilities.
Z_GDU * z_get_HTTP_Response(ODR o, int code)
Definition: http.c:384
const char * z_HTTP_header_lookup(const Z_HTTP_Header *hp, const char *n)
Definition: http.c:233
void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, const char *v)
Definition: http.c:189
FILE * yaz_log_file(void)
returns FILE handle for log or NULL if no file is in use
Definition: log.c:138
void yaz_log(int level, const char *fmt,...)
Writes log message.
Definition: log.c:487
int yaz_log_module_level(const char *name)
returns level for module
Definition: log.c:586
Logging utility.
#define YLOG_WARN
log level: warning
Definition: log.h:46
#define YLOG_FATAL
log level: fatal
Definition: log.h:42
#define YLOG_ERRNO
log level: append system error message
Definition: log.h:50
#define YLOG_DEBUG
log level: debugging
Definition: log.h:44
#define YLOG_LOG
log level: log (regular)
Definition: log.h:48
void log_scan_term_level(int loglevel, Z_AttributesPlusTerm *zapt, const Odr_oid *ast)
Definition: logrpn.c:346
void yaz_log_zquery_level(int loglevel, Z_Query *q)
Definition: logrpn.c:367
Header for Z39.50 Query Printing.
yaz_marc_t yaz_marc_create(void)
construct yaz_marc_t handle
Definition: marcdisp.c:102
void yaz_marc_destroy(yaz_marc_t mt)
destroy yaz_marc_t handle
Definition: marcdisp.c:120
yaz_mime_types yaz_mime_types_create()
Definition: mime.c:30
const char * yaz_mime_lookup_fname(yaz_mime_types t, const char *fname)
Definition: mime.c:58
void yaz_mime_types_destroy(yaz_mime_types t)
Definition: mime.c:66
void yaz_mime_types_add(yaz_mime_types t, const char *suffix, const char *mime_type)
Definition: mime.c:37
Small utility to manage MIME types.
void nmem_transfer(NMEM dst, NMEM src)
transfers memory from one NMEM handle to another
Definition: nmem.c:216
void * nmem_malloc(NMEM n, size_t size)
allocates memory block on NMEM handle
Definition: nmem.c:145
int odr_geterror(ODR o)
Definition: odr.c:78
int odr_offset(ODR o)
Definition: odr.c:285
ODR odr_createmem(int direction)
Definition: odr.c:200
char * odr_errmsg(int n)
Definition: odr.c:52
void odr_setbuf(ODR o, char *buf, int len, int can_grow)
Definition: odr.c:267
void odr_setprint(ODR o, FILE *file)
Definition: odr.c:164
Odr_null * odr_nullval(void)
Definition: odr.c:30
char * odr_getbuf(ODR o, int *len, int *size)
Definition: odr.c:277
const char * odr_getelement(ODR o)
Definition: odr.c:90
void odr_destroy(ODR o)
Definition: odr.c:253
void odr_reset(ODR o)
Definition: odr.c:226
#define OHTTP
Definition: odr.h:162
#define ODR_DECODE
Definition: odr.h:95
#define ODR_MASK_SET(mask, num)
Definition: odr.h:204
#define odr_getmem(o)
Definition: odr.h:216
#define ODR_INT_PRINTF
Definition: odr.h:49
#define bool_t
Definition: odr.h:52
nmem_int_t Odr_int
Definition: odr.h:47
#define ODR_PRINT
Definition: odr.h:97
#define ODR_MASK_GET(mask, num)
Definition: odr.h:211
#define ODR_ENCODE
Definition: odr.h:96
NMEM odr_extract_mem(ODR o)
Definition: odr_mem.c:23
size_t odr_total(ODR o)
Definition: odr_mem.c:61
char * odr_strdupn(ODR o, const char *str, size_t n)
Definition: odr_mem.c:46
Odr_bool * odr_booldup(ODR o, Odr_bool v)
Definition: odr_mem.c:56
char * odr_strdup_null(ODR o, const char *str)
Definition: odr_mem.c:41
char * odr_strdup(ODR o, const char *str)
Definition: odr_mem.c:36
Odr_int * odr_intdup(ODR o, Odr_int v)
Definition: odr_mem.c:51
void * odr_malloc(ODR o, size_t size)
Definition: odr_mem.c:31
Odr_oct * odr_create_Odr_oct(ODR o, const char *buf, int sz)
Definition: odr_mem.c:66
Odr_oid * odr_oiddup(ODR odr, const Odr_oid *o)
Definition: odr_util.c:60
char * odr_prepend(ODR o, const char *prefix, const char *old)
Definition: odr_util.c:103
Odr_oid * odr_getoidbystr(ODR o, const char *str)
Definition: odr_util.c:77
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
Header for OID database.
oid_class
Definition: oid_db.h:46
const Odr_oid yaz_oid_userinfo_client_ip[]
Definition: oid_std.c:116
const Odr_oid yaz_oid_userinfo_proxy[]
Definition: oid_std.c:114
const Odr_oid yaz_oid_recsyn_xml[]
Definition: oid_std.c:89
const Odr_oid yaz_oid_userinfo_scan_set[]
Definition: oid_std.c:117
const Odr_oid yaz_oid_recsyn_extended[]
Definition: oid_std.c:73
const Odr_oid yaz_oid_recsyn_opac[]
Definition: oid_std.c:69
int oid_oidcmp(const Odr_oid *o1, const Odr_oid *o2)
compares OIDs
Definition: oid_util.c:34
char * oid_oid_to_dotstring(const Odr_oid *oid, char *oidbuf)
converts OID to string (dot notation)
Definition: oid_util.c:59
short Odr_oid
Definition: oid_util.h:42
#define OID_STR_MAX
Definition: oid_util.h:40
int options(const char *desc, char **argv, int argc, char **arg)
command-line options parsing for main
Definition: options.c:21
Z_OtherInformationUnit * yaz_oi_update(Z_OtherInformation **otherInformationP, ODR odr, const Odr_oid *oid, int categoryValue, int delete_flag)
Definition: otherinfo.c:76
char * yaz_oi_get_string_oid(Z_OtherInformation **otherInformation, const Odr_oid *oid, int categoryValue, int delete_flag)
Definition: otherinfo.c:172
Header for Z39.50 OtherInfo utilities.
void yaz_pqf_destroy(YAZ_PQF_Parser p)
Definition: pquery.c:811
YAZ_PQF_Parser yaz_pqf_create(void)
Definition: pquery.c:798
int yaz_pqf_error(YAZ_PQF_Parser p, const char **msg, size_t *off)
Definition: pquery.c:907
Z_AttributesPlusTerm * yaz_pqf_scan(YAZ_PQF_Parser p, ODR o, Odr_oid **attributeSetP, const char *qbuf)
Definition: pquery.c:824
Z_RPNQuery * yaz_pqf_parse(YAZ_PQF_Parser p, ODR o, const char *qbuf)
Definition: pquery.c:816
Header for PQF parsing.
Header for Z39.50 Protocol.
Z_External * zget_init_diagnostics(ODR odr, int error, const char *addinfo)
Creates Initialize Response diagnostics.
Definition: zget.c:546
Z_DefaultDiagFormat * zget_DefaultDiagFormat(ODR o, int error, const char *addinfo)
Creates Default Diag Format Diagnostic.
Definition: zget.c:498
Z_NamePlusRecord * zget_surrogateDiagRec(ODR o, const char *dbname, int error, const char *addinfo)
Creates Surrogate Diagnostic Records.
Definition: zget.c:529
Z_APDU * zget_APDU(ODR o, int which)
Definition: zget.c:410
Z_DiagRecs * zget_DiagRecs(ODR o, int error, const char *addinfo)
Creates Diagnostic record - Z_DiagRecs type.
Definition: zget.c:519
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
#define Z_External_CQL
Definition: prt-ext.h:93
void yaz_query_charset_convert_rpnquery(Z_RPNQuery *q, ODR o, yaz_iconv_t cd)
Query to WRBUF (to strings)
void yaz_query_to_wrbuf(WRBUF b, const Z_Query *q)
Definition: querytowrbuf.c:213
void yaz_scan_to_wrbuf(WRBUF b, const Z_AttributesPlusTerm *zapt, const Odr_oid *attrbute_set)
Definition: querytowrbuf.c:243
void wrbuf_diags(WRBUF b, int num_diagnostics, Z_DiagRec **diags)
Definition: querytowrbuf.c:251
Query to WRBUF (to strings)
const char * yaz_record_conv_get_error(yaz_record_conv_t p)
Definition: record_conv.c:1298
int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record_buf, size_t input_record_len, WRBUF output_record)
Definition: record_conv.c:1288
const char * yaz_record_get_output_charset(yaz_record_conv_t p)
Definition: record_conv.c:1229
int yaz_record_conv_opac_record(yaz_record_conv_t p, Z_OPACRecord *input_record, WRBUF output_record)
Definition: record_conv.c:1240
request * request_deq(request_q *q)
Definition: requestq.c:36
void request_release(request *r)
Definition: requestq.c:91
void request_enq(request_q *q, request *r)
Definition: requestq.c:21
void request_initq(request_q *q)
Definition: requestq.c:49
request * request_get(request_q *q)
Definition: requestq.c:67
void request_delq(request_q *q)
Definition: requestq.c:55
request * request_head(request_q *q)
Definition: requestq.c:31
const char * yaz_retrieval_get_error(yaz_retrieval_t p)
Definition: retrieval.c:402
int yaz_retrieval_request(yaz_retrieval_t p, const char *schema, const Odr_oid *syntax, const char **match_schema, Odr_oid **match_syntax, yaz_record_conv_t *rc, const char **backend_schema, Odr_oid **backend_syntax)
Definition: retrieval.c:297
static int log_session
Definition: seshigh.c:102
static Z_APDU * process_ESRequest(association *assoc, request *reqb)
Definition: seshigh.c:3455
static Z_APDU * process_presentRequest(association *assoc, request *reqb)
Definition: seshigh.c:2959
static void srw_bend_search(association *assoc, Z_HTTP_Header *headers, Z_SRW_PDU *sr, Z_SRW_PDU *res, int *http_code)
Definition: seshigh.c:924
static void do_close(association *a, int reason, char *message)
Definition: seshigh.c:259
static Z_Records * diagrec(association *assoc, int error, char *addinfo)
Definition: seshigh.c:2495
static void wr_diag(WRBUF w, int error, const char *addinfo)
Definition: seshigh.c:120
static int process_gdu_response(association *assoc, request *req, Z_GDU *res)
Definition: seshigh.c:2145
static Z_APDU * process_segmentRequest(association *assoc, request *reqb)
Definition: seshigh.c:3440
static int cql2pqf_scan(ODR odr, const char *cql, cql_transform_t ct, Z_AttributesPlusTerm *result)
Definition: seshigh.c:881
int bend_assoc_is_alive(bend_association assoc)
Definition: seshigh.c:3550
static int logbits_set
Definition: seshigh.c:101
void destroy_association(association *h)
Definition: seshigh.c:207
static Z_Records * pack_records(association *a, char *setname, Odr_int start, Odr_int *num, Z_RecordComposition *comp, Odr_int *next, Odr_int *pres, Z_ReferenceId *referenceId, Odr_oid *oid, int *errcode)
Definition: seshigh.c:2520
static Z_APDU * process_deleteRequest(association *assoc, request *reqb)
Definition: seshigh.c:3329
static int log_requestdetail
Definition: seshigh.c:105
static char * srw_bend_explain_default(bend_explain_rr *rr)
Definition: seshigh.c:1242
static int retrieve_fetch(association *assoc, bend_fetch_rr *rr)
Definition: seshigh.c:595
static Z_APDU * process_searchRequest(association *assoc, request *reqb)
Definition: seshigh.c:2689
static void do_close_req(association *a, int reason, char *message, request *req)
Definition: seshigh.c:231
association * create_association(IOCHAN channel, COMSTACK link, const char *apdufile)
Definition: seshigh.c:148
static void process_http_request(association *assoc, request *req)
Definition: seshigh.c:1792
static int log_request
Definition: seshigh.c:104
static void process_gdu_request(association *assoc, request *req)
Definition: seshigh.c:2033
static int check_path(const char *path)
Definition: seshigh.c:1746
static int process_z_request(association *assoc, request *req, char **msg)
Definition: seshigh.c:2053
static Z_APDU * process_initRequest(association *assoc, request *reqb)
Definition: seshigh.c:2211
static int cql2pqf(ODR odr, const char *cql, cql_transform_t ct, Z_Query *query_result, char **sortkeys_p)
Definition: seshigh.c:812
int ir_read(IOCHAN h, int event)
Definition: seshigh.c:266
static void srw_bend_explain(association *assoc, Z_HTTP_Header *headers, Z_SRW_PDU *sr, Z_SRW_explainResponse *srw_res, int *http_code)
Definition: seshigh.c:1278
static void assoc_init_reset(association *assoc, const char *peer_name1)
Definition: seshigh.c:483
static Z_APDU * response_searchRequest(association *assoc, request *reqb, bend_search_rr *bsrr)
Definition: seshigh.c:2791
static int process_z_response(association *assoc, request *req, Z_APDU *res)
Definition: seshigh.c:2190
static int srw_bend_fetch(association *assoc, int pos, Z_SRW_searchRetrieveRequest *srw_req, Z_SRW_record *record, const char **addinfo, int *last_in_set)
Definition: seshigh.c:726
static char * get_vhost(Z_OtherInformation *otherInfo)
Definition: seshigh.c:2199
static char * read_file(const char *fname, ODR o, long *sz)
Definition: seshigh.c:1755
static void process_close(association *assoc, request *reqb)
Definition: seshigh.c:3413
static void get_logbits(void)
Definition: seshigh.c:108
static int srw_bend_init(association *assoc, Z_HTTP_Header *headers, Z_SRW_diagnostic **d, int *num, Z_SRW_PDU *sr)
Definition: seshigh.c:532
static Z_APDU * process_sortRequest(association *assoc, request *reqb)
Definition: seshigh.c:3253
static Z_NamePlusRecord * surrogatediagrec(association *assoc, const char *dbname, int error, const char *addinfo)
Definition: seshigh.c:2511
static void srw_bend_scan(association *assoc, Z_HTTP_Header *headers, Z_SRW_PDU *sr, Z_SRW_PDU *res, int *http_code)
Definition: seshigh.c:1329
static Z_APDU * process_scanRequest(association *assoc, request *reqb)
Definition: seshigh.c:3047
void ir_session(IOCHAN h, int event)
Definition: seshigh.c:365
static int ccl2pqf(ODR odr, const Odr_oct *ccl, CCL_bibset bibset, bend_search_rr *bsrr)
Definition: seshigh.c:905
static void srw_bend_update(association *assoc, Z_HTTP_Header *headers, Z_SRW_PDU *sr, Z_SRW_updateResponse *srw_res, int *http_code)
Definition: seshigh.c:1509
static Z_External * init_diagnostics(ODR odr, int errcode, const char *errstring)
Definition: seshigh.c:2485
static int odr_int_to_int(Odr_int v)
Definition: seshigh.c:132
static int log_sessiondetail
Definition: seshigh.c:103
Internal header for GFS.
int control_association(association *assoc, const char *host, int force)
Definition: statserv.c:267
@ REQUEST_PENDING
Definition: session.h:67
@ REQUEST_IDLE
Definition: session.h:66
@ ASSOC_DEAD
Definition: session.h:103
@ ASSOC_UP
Definition: session.h:102
@ ASSOC_NEW
Definition: session.h:101
int yaz_iconv_close(yaz_iconv_t cd)
just like iconv_close(3)
Definition: siconv.c:284
yaz_iconv_t yaz_iconv_open(const char *tocode, const char *fromcode)
just like iconv_open(3)
Definition: siconv.c:95
int z_soap_codec_enc_xsl(ODR o, Z_SOAP **pp, char **content_buf, int *content_len, Z_SOAP_Handler *handlers, const char *encoding, const char *stylesheet)
Definition: soap.c:26
int z_soap_error(ODR o, Z_SOAP *p, const char *fault_code, const char *fault_string, const char *details)
Definition: soap.c:347
int(* Z_SOAP_fun)(ODR o, void *ptr, void **handler_data, void *client_data, const char *ns)
Definition: soap.h:65
int yaz_ucp_codec(ODR o, void *vptr, Z_SRW_PDU **handler_data, void *client_data, const char *ns_ucp_str)
Definition: srw.c:1144
int yaz_srw_codec(ODR o, void *vptr, Z_SRW_PDU **handler_data, void *client_data, const char *ns)
Definition: srw.c:575
Header for SRW/SRU.
#define Z_SRW_searchRetrieve_response
Definition: srw.h:192
#define Z_SRW_explain_request
Definition: srw.h:193
#define Z_SRW_update_request
Definition: srw.h:197
#define Z_SRW_scan_request
Definition: srw.h:195
#define YAZ_XMLNS_SRU_v1_1
Definition: srw.h:328
#define Z_SRW_recordPacking_string
Definition: srw.h:54
#define Z_SRW_update_response
Definition: srw.h:198
#define Z_SRW_explain_response
Definition: srw.h:194
#define YAZ_XMLNS_SRU_v1_0
Definition: srw.h:327
#define Z_SRW_scan_response
Definition: srw.h:196
#define Z_SRW_searchRetrieve_request
Definition: srw.h:191
#define YAZ_XMLNS_UPDATE_v0_9
Definition: srw.h:331
int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SOAP **soap_package, ODR decode, char **charset, Z_SRW_diagnostic **diag, int *num_diag)
Definition: srwutil.c:356
Z_SRW_PDU * yaz_srw_get_pdu_e(ODR o, int which, Z_SRW_PDU *req)
Definition: srwutil.c:761
void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d, int *num, int code, const char *addinfo)
Definition: srwutil.c:193
int yaz_srw_str_to_pack(const char *str)
Definition: srwutil.c:1224
Z_SRW_extra_record * yaz_srw_get_extra_record(ODR o)
Definition: srwutil.c:705
void yaz_add_srw_diagnostic_uri(ODR o, Z_SRW_diagnostic **d, int *num, const char *uri, const char *message, const char *details)
Definition: srwutil.c:169
void yaz_mk_sru_surrogate(ODR o, Z_SRW_record *record, int pos, int code, const char *details)
Definition: srwutil.c:203
int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SOAP **soap_package, ODR decode, char **charset)
Definition: srwutil.c:257
Z_SRW_PDU * yaz_srw_get_pdu(ODR o, int which, const char *version)
Definition: srwutil.c:816
const char * yaz_srw_pack_to_str(int pack)
Definition: srwutil.c:1210
void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d, int *num, int code, const char *addinfo)
Definition: srwutil.c:183
Z_SRW_record * yaz_srw_get_record(ODR o)
Definition: srwutil.c:733
statserv_options_block * statserv_getcontrol(void)
Definition: statserv.c:1215
Header for GFS (Obsolete. Use yaz/backend.h)
Definition: z-core.h:321
int which
Definition: z-core.h:322
Z_InitRequest * initRequest
Definition: z-core.h:324
Z_DeleteResultSetRequest * deleteResultSetRequest
Definition: z-core.h:330
Z_ScanResponse * scanResponse
Definition: z-core.h:340
Z_DeleteResultSetResponse * deleteResultSetResponse
Definition: z-core.h:331
Z_InitResponse * initResponse
Definition: z-core.h:325
Z_ExtendedServicesResponse * extendedServicesResponse
Definition: z-core.h:345
Z_ScanRequest * scanRequest
Definition: z-core.h:339
Z_SearchResponse * searchResponse
Definition: z-core.h:327
Z_Segment * segmentRequest
Definition: z-core.h:343
Z_Close * close
Definition: z-core.h:346
union Z_APDU::@43 u
Z_PresentResponse * presentResponse
Definition: z-core.h:329
Z_ExtendedServicesRequest * extendedServicesRequest
Definition: z-core.h:344
Z_SortRequest * sortRequest
Definition: z-core.h:341
Z_SearchRequest * searchRequest
Definition: z-core.h:326
Z_SortResponse * sortResponse
Definition: z-core.h:342
Z_PresentRequest * presentRequest
Definition: z-core.h:328
Z_InternationalString * diagnosticInformation
Definition: z-core.h:1172
Z_CloseReason * closeReason
Definition: z-core.h:1171
Z_DbSpecific ** dbSpecific
Definition: z-core.h:794
int num_recordSyntax
Definition: z-core.h:795
Odr_bool * selectAlternativeSyntax
Definition: z-core.h:791
Z_Specification * generic
Definition: z-core.h:792
Odr_oid ** recordSyntax
Definition: z-core.h:796
int num_dbSpecific
Definition: z-core.h:793
Z_ReferenceId * referenceId
Definition: z-core.h:821
Z_ResultSetId ** resultSetList
Definition: z-core.h:826
Odr_int * deleteFunction
Definition: z-core.h:824
Z_ListStatuses * bulkStatuses
Definition: z-core.h:835
Z_InternationalString * deleteMessage
Definition: z-core.h:836
Z_OtherInformation * otherInfo
Definition: z-core.h:837
Z_ReferenceId * referenceId
Definition: z-core.h:831
Z_ListStatuses * deleteListStatuses
Definition: z-core.h:833
Z_DeleteStatus * deleteOperationStatus
Definition: z-core.h:832
Odr_int * numberNotDeleted
Definition: z-core.h:834
int num_diagRecs
Definition: z-core.h:688
Z_DiagRec ** diagRecs
Definition: z-core.h:689
union Z_ElementSetNames::@58 u
Z_InternationalString * generic
Definition: z-core.h:771
Z_InternationalString * elementSetName
Definition: z-core.h:802
union Z_ElementSpec::@59 u
Definition: z-core.h:981
Z_TermInfo * termInfo
Definition: z-core.h:984
union Z_Entry::@63 u
Z_DiagRec * surrogateDiagnostic
Definition: z-core.h:985
int which
Definition: z-core.h:982
Z_ReferenceId * referenceId
Definition: z-core.h:1120
Z_External * taskSpecificParameters
Definition: z-core.h:1131
Z_ReferenceId * referenceId
Definition: z-core.h:1142
Z_DiagRec ** diagnostics
Definition: z-core.h:1148
Z_External * taskPackage
Definition: z-core.h:1149
structure for all known EXTERNALs
Definition: prt-ext.h:59
Z_CharSetandLanguageNegotiation * charNeg3
Definition: prt-ext.h:132
Odr_int * indirect_reference
Definition: prt-ext.h:61
Z_InternationalString * cql
Definition: prt-ext.h:138
int which
Definition: prt-ext.h:63
union Z_External::@27 u
Odr_oid * direct_reference
Definition: prt-ext.h:60
char * descriptor
Definition: prt-ext.h:62
Definition: zgdu.h:68
Z_HTTP_Request * HTTP_Request
Definition: zgdu.h:72
int which
Definition: zgdu.h:69
Z_APDU * z3950
Definition: zgdu.h:71
union Z_GDU::@132 u
Z_HTTP_Response * HTTP_Response
Definition: zgdu.h:73
Z_HTTP_Header * headers
Definition: zgdu.h:52
char * path
Definition: zgdu.h:51
char * version
Definition: zgdu.h:50
char * method
Definition: zgdu.h:49
char * content_buf
Definition: zgdu.h:61
int code
Definition: zgdu.h:58
Z_HTTP_Header * headers
Definition: zgdu.h:60
char * version
Definition: zgdu.h:59
int content_len
Definition: zgdu.h:62
Z_IdPass * idPass
Definition: z-core.h:401
union Z_IdAuthentication::@44 u
Z_InternationalString * groupId
Definition: z-core.h:392
Z_InternationalString * userId
Definition: z-core.h:393
Z_Options * options
Definition: z-core.h:380
Z_InternationalString * implementationVersion
Definition: z-core.h:386
Odr_int * maximumRecordSize
Definition: z-core.h:382
Z_IdAuthentication * idAuthentication
Definition: z-core.h:383
Z_InternationalString * implementationId
Definition: z-core.h:384
Z_ProtocolVersion * protocolVersion
Definition: z-core.h:379
Z_InternationalString * implementationName
Definition: z-core.h:385
Z_ReferenceId * referenceId
Definition: z-core.h:378
Odr_int * preferredMessageSize
Definition: z-core.h:381
Z_OtherInformation * otherInfo
Definition: z-core.h:388
Z_InternationalString * implementationId
Definition: z-core.h:418
Z_InternationalString * implementationVersion
Definition: z-core.h:420
Z_External * userInformationField
Definition: z-core.h:421
Z_Options * options
Definition: z-core.h:414
Odr_bool * result
Definition: z-core.h:417
Z_OtherInformation * otherInfo
Definition: z-core.h:422
Z_ReferenceId * referenceId
Definition: z-core.h:412
Z_InternationalString * implementationName
Definition: z-core.h:419
Odr_int * preferredMessageSize
Definition: z-core.h:415
Z_ProtocolVersion * protocolVersion
Definition: z-core.h:413
Odr_int * maximumRecordSize
Definition: z-core.h:416
Z_DiagRec ** nonsurrogateDiagnostics
Definition: z-core.h:978
int num_nonsurrogateDiagnostics
Definition: z-core.h:977
int num_entries
Definition: z-core.h:975
Z_Entry ** entries
Definition: z-core.h:976
Z_DeleteStatus * status
Definition: z-core.h:842
Z_ResultSetId * id
Definition: z-core.h:841
Z_ListStatus ** elements
Definition: z-core.h:847
Z_NamePlusRecord ** records
Definition: z-core.h:684
Z_External * databaseRecord
Definition: z-core.h:708
Z_DatabaseName * databaseName
Definition: z-core.h:705
union Z_NamePlusRecord::@54 u
union Z_Operand::@47 u
int which
Definition: z-core.h:510
Z_AttributesPlusTerm * attributesPlusTerm
Definition: z-core.h:512
Z_External * externallyDefinedInfo
Definition: z-core.h:1285
union Z_OtherInformationUnit::@71 information
Z_ResultSetId * resultSetId
Definition: z-core.h:652
Odr_int * resultSetStartPoint
Definition: z-core.h:653
Z_ReferenceId * referenceId
Definition: z-core.h:651
Odr_oid * preferredRecordSyntax
Definition: z-core.h:658
Z_RecordComposition * recordComposition
Definition: z-core.h:657
Odr_int * numberOfRecordsRequested
Definition: z-core.h:654
Z_OtherInformation * otherInfo
Definition: z-core.h:679
Odr_int * nextResultSetPosition
Definition: z-core.h:676
Z_PresentStatus * presentStatus
Definition: z-core.h:677
Z_Records * records
Definition: z-core.h:678
Odr_int * numberOfRecordsReturned
Definition: z-core.h:675
Z_ReferenceId * referenceId
Definition: z-core.h:674
Z_External * type_104
Definition: z-core.h:477
Z_RPNQuery * type_1
Definition: z-core.h:472
Odr_oct * type_2
Definition: z-core.h:473
int which
Definition: z-core.h:469
union Z_Query::@45 u
Z_RPNStructure * RPNStructure
Definition: z-core.h:490
union Z_RPNStructure::@46 u
Z_Operand * simple
Definition: z-core.h:502
Z_CompSpec * complex
Definition: z-core.h:644
union Z_RecordComposition::@52 u
Z_ElementSetNames * simple
Definition: z-core.h:643
union Z_Records::@53 u
int which
Definition: z-core.h:693
Z_NamePlusRecordList * databaseOrSurDiagnostics
Definition: z-core.h:695
Z_DefaultDiagFormat * nonSurrogateDiagnostic
Definition: z-core.h:696
void * p
Definition: soap.h:49
Definition: soap.h:55
Z_SOAP_Generic * generic
Definition: soap.h:59
union Z_SOAP::@28 u
Definition: srw.h:200
Z_SRW_explainRequest * explain_request
Definition: srw.h:205
Z_SRW_updateRequest * update_request
Definition: srw.h:209
Z_SRW_updateResponse * update_response
Definition: srw.h:210
union Z_SRW_PDU::@30 u
char * srw_version
Definition: srw.h:212
Z_SRW_scanRequest * scan_request
Definition: srw.h:207
Z_SRW_searchRetrieveResponse * response
Definition: srw.h:204
Z_SRW_extra_arg * extra_args
Definition: srw.h:219
Z_SRW_scanResponse * scan_response
Definition: srw.h:208
Z_SRW_explainResponse * explain_response
Definition: srw.h:206
Z_SRW_searchRetrieveRequest * request
Definition: srw.h:203
char * password
Definition: srw.h:214
int which
Definition: srw.h:201
char * extraResponseData_buf
Definition: srw.h:221
int extraResponseData_len
Definition: srw.h:222
char * username
Definition: srw.h:213
char * uri
Definition: srw.h:64
char * database
Definition: srw.h:118
char * stylesheet
Definition: srw.h:119
char * recordPacking
Definition: srw.h:116
Z_SRW_diagnostic * diagnostics
Definition: srw.h:124
Z_SRW_record record
Definition: srw.h:123
int extraRecordData_len
Definition: srw.h:46
char * extraRecordData_buf
Definition: srw.h:45
char * recordIdentifier
Definition: srw.h:47
char * recordData_buf
Definition: srw.h:58
int recordPacking
Definition: srw.h:53
char * recordSchema
Definition: srw.h:51
int recordData_len
Definition: srw.h:59
Odr_int * recordPosition
Definition: srw.h:60
Odr_int * responsePosition
Definition: srw.h:132
Odr_int * maximumTerms
Definition: srw.h:133
char * queryType
Definition: srw.h:130
char * scanClause
Definition: srw.h:131
char * stylesheet
Definition: srw.h:134
char * database
Definition: srw.h:135
Z_SRW_diagnostic * diagnostics
Definition: srw.h:148
Z_SRW_scanTerm * terms
Definition: srw.h:146
int num_diagnostics
Definition: srw.h:149
char * displayTerm
Definition: srw.h:141
char * whereInList
Definition: srw.h:142
Odr_int * numberOfRecords
Definition: srw.h:140
char * value
Definition: srw.h:139
Z_FacetList * facetList
Definition: srw.h:94
Odr_int * maximumRecords
Definition: srw.h:84
Odr_int * startRecord
Definition: srw.h:83
union Z_SRW_searchRetrieveRequest::@29 sort
Z_SRW_record * records
Definition: srw.h:103
Odr_int * numberOfRecords
Definition: srw.h:98
Z_SRW_diagnostic * diagnostics
Definition: srw.h:106
char * resultCountPrecision
Definition: srw.h:99
Odr_int * resultSetIdleTime
Definition: srw.h:101
Z_SRW_extra_record ** extra_records
Definition: srw.h:110
Z_FacetList * facetList
Definition: srw.h:111
char * database
Definition: srw.h:159
int extraRequestData_len
Definition: srw.h:167
char * operation
Definition: srw.h:160
char * recordId
Definition: srw.h:161
Z_SRW_extra_record * extra_record
Definition: srw.h:165
Z_SRW_recordVersion * recordVersions
Definition: srw.h:162
int num_recordVersions
Definition: srw.h:163
Z_SRW_record * record
Definition: srw.h:164
char * extraRequestData_buf
Definition: srw.h:166
char * operationStatus
Definition: srw.h:179
int num_diagnostics
Definition: srw.h:188
char * recordId
Definition: srw.h:180
Z_SRW_diagnostic * diagnostics
Definition: srw.h:187
Z_SRW_record * record
Definition: srw.h:183
int extraResponseData_len
Definition: srw.h:186
int num_recordVersions
Definition: srw.h:182
Z_SRW_recordVersion * recordVersions
Definition: srw.h:181
char * extraResponseData_buf
Definition: srw.h:185
Z_SRW_extra_record * extra_record
Definition: srw.h:184
Z_AttributeSetId * attributeSet
Definition: z-core.h:948
Odr_int * preferredPositionInResponse
Definition: z-core.h:952
int num_databaseNames
Definition: z-core.h:946
Z_ReferenceId * referenceId
Definition: z-core.h:945
Z_DatabaseName ** databaseNames
Definition: z-core.h:947
Z_AttributesPlusTerm * termListAndStartPoint
Definition: z-core.h:949
Odr_int * numberOfTermsRequested
Definition: z-core.h:951
Odr_int * stepSize
Definition: z-core.h:950
Z_OtherInformation * otherInfo
Definition: z-core.h:953
Odr_int * stepSize
Definition: z-core.h:958
Z_ListEntries * entries
Definition: z-core.h:969
Odr_int * positionOfTerm
Definition: z-core.h:968
Z_AttributeSetId * attributeSet
Definition: z-core.h:970
Odr_int * scanStatus
Definition: z-core.h:966
Z_ReferenceId * referenceId
Definition: z-core.h:957
Odr_int * numberOfEntriesReturned
Definition: z-core.h:967
Z_OtherInformation * otherInfo
Definition: z-core.h:971
Z_Query * query
Definition: z-core.h:463
Odr_bool * replaceIndicator
Definition: z-core.h:456
Z_InternationalString * resultSetName
Definition: z-core.h:457
Z_ElementSetNames * smallSetElementSetNames
Definition: z-core.h:460
Z_OtherInformation * additionalSearchInfo
Definition: z-core.h:464
Z_OtherInformation * otherInfo
Definition: z-core.h:465
int num_databaseNames
Definition: z-core.h:458
Z_DatabaseName ** databaseNames
Definition: z-core.h:459
Odr_int * largeSetLowerBound
Definition: z-core.h:454
Z_ReferenceId * referenceId
Definition: z-core.h:452
Z_ElementSetNames * mediumSetElementSetNames
Definition: z-core.h:461
Odr_int * mediumSetPresentNumber
Definition: z-core.h:455
Odr_oid * preferredRecordSyntax
Definition: z-core.h:462
Odr_int * smallSetUpperBound
Definition: z-core.h:453
Odr_int * numberOfRecordsReturned
Definition: z-core.h:626
Z_PresentStatus * presentStatus
Definition: z-core.h:634
Odr_int * resultSetStatus
Definition: z-core.h:633
Odr_int * nextResultSetPosition
Definition: z-core.h:627
Z_OtherInformation * otherInfo
Definition: z-core.h:637
Z_Records * records
Definition: z-core.h:635
Odr_bool * searchStatus
Definition: z-core.h:628
Z_OtherInformation * additionalSearchInfo
Definition: z-core.h:636
Z_ReferenceId * referenceId
Definition: z-core.h:624
Odr_int * resultCount
Definition: z-core.h:625
int num_inputResultSetNames
Definition: z-core.h:1037
Z_InternationalString * sortedResultSetName
Definition: z-core.h:1039
Z_SortKeySpecList * sortSequence
Definition: z-core.h:1040
Z_InternationalString ** inputResultSetNames
Definition: z-core.h:1038
Z_ReferenceId * referenceId
Definition: z-core.h:1036
Z_DiagRec ** diagnostics
Definition: z-core.h:1056
Z_ReferenceId * referenceId
Definition: z-core.h:1045
Odr_int * resultCount
Definition: z-core.h:1057
Odr_int * sortStatus
Definition: z-core.h:1049
int num_diagnostics
Definition: z-core.h:1055
Odr_int * resultSetStatus
Definition: z-core.h:1054
Z_OtherInformation * otherInfo
Definition: z-core.h:1058
union Z_Specification::@60 schema
Z_ElementSpec * elementSpec
Definition: z-core.h:817
Z_InternationalString * uri
Definition: z-core.h:813
Odr_int * globalOccurrences
Definition: z-core.h:997
Z_AttributeList * suggestedAttributes
Definition: z-core.h:994
Z_OtherInformation * otherTermInfo
Definition: z-core.h:999
Z_AttributesPlusTerm ** alternativeTerm
Definition: z-core.h:996
Z_Term * term
Definition: z-core.h:992
Z_OccurrenceByAttributes * byAttributes
Definition: z-core.h:998
Z_InternationalString * displayTerm
Definition: z-core.h:993
Definition: z-core.h:536
Odr_oct * general
Definition: z-core.h:539
union Z_Term::@48 u
int which
Definition: z-core.h:537
struct bend_initrequest * init
Definition: session.h:133
COMSTACK client_link
Definition: session.h:109
ODR decode
Definition: session.h:110
int cs_put_mask
Definition: session.h:130
int cs_get_mask
Definition: session.h:129
ODR print
Definition: session.h:112
int version
Definition: session.h:127
request_q incoming
Definition: session.h:120
request_q outgoing
Definition: session.h:121
int maximumRecordSize
Definition: session.h:126
int cs_accept_mask
Definition: session.h:131
int preferredMessageSize
Definition: session.h:125
struct gfs_server * server
Definition: session.h:136
void * backend
Definition: session.h:119
association_state state
Definition: session.h:122
char * input_buffer
Definition: session.h:115
oid_proto proto
Definition: session.h:118
int input_buffer_len
Definition: session.h:116
IOCHAN client_chan
Definition: session.h:108
statserv_options_block * last_control
Definition: session.h:134
ODR encode
Definition: session.h:111
Information for Z39.50 delete result set handler.
Definition: backend.h:182
int num_setnames
Definition: backend.h:184
Z_ReferenceId * referenceId
Definition: backend.h:186
int delete_status
Definition: backend.h:187
char ** setnames
Definition: backend.h:185
int * statuses
Definition: backend.h:188
Information for Z39.50 extended services handler.
Definition: backend.h:211
bend_association association
Definition: backend.h:219
Z_External * taskPackageExt
Definition: backend.h:223
Z_ExtendedServicesRequest * esr
Definition: backend.h:213
Z_ReferenceId * referenceId
Definition: backend.h:218
char * errstring
Definition: backend.h:221
Z_TaskPackage * taskPackage
Definition: backend.h:222
Information for SRU Explain handler.
Definition: backend.h:236
char * explain_buf
Definition: backend.h:240
void * server_node_ptr
Definition: backend.h:243
char * database
Definition: backend.h:241
char * schema
Definition: backend.h:242
Information for fetch record handler.
Definition: backend.h:98
char * basename
Definition: backend.h:107
char * record
Definition: backend.h:109
Odr_oid * request_format
Definition: backend.h:102
int last_in_set
Definition: backend.h:110
Z_RecordComposition * comp
Definition: backend.h:103
Odr_oid * output_format
Definition: backend.h:111
char * schema
Definition: backend.h:115
char * setname
Definition: backend.h:99
int surrogate_flag
Definition: backend.h:114
char * errstring
Definition: backend.h:113
Z_ReferenceId * referenceId
Definition: backend.h:101
Information for the Init handler.
Definition: backend.h:253
int(* bend_scan)(void *handle, bend_scan_rr *rr)
Z39.50 scan handler.
Definition: backend.h:306
int records_in_same_charset
whether query_charset also applies to records
Definition: backend.h:287
ODR decode
decoding stream (use stream for results)
Definition: backend.h:261
Z_CharSetandLanguageNegotiation * charneg_request
character set and language negotiation
Definition: backend.h:271
int(* bend_search)(void *handle, bend_search_rr *rr)
SRU/Z39.50 search handler.
Definition: backend.h:296
int(* bend_fetch)(void *handle, bend_fetch_rr *rr)
SRU/Z39.50 fetch handler.
Definition: backend.h:298
int named_result_sets
whether named result sets are supported (0=disable, 1=enable)
Definition: backend.h:317
Z_External * charneg_response
character negotiation response
Definition: backend.h:274
int(* bend_srw_scan)(void *handle, bend_scan_rr *rr)
SRU scan handler.
Definition: backend.h:312
char * implementation_name
Definition: backend.h:290
Z_ReferenceId * referenceId
reference ID
Definition: backend.h:263
Z_IdAuthentication * auth
user/name/password to be read
Definition: backend.h:255
int(* bend_segment)(void *handle, bend_segment_rr *rr)
Z39.50 segment facility handler.
Definition: backend.h:308
int(* bend_srw_update)(void *handle, bend_update_rr *rr)
SRU record update handler.
Definition: backend.h:314
char * implementation_version
Definition: backend.h:291
int(* bend_explain)(void *handle, bend_explain_rr *rr)
SRU explain handler.
Definition: backend.h:310
int(* bend_sort)(void *handle, bend_sort_rr *rr)
Z39.50 sort handler.
Definition: backend.h:294
ODR stream
encoding stream (for results)
Definition: backend.h:257
char * implementation_id
Definition: backend.h:289
char * peer_name
peer address of client
Definition: backend.h:265
char * query_charset
character set (encoding) for query terms
Definition: backend.h:280
int(* bend_esrequest)(void *handle, bend_esrequest_rr *rr)
Z39.50 extended services handler.
Definition: backend.h:302
int(* bend_present)(void *handle, bend_present_rr *rr)
SRU/Z39.50 present handler.
Definition: backend.h:300
int(* bend_delete)(void *handle, bend_delete_rr *rr)
Z39.50 delete result set handler.
Definition: backend.h:304
ODR print
printing stream
Definition: backend.h:259
result for init handler (must be filled by handler)
Definition: backend.h:322
void * handle
Definition: backend.h:325
char * errstring
Definition: backend.h:324
Information for present handler. Does not replace bend_fetch.
Definition: backend.h:82
Z_RecordComposition * comp
Definition: backend.h:88
char * errstring
Definition: backend.h:94
bend_association association
Definition: backend.h:91
char * setname
Definition: backend.h:83
Odr_oid * format
Definition: backend.h:86
Z_ReferenceId * referenceId
Definition: backend.h:87
Information for SRU / Z39.50 scan handler.
Definition: backend.h:133
char * scanClause
Definition: backend.h:152
Z_SRW_extra_arg * extra_args
Definition: backend.h:154
Z_ReferenceId * referenceId
Definition: backend.h:137
Z_AttributesPlusTerm * term
Definition: backend.h:138
int num_entries
Definition: backend.h:144
int errcode
Definition: backend.h:150
bend_scan_status status
Definition: backend.h:149
ODR stream
Definition: backend.h:139
int term_position
Definition: backend.h:143
char ** basenames
Definition: backend.h:135
char * errstring
Definition: backend.h:151
int * step_size
Definition: backend.h:142
char * setname
Definition: backend.h:153
struct scan_entry * entries
Definition: backend.h:148
char * extra_response_data
Definition: backend.h:155
int num_bases
Definition: backend.h:134
Odr_oid * attributeset
Definition: backend.h:136
Information for Z39.50/SRU search handler.
Definition: backend.h:54
Z_ReferenceId * referenceId
Definition: backend.h:59
char ** basenames
Definition: backend.h:58
Odr_int hits
Definition: backend.h:66
int partial_resultset
Definition: backend.h:74
Odr_int present_number
Definition: backend.h:78
char * srw_setname
Definition: backend.h:71
char * errstring
Definition: backend.h:68
int * srw_setnameIdleTime
Definition: backend.h:72
Z_OtherInformation * search_input
Definition: backend.h:77
char * setname
Definition: backend.h:55
int estimated_hit_count
Definition: backend.h:73
Z_SRW_extra_arg * extra_args
Definition: backend.h:75
char * srw_sortKeys
Definition: backend.h:70
int num_bases
Definition: backend.h:57
Z_OtherInformation * search_info
Definition: backend.h:69
int replace_set
Definition: backend.h:56
char * extra_response_data
Definition: backend.h:76
Z_Query * query
Definition: backend.h:60
bend_association association
Definition: backend.h:65
Information for Z39.50 segment handler.
Definition: backend.h:227
bend_association association
Definition: backend.h:232
Z_Segment * segment
Definition: backend.h:228
Information for Z39.50 sort handler.
Definition: backend.h:195
char * output_setname
Definition: backend.h:198
Z_ReferenceId * referenceId
Definition: backend.h:202
int sort_status
Definition: backend.h:204
int num_input_setnames
Definition: backend.h:196
Z_SortKeySpecList * sort_sequence
Definition: backend.h:199
char * errstring
Definition: backend.h:206
char ** input_setnames
Definition: backend.h:197
int errcode
Definition: backend.h:205
ODR stream
Definition: backend.h:200
Information for SRU record update handler.
Definition: backend.h:159
char * extra_response_data
Definition: backend.h:175
char * extra_request_data
Definition: backend.h:174
char * details
Definition: backend.h:178
char * extra_record_data
Definition: backend.h:173
Z_SRW_recordVersion * record_versions
Definition: backend.h:168
char * operation_status
Definition: backend.h:166
char * operation
Definition: backend.h:165
char * record_packing
Definition: backend.h:170
char * message
Definition: backend.h:177
char * uri
Definition: backend.h:176
char * record_schema
Definition: backend.h:171
char ** basenames
Definition: backend.h:161
char * record_data
Definition: backend.h:172
int num_versions
Definition: backend.h:169
char * record_id
Definition: backend.h:167
RPN tree structure node.
Definition: ccl.h:128
unsigned io_pending
Definition: comstack.h:63
CQL parse tree (node)
Definition: cql.h:119
CCL_bibset ccl_transform
Definition: session.h:49
yaz_retrieval_t retrieval
Definition: session.h:55
char * stylesheet
Definition: session.h:53
void * server_node_ptr
Definition: session.h:50
cql_transform_t cql_transform
Definition: session.h:48
char * client_query_charset
Definition: session.h:54
char * docpath
Definition: session.h:52
Definition: eventl.h:46
Definition: odr.h:100
int len
Definition: odr.h:102
char * buf
Definition: odr.h:101
Definition: odr.h:125
int error
Definition: odr.h:128
NMEM mem
Definition: odr.h:130
Z_APDU * apdu_request
Definition: session.h:76
int size_response
Definition: session.h:79
request_state state
Definition: session.h:73
char * response
Definition: session.h:81
NMEM request_mem
Definition: session.h:77
int len_response
Definition: session.h:80
Z_GDU * gdu_request
Definition: session.h:75
Information for scan entry.
Definition: backend.h:119
char * display_term
Definition: backend.h:124
char * term
Definition: backend.h:120
int errcode
Definition: backend.h:122
char * errstring
Definition: backend.h:123
Odr_int occurrences
Definition: backend.h:121
control block for server
Definition: backend.h:332
bend_initresult *(* bend_init)(bend_initrequest *r)
Definition: backend.h:351
char configname[BEND_NAME_MAX]
Definition: backend.h:341
void(* bend_close)(void *handle)
Definition: backend.h:352
string buffer
Definition: wrbuf.h:43
the internals of a yaz_marc_t handle
Definition: marcdisp.c:86
The internal structure for yaz_record_conv_t.
Definition: record_conv.c:44
void wrbuf_destroy(WRBUF b)
destroy WRBUF and its buffer
Definition: wrbuf.c:38
WRBUF wrbuf_alloc(void)
construct WRBUF
Definition: wrbuf.c:25
void wrbuf_printf(WRBUF b, const char *fmt,...)
writes printf result to WRBUF
Definition: wrbuf.c:178
void wrbuf_puts_replace_char(WRBUF b, const char *buf, const char from, const char to)
puts buf to WRBUF and replaces a single char
Definition: wrbuf.c:100
void wrbuf_vp_puts(const char *buf, void *client_data)
appends C-string to WRBUF - void pointer variant
Definition: wrbuf.c:94
const char * wrbuf_cstr(WRBUF b)
returns WRBUF content as C-string
Definition: wrbuf.c:281
void wrbuf_puts(WRBUF b, const char *buf)
appends C-string to WRBUF
Definition: wrbuf.c:89
#define wrbuf_buf(b)
Definition: wrbuf.h:251
#define wrbuf_len(b)
Definition: wrbuf.h:250
Header for memory handling functions.
#define xfree(x)
utility macro which calls xfree_f
Definition: xmalloc.h:53
#define xmalloc_trav(s)
utility macro which calls malloc_trav_f
Definition: xmalloc.h:59
#define xmalloc(x)
utility macro which calls malloc_f
Definition: xmalloc.h:49
int yaz_xml_to_opac(yaz_marc_t mt, const char *buf_in, size_t size_in, Z_OPACRecord **dst, yaz_iconv_t cd, NMEM nmem, const Odr_oid *syntax)
Converts XML to OPAC.
Definition: xml_to_opac.c:299
Header for CCL node tree to RPN converson utilities.
Z_RPNQuery * ccl_rpn_query(ODR o, struct ccl_rpn_node *p)
Definition: yaz-ccl.c:20
#define yaz_isdigit(x)
Definition: yaz-iconv.h:86
Header for common YAZ utilities.
#define Z_CharSetandLanguageNegotiation_proposal
Definition: z-charneg.h:65
#define Z_Close_finished
Definition: z-core.h:1178
#define Z_ProtocolVersion_1
Definition: z-core.h:425
#define Z_Options_extendedServices
Definition: z-core.h:438
#define Z_ProtocolVersion_2
Definition: z-core.h:426
#define Z_APDU_initRequest
Definition: z-core.h:349
#define Z_Options_sort
Definition: z-core.h:437
#define Z_ElementSetNames_generic
Definition: z-core.h:773
#define Z_IdAuthentication_anonymous
Definition: z-core.h:406
#define Z_Options_triggerResourceCtrl
Definition: z-core.h:433
#define Z_Scan_failure
Definition: z-core.h:965
#define Z_RecordComp_complex
Definition: z-core.h:646
#define Z_Options_delSet
Definition: z-core.h:431
#define Z_Options_present
Definition: z-core.h:430
#define Z_ExtendedServicesResponse_accepted
Definition: z-core.h:1144
#define Z_Close_systemProblem
Definition: z-core.h:1180
#define Z_APDU_scanRequest
Definition: z-core.h:364
#define Z_Schema_uri
Definition: z-core.h:815
#define Z_Entry_surrogateDiagnostic
Definition: z-core.h:987
#define Z_APDU_presentResponse
Definition: z-core.h:354
#define Z_SearchResponse_none
Definition: z-core.h:631
#define Z_APDU_triggerResourceControlRequest
Definition: z-core.h:361
#define Z_NamePlusRecord_databaseRecord
Definition: z-core.h:713
#define Z_Records_DBOSD
Definition: z-core.h:698
#define Z_APDU_sortResponse
Definition: z-core.h:367
#define Z_ElementSpec_elementSetName
Definition: z-core.h:804
#define Z_Operand_APT
Definition: z-core.h:515
#define Z_Scan_partial_5
Definition: z-core.h:964
#define Z_Scan_success
Definition: z-core.h:959
#define Z_APDU_presentRequest
Definition: z-core.h:353
#define Z_Options_search
Definition: z-core.h:429
#define Z_Term_general
Definition: z-core.h:547
#define Z_Query_type_1
Definition: z-core.h:479
#define Z_ExtendedServicesResponse_failure
Definition: z-core.h:1145
#define Z_PresentStatus_success
Definition: z-core.h:778
#define Z_IdAuthentication_open
Definition: z-core.h:404
#define Z_APDU_extendedServicesResponse
Definition: z-core.h:370
#define Z_PresentStatus_failure
Definition: z-core.h:783
#define Z_APDU_searchRequest
Definition: z-core.h:351
#define Z_APDU_deleteResultSetResponse
Definition: z-core.h:356
#define Z_APDU_initResponse
Definition: z-core.h:350
#define Z_RecordComp_simple
Definition: z-core.h:645
#define Z_Options_negotiationModel
Definition: z-core.h:445
#define Z_Options_scan
Definition: z-core.h:436
#define Z_OtherInfo_externallyDefinedInfo
Definition: z-core.h:1289
#define Z_Query_type_101
Definition: z-core.h:482
#define Z_IdAuthentication_idPass
Definition: z-core.h:405
#define Z_Options_concurrentOperations
Definition: z-core.h:441
#define Z_Records_NSD
Definition: z-core.h:699
#define Z_SearchResponse_estimate
Definition: z-core.h:632
#define Z_Close_protocolError
Definition: z-core.h:1184
#define Z_APDU_close
Definition: z-core.h:371
#define Z_PresentStatus_partial_2
Definition: z-core.h:780
#define Z_APDU_segmentRequest
Definition: z-core.h:368
#define Z_APDU_scanResponse
Definition: z-core.h:365
#define Z_RPNStructure_simple
Definition: z-core.h:504
#define Z_SearchResponse_subset
Definition: z-core.h:629
#define Z_ExtendedServicesResponse_done
Definition: z-core.h:1143
#define Z_PresentStatus_partial_4
Definition: z-core.h:782
#define Z_ProtocolVersion_3
Definition: z-core.h:427
#define Z_SortResponse_failure
Definition: z-core.h:1048
#define Z_APDU_sortRequest
Definition: z-core.h:366
#define Z_Close_lackOfActivity
Definition: z-core.h:1185
#define Z_APDU_deleteResultSetRequest
Definition: z-core.h:355
#define Z_Options_namedResultSets
Definition: z-core.h:442
#define Z_APDU_searchResponse
Definition: z-core.h:352
#define Z_APDU_extendedServicesRequest
Definition: z-core.h:369
#define Z_Query_type_104
Definition: z-core.h:484
#define Z_Entry_termInfo
Definition: z-core.h:986
#define Z_Query_type_2
Definition: z-core.h:480
#define Z_GDU_Z3950
Definition: zgdu.h:65
#define Z_GDU_HTTP_Request
Definition: zgdu.h:66
int z_GDU(ODR o, Z_GDU **p, int opt, const char *name)
Definition: zgdu.c:17