Added second part of helper functions for CharSetandLanguageNegotaiation-3 Model.
[yaz-moved-to-github.git] / client / client.c
index 748c184..85063a5 100644 (file)
@@ -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.153 2002-05-19 15:39:54 oleg Exp $
  */
 
 #include <stdio.h>
@@ -20,6 +20,7 @@
 #include <yaz/marcdisp.h>
 #include <yaz/diagbib1.h>
 #include <yaz/otherinfo.h>
+#include <yaz/charneg.h>
 
 #include <yaz/pquery.h>
 #include <yaz/sortspec.h>
@@ -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_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 +301,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, *lang;
+               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;
 }
@@ -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, "<item>",NULL,0},
     {"packagename", cmd_packagename, "<packagename>",NULL,0},
     {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0},
+    {"charset", cmd_charset, "<charset_name>",NULL,0},
+    {"lang", cmd_lang, "<language_code>",NULL,0},
     {".", cmd_source, "<filename>",NULL,1},
     {"!", cmd_subshell, "Subshell command",NULL,0},
     {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,0},