From ab2ce62608c39f599a199ee62fe2a22127c0b251 Mon Sep 17 00:00:00 2001 From: "Anders S. Mortensen" Date: Mon, 21 May 2001 11:07:02 +0000 Subject: [PATCH] Extended maximum numbers of GRS-1 elements. Should be done dynamically. --- GRS1.pm | 25 +++++++++++++++++++----- Makefile | 5 ++++- SimpleServer.c | 57 ++++++++++++++++++++++++++++++------------------------- SimpleServer.xs | 12 ++++++++++-- 4 files changed, 65 insertions(+), 34 deletions(-) diff --git a/GRS1.pm b/GRS1.pm index 1561136..15a510e 100644 --- a/GRS1.pm +++ b/GRS1.pm @@ -16,9 +16,9 @@ sub new { bless $self, $class; if (defined($href) && ref($href) eq 'HASH') { if (!defined($map)) { - croak "Usage: new Net::Z3950::GRS1($href, $map);"; + croak 'Usage: new Net::Z3950::GRS1($href, $map);'; } - $self->Hash2grs($href); + $self->Hash2grs($href, $map); } return $self; @@ -30,25 +30,37 @@ sub Hash2grs { my $key; my $content; my $aref; + my $issue; $mapping = defined($mapping) ? $mapping : $self->{MAP}; + $self->{MAP} = $mapping; foreach $key (keys %$href) { $content = $href->{$key}; + next unless defined($content); if (!defined($aref = $mapping->{$key})) { print STDERR "Hash2grs: Unmapped key: '$key'\n"; next; } if (ref($content) eq 'HASH') { ## Subtree? - my $subtree = new Net::Z3950::GRS1($content); + my $subtree = new Net::Z3950::GRS1($content, $mapping); $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::Subtree, $subtree); - } elsif (ref($content) eq '') { ## Regular string? + } elsif (!ref($content)) { ## Regular string? $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::String, $content); + } elsif (ref($content) eq 'ARRAY') { + my $issues = new Net::Z3950::GRS1; + foreach $issue (@$content) { + my $entry = new Net::Z3950::GRS1($issue, $mapping); + $issues->AddElement(5, 1, &Net::Z3950::GRS1::ElementData::Subtree, $entry); + } + $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::Subtree, $issues); } else { print STDERR "Hash2grs: Unsupported content type\n"; next; } } } + + sub GetElementList { my $self = shift; @@ -344,7 +356,10 @@ Specification of the GRS-1 standard, for instance in the Z39.50 protocol specifi =cut #$Log: GRS1.pm,v $ -#Revision 1.4 2001-05-17 14:07:06 sondberg +#Revision 1.5 2001-05-21 11:07:02 sondberg +#Extended maximum numbers of GRS-1 elements. Should be done dynamically. +# +#Revision 1.4 2001/05/17 14:07:06 sondberg #Added some documentation. # #Revision 1.3 2001/05/17 13:43:04 sondberg diff --git a/Makefile b/Makefile index 0be2e5f..fa00ff6 100644 --- a/Makefile +++ b/Makefile @@ -158,12 +158,15 @@ TO_INST_PM = GRS1.pm \ OID.pm \ SimpleServer.pm \ grs_test.pl \ + hash2grs.pl \ ztest.pl PM_TO_BLIB = GRS1.pm \ $(INST_LIBDIR)/GRS1.pm \ ztest.pl \ $(INST_LIBDIR)/ztest.pl \ + hash2grs.pl \ + $(INST_LIBDIR)/hash2grs.pl \ OID.pm \ $(INST_LIBDIR)/OID.pm \ grs_test.pl \ @@ -510,7 +513,7 @@ realclean purge :: clean rm -rf $(INST_AUTODIR) $(INST_ARCHAUTODIR) rm -f $(INST_DYNAMIC) $(INST_BOOT) rm -f $(INST_STATIC) - rm -f $(INST_LIBDIR)/GRS1.pm $(INST_LIBDIR)/ztest.pl $(INST_LIBDIR)/OID.pm $(INST_LIBDIR)/grs_test.pl $(INST_LIBDIR)/SimpleServer.pm + rm -f $(INST_LIBDIR)/GRS1.pm $(INST_LIBDIR)/ztest.pl $(INST_LIBDIR)/hash2grs.pl $(INST_LIBDIR)/OID.pm $(INST_LIBDIR)/grs_test.pl $(INST_LIBDIR)/SimpleServer.pm rm -rf Makefile Makefile.old diff --git a/SimpleServer.c b/SimpleServer.c index 744501f..4b62b93 100644 --- a/SimpleServer.c +++ b/SimpleServer.c @@ -34,8 +34,8 @@ */ /*$Log: SimpleServer.c,v $ -/*Revision 1.9 2001-05-17 13:43:04 sondberg -/*Added method Hash2grs into GRS1 module. +/*Revision 1.10 2001-05-21 11:07:02 sondberg +/*Extended maximum numbers of GRS-1 elements. Should be done dynamically. /* /*Revision 1.7 2001/03/13 14:17:15 sondberg /*Added support for GRS-1. @@ -52,7 +52,7 @@ #include #include #include -#define GRS_MAX_FIELDS 50 +#define GRS_MAX_FIELDS 500 #ifdef ASN_COMPILED #include #endif @@ -134,6 +134,11 @@ Z_GenericRecord *read_grs1(char *str, ODR o) odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS); r->num_elements = 0; } + if (r->num_elements > GRS_MAX_FIELDS) + { + yaz_log(LOG_WARN, "Max number of GRS-1 elements exceeded [GRS_MAX_FIELDS=%d]", GRS_MAX_FIELDS); + exit(0); + } r->elements[r->num_elements] = t = (Z_TaggedElement *) odr_malloc(o, sizeof(Z_TaggedElement)); t->tagType = (int *)odr_malloc(o, sizeof(int)); *t->tagType = type; @@ -911,7 +916,7 @@ void bend_close(void *handle) } -#line 912 "SimpleServer.c" +#line 917 "SimpleServer.c" XS(XS_Net__Z3950__SimpleServer_set_init_handler) { dXSARGS; @@ -919,9 +924,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 908 "SimpleServer.xs" +#line 913 "SimpleServer.xs" init_ref = newSVsv(arg); -#line 922 "SimpleServer.c" +#line 927 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -933,9 +938,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 915 "SimpleServer.xs" +#line 920 "SimpleServer.xs" close_ref = newSVsv(arg); -#line 936 "SimpleServer.c" +#line 941 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -947,9 +952,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 922 "SimpleServer.xs" +#line 927 "SimpleServer.xs" sort_ref = newSVsv(arg); -#line 950 "SimpleServer.c" +#line 955 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -961,9 +966,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 928 "SimpleServer.xs" +#line 933 "SimpleServer.xs" search_ref = newSVsv(arg); -#line 964 "SimpleServer.c" +#line 969 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -975,9 +980,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 935 "SimpleServer.xs" +#line 940 "SimpleServer.xs" fetch_ref = newSVsv(arg); -#line 978 "SimpleServer.c" +#line 983 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -989,9 +994,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 942 "SimpleServer.xs" +#line 947 "SimpleServer.xs" present_ref = newSVsv(arg); -#line 992 "SimpleServer.c" +#line 997 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -1003,9 +1008,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 949 "SimpleServer.xs" +#line 954 "SimpleServer.xs" esrequest_ref = newSVsv(arg); -#line 1006 "SimpleServer.c" +#line 1011 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -1017,9 +1022,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 956 "SimpleServer.xs" +#line 961 "SimpleServer.xs" delete_ref = newSVsv(arg); -#line 1020 "SimpleServer.c" +#line 1025 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -1031,9 +1036,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 963 "SimpleServer.xs" +#line 968 "SimpleServer.xs" scan_ref = newSVsv(arg); -#line 1034 "SimpleServer.c" +#line 1039 "SimpleServer.c" } XSRETURN_EMPTY; } @@ -1042,16 +1047,16 @@ XS(XS_Net__Z3950__SimpleServer_start_server) { dXSARGS; { -#line 969 "SimpleServer.xs" +#line 974 "SimpleServer.xs" char **argv; char **argv_buf; char *ptr; int i; STRLEN len; -#line 1049 "SimpleServer.c" +#line 1054 "SimpleServer.c" int RETVAL; dXSTARG; -#line 975 "SimpleServer.xs" +#line 980 "SimpleServer.xs" argv_buf = (char **)xmalloc((items + 1) * sizeof(char *)); argv = argv_buf; for (i = 0; i < items; i++) @@ -1063,7 +1068,7 @@ XS(XS_Net__Z3950__SimpleServer_start_server) *argv_buf = NULL; RETVAL = statserv_main(items, argv, bend_init, bend_close); -#line 1064 "SimpleServer.c" +#line 1069 "SimpleServer.c" XSprePUSH; PUSHi((IV)RETVAL); } XSRETURN(1); diff --git a/SimpleServer.xs b/SimpleServer.xs index aa020fa..74d2281 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -25,7 +25,10 @@ */ /*$Log: SimpleServer.xs,v $ -/*Revision 1.7 2001-03-13 14:17:15 sondberg +/*Revision 1.8 2001-05-21 11:07:02 sondberg +/*Extended maximum numbers of GRS-1 elements. Should be done dynamically. +/* +/*Revision 1.7 2001/03/13 14:17:15 sondberg /*Added support for GRS-1. /**/ @@ -40,7 +43,7 @@ #include #include #include -#define GRS_MAX_FIELDS 50 +#define GRS_MAX_FIELDS 500 #ifdef ASN_COMPILED #include #endif @@ -122,6 +125,11 @@ Z_GenericRecord *read_grs1(char *str, ODR o) odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS); r->num_elements = 0; } + if (r->num_elements > GRS_MAX_FIELDS) + { + yaz_log(LOG_WARN, "Max number of GRS-1 elements exceeded [GRS_MAX_FIELDS=%d]", GRS_MAX_FIELDS); + exit(0); + } r->elements[r->num_elements] = t = (Z_TaggedElement *) odr_malloc(o, sizeof(Z_TaggedElement)); t->tagType = (int *)odr_malloc(o, sizeof(int)); *t->tagType = type; -- 1.7.10.4