Added several type casts due to no portable way of doing printf of
[yaz-moved-to-github.git] / ztest / ztest.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: ztest.c,v 1.79 2006-04-21 10:28:09 adam Exp $
6  */
7
8 /*
9  * Demonstration of simple server
10  */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <ctype.h>
15 #if HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18
19 #include <yaz/yaz-util.h>
20 #include <yaz/backend.h>
21 #include <yaz/ill.h>
22
23 static int log_level=0;
24 static int log_level_set=0;
25
26 Z_GenericRecord *dummy_grs_record (int num, ODR o);
27 char *dummy_marc_record (int num, ODR odr);
28 char *dummy_xml_record (int num, ODR odr);
29
30 int ztest_search(void *handle, bend_search_rr *rr);
31 int ztest_sort(void *handle, bend_sort_rr *rr);
32 int ztest_present(void *handle, bend_present_rr *rr);
33 int ztest_esrequest(void *handle, bend_esrequest_rr *rr);
34 int ztest_delete(void *handle, bend_delete_rr *rr);
35
36 int ztest_search(void *handle, bend_search_rr *rr)
37 {
38     if (rr->num_bases != 1)
39     {
40         rr->errcode = 23;
41         return 0;
42     }
43 #if NMEM_DEBUG
44     /* if database is stop, stop this process.. For debugging only. */
45     if (!yaz_matchstr (rr->basenames[0], "stop"))
46     {
47         nmem_print_list_l(YLOG_LOG);
48         exit(0);
49     }
50 #endif
51     /* Throw Database unavailable if other than Default or Slow */
52     if (!yaz_matchstr (rr->basenames[0], "Default"))
53         ;  /* Default is OK in our test */
54     else if(!yaz_matchstr (rr->basenames[0], "Slow"))
55     {
56 #if HAVE_UNISTD_H
57         sleep(3);
58 #endif
59         ;
60     }
61     else
62     {
63         rr->errcode = 109;
64         rr->errstring = rr->basenames[0];
65         return 0;
66     }
67     rr->hits = rand() % 24;
68     return 0;
69 }
70
71
72 /* this huge function handles extended services */
73 int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
74 {
75     /* user-defined handle - created in bend_init */
76     int *counter = (int*) handle;  
77
78     yaz_log(log_level, "ESRequest no %d", *counter);
79
80     (*counter)++;
81
82     if (rr->esr->packageName)
83         yaz_log(log_level, "packagename: %s", rr->esr->packageName);
84     yaz_log(log_level, "Waitaction: %d", *rr->esr->waitAction);
85
86
87     yaz_log(log_level, "function: %d", *rr->esr->function);
88
89     if (!rr->esr->taskSpecificParameters)
90     {
91         yaz_log (log_level, "No task specific parameters");
92     }
93     else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder)
94     {
95         Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder;
96         yaz_log (log_level, "Received ItemOrder");
97         if (it->which == Z_IOItemOrder_esRequest)
98         {
99             Z_IORequest *ir = it->u.esRequest;
100             Z_IOOriginPartToKeep *k = ir->toKeep;
101             Z_IOOriginPartNotToKeep *n = ir->notToKeep;
102             
103             if (k && k->contact)
104             {
105                 if (k->contact->name)
106                     yaz_log(log_level, "contact name %s", k->contact->name);
107                 if (k->contact->phone)
108                     yaz_log(log_level, "contact phone %s", k->contact->phone);
109                 if (k->contact->email)
110                     yaz_log(log_level, "contact email %s", k->contact->email);
111             }
112             if (k->addlBilling)
113             {
114                 yaz_log(log_level, "Billing info (not shown)");
115             }
116             
117             if (n->resultSetItem)
118             {
119                 yaz_log(log_level, "resultsetItem");
120                 yaz_log(log_level, "setId: %s", n->resultSetItem->resultSetId);
121                 yaz_log(log_level, "item: %d", *n->resultSetItem->item);
122             }
123             if (n->itemRequest)
124             {
125                 Z_External *r = (Z_External*) n->itemRequest;
126                 ILL_ItemRequest *item_req = 0;
127                 ILL_APDU *ill_apdu = 0;
128                 if (r->direct_reference)
129                 {
130                     oident *ent = oid_getentbyoid(r->direct_reference);
131                     if (ent)
132                         yaz_log(log_level, "OID %s", ent->desc);
133                     if (ent && ent->value == VAL_TEXT_XML)
134                     {
135                         yaz_log (log_level, "ILL XML request");
136                         if (r->which == Z_External_octet)
137                             yaz_log (log_level, "%.*s", r->u.octet_aligned->len,
138                                      r->u.octet_aligned->buf); 
139                     }
140                     if (ent && ent->value == VAL_ISO_ILL_1)
141                     {
142                         yaz_log (log_level, "Decode ItemRequest begin");
143                         if (r->which == ODR_EXTERNAL_single)
144                         {
145                             odr_setbuf(rr->decode,
146                                        (char *) r->u.single_ASN1_type->buf,
147                                        r->u.single_ASN1_type->len, 0);
148                             
149                             if (!ill_ItemRequest (rr->decode, &item_req, 0, 0))
150                             {
151                                 yaz_log (log_level,
152                                     "Couldn't decode ItemRequest %s near %ld",
153                                        odr_errmsg(odr_geterror(rr->decode)),
154                                        (long) odr_offset(rr->decode));
155                             }
156                             else
157                                 yaz_log(log_level, "Decode ItemRequest OK");
158                             if (rr->print)
159                             {
160                                 ill_ItemRequest (rr->print, &item_req, 0,
161                                     "ItemRequest");
162                                 odr_reset (rr->print);
163                             }
164                         }
165                         if (!item_req && r->which == ODR_EXTERNAL_single)
166                         {
167                             yaz_log (log_level, "Decode ILL APDU begin");
168                             odr_setbuf(rr->decode,
169                                        (char*) r->u.single_ASN1_type->buf,
170                                        r->u.single_ASN1_type->len, 0);
171                             
172                             if (!ill_APDU (rr->decode, &ill_apdu, 0, 0))
173                             {
174                                 yaz_log (log_level,
175                                     "Couldn't decode ILL APDU %s near %ld",
176                                        odr_errmsg(odr_geterror(rr->decode)),
177                                        (long) odr_offset(rr->decode));
178                                 yaz_log(log_level, "PDU dump:");
179                                 odr_dumpBER(yaz_log_file(),
180                                      (char *) r->u.single_ASN1_type->buf,
181                                      r->u.single_ASN1_type->len);
182                             }
183                             else
184                                 yaz_log(log_level, "Decode ILL APDU OK");
185                             if (rr->print)
186                             {
187                                 ill_APDU (rr->print, &ill_apdu, 0,
188                                     "ILL APDU");
189                                 odr_reset (rr->print);
190                             }
191                         }
192                     }
193                 }
194                 if (item_req)
195                 {
196                     yaz_log (log_level, "ILL protocol version = %d",
197                              *item_req->protocol_version_num);
198                 }
199             }
200             if (k)
201             {
202
203                 Z_External *ext = (Z_External *)
204                     odr_malloc (rr->stream, sizeof(*ext));
205                 Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *)
206                     odr_malloc (rr->stream, sizeof(*keep));
207                 Z_IOTargetPart *targetPart = (Z_IOTargetPart *)
208                     odr_malloc (rr->stream, sizeof(*targetPart));
209
210                 rr->taskPackage = (Z_TaskPackage *)
211                     odr_malloc (rr->stream, sizeof(*rr->taskPackage));
212                 rr->taskPackage->packageType =
213                     odr_oiddup (rr->stream, rr->esr->packageType);
214                 rr->taskPackage->packageName = 0;
215                 rr->taskPackage->userId = 0;
216                 rr->taskPackage->retentionTime = 0;
217                 rr->taskPackage->permissions = 0;
218                 rr->taskPackage->description = 0;
219                 rr->taskPackage->targetReference = (Odr_oct *)
220                     odr_malloc (rr->stream, sizeof(Odr_oct));
221                 rr->taskPackage->targetReference->buf =
222                     (unsigned char *) odr_strdup (rr->stream, "911");
223                 rr->taskPackage->targetReference->len =
224                     rr->taskPackage->targetReference->size =
225                     strlen((char *) (rr->taskPackage->targetReference->buf));
226                 rr->taskPackage->creationDateTime = 0;
227                 rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0);
228                 rr->taskPackage->packageDiagnostics = 0;
229                 rr->taskPackage->taskSpecificParameters = ext;
230
231                 ext->direct_reference =
232                     odr_oiddup (rr->stream, rr->esr->packageType);
233                 ext->indirect_reference = 0;
234                 ext->descriptor = 0;
235                 ext->which = Z_External_itemOrder;
236                 ext->u.itemOrder = (Z_ItemOrder *)
237                     odr_malloc (rr->stream, sizeof(*ext->u.update));
238                 ext->u.itemOrder->which = Z_IOItemOrder_taskPackage;
239                 ext->u.itemOrder->u.taskPackage =  (Z_IOTaskPackage *)
240                     odr_malloc (rr->stream, sizeof(Z_IOTaskPackage));
241                 ext->u.itemOrder->u.taskPackage->originPart = k;
242                 ext->u.itemOrder->u.taskPackage->targetPart = targetPart;
243
244                 targetPart->itemRequest = 0;
245                 targetPart->statusOrErrorReport = 0;
246                 targetPart->auxiliaryStatus = 0;
247             }
248         }
249     }
250     else if (rr->esr->taskSpecificParameters->which == Z_External_update)
251     {
252         Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
253         yaz_log (log_level, "Received DB Update");
254         if (up->which == Z_IUUpdate_esRequest)
255         {
256             Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
257             Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
258             Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
259             
260             yaz_log (log_level, "action");
261             if (toKeep->action)
262             {
263                 switch (*toKeep->action)
264                 {
265                 case Z_IUOriginPartToKeep_recordInsert:
266                     yaz_log (log_level, " recordInsert");
267                     break;
268                 case Z_IUOriginPartToKeep_recordReplace:
269                     yaz_log (log_level, " recordReplace");
270                     break;
271                 case Z_IUOriginPartToKeep_recordDelete:
272                     yaz_log (log_level, " recordDelete");
273                     break;
274                 case Z_IUOriginPartToKeep_elementUpdate:
275                     yaz_log (log_level, " elementUpdate");
276                     break;
277                 case Z_IUOriginPartToKeep_specialUpdate:
278                     yaz_log (log_level, " specialUpdate");
279                     break;
280                 default:
281                     yaz_log (log_level, " unknown (%d)", *toKeep->action);
282                 }
283             }
284             if (toKeep->databaseName)
285             {
286                 yaz_log (log_level, "database: %s", toKeep->databaseName);
287                 if (!strcmp(toKeep->databaseName, "fault"))
288                 {
289                     rr->errcode = 109;
290                     rr->errstring = toKeep->databaseName;
291                 }
292                 if (!strcmp(toKeep->databaseName, "accept"))
293                     rr->errcode = -1;
294             }
295             if (toKeep)
296             {
297                 Z_External *ext = (Z_External *)
298                     odr_malloc (rr->stream, sizeof(*ext));
299                 Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *)
300                     odr_malloc (rr->stream, sizeof(*keep));
301                 Z_IUTargetPart *targetPart = (Z_IUTargetPart *)
302                     odr_malloc (rr->stream, sizeof(*targetPart));
303
304                 rr->taskPackage = (Z_TaskPackage *)
305                     odr_malloc (rr->stream, sizeof(*rr->taskPackage));
306                 rr->taskPackage->packageType =
307                     odr_oiddup (rr->stream, rr->esr->packageType);
308                 rr->taskPackage->packageName = 0;
309                 rr->taskPackage->userId = 0;
310                 rr->taskPackage->retentionTime = 0;
311                 rr->taskPackage->permissions = 0;
312                 rr->taskPackage->description = 0;
313                 rr->taskPackage->targetReference = (Odr_oct *)
314                     odr_malloc (rr->stream, sizeof(Odr_oct));
315                 rr->taskPackage->targetReference->buf =
316                     (unsigned char *) odr_strdup (rr->stream, "123");
317                 rr->taskPackage->targetReference->len =
318                     rr->taskPackage->targetReference->size =
319                     strlen((char *) (rr->taskPackage->targetReference->buf));
320                 rr->taskPackage->creationDateTime = 0;
321                 rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0);
322                 rr->taskPackage->packageDiagnostics = 0;
323                 rr->taskPackage->taskSpecificParameters = ext;
324
325                 ext->direct_reference =
326                     odr_oiddup (rr->stream, rr->esr->packageType);
327                 ext->indirect_reference = 0;
328                 ext->descriptor = 0;
329                 ext->which = Z_External_update;
330                 ext->u.update = (Z_IUUpdate *)
331                     odr_malloc (rr->stream, sizeof(*ext->u.update));
332                 ext->u.update->which = Z_IUUpdate_taskPackage;
333                 ext->u.update->u.taskPackage =  (Z_IUUpdateTaskPackage *)
334                     odr_malloc (rr->stream, sizeof(Z_IUUpdateTaskPackage));
335                 ext->u.update->u.taskPackage->originPart = keep;
336                 ext->u.update->u.taskPackage->targetPart = targetPart;
337
338                 keep->action = (int *) odr_malloc (rr->stream, sizeof(int));
339                 *keep->action = *toKeep->action;
340                 keep->databaseName =
341                     odr_strdup (rr->stream, toKeep->databaseName);
342                 keep->schema = 0;
343                 keep->elementSetName = 0;
344                 keep->actionQualifier = 0;
345
346                 targetPart->updateStatus = odr_intdup (rr->stream, 1);
347                 targetPart->num_globalDiagnostics = 0;
348                 targetPart->globalDiagnostics = (Z_DiagRec **) odr_nullval();
349                 targetPart->num_taskPackageRecords = 1;
350                 targetPart->taskPackageRecords = 
351                     (Z_IUTaskPackageRecordStructure **)
352                     odr_malloc (rr->stream,
353                                 sizeof(Z_IUTaskPackageRecordStructure *));
354                 targetPart->taskPackageRecords[0] =
355                     (Z_IUTaskPackageRecordStructure *)
356                     odr_malloc (rr->stream,
357                                 sizeof(Z_IUTaskPackageRecordStructure));
358                 
359                 targetPart->taskPackageRecords[0]->which =
360                     Z_IUTaskPackageRecordStructure_record;
361                 targetPart->taskPackageRecords[0]->u.record = 
362                     z_ext_record (rr->stream, VAL_SUTRS, "test", 4);
363                 targetPart->taskPackageRecords[0]->correlationInfo = 0; 
364                 targetPart->taskPackageRecords[0]->recordStatus =
365                     odr_intdup (rr->stream,
366                                 Z_IUTaskPackageRecordStructure_success);  
367                 targetPart->taskPackageRecords[0]->num_supplementalDiagnostics
368                     = 0;
369
370                 targetPart->taskPackageRecords[0]->supplementalDiagnostics = 0;
371             }
372             if (notToKeep)
373             {
374                 int i;
375                 for (i = 0; i < notToKeep->num; i++)
376                 {
377                     Z_External *rec = notToKeep->elements[i]->record;
378
379                     if (rec->direct_reference)
380                     {
381                         struct oident *oident;
382                         oident = oid_getentbyoid(rec->direct_reference);
383                         if (oident)
384                             yaz_log (log_level, "record %d type %s", i,
385                                      oident->desc);
386                     }
387                     switch (rec->which)
388                     {
389                     case Z_External_sutrs:
390                         if (rec->u.octet_aligned->len > 170)
391                             yaz_log (log_level, "%d bytes:\n%.168s ...",
392                                      rec->u.sutrs->len,
393                                      rec->u.sutrs->buf);
394                         else
395                             yaz_log (log_level, "%d bytes:\n%s",
396                                      rec->u.sutrs->len,
397                                      rec->u.sutrs->buf);
398                         break;
399                     case Z_External_octet        :
400                         if (rec->u.octet_aligned->len > 170)
401                             yaz_log (log_level, "%d bytes:\n%.168s ...",
402                                      rec->u.octet_aligned->len,
403                                      rec->u.octet_aligned->buf);
404                         else
405                             yaz_log (log_level, "%d bytes\n%s",
406                                      rec->u.octet_aligned->len,
407                                      rec->u.octet_aligned->buf);
408                     }
409                 }
410             }
411         }
412     }
413     return 0;
414 }
415
416 /* result set delete */
417 int ztest_delete (void *handle, bend_delete_rr *rr)
418 {
419     if (rr->num_setnames == 1 && !strcmp (rr->setnames[0], "1"))
420         rr->delete_status = Z_DeleteStatus_success;
421     else
422         rr->delete_status = Z_DeleteStatus_resultSetDidNotExist;
423     return 0;
424 }
425
426 /* Our sort handler really doesn't sort... */
427 int ztest_sort (void *handle, bend_sort_rr *rr)
428 {
429     rr->errcode = 0;
430     rr->sort_status = Z_SortResponse_success;
431     return 0;
432 }
433
434
435 /* present request handler */
436 int ztest_present (void *handle, bend_present_rr *rr)
437 {
438     return 0;
439 }
440
441 /* retrieval of a single record (present, and piggy back search) */
442 int ztest_fetch(void *handle, bend_fetch_rr *r)
443 {
444     char *cp;
445
446     r->last_in_set = 0;
447     r->basename = "Default";
448     r->output_format = r->request_format;  
449     if (r->request_format == VAL_SUTRS)
450     {
451         /* this section returns a small record */
452         char buf[100];
453         
454         sprintf(buf, "This is dummy SUTRS record number %d\n", r->number);
455
456         r->len = strlen(buf);
457         r->record = (char *) odr_malloc (r->stream, r->len+1);
458         strcpy(r->record, buf);
459     }
460     else if (r->request_format == VAL_GRS1)
461     {
462         r->len = -1;
463         r->record = (char*) dummy_grs_record(r->number, r->stream);
464         if (!r->record)
465         {
466             r->errcode = 13;
467             return 0;
468         }
469     }
470     else if (r->request_format == VAL_POSTSCRIPT)
471     {
472         char fname[20];
473         FILE *f;
474         long size;
475
476         sprintf (fname, "part.%d.ps", r->number);
477         f = fopen(fname, "rb");
478         if (!f)
479         {
480             r->errcode = 13;
481             return 0;
482         }
483         fseek (f, 0L, SEEK_END);
484         size = ftell (f);
485         if (size <= 0 || size >= 5000000)
486         {
487             r->errcode = 14;
488             return 0;
489         }
490         fseek (f, 0L, SEEK_SET);
491         r->record = (char*) odr_malloc (r->stream, size);
492         r->len = size;
493         r->output_format = VAL_POSTSCRIPT;
494         fread (r->record, size, 1, f);
495         fclose (f);
496     }
497     else if (r->request_format == VAL_TEXT_XML)
498     {
499         if ((cp = dummy_xml_record (r->number, r->stream)))
500         {
501             r->len = strlen(cp);
502             r->record = cp;
503             r->output_format = VAL_TEXT_XML;
504         }
505         else 
506         {
507             r->errcode = 14;
508             r->surrogate_flag = 1;
509             return 0;
510         }
511     }
512     else if ((cp = dummy_marc_record(r->number, r->stream)))
513     {
514         r->len = strlen(cp);
515         r->record = cp;
516         r->output_format = VAL_USMARC;
517     }
518     else
519     {
520         r->errcode = 13;
521         return 0;
522     }
523     r->errcode = 0;
524     return 0;
525 }
526
527 /*
528  * silly dummy-scan what reads words from a file.
529  */
530 int ztest_scan(void *handle, bend_scan_rr *q)
531 {
532     static FILE *f = 0;
533     static struct scan_entry list[200];
534     static char entries[200][80];
535     int hits[200];
536     char term[80], *p;
537     int i, pos;
538     int term_position_req = q->term_position;
539     int num_entries_req = q->num_entries;
540
541     /* Throw Database unavailable if other than Default or Slow */
542     if (!yaz_matchstr (q->basenames[0], "Default"))
543         ;  /* Default is OK in our test */
544     else if(!yaz_matchstr (q->basenames[0], "Slow"))
545     {
546 #if HAVE_UNISTD_H
547         sleep(3);
548 #endif
549         ;
550     }
551     else
552     {
553         q->errcode = 109;
554         q->errstring = q->basenames[0];
555         return 0;
556     }
557
558     q->errcode = 0;
559     q->errstring = 0;
560     q->entries = list;
561     q->status = BEND_SCAN_SUCCESS;
562     if (!f && !(f = fopen("dummy-words", "r")))
563     {
564         perror("dummy-words");
565         exit(1);
566     }
567     if (q->num_entries > 200)
568     {
569         q->errcode = 31;
570         return 0;
571     }
572     if (q->term)
573     {
574         int len;
575         if (q->term->term->which != Z_Term_general)
576         {
577             q->errcode = 229; /* unsupported term type */
578             return 0;
579         }
580         if (*q->step_size != 0)
581         {
582             q->errcode = 205; /*Only zero step size supported for Scan */
583             return 0;
584         }
585         len = q->term->term->u.general->len;
586         if (len >= sizeof(term))
587             len = sizeof(term)-1;
588         memcpy(term, q->term->term->u.general->buf, len);
589         term[len] = '\0';
590     }
591     else if (q->scanClause)
592     {
593         strncpy(term, q->scanClause, sizeof(term)-1);
594         term[sizeof(term)-1] = '\0';
595     }
596     else
597         strcpy(term, "0");
598
599     for (p = term; *p; p++)
600         if (islower(*(unsigned char *) p))
601             *p = toupper(*p);
602
603     fseek(f, 0, SEEK_SET);
604     q->num_entries = 0;
605
606     for (i = 0, pos = 0; fscanf(f, " %79[^:]:%d", entries[pos], &hits[pos]) == 2;
607         i++, pos < 199 ? pos++ : (pos = 0))
608     {
609         if (!q->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */
610         {
611             if ((q->term_position = term_position_req) > i + 1)
612             {
613                 q->term_position = i + 1;
614                 q->status = BEND_SCAN_PARTIAL;
615             }
616             for (; q->num_entries < q->term_position; q->num_entries++)
617             {
618                 int po;
619
620                 po = pos - q->term_position + q->num_entries+1; /* find pos */
621                 if (po < 0)
622                     po += 200;
623
624                 if (!strcmp (term, "SD") && q->num_entries == 2)
625                 {
626                     list[q->num_entries].term = entries[pos];
627                     list[q->num_entries].occurrences = -1;
628                     list[q->num_entries].errcode = 233;
629                     list[q->num_entries].errstring = "SD for Scan Term";
630                 }
631                 else
632                 {
633                     list[q->num_entries].term = entries[po];
634                     list[q->num_entries].occurrences = hits[po];
635                 }
636             }
637         }
638         else if (q->num_entries)
639         {
640             list[q->num_entries].term = entries[pos];
641             list[q->num_entries].occurrences = hits[pos];
642             q->num_entries++;
643         }
644         if (q->num_entries >= num_entries_req)
645             break;
646     }
647     if (feof(f))
648         q->status = BEND_SCAN_PARTIAL;
649     return 0;
650 }
651
652 int ztest_explain(void *handle, bend_explain_rr *rr)
653 {
654     if (rr->database && !strcmp(rr->database, "Default"))
655     {
656         rr->explain_buf = "<explain>\n"
657             "\t<serverInfo>\n"
658             "\t\t<host>localhost</host>\n"
659             "\t\t<port>210</port>\n"
660             "\t</serverInfo>\n"
661             "</explain>\n";
662     }
663     return 0;
664 }
665
666 bend_initresult *bend_init(bend_initrequest *q)
667 {
668     bend_initresult *r = (bend_initresult *)
669         odr_malloc (q->stream, sizeof(*r));
670     int *counter = (int *) xmalloc (sizeof(int));
671
672     if (!log_level_set)
673     {
674         log_level=yaz_log_module_level("ztest");
675         log_level_set=1;
676     }
677
678     *counter = 0;
679     r->errcode = 0;
680     r->errstring = 0;
681     r->handle = counter;         /* user handle, in this case a simple int */
682     q->bend_sort = ztest_sort;              /* register sort handler */
683     q->bend_search = ztest_search;          /* register search handler */
684     q->bend_present = ztest_present;        /* register present handle */
685     q->bend_esrequest = ztest_esrequest;
686     q->bend_delete = ztest_delete;
687     q->bend_fetch = ztest_fetch;
688     q->bend_scan = ztest_scan;
689 #if 0
690     q->bend_explain = ztest_explain;
691 #endif
692     q->bend_srw_scan = ztest_scan;
693
694     return r;
695 }
696
697 void bend_close(void *handle)
698 {
699     xfree (handle);              /* release our user-defined handle */
700     return;
701 }
702
703 int main(int argc, char **argv)
704 {
705     return statserv_main(argc, argv, bend_init, bend_close);
706 }
707 /*
708  * Local variables:
709  * c-basic-offset: 4
710  * indent-tabs-mode: nil
711  * End:
712  * vim: shiftwidth=4 tabstop=8 expandtab
713  */
714