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