From 76c6d9aa7b7671681fdb7f85f68d45201c080899 Mon Sep 17 00:00:00 2001 From: "Anders S. Mortensen" Date: Fri, 8 Sep 2000 14:28:08 +0000 Subject: [PATCH 1/1] Removed LEN, and updated the documentation. --- Makefile | 8 +++--- SimpleServer.c | 85 ++++++++++++++++++++++++++++++++++--------------------- SimpleServer.pm | 63 ++++++++++++++++++++++++++++++----------- SimpleServer.xs | 39 ++++++++++++++++++------- ztest.pl | 1 - 5 files changed, 132 insertions(+), 64 deletions(-) diff --git a/Makefile b/Makefile index a69c411..a678b84 100644 --- a/Makefile +++ b/Makefile @@ -151,10 +151,10 @@ TO_INST_PM = OID.pm \ SimpleServer.pm \ ztest.pl -PM_TO_BLIB = SimpleServer.pm \ - $(INST_LIBDIR)/SimpleServer.pm \ - ztest.pl \ +PM_TO_BLIB = ztest.pl \ $(INST_LIBDIR)/ztest.pl \ + SimpleServer.pm \ + $(INST_LIBDIR)/SimpleServer.pm \ OID.pm \ $(INST_LIBDIR)/OID.pm @@ -491,7 +491,7 @@ realclean purge :: clean rm -rf $(INST_AUTODIR) $(INST_ARCHAUTODIR) rm -f $(INST_DYNAMIC) $(INST_BOOT) rm -f $(INST_STATIC) - rm -f $(INST_LIBDIR)/SimpleServer.pm $(INST_LIBDIR)/ztest.pl $(INST_LIBDIR)/OID.pm + rm -f $(INST_LIBDIR)/ztest.pl $(INST_LIBDIR)/SimpleServer.pm $(INST_LIBDIR)/OID.pm rm -rf Makefile Makefile.old diff --git a/SimpleServer.c b/SimpleServer.c index 80dd5c7..59608d7 100644 --- a/SimpleServer.c +++ b/SimpleServer.c @@ -7,6 +7,33 @@ */ #line 1 "SimpleServer.xs" +/* + * Copyright (c) 2000, Index Data. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The name of Index Data or the individual authors may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR + * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + + #include "EXTERN.h" #include "perl.h" #include "XSUB.h" @@ -310,7 +337,6 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) HV *href; SV **temp; SV *basename; - SV *len; SV *record; SV *last; SV *err_code; @@ -343,7 +369,6 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) hv_store(href, "REQ_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0); hv_store(href, "REP_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0); hv_store(href, "BASENAME", 8, newSVpv("", 0), 0); - hv_store(href, "LEN", 3, newSViv(0), 0); hv_store(href, "RECORD", 6, newSVpv("", 0), 0); hv_store(href, "LAST", 4, newSViv(0), 0); hv_store(href, "ERR_CODE", 8, newSViv(0), 0); @@ -353,7 +378,7 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) if (rr->comp) { composition = rr->comp; - if (composition->which == 1) + if (composition->which == Z_RecordComp_simple) { simple = composition->u.simple; if (simple->which == 1) @@ -384,9 +409,6 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) temp = hv_fetch(href, "BASENAME", 8, 1); basename = newSVsv(*temp); - temp = hv_fetch(href, "LEN", 3, 1); - len = newSVsv(*temp); - temp = hv_fetch(href, "RECORD", 6, 1); record = newSVsv(*temp); @@ -427,12 +449,11 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) } rr->output_format_raw = ODR_oid_buf; - rr->len = SvIV(len); - ptr = SvPV(record, length); ODR_record = (char *)odr_malloc(rr->stream, length + 1); strcpy(ODR_record, ptr); rr->record = ODR_record; + rr->len = length; zhandle->handle = point; handle = zhandle; @@ -448,11 +469,9 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) } rr->surrogate_flag = SvIV(sur_flag); - /*sv_free(point);*/ wrbuf_free(oid_dotted, 1); sv_free((SV*) href); sv_free(basename); - sv_free(len); sv_free(record); sv_free(last); sv_free(err_string); @@ -690,7 +709,7 @@ void bend_close(void *handle) } -#line 694 "SimpleServer.c" +#line 713 "SimpleServer.c" XS(XS_Net__Z3950__SimpleServer_set_init_handler) { dXSARGS; @@ -698,9 +717,9 @@ XS(XS_Net__Z3950__SimpleServer_set_init_handler) croak("Usage: Net::Z3950::SimpleServer::set_init_handler(arg)"); { SV * arg = ST(0); -#line 690 "SimpleServer.xs" +#line 709 "SimpleServer.xs" init_ref = newSVsv(arg); -#line 704 "SimpleServer.c" +#line 723 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -712,9 +731,9 @@ XS(XS_Net__Z3950__SimpleServer_set_close_handler) croak("Usage: Net::Z3950::SimpleServer::set_close_handler(arg)"); { SV * arg = ST(0); -#line 697 "SimpleServer.xs" +#line 716 "SimpleServer.xs" close_ref = newSVsv(arg); -#line 718 "SimpleServer.c" +#line 737 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -726,9 +745,9 @@ XS(XS_Net__Z3950__SimpleServer_set_sort_handler) croak("Usage: Net::Z3950::SimpleServer::set_sort_handler(arg)"); { SV * arg = ST(0); -#line 704 "SimpleServer.xs" +#line 723 "SimpleServer.xs" sort_ref = newSVsv(arg); -#line 732 "SimpleServer.c" +#line 751 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -740,9 +759,9 @@ XS(XS_Net__Z3950__SimpleServer_set_search_handler) croak("Usage: Net::Z3950::SimpleServer::set_search_handler(arg)"); { SV * arg = ST(0); -#line 710 "SimpleServer.xs" +#line 729 "SimpleServer.xs" search_ref = newSVsv(arg); -#line 746 "SimpleServer.c" +#line 765 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -754,9 +773,9 @@ XS(XS_Net__Z3950__SimpleServer_set_fetch_handler) croak("Usage: Net::Z3950::SimpleServer::set_fetch_handler(arg)"); { SV * arg = ST(0); -#line 717 "SimpleServer.xs" +#line 736 "SimpleServer.xs" fetch_ref = newSVsv(arg); -#line 760 "SimpleServer.c" +#line 779 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -768,9 +787,9 @@ XS(XS_Net__Z3950__SimpleServer_set_present_handler) croak("Usage: Net::Z3950::SimpleServer::set_present_handler(arg)"); { SV * arg = ST(0); -#line 724 "SimpleServer.xs" +#line 743 "SimpleServer.xs" present_ref = newSVsv(arg); -#line 774 "SimpleServer.c" +#line 793 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -782,9 +801,9 @@ XS(XS_Net__Z3950__SimpleServer_set_esrequest_handler) croak("Usage: Net::Z3950::SimpleServer::set_esrequest_handler(arg)"); { SV * arg = ST(0); -#line 731 "SimpleServer.xs" +#line 750 "SimpleServer.xs" esrequest_ref = newSVsv(arg); -#line 788 "SimpleServer.c" +#line 807 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -796,9 +815,9 @@ XS(XS_Net__Z3950__SimpleServer_set_delete_handler) croak("Usage: Net::Z3950::SimpleServer::set_delete_handler(arg)"); { SV * arg = ST(0); -#line 738 "SimpleServer.xs" +#line 757 "SimpleServer.xs" delete_ref = newSVsv(arg); -#line 802 "SimpleServer.c" +#line 821 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -810,9 +829,9 @@ XS(XS_Net__Z3950__SimpleServer_set_scan_handler) croak("Usage: Net::Z3950::SimpleServer::set_scan_handler(arg)"); { SV * arg = ST(0); -#line 745 "SimpleServer.xs" +#line 764 "SimpleServer.xs" scan_ref = newSVsv(arg); -#line 816 "SimpleServer.c" +#line 835 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -821,15 +840,15 @@ XS(XS_Net__Z3950__SimpleServer_start_server) { dXSARGS; { -#line 751 "SimpleServer.xs" +#line 770 "SimpleServer.xs" char **argv; char **argv_buf; char *ptr; int i; STRLEN len; -#line 831 "SimpleServer.c" +#line 850 "SimpleServer.c" int RETVAL; -#line 757 "SimpleServer.xs" +#line 776 "SimpleServer.xs" argv_buf = (char **)xmalloc((items + 1) * sizeof(char *)); argv = argv_buf; for (i = 0; i < items; i++) @@ -841,7 +860,7 @@ XS(XS_Net__Z3950__SimpleServer_start_server) *argv_buf = NULL; RETVAL = statserv_main(items, argv, bend_init, bend_close); -#line 845 "SimpleServer.c" +#line 864 "SimpleServer.c" ST(0) = sv_newmortal(); sv_setiv(ST(0), (IV)RETVAL); } diff --git a/SimpleServer.pm b/SimpleServer.pm index d62c45a..9dcfe5e 100644 --- a/SimpleServer.pm +++ b/SimpleServer.pm @@ -1,3 +1,30 @@ +## +## Copyright (c) 2000, Index Data. +## +## Permission to use, copy, modify, distribute, and sell this software and +## its documentation, in whole or in part, for any purpose, is hereby granted, +## provided that: +## +## 1. This copyright and permission notice appear in all copies of the +## software and its documentation. Notices of copyright or attribution +## which appear at the beginning of any file must remain unchanged. +## +## 2. The name of Index Data or the individual authors may not be used to +## endorse or promote products derived from this software without specific +## prior written permission. +## +## THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, +## EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY +## WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +## IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, +## INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES +## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR +## NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF +## LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +## OF THIS SOFTWARE. +## +## + package Net::Z3950::SimpleServer; use strict; @@ -68,11 +95,11 @@ __END__ =head1 NAME -Zfront - Simple Perl API for building Z39.50 servers. +Net::Z3950::SimpleServer - Simple Perl API for building Z39.50 servers. =head1 SYNOPSIS - use Zfront; + use Net::Z3950::SimpleServer; sub my_search_handler { my $args = shift; @@ -106,16 +133,19 @@ Zfront - Simple Perl API for building Z39.50 servers. ## Register custom event handlers: - Zfront::set_search_handler(\&my_search_handler); - Zfront::set_fetch_handler(\&my_fetch_handler); - + my $handle = Net::Z3950::SimpleServer->new({ + INIT => \&my_init_handler, + CLOSE => \&my_close_handler, + SEARCH => \&my_search_handler, + FETCH => \&my_fetch_handler + }); ## Launch server: - Zfront::start_server("mytestserver", @ARGV); + $handle->launch_server("ztest.pl", @ARGV); =head1 DESCRIPTION -The Zfront module is a tool for constructing Z39.50 "Information +The SimpleServer module is a tool for constructing Z39.50 "Information Retrieval" servers in Perl. The module is easy to use, but it does help to have an understanding of the Z39.50 query structure and the construction of structured retrieval records. @@ -156,17 +186,18 @@ the entries of these hashes are to be considered input and others output parameters. The Perl programmer specifies the event handles for the server by -means of the subroutines +means of the the SimpleServer object constructor - Zfront::set_init_handler(\&my_init_handler); - Zfront::set_search_handler(\&my_search_handler); - Zfront::set_fetch_handler(\&my_fetch_handler); - Zfront::set_close_handler(\&my_close_handler); + my $handle = Net::Z3950::SimpleServer->new({ + INIT => \&my_init_handler, + CLOSE => \&my_close_handler, + SEARCH => \&my_search_handler, + FETCH => \&my_fetch_handler }); -After each handle is declared, the server is launched by means of -the subroutine +After the custom event handles are declared, the server is launched +by means of the method - Zfront::start_server($script_name, @ARGV); + $handle->launch_server("MyServer.pl", @ARGV); Notice, the first argument should be the name of your server script (for logging purposes), while the rest of the arguments @@ -283,11 +314,11 @@ The parameters exchanged between the server and the fetch handler are SETNAME => "id" ## ID of the requested result set OFFSET => nnn ## Record offset number REQ_FORM => "USMARC" ## Client requested record format + COMP => "xyz" ## Formatting instructions ## Handler response: RECORD => "" ## Record string - LEN => 0 ## Length of record string BASENAME => "" ## Origin of returned record LAST => 0 ## Last record in set? ERR_CODE => 0 ## Error code diff --git a/SimpleServer.xs b/SimpleServer.xs index 7280768..7a0b17a 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -1,3 +1,30 @@ +/* + * Copyright (c) 2000, Index Data. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The name of Index Data or the individual authors may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR + * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + + #include "EXTERN.h" #include "perl.h" #include "XSUB.h" @@ -301,7 +328,6 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) HV *href; SV **temp; SV *basename; - SV *len; SV *record; SV *last; SV *err_code; @@ -334,7 +360,6 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) hv_store(href, "REQ_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0); hv_store(href, "REP_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0); hv_store(href, "BASENAME", 8, newSVpv("", 0), 0); - hv_store(href, "LEN", 3, newSViv(0), 0); hv_store(href, "RECORD", 6, newSVpv("", 0), 0); hv_store(href, "LAST", 4, newSViv(0), 0); hv_store(href, "ERR_CODE", 8, newSViv(0), 0); @@ -344,7 +369,7 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) if (rr->comp) { composition = rr->comp; - if (composition->which == 1) + if (composition->which == Z_RecordComp_simple) { simple = composition->u.simple; if (simple->which == 1) @@ -375,9 +400,6 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) temp = hv_fetch(href, "BASENAME", 8, 1); basename = newSVsv(*temp); - temp = hv_fetch(href, "LEN", 3, 1); - len = newSVsv(*temp); - temp = hv_fetch(href, "RECORD", 6, 1); record = newSVsv(*temp); @@ -418,12 +440,11 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) } rr->output_format_raw = ODR_oid_buf; - rr->len = SvIV(len); - ptr = SvPV(record, length); ODR_record = (char *)odr_malloc(rr->stream, length + 1); strcpy(ODR_record, ptr); rr->record = ODR_record; + rr->len = length; zhandle->handle = point; handle = zhandle; @@ -439,11 +460,9 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) } rr->surrogate_flag = SvIV(sur_flag); - /*sv_free(point);*/ wrbuf_free(oid_dotted, 1); sv_free((SV*) href); sv_free(basename); - sv_free(len); sv_free(record); sv_free(last); sv_free(err_string); diff --git a/ztest.pl b/ztest.pl index 5640d93..27446d4 100755 --- a/ztest.pl +++ b/ztest.pl @@ -106,7 +106,6 @@ sub my_fetch_handler { $hash->{Fetch} = "Fetch handler er besøgt"; ##$href->{RECORD} = "Overskrift Her kommer teksten"; $href->{RECORD} = "OverskriftDer var engang en mand"; - $href->{LEN} = 69; $href->{NUMBER} = 1; $href->{BASENAME} = "MS-Gud"; $href->{LAST} = 1; -- 1.7.10.4