* Copyright (c) 1995-2002, Index Data
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.149 2002-04-13 18:09:01 adam Exp $
+ * $Id: client.c,v 1.156 2002-06-02 21:34:45 adam Exp $
*/
#include <stdio.h>
#include <yaz/marcdisp.h>
#include <yaz/diagbib1.h>
#include <yaz/otherinfo.h>
+#include <yaz/charneg.h>
#include <yaz/pquery.h>
#include <yaz/sortspec.h>
-#if YAZ_MODULE_ill
#include <yaz/ill.h>
-#endif
-#if YAZ_MODULE_ccl
#include <yaz/yaz-ccl.h>
-#endif
#if HAVE_READLINE_READLINE_H
#include <readline/readline.h>
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;
static QueryType queryType = QueryType_Prefix;
-#if YAZ_MODULE_ccl
static CCL_bibset bibset; /* CCL bibset handle */
-#endif
-#if HAVE_READLINE_READLINE_H
-#ifndef RL_READLINE_VERSION
+#if HAVE_READLINE_COMPLETION_OVER
+
+#else
+/* readline doesn't have this var. Define it ourselves. */
int rl_attempted_completion_over = 0;
#endif
-#endif
/* set this one to 1, to avoid decode of unknown MARCs */
#define AVOID_MARC_DECODE 1
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");
}
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;
}
}
/* SEARCH SERVICE ------------------------------ */
+static void display_record(Z_External *r);
static void display_variant(Z_Variant *v, int level)
{
int i;
if (!r)
+ {
return;
+ }
for (i = 0; i < r->num_elements; i++)
{
Z_TaggedElement *t;
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);
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)
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);
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);
return 0;
}
}
-#endif
req->referenceId = set_refid (out);
if (!strcmp(arg, "@big")) /* strictly for troublemaking */
{
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);
query.u.type_1 = RPNquery;
ccl_rpn_delete (rpn);
break;
-#endif
default:
printf ("Unsupported query type\n");
return 0;
}
}
-#if YAZ_MODULE_ill
-
const char *get_ill_element (void *clientData, const char *element)
{
return 0;
}
return r;
}
-#endif
-#ifdef YAZ_MODULE_ill
static Z_External *create_external_ILL_APDU(int which)
{
struct ill_get_ctl ctl;
}
return r;
}
-#endif
static Z_External *create_ItemOrderExternal(const char *type, int itemno)
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)
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.. */
{"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},
#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
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);