X-Git-Url: http://git.indexdata.com/?p=simpleserver-moved-to-github.git;a=blobdiff_plain;f=SimpleServer.xs;h=b838b29e78d06424bf79e265b0371d17a872c66e;hp=f4f43566b13514f109cefc62d96b8d13578ecc53;hb=cd5a3539e5474438a71a66871d2a285cfd2f2510;hpb=60a0c4dbeddc69d23c1c8a2ab552dae2f96cb952 diff --git a/SimpleServer.xs b/SimpleServer.xs index f4f4356..b838b29 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -1,5 +1,5 @@ /* - * $Id: SimpleServer.xs,v 1.74 2007-08-20 15:36:13 mike Exp $ + * $Id: SimpleServer.xs,v 1.83 2008-09-02 15:16:34 mike Exp $ * ---------------------------------------------------------------------- * * Copyright (c) 2000-2004, Index Data. @@ -424,9 +424,10 @@ static SV *apt2perl(Z_AttributesPlusTerm *at) setMember(hv2, "attributeValue", newSViv(*elem->value.numeric)); } else { - assert(elem->which == Z_AttributeValue_complex); - Z_ComplexAttribute *c = elem->value.complex; + Z_ComplexAttribute *c; Z_StringOrNumeric *son; + assert(elem->which == Z_AttributeValue_complex); + c = elem->value.complex; /* We ignore semantic actions and multiple values */ assert(c->num_list > 0); son = c->list[0]; @@ -824,6 +825,78 @@ int bend_search(void *handle, bend_search_rr *rr) } +/* ### I am not 100% about the memory management in this handler */ +int bend_delete(void *handle, bend_delete_rr *rr) +{ + Zfront_handle *zhandle = (Zfront_handle *)handle; + HV *href; + CV* handler_cv; + int i; + SV **temp; + SV *point; + + dSP; + ENTER; + SAVETMPS; + + href = newHV(); + hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0); + hv_store(href, "HANDLE", 6, zhandle->handle, 0); + hv_store(href, "STATUS", 6, newSViv(0), 0); + + PUSHMARK(sp); + XPUSHs(sv_2mortal(newRV( (SV*) href))); + PUTBACK; + + handler_cv = simpleserver_sv2cv(delete_ref); + + if (rr->function == 1) { + /* Delete all result sets in the session */ + perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD); + temp = hv_fetch(href, "STATUS", 6, 1); + rr->delete_status = SvIV(*temp); + } else { + rr->delete_status = 0; + /* + * For some reason, deleting two or more result-sets in + * one operation goes horribly wrong, and ### I don't have + * time to debug it right now. + */ + if (rr->num_setnames > 1) { + rr->delete_status = 3; /* "System problem at target" */ + /* There's no way to sent delete-msg using the GFS */ + return 0; + } + + for (i = 0; i < rr->num_setnames; i++) { + hv_store(href, "SETNAME", 7, newSVpv(rr->setnames[i], 0), 0); + perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD); + temp = hv_fetch(href, "STATUS", 6, 1); + rr->statuses[i] = SvIV(*temp); + if (rr->statuses[i] != 0) + rr->delete_status = rr->statuses[i]; + } + } + + SPAGAIN; + + temp = hv_fetch(href, "HANDLE", 6, 1); + point = newSVsv(*temp); + + hv_undef(href); + + zhandle->handle = point; + + sv_free( (SV*) href); + + PUTBACK; + FREETMPS; + LEAVE; + + return 0; +} + + int bend_fetch(void *handle, bend_fetch_rr *rr) { HV *href; @@ -894,6 +967,8 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) else { rr->errcode = 26; + rr->errstring = odr_strdup(rr->stream, "non-generic 'simple' composition"); + return 0; } } else if (composition->which == Z_RecordComp_complex) @@ -912,8 +987,8 @@ 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; + rr->errstring = odr_strdup(rr->stream, "'complex' composition is not generic ESN"); return 0; #endif /*0*/ } @@ -921,6 +996,7 @@ int bend_fetch(void *handle, bend_fetch_rr *rr) else { rr->errcode = 26; + rr->errstring = odr_strdup(rr->stream, "composition neither simple nor complex"); return 0; } } @@ -1085,6 +1161,7 @@ int bend_present(void *handle, bend_present_rr *rr) else { rr->errcode = 26; + rr->errstring = odr_strdup(rr->stream, "non-generic 'simple' composition"); return 0; } } @@ -1104,12 +1181,14 @@ int bend_present(void *handle, bend_present_rr *rr) else { rr->errcode = 26; + rr->errstring = odr_strdup(rr->stream, "'complex' composition is not generic ESN"); return 0; } } else { rr->errcode = 26; + rr->errstring = odr_strdup(rr->stream, "composition neither simple nor complex"); return 0; } } @@ -1168,59 +1247,6 @@ int bend_esrequest(void *handle, bend_esrequest_rr *rr) } -/* ### I am not 100% about the memory management in this handler */ -int bend_delete(void *handle, bend_delete_rr *rr) -{ - Zfront_handle *zhandle = (Zfront_handle *)handle; - HV *href; - CV* handler_cv; - int i; - SV **temp; - - dSP; - ENTER; - SAVETMPS; - - href = newHV(); - hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0); - hv_store(href, "HANDLE", 6, zhandle->handle, 0); - hv_store(href, "STATUS", 6, newSViv(0), 0); - - PUSHMARK(sp); - XPUSHs(sv_2mortal(newRV( (SV*) href))); - PUTBACK; - - handler_cv = simpleserver_sv2cv(delete_ref); - - if (rr->function == 1) { - /* Delete all result setss in the session */ - perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD); - temp = hv_fetch(href, "STATUS", 6, 1); - rr->delete_status = SvIV(*temp); - } else { - rr->delete_status = 0; - for (i = 0; i < rr->num_setnames; i++) { - hv_store(href, "SETNAME", 7, newSVpv(rr->setnames[i], 0), 0); - perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD); - temp = hv_fetch(href, "STATUS", 6, 1); - rr->statuses[i] = SvIV(*temp); - if (rr->statuses[i] != 0) - rr->delete_status = rr->statuses[i]; - } - } - - SPAGAIN; - - sv_free( (SV*) href); - - PUTBACK; - FREETMPS; - LEAVE; - - return 0; -} - - int bend_scan(void *handle, bend_scan_rr *rr) { HV *href; @@ -1402,6 +1428,21 @@ int bend_explain(void *handle, bend_explain_rr *q) return 0; } + +/* + * You'll laugh when I tell you this ... Astonishingly, it turns out + * that ActivePerl (which is widely used on Windows) has, in the + * header file Perl\lib\CORE\XSUB.h, the following heinous crime: + * # define open PerlLIO_open + * This of course screws up the use of the "open" member of the + * Z_IdAuthentication structure below, so we have to undo this + * brain-damage. + */ +#ifdef open +#undef open +#endif + + bend_initresult *bend_init(bend_initrequest *q) { int dummy = simpleserver_clone(); @@ -1455,9 +1496,12 @@ bend_initresult *bend_init(bend_initrequest *q) } href = newHV(); + + /* ### These should be given initial values from the client */ hv_store(href, "IMP_ID", 6, newSVpv("", 0), 0); hv_store(href, "IMP_NAME", 8, newSVpv("", 0), 0); hv_store(href, "IMP_VER", 7, newSVpv("", 0), 0); + hv_store(href, "ERR_CODE", 8, newSViv(0), 0); hv_store(href, "ERR_STR", 7, newSViv(0), 0); hv_store(href, "PEER_NAME", 9, newSVpv(q->peer_name, 0), 0);