X-Git-Url: http://git.indexdata.com/?p=simpleserver-moved-to-github.git;a=blobdiff_plain;f=SimpleServer.xs;h=54d61f894297b577533d9739ce783523cd636e41;hp=012a3014135a320e6400a76942b27fb317db8f77;hb=3ee948d799b9207fd02662bcb66b1d8848da48f6;hpb=43dc6cc6daf84b2d8689b3e1ab85a1684a6ea913 diff --git a/SimpleServer.xs b/SimpleServer.xs index 012a301..54d61f8 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -1,5 +1,5 @@ /* - * $Id: SimpleServer.xs,v 1.48 2006-06-07 18:25:15 quinn Exp $ + * $Id: SimpleServer.xs,v 1.57 2007-04-17 07:55:02 adam Exp $ * ---------------------------------------------------------------------- * * Copyright (c) 2000-2004, Index Data. @@ -35,6 +35,7 @@ #include #include #include +#include #include #ifdef WIN32 #else @@ -84,7 +85,7 @@ SV *explain_ref = NULL; PerlInterpreter *root_perl_context; int MAX_OID = 15; -#define GRS_BUF_SIZE 512 +#define GRS_BUF_SIZE 8192 CV * simpleserver_sv2cv(SV *handler) { STRLEN len; @@ -194,7 +195,7 @@ Z_GenericRecord *read_grs1(char *str, ODR o) } len = ptr - str; if (len > GRS_BUF_SIZE) { - yaz_log(LOG_WARN, "GRS string too long - truncating (%d > %d)", len, GRS_BUF_SIZE); + yaz_log(YLOG_WARN, "GRS string too long - truncating (%d > %d)", len, GRS_BUF_SIZE); len = GRS_BUF_SIZE; } strncpy(line, str, len); @@ -209,7 +210,7 @@ Z_GenericRecord *read_grs1(char *str, ODR o) } if (sscanf(buf, "(%d,%[^)])", &type, value) != 2) { - yaz_log(LOG_WARN, "Bad data in '%s'", buf); + yaz_log(YLOG_WARN, "Bad data in '%s'", buf); return r; } if (!type && *value == '0') @@ -221,7 +222,7 @@ Z_GenericRecord *read_grs1(char *str, ODR o) buf++; 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); + yaz_log(YLOG_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)); @@ -460,7 +461,7 @@ int simpleserver_ExpandSortAttributes (HV *sort_spec, Z_SortAttributes *sattr) oid2str(sattr->id, attrset_wr); hv_store(sort_spec, "ATTRSET", 7, newSVpv(attrset_wr->buf, attrset_wr->pos), 0); - wrbuf_free(attrset_wr, 1); + wrbuf_destroy(attrset_wr); hv_store(sort_spec, "SORT_ATTR", 9, newRV( sv_2mortal( (SV*) list ) ), 0); @@ -517,7 +518,7 @@ int simpleserver_SortKeySpecToHash (HV *sort_spec, Z_SortKeySpec *spec) oid2str(zspec->schema.oid, elementSpec); hv_store(sort_spec, "ELEMENTSPEC_VALUE", 17, newSVpv(elementSpec->buf, elementSpec->pos), 0); - wrbuf_free(elementSpec, 1); + wrbuf_destroy(elementSpec); } else if (zspec->which == Z_Schema_uri) { @@ -758,7 +759,7 @@ int bend_search(void *handle, bend_search_rr *rr) sv_free( (SV*) aref); sv_free( (SV*) href); if (query) - wrbuf_free(query, 1); + wrbuf_destroy(query); PUTBACK; FREETMPS; LEAVE; @@ -843,12 +844,12 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) SV *sur_flag; SV *point; SV *rep_form; + SV *schema = 0; char *ptr; char *ODR_record; char *ODR_basename; char *ODR_errstr; int *ODR_oid_buf; - oident *oid; WRBUF oid_dotted; Zfront_handle *zhandle = (Zfront_handle *)handle; CV* handler_cv = 0; @@ -865,9 +866,11 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) rr->errcode = 0; href = newHV(); hv_store(href, "SETNAME", 7, newSVpv(rr->setname, 0), 0); + if (rr->schema) + hv_store(href, "SCHEMA", 6, newSVpv(rr->schema, 0), 0); temp = hv_store(href, "OFFSET", 6, newSViv(rr->number), 0); - if (rr->request_format_raw != 0) { - oid_dotted = oid2dotted(rr->request_format_raw); + if (rr->request_format != 0) { + oid_dotted = oid2dotted(rr->request_format); } else { /* Probably an SRU request: assume XML is required */ oid_dotted = wrbuf_alloc(); @@ -913,14 +916,17 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) } else { +#if 0 /* For now ignore this error, which is ubiquitous in SRU */ + fprintf(stderr, "complex is weird\n"); rr->errcode = 26; return 0; +#endif /*0*/ } } else { rr->errcode = 26; - return; + return 0; } } @@ -956,6 +962,16 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) temp = hv_fetch(href, "REP_FORM", 8, 1); rep_form = newSVsv(*temp); + temp = hv_fetch(href, "SCHEMA", 6, 1); + if (temp != 0) { + schema = newSVsv(*temp); + ptr = SvPV(schema, length); + if (length > 0) { + rr->schema = (char *)odr_malloc(rr->stream, length + 1); + strcpy(rr->schema, ptr); + } + } + temp = hv_fetch(href, "HANDLE", 6, 1); point = newSVsv(*temp); @@ -968,16 +984,17 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) rr->basename = ODR_basename; ptr = SvPV(rep_form, length); + ODR_oid_buf = (int *)odr_malloc(rr->stream, (MAX_OID + 1) * sizeof(int)); - if (dotted2oid(ptr, ODR_oid_buf) == -1) /* Maximum number of OID elements exceeded */ + if (oid_dotstring_to_oid(ptr, ODR_oid_buf)) { printf("Net::Z3950::SimpleServer: WARNING: OID structure too long, max length is %d\n", MAX_OID); } - rr->output_format_raw = ODR_oid_buf; + rr->output_format = ODR_oid_buf; ptr = SvPV(record, length); - oid = oid_getentbyoid(ODR_oid_buf); - if (oid->value == VAL_GRS1) /* Treat GRS-1 records separately */ + /* Treat GRS-1 records separately */ + if (!oid_oidcmp(ODR_oid_buf, yaz_oid_recsyn_grs_1)) { rr->record = (char *) read_grs1(ptr, rr->stream); rr->len = -1; @@ -1003,7 +1020,7 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) } rr->surrogate_flag = SvIV(sur_flag); - wrbuf_free(oid_dotted, 1); + wrbuf_destroy(oid_dotted); sv_free((SV*) href); sv_free(basename); sv_free(record); @@ -1013,6 +1030,9 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) sv_free(sur_flag); sv_free(rep_form); + if (schema) + sv_free(schema); + PUTBACK; FREETMPS; LEAVE; @@ -1093,7 +1113,7 @@ int bend_present(void *handle, bend_present_rr *rr) else { rr->errcode = 26; - return; + return 0; } } @@ -1192,7 +1212,7 @@ int bend_scan(void *handle, bend_scan_rr *rr) if (rr->term->term->which == Z_Term_general) { term_len = rr->term->term->u.general->len; - hv_store(href, "TERM", 4, newSVpv(rr->term->term->u.general->buf, term_len), 0); + hv_store(href, "TERM", 4, newSVpv((char*) rr->term->term->u.general->buf, term_len), 0); } else { rr->errcode = 229; /* Unsupported term type */ return 0;