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