2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: seshigh.c,v 1.66 2006-01-20 10:34:51 adam Exp $
9 * \brief Implements GFS session logic.
11 * Frontend server logic.
13 * This code receives incoming APDUs, and handles client requests by means
16 * Some of the code is getting quite involved, compared to simpler servers -
17 * primarily because it is asynchronous both in the communication with
18 * the user and the backend. We think the complexity will pay off in
19 * the form of greater flexibility when more asynchronous facilities
22 * Memory management has become somewhat involved. In the simple case, where
23 * only one PDU is pending at a time, it will simply reuse the same memory,
24 * once it has found its working size. When we enable multiple concurrent
25 * operations, perhaps even with multiple parallel calls to the backend, it
26 * will maintain a pool of buffers for encoding and decoding, trying to
27 * minimize memory allocation/deallocation during normal operation.
37 #include <sys/types.h>
45 #define S_ISREG(x) (x & _S_IFREG)
54 #include <libxml/parser.h>
55 #include <libxml/tree.h>
58 #include <yaz/yconfig.h>
59 #include <yaz/xmalloc.h>
60 #include <yaz/comstack.h>
63 #include <yaz/proto.h>
66 #include <yaz/logrpn.h>
67 #include <yaz/querytowrbuf.h>
68 #include <yaz/statserv.h>
69 #include <yaz/diagbib1.h>
70 #include <yaz/charneg.h>
71 #include <yaz/otherinfo.h>
72 #include <yaz/yaz-util.h>
73 #include <yaz/pquery.h>
76 #include <yaz/backend.h>
78 static void process_gdu_request(association *assoc, request *req);
79 static int process_z_request(association *assoc, request *req, char **msg);
80 void backend_response(IOCHAN i, int event);
81 static int process_gdu_response(association *assoc, request *req, Z_GDU *res);
82 static int process_z_response(association *assoc, request *req, Z_APDU *res);
83 static Z_APDU *process_initRequest(association *assoc, request *reqb);
84 static Z_External *init_diagnostics(ODR odr, int errcode,
85 const char *errstring);
86 static Z_APDU *process_searchRequest(association *assoc, request *reqb,
88 static Z_APDU *response_searchRequest(association *assoc, request *reqb,
89 bend_search_rr *bsrr, int *fd);
90 static Z_APDU *process_presentRequest(association *assoc, request *reqb,
92 static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd);
93 static Z_APDU *process_sortRequest(association *assoc, request *reqb, int *fd);
94 static void process_close(association *assoc, request *reqb);
95 void save_referenceId (request *reqb, Z_ReferenceId *refid);
96 static Z_APDU *process_deleteRequest(association *assoc, request *reqb,
98 static Z_APDU *process_segmentRequest (association *assoc, request *reqb);
100 static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd);
102 /* dynamic logging levels */
103 static int logbits_set = 0;
104 static int log_session = 0;
105 static int log_request = 0; /* one-line logs for requests */
106 static int log_requestdetail = 0; /* more detailed stuff */
108 /** get_logbits sets global loglevel bits */
109 static void get_logbits()
110 { /* needs to be called after parsing cmd-line args that can set loglevels!*/
114 log_session = yaz_log_module_level("session");
115 log_request = yaz_log_module_level("request");
116 log_requestdetail = yaz_log_module_level("requestdetail");
120 static void wr_diag(WRBUF w, int error, const char *addinfo)
122 wrbuf_printf(w, "ERROR [%d] %s%s%s",
123 error, diagbib1_str(error),
124 addinfo ? "--" : "", addinfo ? addinfo : "");
129 * Create and initialize a new association-handle.
130 * channel : iochannel for the current line.
131 * link : communications channel.
132 * Returns: 0 or a new association handle.
134 association *create_association(IOCHAN channel, COMSTACK link,
135 const char *apdufile)
141 if (!(anew = (association *)xmalloc(sizeof(*anew))))
145 anew->last_control = 0;
146 anew->client_chan = channel;
147 anew->client_link = link;
148 anew->cs_get_mask = 0;
149 anew->cs_put_mask = 0;
150 anew->cs_accept_mask = 0;
151 if (!(anew->decode = odr_createmem(ODR_DECODE)) ||
152 !(anew->encode = odr_createmem(ODR_ENCODE)))
154 if (apdufile && *apdufile)
158 if (!(anew->print = odr_createmem(ODR_PRINT)))
160 if (*apdufile == '@')
162 odr_setprint(anew->print, yaz_log_file());
164 else if (*apdufile != '-')
167 sprintf(filename, "%.200s.%ld", apdufile, (long)getpid());
168 if (!(f = fopen(filename, "w")))
170 yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", filename);
173 setvbuf(f, 0, _IONBF, 0);
174 odr_setprint(anew->print, f);
179 anew->input_buffer = 0;
180 anew->input_buffer_len = 0;
182 anew->state = ASSOC_NEW;
183 request_initq(&anew->incoming);
184 request_initq(&anew->outgoing);
185 anew->proto = cs_getproto(link);
186 anew->cql_transform = 0;
187 anew->server_node_ptr = 0;
192 * Free association and release resources.
194 void destroy_association(association *h)
196 statserv_options_block *cb = statserv_getcontrol();
200 odr_destroy(h->decode);
201 odr_destroy(h->encode);
203 odr_destroy(h->print);
205 xfree(h->input_buffer);
207 (*cb->bend_close)(h->backend);
208 while ((req = request_deq(&h->incoming)))
209 request_release(req);
210 while ((req = request_deq(&h->outgoing)))
211 request_release(req);
212 request_delq(&h->incoming);
213 request_delq(&h->outgoing);
215 xmalloc_trav("session closed");
216 if (cb && cb->one_shot)
222 static void do_close_req(association *a, int reason, char *message,
226 Z_Close *cls = zget_Close(a->encode);
228 /* Purge request queue */
229 while (request_deq(&a->incoming));
230 while (request_deq(&a->outgoing));
233 yaz_log(log_requestdetail, "Sending Close PDU, reason=%d, message=%s",
234 reason, message ? message : "none");
235 apdu.which = Z_APDU_close;
237 *cls->closeReason = reason;
238 cls->diagnosticInformation = message;
239 process_z_response(a, req, &apdu);
240 iochan_settimeout(a->client_chan, 20);
244 request_release(req);
245 yaz_log(log_requestdetail, "v2 client. No Close PDU");
246 iochan_setevent(a->client_chan, EVENT_TIMEOUT); /* force imm close */
249 a->state = ASSOC_DEAD;
252 static void do_close(association *a, int reason, char *message)
254 request *req = request_get(&a->outgoing);
255 do_close_req (a, reason, message, req);
259 * This is where PDUs from the client are read and the further
260 * processing is initiated. Flow of control moves down through the
261 * various process_* functions below, until the encoded result comes back up
262 * to the output handler in here.
264 * h : the I/O channel that has an outstanding event.
265 * event : the current outstanding event.
267 void ir_session(IOCHAN h, int event)
270 association *assoc = (association *)iochan_getdata(h);
271 COMSTACK conn = assoc->client_link;
274 assert(h && conn && assoc);
275 if (event == EVENT_TIMEOUT)
277 if (assoc->state != ASSOC_UP)
279 yaz_log(YLOG_DEBUG, "Final timeout - closing connection.");
280 /* do we need to lod this at all */
282 destroy_association(assoc);
287 yaz_log(log_session, "Session idle too long. Sending close.");
288 do_close(assoc, Z_Close_lackOfActivity, 0);
292 if (event & assoc->cs_accept_mask)
294 if (!cs_accept (conn))
296 yaz_log (YLOG_WARN, "accept failed");
297 destroy_association(assoc);
300 iochan_clearflag (h, EVENT_OUTPUT);
301 if (conn->io_pending)
302 { /* cs_accept didn't complete */
303 assoc->cs_accept_mask =
304 ((conn->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) |
305 ((conn->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0);
307 iochan_setflag (h, assoc->cs_accept_mask);
310 { /* cs_accept completed. Prepare for reading (cs_get) */
311 assoc->cs_accept_mask = 0;
312 assoc->cs_get_mask = EVENT_INPUT;
313 iochan_setflag (h, assoc->cs_get_mask);
317 if ((event & assoc->cs_get_mask) || (event & EVENT_WORK)) /* input */
319 if ((assoc->cs_put_mask & EVENT_INPUT) == 0 && (event & assoc->cs_get_mask))
321 yaz_log(YLOG_DEBUG, "ir_session (input)");
322 /* We aren't speaking to this fellow */
323 if (assoc->state == ASSOC_DEAD)
325 yaz_log(log_session, "Connection closed - end of session");
327 destroy_association(assoc);
331 assoc->cs_get_mask = EVENT_INPUT;
332 if ((res = cs_get(conn, &assoc->input_buffer,
333 &assoc->input_buffer_len)) <= 0)
335 yaz_log(log_session, "Connection closed by client");
337 destroy_association(assoc);
341 else if (res == 1) /* incomplete read - wait for more */
343 if (conn->io_pending & CS_WANT_WRITE)
344 assoc->cs_get_mask |= EVENT_OUTPUT;
345 iochan_setflag(h, assoc->cs_get_mask);
348 if (cs_more(conn)) /* more stuff - call us again later, please */
349 iochan_setevent(h, EVENT_INPUT);
351 /* we got a complete PDU. Let's decode it */
352 yaz_log(YLOG_DEBUG, "Got PDU, %d bytes: lead=%02X %02X %02X", res,
353 assoc->input_buffer[0] & 0xff,
354 assoc->input_buffer[1] & 0xff,
355 assoc->input_buffer[2] & 0xff);
356 req = request_get(&assoc->incoming); /* get a new request */
357 odr_reset(assoc->decode);
358 odr_setbuf(assoc->decode, assoc->input_buffer, res, 0);
359 if (!z_GDU(assoc->decode, &req->gdu_request, 0, 0))
361 yaz_log(YLOG_WARN, "ODR error on incoming PDU: %s [element %s] "
363 odr_errmsg(odr_geterror(assoc->decode)),
364 odr_getelement(assoc->decode),
365 odr_offset(assoc->decode));
366 if (assoc->decode->error != OHTTP)
368 yaz_log(YLOG_WARN, "PDU dump:");
369 odr_dumpBER(yaz_log_file(), assoc->input_buffer, res);
370 request_release(req);
371 do_close(assoc, Z_Close_protocolError,"Malformed package");
375 Z_GDU *p = z_get_HTTP_Response(assoc->encode, 400);
376 assoc->state = ASSOC_DEAD;
377 process_gdu_response(assoc, req, p);
381 req->request_mem = odr_extract_mem(assoc->decode);
384 if (!z_GDU(assoc->print, &req->gdu_request, 0, 0))
385 yaz_log(YLOG_WARN, "ODR print error: %s",
386 odr_errmsg(odr_geterror(assoc->print)));
387 odr_reset(assoc->print);
389 request_enq(&assoc->incoming, req);
392 /* can we do something yet? */
393 req = request_head(&assoc->incoming);
394 if (req->state == REQUEST_IDLE)
396 request_deq(&assoc->incoming);
397 process_gdu_request(assoc, req);
400 if (event & assoc->cs_put_mask)
402 request *req = request_head(&assoc->outgoing);
404 assoc->cs_put_mask = 0;
405 yaz_log(YLOG_DEBUG, "ir_session (output)");
406 req->state = REQUEST_PENDING;
407 switch (res = cs_put(conn, req->response, req->len_response))
410 yaz_log(log_session, "Connection closed by client");
412 destroy_association(assoc);
415 case 0: /* all sent - release the request structure */
416 yaz_log(YLOG_DEBUG, "Wrote PDU, %d bytes", req->len_response);
418 yaz_log(YLOG_DEBUG, "HTTP out:\n%.*s", req->len_response,
421 nmem_destroy(req->request_mem);
422 request_deq(&assoc->outgoing);
423 request_release(req);
424 if (!request_head(&assoc->outgoing))
425 { /* restore mask for cs_get operation ... */
426 iochan_clearflag(h, EVENT_OUTPUT|EVENT_INPUT);
427 iochan_setflag(h, assoc->cs_get_mask);
428 if (assoc->state == ASSOC_DEAD)
429 iochan_setevent(assoc->client_chan, EVENT_TIMEOUT);
433 assoc->cs_put_mask = EVENT_OUTPUT;
437 if (conn->io_pending & CS_WANT_WRITE)
438 assoc->cs_put_mask |= EVENT_OUTPUT;
439 if (conn->io_pending & CS_WANT_READ)
440 assoc->cs_put_mask |= EVENT_INPUT;
441 iochan_setflag(h, assoc->cs_put_mask);
444 if (event & EVENT_EXCEPT)
446 yaz_log(YLOG_WARN, "ir_session (exception)");
448 destroy_association(assoc);
453 static int process_z_request(association *assoc, request *req, char **msg);
456 static void assoc_init_reset(association *assoc)
459 assoc->init = (bend_initrequest *) xmalloc (sizeof(*assoc->init));
461 assoc->init->stream = assoc->encode;
462 assoc->init->print = assoc->print;
463 assoc->init->auth = 0;
464 assoc->init->referenceId = 0;
465 assoc->init->implementation_version = 0;
466 assoc->init->implementation_id = 0;
467 assoc->init->implementation_name = 0;
468 assoc->init->bend_sort = NULL;
469 assoc->init->bend_search = NULL;
470 assoc->init->bend_present = NULL;
471 assoc->init->bend_esrequest = NULL;
472 assoc->init->bend_delete = NULL;
473 assoc->init->bend_scan = NULL;
474 assoc->init->bend_segment = NULL;
475 assoc->init->bend_fetch = NULL;
476 assoc->init->bend_explain = NULL;
477 assoc->init->bend_srw_scan = NULL;
478 assoc->init->bend_srw_update = NULL;
480 assoc->init->charneg_request = NULL;
481 assoc->init->charneg_response = NULL;
483 assoc->init->decode = assoc->decode;
484 assoc->init->peer_name =
485 odr_strdup (assoc->encode, cs_addrstr(assoc->client_link));
487 yaz_log(log_requestdetail, "peer %s", assoc->init->peer_name);
490 static int srw_bend_init(association *assoc, Z_SRW_diagnostic **d, int *num)
492 statserv_options_block *cb = statserv_getcontrol();
495 const char *encoding = "UTF-8";
497 bend_initresult *binitres;
499 yaz_log(YLOG_LOG, "srw_bend_init config=%s", cb->configname);
500 assoc_init_reset(assoc);
502 assoc->maximumRecordSize = 3000000;
503 assoc->preferredMessageSize = 3000000;
505 ce = yaz_set_proposal_charneg(assoc->decode, &encoding, 1, 0, 0, 1);
506 assoc->init->charneg_request = ce->u.charNeg3;
509 if (!(binitres = (*cb->bend_init)(assoc->init)))
511 assoc->state = ASSOC_DEAD;
512 yaz_add_srw_diagnostic(assoc->encode, d, num,
513 YAZ_SRW_AUTHENTICATION_ERROR, 0);
516 assoc->backend = binitres->handle;
517 if (binitres->errcode)
519 assoc->state = ASSOC_DEAD;
520 yaz_add_srw_diagnostic(assoc->encode, d, num, binitres->errcode,
521 binitres->errstring);
529 static int srw_bend_fetch(association *assoc, int pos,
530 Z_SRW_searchRetrieveRequest *srw_req,
531 Z_SRW_record *record)
534 ODR o = assoc->encode;
536 rr.setname = "default";
539 rr.request_format = VAL_TEXT_XML;
540 rr.request_format_raw = yaz_oidval_to_z3950oid(assoc->decode,
543 rr.comp = (Z_RecordComposition *)
544 odr_malloc(assoc->decode, sizeof(*rr.comp));
545 rr.comp->which = Z_RecordComp_complex;
546 rr.comp->u.complex = (Z_CompSpec *)
547 odr_malloc(assoc->decode, sizeof(Z_CompSpec));
548 rr.comp->u.complex->selectAlternativeSyntax = (bool_t *)
549 odr_malloc(assoc->encode, sizeof(bool_t));
550 *rr.comp->u.complex->selectAlternativeSyntax = 0;
551 rr.comp->u.complex->num_dbSpecific = 0;
552 rr.comp->u.complex->dbSpecific = 0;
553 rr.comp->u.complex->num_recordSyntax = 0;
554 rr.comp->u.complex->recordSyntax = 0;
556 rr.comp->u.complex->generic = (Z_Specification *)
557 odr_malloc(assoc->decode, sizeof(Z_Specification));
559 /* schema uri = recordSchema (or NULL if recordSchema is not given) */
560 rr.comp->u.complex->generic->which = Z_Schema_uri;
561 rr.comp->u.complex->generic->schema.uri = srw_req->recordSchema;
563 /* ESN = recordSchema if recordSchema is present */
564 rr.comp->u.complex->generic->elementSpec = 0;
565 if (srw_req->recordSchema)
567 rr.comp->u.complex->generic->elementSpec =
568 (Z_ElementSpec *) odr_malloc(assoc->encode, sizeof(Z_ElementSpec));
569 rr.comp->u.complex->generic->elementSpec->which =
570 Z_ElementSpec_elementSetName;
571 rr.comp->u.complex->generic->elementSpec->u.elementSetName =
572 srw_req->recordSchema;
575 rr.stream = assoc->encode;
576 rr.print = assoc->print;
582 rr.output_format = VAL_TEXT_XML;
583 rr.output_format_raw = 0;
586 rr.surrogate_flag = 0;
587 rr.schema = srw_req->recordSchema;
589 if (!assoc->init->bend_fetch)
592 (*assoc->init->bend_fetch)(assoc->backend, &rr);
594 if (rr.errcode && rr.surrogate_flag)
596 int code = yaz_diag_bib1_to_srw(rr.errcode);
597 const char *message = yaz_diag_srw_str(code);
600 len += strlen(message);
602 len += strlen(rr.errstring);
604 record->recordData_buf = odr_malloc(o, len);
606 sprintf(record->recordData_buf, "<diagnostic "
607 "xmlns=\"http://www.loc.gov/zing/srw/diagnostic/\">\n"
608 " <uri>info:srw/diagnostic/1/%d</uri>\n", code);
610 sprintf(record->recordData_buf + strlen(record->recordData_buf),
611 " <details>%s</details>\n", rr.errstring);
613 sprintf(record->recordData_buf + strlen(record->recordData_buf),
614 " <message>%s</message>\n", message);
615 sprintf(record->recordData_buf + strlen(record->recordData_buf),
617 record->recordData_len = strlen(record->recordData_buf);
618 record->recordPosition = odr_intdup(o, pos);
619 record->recordSchema = "info:srw/schema/1/diagnostics-v1.1";
622 else if (rr.len >= 0)
624 record->recordData_buf = rr.record;
625 record->recordData_len = rr.len;
626 record->recordPosition = odr_intdup(o, pos);
628 record->recordSchema = odr_strdup(o, rr.schema);
630 record->recordSchema = 0;
635 static int cql2pqf(ODR odr, const char *cql, cql_transform_t ct,
636 Z_Query *query_result)
638 /* have a CQL query and CQL to PQF transform .. */
639 CQL_parser cp = cql_parser_create();
645 r = cql_parser_string(cp, cql);
648 /* CQL syntax error */
654 r = cql_transform_buf(ct,
655 cql_parser_result(cp),
656 rpn_buf, sizeof(rpn_buf)-1);
658 srw_errcode = cql_transform_error(ct, &add);
662 /* Syntax & transform OK. */
663 /* Convert PQF string to Z39.50 to RPN query struct */
664 YAZ_PQF_Parser pp = yaz_pqf_create();
665 Z_RPNQuery *rpnquery = yaz_pqf_parse(pp, odr, rpn_buf);
670 int code = yaz_pqf_error(pp, &pqf_msg, &off);
671 yaz_log(YLOG_WARN, "PQF Parser Error %s (code %d)",
677 query_result->which = Z_Query_type_1;
678 query_result->u.type_1 = rpnquery;
682 cql_parser_destroy(cp);
686 static int cql2pqf_scan(ODR odr, const char *cql, cql_transform_t ct,
687 Z_AttributesPlusTerm *result)
691 int srw_error = cql2pqf(odr, cql, ct, &query);
694 if (query.which != Z_Query_type_1 && query.which != Z_Query_type_101)
695 return 10; /* bad query type */
696 rpn = query.u.type_1;
697 if (!rpn->RPNStructure)
698 return 10; /* must be structure */
699 if (rpn->RPNStructure->which != Z_RPNStructure_simple)
700 return 10; /* must be simple */
701 if (rpn->RPNStructure->u.simple->which != Z_Operand_APT)
702 return 10; /* must be attributes plus term node .. */
703 memcpy(result, rpn->RPNStructure->u.simple->u.attributesPlusTerm,
708 static void srw_bend_search(association *assoc, request *req,
709 Z_SRW_searchRetrieveRequest *srw_req,
710 Z_SRW_searchRetrieveResponse *srw_res,
717 yaz_log(log_requestdetail, "Got SRW SearchRetrieveRequest");
718 srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
719 if (srw_res->num_diagnostics == 0 && assoc->init)
722 rr.setname = "default";
725 rr.basenames = &srw_req->database;
729 rr.srw_setnameIdleTime = 0;
730 rr.query = (Z_Query *) odr_malloc (assoc->decode, sizeof(*rr.query));
731 rr.query->u.type_1 = 0;
733 if (srw_req->query_type == Z_SRW_query_type_cql)
735 if (assoc->cql_transform)
737 int srw_errcode = cql2pqf(assoc->encode, srw_req->query.cql,
738 assoc->cql_transform, rr.query);
741 yaz_add_srw_diagnostic(assoc->encode,
742 &srw_res->diagnostics,
743 &srw_res->num_diagnostics,
749 /* CQL query to backend. Wrap it - Z39.50 style */
750 ext = (Z_External *) odr_malloc(assoc->decode, sizeof(*ext));
751 ext->direct_reference = odr_getoidbystr(assoc->decode,
752 "1.2.840.10003.16.2");
753 ext->indirect_reference = 0;
755 ext->which = Z_External_CQL;
756 ext->u.cql = srw_req->query.cql;
758 rr.query->which = Z_Query_type_104;
759 rr.query->u.type_104 = ext;
762 else if (srw_req->query_type == Z_SRW_query_type_pqf)
764 Z_RPNQuery *RPNquery;
765 YAZ_PQF_Parser pqf_parser;
767 pqf_parser = yaz_pqf_create ();
769 RPNquery = yaz_pqf_parse (pqf_parser, assoc->decode,
775 int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
776 yaz_log(log_requestdetail, "Parse error %d %s near offset %d",
778 srw_error = YAZ_SRW_QUERY_SYNTAX_ERROR;
781 rr.query->which = Z_Query_type_1;
782 rr.query->u.type_1 = RPNquery;
784 yaz_pqf_destroy (pqf_parser);
788 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
789 &srw_res->num_diagnostics,
790 YAZ_SRW_UNSUPP_QUERY_TYPE, 0);
792 if (rr.query->u.type_1)
794 rr.stream = assoc->encode;
795 rr.decode = assoc->decode;
796 rr.print = assoc->print;
798 if ( srw_req->sort.sortKeys )
799 rr.srw_sortKeys = odr_strdup(assoc->encode,
800 srw_req->sort.sortKeys );
801 rr.association = assoc;
807 yaz_log_zquery_level(log_requestdetail,rr.query);
809 (assoc->init->bend_search)(assoc->backend, &rr);
812 if (rr.errcode == YAZ_BIB1_DATABASE_UNAVAILABLE)
818 srw_error = yaz_diag_bib1_to_srw (rr.errcode);
819 yaz_add_srw_diagnostic(assoc->encode,
820 &srw_res->diagnostics,
821 &srw_res->num_diagnostics,
822 srw_error, rr.errstring);
827 int number = srw_req->maximumRecords ? *srw_req->maximumRecords : 0;
828 int start = srw_req->startRecord ? *srw_req->startRecord : 1;
830 yaz_log(log_requestdetail, "Request to pack %d+%d out of %d",
831 start, number, rr.hits);
833 srw_res->numberOfRecords = odr_intdup(assoc->encode, rr.hits);
836 srw_res->resultSetId =
837 odr_strdup(assoc->encode, rr.srw_setname );
838 srw_res->resultSetIdleTime =
839 odr_intdup(assoc->encode, *rr.srw_setnameIdleTime );
847 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
848 &srw_res->num_diagnostics,
849 YAZ_SRW_FIRST_RECORD_POSITION_OUT_OF_RANGE, 0);
854 int packing = Z_SRW_recordPacking_string;
855 if (start + number > rr.hits)
856 number = rr.hits - start + 1;
857 if (srw_req->recordPacking){
858 if (!strcmp(srw_req->recordPacking, "xml"))
859 packing = Z_SRW_recordPacking_XML;
860 if (!strcmp(srw_req->recordPacking, "url"))
861 packing = Z_SRW_recordPacking_URL;
863 srw_res->records = (Z_SRW_record *)
864 odr_malloc(assoc->encode,
865 number * sizeof(*srw_res->records));
867 srw_res->extra_records = (Z_SRW_extra_record **)
868 odr_malloc(assoc->encode,
869 number*sizeof(*srw_res->extra_records));
871 for (i = 0; i<number; i++)
875 srw_res->records[j].recordPacking = packing;
876 srw_res->records[j].recordData_buf = 0;
877 srw_res->extra_records[j] = 0;
878 yaz_log(YLOG_DEBUG, "srw_bend_fetch %d", i+start);
879 errcode = srw_bend_fetch(assoc, i+start, srw_req,
880 srw_res->records + j);
883 yaz_add_srw_diagnostic(assoc->encode,
884 &srw_res->diagnostics,
885 &srw_res->num_diagnostics,
886 yaz_diag_bib1_to_srw (errcode),
891 if (srw_res->records[j].recordData_buf)
894 srw_res->num_records = j;
896 srw_res->records = 0;
904 const char *querystr = "?";
905 const char *querytype = "?";
906 WRBUF wr = wrbuf_alloc();
908 switch (srw_req->query_type)
910 case Z_SRW_query_type_cql:
912 querystr = srw_req->query.cql;
914 case Z_SRW_query_type_pqf:
916 querystr = srw_req->query.pqf;
919 wrbuf_printf(wr, "SRWSearch ");
920 if (srw_res->num_diagnostics)
921 wrbuf_printf(wr, "ERROR %s", srw_res->diagnostics[0].uri);
922 else if (*http_code != 200)
923 wrbuf_printf(wr, "ERROR info:http/%d", *http_code);
924 else if (srw_res->numberOfRecords)
926 wrbuf_printf(wr, "OK %d",
927 (srw_res->numberOfRecords ?
928 *srw_res->numberOfRecords : 0));
930 wrbuf_printf(wr, " %s %d+%d",
931 (srw_res->resultSetId ?
932 srw_res->resultSetId : "-"),
933 (srw_req->startRecord ? *srw_req->startRecord : 1),
934 srw_res->num_records);
935 yaz_log(log_request, "%s %s: %s", wrbuf_buf(wr), querytype, querystr);
940 static char *srw_bend_explain_default(void *handle, bend_explain_rr *rr)
943 xmlNodePtr ptr = rr->server_node_ptr;
946 for (ptr = ptr->children; ptr; ptr = ptr->next)
948 if (ptr->type != XML_ELEMENT_NODE)
950 if (!strcmp((const char *) ptr->name, "explain"))
953 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
957 ptr = xmlCopyNode(ptr, 1);
959 xmlDocSetRootElement(doc, ptr);
961 xmlDocDumpMemory(doc, &buf_out, &len);
962 content = (char*) odr_malloc(rr->stream, 1+len);
963 memcpy(content, buf_out, len);
968 rr->explain_buf = content;
976 static void srw_bend_explain(association *assoc, request *req,
977 Z_SRW_explainRequest *srw_req,
978 Z_SRW_explainResponse *srw_res,
981 yaz_log(log_requestdetail, "Got SRW ExplainRequest");
983 srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
988 rr.stream = assoc->encode;
989 rr.decode = assoc->decode;
990 rr.print = assoc->print;
992 rr.database = srw_req->database;
993 rr.server_node_ptr = assoc->server_node_ptr;
994 rr.schema = "http://explain.z3950.org/dtd/2.0/";
995 if (assoc->init->bend_explain)
996 (*assoc->init->bend_explain)(assoc->backend, &rr);
998 srw_bend_explain_default(assoc->backend, &rr);
1002 int packing = Z_SRW_recordPacking_string;
1003 if (srw_req->recordPacking)
1005 if (!strcmp(srw_req->recordPacking, "xml"))
1006 packing = Z_SRW_recordPacking_XML;
1007 else if (!strcmp(srw_req->recordPacking, "url"))
1008 packing = Z_SRW_recordPacking_URL;
1010 srw_res->record.recordSchema = rr.schema;
1011 srw_res->record.recordPacking = packing;
1012 srw_res->record.recordData_buf = rr.explain_buf;
1013 srw_res->record.recordData_len = strlen(rr.explain_buf);
1014 srw_res->record.recordPosition = 0;
1020 static void srw_bend_scan(association *assoc, request *req,
1021 Z_SRW_scanRequest *srw_req,
1022 Z_SRW_scanResponse *srw_res,
1025 yaz_log(log_requestdetail, "Got SRW ScanRequest");
1028 srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
1029 if (srw_res->num_diagnostics == 0 && assoc->init)
1031 struct scan_entry *save_entries;
1033 bend_scan_rr *bsrr = (bend_scan_rr *)
1034 odr_malloc (assoc->encode, sizeof(*bsrr));
1035 bsrr->num_bases = 1;
1036 bsrr->basenames = &srw_req->database;
1038 bsrr->num_entries = srw_req->maximumTerms ?
1039 *srw_req->maximumTerms : 10;
1040 bsrr->term_position = srw_req->responsePosition ?
1041 *srw_req->responsePosition : 1;
1044 bsrr->errstring = 0;
1045 bsrr->referenceId = 0;
1046 bsrr->stream = assoc->encode;
1047 bsrr->print = assoc->print;
1048 bsrr->step_size = odr_intdup(assoc->decode, 0);
1051 if (bsrr->num_entries > 0)
1054 bsrr->entries = odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
1056 for (i = 0; i<bsrr->num_entries; i++)
1058 bsrr->entries[i].term = 0;
1059 bsrr->entries[i].occurrences = 0;
1060 bsrr->entries[i].errcode = 0;
1061 bsrr->entries[i].errstring = 0;
1062 bsrr->entries[i].display_term = 0;
1065 save_entries = bsrr->entries; /* save it so we can compare later */
1067 if (srw_req->query_type == Z_SRW_query_type_pqf &&
1068 assoc->init->bend_scan)
1070 Odr_oid *scan_attributeSet = 0;
1072 YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
1074 bsrr->term = yaz_pqf_scan(pqf_parser, assoc->decode,
1076 srw_req->scanClause.pqf);
1077 if (scan_attributeSet &&
1078 (attset = oid_getentbyoid(scan_attributeSet)) &&
1079 (attset->oclass == CLASS_ATTSET ||
1080 attset->oclass == CLASS_GENERAL))
1081 bsrr->attributeset = attset->value;
1083 bsrr->attributeset = VAL_NONE;
1084 yaz_pqf_destroy(pqf_parser);
1085 bsrr->scanClause = 0;
1086 ((int (*)(void *, bend_scan_rr *))
1087 (*assoc->init->bend_scan))(assoc->backend, bsrr);
1089 else if (srw_req->query_type == Z_SRW_query_type_cql
1090 && assoc->init->bend_srw_scan)
1092 if (assoc->cql_transform)
1095 bsrr->scanClause = 0;
1096 bsrr->attributeset = VAL_NONE;
1097 bsrr->term = odr_malloc(assoc->decode, sizeof(*bsrr->term));
1098 srw_error = cql2pqf_scan(assoc->encode,
1099 srw_req->scanClause.cql,
1100 assoc->cql_transform,
1103 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1104 &srw_res->num_diagnostics,
1108 ((int (*)(void *, bend_scan_rr *))
1109 (*assoc->init->bend_scan))(assoc->backend, bsrr);
1115 bsrr->attributeset = VAL_NONE;
1116 bsrr->scanClause = srw_req->scanClause.cql;
1117 ((int (*)(void *, bend_scan_rr *))
1118 (*assoc->init->bend_srw_scan))(assoc->backend, bsrr);
1123 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1124 &srw_res->num_diagnostics,
1125 YAZ_SRW_UNSUPP_OPERATION, "scan");
1130 if (bsrr->errcode == YAZ_BIB1_DATABASE_UNAVAILABLE)
1135 srw_error = yaz_diag_bib1_to_srw (bsrr->errcode);
1137 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1138 &srw_res->num_diagnostics,
1139 srw_error, bsrr->errstring);
1141 else if (srw_res->num_diagnostics == 0 && bsrr->num_entries)
1144 srw_res->terms = (Z_SRW_scanTerm*)
1145 odr_malloc(assoc->encode, sizeof(*srw_res->terms) *
1148 srw_res->num_terms = bsrr->num_entries;
1149 for (i = 0; i<bsrr->num_entries; i++)
1151 Z_SRW_scanTerm *t = srw_res->terms + i;
1152 t->value = odr_strdup(assoc->encode, bsrr->entries[i].term);
1153 t->numberOfRecords =
1154 odr_intdup(assoc->encode, bsrr->entries[i].occurrences);
1156 if (save_entries == bsrr->entries &&
1157 bsrr->entries[i].display_term)
1159 /* the entries was _not_ set by the handler. So it's
1160 safe to test for new member display_term. It is
1163 t->displayTerm = odr_strdup(assoc->encode,
1164 bsrr->entries[i].display_term);
1172 WRBUF wr = wrbuf_alloc();
1173 const char *querytype = 0;
1174 const char *querystr = 0;
1176 switch(srw_req->query_type)
1178 case Z_SRW_query_type_pqf:
1180 querystr = srw_req->scanClause.pqf;
1182 case Z_SRW_query_type_cql:
1184 querystr = srw_req->scanClause.cql;
1187 querytype = "Unknown";
1190 wrbuf_printf(wr, "SRWScan %d+%d",
1191 (srw_req->responsePosition ?
1192 *srw_req->responsePosition : 1),
1193 (srw_req->maximumTerms ?
1194 *srw_req->maximumTerms : 1));
1195 if (srw_res->num_diagnostics)
1196 wrbuf_printf(wr, " ERROR %s", srw_res->diagnostics[0].uri);
1198 wrbuf_printf(wr, " OK -");
1199 wrbuf_printf(wr, " %s: %s", querytype, querystr);
1200 yaz_log(log_request, "%s", wrbuf_buf(wr) );
1206 static void srw_bend_update(association *assoc, request *req,
1207 Z_SRW_updateRequest *srw_req,
1208 Z_SRW_updateResponse *srw_res,
1211 yaz_log(YLOG_DEBUG, "Got SRW UpdateRequest");
1212 yaz_log(YLOG_DEBUG, "num_diag = %d", srw_res->num_diagnostics );
1214 srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
1219 rr.stream = assoc->encode;
1220 rr.print = assoc->print;
1222 rr.basenames = &srw_req->database;
1223 rr.operation = srw_req->operation;
1224 rr.operation_status = "failed";
1226 rr.record_version = 0;
1227 rr.record_checksum = 0;
1228 rr.record_old_version = 0;
1229 rr.record_packing = "xml";
1230 rr.record_schema = 0;
1232 rr.request_extra_record = 0;
1233 rr.response_extra_record = 0;
1234 rr.extra_request_data = 0;
1235 rr.extra_response_data = 0;
1239 yaz_log(YLOG_DEBUG, "basename = %s", rr.basenames[0] );
1240 yaz_log(YLOG_DEBUG, "Operation = %s", rr.operation );
1241 if ( !strcmp( rr.operation, "delete" ) ){
1242 if ( !srw_req->recordId ){
1243 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1244 &srw_res->num_diagnostics,
1248 rr.record_id = srw_req->recordId;
1250 if ( !srw_req->recordVersion ){
1251 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1252 &srw_res->num_diagnostics,
1253 7, "recordVersion" );
1256 rr.record_version = odr_strdup( assoc->encode,
1257 srw_req->recordVersion );
1260 if ( srw_req->recordOldVersion ){
1261 rr.record_old_version = odr_strdup(assoc->encode,
1262 srw_req->recordOldVersion );
1264 if ( srw_req->extraRequestData ){
1265 rr.extra_request_data = odr_strdup(assoc->encode,
1266 srw_req->extraRequestData );
1269 else if ( !strcmp( rr.operation, "replace" ) ){
1270 if ( !srw_req->recordId ){
1271 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1272 &srw_res->num_diagnostics,
1276 rr.record_id = srw_req->recordId;
1278 if ( srw_req->record.recordSchema == 0 ){
1279 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1280 &srw_res->num_diagnostics,
1281 7, "recordSchema" );
1284 rr.record_schema = odr_strdup(assoc->encode,
1285 srw_req->record.recordSchema );
1287 switch (srw_req->record.recordPacking)
1289 case Z_SRW_recordPacking_string:
1290 rr.record_packing = "string";
1292 case Z_SRW_recordPacking_XML:
1293 rr.record_packing = "xml";
1295 case Z_SRW_recordPacking_URL:
1296 rr.record_packing = "url";
1299 if ( srw_req->record.recordData_len ){
1300 rr.record_data = odr_strdupn(assoc->encode,
1301 srw_req->record.recordData_buf,
1302 srw_req->record.recordData_len );
1303 rr.request_extra_record = srw_req->extra_record;
1306 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1307 &srw_res->num_diagnostics,
1310 if (srw_req->extraRequestData)
1311 rr.extra_request_data = odr_strdup(assoc->encode,
1312 srw_req->extraRequestData );
1314 else if ( !strcmp( rr.operation, "insert" ) )
1316 if ( srw_req->record.recordSchema == 0 ){
1317 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1318 &srw_res->num_diagnostics,
1319 7, "recordSchema" );
1322 rr.record_schema = odr_strdup(assoc->encode,
1323 srw_req->record.recordSchema);
1325 switch (srw_req->record.recordPacking)
1327 case Z_SRW_recordPacking_string:
1328 rr.record_packing = "string";
1330 case Z_SRW_recordPacking_XML:
1331 rr.record_packing = "xml";
1333 case Z_SRW_recordPacking_URL:
1334 rr.record_packing = "url";
1338 if (srw_req->record.recordData_len)
1340 rr.record_data = odr_strdupn(assoc->encode,
1341 srw_req->record.recordData_buf,
1342 srw_req->record.recordData_len );
1343 rr.request_extra_record = srw_req->extra_record;
1346 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
1347 &srw_res->num_diagnostics,
1349 if ( srw_req->extraRequestData )
1350 rr.extra_request_data = odr_strdup(assoc->encode,
1351 srw_req->extraRequestData );
1353 if (srw_res->num_diagnostics == 0)
1355 if ( assoc->init->bend_srw_update)
1356 (*assoc->init->bend_srw_update)(assoc->backend, &rr);
1358 yaz_log( YLOG_WARN, "Got No Update function!");
1363 yaz_add_srw_diagnostic(assoc->encode,
1364 &srw_res->diagnostics,
1365 &srw_res->num_diagnostics,
1366 rr.errcode, rr.errstring);
1367 srw_res->recordId = rr.record_id;
1368 srw_res->operationStatus = rr.operation_status;
1369 srw_res->recordVersion = rr.record_version;
1370 srw_res->recordChecksum = rr.record_checksum;
1371 srw_res->extraResponseData = rr.extra_response_data;
1372 srw_res->record.recordPosition = 0;
1373 if (srw_res->num_diagnostics == 0 && rr.record_data)
1375 srw_res->record.recordSchema = rr.record_schema;
1376 srw_res->record.recordPacking = srw_req->record.recordPacking;
1377 srw_res->record.recordData_buf = rr.record_data;
1378 srw_res->record.recordData_len = strlen(rr.record_data);
1379 srw_res->extra_record = rr.response_extra_record;
1383 srw_res->record.recordData_len = 0;
1388 static void process_http_request(association *assoc, request *req)
1390 Z_HTTP_Request *hreq = req->gdu_request->u.HTTP_Request;
1391 ODR o = assoc->encode;
1392 int r = 2; /* 2=NOT TAKEN, 1=TAKEN, 0=SOAP TAKEN */
1394 Z_SOAP *soap_package = 0;
1397 Z_HTTP_Response *hres = 0;
1399 char *stylesheet = 0;
1400 Z_SRW_diagnostic *diagnostic = 0;
1401 int num_diagnostic = 0;
1402 const char *host = z_HTTP_header_lookup(hreq->headers, "Host");
1404 if (!control_association(assoc, host, 0))
1406 p = z_get_HTTP_Response(o, 404);
1409 if (r == 2 && !strcmp(hreq->path, "/test"))
1411 p = z_get_HTTP_Response(o, 200);
1412 hres = p->u.HTTP_Response;
1413 hres->content_buf = "1234567890\n";
1414 hres->content_len = strlen(hres->content_buf);
1419 r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset);
1420 yaz_log(YLOG_DEBUG, "yaz_srw_decode returned %d", r);
1422 if (r == 2) /* not taken */
1424 r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset,
1425 &diagnostic, &num_diagnostic);
1426 yaz_log(YLOG_DEBUG, "yaz_sru_decode returned %d", r);
1428 if (r == 0) /* decode SRW/SRU OK .. */
1430 int http_code = 200;
1431 if (sr->which == Z_SRW_searchRetrieve_request)
1434 yaz_srw_get(assoc->encode, Z_SRW_searchRetrieve_response);
1436 stylesheet = sr->u.request->stylesheet;
1439 res->u.response->diagnostics = diagnostic;
1440 res->u.response->num_diagnostics = num_diagnostic;
1444 srw_bend_search(assoc, req, sr->u.request, res->u.response,
1447 if (http_code == 200)
1448 soap_package->u.generic->p = res;
1450 else if (sr->which == Z_SRW_explain_request)
1452 Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_explain_response);
1453 stylesheet = sr->u.explain_request->stylesheet;
1456 res->u.explain_response->diagnostics = diagnostic;
1457 res->u.explain_response->num_diagnostics = num_diagnostic;
1459 srw_bend_explain(assoc, req, sr->u.explain_request,
1460 res->u.explain_response, &http_code);
1461 if (http_code == 200)
1462 soap_package->u.generic->p = res;
1464 else if (sr->which == Z_SRW_scan_request)
1466 Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_scan_response);
1467 stylesheet = sr->u.scan_request->stylesheet;
1470 res->u.scan_response->diagnostics = diagnostic;
1471 res->u.scan_response->num_diagnostics = num_diagnostic;
1473 srw_bend_scan(assoc, req, sr->u.scan_request,
1474 res->u.scan_response, &http_code);
1475 if (http_code == 200)
1476 soap_package->u.generic->p = res;
1478 else if (sr->which == Z_SRW_update_request)
1480 Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_update_response);
1481 yaz_log(YLOG_DEBUG, "handling SRW UpdateRequest");
1484 res->u.update_response->diagnostics = diagnostic;
1485 res->u.update_response->num_diagnostics = num_diagnostic;
1487 yaz_log(YLOG_DEBUG, "num_diag = %d", res->u.update_response->num_diagnostics );
1488 srw_bend_update(assoc, req, sr->u.update_request,
1489 res->u.update_response, &http_code);
1490 if (http_code == 200)
1491 soap_package->u.generic->p = res;
1495 yaz_log(log_request, "SOAP ERROR");
1496 /* FIXME - what error, what query */
1498 z_soap_error(assoc->encode, soap_package,
1499 "SOAP-ENV:Client", "Bad method", 0);
1501 if (http_code == 200 || http_code == 500)
1503 static Z_SOAP_Handler soap_handlers[4] = {
1505 {"http://www.loc.gov/zing/srw/", 0,
1506 (Z_SOAP_fun) yaz_srw_codec},
1507 {"http://www.loc.gov/zing/srw/v1.0/", 0,
1508 (Z_SOAP_fun) yaz_srw_codec},
1509 {"http://www.loc.gov/zing/srw/update/", 0,
1510 (Z_SOAP_fun) yaz_ucp_codec},
1516 p = z_get_HTTP_Response(o, 200);
1517 hres = p->u.HTTP_Response;
1518 ret = z_soap_codec_enc_xsl(assoc->encode, &soap_package,
1519 &hres->content_buf, &hres->content_len,
1520 soap_handlers, charset, stylesheet);
1521 hres->code = http_code;
1523 strcpy(ctype, "text/xml");
1526 strcat(ctype, "; charset=");
1527 strcat(ctype, charset);
1529 z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype);
1532 p = z_get_HTTP_Response(o, http_code);
1536 p = z_get_HTTP_Response(o, 500);
1537 hres = p->u.HTTP_Response;
1538 if (!strcmp(hreq->version, "1.0"))
1540 const char *v = z_HTTP_header_lookup(hreq->headers, "Connection");
1541 if (v && !strcmp(v, "Keep-Alive"))
1545 hres->version = "1.0";
1549 const char *v = z_HTTP_header_lookup(hreq->headers, "Connection");
1550 if (v && !strcmp(v, "close"))
1554 hres->version = "1.1";
1558 z_HTTP_header_add(o, &hres->headers, "Connection", "close");
1559 assoc->state = ASSOC_DEAD;
1560 assoc->cs_get_mask = 0;
1565 const char *alive = z_HTTP_header_lookup(hreq->headers, "Keep-Alive");
1567 if (alive && isdigit(*(const unsigned char *) alive))
1571 if (t < 0 || t > 3600)
1573 iochan_settimeout(assoc->client_chan,t);
1574 z_HTTP_header_add(o, &hres->headers, "Connection", "Keep-Alive");
1576 process_gdu_response(assoc, req, p);
1579 static void process_gdu_request(association *assoc, request *req)
1581 if (req->gdu_request->which == Z_GDU_Z3950)
1584 req->apdu_request = req->gdu_request->u.z3950;
1585 if (process_z_request(assoc, req, &msg) < 0)
1586 do_close_req(assoc, Z_Close_systemProblem, msg, req);
1588 else if (req->gdu_request->which == Z_GDU_HTTP_Request)
1589 process_http_request(assoc, req);
1592 do_close_req(assoc, Z_Close_systemProblem, "bad protocol packet", req);
1597 * Initiate request processing.
1599 static int process_z_request(association *assoc, request *req, char **msg)
1605 *msg = "Unknown Error";
1606 assert(req && req->state == REQUEST_IDLE);
1607 if (req->apdu_request->which != Z_APDU_initRequest && !assoc->init)
1609 *msg = "Missing InitRequest";
1612 switch (req->apdu_request->which)
1614 case Z_APDU_initRequest:
1615 res = process_initRequest(assoc, req); break;
1616 case Z_APDU_searchRequest:
1617 res = process_searchRequest(assoc, req, &fd); break;
1618 case Z_APDU_presentRequest:
1619 res = process_presentRequest(assoc, req, &fd); break;
1620 case Z_APDU_scanRequest:
1621 if (assoc->init->bend_scan)
1622 res = process_scanRequest(assoc, req, &fd);
1625 *msg = "Cannot handle Scan APDU";
1629 case Z_APDU_extendedServicesRequest:
1630 if (assoc->init->bend_esrequest)
1631 res = process_ESRequest(assoc, req, &fd);
1634 *msg = "Cannot handle Extended Services APDU";
1638 case Z_APDU_sortRequest:
1639 if (assoc->init->bend_sort)
1640 res = process_sortRequest(assoc, req, &fd);
1643 *msg = "Cannot handle Sort APDU";
1648 process_close(assoc, req);
1650 case Z_APDU_deleteResultSetRequest:
1651 if (assoc->init->bend_delete)
1652 res = process_deleteRequest(assoc, req, &fd);
1655 *msg = "Cannot handle Delete APDU";
1659 case Z_APDU_segmentRequest:
1660 if (assoc->init->bend_segment)
1662 res = process_segmentRequest (assoc, req);
1666 *msg = "Cannot handle Segment APDU";
1670 case Z_APDU_triggerResourceControlRequest:
1673 *msg = "Bad APDU received";
1678 yaz_log(YLOG_DEBUG, " result immediately available");
1679 retval = process_z_response(assoc, req, res);
1683 yaz_log(YLOG_DEBUG, " result unavailble");
1686 else /* no result yet - one will be provided later */
1690 /* Set up an I/O handler for the fd supplied by the backend */
1692 yaz_log(YLOG_DEBUG, " establishing handler for result");
1693 req->state = REQUEST_PENDING;
1694 if (!(chan = iochan_create(fd, backend_response, EVENT_INPUT, 0)))
1696 iochan_setdata(chan, assoc);
1703 * Handle message from the backend.
1705 void backend_response(IOCHAN i, int event)
1707 association *assoc = (association *)iochan_getdata(i);
1708 request *req = request_head(&assoc->incoming);
1712 yaz_log(YLOG_DEBUG, "backend_response");
1713 assert(assoc && req && req->state != REQUEST_IDLE);
1714 /* determine what it is we're waiting for */
1715 switch (req->apdu_request->which)
1717 case Z_APDU_searchRequest:
1718 res = response_searchRequest(assoc, req, 0, &fd); break;
1720 case Z_APDU_presentRequest:
1721 res = response_presentRequest(assoc, req, 0, &fd); break;
1722 case Z_APDU_scanRequest:
1723 res = response_scanRequest(assoc, req, 0, &fd); break;
1726 yaz_log(YLOG_FATAL, "Serious programmer's lapse or bug");
1729 if ((res && process_z_response(assoc, req, res) < 0) || fd < 0)
1731 yaz_log(YLOG_WARN, "Fatal error when talking to backend");
1732 do_close(assoc, Z_Close_systemProblem, 0);
1736 else if (!res) /* no result yet - try again later */
1738 yaz_log(YLOG_DEBUG, " no result yet");
1739 iochan_setfd(i, fd); /* in case fd has changed */
1744 * Encode response, and transfer the request structure to the outgoing queue.
1746 static int process_gdu_response(association *assoc, request *req, Z_GDU *res)
1748 odr_setbuf(assoc->encode, req->response, req->size_response, 1);
1752 if (!z_GDU(assoc->print, &res, 0, 0))
1753 yaz_log(YLOG_WARN, "ODR print error: %s",
1754 odr_errmsg(odr_geterror(assoc->print)));
1755 odr_reset(assoc->print);
1757 if (!z_GDU(assoc->encode, &res, 0, 0))
1759 yaz_log(YLOG_WARN, "ODR error when encoding PDU: %s [element %s]",
1760 odr_errmsg(odr_geterror(assoc->decode)),
1761 odr_getelement(assoc->decode));
1764 req->response = odr_getbuf(assoc->encode, &req->len_response,
1765 &req->size_response);
1766 odr_setbuf(assoc->encode, 0, 0, 0); /* don'txfree if we abort later */
1767 odr_reset(assoc->encode);
1768 req->state = REQUEST_IDLE;
1769 request_enq(&assoc->outgoing, req);
1770 /* turn the work over to the ir_session handler */
1771 iochan_setflag(assoc->client_chan, EVENT_OUTPUT);
1772 assoc->cs_put_mask = EVENT_OUTPUT;
1773 /* Is there more work to be done? give that to the input handler too */
1775 if (request_head(&assoc->incoming))
1777 yaz_log (YLOG_DEBUG, "more work to be done");
1778 iochan_setevent(assoc->client_chan, EVENT_WORK);
1785 * Encode response, and transfer the request structure to the outgoing queue.
1787 static int process_z_response(association *assoc, request *req, Z_APDU *res)
1789 Z_GDU *gres = (Z_GDU *) odr_malloc(assoc->encode, sizeof(*res));
1790 gres->which = Z_GDU_Z3950;
1791 gres->u.z3950 = res;
1793 return process_gdu_response(assoc, req, gres);
1796 static char *get_vhost(Z_OtherInformation *otherInfo)
1798 return yaz_oi_get_string_oidval(&otherInfo, VAL_PROXY, 1, 0);
1802 * Handle init request.
1803 * At the moment, we don't check the options
1804 * anywhere else in the code - we just try not to do anything that would
1805 * break a naive client. We'll toss 'em into the association block when
1806 * we need them there.
1808 static Z_APDU *process_initRequest(association *assoc, request *reqb)
1810 Z_InitRequest *req = reqb->apdu_request->u.initRequest;
1811 Z_APDU *apdu = zget_APDU(assoc->encode, Z_APDU_initResponse);
1812 Z_InitResponse *resp = apdu->u.initResponse;
1813 bend_initresult *binitres;
1816 statserv_options_block *cb = 0; /* by default no control for backend */
1818 if (control_association(assoc, get_vhost(req->otherInfo), 1))
1819 cb = statserv_getcontrol(); /* got control block for backend */
1821 if (cb && assoc->backend)
1822 (*cb->bend_close)(assoc->backend);
1824 yaz_log(log_requestdetail, "Got initRequest");
1825 if (req->implementationId)
1826 yaz_log(log_requestdetail, "Id: %s",
1827 req->implementationId);
1828 if (req->implementationName)
1829 yaz_log(log_requestdetail, "Name: %s",
1830 req->implementationName);
1831 if (req->implementationVersion)
1832 yaz_log(log_requestdetail, "Version: %s",
1833 req->implementationVersion);
1835 assoc_init_reset(assoc);
1837 assoc->init->auth = req->idAuthentication;
1838 assoc->init->referenceId = req->referenceId;
1840 if (ODR_MASK_GET(req->options, Z_Options_negotiationModel))
1842 Z_CharSetandLanguageNegotiation *negotiation =
1843 yaz_get_charneg_record (req->otherInfo);
1845 negotiation->which == Z_CharSetandLanguageNegotiation_proposal)
1846 assoc->init->charneg_request = negotiation;
1852 if (req->implementationVersion)
1853 yaz_log(log_requestdetail, "Config: %s",
1856 iochan_settimeout(assoc->client_chan, cb->idle_timeout * 60);
1858 /* we have a backend control block, so call that init function */
1859 if (!(binitres = (*cb->bend_init)(assoc->init)))
1861 yaz_log(YLOG_WARN, "Bad response from backend.");
1864 assoc->backend = binitres->handle;
1868 /* no backend. return error */
1869 binitres = odr_malloc(assoc->encode, sizeof(*binitres));
1870 binitres->errstring = 0;
1871 binitres->errcode = YAZ_BIB1_PERMANENT_SYSTEM_ERROR;
1872 iochan_settimeout(assoc->client_chan, 10);
1874 if ((assoc->init->bend_sort))
1875 yaz_log (YLOG_DEBUG, "Sort handler installed");
1876 if ((assoc->init->bend_search))
1877 yaz_log (YLOG_DEBUG, "Search handler installed");
1878 if ((assoc->init->bend_present))
1879 yaz_log (YLOG_DEBUG, "Present handler installed");
1880 if ((assoc->init->bend_esrequest))
1881 yaz_log (YLOG_DEBUG, "ESRequest handler installed");
1882 if ((assoc->init->bend_delete))
1883 yaz_log (YLOG_DEBUG, "Delete handler installed");
1884 if ((assoc->init->bend_scan))
1885 yaz_log (YLOG_DEBUG, "Scan handler installed");
1886 if ((assoc->init->bend_segment))
1887 yaz_log (YLOG_DEBUG, "Segment handler installed");
1889 resp->referenceId = req->referenceId;
1891 /* let's tell the client what we can do */
1892 if (ODR_MASK_GET(req->options, Z_Options_search))
1894 ODR_MASK_SET(resp->options, Z_Options_search);
1895 strcat(options, "srch");
1897 if (ODR_MASK_GET(req->options, Z_Options_present))
1899 ODR_MASK_SET(resp->options, Z_Options_present);
1900 strcat(options, " prst");
1902 if (ODR_MASK_GET(req->options, Z_Options_delSet) &&
1903 assoc->init->bend_delete)
1905 ODR_MASK_SET(resp->options, Z_Options_delSet);
1906 strcat(options, " del");
1908 if (ODR_MASK_GET(req->options, Z_Options_extendedServices) &&
1909 assoc->init->bend_esrequest)
1911 ODR_MASK_SET(resp->options, Z_Options_extendedServices);
1912 strcat (options, " extendedServices");
1914 if (ODR_MASK_GET(req->options, Z_Options_namedResultSets))
1916 ODR_MASK_SET(resp->options, Z_Options_namedResultSets);
1917 strcat(options, " namedresults");
1919 if (ODR_MASK_GET(req->options, Z_Options_scan) && assoc->init->bend_scan)
1921 ODR_MASK_SET(resp->options, Z_Options_scan);
1922 strcat(options, " scan");
1924 if (ODR_MASK_GET(req->options, Z_Options_concurrentOperations))
1926 ODR_MASK_SET(resp->options, Z_Options_concurrentOperations);
1927 strcat(options, " concurrop");
1929 if (ODR_MASK_GET(req->options, Z_Options_sort) && assoc->init->bend_sort)
1931 ODR_MASK_SET(resp->options, Z_Options_sort);
1932 strcat(options, " sort");
1935 if (ODR_MASK_GET(req->options, Z_Options_negotiationModel)
1936 && assoc->init->charneg_response)
1938 Z_OtherInformation **p;
1939 Z_OtherInformationUnit *p0;
1941 yaz_oi_APDU(apdu, &p);
1943 if ((p0=yaz_oi_update(p, assoc->encode, NULL, 0, 0))) {
1944 ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
1946 p0->which = Z_OtherInfo_externallyDefinedInfo;
1947 p0->information.externallyDefinedInfo =
1948 assoc->init->charneg_response;
1950 ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
1951 strcat(options, " negotiation");
1954 ODR_MASK_SET(resp->options, Z_Options_triggerResourceCtrl);
1956 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1))
1958 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1);
1959 assoc->version = 1; /* 1 & 2 are equivalent */
1961 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2))
1963 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_2);
1966 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_3))
1968 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3);
1972 yaz_log(log_requestdetail, "Negotiated to v%d: %s", assoc->version, options);
1973 assoc->maximumRecordSize = *req->maximumRecordSize;
1975 if (cb && assoc->maximumRecordSize > cb->maxrecordsize)
1976 assoc->maximumRecordSize = cb->maxrecordsize;
1977 assoc->preferredMessageSize = *req->preferredMessageSize;
1978 if (assoc->preferredMessageSize > assoc->maximumRecordSize)
1979 assoc->preferredMessageSize = assoc->maximumRecordSize;
1981 resp->preferredMessageSize = &assoc->preferredMessageSize;
1982 resp->maximumRecordSize = &assoc->maximumRecordSize;
1984 resp->implementationId = odr_prepend(assoc->encode,
1985 assoc->init->implementation_id,
1986 resp->implementationId);
1988 resp->implementationName = odr_prepend(assoc->encode,
1989 assoc->init->implementation_name,
1990 odr_prepend(assoc->encode, "GFS", resp->implementationName));
1992 version = odr_strdup(assoc->encode, "$Revision: 1.66 $");
1993 if (strlen(version) > 10) /* check for unexpanded CVS strings */
1994 version[strlen(version)-2] = '\0';
1995 resp->implementationVersion = odr_prepend(assoc->encode,
1996 assoc->init->implementation_version,
1997 odr_prepend(assoc->encode, &version[11],
1998 resp->implementationVersion));
2000 if (binitres->errcode)
2002 assoc->state = ASSOC_DEAD;
2003 resp->userInformationField =
2004 init_diagnostics(assoc->encode, binitres->errcode,
2005 binitres->errstring);
2010 if (!req->idAuthentication)
2011 yaz_log(log_request, "Auth none");
2012 else if (req->idAuthentication->which == Z_IdAuthentication_open)
2014 const char *open = req->idAuthentication->u.open;
2015 const char *slash = strchr(open, '/');
2021 yaz_log(log_request, "Auth open %.*s", len, open);
2023 else if (req->idAuthentication->which == Z_IdAuthentication_idPass)
2025 const char *user = req->idAuthentication->u.idPass->userId;
2026 const char *group = req->idAuthentication->u.idPass->groupId;
2027 yaz_log(log_request, "Auth idPass %s %s",
2028 user ? user : "-", group ? group : "-");
2030 else if (req->idAuthentication->which
2031 == Z_IdAuthentication_anonymous)
2033 yaz_log(log_request, "Auth anonymous");
2037 yaz_log(log_request, "Auth other");
2042 WRBUF wr = wrbuf_alloc();
2043 wrbuf_printf(wr, "Init ");
2044 if (binitres->errcode)
2045 wrbuf_printf(wr, "ERROR %d", binitres->errcode);
2047 wrbuf_printf(wr, "OK -");
2048 wrbuf_printf(wr, " ID:%s Name:%s Version:%s",
2049 (req->implementationId ? req->implementationId :"-"),
2050 (req->implementationName ?
2051 req->implementationName : "-"),
2052 (req->implementationVersion ?
2053 req->implementationVersion : "-")
2055 yaz_log(log_request, "%s", wrbuf_buf(wr));
2062 * Set the specified `errcode' and `errstring' into a UserInfo-1
2063 * external to be returned to the client in accordance with Z35.90
2064 * Implementor Agreement 5 (Returning diagnostics in an InitResponse):
2065 * http://lcweb.loc.gov/z3950/agency/agree/initdiag.html
2067 static Z_External *init_diagnostics(ODR odr, int error, const char *addinfo)
2069 yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
2070 addinfo ? " -- " : "", addinfo ? addinfo : "");
2071 return zget_init_diagnostics(odr, error, addinfo);
2075 * nonsurrogate diagnostic record.
2077 static Z_Records *diagrec(association *assoc, int error, char *addinfo)
2079 Z_Records *rec = (Z_Records *) odr_malloc (assoc->encode, sizeof(*rec));
2081 yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
2082 addinfo ? " -- " : "", addinfo ? addinfo : "");
2084 rec->which = Z_Records_NSD;
2085 rec->u.nonSurrogateDiagnostic = zget_DefaultDiagFormat(assoc->encode,
2091 * surrogate diagnostic.
2093 static Z_NamePlusRecord *surrogatediagrec(association *assoc,
2095 int error, const char *addinfo)
2097 yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
2098 addinfo ? " -- " : "", addinfo ? addinfo : "");
2099 return zget_surrogateDiagRec(assoc->encode, dbname, error, addinfo);
2102 static Z_Records *pack_records(association *a, char *setname, int start,
2103 int *num, Z_RecordComposition *comp,
2104 int *next, int *pres, oid_value format,
2105 Z_ReferenceId *referenceId,
2106 int *oid, int *errcode)
2108 int recno, total_length = 0, toget = *num, dumped_records = 0;
2109 Z_Records *records =
2110 (Z_Records *) odr_malloc (a->encode, sizeof(*records));
2111 Z_NamePlusRecordList *reclist =
2112 (Z_NamePlusRecordList *) odr_malloc (a->encode, sizeof(*reclist));
2113 Z_NamePlusRecord **list =
2114 (Z_NamePlusRecord **) odr_malloc (a->encode, sizeof(*list) * toget);
2116 records->which = Z_Records_DBOSD;
2117 records->u.databaseOrSurDiagnostics = reclist;
2118 reclist->num_records = 0;
2119 reclist->records = list;
2120 *pres = Z_PresentStatus_success;
2124 yaz_log(log_requestdetail, "Request to pack %d+%d %s", start, toget, setname);
2125 yaz_log(log_requestdetail, "pms=%d, mrs=%d", a->preferredMessageSize,
2126 a->maximumRecordSize);
2127 for (recno = start; reclist->num_records < toget; recno++)
2130 Z_NamePlusRecord *thisrec;
2131 int this_length = 0;
2133 * we get the number of bytes allocated on the stream before any
2134 * allocation done by the backend - this should give us a reasonable
2135 * idea of the total size of the data so far.
2137 total_length = odr_total(a->encode) - dumped_records;
2143 freq.last_in_set = 0;
2144 freq.setname = setname;
2145 freq.surrogate_flag = 0;
2146 freq.number = recno;
2148 freq.request_format = format;
2149 freq.request_format_raw = oid;
2150 freq.output_format = format;
2151 freq.output_format_raw = 0;
2152 freq.stream = a->encode;
2153 freq.print = a->print;
2154 freq.referenceId = referenceId;
2156 (*a->init->bend_fetch)(a->backend, &freq);
2158 *next = freq.last_in_set ? 0 : recno + 1;
2160 /* backend should be able to signal whether error is system-wide
2161 or only pertaining to current record */
2164 if (!freq.surrogate_flag)
2167 *pres = Z_PresentStatus_failure;
2168 /* for 'present request out of range',
2169 set addinfo to record position if not set */
2170 if (freq.errcode == YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE &&
2171 freq.errstring == 0)
2173 sprintf (s, "%d", recno);
2177 *errcode = freq.errcode;
2178 return diagrec(a, freq.errcode, freq.errstring);
2180 reclist->records[reclist->num_records] =
2181 surrogatediagrec(a, freq.basename, freq.errcode,
2183 reclist->num_records++;
2186 if (freq.record == 0) /* no error and no record ? */
2188 *next = 0; /* signal end-of-set and stop */
2192 this_length = freq.len;
2194 this_length = odr_total(a->encode) - total_length - dumped_records;
2195 yaz_log(YLOG_DEBUG, " fetched record, len=%d, total=%d dumped=%d",
2196 this_length, total_length, dumped_records);
2197 if (a->preferredMessageSize > 0 &&
2198 this_length + total_length > a->preferredMessageSize)
2200 /* record is small enough, really */
2201 if (this_length <= a->preferredMessageSize && recno > start)
2203 yaz_log(log_requestdetail, " Dropped last normal-sized record");
2204 *pres = Z_PresentStatus_partial_2;
2207 /* record can only be fetched by itself */
2208 if (this_length < a->maximumRecordSize)
2210 yaz_log(log_requestdetail, " Record > prefmsgsz");
2213 yaz_log(YLOG_DEBUG, " Dropped it");
2214 reclist->records[reclist->num_records] =
2215 surrogatediagrec(a, freq.basename, 16, 0);
2216 reclist->num_records++;
2217 dumped_records += this_length;
2221 else /* too big entirely */
2223 yaz_log(log_requestdetail, "Record > maxrcdsz this=%d max=%d",
2224 this_length, a->maximumRecordSize);
2225 reclist->records[reclist->num_records] =
2226 surrogatediagrec(a, freq.basename, 17, 0);
2227 reclist->num_records++;
2228 dumped_records += this_length;
2233 if (!(thisrec = (Z_NamePlusRecord *)
2234 odr_malloc(a->encode, sizeof(*thisrec))))
2237 thisrec->databaseName = odr_strdup(a->encode, freq.basename);
2239 thisrec->databaseName = 0;
2240 thisrec->which = Z_NamePlusRecord_databaseRecord;
2242 if (freq.output_format_raw)
2244 struct oident *ident = oid_getentbyoid(freq.output_format_raw);
2245 freq.output_format = ident->value;
2247 thisrec->u.databaseRecord = z_ext_record(a->encode, freq.output_format,
2248 freq.record, freq.len);
2249 if (!thisrec->u.databaseRecord)
2251 reclist->records[reclist->num_records] = thisrec;
2252 reclist->num_records++;
2254 *num = reclist->num_records;
2258 static Z_APDU *process_searchRequest(association *assoc, request *reqb,
2261 Z_SearchRequest *req = reqb->apdu_request->u.searchRequest;
2262 bend_search_rr *bsrr =
2263 (bend_search_rr *)nmem_malloc (reqb->request_mem, sizeof(*bsrr));
2265 yaz_log(log_requestdetail, "Got SearchRequest.");
2267 bsrr->request = reqb;
2268 bsrr->association = assoc;
2269 bsrr->referenceId = req->referenceId;
2270 save_referenceId (reqb, bsrr->referenceId);
2271 bsrr->srw_sortKeys = 0;
2272 bsrr->srw_setname = 0;
2273 bsrr->srw_setnameIdleTime = 0;
2275 yaz_log (log_requestdetail, "ResultSet '%s'", req->resultSetName);
2276 if (req->databaseNames)
2279 for (i = 0; i < req->num_databaseNames; i++)
2280 yaz_log (log_requestdetail, "Database '%s'", req->databaseNames[i]);
2283 yaz_log_zquery_level(log_requestdetail,req->query);
2285 if (assoc->init->bend_search)
2287 bsrr->setname = req->resultSetName;
2288 bsrr->replace_set = *req->replaceIndicator;
2289 bsrr->num_bases = req->num_databaseNames;
2290 bsrr->basenames = req->databaseNames;
2291 bsrr->query = req->query;
2292 bsrr->stream = assoc->encode;
2293 nmem_transfer(bsrr->stream->mem, reqb->request_mem);
2294 bsrr->decode = assoc->decode;
2295 bsrr->print = assoc->print;
2298 bsrr->errstring = NULL;
2299 bsrr->search_info = NULL;
2301 if (assoc->cql_transform &&
2302 req->query->which == Z_Query_type_104 &&
2303 req->query->u.type_104->which == Z_External_CQL)
2305 /* have a CQL query and a CQL to PQF transform .. */
2307 cql2pqf(bsrr->stream, req->query->u.type_104->u.cql,
2308 assoc->cql_transform, bsrr->query);
2310 bsrr->errcode = yaz_diag_srw_to_bib1(srw_errcode);
2313 (assoc->init->bend_search)(assoc->backend, bsrr);
2314 if (!bsrr->request) /* backend not ready with the search response */
2315 return 0; /* should not be used any more */
2319 /* FIXME - make a diagnostic for it */
2320 yaz_log(YLOG_WARN,"Search not supported ?!?!");
2322 return response_searchRequest(assoc, reqb, bsrr, fd);
2325 int bend_searchresponse(void *handle, bend_search_rr *bsrr) {return 0;}
2328 * Prepare a searchresponse based on the backend results. We probably want
2329 * to look at making the fetching of records nonblocking as well, but
2330 * so far, we'll keep things simple.
2331 * If bsrt is null, that means we're called in response to a communications
2332 * event, and we'll have to get the response for ourselves.
2334 static Z_APDU *response_searchRequest(association *assoc, request *reqb,
2335 bend_search_rr *bsrt, int *fd)
2337 Z_SearchRequest *req = reqb->apdu_request->u.searchRequest;
2338 Z_APDU *apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
2339 Z_SearchResponse *resp = (Z_SearchResponse *)
2340 odr_malloc (assoc->encode, sizeof(*resp));
2341 int *nulint = odr_intdup (assoc->encode, 0);
2342 bool_t *sr = odr_intdup(assoc->encode, 1);
2343 int *next = odr_intdup(assoc->encode, 0);
2344 int *none = odr_intdup(assoc->encode, Z_SearchResponse_none);
2347 apdu->which = Z_APDU_searchResponse;
2348 apdu->u.searchResponse = resp;
2349 resp->referenceId = req->referenceId;
2350 resp->additionalSearchInfo = 0;
2351 resp->otherInfo = 0;
2353 if (!bsrt && !bend_searchresponse(assoc->backend, bsrt))
2355 yaz_log(YLOG_FATAL, "Bad result from backend");
2358 else if (bsrt->errcode)
2360 resp->records = diagrec(assoc, bsrt->errcode, bsrt->errstring);
2361 resp->resultCount = nulint;
2362 resp->numberOfRecordsReturned = nulint;
2363 resp->nextResultSetPosition = nulint;
2364 resp->searchStatus = nulint;
2365 resp->resultSetStatus = none;
2366 resp->presentStatus = 0;
2370 int *toget = odr_intdup(assoc->encode, 0);
2371 int *presst = odr_intdup(assoc->encode, 0);
2372 Z_RecordComposition comp, *compp = 0;
2374 yaz_log (log_requestdetail, "resultCount: %d", bsrt->hits);
2377 resp->resultCount = &bsrt->hits;
2379 comp.which = Z_RecordComp_simple;
2380 /* how many records does the user agent want, then? */
2381 if (bsrt->hits <= *req->smallSetUpperBound)
2383 *toget = bsrt->hits;
2384 if ((comp.u.simple = req->smallSetElementSetNames))
2387 else if (bsrt->hits < *req->largeSetLowerBound)
2389 *toget = *req->mediumSetPresentNumber;
2390 if (*toget > bsrt->hits)
2391 *toget = bsrt->hits;
2392 if ((comp.u.simple = req->mediumSetElementSetNames))
2398 if (*toget && !resp->records)
2403 if (!(prefformat = oid_getentbyoid(req->preferredRecordSyntax)))
2406 form = prefformat->value;
2407 resp->records = pack_records(assoc, req->resultSetName, 1,
2408 toget, compp, next, presst, form, req->referenceId,
2409 req->preferredRecordSyntax, NULL);
2412 resp->numberOfRecordsReturned = toget;
2413 returnedrecs = *toget;
2414 resp->nextResultSetPosition = next;
2415 resp->searchStatus = sr;
2416 resp->resultSetStatus = 0;
2417 resp->presentStatus = presst;
2421 if (*resp->resultCount)
2423 resp->numberOfRecordsReturned = nulint;
2424 resp->nextResultSetPosition = next;
2425 resp->searchStatus = sr;
2426 resp->resultSetStatus = 0;
2427 resp->presentStatus = 0;
2430 resp->additionalSearchInfo = bsrt->search_info;
2434 WRBUF wr = wrbuf_alloc();
2436 wrbuf_printf(wr, "ERROR %d", bsrt->errcode);
2438 wrbuf_printf(wr, "OK %d", bsrt->hits);
2439 wrbuf_printf(wr, " %s 1+%d ",
2440 req->resultSetName, returnedrecs);
2441 yaz_query_to_wrbuf(wr, req->query);
2443 yaz_log(log_request, "Search %s", wrbuf_buf(wr));
2450 * Maybe we got a little over-friendly when we designed bend_fetch to
2451 * get only one record at a time. Some backends can optimise multiple-record
2452 * fetches, and at any rate, there is some overhead involved in
2453 * all that selecting and hopping around. Problem is, of course, that the
2454 * frontend can't know ahead of time how many records it'll need to
2455 * fill the negotiated PDU size. Annoying. Segmentation or not, Z/SR
2456 * is downright lousy as a bulk data transfer protocol.
2458 * To start with, we'll do the fetching of records from the backend
2459 * in one operation: To save some trips in and out of the event-handler,
2460 * and to simplify the interface to pack_records. At any rate, asynch
2461 * operation is more fun in operations that have an unpredictable execution
2462 * speed - which is normally more true for search than for present.
2464 static Z_APDU *process_presentRequest(association *assoc, request *reqb,
2467 Z_PresentRequest *req = reqb->apdu_request->u.presentRequest;
2471 Z_PresentResponse *resp;
2475 const char *errstring = 0;
2477 yaz_log(log_requestdetail, "Got PresentRequest.");
2479 if (!(prefformat = oid_getentbyoid(req->preferredRecordSyntax)))
2482 form = prefformat->value;
2483 resp = (Z_PresentResponse *)odr_malloc (assoc->encode, sizeof(*resp));
2485 resp->presentStatus = odr_intdup(assoc->encode, 0);
2486 if (assoc->init->bend_present)
2488 bend_present_rr *bprr = (bend_present_rr *)
2489 nmem_malloc (reqb->request_mem, sizeof(*bprr));
2490 bprr->setname = req->resultSetId;
2491 bprr->start = *req->resultSetStartPoint;
2492 bprr->number = *req->numberOfRecordsRequested;
2493 bprr->format = form;
2494 bprr->comp = req->recordComposition;
2495 bprr->referenceId = req->referenceId;
2496 bprr->stream = assoc->encode;
2497 bprr->print = assoc->print;
2498 bprr->request = reqb;
2499 bprr->association = assoc;
2501 bprr->errstring = NULL;
2502 (*assoc->init->bend_present)(assoc->backend, bprr);
2505 return 0; /* should not happen */
2508 resp->records = diagrec(assoc, bprr->errcode, bprr->errstring);
2509 *resp->presentStatus = Z_PresentStatus_failure;
2510 errcode = bprr->errcode;
2511 errstring = bprr->errstring;
2514 apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
2515 next = odr_intdup(assoc->encode, 0);
2516 num = odr_intdup(assoc->encode, 0);
2518 apdu->which = Z_APDU_presentResponse;
2519 apdu->u.presentResponse = resp;
2520 resp->referenceId = req->referenceId;
2521 resp->otherInfo = 0;
2525 *num = *req->numberOfRecordsRequested;
2527 pack_records(assoc, req->resultSetId, *req->resultSetStartPoint,
2528 num, req->recordComposition, next,
2529 resp->presentStatus,
2530 form, req->referenceId, req->preferredRecordSyntax,
2535 WRBUF wr = wrbuf_alloc();
2536 wrbuf_printf(wr, "Present ");
2538 if (*resp->presentStatus == Z_PresentStatus_failure)
2539 wrbuf_printf(wr, "ERROR %d", errcode);
2540 else if (*resp->presentStatus == Z_PresentStatus_success)
2541 wrbuf_printf(wr, "OK -");
2543 wrbuf_printf(wr, "Partial %d", *resp->presentStatus);
2545 wrbuf_printf(wr, " %s %d+%d ",
2546 req->resultSetId, *req->resultSetStartPoint,
2547 *req->numberOfRecordsRequested);
2548 yaz_log(log_request, "%s", wrbuf_buf(wr) );
2553 resp->numberOfRecordsReturned = num;
2554 resp->nextResultSetPosition = next;
2560 * Scan was implemented rather in a hurry, and with support for only the basic
2561 * elements of the service in the backend API. Suggestions are welcome.
2563 static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
2565 Z_ScanRequest *req = reqb->apdu_request->u.scanRequest;
2566 Z_APDU *apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
2567 Z_ScanResponse *res = (Z_ScanResponse *)
2568 odr_malloc (assoc->encode, sizeof(*res));
2569 int *scanStatus = odr_intdup(assoc->encode, Z_Scan_failure);
2570 int *numberOfEntriesReturned = odr_intdup(assoc->encode, 0);
2571 Z_ListEntries *ents = (Z_ListEntries *)
2572 odr_malloc (assoc->encode, sizeof(*ents));
2573 Z_DiagRecs *diagrecs_p = NULL;
2575 bend_scan_rr *bsrr = (bend_scan_rr *)
2576 odr_malloc (assoc->encode, sizeof(*bsrr));
2577 struct scan_entry *save_entries;
2579 yaz_log(log_requestdetail, "Got ScanRequest");
2581 apdu->which = Z_APDU_scanResponse;
2582 apdu->u.scanResponse = res;
2583 res->referenceId = req->referenceId;
2585 /* if step is absent, set it to 0 */
2586 res->stepSize = odr_intdup(assoc->encode, 0);
2588 *res->stepSize = *req->stepSize;
2590 res->scanStatus = scanStatus;
2591 res->numberOfEntriesReturned = numberOfEntriesReturned;
2592 res->positionOfTerm = 0;
2593 res->entries = ents;
2594 ents->num_entries = 0;
2595 ents->entries = NULL;
2596 ents->num_nonsurrogateDiagnostics = 0;
2597 ents->nonsurrogateDiagnostics = NULL;
2598 res->attributeSet = 0;
2601 if (req->databaseNames)
2604 for (i = 0; i < req->num_databaseNames; i++)
2605 yaz_log (log_requestdetail, "Database '%s'", req->databaseNames[i]);
2607 bsrr->scanClause = 0;
2609 bsrr->errstring = 0;
2610 bsrr->num_bases = req->num_databaseNames;
2611 bsrr->basenames = req->databaseNames;
2612 bsrr->num_entries = *req->numberOfTermsRequested;
2613 bsrr->term = req->termListAndStartPoint;
2614 bsrr->referenceId = req->referenceId;
2615 bsrr->stream = assoc->encode;
2616 bsrr->print = assoc->print;
2617 bsrr->step_size = res->stepSize;
2619 /* For YAZ 2.0 and earlier it was the backend handler that
2620 initialized entries (member display_term did not exist)
2621 YAZ 2.0 and later sets 'entries' and initialize all members
2622 including 'display_term'. If YAZ 2.0 or later sees that
2623 entries was modified - we assume that it is an old handler and
2624 that 'display_term' is _not_ set.
2626 if (bsrr->num_entries > 0)
2629 bsrr->entries = odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
2631 for (i = 0; i<bsrr->num_entries; i++)
2633 bsrr->entries[i].term = 0;
2634 bsrr->entries[i].occurrences = 0;
2635 bsrr->entries[i].errcode = 0;
2636 bsrr->entries[i].errstring = 0;
2637 bsrr->entries[i].display_term = 0;
2640 save_entries = bsrr->entries; /* save it so we can compare later */
2642 if (req->attributeSet &&
2643 (attset = oid_getentbyoid(req->attributeSet)) &&
2644 (attset->oclass == CLASS_ATTSET || attset->oclass == CLASS_GENERAL))
2645 bsrr->attributeset = attset->value;
2647 bsrr->attributeset = VAL_NONE;
2648 log_scan_term_level (log_requestdetail, req->termListAndStartPoint,
2649 bsrr->attributeset);
2650 bsrr->term_position = req->preferredPositionInResponse ?
2651 *req->preferredPositionInResponse : 1;
2653 ((int (*)(void *, bend_scan_rr *))
2654 (*assoc->init->bend_scan))(assoc->backend, bsrr);
2657 diagrecs_p = zget_DiagRecs(assoc->encode,
2658 bsrr->errcode, bsrr->errstring);
2662 Z_Entry **tab = (Z_Entry **)
2663 odr_malloc (assoc->encode, sizeof(*tab) * bsrr->num_entries);
2665 if (bsrr->status == BEND_SCAN_PARTIAL)
2666 *scanStatus = Z_Scan_partial_5;
2668 *scanStatus = Z_Scan_success;
2669 ents->entries = tab;
2670 ents->num_entries = bsrr->num_entries;
2671 res->numberOfEntriesReturned = &ents->num_entries;
2672 res->positionOfTerm = &bsrr->term_position;
2673 for (i = 0; i < bsrr->num_entries; i++)
2679 tab[i] = e = (Z_Entry *)odr_malloc(assoc->encode, sizeof(*e));
2680 if (bsrr->entries[i].occurrences >= 0)
2682 e->which = Z_Entry_termInfo;
2683 e->u.termInfo = t = (Z_TermInfo *)
2684 odr_malloc(assoc->encode, sizeof(*t));
2685 t->suggestedAttributes = 0;
2687 if (save_entries == bsrr->entries &&
2688 bsrr->entries[i].display_term)
2690 /* the entries was _not_ set by the handler. So it's
2691 safe to test for new member display_term. It is
2694 t->displayTerm = odr_strdup(assoc->encode,
2695 bsrr->entries[i].display_term);
2697 t->alternativeTerm = 0;
2698 t->byAttributes = 0;
2699 t->otherTermInfo = 0;
2700 t->globalOccurrences = &bsrr->entries[i].occurrences;
2701 t->term = (Z_Term *)
2702 odr_malloc(assoc->encode, sizeof(*t->term));
2703 t->term->which = Z_Term_general;
2704 t->term->u.general = o =
2705 (Odr_oct *)odr_malloc(assoc->encode, sizeof(Odr_oct));
2706 o->buf = (unsigned char *)
2707 odr_malloc(assoc->encode, o->len = o->size =
2708 strlen(bsrr->entries[i].term));
2709 memcpy(o->buf, bsrr->entries[i].term, o->len);
2710 yaz_log(YLOG_DEBUG, " term #%d: '%s' (%d)", i,
2711 bsrr->entries[i].term, bsrr->entries[i].occurrences);
2715 Z_DiagRecs *drecs = zget_DiagRecs(assoc->encode,
2716 bsrr->entries[i].errcode,
2717 bsrr->entries[i].errstring);
2718 assert (drecs->num_diagRecs == 1);
2719 e->which = Z_Entry_surrogateDiagnostic;
2720 assert (drecs->diagRecs[0]);
2721 e->u.surrogateDiagnostic = drecs->diagRecs[0];
2727 ents->num_nonsurrogateDiagnostics = diagrecs_p->num_diagRecs;
2728 ents->nonsurrogateDiagnostics = diagrecs_p->diagRecs;
2732 WRBUF wr = wrbuf_alloc();
2734 wr_diag(wr, bsrr->errcode, bsrr->errstring);
2735 else if (*res->scanStatus == Z_Scan_success)
2736 wrbuf_printf(wr, "OK");
2738 wrbuf_printf(wr, "Partial");
2740 wrbuf_printf(wr, " %d+%d %d ",
2741 (req->preferredPositionInResponse ?
2742 *req->preferredPositionInResponse : 1),
2743 *req->numberOfTermsRequested,
2744 (res->stepSize ? *res->stepSize : 0));
2745 yaz_scan_to_wrbuf(wr, req->termListAndStartPoint,
2746 bsrr->attributeset);
2747 yaz_log(log_request, "Scan %s", wrbuf_buf(wr) );
2753 static Z_APDU *process_sortRequest(association *assoc, request *reqb,
2757 Z_SortRequest *req = reqb->apdu_request->u.sortRequest;
2758 Z_SortResponse *res = (Z_SortResponse *)
2759 odr_malloc (assoc->encode, sizeof(*res));
2760 bend_sort_rr *bsrr = (bend_sort_rr *)
2761 odr_malloc (assoc->encode, sizeof(*bsrr));
2763 Z_APDU *apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
2765 yaz_log(log_requestdetail, "Got SortRequest.");
2767 bsrr->num_input_setnames = req->num_inputResultSetNames;
2768 for (i=0;i<req->num_inputResultSetNames;i++)
2769 yaz_log(log_requestdetail, "Input resultset: '%s'",
2770 req->inputResultSetNames[i]);
2771 bsrr->input_setnames = req->inputResultSetNames;
2772 bsrr->referenceId = req->referenceId;
2773 bsrr->output_setname = req->sortedResultSetName;
2774 yaz_log(log_requestdetail, "Output resultset: '%s'",
2775 req->sortedResultSetName);
2776 bsrr->sort_sequence = req->sortSequence;
2777 /*FIXME - dump those sequences too */
2778 bsrr->stream = assoc->encode;
2779 bsrr->print = assoc->print;
2781 bsrr->sort_status = Z_SortResponse_failure;
2783 bsrr->errstring = 0;
2785 (*assoc->init->bend_sort)(assoc->backend, bsrr);
2787 res->referenceId = bsrr->referenceId;
2788 res->sortStatus = odr_intdup(assoc->encode, bsrr->sort_status);
2789 res->resultSetStatus = 0;
2792 Z_DiagRecs *dr = zget_DiagRecs(assoc->encode,
2793 bsrr->errcode, bsrr->errstring);
2794 res->diagnostics = dr->diagRecs;
2795 res->num_diagnostics = dr->num_diagRecs;
2799 res->num_diagnostics = 0;
2800 res->diagnostics = 0;
2802 res->resultCount = 0;
2805 apdu->which = Z_APDU_sortResponse;
2806 apdu->u.sortResponse = res;
2809 WRBUF wr = wrbuf_alloc();
2810 wrbuf_printf(wr, "Sort ");
2812 wrbuf_printf(wr, " ERROR %d", bsrr->errcode);
2814 wrbuf_printf(wr, "OK -");
2815 wrbuf_printf(wr, " (");
2816 for (i = 0; i<req->num_inputResultSetNames; i++)
2819 wrbuf_printf(wr, ",");
2820 wrbuf_printf(wr, req->inputResultSetNames[i]);
2822 wrbuf_printf(wr, ")->%s ",req->sortedResultSetName);
2824 yaz_log(log_request, "%s", wrbuf_buf(wr) );
2830 static Z_APDU *process_deleteRequest(association *assoc, request *reqb,
2834 Z_DeleteResultSetRequest *req =
2835 reqb->apdu_request->u.deleteResultSetRequest;
2836 Z_DeleteResultSetResponse *res = (Z_DeleteResultSetResponse *)
2837 odr_malloc (assoc->encode, sizeof(*res));
2838 bend_delete_rr *bdrr = (bend_delete_rr *)
2839 odr_malloc (assoc->encode, sizeof(*bdrr));
2840 Z_APDU *apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
2842 yaz_log(log_requestdetail, "Got DeleteRequest.");
2844 bdrr->num_setnames = req->num_resultSetList;
2845 bdrr->setnames = req->resultSetList;
2846 for (i = 0; i<req->num_resultSetList; i++)
2847 yaz_log(log_requestdetail, "resultset: '%s'",
2848 req->resultSetList[i]);
2849 bdrr->stream = assoc->encode;
2850 bdrr->print = assoc->print;
2851 bdrr->function = *req->deleteFunction;
2852 bdrr->referenceId = req->referenceId;
2854 if (bdrr->num_setnames > 0)
2856 bdrr->statuses = (int*)
2857 odr_malloc(assoc->encode, sizeof(*bdrr->statuses) *
2858 bdrr->num_setnames);
2859 for (i = 0; i < bdrr->num_setnames; i++)
2860 bdrr->statuses[i] = 0;
2862 (*assoc->init->bend_delete)(assoc->backend, bdrr);
2864 res->referenceId = req->referenceId;
2866 res->deleteOperationStatus = odr_intdup(assoc->encode,bdrr->delete_status);
2868 res->deleteListStatuses = 0;
2869 if (bdrr->num_setnames > 0)
2872 res->deleteListStatuses = (Z_ListStatuses *)
2873 odr_malloc(assoc->encode, sizeof(*res->deleteListStatuses));
2874 res->deleteListStatuses->num = bdrr->num_setnames;
2875 res->deleteListStatuses->elements =
2877 odr_malloc (assoc->encode,
2878 sizeof(*res->deleteListStatuses->elements) *
2879 bdrr->num_setnames);
2880 for (i = 0; i<bdrr->num_setnames; i++)
2882 res->deleteListStatuses->elements[i] =
2884 odr_malloc (assoc->encode,
2885 sizeof(**res->deleteListStatuses->elements));
2886 res->deleteListStatuses->elements[i]->status = bdrr->statuses+i;
2887 res->deleteListStatuses->elements[i]->id =
2888 odr_strdup (assoc->encode, bdrr->setnames[i]);
2891 res->numberNotDeleted = 0;
2892 res->bulkStatuses = 0;
2893 res->deleteMessage = 0;
2896 apdu->which = Z_APDU_deleteResultSetResponse;
2897 apdu->u.deleteResultSetResponse = res;
2900 WRBUF wr = wrbuf_alloc();
2901 wrbuf_printf(wr, "Delete ");
2902 if (bdrr->delete_status)
2903 wrbuf_printf(wr, "ERROR %d", bdrr->delete_status);
2905 wrbuf_printf(wr, "OK -");
2906 for (i = 0; i<req->num_resultSetList; i++)
2907 wrbuf_printf(wr, " %s ", req->resultSetList[i]);
2908 yaz_log(log_request, "%s", wrbuf_buf(wr) );
2914 static void process_close(association *assoc, request *reqb)
2916 Z_Close *req = reqb->apdu_request->u.close;
2917 static char *reasons[] =
2924 "securityViolation",
2931 yaz_log(log_requestdetail, "Got Close, reason %s, message %s",
2932 reasons[*req->closeReason], req->diagnosticInformation ?
2933 req->diagnosticInformation : "NULL");
2934 if (assoc->version < 3) /* to make do_force respond with close */
2936 do_close_req(assoc, Z_Close_finished,
2937 "Association terminated by client", reqb);
2938 yaz_log(log_request,"Close OK");
2941 void save_referenceId (request *reqb, Z_ReferenceId *refid)
2945 reqb->len_refid = refid->len;
2946 reqb->refid = (char *)nmem_malloc (reqb->request_mem, refid->len);
2947 memcpy (reqb->refid, refid->buf, refid->len);
2951 reqb->len_refid = 0;
2956 void bend_request_send (bend_association a, bend_request req, Z_APDU *res)
2958 process_z_response (a, req, res);
2961 bend_request bend_request_mk (bend_association a)
2963 request *nreq = request_get (&a->outgoing);
2964 nreq->request_mem = nmem_create ();
2968 Z_ReferenceId *bend_request_getid (ODR odr, bend_request req)
2973 id = (Odr_oct *)odr_malloc (odr, sizeof(*odr));
2974 id->buf = (unsigned char *)odr_malloc (odr, req->len_refid);
2975 id->len = id->size = req->len_refid;
2976 memcpy (id->buf, req->refid, req->len_refid);
2980 void bend_request_destroy (bend_request *req)
2982 nmem_destroy((*req)->request_mem);
2983 request_release(*req);
2987 int bend_backend_respond (bend_association a, bend_request req)
2991 r = process_z_request (a, req, &msg);
2993 yaz_log (YLOG_WARN, "%s", msg);
2997 void bend_request_setdata(bend_request r, void *p)
3002 void *bend_request_getdata(bend_request r)
3004 return r->clientData;
3007 static Z_APDU *process_segmentRequest (association *assoc, request *reqb)
3009 bend_segment_rr req;
3011 req.segment = reqb->apdu_request->u.segmentRequest;
3012 req.stream = assoc->encode;
3013 req.decode = assoc->decode;
3014 req.print = assoc->print;
3015 req.association = assoc;
3017 (*assoc->init->bend_segment)(assoc->backend, &req);
3022 static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd)
3024 bend_esrequest_rr esrequest;
3026 Z_ExtendedServicesRequest *req =
3027 reqb->apdu_request->u.extendedServicesRequest;
3028 Z_APDU *apdu = zget_APDU(assoc->encode, Z_APDU_extendedServicesResponse);
3030 Z_ExtendedServicesResponse *resp = apdu->u.extendedServicesResponse;
3032 yaz_log(log_requestdetail,"Got EsRequest");
3034 esrequest.esr = reqb->apdu_request->u.extendedServicesRequest;
3035 esrequest.stream = assoc->encode;
3036 esrequest.decode = assoc->decode;
3037 esrequest.print = assoc->print;
3038 esrequest.errcode = 0;
3039 esrequest.errstring = NULL;
3040 esrequest.request = reqb;
3041 esrequest.association = assoc;
3042 esrequest.taskPackage = 0;
3043 esrequest.referenceId = req->referenceId;
3045 (*assoc->init->bend_esrequest)(assoc->backend, &esrequest);
3047 /* If the response is being delayed, return NULL */
3048 if (esrequest.request == NULL)
3051 resp->referenceId = req->referenceId;
3053 if (esrequest.errcode == -1)
3055 /* Backend service indicates request will be processed */
3056 yaz_log(log_request,"EsRequest OK: Accepted !");
3057 *resp->operationStatus = Z_ExtendedServicesResponse_accepted;
3059 else if (esrequest.errcode == 0)
3061 /* Backend service indicates request will be processed */
3062 yaz_log(log_request,"EsRequest OK: Done !");
3063 *resp->operationStatus = Z_ExtendedServicesResponse_done;
3067 Z_DiagRecs *diagRecs =
3068 zget_DiagRecs(assoc->encode, esrequest.errcode,
3069 esrequest.errstring);
3070 /* Backend indicates error, request will not be processed */
3071 yaz_log(YLOG_DEBUG,"Request could not be processed...failure !");
3072 *resp->operationStatus = Z_ExtendedServicesResponse_failure;
3073 resp->num_diagnostics = diagRecs->num_diagRecs;
3074 resp->diagnostics = diagRecs->diagRecs;
3077 WRBUF wr = wrbuf_alloc();
3078 wrbuf_diags(wr, resp->num_diagnostics, resp->diagnostics);
3079 yaz_log(log_request, "EsRequest %s", wrbuf_buf(wr) );
3084 /* Do something with the members of bend_extendedservice */
3085 if (esrequest.taskPackage)
3086 resp->taskPackage = z_ext_record (assoc->encode, VAL_EXTENDED,
3087 (const char *) esrequest.taskPackage,
3089 yaz_log(YLOG_DEBUG,"Send the result apdu");
3096 * indent-tabs-mode: nil
3098 * vim: shiftwidth=4 tabstop=8 expandtab