X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=0c67a8771cd97b6a929ab41175d701a9a8df8465;hp=f472260e35757e2283e7d3db19e07bc84781be9c;hb=27e67487d8100738feb98ae7315540846d6bfdf0;hpb=2e817711bcfc8076b2500ab298e281357ed50115 diff --git a/client/client.c b/client/client.c index f472260..0c67a87 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.150 2002-04-15 11:19:32 adam Exp $ + * $Id: client.c,v 1.156 2002-06-02 21:34:45 adam Exp $ */ #include @@ -20,17 +20,14 @@ #include #include #include +#include #include #include -#if YAZ_MODULE_ill #include -#endif -#if YAZ_MODULE_ccl #include -#endif #if HAVE_READLINE_READLINE_H #include @@ -72,6 +69,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; @@ -85,9 +84,7 @@ typedef enum { static QueryType queryType = QueryType_Prefix; -#if YAZ_MODULE_ccl static CCL_bibset bibset; /* CCL bibset handle */ -#endif #if HAVE_READLINE_COMPLETION_OVER @@ -204,6 +201,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_proposal_charneg(out, + (const char**)&yazCharset, (yazCharset)?1:0, + (const char**)&yazLang, (yazLang)?1:0, 1); + } + } + send_apdu(apdu); printf("Sent initrequest.\n"); } @@ -281,6 +295,24 @@ static int process_initResponse(Z_InitResponse *res) if (ODR_MASK_GET(res->options, Z_Options_queryType104)) printf (" queryType104"); printf ("\n"); + + if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) { + + Z_CharSetandLanguageNegotiation *p = + yaz_get_charneg_record(res->otherInfo); + + if (p) { + + char *charset=NULL, *lang=NULL; + int selected; + + yaz_get_response_charneg(session_mem, p, &charset, &lang, &selected); + + printf("Accepted character set : `%s'\n", charset); + printf("Accepted code language : `%s'\n", lang); + printf("Accepted records in ...: %d\n", selected ); + } + } fflush (stdout); return 0; } @@ -404,6 +436,7 @@ int cmd_authentication(char *arg) } /* SEARCH SERVICE ------------------------------ */ +static void display_record(Z_External *r); static void display_variant(Z_Variant *v, int level) { @@ -425,7 +458,9 @@ static void display_grs1(Z_GenericRecord *r, int level) int i; if (!r) + { return; + } for (i = 0; i < r->num_elements; i++) { Z_TaggedElement *t; @@ -443,8 +478,13 @@ static void display_grs1(Z_GenericRecord *r, int level) printf("%s) ", t->tagValue->u.string); if (t->content->which == Z_ElementData_subtree) { - printf("\n"); - display_grs1(t->content->u.subtree, level+1); + if (!t->content->u.subtree) + printf (" (no subtree)\n"); + else + { + printf("\n"); + display_grs1(t->content->u.subtree, level+1); + } } else if (t->content->which == Z_ElementData_string) printf("%s\n", t->content->u.string); @@ -471,8 +511,15 @@ static void display_grs1(Z_GenericRecord *r, int level) printf("[Element empty]\n"); else if (t->content->which == Z_ElementData_elementNotThere) printf("[Element not there]\n"); + else if (t->content->which == Z_ElementData_date) + printf("Date: %s\n", t->content->u.date); + else if (t->content->which == Z_ElementData_ext) + { + printf ("External\n"); + display_record (t->content->u.ext); + } else - printf("??????\n"); + printf("? type = %d\n",t->content->which); if (t->appliedVariant) display_variant(t->appliedVariant, level+1); if (t->metaData && t->metaData->supportedVariants) @@ -549,6 +596,8 @@ static void display_record(Z_External *r) r->which = type->what; } } + if (ent && ent->oclass != CLASS_RECSYN) + return; if (ent && ent->value == VAL_SOIF) print_record((const unsigned char *) r->u.octet_aligned->buf, r->u.octet_aligned->len); @@ -735,15 +784,12 @@ static int send_searchRequest(char *arg) Z_SearchRequest *req = apdu->u.searchRequest; Z_Query query; int oid[OID_SIZE]; -#if YAZ_MODULE_ccl struct ccl_rpn_node *rpn = NULL; int error, pos; -#endif char setstring[100]; Z_RPNQuery *RPNquery; Odr_oct ccl_query; -#if YAZ_MODULE_ccl if (queryType == QueryType_CCL2RPN) { rpn = ccl_find_str(bibset, arg, &error, &pos); @@ -753,7 +799,6 @@ static int send_searchRequest(char *arg) return 0; } } -#endif req->referenceId = set_refid (out); if (!strcmp(arg, "@big")) /* strictly for troublemaking */ { @@ -811,7 +856,6 @@ static int send_searchRequest(char *arg) ccl_query.buf = (unsigned char*) arg; ccl_query.len = strlen(arg); break; -#if YAZ_MODULE_ccl case QueryType_CCL2RPN: query.which = Z_Query_type_1; RPNquery = ccl_rpn_query(out, rpn); @@ -823,7 +867,6 @@ static int send_searchRequest(char *arg) query.u.type_1 = RPNquery; ccl_rpn_delete (rpn); break; -#endif default: printf ("Unsupported query type\n"); return 0; @@ -1136,8 +1179,6 @@ void process_ESResponse(Z_ExtendedServicesResponse *res) } } -#if YAZ_MODULE_ill - const char *get_ill_element (void *clientData, const char *element) { return 0; @@ -1199,9 +1240,7 @@ static Z_External *create_external_itemRequest() } return r; } -#endif -#ifdef YAZ_MODULE_ill static Z_External *create_external_ILL_APDU(int which) { struct ill_get_ctl ctl; @@ -1257,7 +1296,6 @@ static Z_External *create_external_ILL_APDU(int which) } return r; } -#endif static Z_External *create_ItemOrderExternal(const char *type, int itemno) @@ -2056,6 +2094,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 +2108,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 +2575,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}, @@ -2645,7 +2721,7 @@ char ** readline_completer(char *text, int start, int end) { #if HAVE_READLINE_READLINE_H if(start == 0) { -#ifdef RL_READLINE_VERSION +#if HAVE_READLINE_RL_COMPLETION_MATCHES char** res=rl_completion_matches(text, command_generator); #else @@ -2676,7 +2752,7 @@ char ** readline_completer(char *text, int start, int end) { if(!cmd[i].complete_filenames) rl_attempted_completion_over = 1; if(cmd[i].rl_completerfunction) { -#ifdef RL_READLINE_VERSION +#ifdef HAVE_READLINE_RL_COMPLETION_MATCHES char** res= rl_completion_matches(text, cmd[i].rl_completerfunction);