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