+ {
+ *res->closeReason = Z_Close_finished;
+ send_apdu(apdu);
+ printf("Sent response.\n");
+ sent_close = 1;
+ }
+}
+
+static int cmd_show(char *arg)
+{
+ if (!conn)
+ {
+ printf("Not connected yet\n");
+ return 0;
+ }
+ if (!send_presentRequest(arg))
+ return 0;
+ return 2;
+}
+
+int cmd_quit(char *arg)
+{
+ printf("See you later, alligator.\n");
+ xmalloc_trav ("");
+ exit(0);
+ return 0;
+}
+
+int cmd_cancel(char *arg)
+{
+ Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
+ Z_TriggerResourceControlRequest *req =
+ apdu->u.triggerResourceControlRequest;
+ bool_t rfalse = 0;
+
+ if (!conn)
+ {
+ printf("Session not initialized yet\n");
+ return 0;
+ }
+ if (!ODR_MASK_GET(session->options, Z_Options_triggerResourceCtrl))
+ {
+ printf("Target doesn't support cancel (trigger resource ctrl)\n");
+ return 0;
+ }
+ *req->requestedAction = Z_TriggerResourceCtrl_cancel;
+ req->resultSetWanted = &rfalse;
+
+ send_apdu(apdu);
+ printf("Sent cancel request\n");
+ return 2;
+}
+
+int send_scanrequest(const char *query, int pp, int num, const char *term)
+{
+ Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
+ Z_ScanRequest *req = apdu->u.scanRequest;
+ int oid[OID_SIZE];
+
+ if (queryType == QueryType_CCL2RPN)
+ {
+ oident bib1;
+ int error, pos;
+ struct ccl_rpn_node *rpn;
+
+ rpn = ccl_find_str (bibset, query, &error, &pos);
+ if (error)
+ {
+ printf("CCL ERROR: %s\n", ccl_err_msg(error));
+ return -1;
+ }
+ bib1.proto = PROTO_Z3950;
+ bib1.oclass = CLASS_ATTSET;
+ bib1.value = VAL_BIB1;
+ req->attributeSet = oid_ent_to_oid (&bib1, oid);
+ if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
+ {
+ printf("Couldn't convert CCL to Scan term\n");
+ return -1;
+ }
+ ccl_rpn_delete (rpn);
+ }
+ else
+ {
+ YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
+
+ if (!(req->termListAndStartPoint =
+ yaz_pqf_scan(pqf_parser, out, &req->attributeSet, query)))
+ {
+ const char *pqf_msg;
+ size_t off;
+ int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
+ printf("%*s^\n", off+7, "");
+ printf("Prefix query error: %s (code %d)\n", pqf_msg, code);
+ yaz_pqf_destroy (pqf_parser);
+ return -1;
+ }
+ yaz_pqf_destroy (pqf_parser);
+ }
+ if (term && *term)
+ {
+ if (req->termListAndStartPoint->term &&
+ req->termListAndStartPoint->term->which == Z_Term_general &&
+ req->termListAndStartPoint->term->u.general)
+ {
+ req->termListAndStartPoint->term->u.general->buf =
+ (unsigned char *) odr_strdup(out, term);
+ req->termListAndStartPoint->term->u.general->len =
+ req->termListAndStartPoint->term->u.general->size =
+ strlen(term);
+ }
+ }
+ req->referenceId = set_refid (out);
+ req->num_databaseNames = num_databaseNames;
+ req->databaseNames = databaseNames;
+ req->numberOfTermsRequested = #
+ req->preferredPositionInResponse = &pp;
+ send_apdu(apdu);
+ return 2;
+}
+
+int send_sortrequest(char *arg, int newset)
+{
+ Z_APDU *apdu = zget_APDU(out, Z_APDU_sortRequest);
+ Z_SortRequest *req = apdu->u.sortRequest;
+ Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
+ odr_malloc (out, sizeof(*sksl));
+ char setstring[32];
+
+ if (setnumber >= 0)
+ sprintf (setstring, "%d", setnumber);
+ else
+ sprintf (setstring, "default");
+
+ req->referenceId = set_refid (out);
+
+ req->num_inputResultSetNames = 1;
+ req->inputResultSetNames = (Z_InternationalString **)
+ odr_malloc (out, sizeof(*req->inputResultSetNames));
+ req->inputResultSetNames[0] = odr_strdup (out, setstring);
+
+ if (newset && setnumber >= 0)
+ sprintf (setstring, "%d", ++setnumber);
+
+ req->sortedResultSetName = odr_strdup (out, setstring);
+
+ req->sortSequence = yaz_sort_spec (out, arg);
+ if (!req->sortSequence)
+ {
+ printf ("Missing sort specifications\n");
+ return -1;
+ }
+ send_apdu(apdu);
+ return 2;
+}
+
+void display_term(Z_TermInfo *t)
+{
+ if (t->term->which == Z_Term_general)
+ {
+ printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
+ sprintf(last_scan_line, "%.*s", t->term->u.general->len,
+ t->term->u.general->buf);
+ }
+ else
+ printf("Term (not general)");
+ if (t->globalOccurrences)
+ printf (" (%d)\n", *t->globalOccurrences);
+ else
+ printf ("\n");
+}
+
+void process_scanResponse(Z_ScanResponse *res)
+{
+ int i;
+ Z_Entry **entries = NULL;
+ int num_entries = 0;
+
+ printf("Received ScanResponse\n");
+ print_refid (res->referenceId);
+ printf("%d entries", *res->numberOfEntriesReturned);
+ if (res->positionOfTerm)
+ printf (", position=%d", *res->positionOfTerm);
+ printf ("\n");
+ if (*res->scanStatus != Z_Scan_success)
+ printf("Scan returned code %d\n", *res->scanStatus);
+ if (!res->entries)
+ return;
+ if ((entries = res->entries->entries))
+ num_entries = res->entries->num_entries;
+ for (i = 0; i < num_entries; i++)
+ {
+ int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
+ if (entries[i]->which == Z_Entry_termInfo)
+ {
+ printf("%c ", i + 1 == pos_term ? '*' : ' ');
+ display_term(entries[i]->u.termInfo);
+ }
+ else
+ display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1);
+ }
+ if (res->entries->nonsurrogateDiagnostics)
+ display_diagrecs (res->entries->nonsurrogateDiagnostics,
+ res->entries->num_nonsurrogateDiagnostics);
+}
+
+void process_sortResponse(Z_SortResponse *res)
+{
+ printf("Received SortResponse: status=");
+ switch (*res->sortStatus)
+ {
+ case Z_SortStatus_success:
+ printf ("success"); break;
+ case Z_SortStatus_partial_1:
+ printf ("partial"); break;
+ case Z_SortStatus_failure:
+ printf ("failure"); break;
+ default:
+ printf ("unknown (%d)", *res->sortStatus);
+ }
+ printf ("\n");
+ print_refid (res->referenceId);
+ if (res->diagnostics)
+ display_diagrecs(res->diagnostics,
+ res->num_diagnostics);
+}
+
+void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res)
+{
+ printf("Got deleteResultSetResponse status=%d\n",
+ *res->deleteOperationStatus);
+ if (res->deleteListStatuses)
+ {
+ int i;
+ for (i = 0; i < res->deleteListStatuses->num; i++)
+ {
+ printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id,
+ *res->deleteListStatuses->elements[i]->status);
+ }
+ }
+}
+
+int cmd_sort_generic(char *arg, int newset)
+{
+ if (!conn)
+ {
+ printf("Session not initialized yet\n");
+ return 0;
+ }
+ if (!ODR_MASK_GET(session->options, Z_Options_sort))
+ {
+ printf("Target doesn't support sort\n");
+ return 0;
+ }
+ if (*arg)
+ {
+ if (send_sortrequest(arg, newset) < 0)
+ return 0;
+ return 2;
+ }
+ return 0;
+}
+
+int cmd_sort(char *arg)
+{
+ return cmd_sort_generic (arg, 0);
+}
+
+int cmd_sort_newset (char *arg)
+{
+ return cmd_sort_generic (arg, 1);
+}
+
+int cmd_scan(char *arg)
+{
+ if (!conn)
+ {
+ try_reconnect();
+
+ if (!conn) {
+ printf("Session not initialized yet\n");
+ return 0;
+ };
+ }
+ if (!ODR_MASK_GET(session->options, Z_Options_scan))
+ {
+ printf("Target doesn't support scan\n");
+ return 0;
+ }
+ if (*arg)
+ {
+ strcpy (last_scan_query, arg);
+ if (send_scanrequest(arg, 1, 20, 0) < 0)
+ return 0;
+ }
+ else
+ {
+ if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0)
+ return 0;
+ }
+ return 2;
+}
+
+int cmd_schema(char *arg)
+{
+ if (!arg || !*arg)
+ {
+ schema = VAL_NONE;
+ return 1;
+ }
+ schema = oid_getvalbyname (arg);
+ if (schema == VAL_NONE)
+ {
+ printf ("unknown schema\n");
+ return 0;
+ }
+ return 1;
+}
+
+int cmd_format(char *arg)
+{
+ if (!arg || !*arg)
+ {
+ printf("Usage: format <recordsyntax>\n");
+ return 0;
+ }
+ recordsyntax = oid_getvalbyname (arg);
+ if (recordsyntax == VAL_NONE)
+ {
+ printf ("unknown record syntax\n");
+ return 0;
+ }
+ return 1;
+}
+
+int cmd_elements(char *arg)
+{
+ static Z_ElementSetNames esn;
+ static char what[100];
+
+ if (!arg || !*arg)
+ {
+ elementSetNames = 0;
+ return 1;
+ }
+ strcpy(what, arg);
+ esn.which = Z_ElementSetNames_generic;
+ esn.u.generic = what;
+ elementSetNames = &esn;
+ return 1;
+}
+
+int cmd_attributeset(char *arg)
+{
+ char what[100];
+
+ if (!arg || !*arg)
+ {
+ printf("Usage: attributeset <setname>\n");
+ return 0;
+ }
+ sscanf(arg, "%s", what);
+ if (p_query_attset (what))
+ {
+ printf("Unknown attribute set name\n");
+ return 0;
+ }
+ return 1;
+}
+
+int cmd_querytype (char *arg)
+{
+ if (!strcmp (arg, "ccl"))
+ queryType = QueryType_CCL;
+ else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn"))
+ queryType = QueryType_Prefix;
+ else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
+ queryType = QueryType_CCL2RPN;
+ else
+ {
+ printf ("Querytype must be one of:\n");
+ printf (" prefix - Prefix query\n");
+ printf (" ccl - CCL query\n");
+ printf (" ccl2rpn - CCL query converted to RPN\n");
+ return 0;
+ }
+ return 1;
+}
+
+int cmd_refid (char *arg)
+{
+ xfree (refid);
+ refid = NULL;
+ if (*arg)
+ {
+ refid = (char *) xmalloc (strlen(arg)+1);
+ strcpy (refid, arg);
+ }
+ return 1;
+}
+
+int cmd_close(char *arg)
+{
+ Z_APDU *apdu;
+ Z_Close *req;
+ if (!conn)
+ return 0;
+
+ apdu = zget_APDU(out, Z_APDU_close);
+ req = apdu->u.close;
+ *req->closeReason = Z_Close_finished;
+ send_apdu(apdu);
+ printf("Sent close request.\n");
+ sent_close = 1;
+ return 2;
+}
+
+int cmd_packagename(char* arg)
+{
+ xfree (esPackageName);
+ esPackageName = NULL;
+ if (*arg)
+ {
+ esPackageName = (char *) xmalloc (strlen(arg)+1);
+ strcpy (esPackageName, arg);
+ }
+ return 1;
+}
+
+int cmd_proxy(char* arg)
+{
+ if (*arg == '\0') {
+ xfree (yazProxy);
+ yazProxy = NULL;
+
+ }
+ xfree (yazProxy);
+ yazProxy = NULL;
+ if (*arg)
+ {
+ yazProxy = (char *) xmalloc (strlen(arg)+1);
+ strcpy (yazProxy, arg);
+ }
+ return 1;
+}
+
+int cmd_charset(char* arg)
+{
+ char l1[30], l2[30];
+
+ *l1 = *l2 = 0;
+ if (sscanf(arg, "%29s %29s", l1, l2) < 1)
+ {
+ printf("Current character set is `%s'\n", (yazCharset) ? yazCharset:NULL);
+ return 1;
+ }
+ xfree (yazCharset);
+ yazCharset = NULL;
+ if (*l1)
+ yazCharset = xstrdup(l1);
+ if (*l2)
+ {
+ odr_set_charset (out, l1, l2);
+ odr_set_charset (in, l2, l1);
+ }
+ 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.. */
+ FILE* includeFile;
+ char line[1024], *cp;
+
+ {
+ char* args_end=(arg)+strlen(arg)-1;
+ while(isspace(*args_end))
+ {*args_end=0;
+ --args_end;};
+ }
+
+ REMOVE_TAILING_BLANKS(arg);
+
+ if(strlen(arg)<1) {
+ fprintf(stderr,"Error in source command use a filename\n");
+ return -1;
+ }
+
+ includeFile = fopen (arg, "r");
+
+ if(!includeFile) {
+ fprintf(stderr,"Unable to open file %s for reading\n",arg);
+ return -1;
+ }
+
+ while(!feof(includeFile)) {
+ memset(line,0,sizeof(line));
+ fgets(line,sizeof(line),includeFile);
+
+ if(strlen(line) < 2) continue;
+ if(line[0] == '#') continue;
+
+ if ((cp = strrchr (line, '\n')))
+ *cp = '\0';
+
+ process_cmd_line(line);
+ }
+
+ if(fclose(includeFile)<0) {
+ perror("unable to close include file");
+ exit(1);
+ }
+ return 1;
+}
+
+int cmd_subshell(char* args)
+{
+ if(strlen(args))
+ system(args);
+ else
+ system(getenv("SHELL"));
+
+ printf("\n");
+ return 1;
+}
+
+int cmd_set_apdufile(char* arg)
+{
+ REMOVE_TAILING_BLANKS(arg);
+
+ if(apdu_file && apdu_file != stderr) { /* don't close stdout*/
+ perror("unable to close apdu log file");
+ }
+ apdu_file=NULL;
+
+ if(strlen(arg)<1) {
+ return 1;
+ }
+
+ if(!strcmp(arg,"-"))
+ apdu_file=stderr;
+ else
+ apdu_file=fopen(arg, "a");
+
+ if(!apdu_file) {
+ perror("unable to open apdu log file no apdu log loaded");
+ } else {
+ odr_setprint(print, apdu_file);
+ }
+
+ return 1;
+}
+
+int cmd_set_cclfile(char* arg)
+{
+ FILE *inf;
+
+ REMOVE_TAILING_BLANKS(arg);
+
+ bibset = ccl_qual_mk ();
+ inf = fopen (arg, "r");
+ if (inf)
+ {
+ ccl_qual_file (bibset, inf);
+ fclose (inf);
+ }
+ strcpy(ccl_fields,arg);
+ return 0;
+}
+
+
+int cmd_set_auto_reconnect(char* arg)
+{
+ REMOVE_TAILING_BLANKS(arg);
+
+ if(strlen(arg)==0) {
+ auto_reconnect = ! auto_reconnect;
+ } else if(strcmp(arg,"on")==0) {
+ auto_reconnect = 1;
+ } else if(strcmp(arg,"off")==0) {
+ auto_reconnect = 0;
+ } else {
+ printf("Error use on or off\n");
+ return 1;
+ }
+
+ if (auto_reconnect)
+ printf("Set auto reconnect enabled.\n");
+ else
+ printf("Set auto reconnect disabled.\n");
+
+ return 0;
+}
+
+int cmd_set_marcdump(char* arg)
+{
+ if(marcdump && marcdump != stderr) { /* don't close stdout*/
+ perror("unable to close apdu log file");
+ }
+ marcdump=NULL;
+
+ if(strlen(arg)<1) {
+ return 1;
+ }
+
+ if(!strcmp(arg,"-"))
+ marcdump=stderr;
+ else
+ marcdump=fopen(arg, "a");
+
+ if(!marcdump) {
+ perror("unable to open apdu marcdump file no marcdump done\n");
+ }
+
+ return 1;
+}
+
+int cmd_set_proxy(char* arg)
+{
+ if(yazProxy) free(yazProxy);
+ yazProxy=NULL;
+
+ if(strlen(arg) > 1) {
+ yazProxy=strdup(arg);
+ }
+ return 1;
+}
+
+/*
+ this command takes 3 arge {name class oid}
+*/
+int cmd_register_oid(char* args) {
+ static struct {
+ char* className;
+ oid_class oclass;
+ } oid_classes[] = {
+ {"appctx",CLASS_APPCTX},
+ {"absyn",CLASS_ABSYN},
+ {"attset",CLASS_ATTSET},
+ {"transyn",CLASS_TRANSYN},
+ {"diagset",CLASS_DIAGSET},
+ {"recsyn",CLASS_RECSYN},
+ {"resform",CLASS_RESFORM},
+ {"accform",CLASS_ACCFORM},
+ {"extserv",CLASS_EXTSERV},
+ {"userinfo",CLASS_USERINFO},
+ {"elemspec",CLASS_ELEMSPEC},
+ {"varset",CLASS_VARSET},
+ {"schema",CLASS_SCHEMA},
+ {"tagset",CLASS_TAGSET},
+ {"general",CLASS_GENERAL},
+ {0,(enum oid_class) 0}
+ };
+ char oname_str[101], oclass_str[101], oid_str[101];
+ char* name;
+ int i;
+ oid_class oidclass = CLASS_GENERAL;
+ int val = 0, oid[OID_SIZE];
+ struct oident * new_oident=NULL;
+
+ if (sscanf (args, "%100[^ ] %100[^ ] %100s",
+ oname_str,oclass_str, oid_str) < 1) {
+ printf("Error in regristrate command \n");
+ return 0;
+ }
+
+ for (i = 0; oid_classes[i].className; i++) {
+ if (!strcmp(oid_classes[i].className, oclass_str))
+ {
+ oidclass=oid_classes[i].oclass;
+ break;
+ }
+ }
+
+ if(!(oid_classes[i].className)) {
+ printf("Unknonwn oid class %s\n",oclass_str);
+ return 0;
+ }
+
+ i = 0;
+ name = oid_str;
+ val = 0;
+
+ while (isdigit (*name))
+ {
+ val = val*10 + (*name - '0');
+ name++;
+ if (*name == '.')
+ {
+ if (i < OID_SIZE-1)
+ oid[i++] = val;
+ val = 0;
+ name++;
+ }
+ }
+ oid[i] = val;
+ oid[i+1] = -1;
+
+ new_oident=oid_addent (oid,PROTO_GENERAL,oidclass,oname_str,VAL_DYNAMIC);
+ if(strcmp(new_oident->desc,oname_str)) {
+ fprintf(stderr,"oid is already named as %s, regristration faild\n",
+ new_oident->desc);
+ }
+ return 1;
+}
+
+int cmd_push_command(char* arg)
+{
+#if HAVE_READLINE_HISTORY_H
+ if(strlen(arg)>1)
+ add_history(arg);
+#else
+ fprintf(stderr,"Not compiled with the readline/history module\n");
+#endif
+ return 1;
+}
+
+void source_rcfile()
+{
+ /* Look for a $HOME/.yazclientrc and source it if it exists */
+ struct stat statbuf;
+ char buffer[1000];
+ char* homedir=getenv("HOME");
+
+ if(!homedir) return;
+
+ sprintf(buffer,"%s/.yazclientrc",homedir);
+
+ if(stat(buffer,&statbuf)==0) {
+ cmd_source(buffer);
+ }
+
+ if(stat(".yazclientrc",&statbuf)==0) {
+ cmd_source(".yazclientrc");
+ }
+}
+
+
+static void initialize(void)
+{
+ FILE *inf;
+ int i;
+
+ if (!(out = odr_createmem(ODR_ENCODE)) ||
+ !(in = odr_createmem(ODR_DECODE)) ||
+ !(print = odr_createmem(ODR_PRINT)))
+ {
+ fprintf(stderr, "failed to allocate ODR streams\n");
+ exit(1);
+ }
+ oid_init();
+
+ setvbuf(stdout, 0, _IONBF, 0);
+ if (apdu_file)
+ odr_setprint(print, apdu_file);
+
+ bibset = ccl_qual_mk ();
+ inf = fopen (ccl_fields, "r");
+ if (inf)
+ {
+ ccl_qual_file (bibset, inf);
+ fclose (inf);
+ }
+ cmd_base("Default");
+
+#if HAVE_READLINE_READLINE_H
+ rl_attempted_completion_function = (CPPFunction*)readline_completer;
+#endif
+
+
+ for(i=0; i<maxOtherInfosSupported; ++i) {
+ extraOtherInfos[i].oidval = -1;
+ }
+
+ source_rcfile();
+}
+
+
+#if HAVE_GETTIMEOFDAY
+struct timeval tv_start, tv_end;
+#endif
+
+void wait_and_handle_responce()
+{
+
+ int res;
+ char *netbuffer= 0;
+ int netbufferlen = 0;
+ Z_APDU *apdu;
+
+
+ if (conn)
+ {
+ do
+ {
+ if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
+ {
+ printf("Target closed connection\n");
+ close_session ();
+ break;
+ }
+ if (!res)
+ {
+ printf("Target closed connection.\n");
+ close_session ();
+ break;
+ }
+ odr_reset(in); /* release APDU from last round */
+ record_last = 0;
+ odr_setbuf(in, netbuffer, res, 0);
+ if (!z_APDU(in, &apdu, 0, 0))
+ {
+ odr_perror(in, "Decoding incoming APDU");
+ fprintf(stderr, "[Near %d]\n", odr_offset(in));
+ fprintf(stderr, "Packet dump:\n---------\n");
+ odr_dumpBER(stderr, netbuffer, res);
+ fprintf(stderr, "---------\n");
+ if (apdu_file)
+ z_APDU(print, &apdu, 0, 0);
+ close_session ();
+ break;
+ }
+ if (apdu_file && !z_APDU(print, &apdu, 0, 0))
+ {
+ odr_perror(print, "Failed to print incoming APDU");
+ odr_reset(print);
+ continue;
+ }
+ switch(apdu->which)
+ {
+ case Z_APDU_initResponse:
+ process_initResponse(apdu->u.initResponse);
+ break;
+ case Z_APDU_searchResponse:
+ process_searchResponse(apdu->u.searchResponse);
+ break;
+ case Z_APDU_scanResponse:
+ process_scanResponse(apdu->u.scanResponse);
+ break;
+ case Z_APDU_presentResponse:
+ print_refid (apdu->u.presentResponse->referenceId);
+ setno +=
+ *apdu->u.presentResponse->numberOfRecordsReturned;
+ if (apdu->u.presentResponse->records)
+ display_records(apdu->u.presentResponse->records);
+ else
+ printf("No records.\n");
+ printf ("nextResultSetPosition = %d\n",
+ *apdu->u.presentResponse->nextResultSetPosition);
+ break;
+ case Z_APDU_sortResponse:
+ process_sortResponse(apdu->u.sortResponse);
+ break;
+ case Z_APDU_extendedServicesResponse:
+ printf("Got extended services response\n");
+ process_ESResponse(apdu->u.extendedServicesResponse);
+ break;
+ case Z_APDU_close:
+ printf("Target has closed the association.\n");
+ process_close(apdu->u.close);
+ break;
+ case Z_APDU_resourceControlRequest:
+ process_resourceControlRequest
+ (apdu->u.resourceControlRequest);
+ break;
+ case Z_APDU_deleteResultSetResponse:
+ process_deleteResultSetResponse(apdu->u.
+ deleteResultSetResponse);
+ break;
+ default:
+ printf("Received unknown APDU type (%d).\n",
+ apdu->which);
+ close_session ();
+ }
+ }
+ while (conn && cs_more(conn));
+#if HAVE_GETTIMEOFDAY
+ gettimeofday (&tv_end, 0);
+#if 0
+ printf ("S/U S/U=%ld/%ld %ld/%ld",
+ (long) tv_start.tv_sec,
+ (long) tv_start.tv_usec,
+ (long) tv_end.tv_sec,
+ (long) tv_end.tv_usec);
+#endif
+ printf ("Elapsed: %.6f\n",
+ (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
+ ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
+#endif
+ }
+ xfree (netbuffer);
+}
+
+
+int cmd_cclparse(char* arg)
+{
+ int error, pos;
+ struct ccl_rpn_node *rpn=NULL;
+
+
+ rpn = ccl_find_str (bibset, arg, &error, &pos);
+
+ if (error) {
+ printf ("%*s^ - ", 3+strlen(last_cmd)+1+pos, " ");
+ printf ("%s\n", ccl_err_msg (error));
+ }
+ else
+ {
+ if (rpn)
+ {
+ ccl_pr_tree(rpn, stdout);
+ }
+ }
+ if (rpn)
+ ccl_rpn_delete(rpn);
+
+ printf ("\n");
+
+ return 0;
+}
+
+
+int cmd_set_otherinfo(char* args)
+{
+ char oid[101], otherinfoString[101];
+ int otherinfoNo;
+ int sscan_res;
+ int oidval;
+
+ sscan_res = sscanf (args, "%d %100[^ ] %100s", &otherinfoNo, oid, otherinfoString);
+ if(sscan_res==1) {
+ /* reset this otherinfo */
+ if(otherinfoNo>=maxOtherInfosSupported) {
+ printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
+ }
+ extraOtherInfos[otherinfoNo].oidval = -1;
+ if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
+ return 0;
+ }
+ if (sscan_res<3) {
+ printf("Error in set_otherinfo command \n");
+ return 0;
+ }
+
+ if(otherinfoNo>=maxOtherInfosSupported) {
+ printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
+ }
+
+
+ oidval = oid_getvalbyname (oid);
+ if(oidval == -1 ) {
+ printf("Error in set_otherinfo command unknown oid %s \n",oid);
+ return 0;
+ }
+ extraOtherInfos[otherinfoNo].oidval = oidval;
+ if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
+ extraOtherInfos[otherinfoNo].value = strdup(otherinfoString);
+
+ return 0;
+}
+
+int cmd_list_otherinfo(char* args)
+{
+ int i;
+
+ if(strlen(args)>0) {
+ i = atoi(args);
+ if( i >= maxOtherInfosSupported ) {
+ printf("Error otherinfo index to large (%d>%d)\n",i,maxOtherInfosSupported);
+ return 0;
+ }
+
+ if(extraOtherInfos[i].oidval != -1)
+ printf(" otherinfo %d %s %s\n",
+ i,
+ yaz_z3950_oid_value_to_str(
+ (enum oid_value) extraOtherInfos[i].oidval,
+ CLASS_RECSYN),
+ extraOtherInfos[i].value);
+
+ } else {
+ for(i=0; i<maxOtherInfosSupported; ++i) {
+ if(extraOtherInfos[i].oidval != -1)
+ printf(" otherinfo %d %s %s\n",
+ i,
+ yaz_z3950_oid_value_to_str(
+ (enum oid_value) extraOtherInfos[i].oidval,
+ CLASS_RECSYN),
+ extraOtherInfos[i].value);
+ }
+
+ }
+ return 0;