X-Git-Url: http://git.indexdata.com/?p=simpleserver-moved-to-github.git;a=blobdiff_plain;f=SimpleServer.xs;h=e83f47b2aa62b9d8f43defa48037a89442657b00;hp=dfa4bf9f4abb4ae7a9a396e2fc92afa6aa12f39e;hb=cdc764afd8ddc92658f972fdccfa3349be97d403;hpb=895c753fdac64b0d288a7edf5cab1b816e92c6ee diff --git a/SimpleServer.xs b/SimpleServer.xs index dfa4bf9..e83f47b 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -1,30 +1,28 @@ -/* - * $Id: SimpleServer.xs,v 1.76 2007-08-20 21:27:50 mike Exp $ - * ---------------------------------------------------------------------- - * - * Copyright (c) 2000-2004, Index Data. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation, in whole or in part, for any purpose, is hereby granted, - * provided that: - * - * 1. This copyright and permission notice appear in all copies of the - * software and its documentation. Notices of copyright or attribution - * which appear at the beginning of any file must remain unchanged. +/* This file is part of simpleserver. + * Copyright (C) 2000-2011 Index Data. + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * 2. The name of Index Data or the individual authors may not be used to - * endorse or promote products derived from this software without specific - * prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Index Data nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR - * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "EXTERN.h" @@ -424,9 +422,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]; @@ -864,7 +863,7 @@ int bend_delete(void *handle, bend_delete_rr *rr) 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; + return 0; } for (i = 0; i < rr->num_setnames; i++) { @@ -966,6 +965,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) @@ -984,8 +985,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*/ } @@ -993,6 +994,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; } } @@ -1115,7 +1117,6 @@ int bend_present(void *handle, bend_present_rr *rr) SV **temp; SV *err_code; SV *err_string; - SV *hits; SV *point; STRLEN len; Z_RecordComposition *composition; @@ -1142,7 +1143,6 @@ int bend_present(void *handle, bend_present_rr *rr) hv_store(href, "NUMBER", 6, newSViv(rr->number), 0); /*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) { @@ -1157,6 +1157,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; } } @@ -1176,12 +1177,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; } } @@ -1203,9 +1206,6 @@ int bend_present(void *handle, bend_present_rr *rr) temp = hv_fetch(href, "ERR_STR", 7, 1); err_string = newSVsv(*temp); - temp = hv_fetch(href, "HITS", 4, 1); - hits = newSVsv(*temp); - temp = hv_fetch(href, "HANDLE", 6, 1); point = newSVsv(*temp); @@ -1215,7 +1215,6 @@ int bend_present(void *handle, bend_present_rr *rr) hv_undef(href); rr->errcode = SvIV(err_code); - rr->hits = SvIV(hits); ptr = SvPV(err_string, len); ODR_errstr = (char *)odr_malloc(rr->stream, len + 1); @@ -1226,7 +1225,6 @@ int bend_present(void *handle, bend_present_rr *rr) handle = zhandle; sv_free(err_code); sv_free(err_string); - sv_free(hits); sv_free( (SV*) href); return 0; @@ -1421,6 +1419,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(); @@ -1474,9 +1487,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); @@ -1731,7 +1747,7 @@ yazlog(arg) STRLEN len; char *ptr; ptr = SvPV(arg, len); - yaz_log(YLOG_LOG, "%.*s", len, ptr); + yaz_log(YLOG_LOG, "%.*s", (int) len, ptr); int yaz_diag_srw_to_bib1(srw_code)