#include <yaz/log.h>
#include <yaz/wrbuf.h>
#include <stdio.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++) {
hv_store(href, "HITS", 4, newSViv(0), 0);
hv_store(href, "DATABASES", 9, newRV( (SV*) aref), 0);
hv_store(href, "HANDLE", 6, zhandle->handle, 0);
+ hv_store(href, "PID", 3, newSViv(getpid()), 0);
query = zquery2pquery(rr->query);
if (query)
{
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;
hv_store(href, "ERR_STR", 7, newSVpv("", 0), 0);
hv_store(href, "SUR_FLAG", 8, newSViv(0), 0);
hv_store(href, "HANDLE", 6, zhandle->handle, 0);
+ hv_store(href, "PID", 3, newSViv(getpid()), 0);
if (rr->comp)
{
composition = rr->comp;
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);
/*oid_dotted = oid2dotted(rr->request_format_raw);
hv_store(href, "REQ_FORM", 8, newSVpv((char *)oid_dotted->buf, oid_dotted->pos), 0);*/
hv_store(href, "HITS", 4, newSViv(0), 0);
+ hv_store(href, "PID", 3, newSViv(getpid()), 0);
if (rr->comp)
{
composition = rr->comp;
hv_store(href, "ERR_CODE", 8, newSViv(0), 0);
hv_store(href, "PEER_NAME", 9, newSVpv(q->peer_name, 0), 0);
hv_store(href, "HANDLE", 6, newSVsv(&sv_undef), 0);
+ hv_store(href, "PID", 3, newSViv(getpid()), 0);
PUSHMARK(sp);
}
-#line 804 "SimpleServer.c"
+#line 907 "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 800 "SimpleServer.xs"
+#line 903 "SimpleServer.xs"
init_ref = newSVsv(arg);
-#line 814 "SimpleServer.c"
+#line 917 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_close_handler(arg)");
{
SV * arg = ST(0);
-#line 807 "SimpleServer.xs"
+#line 910 "SimpleServer.xs"
close_ref = newSVsv(arg);
-#line 828 "SimpleServer.c"
+#line 931 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_sort_handler(arg)");
{
SV * arg = ST(0);
-#line 814 "SimpleServer.xs"
+#line 917 "SimpleServer.xs"
sort_ref = newSVsv(arg);
-#line 842 "SimpleServer.c"
+#line 945 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_search_handler(arg)");
{
SV * arg = ST(0);
-#line 820 "SimpleServer.xs"
+#line 923 "SimpleServer.xs"
search_ref = newSVsv(arg);
-#line 856 "SimpleServer.c"
+#line 959 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_fetch_handler(arg)");
{
SV * arg = ST(0);
-#line 827 "SimpleServer.xs"
+#line 930 "SimpleServer.xs"
fetch_ref = newSVsv(arg);
-#line 870 "SimpleServer.c"
+#line 973 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_present_handler(arg)");
{
SV * arg = ST(0);
-#line 834 "SimpleServer.xs"
+#line 937 "SimpleServer.xs"
present_ref = newSVsv(arg);
-#line 884 "SimpleServer.c"
+#line 987 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_esrequest_handler(arg)");
{
SV * arg = ST(0);
-#line 841 "SimpleServer.xs"
+#line 944 "SimpleServer.xs"
esrequest_ref = newSVsv(arg);
-#line 898 "SimpleServer.c"
+#line 1001 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_delete_handler(arg)");
{
SV * arg = ST(0);
-#line 848 "SimpleServer.xs"
+#line 951 "SimpleServer.xs"
delete_ref = newSVsv(arg);
-#line 912 "SimpleServer.c"
+#line 1015 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
Perl_croak(aTHX_ "Usage: Net::Z3950::SimpleServer::set_scan_handler(arg)");
{
SV * arg = ST(0);
-#line 855 "SimpleServer.xs"
+#line 958 "SimpleServer.xs"
scan_ref = newSVsv(arg);
-#line 926 "SimpleServer.c"
+#line 1029 "SimpleServer.c"
}
XSRETURN_EMPTY;
}
{
dXSARGS;
{
-#line 861 "SimpleServer.xs"
+#line 964 "SimpleServer.xs"
char **argv;
char **argv_buf;
char *ptr;
int i;
STRLEN len;
-#line 941 "SimpleServer.c"
+#line 1044 "SimpleServer.c"
int RETVAL;
dXSTARG;
-#line 867 "SimpleServer.xs"
+#line 970 "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 956 "SimpleServer.c"
+#line 1059 "SimpleServer.c"
XSprePUSH; PUSHi((IV)RETVAL);
}
XSRETURN(1);