From 76bd6780cebee47ffefa4170fa2daa1f079d9559 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 15 Jan 2004 10:16:26 +0000 Subject: [PATCH] Change proto of yaz_init_opt_decode. Added new function nmem_print_list_l (variant of nmem_print_list). Added new yaz-client command zversion that sets Z39.50 option bits - using yaz_init_opt_encode. --- CHANGELOG | 7 +++++++ client/client.c | 30 +++++++++++++++++++++--------- include/yaz/nmem.h | 3 ++- include/yaz/proto.h | 6 ++++-- src/initopt.c | 8 +++++--- src/nmem.c | 11 ++++++++--- src/seshigh.c | 33 +++++++++++++++++++++++++-------- 7 files changed, 72 insertions(+), 26 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ade812d..1621a7b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,12 @@ Possible compatibility problems with earlier versions marked with '*'. +Fixed a bug in Generic Frontend Server that could make it crash if a +client sets characterSetNegotation bit, but didn't pass negotiation stuff +in InitRequest. + +New YAZ client command, zversion, that sets Z39.50 version (1,2,3..). +Must be issued before open, in order to be in effect. + --- 2.0.9-6 2004/01/12 Debian/Windows Make the SRU server more picky WRT unknown params, etc. diff --git a/client/client.c b/client/client.c index 1512e88..6fa6a4a 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.225 2004-01-13 11:19:24 adam Exp $ + * $Id: client.c,v 1.226 2004-01-15 10:16:26 adam Exp $ */ #include @@ -104,6 +104,7 @@ static char *refid = NULL; static char *last_open_command = NULL; static int auto_reconnect = 0; static Odr_bitmask z3950_options; +static int z3950_version = 3; static char cur_host[200]; @@ -280,12 +281,13 @@ static void send_initRequest(const char* type_and_host) { Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest); Z_InitRequest *req = apdu->u.initRequest; + int i; req->options = &z3950_options; - ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1); - ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2); - ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3); + ODR_MASK_ZERO(req->protocolVersion); + for (i = 0; iprotocolVersion, i); *req->maximumRecordSize = 1024*kilobytes; *req->preferredMessageSize = 1024*kilobytes; @@ -326,7 +328,7 @@ static void send_initRequest(const char* type_and_host) static void render_initUserInfo(Z_OtherInformation *ui1); static void render_diag(Z_DiagnosticFormat *diag); -static void pr_opt(const char *opt) +static void pr_opt(const char *opt, void *clientData) { printf (" %s", opt); } @@ -338,7 +340,7 @@ static int process_initResponse(Z_InitResponse *res) session_mem = odr_extract_mem(in); session = res; - for (ver = 0; ver<5; ver++) + for (ver = 0; ver < 8; ver++) if (!ODR_MASK_GET(res->protocolVersion, ver)) break; @@ -375,7 +377,7 @@ static int process_initResponse(Z_InitResponse *res) } } printf ("Options:"); - yaz_init_opt_decode(res->options, pr_opt); + yaz_init_opt_decode(res->options, pr_opt, 0); printf ("\n"); if (ODR_MASK_GET(res->options, Z_Options_namedResultSets)) @@ -2101,11 +2103,20 @@ static int cmd_itemorder(const char *arg) return 2; } -static void show_opt(const char *arg) +static void show_opt(const char *arg, void *clientData) { printf ("%s ", arg); } +static int cmd_zversion(const char *arg) +{ + if (*arg && arg) + z3950_version = atoi(arg); + else + printf ("version is %d\n", z3950_version); + return 0; +} + static int cmd_options(const char *arg) { if (*arg) @@ -2116,7 +2127,7 @@ static int cmd_options(const char *arg) } else { - yaz_init_opt_decode(&z3950_options, show_opt); + yaz_init_opt_decode(&z3950_options, show_opt, 0); printf ("\n"); } return 0; @@ -3799,6 +3810,7 @@ static struct { {"adm-startup", cmd_adm_startup, "",NULL,0,NULL}, {"explain", cmd_explain, "", NULL, 0, NULL}, {"options", cmd_options, "", NULL, 0, NULL}, + {"zversion", cmd_zversion, "", NULL, 0, NULL}, {"help", cmd_help, "", NULL,0,NULL}, {0,0,0,0,0,0} }; diff --git a/include/yaz/nmem.h b/include/yaz/nmem.h index bf29b6a..293840c 100644 --- a/include/yaz/nmem.h +++ b/include/yaz/nmem.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: nmem.h,v 1.11 2003-03-18 13:34:35 adam Exp $ + * $Id: nmem.h,v 1.12 2004-01-15 10:16:26 adam Exp $ */ #ifndef NMEM_H @@ -81,6 +81,7 @@ YAZ_EXPORT void *nmem_malloc_f(const char *file, int line, NMEM n, int size); #define nmem_malloc(x, y) nmem_malloc_f(__FILE__, __LINE__, (x), (y)) YAZ_EXPORT void nmem_print_list (void); +YAZ_EXPORT void nmem_print_list_l (int level); #else diff --git a/include/yaz/proto.h b/include/yaz/proto.h index 2568413..9dc54c2 100644 --- a/include/yaz/proto.h +++ b/include/yaz/proto.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data * See the file LICENSE for details. * - * $Id: proto.h,v 1.12 2004-01-12 12:11:57 adam Exp $ + * $Id: proto.h,v 1.13 2004-01-15 10:16:26 adam Exp $ */ #ifndef Z_PROTO_H #define Z_PROTO_H @@ -116,7 +116,9 @@ YAZ_EXPORT void yaz_display_OPAC(WRBUF wrbuf, Z_OPACRecord *r, int flags); YAZ_EXPORT int yaz_init_opt_encode(Z_Options *opt, const char *opt_str, int *error_pos); YAZ_EXPORT void yaz_init_opt_decode(Z_Options *opt, - void (*pr)(const char *name)); + void (*pr)(const char *name, + void *clientData), + void *clientData); YAZ_END_CDECL #include diff --git a/src/initopt.c b/src/initopt.c index a0eef33..d475a82 100644 --- a/src/initopt.c +++ b/src/initopt.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: initopt.c,v 1.1 2004-01-12 12:11:57 adam Exp $ + * $Id: initopt.c,v 1.2 2004-01-15 10:16:27 adam Exp $ */ #if HAVE_CONFIG_H @@ -78,10 +78,12 @@ int yaz_init_opt_encode(Z_Options *opt, const char *opt_str, int *error_pos) return 0; } -void yaz_init_opt_decode(Z_Options *opt, void (*pr)(const char *name)) +void yaz_init_opt_decode(Z_Options *opt, void (*pr)(const char *name, + void *clientData), + void *clientData) { int i; for (i = 0; opt_array[i].name; i++) if (ODR_MASK_GET(opt, opt_array[i].opt)) - (*pr)(opt_array[i].name); + (*pr)(opt_array[i].name, clientData); } diff --git a/src/nmem.c b/src/nmem.c index 596d55b..35426da 100644 --- a/src/nmem.c +++ b/src/nmem.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: nmem.c,v 1.2 2003-12-04 11:47:50 adam Exp $ + * $Id: nmem.c,v 1.3 2004-01-15 10:16:27 adam Exp $ */ /* @@ -149,12 +149,17 @@ static void free_block(nmem_block *p) #if NMEM_DEBUG void nmem_print_list (void) { + nmem_print_list_l(LOG_DEBUG); +} + +void nmem_print_list_l (int level) +{ struct nmem_debug_info *p; - yaz_log (LOG_DEBUG, "nmem print list"); + yaz_log (level, "nmem print list"); NMEM_ENTER; for (p = nmem_debug_list; p; p = p->next) - yaz_log (LOG_DEBUG, " %s:%d p=%p size=%d", p->file, p->line, p->p, + yaz_log (level, " %s:%d p=%p size=%d", p->file, p->line, p->p, nmem_total(p->p)); NMEM_LEAVE; } diff --git a/src/seshigh.c b/src/seshigh.c index 08f5c32..3395c8b 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.16 2004-01-09 18:10:31 adam Exp $ + * $Id: seshigh.c,v 1.17 2004-01-15 10:16:27 adam Exp $ */ /* @@ -775,21 +775,36 @@ static void process_http_request(association *assoc, request *req) { Z_HTTP_Request *hreq = req->gdu_request->u.HTTP_Request; ODR o = assoc->encode; - int r; + int r = 2; /* 2=NOT TAKEN, 1=TAKEN, 0=SOAP TAKEN */ Z_SRW_PDU *sr = 0; Z_SOAP *soap_package = 0; Z_GDU *p = 0; char *charset = 0; - Z_HTTP_Response *hres; + Z_HTTP_Response *hres = 0; int keepalive = 1; char *stylesheet = 0; Z_SRW_diagnostic *diagnostic = 0; int num_diagnostic = 0; - r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset); + if (!strcmp(hreq->path, "/test")) + { + p = z_get_HTTP_Response(o, 200); + hres = p->u.HTTP_Response; + hres->content_buf = "1234567890\n"; + hres->content_len = strlen(hres->content_buf); + r = 1; + } + if (r == 2) + { + r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset); + yaz_log(LOG_DEBUG, "yaz_srw_decode returned %d", r); + } if (r == 2) /* not taken */ + { r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset, &diagnostic, &num_diagnostic); + yaz_log(LOG_DEBUG, "yaz_sru_decode returned %d", r); + } if (r == 0) /* decode SRW/SRU OK .. */ { int http_code = 200; @@ -879,7 +894,8 @@ static void process_http_request(association *assoc, request *req) else p = z_get_HTTP_Response(o, http_code); } - else + + if (p == 0) p = z_get_HTTP_Response(o, 500); hres = p->u.HTTP_Response; if (!strcmp(hreq->version, "1.0")) @@ -1176,7 +1192,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) { Z_CharSetandLanguageNegotiation *negotiation = yaz_get_charneg_record (req->otherInfo); - if (negotiation->which == Z_CharSetandLanguageNegotiation_proposal) + if (negotiation && + negotiation->which == Z_CharSetandLanguageNegotiation_proposal) assoc->init->charneg_request = negotiation; } @@ -1270,7 +1287,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1)) { ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1); - assoc->version = 2; /* 1 & 2 are equivalent */ + assoc->version = 1; /* 1 & 2 are equivalent */ } if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2)) { @@ -1302,7 +1319,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.16 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.17 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, -- 1.7.10.4