From: Adam Dickmeiss Date: Mon, 12 Jan 2004 12:11:57 +0000 (+0000) Subject: Small utility to encode/decode init options as a string X-Git-Tag: YAZ.2.0.9.6~1 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=6d9e8305bb173398dc9b886070a72b40618304ca;p=yaz-moved-to-github.git Small utility to encode/decode init options as a string --- diff --git a/client/client.c b/client/client.c index f320aec..b5626d5 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.223 2004-01-07 21:02:42 adam Exp $ + * $Id: client.c,v 1.224 2004-01-12 12:11:57 adam Exp $ */ #include @@ -103,6 +103,7 @@ static FILE *marc_file = 0; static char *refid = NULL; static char *last_open_command = NULL; static int auto_reconnect = 0; +static Odr_bitmask z3950_options; static char cur_host[200]; @@ -280,14 +281,7 @@ static void send_initRequest(const char* type_and_host) Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest); Z_InitRequest *req = apdu->u.initRequest; - ODR_MASK_SET(req->options, Z_Options_search); - ODR_MASK_SET(req->options, Z_Options_present); - ODR_MASK_SET(req->options, Z_Options_namedResultSets); - ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl); - ODR_MASK_SET(req->options, Z_Options_scan); - ODR_MASK_SET(req->options, Z_Options_sort); - ODR_MASK_SET(req->options, Z_Options_extendedServices); - ODR_MASK_SET(req->options, Z_Options_delSet); + req->options = &z3950_options; ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2); @@ -2137,6 +2131,27 @@ static int cmd_itemorder(const char *arg) return 2; } +static void show_opt(const char *arg) +{ + printf ("%s ", arg); +} + +static int cmd_options(const char *arg) +{ + if (*arg) + { + int r; + int pos; + r = yaz_init_opt_encode(&z3950_options, arg, &pos); + } + else + { + yaz_init_opt_decode(&z3950_options, show_opt); + printf ("\n"); + } + return 0; +} + static int cmd_explain(const char *arg) { if (protocol != PROTO_HTTP) @@ -3813,6 +3828,7 @@ static struct { {"adm-shutdown", cmd_adm_shutdown, "",NULL,0,NULL}, {"adm-startup", cmd_adm_startup, "",NULL,0,NULL}, {"explain", cmd_explain, "", NULL, 0, NULL}, + {"options", cmd_options, "", NULL, 0, NULL}, {"help", cmd_help, "", NULL,0,NULL}, {0,0,0,0,0,0} }; @@ -4111,6 +4127,15 @@ int main(int argc, char **argv) #endif if (codeset) outputCharset = xstrdup(codeset); + + ODR_MASK_SET(&z3950_options, Z_Options_search); + ODR_MASK_SET(&z3950_options, Z_Options_present); + ODR_MASK_SET(&z3950_options, Z_Options_namedResultSets); + ODR_MASK_SET(&z3950_options, Z_Options_triggerResourceCtrl); + ODR_MASK_SET(&z3950_options, Z_Options_scan); + ODR_MASK_SET(&z3950_options, Z_Options_sort); + ODR_MASK_SET(&z3950_options, Z_Options_extendedServices); + ODR_MASK_SET(&z3950_options, Z_Options_delSet); while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vxd:", argv, argc, &arg)) != -2) { diff --git a/include/yaz/proto.h b/include/yaz/proto.h index 5023c15..2568413 100644 --- a/include/yaz/proto.h +++ b/include/yaz/proto.h @@ -1,9 +1,8 @@ /* - * Copyright (c) 1998-2003, Index Data + * Copyright (c) 1998-2004, Index Data * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss * - * $Id: proto.h,v 1.11 2003-07-18 19:54:30 mike Exp $ + * $Id: proto.h,v 1.12 2004-01-12 12:11:57 adam Exp $ */ #ifndef Z_PROTO_H #define Z_PROTO_H @@ -114,6 +113,10 @@ YAZ_EXPORT void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags); 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)); YAZ_END_CDECL #include diff --git a/src/Makefile.am b/src/Makefile.am index 67c8b01..897df40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## Copyright (C) 1994-2003, Index Data ## All rights reserved. -## $Id: Makefile.am,v 1.4 2004-01-05 09:41:31 adam Exp $ +## $Id: Makefile.am,v 1.5 2004-01-12 12:11:57 adam Exp $ if ISTHR thrlib=libyazthread.la @@ -55,7 +55,7 @@ libyaz_la_SOURCES=version.c options.c log.c marcdisp.c oid.c wrbuf.c \ prt-ext.c \ ill-core.c item-req.c ill-get.c \ zget.c yaz-ccl.c diagbib1.c logrpn.c \ - otherinfo.c pquery.c sortspec.c z3950oid.c charneg.c \ + otherinfo.c pquery.c sortspec.c z3950oid.c charneg.c initopt.c \ zoom-c.c zoom-opt.c zoom-p.h grs1disp.c zgdu.c soap.c srw.c srwutil.c \ opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c \ cclqfile.c cclstr.c \ diff --git a/src/initopt.c b/src/initopt.c new file mode 100644 index 0000000..a0eef33 --- /dev/null +++ b/src/initopt.c @@ -0,0 +1,87 @@ +/* + * 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 $ + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include + +static struct { + char *name; + int opt; +} opt_array[] = { + {"search", Z_Options_search}, + {"present", Z_Options_present}, + {"delSet", Z_Options_delSet}, + {"resourceReport", Z_Options_resourceReport}, + {"triggerResourceCtrl", Z_Options_triggerResourceCtrl}, + {"resourceCtrl", Z_Options_resourceCtrl}, + {"accessCtrl", Z_Options_accessCtrl}, + {"scan", Z_Options_scan}, + {"sort", Z_Options_sort}, + {"extendedServices", Z_Options_extendedServices}, + {"level_1Segmentation", Z_Options_level_1Segmentation}, + {"level_2Segmentation", Z_Options_level_2Segmentation}, + {"concurrentOperations", Z_Options_concurrentOperations}, + {"namedResultSets", Z_Options_namedResultSets}, + {"encapsulation", Z_Options_encapsulation}, + {"resultCount", Z_Options_resultCount}, + {"negotiationModel", Z_Options_negotiationModel}, + {"duplicationDetection", Z_Options_duplicateDetection}, + {"queryType104", Z_Options_queryType104}, + {"pQESCorrection", Z_Options_pQESCorrection}, + {"stringSchema", Z_Options_stringSchema}, + {0, 0} +}; + +int yaz_init_opt_encode(Z_Options *opt, const char *opt_str, int *error_pos) +{ + const char *cp = opt_str; + + ODR_MASK_ZERO(opt); + while (*cp) + { + char this_opt[20]; + int i, j; + if (*cp == ' ' || *cp == ',') + { + cp++; + continue; + } + for (i = 0; i < (sizeof(this_opt)-1) && + cp[i] && cp[i] != ' ' && cp[i] != ','; i++) + this_opt[i] = cp[i]; + this_opt[i] = 0; + for (j = 0; opt_array[j].name; j++) + { + if (yaz_matchstr(this_opt, opt_array[j].name) == 0) + { + ODR_MASK_SET(opt, opt_array[j].opt); + break; + } + } + if (!opt_array[j].name) + { + if (error_pos) + { + *error_pos = cp - opt_str; + return -1; + } + } + cp += i; + } + return 0; +} + +void yaz_init_opt_decode(Z_Options *opt, void (*pr)(const char *name)) +{ + int i; + for (i = 0; opt_array[i].name; i++) + if (ODR_MASK_GET(opt, opt_array[i].opt)) + (*pr)(opt_array[i].name); +} diff --git a/win/makefile b/win/makefile index 63edac3..be4e2c8 100644 --- a/win/makefile +++ b/win/makefile @@ -1,6 +1,6 @@ # Copyright (C) 1994-2003, Index Data # All rights reserved. -# $Id: makefile,v 1.68 2003-12-30 00:23:28 adam Exp $ +# $Id: makefile,v 1.69 2004-01-12 12:11:58 adam Exp $ # # Programmed by # HL: Heikki Levanto, Index Data @@ -352,7 +352,8 @@ YAZ_ZUTIL_OBJS= \ $(OBJDIR)\srw.obj \ $(OBJDIR)\srwutil.obj \ $(OBJDIR)\zoom-c.obj \ - $(OBJDIR)\zoom-opt.obj + $(OBJDIR)\zoom-opt.obj \ + $(OBJDIR)\initopt.obj Z3950_OBJS= \ $(OBJDIR)\z-date.obj\