X-Git-Url: http://git.indexdata.com/?p=simpleserver-moved-to-github.git;a=blobdiff_plain;f=SimpleServer.xs;h=7146877db341de753361bb1c434cc3c7d36afe76;hp=0562cee724cb455f4ccbf057ea3bf1b9c2eb18fc;hb=4956f4b56e38c33e1f1dc81819112a9ab6551334;hpb=9e3ced13f26e2d144436abedd28f89a55d5bd172 diff --git a/SimpleServer.xs b/SimpleServer.xs index 0562cee..7146877 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -1,5 +1,5 @@ /* - * $Id: SimpleServer.xs,v 1.55 2006-12-22 12:27:19 sondberg Exp $ + * $Id: SimpleServer.xs,v 1.60 2007-04-17 20:26:58 adam Exp $ * ---------------------------------------------------------------------- * * Copyright (c) 2000-2004, Index Data. @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef WIN32 #else #include @@ -51,7 +52,7 @@ #define sv_undef PL_sv_undef #endif -NMEM_MUTEX simpleserver_mutex; +YAZ_MUTEX simpleserver_mutex; typedef struct { SV *handle; @@ -85,7 +86,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; @@ -129,7 +130,7 @@ void tst_clones(void) int simpleserver_clone(void) { #ifdef USE_ITHREADS - nmem_mutex_enter(simpleserver_mutex); + yaz_mutex_enter(simpleserver_mutex); if (1) { PerlInterpreter *current = PERL_GET_CONTEXT; @@ -145,14 +146,14 @@ int simpleserver_clone(void) { PERL_SET_CONTEXT( perl_interp ); } } - nmem_mutex_leave(simpleserver_mutex); + yaz_mutex_leave(simpleserver_mutex); #endif return 0; } void simpleserver_free(void) { - nmem_mutex_enter(simpleserver_mutex); + yaz_mutex_enter(simpleserver_mutex); if (1) { PerlInterpreter *current_interp = PERL_GET_CONTEXT; @@ -167,7 +168,7 @@ void simpleserver_free(void) { perl_free(current_interp); } } - nmem_mutex_leave(simpleserver_mutex); + yaz_mutex_leave(simpleserver_mutex); } @@ -262,7 +263,6 @@ Z_GenericRecord *read_grs1(char *str, ODR o) - static void oid2str(Odr_oid *o, WRBUF buf) { for (; *o >= 0; o++) { @@ -274,6 +274,13 @@ static void oid2str(Odr_oid *o, WRBUF buf) } } +WRBUF oid2dotted(int *oid) +{ + WRBUF buf = wrbuf_alloc(); + oid2str(oid, buf); + return buf; +} + WRBUF zquery2pquery(Z_Query *q) { @@ -461,7 +468,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); @@ -518,7 +525,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) { @@ -759,7 +766,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; @@ -767,71 +774,6 @@ int bend_search(void *handle, bend_search_rr *rr) } -/* ### this is worryingly similar to oid2str() */ -WRBUF oid2dotted(int *oid) -{ - - WRBUF buf = wrbuf_alloc(); - int dot = 0; - - for (; *oid != -1 ; oid++) - { - char ibuf[16]; - if (dot) - { - wrbuf_putc(buf, '.'); - } - else - { - dot = 1; - } - sprintf(ibuf, "%d", *oid); - wrbuf_puts(buf, ibuf); - } - return buf; -} - - -int dotted2oid(char *dotted, int *buffer) -{ - int *oid; - char ibuf[16]; - char *ptr; - int n = 0; - - ptr = ibuf; - oid = buffer; - while (*dotted) - { - if (*dotted == '.') - { - n++; - if (n == MAX_OID) /* Terminate if more than MAX_OID entries */ - { - *oid = -1; - return -1; - } - *ptr = 0; - sscanf(ibuf, "%d", oid++); - ptr = ibuf; - dotted++; - - } - else - { - *ptr++ = *dotted++; - } - } - if (n < MAX_OID) - { - *ptr = 0; - sscanf(ibuf, "%d", oid++); - } - *oid = -1; - return 0; -} - - int bend_fetch(void *handle, bend_fetch_rr *rr) { HV *href; @@ -850,7 +792,6 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) 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; @@ -870,8 +811,8 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) 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(); @@ -985,16 +926,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; @@ -1020,7 +962,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); @@ -1615,7 +1557,7 @@ start_server(...) } *argv_buf = NULL; root_perl_context = PERL_GET_CONTEXT; - nmem_mutex_create(&simpleserver_mutex); + yaz_mutex_create(&simpleserver_mutex); #if 0 /* only for debugging perl_clone .. */ tst_clones();