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.
5 * ANY CHANGES MADE HERE WILL BE LOST!
9 #line 1 "SimpleServer.xs"
11 * Copyright (c) 2000, Index Data.
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,
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.
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.
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
40 #include <yaz/backend.h>
42 #include <yaz/wrbuf.h>
68 SV *search_ref = NULL;
70 SV *present_ref = NULL;
71 SV *esrequest_ref = NULL;
72 SV *delete_ref = NULL;
76 static void oid2str(Odr_oid *o, WRBUF buf)
78 for (; *o >= 0; o++) {
80 sprintf(ibuf, "%d", *o);
81 wrbuf_puts(buf, ibuf);
88 static int rpn2pquery(Z_RPNStructure *s, WRBUF buf)
91 case Z_RPNStructure_simple: {
92 Z_Operand *o = s->u.simple;
96 Z_AttributesPlusTerm *at = o->u.attributesPlusTerm;
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, ' ');
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);
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, "\" ");
130 case Z_RPNStructure_complex: {
131 Z_Complex *c = s->u.complex;
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();
140 if (!rpn2pquery(c->s1, buf))
142 if (!rpn2pquery(c->s2, buf))
152 WRBUF zquery2pquery(Z_Query *q)
154 WRBUF buf = wrbuf_alloc();
156 if (q->which != Z_Query_type_1 && q->which != Z_Query_type_101)
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, ' ');
164 return rpn2pquery(q->u.type_1->RPNStructure, buf) ? buf : 0;
168 int bend_sort(void *handle, bend_sort_rr *rr)
170 perl_call_sv(sort_ref, G_VOID | G_DISCARD | G_NOARGS);
175 int bend_search(void *handle, bend_search_rr *rr)
192 Zfront_handle *zhandle = (Zfront_handle *)handle;
199 basenames = rr->basenames;
200 for (i = 0; i < rr->num_bases; i++)
202 av_push(aref, newSVpv(*basenames++, 0));
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);
215 hv_store(href, "QUERY", 5, newSVpv((char *)query->buf, query->pos), 0);
223 XPUSHs(sv_2mortal(newRV( (SV*) href)));
227 n = perl_call_sv(search_ref, G_SCALAR | G_DISCARD);
231 temp = hv_fetch(href, "HITS", 4, 1);
232 hits = newSVsv(*temp);
234 temp = hv_fetch(href, "ERR_CODE", 8, 1);
235 err_code = newSVsv(*temp);
237 temp = hv_fetch(href, "ERR_STR", 7, 1);
238 err_str = newSVsv(*temp);
240 temp = hv_fetch(href, "HANDLE", 6, 1);
241 point = newSVsv(*temp);
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;
263 sv_free( (SV*) aref);
264 sv_free( (SV*) href);
266 wrbuf_free(query, 1);
271 WRBUF oid2dotted(int *oid)
274 WRBUF buf = wrbuf_alloc();
277 for (; *oid != -1 ; oid++)
282 wrbuf_putc(buf, '.');
288 sprintf(ibuf, "%d", *oid);
289 wrbuf_puts(buf, ibuf);
295 int dotted2oid(char *dotted, int *buffer)
309 if (n == MAX_OID) /* Terminate if more than MAX_OID entries */
315 sscanf(ibuf, "%d", oid++);
328 sscanf(ibuf, "%d", oid++);
335 int bend_fetch(void *handle, bend_fetch_rr *rr)
353 Zfront_handle *zhandle = (Zfront_handle *)handle;
355 Z_RecordComposition *composition;
356 Z_ElementSetNames *simple;
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);
380 composition = rr->comp;
381 if (composition->which == Z_RecordComp_simple)
383 simple = composition->u.simple;
384 if (simple->which == 1)
386 hv_store(href, "COMP", 4, newSVpv(simple->u.generic, 0), 0);
401 XPUSHs(sv_2mortal(newRV( (SV*) href)));
405 perl_call_sv(fetch_ref, G_SCALAR | G_DISCARD);
409 temp = hv_fetch(href, "BASENAME", 8, 1);
410 basename = newSVsv(*temp);
412 temp = hv_fetch(href, "RECORD", 6, 1);
413 record = newSVsv(*temp);
415 temp = hv_fetch(href, "LAST", 4, 1);
416 last = newSVsv(*temp);
418 temp = hv_fetch(href, "ERR_CODE", 8, 1);
419 err_code = newSVsv(*temp);
421 temp = hv_fetch(href, "ERR_STR", 7, 1),
422 err_string = newSVsv(*temp);
424 temp = hv_fetch(href, "SUR_FLAG", 8, 1);
425 sur_flag = newSVsv(*temp);
427 temp = hv_fetch(href, "REP_FORM", 8, 1);
428 rep_form = newSVsv(*temp);
430 temp = hv_fetch(href, "HANDLE", 6, 1);
431 point = newSVsv(*temp);
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;
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 */
448 printf("Net::Z3950::SimpleServer: WARNING: OID structure too long, max length is %d\n", MAX_OID);
450 rr->output_format_raw = ODR_oid_buf;
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;
458 zhandle->handle = point;
460 rr->last_in_set = SvIV(last);
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;
470 rr->surrogate_flag = SvIV(sur_flag);
472 wrbuf_free(oid_dotted, 1);
486 int bend_present(void *handle, bend_present_rr *rr)
495 Z_RecordComposition *composition;
496 Z_ElementSetNames *simple;
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);
512 composition = rr->comp;
513 if (composition->which == 1)
515 simple = composition->u.simple;
516 if (simple->which == 1)
518 hv_store(href, "COMP", 4, newSVpv(simple->u.generic, 0), 0);
535 XPUSHs(sv_2mortal(newRV( (SV*) href)));
539 n = perl_call_sv(present_ref, G_SCALAR | G_DISCARD);
543 temp = hv_fetch(href, "ERR_CODE", 8, 1);
544 err_code = newSVsv(*temp);
546 temp = hv_fetch(href, "ERR_STR", 7, 1);
547 err_string = newSVsv(*temp);
554 rr->errcode = SvIV(err_code);
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;
563 sv_free( (SV*) href);
569 int bend_esrequest(void *handle, bend_esrequest_rr *rr)
571 perl_call_sv(esrequest_ref, G_VOID | G_DISCARD | G_NOARGS);
576 int bend_delete(void *handle, bend_delete_rr *rr)
578 perl_call_sv(delete_ref, G_VOID | G_DISCARD | G_NOARGS);
583 int bend_scan(void *handle, bend_scan_rr *rr)
585 perl_call_sv(scan_ref, G_VOID | G_DISCARD | G_NOARGS);
590 bend_initresult *bend_init(bend_initrequest *q)
592 bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r));
599 Zfront_handle *zhandle = (Zfront_handle *) xmalloc (sizeof(*zhandle));
611 /*q->bend_sort = bend_sort;*/
614 q->bend_search = bend_search;
616 /*q->bend_present = present;*/
617 /*q->bend_esrequest = bend_esrequest;*/
618 /*q->bend_delete = bend_delete;*/
621 q->bend_fetch = bend_fetch;
623 /*q->bend_scan = bend_scan;*/
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);
632 XPUSHs(sv_2mortal(newRV( (SV*) href)));
636 if (init_ref != NULL)
638 perl_call_sv(init_ref, G_SCALAR | G_DISCARD);
643 temp = hv_fetch(href, "IMP_NAME", 8, 1);
644 name = newSVsv(*temp);
646 temp = hv_fetch(href, "IMP_VER", 7, 1);
647 ver = newSVsv(*temp);
649 temp = hv_fetch(href, "ERR_CODE", 8, 1);
650 status = newSVsv(*temp);
652 temp = hv_fetch(href, "HANDLE", 6, 1);
653 handle= newSVsv(*temp);
659 zhandle->handle = handle;
660 r->errcode = SvIV(status);
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);
674 void bend_close(void *handle)
677 Zfront_handle *zhandle = (Zfront_handle *)handle;
684 if (close_ref == NULL)
690 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
694 XPUSHs(sv_2mortal(newRV((SV *)href)));
698 perl_call_sv(close_ref, G_SCALAR | G_DISCARD);
712 #line 713 "SimpleServer.c"
713 XS(XS_Net__Z3950__SimpleServer_set_init_handler)
717 croak("Usage: Net::Z3950::SimpleServer::set_init_handler(arg)");
720 #line 709 "SimpleServer.xs"
721 init_ref = newSVsv(arg);
722 #line 723 "SimpleServer.c"
727 XS(XS_Net__Z3950__SimpleServer_set_close_handler)
731 croak("Usage: Net::Z3950::SimpleServer::set_close_handler(arg)");
734 #line 716 "SimpleServer.xs"
735 close_ref = newSVsv(arg);
736 #line 737 "SimpleServer.c"
741 XS(XS_Net__Z3950__SimpleServer_set_sort_handler)
745 croak("Usage: Net::Z3950::SimpleServer::set_sort_handler(arg)");
748 #line 723 "SimpleServer.xs"
749 sort_ref = newSVsv(arg);
750 #line 751 "SimpleServer.c"
755 XS(XS_Net__Z3950__SimpleServer_set_search_handler)
759 croak("Usage: Net::Z3950::SimpleServer::set_search_handler(arg)");
762 #line 729 "SimpleServer.xs"
763 search_ref = newSVsv(arg);
764 #line 765 "SimpleServer.c"
769 XS(XS_Net__Z3950__SimpleServer_set_fetch_handler)
773 croak("Usage: Net::Z3950::SimpleServer::set_fetch_handler(arg)");
776 #line 736 "SimpleServer.xs"
777 fetch_ref = newSVsv(arg);
778 #line 779 "SimpleServer.c"
783 XS(XS_Net__Z3950__SimpleServer_set_present_handler)
787 croak("Usage: Net::Z3950::SimpleServer::set_present_handler(arg)");
790 #line 743 "SimpleServer.xs"
791 present_ref = newSVsv(arg);
792 #line 793 "SimpleServer.c"
797 XS(XS_Net__Z3950__SimpleServer_set_esrequest_handler)
801 croak("Usage: Net::Z3950::SimpleServer::set_esrequest_handler(arg)");
804 #line 750 "SimpleServer.xs"
805 esrequest_ref = newSVsv(arg);
806 #line 807 "SimpleServer.c"
811 XS(XS_Net__Z3950__SimpleServer_set_delete_handler)
815 croak("Usage: Net::Z3950::SimpleServer::set_delete_handler(arg)");
818 #line 757 "SimpleServer.xs"
819 delete_ref = newSVsv(arg);
820 #line 821 "SimpleServer.c"
825 XS(XS_Net__Z3950__SimpleServer_set_scan_handler)
829 croak("Usage: Net::Z3950::SimpleServer::set_scan_handler(arg)");
832 #line 764 "SimpleServer.xs"
833 scan_ref = newSVsv(arg);
834 #line 835 "SimpleServer.c"
839 XS(XS_Net__Z3950__SimpleServer_start_server)
843 #line 770 "SimpleServer.xs"
849 #line 850 "SimpleServer.c"
851 #line 776 "SimpleServer.xs"
852 argv_buf = (char **)xmalloc((items + 1) * sizeof(char *));
854 for (i = 0; i < items; i++)
856 ptr = SvPV(ST(i), len);
857 *argv_buf = (char *)xmalloc(len + 1);
858 strcpy(*argv_buf++, ptr);
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);
873 XS(boot_Net__Z3950__SimpleServer)
876 char* file = __FILE__;
878 XS_VERSION_BOOTCHECK ;
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);