* 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"
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
+#define GRS_MAX_FIELDS 50
#ifdef ASN_COMPILED
#include <yaz/ill.h>
#endif
SV *scan_ref = NULL;
int MAX_OID = 15;
+
+Z_GenericRecord *read_grs1(char *str, ODR o)
+{
+ int type, ivalue;
+ char line[512], *buf, *ptr, *original;
+ char value[512];
+ Z_GenericRecord *r = 0;
+
+ original = str;
+ for (;;)
+ {
+ Z_TaggedElement *t;
+ Z_ElementData *c;
+
+ ptr = strchr(str, '\n');
+ if (!ptr) {
+ return r;
+ }
+ strncpy(line, str, ptr - str);
+ line[ptr - str] = 0;
+ buf = line;
+ str = ptr + 1;
+ while (*buf && isspace(*buf))
+ buf++;
+ if (*buf == '}') {
+ memmove(original, str, strlen(str));
+ return r;
+ }
+ if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
+ {
+ yaz_log(LOG_WARN, "Bad data in '%s'", buf);
+ return 0;
+ }
+ if (!type && *value == '0')
+ return r;
+ if (!(buf = strchr(buf, ')')))
+ return 0;
+ buf++;
+ while (*buf && isspace(*buf))
+ buf++;
+ if (!*buf)
+ return 0;
+ if (!r)
+ {
+ r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r));
+ r->elements = (Z_TaggedElement **)
+ odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS);
+ r->num_elements = 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;
+ t->tagValue = (Z_StringOrNumeric *)
+ odr_malloc(o, sizeof(Z_StringOrNumeric));
+ if ((ivalue = atoi(value)))
+ {
+ t->tagValue->which = Z_StringOrNumeric_numeric;
+ t->tagValue->u.numeric = (int *)odr_malloc(o, sizeof(int));
+ *t->tagValue->u.numeric = ivalue;
+ }
+ else
+ {
+ t->tagValue->which = Z_StringOrNumeric_string;
+ t->tagValue->u.string = (char *)odr_malloc(o, strlen(value)+1);
+ strcpy(t->tagValue->u.string, value);
+ }
+ t->tagOccurrence = 0;
+ t->metaData = 0;
+ t->appliedVariant = 0;
+ t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData));
+ if (*buf == '{')
+ {
+ c->which = Z_ElementData_subtree;
+ c->u.subtree = read_grs1(str, o);
+ }
+ else
+ {
+ c->which = Z_ElementData_string;
+/* buf[strlen(buf)-1] = '\0';*/
+ buf[strlen(buf)] = '\0';
+ c->u.string = odr_strdup(o, buf);
+ }
+ r->num_elements++;
+ }
+}
+
+
+
+
static void oid2str(Odr_oid *o, WRBUF buf)
{
for (; *o >= 0; o++) {
char *ODR_basename;
char *ODR_errstr;
int *ODR_oid_buf;
+ oident *oid;
WRBUF oid_dotted;
Zfront_handle *zhandle = (Zfront_handle *)handle;
Z_RecordComposition *composition;
Z_ElementSetNames *simple;
STRLEN length;
- int oid;
dSP;
ENTER;
rr->output_format_raw = ODR_oid_buf;
ptr = SvPV(record, length);
- ODR_record = (char *)odr_malloc(rr->stream, length + 1);
- strcpy(ODR_record, ptr);
- rr->record = ODR_record;
- rr->len = length;
-
+ oid = oid_getentbyoid(ODR_oid_buf);
+ if (oid->value == VAL_GRS1) /* Treat GRS-1 records separately */
+ {
+ rr->record = (char *) read_grs1(ptr, rr->stream);
+ rr->len = -1;
+ }
+ else
+ {
+ 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;
rr->last_in_set = SvIV(last);
}
-#line 809 "SimpleServer.c"
+#line 912 "SimpleServer.c"
XS(XS_Net__Z3950__SimpleServer_set_init_handler)
{
dXSARGS;
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_init_handler(arg)");
{
SV * arg = ST(0);
-#line 805 "SimpleServer.xs"
+#line 908 "SimpleServer.xs"
init_ref = newSVsv(arg);
-#line 819 "SimpleServer.c"
+#line 922 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_close_handler(arg)");
{
SV * arg = ST(0);
-#line 812 "SimpleServer.xs"
+#line 915 "SimpleServer.xs"
close_ref = newSVsv(arg);
-#line 833 "SimpleServer.c"
+#line 936 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_sort_handler(arg)");
{
SV * arg = ST(0);
-#line 819 "SimpleServer.xs"
+#line 922 "SimpleServer.xs"
sort_ref = newSVsv(arg);
-#line 847 "SimpleServer.c"
+#line 950 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_search_handler(arg)");
{
SV * arg = ST(0);
-#line 825 "SimpleServer.xs"
+#line 928 "SimpleServer.xs"
search_ref = newSVsv(arg);
-#line 861 "SimpleServer.c"
+#line 964 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_fetch_handler(arg)");
{
SV * arg = ST(0);
-#line 832 "SimpleServer.xs"
+#line 935 "SimpleServer.xs"
fetch_ref = newSVsv(arg);
-#line 875 "SimpleServer.c"
+#line 978 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_present_handler(arg)");
{
SV * arg = ST(0);
-#line 839 "SimpleServer.xs"
+#line 942 "SimpleServer.xs"
present_ref = newSVsv(arg);
-#line 889 "SimpleServer.c"
+#line 992 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_esrequest_handler(arg)");
{
SV * arg = ST(0);
-#line 846 "SimpleServer.xs"
+#line 949 "SimpleServer.xs"
esrequest_ref = newSVsv(arg);
-#line 903 "SimpleServer.c"
+#line 1006 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_delete_handler(arg)");
{
SV * arg = ST(0);
-#line 853 "SimpleServer.xs"
+#line 956 "SimpleServer.xs"
delete_ref = newSVsv(arg);
-#line 917 "SimpleServer.c"
+#line 1020 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_scan_handler(arg)");
{
SV * arg = ST(0);
-#line 860 "SimpleServer.xs"
+#line 963 "SimpleServer.xs"
scan_ref = newSVsv(arg);
-#line 931 "SimpleServer.c"
+#line 1034 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
{
dXSARGS;
{
-#line 866 "SimpleServer.xs"
+#line 969 "SimpleServer.xs"
char **argv;
char **argv_buf;
char *ptr;
int i;
STRLEN len;
-#line 946 "SimpleServer.c"
+#line 1049 "SimpleServer.c"
int RETVAL;
dXSTARG;
-#line 872 "SimpleServer.xs"
+#line 975 "SimpleServer.xs"
argv_buf = (char **)xmalloc((items + 1) * sizeof(char *));
argv = argv_buf;
for (i = 0; i < items; i++)
*argv_buf = NULL;
RETVAL = statserv_main(items, argv, bend_init, bend_close);
-#line 961 "SimpleServer.c"
+#line 1064 "SimpleServer.c"
XSprePUSH; PUSHi((IV)RETVAL);
}
XSRETURN(1);