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