1 /* This file is part of simpleserver.
2 * Copyright (C) 2000-2011 Index Data.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <yaz/backend.h>
35 #include <yaz/facet.h>
37 #include <yaz/wrbuf.h>
38 #include <yaz/pquery.h>
39 #include <yaz/querytowrbuf.h>
41 #include <yaz/mutex.h>
42 #include <yaz/oid_db.h>
49 #define GRS_MAX_FIELDS 500
53 #ifndef sv_undef /* To fix the problem with Perl 5.6.0 */
54 #define sv_undef PL_sv_undef
57 YAZ_MUTEX simpleserver_mutex;
60 SV *ghandle; /* Global handle specified at creation */
61 SV *handle; /* Per-connection handle set at Init */
63 /* ### These callback-reference elements are never used! */
76 int stop_flag; /* is used to stop server prematurely .. */
79 #define ENABLE_STOP_SERVER 0
81 SV *_global_ghandle = NULL; /* To be copied into zhandle then ignored */
85 SV *search_ref = NULL;
87 SV *present_ref = NULL;
88 SV *esrequest_ref = NULL;
89 SV *delete_ref = NULL;
91 SV *explain_ref = NULL;
92 PerlInterpreter *root_perl_context;
94 #define GRS_BUF_SIZE 8192
98 * Inspects the SV indicated by svp, and returns a null pointer if
99 * it's an undefined value, or a string allocation from `stream'
100 * otherwise. Using this when filling in addinfo avoids those
101 * irritating "Use of uninitialized value in subroutine entry"
102 * warnings from Perl.
104 char *string_or_undef(SV **svp, ODR stream) {
111 ptr = SvPV(*svp, len);
112 buf = (char*) odr_malloc(stream, len+1);
118 CV * simpleserver_sv2cv(SV *handler) {
122 if (SvPOK(handler)) {
124 buf = SvPV( handler, len);
125 if ( !( ret = perl_get_cv(buf, FALSE ) ) ) {
126 fprintf( stderr, "simpleserver_sv2cv: No such handler '%s'\n\n", buf );
132 return (CV *) handler;
136 /* debugging routine to check for destruction of Perl interpreters */
138 void tst_clones(void)
141 PerlInterpreter *parent = PERL_GET_CONTEXT;
142 for (i = 0; i<5000; i++)
144 PerlInterpreter *perl_interp;
146 PERL_SET_CONTEXT(parent);
147 PL_perl_destruct_level = 2;
148 perl_interp = perl_clone(parent, CLONEf_CLONE_HOST);
149 PL_perl_destruct_level = 2;
150 PERL_SET_CONTEXT(perl_interp);
151 perl_destruct(perl_interp);
152 perl_free(perl_interp);
158 int simpleserver_clone(void) {
160 yaz_mutex_enter(simpleserver_mutex);
163 PerlInterpreter *current = PERL_GET_CONTEXT;
165 /* if current is unset, then we're in a new thread with
166 * no Perl interpreter for it. So we must create one .
167 * This will only happen when threaded is used..
170 PerlInterpreter *perl_interp;
171 PERL_SET_CONTEXT( root_perl_context );
172 perl_interp = perl_clone(root_perl_context, CLONEf_CLONE_HOST);
173 PERL_SET_CONTEXT( perl_interp );
176 yaz_mutex_leave(simpleserver_mutex);
182 void simpleserver_free(void) {
183 yaz_mutex_enter(simpleserver_mutex);
186 PerlInterpreter *current_interp = PERL_GET_CONTEXT;
188 /* If current Perl Interp is different from root interp, then
189 * we're in threaded mode and we must destroy..
191 if (current_interp != root_perl_context) {
192 PL_perl_destruct_level = 2;
193 PERL_SET_CONTEXT(current_interp);
194 perl_destruct(current_interp);
195 perl_free(current_interp);
198 yaz_mutex_leave(simpleserver_mutex);
202 Z_GenericRecord *read_grs1(char *str, ODR o)
205 char line[GRS_BUF_SIZE+1], *buf, *ptr, *original;
206 char value[GRS_BUF_SIZE+1];
207 Z_GenericRecord *r = 0;
210 r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r));
211 r->elements = (Z_TaggedElement **) odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS);
220 ptr = strchr(str, '\n');
225 if (len > GRS_BUF_SIZE) {
226 yaz_log(YLOG_WARN, "GRS string too long - truncating (%d > %d)", len, GRS_BUF_SIZE);
229 strncpy(line, str, len);
233 while (*buf && isspace(*buf))
236 memmove(original, str, strlen(str));
239 if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
241 yaz_log(YLOG_WARN, "Bad data in '%s'", buf);
244 if (!type && *value == '0')
246 if (!(buf = strchr(buf, ')')))
249 while (*buf && isspace(*buf))
251 if (r->num_elements >= GRS_MAX_FIELDS)
253 yaz_log(YLOG_WARN, "Max number of GRS-1 elements exceeded [GRS_MAX_FIELDS=%d]", GRS_MAX_FIELDS);
256 r->elements[r->num_elements] = t = (Z_TaggedElement *) odr_malloc(o, sizeof(Z_TaggedElement));
257 t->tagType = odr_intdup(o, type);
258 t->tagValue = (Z_StringOrNumeric *)
259 odr_malloc(o, sizeof(Z_StringOrNumeric));
260 if ((ivalue = atoi(value)))
262 t->tagValue->which = Z_StringOrNumeric_numeric;
263 t->tagValue->u.numeric = odr_intdup(o, ivalue);
267 t->tagValue->which = Z_StringOrNumeric_string;
268 t->tagValue->u.string = odr_strdup(o, value);
270 t->tagOccurrence = 0;
272 t->appliedVariant = 0;
273 t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData));
276 c->which = Z_ElementData_subtree;
277 c->u.subtree = read_grs1(str, o);
281 c->which = Z_ElementData_string;
282 c->u.string = odr_strdup(o, buf);
290 static void oid2str(Odr_oid *o, WRBUF buf)
292 for (; *o >= 0; o++) {
294 sprintf(ibuf, "%d", *o);
295 wrbuf_puts(buf, ibuf);
297 wrbuf_putc(buf, '.');
301 WRBUF oid2dotted(Odr_oid *oid)
303 WRBUF buf = wrbuf_alloc();
309 WRBUF zquery2pquery(Z_Query *q)
311 WRBUF buf = wrbuf_alloc();
313 if (q->which != Z_Query_type_1 && q->which != Z_Query_type_101)
315 yaz_rpnquery_to_wrbuf(buf, q->u.type_1);
320 /* Lifted verbatim from Net::Z3950 yazwrap/util.c */
322 void fatal(char *fmt, ...)
326 fprintf(stderr, "FATAL (SimpleServer): ");
328 vfprintf(stderr, fmt, ap);
330 fprintf(stderr, "\n");
335 /* Lifted verbatim from Net::Z3950 yazwrap/receive.c */
337 * Creates a new Perl object of type `class'; the newly-created scalar
338 * that is a reference to the blessed thingy `referent' is returned.
340 static SV *newObject(char *class, SV *referent)
345 sv = newRV_noinc((SV*) referent);
346 stash = gv_stashpv(class, 0);
348 fatal("attempt to create object of undefined class '%s'", class);
349 /*assert(stash != 0);*/
355 /* Lifted verbatim from Net::Z3950 yazwrap/receive.c */
356 static void setMember(HV *hv, char *name, SV *val)
358 /* We don't increment `val's reference count -- I think this is
359 * right because it's created with a refcount of 1, and in fact
360 * the reference via this hash is the only reference to it in
363 if (!hv_store(hv, name, (U32) strlen(name), val, (U32) 0))
364 fatal("couldn't store member in hash");
368 /* Lifted verbatim from Net::Z3950 yazwrap/receive.c */
369 static SV *translateOID(Odr_oid *x)
371 /* Yaz represents an OID by an int array terminated by a negative
372 * value, typically -1; we represent it as a reference to a
373 * blessed scalar string of "."-separated elements.
379 for (i = 0; x[i] >= 0; i++) {
380 sprintf(buf + strlen(buf), "%d", (int) x[i]);
386 * ### We'd like to return a blessed scalar (string) here, but of
387 * course you can't do that in Perl: only references can be
388 * blessed, so we'd have to return a _reference_ to a string, and
389 * bless _that_. Better to do without the blessing, I think.
392 return newSVpv(buf, 0);
394 return newObject("Net::Z3950::APDU::OID", newSVpv(buf, 0));
398 static SV *attributes2perl(Z_AttributeList *list)
402 SV *attrs = newObject("Net::Z3950::RPN::Attributes",
403 (SV*) (av = newAV()));
404 for (i = 0; i < list->num_attributes; i++) {
405 Z_AttributeElement *elem = list->attributes[i];
407 SV *tmp = newObject("Net::Z3950::RPN::Attribute",
408 (SV*) (hv2 = newHV()));
409 if (elem->attributeSet)
410 setMember(hv2, "attributeSet",
411 translateOID(elem->attributeSet));
412 setMember(hv2, "attributeType",
413 newSViv(*elem->attributeType));
414 if (elem->which == Z_AttributeValue_numeric) {
415 setMember(hv2, "attributeValue",
416 newSViv(*elem->value.numeric));
418 Z_ComplexAttribute *c;
419 Z_StringOrNumeric *son;
420 assert(elem->which == Z_AttributeValue_complex);
421 c = elem->value.complex;
422 /* We ignore semantic actions and multiple values */
423 assert(c->num_list > 0);
425 if (son->which == Z_StringOrNumeric_numeric) {
426 setMember(hv2, "attributeValue",
427 newSViv(*son->u.numeric));
428 } else { /*Z_StringOrNumeric_string*/
429 setMember(hv2, "attributeValue",
430 newSVpv(son->u.string, 0));
438 static SV *f_Term_to_SV(Z_Term *term, Z_AttributeList *attributes)
441 SV *sv = newObject("Net::Z3950::RPN::Term", (SV*) (hv = newHV()));
443 if (term->which != Z_Term_general)
444 fatal("can't handle RPN terms other than general");
446 setMember(hv, "term", newSVpv((char*) term->u.general->buf,
447 term->u.general->len));
450 setMember(hv, "attributes", attributes2perl(attributes));
455 static SV *rpn2perl(Z_RPNStructure *s)
463 case Z_RPNStructure_simple:
466 case Z_Operand_resultSetId: {
467 /* This code causes a SIGBUS on my machine, and I have no
468 idea why. It seems as clear as day to me */
470 char *rsid = (char*) o->u.resultSetId;
471 /*printf("Encoding resultSetId '%s'\n", rsid);*/
472 sv = newObject("Net::Z3950::RPN::RSID", (SV*) (hv = newHV()));
473 /*printf("Made sv=0x%lx, hv=0x%lx\n", (unsigned long) sv ,(unsigned long) hv);*/
474 sv2 = newSVpv(rsid, strlen(rsid));
475 setMember(hv, "id", sv2);
476 /*printf("Set hv{id} to 0x%lx\n", (unsigned long) sv2);*/
481 return f_Term_to_SV(o->u.attributesPlusTerm->term,
482 o->u.attributesPlusTerm->attributes);
484 fatal("unknown RPN simple type %d", (int) o->which);
487 case Z_RPNStructure_complex: {
489 Z_Complex *c = s->u.complex;
490 char *type = 0; /* vacuous assignment satisfies gcc -Wall */
491 switch (c->roperator->which) {
492 case Z_Operator_and: type = "Net::Z3950::RPN::And"; break;
493 case Z_Operator_or: type = "Net::Z3950::RPN::Or"; break;
494 case Z_Operator_and_not: type = "Net::Z3950::RPN::AndNot"; break;
495 case Z_Operator_prox: fatal("proximity not yet supported");
496 default: fatal("unknown RPN operator %d", (int) c->roperator->which);
498 sv = newObject(type, (SV*) (av = newAV()));
499 if ((tmp = rpn2perl(c->s1)) == 0)
502 if ((tmp = rpn2perl(c->s2)) == 0)
509 fatal("unknown RPN node type %d", (int) s->which);
516 /* Decode the Z_SortAttributes struct and store the whole thing into the
519 int simpleserver_ExpandSortAttributes (HV *sort_spec, Z_SortAttributes *sattr)
521 WRBUF attrset_wr = wrbuf_alloc();
523 Z_AttributeList *attr_list = sattr->list;
526 oid2str(sattr->id, attrset_wr);
527 hv_store(sort_spec, "ATTRSET", 7,
528 newSVpv(attrset_wr->buf, attrset_wr->pos), 0);
529 wrbuf_destroy(attrset_wr);
531 hv_store(sort_spec, "SORT_ATTR", 9, newRV( sv_2mortal( (SV*) list ) ), 0);
533 for (i = 0; i < attr_list->num_attributes; i++)
535 Z_AttributeElement *attr = *attr_list->attributes++;
536 HV *attr_spec = newHV();
538 av_push(list, newRV( sv_2mortal( (SV*) attr_spec ) ));
539 hv_store(attr_spec, "ATTR_TYPE", 9, newSViv(*attr->attributeType), 0);
541 if (attr->which == Z_AttributeValue_numeric)
543 hv_store(attr_spec, "ATTR_VALUE", 10,
544 newSViv(*attr->value.numeric), 0);
554 /* Decode the Z_SortKeySpec struct and store the whole thing in a perl hash */
555 int simpleserver_SortKeySpecToHash (HV *sort_spec, Z_SortKeySpec *spec)
557 Z_SortElement *element = spec->sortElement;
559 hv_store(sort_spec, "RELATION", 8, newSViv(*spec->sortRelation), 0);
560 hv_store(sort_spec, "CASE", 4, newSViv(*spec->caseSensitivity), 0);
561 hv_store(sort_spec, "MISSING", 7, newSViv(spec->which), 0);
563 if (element->which == Z_SortElement_generic)
565 Z_SortKey *key = element->u.generic;
567 if (key->which == Z_SortKey_sortField)
569 hv_store(sort_spec, "SORTFIELD", 9,
570 newSVpv((char *) key->u.sortField, 0), 0);
572 else if (key->which == Z_SortKey_elementSpec)
574 Z_Specification *zspec = key->u.elementSpec;
576 hv_store(sort_spec, "ELEMENTSPEC_TYPE", 16,
577 newSViv(zspec->which), 0);
579 if (zspec->which == Z_Schema_oid)
581 WRBUF elementSpec = wrbuf_alloc();
583 oid2str(zspec->schema.oid, elementSpec);
584 hv_store(sort_spec, "ELEMENTSPEC_VALUE", 17,
585 newSVpv(elementSpec->buf, elementSpec->pos), 0);
586 wrbuf_destroy(elementSpec);
588 else if (zspec->which == Z_Schema_uri)
590 hv_store(sort_spec, "ELEMENTSPEC_VALUE", 17,
591 newSVpv((char *) zspec->schema.uri, 0), 0);
594 else if (key->which == Z_SortKey_sortAttributes)
596 return simpleserver_ExpandSortAttributes(sort_spec,
597 key->u.sortAttributes);
613 static SV *zquery2perl(Z_Query *q)
618 if (q->which != Z_Query_type_1 && q->which != Z_Query_type_101)
620 sv = newObject("Net::Z3950::APDU::Query", (SV*) (hv = newHV()));
621 if (q->u.type_1->attributeSetId)
622 setMember(hv, "attributeSet",
623 translateOID(q->u.type_1->attributeSetId));
624 setMember(hv, "query", rpn2perl(q->u.type_1->RPNStructure));
629 int bend_sort(void *handle, bend_sort_rr *rr)
642 char **input_setnames;
643 Zfront_handle *zhandle = (Zfront_handle *)handle;
644 Z_SortKeySpecList *sort_spec = rr->sort_sequence;
652 input_setnames = rr->input_setnames;
653 for (i = 0; i < rr->num_input_setnames; i++)
655 av_push(aref, newSVpv(*input_setnames++, 0));
659 for (i = 0; i < sort_spec->num_specs; i++)
661 Z_SortKeySpec *spec = *sort_spec->specs++;
662 HV *sort_spec = newHV();
664 if ( simpleserver_SortKeySpecToHash(sort_spec, spec) )
665 av_push(sort_seq, newRV( sv_2mortal( (SV*) sort_spec ) ));
674 hv_store(href, "INPUT", 5, newRV( (SV*) aref), 0);
675 hv_store(href, "OUTPUT", 6, newSVpv(rr->output_setname, 0), 0);
676 hv_store(href, "SEQUENCE", 8, newRV( (SV*) sort_seq), 0);
677 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
678 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
679 hv_store(href, "STATUS", 6, newSViv(0), 0);
680 hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
681 hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
685 XPUSHs(sv_2mortal(newRV( (SV*) href)));
689 perl_call_sv(sort_ref, G_SCALAR | G_DISCARD);
693 temp = hv_fetch(href, "ERR_CODE", 8, 1);
694 err_code = newSVsv(*temp);
696 temp = hv_fetch(href, "ERR_STR", 7, 1);
697 err_str = newSVsv(*temp);
699 temp = hv_fetch(href, "STATUS", 6, 1);
700 status = newSVsv(*temp);
702 temp = hv_fetch(href, "HANDLE", 6, 1);
703 point = newSVsv(*temp);
709 sv_free( (SV*) aref);
710 sv_free( (SV*) href);
711 sv_free( (SV*) sort_seq);
713 rr->errcode = SvIV(err_code);
714 rr->sort_status = SvIV(status);
716 ptr = SvPV(err_str, len);
717 ODR_err_str = (char *)odr_malloc(rr->stream, len + 1);
718 strcpy(ODR_err_str, ptr);
719 rr->errstring = ODR_err_str;
720 zhandle->handle = point;
733 static SV *f_FacetField_to_SV(Z_FacetField *facet_field)
739 SV *sv = newObject("Net::Z3950::FacetField", (SV *) (hv = newHV()));
740 if (facet_field->attributes) {
741 setMember(hv, "attributes",
742 attributes2perl(facet_field->attributes));
744 terms = newObject("Net::Z3950::FacetTerms", (SV *) (av = newAV()));
746 for (i = 0; i < facet_field->num_terms; i++) {
747 SV *sv_count = newSViv(*facet_field->terms[i]->count);
748 SV *sv_term = f_Term_to_SV(facet_field->terms[i]->term, 0);
749 SV *tmp = newObject("Net::Z3950::FacetTerm", (SV *) (hv = newHV()));
751 setMember(hv, "count", sv_count);
752 setMember(hv, "term", sv_term);
756 setMember(hv, "terms", terms);
760 static SV *f_FacetList_to_SV(Z_FacetList *facet_list)
766 sv = newObject("Net::Z3950::FacetList", (SV *) (av = newAV()));
768 for (i = 0; i < facet_list->num; i++) {
769 SV *sv = f_FacetField_to_SV(facet_list->elements[i]);
777 static void f_SV_to_FacetField(HV *facet_field_hv, Z_FacetField **fl, ODR odr)
780 int num_terms, num_attributes;
782 Z_AttributeList *attributes = odr_malloc(odr, sizeof(*attributes));
784 AV *sv_terms, *sv_attributes;
785 printf("facet_field=%p\n", facet_field_hv);
787 temp = hv_fetch(facet_field_hv, "attributes", 10, 1);
788 sv_attributes = (AV *) SvRV(*temp);
789 num_attributes = av_len(sv_attributes) + 1;
790 printf(" attributes length=%d\n", num_attributes);
791 attributes->num_attributes = num_attributes;
792 attributes->attributes = (Z_AttributeElement **)
793 odr_malloc(odr, sizeof(*attributes->attributes) * num_attributes);
795 for (i = 0; i < num_attributes; i++) {
796 HV *hv_elem = (HV*) SvRV(sv_2mortal(av_shift(sv_attributes)));
797 Z_AttributeElement *elem;
798 elem = (Z_AttributeElement *) odr_malloc(odr, sizeof(*elem));
799 attributes->attributes[i] = elem;
801 elem->attributeSet = 0;
803 temp = hv_fetch(hv_elem, "attributeType", 13, 1);
804 elem->attributeType = odr_intdup(odr, SvIV(*temp));
806 temp = hv_fetch(hv_elem, "attributeValue", 14, 1);
809 elem->which = Z_AttributeValue_numeric;
810 elem->value.numeric = odr_intdup(odr, SvIV(*temp));
813 char *s_buf = SvPV(*temp, s_len);
814 Z_ComplexAttribute *c = odr_malloc(odr, sizeof *c);
815 elem->which = Z_AttributeValue_complex;
816 elem->value.complex = c;
819 c->list = (Z_StringOrNumeric **) odr_malloc(odr,
821 c->list[0] = (Z_StringOrNumeric *) odr_malloc(odr,
823 c->list[0]->which = Z_StringOrNumeric_string;
824 c->list[0]->u.string = odr_malloc(odr, s_len + 1);
825 memcpy(c->list[0]->u.string, s_buf, s_len);
826 c->list[0]->u.string[s_len] = '\0';
827 c->num_semanticAction = 0;
828 c->semanticAction = 0;
833 temp = hv_fetch(facet_field_hv, "terms", 5, 1);
834 sv_terms = (AV *) SvRV(*temp);
835 num_terms = av_len(sv_terms) + 1;
836 printf(" terms length=%d\n", num_terms);
837 *fl = facet_field_create(odr, attributes, num_terms);
838 for (i = 0; i < num_terms; i++) {
841 HV *hv_elem = (HV*) SvRV(sv_2mortal(av_shift(sv_terms)));
843 Z_FacetTerm *facet_term =
844 (Z_FacetTerm *) odr_malloc(odr, sizeof(*facet_term));
845 (*fl)->terms[i] = facet_term;
847 temp = hv_fetch(hv_elem, "count", 5, 1);
848 facet_term->count = odr_intdup(odr, SvIV(*temp));
852 temp = hv_fetch(hv_elem, "term", 4, 1);
854 s_buf = SvPV(*temp, s_len);
855 facet_term->term = z_Term_create(odr, Z_Term_general, s_buf, s_len);
861 static void f_SV_to_FacetList(SV *sv, Z_OtherInformation **oip, ODR odr)
863 AV *entries = (AV *) SvRV(sv);
865 if (SvTYPE(entries) == SVt_PVAV && (num_facets = av_len(entries) + 1) > 0)
868 Z_FacetList *facet_list = facet_list_create(odr, num_facets);
869 for (; i < num_facets; i++) {
870 HV *facet_field = (HV*) SvRV(sv_2mortal(av_shift(entries)));
871 f_SV_to_FacetField(facet_field, &facet_list->elements[i], odr);
873 hv_undef(facet_field);
875 Z_OtherInformation *oi = odr_malloc(odr, sizeof(*oi));
876 Z_OtherInformationUnit *oiu = odr_malloc(odr, sizeof(*oiu));
877 oi->num_elements = 1;
878 oi->list = odr_malloc(odr, oi->num_elements * sizeof(*oi->list));
880 oiu->which = Z_OtherInfo_externallyDefinedInfo;
881 oiu->information.externallyDefinedInfo = odr_malloc(odr, sizeof(*oiu->information.externallyDefinedInfo));
882 oiu->information.externallyDefinedInfo->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_facet_1);
883 oiu->information.externallyDefinedInfo->descriptor = 0;
884 oiu->information.externallyDefinedInfo->indirect_reference = 0;
885 oiu->information.externallyDefinedInfo->which = Z_External_userFacets;
886 oiu->information.externallyDefinedInfo->u.facetList = facet_list;
892 int bend_search(void *handle, bend_search_rr *rr)
901 Zfront_handle *zhandle = (Zfront_handle *)handle;
911 basenames = rr->basenames;
912 for (i = 0; i < rr->num_bases; i++)
914 av_push(aref, newSVpv(*basenames++, 0));
916 #if ENABLE_STOP_SERVER
917 if (rr->num_bases == 1 && !strcmp(rr->basenames[0], "XXstop"))
919 zhandle->stop_flag = 1;
923 hv_store(href, "SETNAME", 7, newSVpv(rr->setname, 0), 0);
924 if (rr->srw_sortKeys && *rr->srw_sortKeys)
925 hv_store(href, "SRW_SORTKEYS", 12, newSVpv(rr->srw_sortKeys, 0), 0);
926 hv_store(href, "REPL_SET", 8, newSViv(rr->replace_set), 0);
927 hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
928 hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
929 hv_store(href, "HITS", 4, newSViv(0), 0);
930 hv_store(href, "DATABASES", 9, newRV( (SV*) aref), 0);
931 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
932 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
933 hv_store(href, "PID", 3, newSViv(getpid()), 0);
934 if ((rpnSV = zquery2perl(rr->query)) != 0) {
935 hv_store(href, "RPN", 3, rpnSV, 0);
937 facetSV = f_FacetList_to_SV(yaz_oi_get_facetlist(&rr->search_input));
939 hv_store(href, "INPUTFACETS", 11, facetSV, 0);
942 query = zquery2pquery(rr->query);
945 hv_store(href, "QUERY", 5, newSVpv((char *)query->buf, query->pos), 0);
947 else if (rr->query->which == Z_Query_type_104 &&
948 rr->query->u.type_104->which == Z_External_CQL) {
949 hv_store(href, "CQL", 3,
950 newSVpv(rr->query->u.type_104->u.cql, 0), 0);
959 XPUSHs(sv_2mortal(newRV( (SV*) href)));
963 handler_cv = simpleserver_sv2cv( search_ref );
964 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
968 temp = hv_fetch(href, "HITS", 4, 1);
969 rr->hits = SvIV(*temp);
971 temp = hv_fetch(href, "ERR_CODE", 8, 1);
972 rr->errcode = SvIV(*temp);
974 temp = hv_fetch(href, "ERR_STR", 7, 1);
975 rr->errstring = string_or_undef(temp, rr->stream);
977 temp = hv_fetch(href, "HANDLE", 6, 1);
978 point = newSVsv(*temp);
980 temp = hv_fetch(href, "OUTPUTFACETS", 12, 1);
981 f_SV_to_FacetList(*temp, &rr->search_info, rr->stream);
986 zhandle->handle = point;
987 sv_free( (SV*) aref);
988 sv_free( (SV*) href);
990 wrbuf_destroy(query);
998 /* ### I am not 100% about the memory management in this handler */
999 int bend_delete(void *handle, bend_delete_rr *rr)
1001 Zfront_handle *zhandle = (Zfront_handle *)handle;
1013 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
1014 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
1015 hv_store(href, "STATUS", 6, newSViv(0), 0);
1018 XPUSHs(sv_2mortal(newRV( (SV*) href)));
1021 handler_cv = simpleserver_sv2cv(delete_ref);
1023 if (rr->function == 1) {
1024 /* Delete all result sets in the session */
1025 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
1026 temp = hv_fetch(href, "STATUS", 6, 1);
1027 rr->delete_status = SvIV(*temp);
1029 rr->delete_status = 0;
1031 * For some reason, deleting two or more result-sets in
1032 * one operation goes horribly wrong, and ### I don't have
1033 * time to debug it right now.
1035 if (rr->num_setnames > 1) {
1036 rr->delete_status = 3; /* "System problem at target" */
1037 /* There's no way to sent delete-msg using the GFS */
1041 for (i = 0; i < rr->num_setnames; i++) {
1042 hv_store(href, "SETNAME", 7, newSVpv(rr->setnames[i], 0), 0);
1043 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
1044 temp = hv_fetch(href, "STATUS", 6, 1);
1045 rr->statuses[i] = SvIV(*temp);
1046 if (rr->statuses[i] != 0)
1047 rr->delete_status = rr->statuses[i];
1053 temp = hv_fetch(href, "HANDLE", 6, 1);
1054 point = newSVsv(*temp);
1058 zhandle->handle = point;
1060 sv_free( (SV*) href);
1070 int bend_fetch(void *handle, bend_fetch_rr *rr)
1088 Zfront_handle *zhandle = (Zfront_handle *)handle;
1091 Z_RecordComposition *composition;
1092 Z_ElementSetNames *simple;
1093 Z_CompSpec *complex;
1102 hv_store(href, "SETNAME", 7, newSVpv(rr->setname, 0), 0);
1104 hv_store(href, "SCHEMA", 6, newSVpv(rr->schema, 0), 0);
1106 hv_store(href, "SCHEMA", 6, newSVpv("", 0), 0);
1108 temp = hv_store(href, "OFFSET", 6, newSViv(rr->number), 0);
1109 if (rr->request_format != 0) {
1110 oid_dotted = oid2dotted(rr->request_format);
1112 /* Probably an SRU request: assume XML is required */
1113 oid_dotted = wrbuf_alloc();
1114 wrbuf_puts(oid_dotted, "1.2.840.10003.5.109.10");
1116 hv_store(href, "REQ_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0);
1117 hv_store(href, "REP_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0);
1118 hv_store(href, "BASENAME", 8, newSVpv("", 0), 0);
1119 hv_store(href, "RECORD", 6, newSVpv("", 0), 0);
1120 hv_store(href, "LAST", 4, newSViv(0), 0);
1121 hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
1122 hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
1123 hv_store(href, "SUR_FLAG", 8, newSViv(0), 0);
1124 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
1125 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
1126 hv_store(href, "PID", 3, newSViv(getpid()), 0);
1129 composition = rr->comp;
1130 if (composition->which == Z_RecordComp_simple)
1132 simple = composition->u.simple;
1133 if (simple->which == Z_ElementSetNames_generic)
1135 hv_store(href, "COMP", 4, newSVpv(simple->u.generic, 0), 0);
1140 rr->errstring = odr_strdup(rr->stream, "non-generic 'simple' composition");
1144 else if (composition->which == Z_RecordComp_complex)
1146 if (composition->u.complex->generic &&
1148 composition->u.complex->generic &&
1149 composition->u.complex->generic->elementSpec &&
1150 composition->u.complex->generic->elementSpec->which ==
1151 Z_ElementSpec_elementSetName)
1153 complex = composition->u.complex;
1154 hv_store(href, "COMP", 4,
1155 newSVpv(complex->generic->elementSpec->u.elementSetName, 0), 0);
1159 #if 0 /* For now ignore this error, which is ubiquitous in SRU */
1161 rr->errstring = odr_strdup(rr->stream, "'complex' composition is not generic ESN");
1169 rr->errstring = odr_strdup(rr->stream, "composition neither simple nor complex");
1176 XPUSHs(sv_2mortal(newRV( (SV*) href)));
1180 handler_cv = simpleserver_sv2cv( fetch_ref );
1181 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
1185 temp = hv_fetch(href, "BASENAME", 8, 1);
1186 basename = newSVsv(*temp);
1188 temp = hv_fetch(href, "RECORD", 6, 1);
1189 record = newSVsv(*temp);
1191 temp = hv_fetch(href, "LAST", 4, 1);
1192 last = newSVsv(*temp);
1194 temp = hv_fetch(href, "ERR_CODE", 8, 1);
1195 err_code = newSVsv(*temp);
1197 temp = hv_fetch(href, "ERR_STR", 7, 1),
1198 err_string = newSVsv(*temp);
1200 temp = hv_fetch(href, "SUR_FLAG", 8, 1);
1201 sur_flag = newSVsv(*temp);
1203 temp = hv_fetch(href, "REP_FORM", 8, 1);
1204 rep_form = newSVsv(*temp);
1206 temp = hv_fetch(href, "SCHEMA", 6, 1);
1208 schema = newSVsv(*temp);
1209 ptr = SvPV(schema, length);
1211 rr->schema = (char *)odr_malloc(rr->stream, length + 1);
1212 strcpy(rr->schema, ptr);
1216 temp = hv_fetch(href, "HANDLE", 6, 1);
1217 point = newSVsv(*temp);
1222 ptr = SvPV(basename, length);
1223 ODR_basename = (char *)odr_malloc(rr->stream, length + 1);
1224 strcpy(ODR_basename, ptr);
1225 rr->basename = ODR_basename;
1227 ptr = SvPV(rep_form, length);
1229 rr->output_format = yaz_string_to_oid_odr(yaz_oid_std(),
1230 CLASS_RECSYN, ptr, rr->stream);
1231 if (!rr->output_format)
1233 printf("Net::Z3950::SimpleServer: WARNING: Bad OID %s\n", ptr);
1235 odr_oiddup(rr->stream, yaz_oid_recsyn_sutrs);
1237 ptr = SvPV(record, length);
1238 /* Treat GRS-1 records separately */
1239 if (!oid_oidcmp(rr->output_format, yaz_oid_recsyn_grs_1))
1241 rr->record = (char *) read_grs1(ptr, rr->stream);
1246 ODR_record = (char *)odr_malloc(rr->stream, length + 1);
1247 strcpy(ODR_record, ptr);
1248 rr->record = ODR_record;
1251 zhandle->handle = point;
1253 rr->last_in_set = SvIV(last);
1257 rr->errcode = SvIV(err_code);
1258 ptr = SvPV(err_string, length);
1259 ODR_errstr = (char *)odr_malloc(rr->stream, length + 1);
1260 strcpy(ODR_errstr, ptr);
1261 rr->errstring = ODR_errstr;
1263 rr->surrogate_flag = SvIV(sur_flag);
1265 wrbuf_destroy(oid_dotted);
1266 sv_free((SV*) href);
1270 sv_free(err_string);
1286 int bend_present(void *handle, bend_present_rr *rr)
1294 Z_RecordComposition *composition;
1295 Z_ElementSetNames *simple;
1296 Z_CompSpec *complex;
1299 Zfront_handle *zhandle = (Zfront_handle *)handle;
1302 /* WRBUF oid_dotted; */
1309 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
1310 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
1311 hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
1312 hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
1313 hv_store(href, "START", 5, newSViv(rr->start), 0);
1314 hv_store(href, "SETNAME", 7, newSVpv(rr->setname, 0), 0);
1315 hv_store(href, "NUMBER", 6, newSViv(rr->number), 0);
1316 /*oid_dotted = oid2dotted(rr->request_format_raw);
1317 hv_store(href, "REQ_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0);*/
1318 hv_store(href, "PID", 3, newSViv(getpid()), 0);
1321 composition = rr->comp;
1322 if (composition->which == Z_RecordComp_simple)
1324 simple = composition->u.simple;
1325 if (simple->which == Z_ElementSetNames_generic)
1327 hv_store(href, "COMP", 4, newSVpv(simple->u.generic, 0), 0);
1332 rr->errstring = odr_strdup(rr->stream, "non-generic 'simple' composition");
1336 else if (composition->which == Z_RecordComp_complex)
1338 if (composition->u.complex->generic &&
1340 composition->u.complex->generic &&
1341 composition->u.complex->generic->elementSpec &&
1342 composition->u.complex->generic->elementSpec->which ==
1343 Z_ElementSpec_elementSetName)
1345 complex = composition->u.complex;
1346 hv_store(href, "COMP", 4,
1347 newSVpv(complex->generic->elementSpec->u.elementSetName, 0), 0);
1352 rr->errstring = odr_strdup(rr->stream, "'complex' composition is not generic ESN");
1359 rr->errstring = odr_strdup(rr->stream, "composition neither simple nor complex");
1366 XPUSHs(sv_2mortal(newRV( (SV*) href)));
1370 handler_cv = simpleserver_sv2cv( present_ref );
1371 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
1375 temp = hv_fetch(href, "ERR_CODE", 8, 1);
1376 err_code = newSVsv(*temp);
1378 temp = hv_fetch(href, "ERR_STR", 7, 1);
1379 err_string = newSVsv(*temp);
1381 temp = hv_fetch(href, "HANDLE", 6, 1);
1382 point = newSVsv(*temp);
1389 rr->errcode = SvIV(err_code);
1391 ptr = SvPV(err_string, len);
1392 ODR_errstr = (char *)odr_malloc(rr->stream, len + 1);
1393 strcpy(ODR_errstr, ptr);
1394 rr->errstring = ODR_errstr;
1395 /* wrbuf_free(oid_dotted, 1);*/
1396 zhandle->handle = point;
1399 sv_free(err_string);
1400 sv_free( (SV*) href);
1406 int bend_esrequest(void *handle, bend_esrequest_rr *rr)
1408 perl_call_sv(esrequest_ref, G_VOID | G_DISCARD | G_NOARGS);
1413 int bend_scan(void *handle, bend_scan_rr *rr)
1420 struct scan_entry *scan_list;
1421 struct scan_entry *buffer;
1422 int *step_size = rr->step_size;
1426 SV *err_code = sv_newmortal();
1427 SV *err_str = sv_newmortal();
1428 SV *point = sv_newmortal();
1429 SV *status = sv_newmortal();
1430 SV *number = sv_newmortal();
1436 Zfront_handle *zhandle = (Zfront_handle *)handle;
1446 /* RPN is better than TERM since it includes attributes */
1447 if ((rpnSV = f_Term_to_SV(rr->term->term, rr->term->attributes)) != 0) {
1448 setMember(href, "RPN", rpnSV);
1451 if (rr->term->term->which == Z_Term_general)
1453 term_len = rr->term->term->u.general->len;
1454 hv_store(href, "TERM", 4, newSVpv((char*) rr->term->term->u.general->buf, term_len), 0);
1456 rr->errcode = 229; /* Unsupported term type */
1459 hv_store(href, "STEP", 4, newSViv(*step_size), 0);
1460 hv_store(href, "NUMBER", 6, newSViv(rr->num_entries), 0);
1461 hv_store(href, "POS", 3, newSViv(rr->term_position), 0);
1462 hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
1463 hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
1464 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
1465 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
1466 hv_store(href, "STATUS", 6, newSViv(BEND_SCAN_SUCCESS), 0);
1467 hv_store(href, "ENTRIES", 7, newRV((SV *) list), 0);
1469 basenames = rr->basenames;
1470 for (i = 0; i < rr->num_bases; i++)
1472 av_push(aref, newSVpv(*basenames++, 0));
1474 hv_store(href, "DATABASES", 9, newRV( (SV*) aref), 0);
1478 XPUSHs(sv_2mortal(newRV( (SV*) href)));
1482 handler_cv = simpleserver_sv2cv( scan_ref );
1483 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
1487 temp = hv_fetch(href, "ERR_CODE", 8, 1);
1488 err_code = newSVsv(*temp);
1490 temp = hv_fetch(href, "ERR_STR", 7, 1);
1491 err_str = newSVsv(*temp);
1493 temp = hv_fetch(href, "HANDLE", 6, 1);
1494 point = newSVsv(*temp);
1496 temp = hv_fetch(href, "STATUS", 6, 1);
1497 status = newSVsv(*temp);
1499 temp = hv_fetch(href, "NUMBER", 6, 1);
1500 number = newSVsv(*temp);
1502 temp = hv_fetch(href, "ENTRIES", 7, 1);
1503 entries_ref = newSVsv(*temp);
1509 ptr = SvPV(err_str, len);
1510 ODR_errstr = (char *)odr_malloc(rr->stream, len + 1);
1511 strcpy(ODR_errstr, ptr);
1512 rr->errstring = ODR_errstr;
1513 rr->errcode = SvIV(err_code);
1514 rr->num_entries = SvIV(number);
1515 rr->status = SvIV(status);
1516 scan_list = (struct scan_entry *) odr_malloc (rr->stream, rr->num_entries * sizeof(*scan_list));
1518 entries = (AV *)SvRV(entries_ref);
1519 if (rr->errcode == 0) for (i = 0; i < rr->num_entries; i++)
1521 scan_item = (HV *)SvRV(sv_2mortal(av_shift(entries)));
1522 temp = hv_fetch(scan_item, "TERM", 4, 1);
1523 ptr = SvPV(*temp, len);
1524 buffer->term = (char *) odr_malloc (rr->stream, len + 1);
1525 strcpy(buffer->term, ptr);
1526 temp = hv_fetch(scan_item, "OCCURRENCE", 10, 1);
1527 buffer->occurrences = SvIV(*temp);
1529 hv_undef(scan_item);
1531 rr->entries = scan_list;
1532 zhandle->handle = point;
1539 sv_free((SV *)href);
1541 sv_free((SV *)aref);
1543 sv_free((SV *)list);
1545 /*sv_free((SV *)entries);*/
1546 sv_free(entries_ref);
1551 int bend_explain(void *handle, bend_explain_rr *q)
1559 Zfront_handle *zhandle = (Zfront_handle *)handle;
1566 hv_store(href, "EXPLAIN", 7, newSVpv("", 0), 0);
1567 hv_store(href, "DATABASE", 8, newSVpv(q->database, 0), 0);
1568 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
1569 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
1572 XPUSHs(sv_2mortal(newRV((SV*) href)));
1575 handler_cv = simpleserver_sv2cv(explain_ref);
1576 perl_call_sv((SV*) handler_cv, G_SCALAR | G_DISCARD);
1580 temp = hv_fetch(href, "EXPLAIN", 7, 1);
1581 explainsv = newSVsv(*temp);
1587 explain = SvPV(explainsv, len);
1588 q->explain_buf = (char*) odr_malloc(q->stream, len + 1);
1589 strcpy(q->explain_buf, explain);
1596 * You'll laugh when I tell you this ... Astonishingly, it turns out
1597 * that ActivePerl (which is widely used on Windows) has, in the
1598 * header file Perl\lib\CORE\XSUB.h, the following heinous crime:
1599 * # define open PerlLIO_open
1600 * This of course screws up the use of the "open" member of the
1601 * Z_IdAuthentication structure below, so we have to undo this
1609 bend_initresult *bend_init(bend_initrequest *q)
1611 int dummy = simpleserver_clone();
1612 bend_initresult *r = (bend_initresult *)
1613 odr_malloc (q->stream, sizeof(*r));
1618 NMEM nmem = nmem_create();
1619 Zfront_handle *zhandle = (Zfront_handle *) nmem_malloc (nmem,
1628 zhandle->ghandle = _global_ghandle;
1629 zhandle->nmem = nmem;
1630 zhandle->stop_flag = 0;
1634 q->bend_sort = bend_sort;
1638 q->bend_search = bend_search;
1642 q->bend_present = bend_present;
1644 /*q->bend_esrequest = bend_esrequest;*/
1646 q->bend_delete = bend_delete;
1650 q->bend_fetch = bend_fetch;
1654 q->bend_scan = bend_scan;
1658 q->bend_explain = bend_explain;
1663 /* ### These should be given initial values from the client */
1664 hv_store(href, "IMP_ID", 6, newSVpv("", 0), 0);
1665 hv_store(href, "IMP_NAME", 8, newSVpv("", 0), 0);
1666 hv_store(href, "IMP_VER", 7, newSVpv("", 0), 0);
1668 hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
1669 hv_store(href, "ERR_STR", 7, newSViv(0), 0);
1670 hv_store(href, "PEER_NAME", 9, newSVpv(q->peer_name, 0), 0);
1671 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
1672 hv_store(href, "HANDLE", 6, newSVsv(&sv_undef), 0);
1673 hv_store(href, "PID", 3, newSViv(getpid()), 0);
1676 char *passwd = NULL;
1677 if (q->auth->which == Z_IdAuthentication_open) {
1679 user = nmem_strdup (odr_getmem (q->stream), q->auth->u.open);
1680 cp = strchr (user, '/');
1682 /* password after / given */
1686 } else if (q->auth->which == Z_IdAuthentication_idPass) {
1687 user = q->auth->u.idPass->userId;
1688 passwd = q->auth->u.idPass->password;
1690 /* ### some code paths have user/password unassigned here */
1692 hv_store(href, "USER", 4, newSVpv(user, 0), 0);
1694 hv_store(href, "PASS", 4, newSVpv(passwd, 0), 0);
1699 XPUSHs(sv_2mortal(newRV((SV*) href)));
1703 if (init_ref != NULL)
1705 handler_cv = simpleserver_sv2cv( init_ref );
1706 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
1711 temp = hv_fetch(href, "IMP_ID", 6, 1);
1712 ptr = SvPV(*temp, len);
1713 q->implementation_id = nmem_strdup(nmem, ptr);
1715 temp = hv_fetch(href, "IMP_NAME", 8, 1);
1716 ptr = SvPV(*temp, len);
1717 q->implementation_name = nmem_strdup(nmem, ptr);
1719 temp = hv_fetch(href, "IMP_VER", 7, 1);
1720 ptr = SvPV(*temp, len);
1721 q->implementation_version = nmem_strdup(nmem, ptr);
1723 temp = hv_fetch(href, "ERR_CODE", 8, 1);
1724 r->errcode = SvIV(*temp);
1726 temp = hv_fetch(href, "ERR_STR", 7, 1);
1727 ptr = SvPV(*temp, len);
1728 r->errstring = (char *)odr_malloc(q->stream, len + 1);
1729 strcpy(r->errstring, ptr);
1731 temp = hv_fetch(href, "HANDLE", 6, 1);
1732 handle= newSVsv(*temp);
1733 zhandle->handle = handle;
1735 r->handle = zhandle;
1738 sv_free((SV*) href);
1747 void bend_close(void *handle)
1750 Zfront_handle *zhandle = (Zfront_handle *)handle;
1760 hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
1761 hv_store(href, "HANDLE", 6, zhandle->handle, 0);
1765 XPUSHs(sv_2mortal(newRV((SV *)href)));
1769 handler_cv = simpleserver_sv2cv( close_ref );
1770 perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
1774 sv_free((SV*) href);
1777 sv_free(zhandle->handle);
1781 stop_flag = zhandle->stop_flag;
1782 nmem_destroy(zhandle->nmem);
1783 simpleserver_free();
1791 MODULE = Net::Z3950::SimpleServer PACKAGE = Net::Z3950::SimpleServer
1800 _global_ghandle = newSVsv(arg);
1804 set_init_handler(arg)
1807 init_ref = newSVsv(arg);
1811 set_close_handler(arg)
1814 close_ref = newSVsv(arg);
1818 set_sort_handler(arg)
1821 sort_ref = newSVsv(arg);
1824 set_search_handler(arg)
1827 search_ref = newSVsv(arg);
1831 set_fetch_handler(arg)
1834 fetch_ref = newSVsv(arg);
1838 set_present_handler(arg)
1841 present_ref = newSVsv(arg);
1845 set_esrequest_handler(arg)
1848 esrequest_ref = newSVsv(arg);
1852 set_delete_handler(arg)
1855 delete_ref = newSVsv(arg);
1859 set_scan_handler(arg)
1862 scan_ref = newSVsv(arg);
1865 set_explain_handler(arg)
1868 explain_ref = newSVsv(arg);
1879 argv_buf = (char **)xmalloc((items + 1) * sizeof(char *));
1881 for (i = 0; i < items; i++)
1883 ptr = SvPV(ST(i), len);
1884 *argv_buf = (char *)xmalloc(len + 1);
1885 strcpy(*argv_buf++, ptr);
1888 root_perl_context = PERL_GET_CONTEXT;
1889 yaz_mutex_create(&simpleserver_mutex);
1891 /* only for debugging perl_clone .. */
1895 RETVAL = statserv_main(items, argv, bend_init, bend_close);
1903 RETVAL = BEND_SCAN_SUCCESS;
1910 RETVAL = BEND_SCAN_PARTIAL;
1921 ptr = SvPV(arg, len);
1922 yaz_log(YLOG_LOG, "%.*s", (int) len, ptr);
1925 yaz_diag_srw_to_bib1(srw_code)
1929 yaz_diag_bib1_to_srw(bib1_code)