From 1cd88a77abb7c32e5ff938e2f4b9392d03d45ec5 Mon Sep 17 00:00:00 2001 From: oleg Date: Sat, 18 May 2002 09:52:37 +0000 Subject: [PATCH] Added support of CharacterSetandLanguageNegotiation-3 modele (based on Z_PrivateCharacterSet_externallySpecified) at the client side. --- client/client.c | 60 ++++++++++++++++++++++++++++++++++++++++- include/yaz/Makefile.am | 4 +-- win/makefile | 12 ++++++--- zoom/zoom-c.c | 69 ++++++++++++++++++++++++++++++++++++----------- zoom/zoom-p.h | 4 ++- zoom/zoomsh.c | 4 ++- zutil/Makefile.am | 4 +-- 7 files changed, 131 insertions(+), 26 deletions(-) diff --git a/client/client.c b/client/client.c index 748c184..4aa5ea6 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.151 2002-05-03 13:48:27 adam Exp $ + * $Id: client.c,v 1.152 2002-05-18 09:52:37 oleg Exp $ */ #include @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -72,6 +73,8 @@ static char ccl_fields[512] = "default.bib"; static char* esPackageName = 0; static char* yazProxy = 0; static int kilobytes = 1024; +static char* yazCharset = 0; +static char* yazLang = 0; static char last_cmd[32] = "?"; static FILE *marcdump = 0; @@ -204,6 +207,23 @@ static void send_initRequest(const char* type_and_host) yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY, 1, type_and_host); + if (yazCharset || yazLang) { + Z_OtherInformation **p; + Z_OtherInformationUnit *p0; + + yaz_oi_APDU(apdu, &p); + + if (p0=yaz_oi_update(p, out, NULL, 0, 0)) { + ODR_MASK_SET(req->options, Z_Options_negotiationModel); + + p0->which = Z_OtherInfo_externallyDefinedInfo; + p0->information.externallyDefinedInfo = + yaz_set_charset_and_lang(out, CLASS_NEGOT, VAL_CHARNEG3, + (const char**)&yazCharset, (yazCharset)?1:0, + (const char**)&yazLang, (yazLang)?1:0); + } + } + send_apdu(apdu); printf("Sent initrequest.\n"); } @@ -2056,6 +2076,10 @@ int cmd_packagename(char* arg) int cmd_proxy(char* arg) { + if (*arg == '\0') { + printf("Current proxy is `%s'\n", (yazCharset)?yazProxy:NULL); + return 1; + } xfree (yazProxy); yazProxy = NULL; if (*arg) @@ -2066,6 +2090,38 @@ int cmd_proxy(char* arg) return 1; } +int cmd_charset(char* arg) +{ + if (*arg == '\0') { + printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL); + return 1; + } + xfree (yazCharset); + yazCharset = NULL; + if (*arg) + { + yazCharset = (char *) xmalloc (strlen(arg)+1); + strcpy (yazCharset, arg); + } + return 1; +} + +int cmd_lang(char* arg) +{ + if (*arg == '\0') { + printf("Current language is `%s'\n", (yazLang)?yazLang:NULL); + return 1; + } + xfree (yazLang); + yazLang = NULL; + if (*arg) + { + yazLang = (char *) xmalloc (strlen(arg)+1); + strcpy (yazLang, arg); + } + return 1; +} + int cmd_source(char* arg) { /* first should open the file and read one line at a time.. */ @@ -2501,6 +2557,8 @@ static struct { {"update", cmd_update, "",NULL,0}, {"packagename", cmd_packagename, "",NULL,0}, {"proxy", cmd_proxy, "[('tcp'|'ssl')][':']",NULL,0}, + {"charset", cmd_charset, "",NULL,0}, + {"lang", cmd_lang, "",NULL,0}, {".", cmd_source, "",NULL,1}, {"!", cmd_subshell, "Subshell command",NULL,0}, {"set_apdufile", cmd_set_apdufile, "",NULL,0}, diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 5152f0a..a063372 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.14 2002-05-13 18:34:53 adam Exp $ +## $Id: Makefile.am,v 1.15 2002-05-18 09:52:37 oleg Exp $ pkginclude_HEADERS= backend.h ccl.h comstack.h \ d1_attset.h d1_map.h data1.h diagbib1.h sortspec.h \ @@ -11,5 +11,5 @@ pkginclude_HEADERS= backend.h ccl.h comstack.h \ z-grs.h z-opac.h z-rrf1.h z-rrf2.h z-sum.h z-sutrs.h z-uifr1.h \ z-univ.h zes-expi.h zes-exps.h zes-order.h zes-pquery.h \ zes-psched.h zes-admin.h zes-pset.h zes-update.h zes-update0.h \ - zoom.h z-charneg.h + zoom.h z-charneg.h charneg.h diff --git a/win/makefile b/win/makefile index 6de6dca..2bd8fd5 100644 --- a/win/makefile +++ b/win/makefile @@ -1,5 +1,5 @@ # makefile.mak - makefile for MS NMAKE -# $Id: makefile,v 1.37 2002-05-17 12:48:30 adam Exp $ +# $Id: makefile,v 1.38 2002-05-18 09:52:37 oleg Exp $ # # Programmed by # HL: Heikki Levanto, Index Data @@ -304,7 +304,8 @@ YAZ_ZUTIL_OBJS= \ $(OBJDIR)\yaz-ccl.obj \ $(OBJDIR)\otherinfo.obj \ $(OBJDIR)\sortspec.obj \ - $(OBJDIR)\z3950oid.obj + $(OBJDIR)\z3950oid.obj \ + $(OBJDIR)\charneg.obj YAZ_RET_OBJS= \ @@ -834,7 +835,12 @@ $(ILL_OBJS): $(ILL_CORE_FILES) $(ITEM_REQ_FILES) ########################################################### # # $Log: makefile,v $ -# Revision 1.37 2002-05-17 12:48:30 adam +# Revision 1.38 2002-05-18 09:52:37 oleg +# Added support of CharacterSetandLanguageNegotiation-3 +# modele (based on Z_PrivateCharacterSet_externallySpecified) at the client +# side. +# +# Revision 1.37 2002/05/17 12:48:30 adam # Use __stdcall convention for ZOOM on WIN32 # # Revision 1.36 2002/03/18 21:33:48 adam diff --git a/zoom/zoom-c.c b/zoom/zoom-c.c index 61f29d6..647774f 100644 --- a/zoom/zoom-c.c +++ b/zoom/zoom-c.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-c.c,v 1.28 2002-05-17 12:48:30 adam Exp $ + * $Id: zoom-c.c,v 1.29 2002-05-18 09:52:37 oleg Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -9,6 +9,7 @@ #include #include #include +#include #include "zoom-p.h" @@ -156,6 +157,8 @@ ZOOM_connection_create (ZOOM_options options) c->host_port = 0; c->proxy = 0; + + c->charset = c->lang = 0; c->cookie_out = 0; c->cookie_in = 0; @@ -249,6 +252,18 @@ ZOOM_connection_connect(ZOOM_connection c, else c->proxy = 0; + val = ZOOM_options_get (c->options, "charset"); + if (val && *val) + c->charset = xstrdup (val); + else + c->charset = 0; + + val = ZOOM_options_get (c->options, "lang"); + if (val && *val) + c->lang = xstrdup (val); + else + c->lang = 0; + if (portnum) { char hostn[128]; @@ -342,6 +357,8 @@ ZOOM_connection_destroy(ZOOM_connection c) ZOOM_connection_remove_tasks (c); xfree (c->host_port); xfree (c->proxy); + xfree (c->charset); + xfree (c->lang); xfree (c->cookie_out); xfree (c->cookie_in); xfree (c); @@ -705,6 +722,25 @@ static int ZOOM_connection_send_init (ZOOM_connection c) if (c->proxy) yaz_oi_set_string_oidval(&ireq->otherInfo, c->odr_out, VAL_PROXY, 1, c->host_port); + if (c->charset||c->lang) + { + Z_OtherInformation **oi; + Z_OtherInformationUnit *oi_unit; + + yaz_oi_APDU(apdu, &oi); + + if (oi_unit = yaz_oi_update(oi, c->odr_out, NULL, 0, 0)) + { + ODR_MASK_SET(ireq->options, Z_Options_negotiationModel); + + oi_unit->which = Z_OtherInfo_externallyDefinedInfo; + oi_unit->information.externallyDefinedInfo = + yaz_set_charset_and_lang(c->odr_out, + CLASS_NEGOT, VAL_CHARNEG3, + (const char **)&c->charset, (c->charset) ? 1:0, + (const char **)&c->lang, (c->lang) ? 1:0); + } + } assert (apdu); send_APDU (c, apdu); @@ -914,8 +950,9 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) { Z_NamePlusRecord *npr; - *len = 0; /* if return 0 */ - + if (len) + *len = 0; /* default return */ + if (!rec) return 0; npr = rec->npr; @@ -923,7 +960,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) return 0; if (!strcmp (type, "database")) { - *len = strlen(npr->databaseName)+1; + if (len) *len = strlen(npr->databaseName)+1; return npr->databaseName; } else if (!strcmp (type, "syntax")) @@ -934,7 +971,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) oident *ent = oid_getentbyoid(r->direct_reference); if (ent) { - *len = strlen(ent->desc)+1; + if (len) *len = strlen(ent->desc)+1; return ent->desc; } } @@ -948,7 +985,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) if (r->which == Z_External_sutrs) { - *len = r->u.sutrs->len; + if (len) *len = r->u.sutrs->len; return (const char *) r->u.sutrs->buf; } else if (r->which == Z_External_octet) @@ -972,16 +1009,16 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) r->u.octet_aligned->len, 0) > 0) { - *len = wrbuf_len(rec->wrbuf_marc); + if (len) *len = wrbuf_len(rec->wrbuf_marc); return wrbuf_buf(rec->wrbuf_marc); } } - *len = r->u.octet_aligned->len; + if (len) *len = r->u.octet_aligned->len; return (const char *) r->u.octet_aligned->buf; } else if (r->which == Z_External_grs1) { - *len = 5; + if (len) *len = 5; return "GRS-1"; } return 0; @@ -994,7 +1031,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) if (r->which == Z_External_sutrs) { - *len = r->u.sutrs->len; + if (len) *len = r->u.sutrs->len; return (const char *) r->u.sutrs->buf; } else if (r->which == Z_External_octet) @@ -1018,16 +1055,16 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) r->u.octet_aligned->len, 1) > 0) { - *len = wrbuf_len(rec->wrbuf_marc); + if (len) *len = wrbuf_len(rec->wrbuf_marc); return wrbuf_buf(rec->wrbuf_marc); } } - *len = r->u.octet_aligned->len; + if (len) *len = r->u.octet_aligned->len; return (const char *) r->u.octet_aligned->buf; } else if (r->which == Z_External_grs1) { - *len = 5; + if (len) *len = 5; return "GRS-1"; } return 0; @@ -1040,17 +1077,17 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) if (r->which == Z_External_sutrs) { - *len = r->u.sutrs->len; + if (len) *len = r->u.sutrs->len; return (const char *) r->u.sutrs->buf; } else if (r->which == Z_External_octet) { - *len = r->u.octet_aligned->len; + if (len) *len = r->u.octet_aligned->len; return (const char *) r->u.octet_aligned->buf; } else /* grs-1, explain, ... */ { - *len = -1; + if (len) *len = -1; return (const char *) npr->u.databaseRecord; } } diff --git a/zoom/zoom-p.h b/zoom/zoom-p.h index 80fa968..65621a8 100644 --- a/zoom/zoom-p.h +++ b/zoom/zoom-p.h @@ -1,6 +1,6 @@ /* * Private C header for ZOOM C. - * $Id: zoom-p.h,v 1.9 2002-05-17 12:48:30 adam Exp $ + * $Id: zoom-p.h,v 1.10 2002-05-18 09:52:37 oleg Exp $ */ #include #include @@ -39,6 +39,8 @@ struct ZOOM_connection_p { char *buf_out; int len_out; char *proxy; + char *charset; + char *lang; char *cookie_out; char *cookie_in; int async; diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 627e216..f263768 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,5 +1,5 @@ /* - * $Id: zoomsh.c,v 1.8 2002-02-20 14:40:42 adam Exp $ + * $Id: zoomsh.c,v 1.9 2002-05-18 09:52:37 oleg Exp $ * * ZOOM-C Shell */ @@ -252,6 +252,8 @@ static void cmd_help (ZOOM_connection *c, ZOOM_resultset *r, printf (" user\n"); printf (" pass\n"); printf (" implementationName\n"); + printf (" charset\n"); + printf (" lang\n"); } static void cmd_connect (ZOOM_connection *c, ZOOM_resultset *r, diff --git a/zutil/Makefile.am b/zutil/Makefile.am index 2614004..98f28f0 100644 --- a/zutil/Makefile.am +++ b/zutil/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.9 2002-04-15 09:44:44 adam Exp $ +## $Id: Makefile.am,v 1.10 2002-05-18 09:52:37 oleg Exp $ noinst_LTLIBRARIES = libzutil.la AM_CPPFLAGS=-I$(top_srcdir)/include @@ -6,4 +6,4 @@ AM_CPPFLAGS=-I$(top_srcdir)/include LIBS = libzutil_la_SOURCES = zget.c yaz-ccl.c diagbib1.c logrpn.c \ - otherinfo.c pquery.c sortspec.c z3950oid.c + otherinfo.c pquery.c sortspec.c z3950oid.c charneg.c -- 1.7.10.4