From: Anders S. Mortensen Date: Tue, 13 Mar 2001 14:19:28 +0000 (+0000) Subject: Added a modified version of ztest.pl called grs_test.pl, which shows how to X-Git-Tag: release.0.0.8.lau~63 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=9a63dcdf4759d7856d96d85e0d2276dcf9949b49;p=simpleserver-moved-to-github.git Added a modified version of ztest.pl called grs_test.pl, which shows how to implement support of GRS-1 record syntax. --- diff --git a/SimpleServer.c b/SimpleServer.c index c243259..8114689 100644 --- a/SimpleServer.c +++ b/SimpleServer.c @@ -33,6 +33,15 @@ * OF THIS SOFTWARE. */ +/*$Log: SimpleServer.c,v $ +/*Revision 1.8 2001-03-13 14:19:28 sondberg +/*Added a modified version of ztest.pl called grs_test.pl, which shows how to +/*implement support of GRS-1 record syntax. +/* +/*Revision 1.7 2001/03/13 14:17:15 sondberg +/*Added support for GRS-1. +/**/ + #include "EXTERN.h" #include "perl.h" @@ -903,7 +912,7 @@ void bend_close(void *handle) } -#line 907 "SimpleServer.c" +#line 912 "SimpleServer.c" XS(XS_Net__Z3950__SimpleServer_set_init_handler) { dXSARGS; @@ -911,9 +920,9 @@ XS(XS_Net__Z3950__SimpleServer_set_init_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_init_handler(arg)"); { SV * arg = ST(0); -#line 903 "SimpleServer.xs" +#line 908 "SimpleServer.xs" init_ref = newSVsv(arg); -#line 917 "SimpleServer.c" +#line 922 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -925,9 +934,9 @@ XS(XS_Net__Z3950__SimpleServer_set_close_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_close_handler(arg)"); { SV * arg = ST(0); -#line 910 "SimpleServer.xs" +#line 915 "SimpleServer.xs" close_ref = newSVsv(arg); -#line 931 "SimpleServer.c" +#line 936 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -939,9 +948,9 @@ XS(XS_Net__Z3950__SimpleServer_set_sort_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_sort_handler(arg)"); { SV * arg = ST(0); -#line 917 "SimpleServer.xs" +#line 922 "SimpleServer.xs" sort_ref = newSVsv(arg); -#line 945 "SimpleServer.c" +#line 950 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -953,9 +962,9 @@ XS(XS_Net__Z3950__SimpleServer_set_search_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_search_handler(arg)"); { SV * arg = ST(0); -#line 923 "SimpleServer.xs" +#line 928 "SimpleServer.xs" search_ref = newSVsv(arg); -#line 959 "SimpleServer.c" +#line 964 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -967,9 +976,9 @@ XS(XS_Net__Z3950__SimpleServer_set_fetch_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_fetch_handler(arg)"); { SV * arg = ST(0); -#line 930 "SimpleServer.xs" +#line 935 "SimpleServer.xs" fetch_ref = newSVsv(arg); -#line 973 "SimpleServer.c" +#line 978 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -981,9 +990,9 @@ XS(XS_Net__Z3950__SimpleServer_set_present_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_present_handler(arg)"); { SV * arg = ST(0); -#line 937 "SimpleServer.xs" +#line 942 "SimpleServer.xs" present_ref = newSVsv(arg); -#line 987 "SimpleServer.c" +#line 992 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -995,9 +1004,9 @@ XS(XS_Net__Z3950__SimpleServer_set_esrequest_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_esrequest_handler(arg)"); { SV * arg = ST(0); -#line 944 "SimpleServer.xs" +#line 949 "SimpleServer.xs" esrequest_ref = newSVsv(arg); -#line 1001 "SimpleServer.c" +#line 1006 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -1009,9 +1018,9 @@ XS(XS_Net__Z3950__SimpleServer_set_delete_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_delete_handler(arg)"); { SV * arg = ST(0); -#line 951 "SimpleServer.xs" +#line 956 "SimpleServer.xs" delete_ref = newSVsv(arg); -#line 1015 "SimpleServer.c" +#line 1020 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -1023,9 +1032,9 @@ XS(XS_Net__Z3950__SimpleServer_set_scan_handler) Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_scan_handler(arg)"); { SV * arg = ST(0); -#line 958 "SimpleServer.xs" +#line 963 "SimpleServer.xs" scan_ref = newSVsv(arg); -#line 1029 "SimpleServer.c" +#line 1034 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -1034,16 +1043,16 @@ XS(XS_Net__Z3950__SimpleServer_start_server) { dXSARGS; { -#line 964 "SimpleServer.xs" +#line 969 "SimpleServer.xs" char **argv; char **argv_buf; char *ptr; int i; STRLEN len; -#line 1044 "SimpleServer.c" +#line 1049 "SimpleServer.c" int RETVAL; dXSTARG; -#line 970 "SimpleServer.xs" +#line 975 "SimpleServer.xs" argv_buf = (char **)xmalloc((items + 1) * sizeof(char *)); argv = argv_buf; for (i = 0; i < items; i++) @@ -1055,7 +1064,7 @@ XS(XS_Net__Z3950__SimpleServer_start_server) *argv_buf = NULL; RETVAL = statserv_main(items, argv, bend_init, bend_close); -#line 1059 "SimpleServer.c" +#line 1064 "SimpleServer.c" XSprePUSH; PUSHi((IV)RETVAL); } XSRETURN(1); diff --git a/grs_test.pl b/grs_test.pl new file mode 100755 index 0000000..e6bfbf3 --- /dev/null +++ b/grs_test.pl @@ -0,0 +1,113 @@ +#!/usr/bin/perl -w + +use ExtUtils::testlib; +use Net::Z3950::SimpleServer; +use Net::Z3950::OID; +use Net::Z3950::GRS1; +use strict; + + +sub dump_hash { + my $href = shift; + my $key; + + foreach $key (keys %$href) { + printf("%10s => %s\n", $key, $href->{$key}); + } +} + + +sub my_init_handler { + my $args = shift; + my $session = {}; + + $args->{IMP_NAME} = "DemoServer"; + $args->{IMP_VER} = "3.14159"; + $args->{ERR_CODE} = 0; + $args->{HANDLE} = $session; +} + +sub my_search_handler { + my $args = shift; + my $data = [{ + name => "Peter Dornan", + title => "Spokesman", + collaboration => "ATLAS" + }, { + name => "Jorn Dines Hansen", + title => "Professor", + collaboration => "HERA-B" + }, { + name => "Alain Blondel", + title => "Head of coll.", + collaboration => "ALEPH" + }]; + + my $session = $args->{HANDLE}; + my $set_id = $args->{SETNAME}; + my @database_list = @{ $args->{DATABASES} }; + my $query = $args->{QUERY}; + my $hits = 3; + + print "------------------------------------------------------------\n"; + print "Processing query : $query\n"; + printf("Database set : %s\n", join(" ", @database_list)); + print "Setname : $set_id\n"; + print "------------------------------------------------------------\n"; + + $args->{HITS} = $hits; + $session->{$set_id} = $data; + $session->{__HITS} = $hits; +} + + +sub my_fetch_handler { + my $args = shift; + my $session = $args->{HANDLE}; + my $set_id = $args->{SETNAME}; + my $data = $session->{$set_id}; + my $offset = $args->{OFFSET}; + my $grs1 = new Net::Z3950::GRS1; + my $grs2 = new Net::Z3950::GRS1; + my $grs3 = new Net::Z3950::GRS1; + my $grs4 = new Net::Z3950::GRS1; + my $field; + my $record; + my $hits = $session->{__HITS}; + my $href = $data->[$offset - 1]; + + $args->{REP_FORM} = Net::Z3950::OID::grs1; + foreach $field (keys %$href) { + $grs1->AddElement(1, $field, &Net::Z3950::GRS1::ElementData::String, $href->{$field}); + } + $grs4->AddElement(4,1, &Net::Z3950::GRS1::ElementData::String, "Level 4"); + $grs4->AddElement(4,2, &Net::Z3950::GRS1::ElementData::String, "Lige et felt mere"); + $grs3->AddElement(3,1, &Net::Z3950::GRS1::ElementData::String, "Mit navn er Svend Gønge"); + $grs3->AddElement(3,1, &Net::Z3950::GRS1::ElementData::Subtree, $grs4); + $grs3->AddElement(3,1, &Net::Z3950::GRS1::ElementData::String, "Og det er bare dejligt"); + $grs2->AddElement(2,1, &Net::Z3950::GRS1::ElementData::Subtree, $grs3); + $grs2->AddElement(2,2, &Net::Z3950::GRS1::ElementData::String, "Underfelt"); + $grs1->AddElement(1, 'subfield', &Net::Z3950::GRS1::ElementData::Subtree, $grs2); + $grs1->AddElement(1, 10, &Net::Z3950::GRS1::ElementData::String, 'Imle bimle bumle'); + $grs1->Render(POOL => \$record); + $args->{RECORD} = $record; + if ($offset == $session->{__HITS}) { + $args->{LAST} = 1; + } +} + + +my $handler = Net::Z3950::SimpleServer->new({ + INIT => \&my_init_handler, + SEARCH => \&my_search_handler, + FETCH => \&my_fetch_handler }); + +$handler->launch_server("ztest.pl", @ARGV); + + +## $Log: grs_test.pl,v $ +## Revision 1.1 2001-03-13 14:19:28 sondberg +## Added a modified version of ztest.pl called grs_test.pl, which shows how to +## implement support of GRS-1 record syntax. +## +