59608d7dab300135ad2fd089012128915f59aefd
[simpleserver-moved-to-github.git] / SimpleServer.c
1 /*
2  * This file was generated automatically by xsubpp version 1.9507 from the 
3  * contents of SimpleServer.xs. Do not edit this file, edit SimpleServer.xs instead.
4  *
5  *      ANY CHANGES MADE HERE WILL BE LOST! 
6  *
7  */
8
9 #line 1 "SimpleServer.xs"
10 /*
11  * Copyright (c) 2000, Index Data.
12  *
13  * Permission to use, copy, modify, distribute, and sell this software and
14  * its documentation, in whole or in part, for any purpose, is hereby granted,
15  * provided that:
16  *
17  * 1. This copyright and permission notice appear in all copies of the
18  * software and its documentation. Notices of copyright or attribution
19  * which appear at the beginning of any file must remain unchanged.
20  *
21  * 2. The name of Index Data or the individual authors may not be used to
22  * endorse or promote products derived from this software without specific
23  * prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
27  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
28  * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
30  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
31  * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
32  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
33  * OF THIS SOFTWARE.
34  */
35
36
37 #include "EXTERN.h"
38 #include "perl.h"
39 #include "XSUB.h"
40 #include <yaz/backend.h>
41 #include <yaz/log.h>
42 #include <yaz/wrbuf.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <ctype.h>
46 #ifdef ASN_COMPILED
47 #include <yaz/ill.h>
48 #endif
49
50
51 typedef struct {
52         SV *handle;
53
54         SV *init_ref;
55         SV *close_ref;
56         SV *sort_ref;
57         SV *search_ref;
58         SV *fetch_ref;
59         SV *present_ref;
60         SV *esrequest_ref;
61         SV *delete_ref;
62         SV *scan_ref;
63 } Zfront_handle;
64
65 SV *init_ref = NULL;
66 SV *close_ref = NULL;
67 SV *sort_ref = NULL;
68 SV *search_ref = NULL;
69 SV *fetch_ref = NULL;
70 SV *present_ref = NULL;
71 SV *esrequest_ref = NULL;
72 SV *delete_ref = NULL;
73 SV *scan_ref = NULL;
74 int MAX_OID = 15;
75
76 static void oid2str(Odr_oid *o, WRBUF buf)
77 {
78     for (; *o >= 0; o++) {
79         char ibuf[16];
80         sprintf(ibuf, "%d", *o);
81         wrbuf_puts(buf, ibuf);
82         if (o[1] > 0)
83             wrbuf_putc(buf, '.');
84     }
85 }
86
87
88 static int rpn2pquery(Z_RPNStructure *s, WRBUF buf)
89 {
90     switch (s->which) {
91         case Z_RPNStructure_simple: {
92             Z_Operand *o = s->u.simple;
93
94             switch (o->which) {
95                 case Z_Operand_APT: {
96                     Z_AttributesPlusTerm *at = o->u.attributesPlusTerm;
97
98                     if (at->attributes) {
99                         int i;
100                         char ibuf[16];
101
102                         for (i = 0; i < at->attributes->num_attributes; i++) {
103                             wrbuf_puts(buf, "@attr ");
104                             if (at->attributes->attributes[i]->attributeSet) {
105                                 oid2str(at->attributes->attributes[i]->attributeSet, buf);
106                                 wrbuf_putc(buf, ' ');
107                             }
108                             sprintf(ibuf, "%d=", *at->attributes->attributes[i]->attributeType);
109                             assert(at->attributes->attributes[i]->which == Z_AttributeValue_numeric);
110                             wrbuf_puts(buf, ibuf);
111                             sprintf(ibuf, "%d ", *at->attributes->attributes[i]->value.numeric);
112                             wrbuf_puts(buf, ibuf);
113                         }
114                     }
115                     switch (at->term->which) {
116                         case Z_Term_general: {
117                             wrbuf_putc(buf, '"');
118                             wrbuf_write(buf, (char*) at->term->u.general->buf, at->term->u.general->len);
119                             wrbuf_puts(buf, "\" ");
120                             break;
121                         }
122                         default: abort();
123                     }
124                     break;
125                 }
126                 default: abort();
127             }
128             break;
129         }
130         case Z_RPNStructure_complex: {
131             Z_Complex *c = s->u.complex;
132
133             switch (c->roperator->which) {
134                 case Z_Operator_and: wrbuf_puts(buf, "@and "); break;
135                 case Z_Operator_or: wrbuf_puts(buf, "@or "); break;
136                 case Z_Operator_and_not: wrbuf_puts(buf, "@not "); break;
137                 case Z_Operator_prox: abort();
138                 default: abort();
139             }
140             if (!rpn2pquery(c->s1, buf))
141                 return 0;
142             if (!rpn2pquery(c->s2, buf))
143                 return 0;
144             break;
145         }
146         default: abort();
147     }
148     return 1;
149 }
150
151
152 WRBUF zquery2pquery(Z_Query *q)
153 {
154     WRBUF buf = wrbuf_alloc();
155
156     if (q->which != Z_Query_type_1 && q->which != Z_Query_type_101) 
157         return 0;
158     if (q->u.type_1->attributeSetId) {
159         /* Output attribute set ID */
160         wrbuf_puts(buf, "@attrset ");
161         oid2str(q->u.type_1->attributeSetId, buf);
162         wrbuf_putc(buf, ' ');
163     }
164     return rpn2pquery(q->u.type_1->RPNStructure, buf) ? buf : 0;
165 }
166
167
168 int bend_sort(void *handle, bend_sort_rr *rr)
169 {
170         perl_call_sv(sort_ref, G_VOID | G_DISCARD | G_NOARGS);
171         return;
172 }
173
174
175 int bend_search(void *handle, bend_search_rr *rr)
176 {
177         HV *href;
178         AV *aref;
179         SV **temp;
180         SV *hits;
181         SV *err_code;
182         SV *err_str;
183         char *ODR_errstr;
184         STRLEN len;
185         int i;
186         char **basenames;
187         int n;
188         WRBUF query;
189         char *ptr;
190         SV *point;
191         SV *ODR_point;
192         Zfront_handle *zhandle = (Zfront_handle *)handle;
193
194         dSP;
195         ENTER;
196         SAVETMPS;
197
198         aref = newAV();
199         basenames = rr->basenames;
200         for (i = 0; i < rr->num_bases; i++)
201         {
202                 av_push(aref, newSVpv(*basenames++, 0));
203         }
204         href = newHV();         
205         hv_store(href, "SETNAME", 7, newSVpv(rr->setname, 0), 0);
206         hv_store(href, "REPL_SET", 8, newSViv(rr->replace_set), 0);
207         hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
208         hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
209         hv_store(href, "HITS", 4, newSViv(0), 0);
210         hv_store(href, "DATABASES", 9, newRV( (SV*) aref), 0);
211         hv_store(href, "HANDLE", 6, zhandle->handle, 0);
212         query = zquery2pquery(rr->query);
213         if (query)
214         {
215                 hv_store(href, "QUERY", 5, newSVpv((char *)query->buf, query->pos), 0);
216         }
217         else
218         {       
219                 rr->errcode = 108;
220         }
221         PUSHMARK(sp);
222         
223         XPUSHs(sv_2mortal(newRV( (SV*) href)));
224         
225         PUTBACK;
226
227         n = perl_call_sv(search_ref, G_SCALAR | G_DISCARD);
228
229         SPAGAIN;
230
231         temp = hv_fetch(href, "HITS", 4, 1);
232         hits = newSVsv(*temp);
233
234         temp = hv_fetch(href, "ERR_CODE", 8, 1);
235         err_code = newSVsv(*temp);
236
237         temp = hv_fetch(href, "ERR_STR", 7, 1);
238         err_str = newSVsv(*temp);
239
240         temp = hv_fetch(href, "HANDLE", 6, 1);
241         point = newSVsv(*temp);
242
243         PUTBACK;
244         FREETMPS;
245         LEAVE;
246         
247         hv_undef(href);
248         av_undef(aref);
249         rr->hits = SvIV(hits);
250         rr->errcode = SvIV(err_code);
251         ptr = SvPV(err_str, len);
252         ODR_errstr = (char *)odr_malloc(rr->stream, len + 1);
253         strcpy(ODR_errstr, ptr);
254         rr->errstring = ODR_errstr;
255 /*      ODR_point = (SV *)odr_malloc(rr->stream, sizeof(*point));
256         memcpy(ODR_point, point, sizeof(*point));
257         zhandle->handle = ODR_point;*/
258         zhandle->handle = point;
259         handle = zhandle;
260         sv_free(hits);
261         sv_free(err_code);
262         sv_free(err_str);
263         sv_free( (SV*) aref);
264         sv_free( (SV*) href);
265         /*sv_free(point);*/
266         wrbuf_free(query, 1);
267         return 0;
268 }
269
270
271 WRBUF oid2dotted(int *oid)
272 {
273
274         WRBUF buf = wrbuf_alloc();
275         int dot = 0;
276
277         for (; *oid != -1 ; oid++)
278         {
279                 char ibuf[16];
280                 if (dot)
281                 {
282                         wrbuf_putc(buf, '.');
283                 }
284                 else
285                 {
286                         dot = 1;
287                 }
288                 sprintf(ibuf, "%d", *oid);
289                 wrbuf_puts(buf, ibuf);
290         }
291         return buf;
292 }
293                 
294
295 int dotted2oid(char *dotted, int *buffer)
296 {
297         int *oid;
298         char ibuf[16];
299         char *ptr;
300         int n = 0;
301
302         ptr = ibuf;
303         oid = buffer;
304         while (*dotted)
305         {
306                 if (*dotted == '.')
307                 {
308                         n++;
309                         if (n == MAX_OID)  /* Terminate if more than MAX_OID entries */
310                         {
311                                 *oid = -1;
312                                 return -1;
313                         }
314                         *ptr = 0;
315                         sscanf(ibuf, "%d", oid++);
316                         ptr = ibuf;
317                         dotted++;
318
319                 }
320                 else
321                 {
322                         *ptr++ = *dotted++;
323                 }
324         }
325         if (n < MAX_OID)
326         {
327                 *ptr = 0;
328                 sscanf(ibuf, "%d", oid++);
329         }
330         *oid = -1;
331         return 0;
332 }
333
334
335 int bend_fetch(void *handle, bend_fetch_rr *rr)
336 {
337         HV *href;
338         SV **temp;
339         SV *basename;
340         SV *record;
341         SV *last;
342         SV *err_code;
343         SV *err_string;
344         SV *sur_flag;
345         SV *point;
346         SV *rep_form;
347         char *ptr;
348         char *ODR_record;
349         char *ODR_basename;
350         char *ODR_errstr;
351         int *ODR_oid_buf;
352         WRBUF oid_dotted;
353         Zfront_handle *zhandle = (Zfront_handle *)handle;
354
355         Z_RecordComposition *composition;
356         Z_ElementSetNames *simple;
357         STRLEN length;
358         int oid;
359
360         dSP;
361         ENTER;
362         SAVETMPS;
363
364         rr->errcode = 0;
365         href = newHV();
366         hv_store(href, "SETNAME", 7, newSVpv(rr->setname, 0), 0);
367         temp = hv_store(href, "OFFSET", 6, newSViv(rr->number), 0);
368         oid_dotted = oid2dotted(rr->request_format_raw);
369         hv_store(href, "REQ_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0);
370         hv_store(href, "REP_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0);
371         hv_store(href, "BASENAME", 8, newSVpv("", 0), 0);
372         hv_store(href, "RECORD", 6, newSVpv("", 0), 0);
373         hv_store(href, "LAST", 4, newSViv(0), 0);
374         hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
375         hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
376         hv_store(href, "SUR_FLAG", 8, newSViv(0), 0);
377         hv_store(href, "HANDLE", 6, zhandle->handle, 0);
378         if (rr->comp)
379         {
380                 composition = rr->comp;
381                 if (composition->which == Z_RecordComp_simple)
382                 {
383                         simple = composition->u.simple;
384                         if (simple->which == 1)
385                         {
386                                 hv_store(href, "COMP", 4, newSVpv(simple->u.generic, 0), 0);
387                         } 
388                         else
389                         {
390                                 rr->errcode = 26;
391                         }
392                 }
393                 else
394                 {
395                         rr->errcode = 26;
396                 }
397         }
398
399         PUSHMARK(sp);
400
401         XPUSHs(sv_2mortal(newRV( (SV*) href)));
402
403         PUTBACK;
404         
405         perl_call_sv(fetch_ref, G_SCALAR | G_DISCARD);
406
407         SPAGAIN;
408
409         temp = hv_fetch(href, "BASENAME", 8, 1);
410         basename = newSVsv(*temp);
411
412         temp = hv_fetch(href, "RECORD", 6, 1);
413         record = newSVsv(*temp);
414
415         temp = hv_fetch(href, "LAST", 4, 1);
416         last = newSVsv(*temp);
417
418         temp = hv_fetch(href, "ERR_CODE", 8, 1);
419         err_code = newSVsv(*temp);
420
421         temp = hv_fetch(href, "ERR_STR", 7, 1),
422         err_string = newSVsv(*temp);
423
424         temp = hv_fetch(href, "SUR_FLAG", 8, 1);
425         sur_flag = newSVsv(*temp);
426
427         temp = hv_fetch(href, "REP_FORM", 8, 1);
428         rep_form = newSVsv(*temp);
429
430         temp = hv_fetch(href, "HANDLE", 6, 1);
431         point = newSVsv(*temp);
432
433         PUTBACK;
434         FREETMPS;
435         LEAVE;
436
437         hv_undef(href);
438         
439         ptr = SvPV(basename, length);
440         ODR_basename = (char *)odr_malloc(rr->stream, length + 1);
441         strcpy(ODR_basename, ptr);
442         rr->basename = ODR_basename;
443
444         ptr = SvPV(rep_form, length);
445         ODR_oid_buf = (int *)odr_malloc(rr->stream, (MAX_OID + 1) * sizeof(int));
446         if (dotted2oid(ptr, ODR_oid_buf) == -1)         /* Maximum number of OID elements exceeded */
447         {
448                 printf("Net::Z3950::SimpleServer: WARNING: OID structure too long, max length is %d\n", MAX_OID);
449         }
450         rr->output_format_raw = ODR_oid_buf;    
451         
452         ptr = SvPV(record, length);
453         ODR_record = (char *)odr_malloc(rr->stream, length + 1);
454         strcpy(ODR_record, ptr);
455         rr->record = ODR_record;
456         rr->len = length;
457
458         zhandle->handle = point;
459         handle = zhandle;
460         rr->last_in_set = SvIV(last);
461         
462         if (!(rr->errcode))
463         {
464                 rr->errcode = SvIV(err_code);
465                 ptr = SvPV(err_string, length);
466                 ODR_errstr = (char *)odr_malloc(rr->stream, length + 1);
467                 strcpy(ODR_errstr, ptr);
468                 rr->errstring = ODR_errstr;
469         }
470         rr->surrogate_flag = SvIV(sur_flag);
471
472         wrbuf_free(oid_dotted, 1);
473         sv_free((SV*) href);
474         sv_free(basename);
475         sv_free(record);
476         sv_free(last);
477         sv_free(err_string);
478         sv_free(err_code),
479         sv_free(sur_flag);
480         sv_free(rep_form);
481         
482         return 0;
483 }
484
485
486 int bend_present(void *handle, bend_present_rr *rr)
487 {
488
489         int n;
490         HV *href;
491         SV **temp;
492         SV *err_code;
493         SV *err_string;
494         STRLEN len;
495         Z_RecordComposition *composition;
496         Z_ElementSetNames *simple;
497         char *ODR_errstr;
498         char *ptr;
499
500         dSP;
501         ENTER;
502         SAVETMPS;
503
504         href = newHV();
505         hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
506         hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
507         hv_store(href, "START", 5, newSViv(rr->start), 0);
508         hv_store(href, "SETNAME", 7, newSVpv(rr->setname, 0), 0);
509         hv_store(href, "NUMBER", 6, newSViv(rr->number), 0);
510         if (rr->comp)
511         {
512                 composition = rr->comp;
513                 if (composition->which == 1)
514                 {
515                         simple = composition->u.simple;
516                         if (simple->which == 1)
517                         {
518                                 hv_store(href, "COMP", 4, newSVpv(simple->u.generic, 0), 0);
519                         } 
520                         else
521                         {
522                                 rr->errcode = 26;
523                                 return 0;
524                         }
525                 }
526                 else
527                 {
528                         rr->errcode = 26;
529                         return 0;
530                 }
531         }
532
533         PUSHMARK(sp);
534         
535         XPUSHs(sv_2mortal(newRV( (SV*) href)));
536         
537         PUTBACK;
538         
539         n = perl_call_sv(present_ref, G_SCALAR | G_DISCARD);
540         
541         SPAGAIN;
542
543         temp = hv_fetch(href, "ERR_CODE", 8, 1);
544         err_code = newSVsv(*temp);
545
546         temp = hv_fetch(href, "ERR_STR", 7, 1);
547         err_string = newSVsv(*temp);
548
549         PUTBACK;
550         FREETMPS;
551         LEAVE;
552         
553         hv_undef(href);
554         rr->errcode = SvIV(err_code);
555
556         ptr = SvPV(err_string, len);
557         ODR_errstr = (char *)odr_malloc(rr->stream, len + 1);
558         strcpy(ODR_errstr, ptr);
559         rr->errstring = ODR_errstr;
560
561         sv_free(err_code);
562         sv_free(err_string);
563         sv_free( (SV*) href);
564
565         return 0;
566 }
567
568
569 int bend_esrequest(void *handle, bend_esrequest_rr *rr)
570 {
571         perl_call_sv(esrequest_ref, G_VOID | G_DISCARD | G_NOARGS);
572         return 0;
573 }
574
575
576 int bend_delete(void *handle, bend_delete_rr *rr)
577 {
578         perl_call_sv(delete_ref, G_VOID | G_DISCARD | G_NOARGS);
579         return 0;
580 }
581
582
583 int bend_scan(void *handle, bend_scan_rr *rr)
584 {
585         perl_call_sv(scan_ref, G_VOID | G_DISCARD | G_NOARGS);
586         return 0;
587 }
588
589
590 bend_initresult *bend_init(bend_initrequest *q)
591 {
592         bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r));
593         HV *href;
594         SV **temp;
595         SV *name;
596         SV *ver;
597         SV *err_str;
598         SV *status;
599         Zfront_handle *zhandle =  (Zfront_handle *) xmalloc (sizeof(*zhandle));
600         STRLEN len;
601         int n;
602         SV *handle;
603         /*char *name_ptr;
604         char *ver_ptr;*/
605         char *ptr;
606
607         dSP;
608         ENTER;
609         SAVETMPS;
610
611         /*q->bend_sort = bend_sort;*/
612         if (search_ref)
613         {
614                 q->bend_search = bend_search;
615         }
616         /*q->bend_present = present;*/
617         /*q->bend_esrequest = bend_esrequest;*/
618         /*q->bend_delete = bend_delete;*/
619         if (fetch_ref)
620         {
621                 q->bend_fetch = bend_fetch;
622         }
623         /*q->bend_scan = bend_scan;*/
624         href = newHV(); 
625         hv_store(href, "IMP_NAME", 8, newSVpv("", 0), 0);
626         hv_store(href, "IMP_VER", 7, newSVpv("", 0), 0);
627         hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
628         hv_store(href, "HANDLE", 6, newSVsv(&sv_undef), 0);
629
630         PUSHMARK(sp);   
631
632         XPUSHs(sv_2mortal(newRV( (SV*) href)));
633
634         PUTBACK;
635
636         if (init_ref != NULL)
637         {
638                 perl_call_sv(init_ref, G_SCALAR | G_DISCARD);
639         }
640
641         SPAGAIN;
642
643         temp = hv_fetch(href, "IMP_NAME", 8, 1);
644         name = newSVsv(*temp);
645
646         temp = hv_fetch(href, "IMP_VER", 7, 1);
647         ver = newSVsv(*temp);
648
649         temp = hv_fetch(href, "ERR_CODE", 8, 1);
650         status = newSVsv(*temp);
651
652         temp = hv_fetch(href, "HANDLE", 6, 1);
653         handle= newSVsv(*temp);
654
655         hv_undef(href);
656         PUTBACK;
657         FREETMPS;
658         LEAVE;
659         zhandle->handle = handle;
660         r->errcode = SvIV(status);
661         r->handle = zhandle;
662         ptr = SvPV(name, len);
663         q->implementation_name = (char *)xmalloc(len + 1);
664         strcpy(q->implementation_name, ptr);
665 /*      q->implementation_name = SvPV(name, len);*/
666         ptr = SvPV(ver, len);
667         q->implementation_version = (char *)xmalloc(len + 1);
668         strcpy(q->implementation_version, ptr);
669         
670         return r;
671 }
672
673
674 void bend_close(void *handle)
675 {
676         HV *href;
677         Zfront_handle *zhandle = (Zfront_handle *)handle;
678         SV **temp;
679
680         dSP;
681         ENTER;
682         SAVETMPS;
683
684         if (close_ref == NULL)
685         {
686                 return;
687         }
688
689         href = newHV();
690         hv_store(href, "HANDLE", 6, zhandle->handle, 0);
691
692         PUSHMARK(sp);
693
694         XPUSHs(sv_2mortal(newRV((SV *)href)));
695
696         PUTBACK;
697         
698         perl_call_sv(close_ref, G_SCALAR | G_DISCARD);
699         
700         SPAGAIN;
701
702         PUTBACK;
703         FREETMPS;
704         LEAVE;
705
706         xfree(handle);
707         
708         return;
709 }
710
711
712 #line 713 "SimpleServer.c"
713 XS(XS_Net__Z3950__SimpleServer_set_init_handler)
714 {
715     dXSARGS;
716     if (items != 1)
717         croak("Usage: Net::Z3950::SimpleServer::set_init_handler(arg)");
718     {
719         SV *    arg = ST(0);
720 #line 709 "SimpleServer.xs"
721                 init_ref = newSVsv(arg);
722 #line 723 "SimpleServer.c"
723     }
724     XSRETURN_EMPTY;
725 }
726
727 XS(XS_Net__Z3950__SimpleServer_set_close_handler)
728 {
729     dXSARGS;
730     if (items != 1)
731         croak("Usage: Net::Z3950::SimpleServer::set_close_handler(arg)");
732     {
733         SV *    arg = ST(0);
734 #line 716 "SimpleServer.xs"
735                 close_ref = newSVsv(arg);
736 #line 737 "SimpleServer.c"
737     }
738     XSRETURN_EMPTY;
739 }
740
741 XS(XS_Net__Z3950__SimpleServer_set_sort_handler)
742 {
743     dXSARGS;
744     if (items != 1)
745         croak("Usage: Net::Z3950::SimpleServer::set_sort_handler(arg)");
746     {
747         SV *    arg = ST(0);
748 #line 723 "SimpleServer.xs"
749                 sort_ref = newSVsv(arg);
750 #line 751 "SimpleServer.c"
751     }
752     XSRETURN_EMPTY;
753 }
754
755 XS(XS_Net__Z3950__SimpleServer_set_search_handler)
756 {
757     dXSARGS;
758     if (items != 1)
759         croak("Usage: Net::Z3950::SimpleServer::set_search_handler(arg)");
760     {
761         SV *    arg = ST(0);
762 #line 729 "SimpleServer.xs"
763                 search_ref = newSVsv(arg);
764 #line 765 "SimpleServer.c"
765     }
766     XSRETURN_EMPTY;
767 }
768
769 XS(XS_Net__Z3950__SimpleServer_set_fetch_handler)
770 {
771     dXSARGS;
772     if (items != 1)
773         croak("Usage: Net::Z3950::SimpleServer::set_fetch_handler(arg)");
774     {
775         SV *    arg = ST(0);
776 #line 736 "SimpleServer.xs"
777                 fetch_ref = newSVsv(arg);
778 #line 779 "SimpleServer.c"
779     }
780     XSRETURN_EMPTY;
781 }
782
783 XS(XS_Net__Z3950__SimpleServer_set_present_handler)
784 {
785     dXSARGS;
786     if (items != 1)
787         croak("Usage: Net::Z3950::SimpleServer::set_present_handler(arg)");
788     {
789         SV *    arg = ST(0);
790 #line 743 "SimpleServer.xs"
791                 present_ref = newSVsv(arg);
792 #line 793 "SimpleServer.c"
793     }
794     XSRETURN_EMPTY;
795 }
796
797 XS(XS_Net__Z3950__SimpleServer_set_esrequest_handler)
798 {
799     dXSARGS;
800     if (items != 1)
801         croak("Usage: Net::Z3950::SimpleServer::set_esrequest_handler(arg)");
802     {
803         SV *    arg = ST(0);
804 #line 750 "SimpleServer.xs"
805                 esrequest_ref = newSVsv(arg);
806 #line 807 "SimpleServer.c"
807     }
808     XSRETURN_EMPTY;
809 }
810
811 XS(XS_Net__Z3950__SimpleServer_set_delete_handler)
812 {
813     dXSARGS;
814     if (items != 1)
815         croak("Usage: Net::Z3950::SimpleServer::set_delete_handler(arg)");
816     {
817         SV *    arg = ST(0);
818 #line 757 "SimpleServer.xs"
819                 delete_ref = newSVsv(arg);
820 #line 821 "SimpleServer.c"
821     }
822     XSRETURN_EMPTY;
823 }
824
825 XS(XS_Net__Z3950__SimpleServer_set_scan_handler)
826 {
827     dXSARGS;
828     if (items != 1)
829         croak("Usage: Net::Z3950::SimpleServer::set_scan_handler(arg)");
830     {
831         SV *    arg = ST(0);
832 #line 764 "SimpleServer.xs"
833                 scan_ref = newSVsv(arg);
834 #line 835 "SimpleServer.c"
835     }
836     XSRETURN_EMPTY;
837 }
838
839 XS(XS_Net__Z3950__SimpleServer_start_server)
840 {
841     dXSARGS;
842     {
843 #line 770 "SimpleServer.xs"
844                 char **argv;
845                 char **argv_buf;
846                 char *ptr;
847                 int i;
848                 STRLEN len;
849 #line 850 "SimpleServer.c"
850         int     RETVAL;
851 #line 776 "SimpleServer.xs"
852                 argv_buf = (char **)xmalloc((items + 1) * sizeof(char *));
853                 argv = argv_buf;
854                 for (i = 0; i < items; i++)
855                 {
856                         ptr = SvPV(ST(i), len);
857                         *argv_buf = (char *)xmalloc(len + 1);
858                         strcpy(*argv_buf++, ptr); 
859                 }
860                 *argv_buf = NULL;
861
862                 RETVAL = statserv_main(items, argv, bend_init, bend_close);
863 #line 864 "SimpleServer.c"
864         ST(0) = sv_newmortal();
865         sv_setiv(ST(0), (IV)RETVAL);
866     }
867     XSRETURN(1);
868 }
869
870 #ifdef __cplusplus
871 extern "C"
872 #endif
873 XS(boot_Net__Z3950__SimpleServer)
874 {
875     dXSARGS;
876     char* file = __FILE__;
877
878     XS_VERSION_BOOTCHECK ;
879
880         newXS("Net::Z3950::SimpleServer::set_init_handler", XS_Net__Z3950__SimpleServer_set_init_handler, file);
881         newXS("Net::Z3950::SimpleServer::set_close_handler", XS_Net__Z3950__SimpleServer_set_close_handler, file);
882         newXS("Net::Z3950::SimpleServer::set_sort_handler", XS_Net__Z3950__SimpleServer_set_sort_handler, file);
883         newXS("Net::Z3950::SimpleServer::set_search_handler", XS_Net__Z3950__SimpleServer_set_search_handler, file);
884         newXS("Net::Z3950::SimpleServer::set_fetch_handler", XS_Net__Z3950__SimpleServer_set_fetch_handler, file);
885         newXS("Net::Z3950::SimpleServer::set_present_handler", XS_Net__Z3950__SimpleServer_set_present_handler, file);
886         newXS("Net::Z3950::SimpleServer::set_esrequest_handler", XS_Net__Z3950__SimpleServer_set_esrequest_handler, file);
887         newXS("Net::Z3950::SimpleServer::set_delete_handler", XS_Net__Z3950__SimpleServer_set_delete_handler, file);
888         newXS("Net::Z3950::SimpleServer::set_scan_handler", XS_Net__Z3950__SimpleServer_set_scan_handler, file);
889         newXS("Net::Z3950::SimpleServer::start_server", XS_Net__Z3950__SimpleServer_start_server, file);
890     XSRETURN_YES;
891 }
892