1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
7 * \brief yaz-ztest Generic Frontend Server
18 #include <yaz/backend.h>
20 #include <yaz/diagbib1.h>
24 static int log_level=0;
25 static int log_level_set=0;
31 struct result_set *next;
34 struct session_handle {
35 struct result_set *result_sets;
38 int ztest_search(void *handle, bend_search_rr *rr);
39 int ztest_sort(void *handle, bend_sort_rr *rr);
40 int ztest_present(void *handle, bend_present_rr *rr);
41 int ztest_esrequest(void *handle, bend_esrequest_rr *rr);
42 int ztest_delete(void *handle, bend_delete_rr *rr);
44 static struct result_set *get_set(struct session_handle *sh, const char *name)
46 struct result_set *set = sh->result_sets;
47 for (; set; set = set->next)
48 if (!strcmp(name, set->name))
53 static void remove_sets(struct session_handle *sh)
55 struct result_set *set = sh->result_sets;
58 struct result_set *set_next = set->next;
67 /** \brief use term value as hit count
68 \param s RPN structure
69 \return >= 0: search term number or -1: not found
71 Traverse RPN tree 'in order' and use term value as hit count.
72 Only terms that looks a numeric is used.. Returns -1 if
73 no sub tree has a hit count term
75 static Odr_int get_term_hit(Z_RPNStructure *s)
80 case Z_RPNStructure_simple:
81 if (s->u.simple->which == Z_Operand_APT)
83 Z_AttributesPlusTerm *apt = s->u.simple->u.attributesPlusTerm;
84 if (apt->term->which == Z_Term_general)
86 Odr_oct *oct = apt->term->u.general;
87 if (oct->len > 0 && oct->buf[0] >= '0' && oct->buf[0] <= '9')
89 WRBUF hits_str = wrbuf_alloc();
90 wrbuf_write(hits_str, (const char *) oct->buf, oct->len);
91 h = odr_atoi(wrbuf_cstr(hits_str));
92 wrbuf_destroy(hits_str);
97 case Z_RPNStructure_complex:
98 h = get_term_hit(s->u.complex->s1);
100 h = get_term_hit(s->u.complex->s2);
106 /** \brief gets hit count for numeric terms in RPN queries
108 \return number of hits (random or number for term)
110 This is just for testing.. A real database of course uses
111 the content of a database to establish a value.. In our case, we
112 have a way to trigger a certain hit count. Good for testing of
113 client applications etc
115 static Odr_int get_hit_count(Z_Query *q)
118 if (q->which == Z_Query_type_1 || q->which == Z_Query_type_101)
119 h = get_term_hit(q->u.type_1->RPNStructure);
125 /** \brief checks if it's a dummy Slow database
126 \param basename database name to check
127 \param association backend association (or NULL if not available)
128 \retval 1 is slow database
129 \retval 0 is not a slow database
131 The Slow database is for testing.. It allows us to simulate
134 static int check_slow(const char *basename, bend_association association)
136 if (strncmp(basename, "Slow", 4) == 0)
141 sscanf(basename+4, "%d", &w);
142 /* wait up to 3 seconds and check if connection is still alive */
143 for (i = 0; i < w; i++)
145 if (association && !bend_assoc_is_alive(association))
147 yaz_log(YLOG_LOG, "search aborted");
158 int ztest_search(void *handle, bend_search_rr *rr)
160 struct session_handle *sh = (struct session_handle*) handle;
161 struct result_set *new_set;
163 if (rr->num_bases != 1)
165 rr->errcode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
168 /* Allow Default, db.* and Slow */
169 if (!yaz_matchstr(rr->basenames[0], "Default"))
170 ; /* Default is OK in our test */
171 else if (!strncmp(rr->basenames[0], "db", 2))
172 ; /* db.* is OK in our test */
173 else if (check_slow(rr->basenames[0], rr->association))
175 rr->estimated_hit_count = 1;
179 rr->errcode = YAZ_BIB1_DATABASE_UNAVAILABLE;
180 rr->errstring = rr->basenames[0];
184 new_set = get_set(sh, rr->setname);
187 if (!rr->replace_set)
189 rr->errcode = YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF;
196 new_set = xmalloc(sizeof(*new_set));
197 new_set->next = sh->result_sets;
198 sh->result_sets = new_set;
199 new_set->name = xstrdup(rr->setname);
205 WRBUF response_xml = wrbuf_alloc();
206 wrbuf_puts(response_xml, "<extra>");
207 for (a = rr->extra_args; a; a = a->next)
209 wrbuf_puts(response_xml, "<extra name=\"");
210 wrbuf_xmlputs(response_xml, a->name);
211 wrbuf_puts(response_xml, "\"");
214 wrbuf_puts(response_xml, " value=\"");
215 wrbuf_xmlputs(response_xml, a->value);
216 wrbuf_puts(response_xml, "\"");
218 wrbuf_puts(response_xml, "/>");
220 wrbuf_puts(response_xml, "</extra>");
221 rr->extra_response_data =
222 odr_strdup(rr->stream, wrbuf_cstr(response_xml));
223 wrbuf_destroy(response_xml);
225 rr->hits = get_hit_count(rr->query);
227 new_set->hits = rr->hits;
228 new_set->db = xstrdup(rr->basenames[0]);
234 /* this huge function handles extended services */
235 int ztest_esrequest(void *handle, bend_esrequest_rr *rr)
237 /* user-defined handle - created in bend_init */
238 int *counter = (int*) handle;
240 yaz_log(log_level, "ESRequest no %d", *counter);
244 if (rr->esr->packageName)
245 yaz_log(log_level, "packagename: %s", rr->esr->packageName);
246 yaz_log(log_level, "Waitaction: " ODR_INT_PRINTF, *rr->esr->waitAction);
249 yaz_log(log_level, "function: " ODR_INT_PRINTF, *rr->esr->function);
251 if (!rr->esr->taskSpecificParameters)
253 yaz_log(log_level, "No task specific parameters");
255 else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder)
257 Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder;
258 yaz_log(log_level, "Received ItemOrder");
259 if (it->which == Z_IOItemOrder_esRequest)
261 Z_IORequest *ir = it->u.esRequest;
262 Z_IOOriginPartToKeep *k = ir->toKeep;
263 Z_IOOriginPartNotToKeep *n = ir->notToKeep;
264 const char *xml_in_response = 0;
268 if (k->contact->name)
269 yaz_log(log_level, "contact name %s", k->contact->name);
270 if (k->contact->phone)
271 yaz_log(log_level, "contact phone %s", k->contact->phone);
272 if (k->contact->email)
273 yaz_log(log_level, "contact email %s", k->contact->email);
277 yaz_log(log_level, "Billing info (not shown)");
280 if (n->resultSetItem)
282 yaz_log(log_level, "resultsetItem");
283 yaz_log(log_level, "setId: %s", n->resultSetItem->resultSetId);
284 yaz_log(log_level, "item: " ODR_INT_PRINTF, *n->resultSetItem->item);
288 Z_External *r = (Z_External*) n->itemRequest;
289 ILL_ItemRequest *item_req = 0;
290 ILL_APDU *ill_apdu = 0;
291 if (r->direct_reference)
293 char oid_name_str[OID_STR_MAX];
295 const char *oid_name =
296 yaz_oid_to_string_buf(r->direct_reference,
297 &oclass, oid_name_str);
299 yaz_log(log_level, "OID %s", oid_name);
300 if (!oid_oidcmp(r->direct_reference, yaz_oid_recsyn_xml))
302 yaz_log(log_level, "ILL XML request");
303 if (r->which == Z_External_octet)
304 yaz_log(log_level, "%.*s",
305 r->u.octet_aligned->len,
306 r->u.octet_aligned->buf);
307 xml_in_response = "<dummy>x</dummy>";
309 if (!oid_oidcmp(r->direct_reference,
310 yaz_oid_general_isoill_1))
312 yaz_log(log_level, "Decode ItemRequest begin");
313 if (r->which == ODR_EXTERNAL_single)
315 odr_setbuf(rr->decode,
316 (char *) r->u.single_ASN1_type->buf,
317 r->u.single_ASN1_type->len, 0);
319 if (!ill_ItemRequest(rr->decode, &item_req, 0, 0))
322 "Couldn't decode ItemRequest %s near %ld",
323 odr_errmsg(odr_geterror(rr->decode)),
324 (long) odr_offset(rr->decode));
327 yaz_log(log_level, "Decode ItemRequest OK");
330 ill_ItemRequest(rr->print, &item_req, 0,
332 odr_reset(rr->print);
335 if (!item_req && r->which == ODR_EXTERNAL_single)
337 yaz_log(log_level, "Decode ILL APDU begin");
338 odr_setbuf(rr->decode,
339 (char*) r->u.single_ASN1_type->buf,
340 r->u.single_ASN1_type->len, 0);
342 if (!ill_APDU(rr->decode, &ill_apdu, 0, 0))
345 "Couldn't decode ILL APDU %s near %ld",
346 odr_errmsg(odr_geterror(rr->decode)),
347 (long) odr_offset(rr->decode));
348 yaz_log(log_level, "PDU dump:");
349 odr_dumpBER(yaz_log_file(),
350 (char *) r->u.single_ASN1_type->buf,
351 r->u.single_ASN1_type->len);
354 yaz_log(log_level, "Decode ILL APDU OK");
357 ill_APDU(rr->print, &ill_apdu, 0,
359 odr_reset(rr->print);
366 yaz_log(log_level, "ILL protocol version = "
368 *item_req->protocol_version_num);
374 Z_External *ext = (Z_External *)
375 odr_malloc(rr->stream, sizeof(*ext));
376 Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *)
377 odr_malloc(rr->stream, sizeof(*keep));
378 Z_IOTargetPart *targetPart = (Z_IOTargetPart *)
379 odr_malloc(rr->stream, sizeof(*targetPart));
381 rr->taskPackage = (Z_TaskPackage *)
382 odr_malloc(rr->stream, sizeof(*rr->taskPackage));
383 rr->taskPackage->packageType =
384 odr_oiddup(rr->stream, rr->esr->packageType);
385 rr->taskPackage->packageName = 0;
386 rr->taskPackage->userId = 0;
387 rr->taskPackage->retentionTime = 0;
388 rr->taskPackage->permissions = 0;
389 rr->taskPackage->description = 0;
390 rr->taskPackage->targetReference = (Odr_oct *)
391 odr_malloc(rr->stream, sizeof(Odr_oct));
392 rr->taskPackage->targetReference->buf =
393 (unsigned char *) odr_strdup(rr->stream, "911");
394 rr->taskPackage->targetReference->len =
395 rr->taskPackage->targetReference->size =
396 strlen((char *) (rr->taskPackage->targetReference->buf));
397 rr->taskPackage->creationDateTime = 0;
398 rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0);
399 rr->taskPackage->packageDiagnostics = 0;
400 rr->taskPackage->taskSpecificParameters = ext;
402 ext->direct_reference =
403 odr_oiddup(rr->stream, rr->esr->packageType);
404 ext->indirect_reference = 0;
406 ext->which = Z_External_itemOrder;
407 ext->u.itemOrder = (Z_ItemOrder *)
408 odr_malloc(rr->stream, sizeof(*ext->u.update));
409 ext->u.itemOrder->which = Z_IOItemOrder_taskPackage;
410 ext->u.itemOrder->u.taskPackage = (Z_IOTaskPackage *)
411 odr_malloc(rr->stream, sizeof(Z_IOTaskPackage));
412 ext->u.itemOrder->u.taskPackage->originPart = k;
413 ext->u.itemOrder->u.taskPackage->targetPart = targetPart;
416 targetPart->itemRequest =
417 z_ext_record_xml(rr->stream, xml_in_response,
418 strlen(xml_in_response));
420 targetPart->itemRequest = 0;
422 targetPart->statusOrErrorReport = 0;
423 targetPart->auxiliaryStatus = 0;
427 else if (rr->esr->taskSpecificParameters->which == Z_External_update)
429 Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
430 yaz_log(log_level, "Received DB Update");
431 if (up->which == Z_IUUpdate_esRequest)
433 Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
434 Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
435 Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
437 yaz_log(log_level, "action");
440 switch (*toKeep->action)
442 case Z_IUOriginPartToKeep_recordInsert:
443 yaz_log(log_level, " recordInsert");
445 case Z_IUOriginPartToKeep_recordReplace:
446 yaz_log(log_level, " recordReplace");
448 case Z_IUOriginPartToKeep_recordDelete:
449 yaz_log(log_level, " recordDelete");
451 case Z_IUOriginPartToKeep_elementUpdate:
452 yaz_log(log_level, " elementUpdate");
454 case Z_IUOriginPartToKeep_specialUpdate:
455 yaz_log(log_level, " specialUpdate");
458 yaz_log(log_level, " unknown (" ODR_INT_PRINTF ")",
462 if (toKeep->databaseName)
464 yaz_log(log_level, "database: %s", toKeep->databaseName);
465 if (!strcmp(toKeep->databaseName, "fault"))
467 rr->errcode = YAZ_BIB1_DATABASE_UNAVAILABLE;
468 rr->errstring = toKeep->databaseName;
470 if (!strcmp(toKeep->databaseName, "accept"))
475 Z_External *ext = (Z_External *)
476 odr_malloc(rr->stream, sizeof(*ext));
477 Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *)
478 odr_malloc(rr->stream, sizeof(*keep));
479 Z_IUTargetPart *targetPart = (Z_IUTargetPart *)
480 odr_malloc(rr->stream, sizeof(*targetPart));
482 rr->taskPackage = (Z_TaskPackage *)
483 odr_malloc(rr->stream, sizeof(*rr->taskPackage));
484 rr->taskPackage->packageType =
485 odr_oiddup(rr->stream, rr->esr->packageType);
486 rr->taskPackage->packageName = 0;
487 rr->taskPackage->userId = 0;
488 rr->taskPackage->retentionTime = 0;
489 rr->taskPackage->permissions = 0;
490 rr->taskPackage->description = 0;
491 rr->taskPackage->targetReference = (Odr_oct *)
492 odr_malloc(rr->stream, sizeof(Odr_oct));
493 rr->taskPackage->targetReference->buf =
494 (unsigned char *) odr_strdup(rr->stream, "123");
495 rr->taskPackage->targetReference->len =
496 rr->taskPackage->targetReference->size =
497 strlen((char *) (rr->taskPackage->targetReference->buf));
498 rr->taskPackage->creationDateTime = 0;
499 rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0);
500 rr->taskPackage->packageDiagnostics = 0;
501 rr->taskPackage->taskSpecificParameters = ext;
503 ext->direct_reference =
504 odr_oiddup(rr->stream, rr->esr->packageType);
505 ext->indirect_reference = 0;
507 ext->which = Z_External_update;
508 ext->u.update = (Z_IUUpdate *)
509 odr_malloc(rr->stream, sizeof(*ext->u.update));
510 ext->u.update->which = Z_IUUpdate_taskPackage;
511 ext->u.update->u.taskPackage = (Z_IUUpdateTaskPackage *)
512 odr_malloc(rr->stream, sizeof(Z_IUUpdateTaskPackage));
513 ext->u.update->u.taskPackage->originPart = keep;
514 ext->u.update->u.taskPackage->targetPart = targetPart;
516 keep->action = odr_intdup(rr->stream, *toKeep->action);
518 odr_strdup(rr->stream, toKeep->databaseName);
520 keep->elementSetName = 0;
521 keep->actionQualifier = 0;
523 targetPart->updateStatus = odr_intdup(rr->stream, 1);
524 targetPart->num_globalDiagnostics = 0;
525 targetPart->globalDiagnostics = (Z_DiagRec **) odr_nullval();
526 targetPart->num_taskPackageRecords = 1;
527 targetPart->taskPackageRecords =
528 (Z_IUTaskPackageRecordStructure **)
529 odr_malloc(rr->stream,
530 sizeof(Z_IUTaskPackageRecordStructure *));
531 targetPart->taskPackageRecords[0] =
532 (Z_IUTaskPackageRecordStructure *)
533 odr_malloc(rr->stream,
534 sizeof(Z_IUTaskPackageRecordStructure));
536 targetPart->taskPackageRecords[0]->which =
537 Z_IUTaskPackageRecordStructure_record;
538 targetPart->taskPackageRecords[0]->u.record =
539 z_ext_record_sutrs(rr->stream, "test", 4);
540 targetPart->taskPackageRecords[0]->correlationInfo = 0;
541 targetPart->taskPackageRecords[0]->recordStatus =
542 odr_intdup(rr->stream,
543 Z_IUTaskPackageRecordStructure_success);
544 targetPart->taskPackageRecords[0]->num_supplementalDiagnostics
547 targetPart->taskPackageRecords[0]->supplementalDiagnostics = 0;
552 for (i = 0; i < notToKeep->num; i++)
554 Z_External *rec = notToKeep->elements[i]->record;
556 if (rec->direct_reference)
558 char oid_name_str[OID_STR_MAX];
560 = oid_name = yaz_oid_to_string_buf(
561 rec->direct_reference, 0,
564 yaz_log(log_level, "record %d type %s", i,
569 case Z_External_sutrs:
570 if (rec->u.octet_aligned->len > 170)
571 yaz_log(log_level, "%d bytes:\n%.168s ...",
575 yaz_log(log_level, "%d bytes:\n%s",
579 case Z_External_octet :
580 if (rec->u.octet_aligned->len > 170)
581 yaz_log(log_level, "%d bytes:\n%.168s ...",
582 rec->u.octet_aligned->len,
583 rec->u.octet_aligned->buf);
585 yaz_log(log_level, "%d bytes\n%s",
586 rec->u.octet_aligned->len,
587 rec->u.octet_aligned->buf);
596 /* result set delete */
597 int ztest_delete(void *handle, bend_delete_rr *rr)
599 if (rr->num_setnames == 1 && !strcmp(rr->setnames[0], "1"))
600 rr->delete_status = Z_DeleteStatus_success;
602 rr->delete_status = Z_DeleteStatus_resultSetDidNotExist;
606 /* Our sort handler really doesn't sort... */
607 int ztest_sort(void *handle, bend_sort_rr *rr)
610 rr->sort_status = Z_SortResponse_success;
615 /* present request handler */
616 int ztest_present(void *handle, bend_present_rr *rr)
621 /* retrieval of a single record (present, and piggy back search) */
622 int ztest_fetch(void *handle, bend_fetch_rr *r)
624 struct session_handle *sh = (struct session_handle*) handle;
626 const Odr_oid *oid = r->request_format;
627 struct result_set *set = get_set(sh, r->setname);
631 r->errcode = YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST;
632 r->errstring = odr_strdup(r->stream, r->setname);
636 r->basename = set->db;
637 r->output_format = r->request_format;
639 if (r->number < 1 || r->number > set->hits)
641 r->errcode = YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE;
644 if (!oid || yaz_oid_is_iso2709(oid))
646 cp = dummy_marc_record(r->number, r->stream);
649 r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
650 r->surrogate_flag = 1;
657 r->output_format = odr_oiddup(r->stream, yaz_oid_recsyn_usmarc);
660 else if (!oid_oidcmp(oid, yaz_oid_recsyn_opac))
662 cp = dummy_marc_record(r->number, r->stream);
665 r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
666 r->surrogate_flag = 1;
669 r->record = (char *) dummy_opac(r->number, r->stream, cp);
672 else if (!oid_oidcmp(oid, yaz_oid_recsyn_sutrs))
674 /* this section returns a small record */
677 sprintf(buf, "This is dummy SUTRS record number %d\n", r->number);
679 r->len = strlen(buf);
680 r->record = (char *) odr_malloc(r->stream, r->len+1);
681 strcpy(r->record, buf);
683 else if (!oid_oidcmp(oid, yaz_oid_recsyn_grs_1))
686 r->record = (char*) dummy_grs_record(r->number, r->stream);
689 r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
690 r->surrogate_flag = 1;
694 else if (!oid_oidcmp(oid, yaz_oid_recsyn_postscript))
700 sprintf(fname, "part.%d.ps", r->number);
701 f = fopen(fname, "rb");
704 r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
705 r->surrogate_flag = 1;
708 fseek(f, 0L, SEEK_END);
710 if (size <= 0 || size >= 5000000)
712 r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
713 r->surrogate_flag = 1;
715 fseek(f, 0L, SEEK_SET);
716 r->record = (char*) odr_malloc(r->stream, size);
718 if (fread(r->record, size, 1, f) != 1)
720 r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
721 r->surrogate_flag = 1;
725 else if (!oid_oidcmp(oid, yaz_oid_recsyn_xml))
727 if ((cp = dummy_xml_record(r->number, r->stream)))
734 r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
735 r->surrogate_flag = 1;
741 char buf[OID_STR_MAX];
742 r->errcode = YAZ_BIB1_RECORD_SYNTAX_UNSUPP;
743 r->errstring = odr_strdup(r->stream, oid_oid_to_dotstring(oid, buf));
751 * silly dummy-scan what reads words from a file.
753 int ztest_scan(void *handle, bend_scan_rr *q)
756 static struct scan_entry list[200];
757 static char entries[200][80];
761 int term_position_req = q->term_position;
762 int num_entries_req = q->num_entries;
764 /* Throw Database unavailable if other than Default or Slow */
765 if (!yaz_matchstr(q->basenames[0], "Default"))
766 ; /* Default is OK in our test */
767 else if (check_slow(q->basenames[0], 0 /* no assoc for scan */))
771 q->errcode = YAZ_BIB1_DATABASE_UNAVAILABLE;
772 q->errstring = q->basenames[0];
779 q->status = BEND_SCAN_SUCCESS;
780 if (!f && !(f = fopen("dummy-words", "r")))
782 perror("dummy-words");
785 if (q->num_entries > 200)
787 q->errcode = YAZ_BIB1_RESOURCES_EXHAUSTED_NO_RESULTS_AVAILABLE;
793 if (q->term->term->which != Z_Term_general)
795 q->errcode = YAZ_BIB1_TERM_TYPE_UNSUPP;
798 if (*q->step_size != 0)
800 q->errcode = YAZ_BIB1_ONLY_ZERO_STEP_SIZE_SUPPORTED_FOR_SCAN;
803 len = q->term->term->u.general->len;
804 if (len >= (int ) sizeof(term))
805 len = sizeof(term)-1;
806 memcpy(term, q->term->term->u.general->buf, len);
809 else if (q->scanClause)
811 strncpy(term, q->scanClause, sizeof(term)-1);
812 term[sizeof(term)-1] = '\0';
817 for (p = term; *p; p++)
818 if (islower(*(unsigned char *) p))
821 fseek(f, 0, SEEK_SET);
824 for (i = 0, pos = 0; fscanf(f, " %79[^:]:%d", entries[pos], &hits[pos]) == 2;
825 i++, pos < 199 ? pos++ : (pos = 0))
827 if (!q->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */
829 if ((q->term_position = term_position_req) > i + 1)
831 q->term_position = i + 1;
832 q->status = BEND_SCAN_PARTIAL;
834 for (; q->num_entries < q->term_position; q->num_entries++)
838 po = pos - q->term_position + q->num_entries+1; /* find pos */
842 if (!strcmp(term, "SD") && q->num_entries == 2)
844 list[q->num_entries].term = entries[pos];
845 list[q->num_entries].occurrences = -1;
846 list[q->num_entries].errcode =
847 YAZ_BIB1_SCAN_UNSUPP_VALUE_OF_POSITION_IN_RESPONSE;
848 list[q->num_entries].errstring = "SD for Scan Term";
852 list[q->num_entries].term = entries[po];
853 list[q->num_entries].occurrences = hits[po];
857 else if (q->num_entries)
859 list[q->num_entries].term = entries[pos];
860 list[q->num_entries].occurrences = hits[pos];
863 if (q->num_entries >= num_entries_req)
867 q->status = BEND_SCAN_PARTIAL;
871 int ztest_explain(void *handle, bend_explain_rr *rr)
873 if (rr->database && !strcmp(rr->database, "Default"))
875 rr->explain_buf = "<explain>\n"
877 "\t\t<host>localhost</host>\n"
878 "\t\t<port>210</port>\n"
885 int ztest_update(void *handle, bend_update_rr *rr)
887 rr->operation_status = "success";
891 bend_initresult *bend_init(bend_initrequest *q)
893 bend_initresult *r = (bend_initresult *)
894 odr_malloc(q->stream, sizeof(*r));
895 struct session_handle *sh = xmalloc(sizeof(*sh));
901 log_level=yaz_log_module_level("ztest");
907 r->handle = sh; /* tell GFS about our handle */
908 q->bend_sort = ztest_sort; /* register sort handler */
909 q->bend_search = ztest_search; /* register search handler */
910 q->bend_present = ztest_present; /* register present handle */
911 q->bend_esrequest = ztest_esrequest;
912 q->bend_delete = ztest_delete;
913 q->bend_fetch = ztest_fetch;
914 q->bend_scan = ztest_scan;
916 q->bend_explain = ztest_explain;
918 q->bend_srw_scan = ztest_scan;
919 q->bend_srw_update = ztest_update;
921 q->query_charset = "ISO-8859-1";
922 q->records_in_same_charset = 0;
927 void bend_close(void *handle)
929 struct session_handle *sh = (struct session_handle*) handle;
931 xfree(sh); /* release our session */
935 int main(int argc, char **argv)
937 return statserv_main(argc, argv, bend_init, bend_close);
942 * c-file-style: "Stroustrup"
943 * indent-tabs-mode: nil
945 * vim: shiftwidth=4 tabstop=8 expandtab