Simplified the character set negotiation code a bit.
[idzebra-moved-to-github.git] / index / zserver.c
1 /* $Id: zserver.c,v 1.102 2003-01-13 15:06:23 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23
24
25 #include <stdio.h>
26 #include <assert.h>
27 #include <fcntl.h>
28 #ifdef WIN32
29 #include <io.h>
30 #include <process.h>
31 #else
32 #include <unistd.h>
33 #endif
34
35 #include <yaz/log.h>
36 #include <yaz/ill.h>
37
38 #include "zserver.h"
39
40 static int bend_sort (void *handle, bend_sort_rr *rr);
41 static int bend_delete (void *handle, bend_delete_rr *rr);
42 static int bend_esrequest (void *handle, bend_esrequest_rr *rr);
43 static int bend_segment (void *handle, bend_segment_rr *rr);
44 static int bend_search (void *handle, bend_search_rr *r);
45 static int bend_fetch (void *handle, bend_fetch_rr *r);
46 static int bend_scan (void *handle, bend_scan_rr *r);
47
48 bend_initresult *bend_init (bend_initrequest *q)
49 {
50     bend_initresult *r = (bend_initresult *)
51         odr_malloc (q->stream, sizeof(*r));
52     ZebraHandle zh;
53     struct statserv_options_block *sob;
54     char *user = NULL;
55     char *passwd = NULL;
56
57     r->errcode = 0;
58     r->errstring = 0;
59     q->bend_sort = bend_sort;
60     q->bend_delete = bend_delete;
61     q->bend_esrequest = bend_esrequest;
62     q->bend_segment = bend_segment;
63     q->bend_search = bend_search;
64     q->bend_fetch = bend_fetch;
65     q->bend_scan = bend_scan;
66
67     q->implementation_name = "Zebra Information Server";
68     q->implementation_version = "Zebra " ZEBRAVER;
69
70     yaz_log (LOG_DEBUG, "bend_init");
71
72     sob = statserv_getcontrol ();
73     if (!(zh = zebra_open (sob->handle)))
74     {
75         yaz_log (LOG_WARN, "Failed to read config `%s'", sob->configname);
76         r->errcode = 1;
77         return r;
78     }
79     if (q->auth)
80     {
81         if (q->auth->which == Z_IdAuthentication_open)
82         {
83             char *openpass = xstrdup (q->auth->u.open);
84             char *cp = strchr (openpass, '/');
85             if (cp)
86             {
87                 *cp = '\0';
88                 user = nmem_strdup (odr_getmem (q->stream), openpass);
89                 passwd = nmem_strdup (odr_getmem (q->stream), cp+1);
90             }
91             xfree (openpass);
92         }
93     }
94     if (zebra_auth (zh, user, passwd))
95     {
96         r->errcode = 222;
97         r->errstring = user;
98         zebra_close (zh);
99         return r;
100     }
101     r->handle = zh;
102     if (q->charneg_request) /* characater set and langauge negotiation? */
103     {
104         char **charsets = 0;
105         int num_charsets;
106         char **langs = 0;
107         int num_langs = 0;
108         int selected = 0;
109         int i;
110         NMEM nmem = nmem_create();
111
112         yaz_log (LOG_LOG, "character set and language negotiation");
113
114         yaz_get_proposal_charneg (nmem, q->charneg_request,
115                                   &charsets, &num_charsets,
116                                   &langs, &num_langs, &selected);
117         
118         for (i = 0; i < num_charsets; i++)
119         {
120             const char *right_name = "";
121             /*
122              * FIXME! It is like rudiment :-))
123              * We have to support this short names of character sets,
124              * because a lot servers in Russia to use own in during
125              * character set and language negotiation still.
126              */
127             
128             if (!yaz_matchstr(charsets[i], "win")) {
129                 right_name = "WINDOWS-1251";
130             } else if (!yaz_matchstr(charsets[i], "koi")) {
131                 right_name = "KOI8-R";
132             } else if (!yaz_matchstr(charsets[i], "iso")) {
133                 right_name = "ISO-8859-5";
134             } else if (!yaz_matchstr(charsets[i], "dos")) {
135                 right_name = "CP866";
136             } else if (!yaz_matchstr(charsets[i], "uni")) {
137                 right_name = "UTF-8";
138             } else {
139                 right_name = charsets[i];
140             }
141             if (odr_set_charset (q->decode, "UTF-8", right_name) == 0)
142             {
143                 yaz_log (LOG_LOG, "charset %d %s (proper name %s): OK", i,
144                          charsets[i], right_name);
145                 odr_set_charset (q->stream, right_name, "UTF-8");
146                 if (selected)
147                     zebra_record_encoding (zh, right_name);
148                 q->charneg_response =
149                     yaz_set_response_charneg (q->stream, right_name,
150                                               0, selected);
151                 break;
152             } else {
153                 yaz_log (LOG_LOG, "charset %d %s (proper name %s): unsupported", i,
154                          charsets[i], right_name);
155             }
156         }
157         nmem_destroy(nmem);
158     }
159     return r;
160 }
161
162 static void search_terms (ZebraHandle zh, bend_search_rr *r)
163 {
164     int count;
165     int no_terms;
166     int i;
167     int type;
168     struct Z_External *ext;
169     Z_SearchInfoReport *sr;
170
171     /* get no of terms for result set */
172     no_terms = zebra_resultSetTerms (zh, r->setname, 0, 0, 0, 0, 0);
173     if (!no_terms)
174         return;
175
176     r->search_info = odr_malloc (r->stream, sizeof(*r->search_info));
177
178     r->search_info->num_elements = 1;
179     r->search_info->list =
180         odr_malloc (r->stream, sizeof(*r->search_info->list));
181     r->search_info->list[0] =
182         odr_malloc (r->stream, sizeof(**r->search_info->list));
183     r->search_info->list[0]->category = 0;
184     r->search_info->list[0]->which = Z_OtherInfo_externallyDefinedInfo;
185     ext = odr_malloc (r->stream, sizeof(*ext));
186     r->search_info->list[0]->information.externallyDefinedInfo = ext;
187     ext->direct_reference =
188         yaz_oidval_to_z3950oid (r->stream, CLASS_USERINFO, VAL_SEARCHRES1);
189     ext->indirect_reference = 0;
190     ext->descriptor = 0;
191     ext->which = Z_External_searchResult1;
192     sr = odr_malloc (r->stream, sizeof(Z_SearchInfoReport));
193     ext->u.searchResult1 = sr;
194     sr->num = no_terms;
195     sr->elements = odr_malloc (r->stream, sr->num *
196                                sizeof(*sr->elements));
197     for (i = 0; i<no_terms; i++)
198     {
199         Z_Term *term;
200         char outbuf[1024];
201         size_t len = sizeof(outbuf);
202         zebra_resultSetTerms (zh, r->setname, i,
203                               &count, &type, outbuf, &len);
204         
205         sr->elements[i] = odr_malloc (r->stream, sizeof(**sr->elements));
206         sr->elements[i]->subqueryId = 0;
207         sr->elements[i]->fullQuery = odr_malloc (r->stream, 
208                                                  sizeof(bool_t));
209         *sr->elements[i]->fullQuery = 0;
210         sr->elements[i]->subqueryExpression = 
211             odr_malloc (r->stream, sizeof(Z_QueryExpression));
212         sr->elements[i]->subqueryExpression->which = 
213             Z_QueryExpression_term;
214         sr->elements[i]->subqueryExpression->u.term =
215             odr_malloc (r->stream, sizeof(Z_QueryExpressionTerm));
216         term = odr_malloc (r->stream, sizeof(Z_Term));
217         sr->elements[i]->subqueryExpression->u.term->queryTerm = term;
218         switch (type)
219         {
220         case Z_Term_characterString:
221             yaz_log (LOG_DEBUG, "term as characterString");
222             term->which = Z_Term_characterString;
223             term->u.characterString = odr_strdup (r->stream, outbuf);
224             break;
225         case Z_Term_general:
226             yaz_log (LOG_DEBUG, "term as general");
227             term->which = Z_Term_general;
228             term->u.general = odr_malloc (r->stream, sizeof(*term->u.general));
229             term->u.general->size = term->u.general->len = len;
230             term->u.general->buf = odr_malloc (r->stream, len);
231             memcpy (term->u.general->buf, outbuf, len);
232             break;
233         default:
234             term->which = Z_Term_general;
235             term->u.null = odr_nullval();
236         }
237         sr->elements[i]->subqueryExpression->u.term->termComment = 0;
238         sr->elements[i]->subqueryInterpretation = 0;
239         sr->elements[i]->subqueryRecommendation = 0;
240         sr->elements[i]->subqueryCount = odr_intdup (r->stream, count);
241         sr->elements[i]->subqueryWeight = 0;
242         sr->elements[i]->resultsByDB = 0;
243     }
244 }
245
246 int bend_search (void *handle, bend_search_rr *r)
247 {
248     ZebraHandle zh = (ZebraHandle) handle;
249
250     r->hits = 0;
251     r->errcode = 0;
252     r->errstring = NULL;
253     
254     if (zebra_select_databases (zh, r->num_bases,
255                                 (const char **) r->basenames))
256     {
257         zebra_result (zh, &r->errcode, &r->errstring);
258         return 0;
259     }
260     yaz_log (LOG_LOG, "ResultSet '%s'", r->setname);
261     switch (r->query->which)
262     {
263     case Z_Query_type_1: case Z_Query_type_101:
264         zebra_search_rpn (zh, r->decode, r->stream, r->query->u.type_1,
265                           r->setname, &r->hits);
266         zebra_result (zh, &r->errcode, &r->errstring);
267         if (!r->errcode)
268             search_terms (zh, r);
269         break;
270     case Z_Query_type_2:
271         r->errcode = 107;
272         r->errstring = "type-2";
273         break;
274     default:
275         r->errcode = 107;
276     }
277     return 0;
278 }
279
280
281 int bend_fetch (void *handle, bend_fetch_rr *r)
282 {
283     ZebraHandle zh = (ZebraHandle) handle;
284     ZebraRetrievalRecord retrievalRecord;
285
286     retrievalRecord.position = r->number;
287     
288     r->last_in_set = 0;
289     zebra_records_retrieve (zh, r->stream, r->setname, r->comp,
290                             r->request_format, 1, &retrievalRecord);
291     zebra_result (zh, &r->errcode, &r->errstring);
292     /*  non Surrogate Diagnostic OR Surrogate Diagnostic */
293     if (r->errcode == 0 && retrievalRecord.errCode)
294     {
295         r->surrogate_flag = 1;
296         r->errcode = retrievalRecord.errCode;
297         r->errstring = retrievalRecord.errString;
298         r->basename = retrievalRecord.base;
299     }
300     else if (r->errcode == 0)        /* Database Record */
301     {
302         r->errcode = 0;
303         r->basename = retrievalRecord.base;
304         r->record = retrievalRecord.buf;
305         r->len = retrievalRecord.len;
306         r->output_format = retrievalRecord.format;
307     }
308     return 0;
309 }
310
311 static int bend_scan (void *handle, bend_scan_rr *r)
312 {
313     ZebraScanEntry *entries;
314     ZebraHandle zh = (ZebraHandle) handle;
315     int is_partial, i;
316
317     if (zebra_select_databases (zh, r->num_bases, 
318                                 (const char **) r->basenames))
319     {
320         zebra_result (zh, &r->errcode, &r->errstring);
321         return 0;
322     }
323     r->entries = (struct scan_entry *)
324         odr_malloc (r->stream, sizeof(*r->entries) * r->num_entries);
325     zebra_scan (zh, r->stream, r->term,
326                 r->attributeset,
327                 &r->term_position,
328                 &r->num_entries, &entries, &is_partial);
329     if (is_partial)
330         r->status = BEND_SCAN_PARTIAL;
331     else
332         r->status = BEND_SCAN_SUCCESS;
333     for (i = 0; i < r->num_entries; i++)
334     {
335         r->entries[i].term = entries[i].term;
336         r->entries[i].occurrences = entries[i].occurrences;
337     }
338     zebra_result (zh, &r->errcode, &r->errstring);
339     return 0;
340 }
341
342 void bend_close (void *handle)
343 {
344     zebra_close ((ZebraHandle) handle);
345     xmalloc_trav("bend_close");
346     nmem_print_list();
347 }
348
349 int bend_sort (void *handle, bend_sort_rr *rr)
350 {
351     ZebraHandle zh = (ZebraHandle) handle;
352
353     zebra_sort (zh, rr->stream,
354                 rr->num_input_setnames, (const char **) rr->input_setnames,
355                 rr->output_setname, rr->sort_sequence, &rr->sort_status);
356     zebra_result (zh, &rr->errcode, &rr->errstring);
357     return 0;
358 }
359
360 int bend_delete (void *handle, bend_delete_rr *rr)
361 {
362     ZebraHandle zh = (ZebraHandle) handle;
363
364     rr->delete_status = zebra_deleleResultSet(zh, rr->function,
365                                               rr->num_setnames, rr->setnames,
366                                               rr->statuses);
367     return 0;
368 }
369
370 static int es_admin_request (ZebraHandle zh, Z_AdminEsRequest *r)
371 {
372     switch (r->toKeep->which)
373     {
374     case Z_ESAdminOriginPartToKeep_reIndex:
375         yaz_log(LOG_LOG, "adm-reindex");
376         break;
377     case Z_ESAdminOriginPartToKeep_truncate:
378         yaz_log(LOG_LOG, "adm-truncate");
379         break;
380     case Z_ESAdminOriginPartToKeep_drop:
381         yaz_log(LOG_LOG, "adm-drop");
382         break;
383     case Z_ESAdminOriginPartToKeep_create:
384         yaz_log(LOG_LOG, "adm-create %s", r->toKeep->databaseName);
385         zebra_admin_create (zh, r->toKeep->databaseName);
386         break;
387     case Z_ESAdminOriginPartToKeep_import:
388         yaz_log(LOG_LOG, "adm-import");
389         zebra_admin_import_begin (zh, r->toKeep->databaseName,
390                         r->toKeep->u.import->recordType);
391         break;
392     case Z_ESAdminOriginPartToKeep_refresh:
393         yaz_log(LOG_LOG, "adm-refresh");
394         break;
395     case Z_ESAdminOriginPartToKeep_commit:
396         yaz_log(LOG_LOG, "adm-commit");
397         break;
398     case Z_ESAdminOriginPartToKeep_shutdown:
399         yaz_log(LOG_LOG, "shutdown");
400         zebra_admin_shutdown(zh);
401         break;
402     case Z_ESAdminOriginPartToKeep_start:
403         yaz_log(LOG_LOG, "start");
404         zebra_admin_start(zh);
405         break;
406     default:
407         yaz_log(LOG_LOG, "unknown admin");
408     }
409     if (r->toKeep->databaseName)
410     {
411         yaz_log(LOG_LOG, "database %s", r->toKeep->databaseName);
412     }
413     return 0;
414 }
415
416 static int es_admin (ZebraHandle zh, Z_Admin *r)
417 {
418     switch (r->which)
419     {
420     case Z_Admin_esRequest:
421         es_admin_request (zh, r->u.esRequest);
422         break;
423     case Z_Admin_taskPackage:
424         yaz_log (LOG_LOG, "adm taskpackage (unhandled)");
425         break;
426     default:
427         break;
428     }
429
430     return 0;
431 }
432
433 int bend_segment (void *handle, bend_segment_rr *rr)
434 {
435     ZebraHandle zh = (ZebraHandle) handle;
436     Z_Segment *segment = rr->segment;
437
438     if (segment->num_segmentRecords)
439         zebra_admin_import_segment (zh, rr->segment);
440     else
441         zebra_admin_import_end (zh);
442     return 0;
443 }
444
445 int bend_esrequest (void *handle, bend_esrequest_rr *rr)
446 {
447     ZebraHandle zh = (ZebraHandle) handle;
448     
449     yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
450     if (rr->esr->packageName)
451         yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);
452     yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
453
454     if (!rr->esr->taskSpecificParameters)
455     {
456         yaz_log (LOG_WARN, "No task specific parameters");
457     }
458     else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin)
459     {
460         es_admin (zh, rr->esr->taskSpecificParameters->u.adminService);
461
462         zebra_result (zh, &rr->errcode, &rr->errstring);
463     }
464     else if (rr->esr->taskSpecificParameters->which == Z_External_update)
465     {
466         Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
467         yaz_log (LOG_LOG, "Received DB Update");
468         if (up->which == Z_IUUpdate_esRequest)
469         {
470             Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
471             Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
472             Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
473             
474             yaz_log (LOG_LOG, "action");
475             if (toKeep->action)
476             {
477                 switch (*toKeep->action)
478                 {
479                 case Z_IUOriginPartToKeep_recordInsert:
480                     yaz_log (LOG_LOG, "recordInsert");
481                     break;
482                 case Z_IUOriginPartToKeep_recordReplace:
483                     yaz_log (LOG_LOG, "recordUpdate");
484                     break;
485                 case Z_IUOriginPartToKeep_recordDelete:
486                     yaz_log (LOG_LOG, "recordDelete");
487                     break;
488                 case Z_IUOriginPartToKeep_elementUpdate:
489                     yaz_log (LOG_LOG, "elementUpdate");
490                     break;
491                 case Z_IUOriginPartToKeep_specialUpdate:
492                     yaz_log (LOG_LOG, "specialUpdate");
493                     break;
494                 case Z_ESAdminOriginPartToKeep_shutdown:
495                     yaz_log (LOG_LOG, "shutDown");
496                     break;
497                 case Z_ESAdminOriginPartToKeep_start:
498                     yaz_log (LOG_LOG, "start");
499                     break;
500                 default:
501                     yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action);
502                 }
503             }
504             if (toKeep->databaseName)
505             {
506                 yaz_log (LOG_LOG, "database: %s", toKeep->databaseName);
507
508                 if (zebra_select_database(zh, toKeep->databaseName))
509                     return 0;
510             }
511             else
512             {
513                 yaz_log (LOG_WARN, "no database supplied for ES Update");
514                 rr->errcode = 1008;
515                 rr->errstring = "database";
516                 return 0;
517             }
518             if (notToKeep)
519             {
520                 int i;
521                 zebra_begin_trans (zh);
522                 for (i = 0; i < notToKeep->num; i++)
523                 {
524                     Z_External *rec = notToKeep->elements[i]->record;
525                     struct oident *oident = 0;
526                     Odr_oct *recid = notToKeep->elements[i]->u.opaque;
527
528                     if (!recid)
529                     {
530                         rr->errcode = 224;
531                         rr->errstring = "record Id not supplied";
532                         break;
533                     }
534                     if (notToKeep->elements[i]->which !=
535                         Z_IUSuppliedRecords_elem_opaque)
536                     {
537                         rr->errcode = 224;
538                         rr->errstring = "only opaque record ID supported";
539                         break;
540                     }
541                         
542                     if (rec->direct_reference)
543                     {
544                         oident = oid_getentbyoid(rec->direct_reference);
545                         if (oident)
546                             yaz_log (LOG_LOG, "record %d type %s", i,
547                                      oident->desc);
548                     }
549                     switch (rec->which)
550                     {
551                     case Z_External_sutrs:
552                         if (rec->u.octet_aligned->len > 170)
553                             yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
554                                      rec->u.sutrs->len,
555                                      rec->u.sutrs->buf);
556                         else
557                             yaz_log (LOG_LOG, "%d bytes:\n%s",
558                                      rec->u.sutrs->len,
559                                      rec->u.sutrs->buf);
560                         break;
561                     case Z_External_octet:
562                         if (rec->u.octet_aligned->len > 170)
563                             yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
564                                      rec->u.octet_aligned->len,
565                                      rec->u.octet_aligned->buf);
566                         else
567                             yaz_log (LOG_LOG, "%d bytes\n%s",
568                                      rec->u.octet_aligned->len,
569                                      rec->u.octet_aligned->buf);
570                     }
571                     if (oident && oident->value != VAL_TEXT_XML)
572                     {
573                         rr->errcode = 224;
574                         rr->errstring = "only XML update supported";
575                         break;
576                     }
577                     if (rec->which == Z_External_octet)
578                     {
579                         int action = 0;
580
581                         if (*toKeep->action ==
582                             Z_IUOriginPartToKeep_recordInsert)
583                             action = 1;
584                         if (*toKeep->action ==
585                             Z_IUOriginPartToKeep_recordReplace)
586                             action = 2;
587                         if (*toKeep->action ==
588                             Z_IUOriginPartToKeep_recordDelete)
589                             action = 3;
590                         if (*toKeep->action ==
591                             Z_IUOriginPartToKeep_specialUpdate)
592                             action = 1;
593
594                         if (!action)
595                         {
596                             rr->errcode = 224;
597                             rr->errstring = "unsupported ES Update action";
598                             break;
599                         }
600                         else
601                         {
602                             int r = zebra_admin_exchange_record (
603                                 zh, toKeep->databaseName,
604                                 rec->u.octet_aligned->buf,
605                                 rec->u.octet_aligned->len,
606                                 recid->buf, recid->len,
607                                 action);
608                             if (r && *toKeep->action ==
609                                 Z_IUOriginPartToKeep_specialUpdate)
610                             {
611                                 r = zebra_admin_exchange_record (
612                                     zh, toKeep->databaseName,
613                                     rec->u.octet_aligned->buf,
614                                     rec->u.octet_aligned->len,
615                                     recid->buf, recid->len,
616                                     2);
617                             }
618                             if (r)
619                             {
620                                 rr->errcode = 224;
621                                 rr->errstring = "record exchange failed";
622                                 break;
623                             }
624                         }
625                     }
626                 }
627                 zebra_end_trans (zh);
628             }
629         }
630     }
631     else
632     {
633         yaz_log (LOG_WARN, "Unknown Extended Service(%d)",
634                  rr->esr->taskSpecificParameters->which);
635         rr->errcode = 221;
636         
637     }
638     return 0;
639 }
640
641 static void bend_start (struct statserv_options_block *sob)
642 {
643 #ifdef WIN32
644     
645 #else
646     if (!sob->inetd) 
647     {
648         char *pidfile = "zebrasrv.pid";
649         int fd = creat (pidfile, 0666);
650         if (fd == -1)
651             yaz_log (LOG_WARN|LOG_ERRNO, "creat %s", pidfile);
652         else
653         {
654             char pidstr[30];
655         
656             sprintf (pidstr, "%ld", (long) getpid ());
657             write (fd, pidstr, strlen(pidstr));
658             close (fd);
659         }
660     }
661 #endif
662     if (sob->handle)
663         zebra_stop((ZebraService) sob->handle);
664     sob->handle = zebra_start(sob->configname);
665     if (!sob->handle)
666     {
667         yaz_log (LOG_FATAL, "Failed to read config `%s'", sob->configname);
668         exit (1);
669     }
670 }
671
672 static void bend_stop(struct statserv_options_block *sob)
673 {
674 #ifdef WIN32
675
676 #else
677     if (!sob->inetd) 
678         unlink ("zebrasrv.pid");
679 #endif
680     if (sob->handle)
681     {
682         ZebraService service = sob->handle;
683         zebra_stop(service);
684     }
685 }
686
687 int main (int argc, char **argv)
688 {
689     struct statserv_options_block *sob;
690
691     sob = statserv_getcontrol ();
692     strcpy (sob->configname, "zebra.cfg");
693     sob->bend_start = bend_start;
694     sob->bend_stop = bend_stop;
695 #ifdef WIN32
696     strcpy (sob->service_display_name, "Zebra Server");
697 #endif
698     statserv_setcontrol (sob);
699
700     return statserv_main (argc, argv, bend_init, bend_close);
701 }