+ *res->closeReason = Z_Close_finished;
+ send_apdu(apdu);
+ printf("Sent response.\n");
+ sent_close = 1;
+ }
+}
+
+static int cmd_show(const char *arg)
+{
+ if (protocol == PROTO_HTTP)
+ {
+#if YAZ_HAVE_XML2
+ if (!conn)
+ session_connect(cur_host);
+ if (!conn)
+ return 0;
+ if (!send_SRW_presentRequest(arg))
+ return 0;
+#else
+ return 0;
+#endif
+ }
+ else
+ {
+ if (!conn)
+ {
+ printf("Not connected yet\n");
+ return 0;
+ }
+ if (!send_Z3950_presentRequest(arg))
+ return 0;
+ }
+ return 2;
+}
+
+static void exit_client(int code)
+{
+ file_history_save(file_history);
+ file_history_destroy(&file_history);
+ nmem_destroy(nmem_auth);
+ exit(code);
+}
+
+static int cmd_quit(const char *arg)
+{
+ printf("See you later, alligator.\n");
+ xmalloc_trav("");
+ exit_client(0);
+ return 0;
+}
+
+static int cmd_cancel(const char *arg)
+{
+ if (only_z3950())
+ return 0;
+ else
+ {
+ Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
+ Z_TriggerResourceControlRequest *req =
+ apdu->u.triggerResourceControlRequest;
+ bool_t rfalse = 0;
+ char command[16];
+
+ *command = '\0';
+ sscanf(arg, "%15s", command);
+
+ if (only_z3950())
+ return 0;
+ if (session_initResponse &&
+ !ODR_MASK_GET(session_initResponse->options,
+ Z_Options_triggerResourceCtrl))
+ {
+ printf("Target doesn't support cancel (trigger resource ctrl)\n");
+ return 0;
+ }
+ *req->requestedAction = Z_TriggerResourceControlRequest_cancel;
+ req->resultSetWanted = &rfalse;
+ req->referenceId = set_refid(out);
+
+ send_apdu(apdu);
+ printf("Sent cancel request\n");
+ if (!strcmp(command, "wait"))
+ return 2;
+ return 1;
+ }
+}
+
+static int cmd_cancel_find(const char *arg)
+{
+ int fres;
+ if (only_z3950())
+ return 0;
+ fres = cmd_find(arg);
+ if (fres > 0)
+ {
+ return cmd_cancel("");
+ };
+ return fres;
+}
+
+static int send_Z3950_scanrequest(const char *set, const char *query,
+ Odr_int *pos, Odr_int num, const char *term)
+{
+ Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
+ Z_ScanRequest *req = apdu->u.scanRequest;
+
+ if (only_z3950())
+ return 0;
+ printf("query: %s\n", query);
+ if (queryType == QueryType_CCL2RPN)
+ {
+ 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;
+ }
+ req->attributeSet =
+ yaz_string_to_oid_odr(yaz_oid_std(),
+ CLASS_ATTSET, "Bib-1", out);
+ 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);
+ int ioff = off;
+ printf("%*s^\n", ioff+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 (queryCharset && outputCharset)
+ {
+ yaz_iconv_t cd = yaz_iconv_open(queryCharset, outputCharset);
+ if (!cd)
+ {
+ printf("Conversion from %s to %s unsupported\n",
+ outputCharset, queryCharset);
+ return -1;
+ }
+ yaz_query_charset_convert_apt(req->termListAndStartPoint, out, cd);
+ yaz_iconv_close(cd);
+ }
+ 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 = pos;
+ req->stepSize = odr_intdup(out, scan_stepSize);
+
+ if (set)
+ yaz_oi_set_string_oid(&req->otherInfo, out,
+ yaz_oid_userinfo_scan_set, 1, set);
+
+ send_apdu(apdu);
+ return 2;
+}
+
+static int send_sortrequest(const 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 (only_z3950())
+ return 0;
+ 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;
+}
+
+static void display_term_info(Z_TermInfo *t)
+{
+ if (t->displayTerm)
+ printf("%s", t->displayTerm);
+ else if (t->term->which == Z_Term_general)
+ printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
+ else
+ printf("Term (not general)");
+ if (t->term->which == Z_Term_general)
+ sprintf(last_scan_line, "%.*s", t->term->u.general->len,
+ t->term->u.general->buf);
+
+ if (t->globalOccurrences)
+ printf(" (" ODR_INT_PRINTF ")\n", *t->globalOccurrences);
+ else
+ printf("\n");
+}
+
+static void process_Z3950_scanResponse(Z_ScanResponse *res)
+{
+ int i;
+ Z_Entry **entries = NULL;
+ int num_entries = 0;
+
+ printf("Received ScanResponse\n");
+ print_refid(res->referenceId);
+ printf(ODR_INT_PRINTF " entries", *res->numberOfEntriesReturned);
+ if (res->positionOfTerm)
+ printf(", position=" ODR_INT_PRINTF, *res->positionOfTerm);
+ printf("\n");
+ if (*res->scanStatus != Z_Scan_success)
+ printf("Scan returned code " ODR_INT_PRINTF "\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_info(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);
+}
+
+static void process_Z3950_sortResponse(Z_SortResponse *res)
+{
+ printf("Received SortResponse: status=");
+ switch (*res->sortStatus)
+ {
+ case Z_SortResponse_success:
+ printf("success"); break;
+ case Z_SortResponse_partial_1:
+ printf("partial"); break;
+ case Z_SortResponse_failure:
+ printf("failure"); break;
+ default:
+ printf("unknown (" ODR_INT_PRINTF ")", *res->sortStatus);
+ }
+ printf("\n");
+ print_refid (res->referenceId);
+ if (res->diagnostics)
+ display_diagrecs(res->diagnostics,
+ res->num_diagnostics);
+}
+
+static void process_Z3950_deleteResultSetResponse(
+ Z_DeleteResultSetResponse *res)
+{
+ printf("Got deleteResultSetResponse status=" ODR_INT_PRINTF "\n",
+ *res->deleteOperationStatus);
+ if (res->deleteListStatuses)
+ {
+ int i;
+ for (i = 0; i < res->deleteListStatuses->num; i++)
+ {
+ printf("%s status=" ODR_INT_PRINTF "\n",
+ res->deleteListStatuses->elements[i]->id,
+ *res->deleteListStatuses->elements[i]->status);
+ }
+ }
+}
+
+static int cmd_sort_generic(const char *arg, int newset)
+{
+ if (only_z3950())
+ return 0;
+ if (session_initResponse &&
+ !ODR_MASK_GET(session_initResponse->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;
+}
+
+static int cmd_sort(const char *arg)
+{
+ return cmd_sort_generic(arg, 0);
+}
+
+static int cmd_sort_newset(const char *arg)
+{
+ return cmd_sort_generic(arg, 1);
+}
+
+static int cmd_scanstep(const char *arg)
+{
+ scan_stepSize = atoi(arg);
+ return 0;
+}
+
+static int cmd_scanpos(const char *arg)
+{
+ if (!strcmp(arg, "none"))
+ strcpy(scan_position, "none");
+ else
+ {
+ int dummy;
+ int r = sscanf(arg, "%d", &dummy);
+ if (r == 1 && strlen(arg) < sizeof(scan_position)-1)
+ strcpy(scan_position, arg);
+ else
+ printf("specify number of none for scanpos\n");
+ }
+ return 0;
+}
+
+static int cmd_scansize(const char *arg)
+{
+ int r = sscanf(arg, "%d", &scan_size);
+ if (r == 0)
+ scan_size = 20;
+ return 0;
+}
+
+static int cmd_scan_common(const char *set, const char *arg)
+{
+ Odr_int pos, *pos_p = 0;
+ const char *scan_term = 0;
+ const char *scan_query = 0;
+
+ if (!*arg)
+ {
+ pos = 1;
+ pos_p = &pos;
+ scan_query = last_scan_query;
+ scan_term = last_scan_line;
+ }
+ else
+ {
+ strcpy(last_scan_query, arg);
+ scan_query = arg;
+ if (strcmp(scan_position, "none"))
+ {
+ pos = odr_atoi(scan_position);
+ pos_p = &pos;
+ }
+ }
+
+ if (protocol == PROTO_HTTP)
+ {
+#if YAZ_HAVE_XML2
+ if (!conn)
+ session_connect(cur_host);
+ if (!conn)
+ return 0;
+ if (send_SRW_scanRequest(scan_query, pos_p, scan_size) < 0)
+ return 0;
+ return 2;
+#else
+ return 0;
+#endif
+ }
+ else
+ {
+ if (*cur_host && !conn && auto_reconnect)
+ {
+ session_connect(cur_host);
+ wait_and_handle_response(0);
+ }
+ if (!conn)
+ return 0;
+ if (session_initResponse &&
+ !ODR_MASK_GET(session_initResponse->options, Z_Options_scan))
+ {
+ printf("Target doesn't support scan\n");
+ return 0;
+ }
+ if (send_Z3950_scanrequest(set, scan_query, pos_p,
+ scan_size, scan_term) < 0)
+ return 0;
+ return 2;
+ }
+}
+
+static int cmd_scan(const char *arg)
+{
+ return cmd_scan_common(0, arg);
+}
+
+static int cmd_setscan(const char *arg)
+{
+ char setstring[100];
+ int nor;
+ if (sscanf(arg, "%99s%n", setstring, &nor) < 1)
+ {
+ printf("missing set for setscan\n");
+ return 0;
+ }
+ return cmd_scan_common(setstring, arg + nor);
+}
+
+static int cmd_schema(const char *arg)
+{
+ xfree(record_schema);
+ record_schema = 0;
+ if (arg && *arg)
+ record_schema = xstrdup(arg);
+ return 1;
+}
+
+static int cmd_format(const char *arg)
+{
+ const char *cp = arg;
+ int nor;
+ int idx = 0;
+ int i;
+ char form_str[41];
+ if (!arg || !*arg)
+ {
+ printf("Usage: format <recordsyntax>\n");
+ return 0;
+ }
+ while (sscanf(cp, "%40s%n", form_str, &nor) >= 1 && nor > 0
+ && idx < RECORDSYNTAX_MAX)
+ {
+ if (strcmp(form_str, "none") &&
+ !yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN, form_str, out))
+ {
+ printf("Bad format: %s\n", form_str);
+ return 0;
+ }
+ cp += nor;
+ }
+ for (i = 0; i < recordsyntax_size; i++)
+ {
+ xfree(recordsyntax_list[i]);
+ recordsyntax_list[i] = 0;
+ }
+
+ cp = arg;
+ while (sscanf(cp, "%40s%n", form_str, &nor) >= 1 && nor > 0
+ && idx < RECORDSYNTAX_MAX)
+ {
+ if (!strcmp(form_str, "none"))
+ break;
+ recordsyntax_list[idx] = xstrdup(form_str);
+ cp += nor;
+ idx++;
+ }
+ recordsyntax_size = idx;
+ return 1;
+}
+
+static int cmd_elements(const 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;
+}
+
+static int cmd_querytype(const 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 if (!strcmp(arg, "cql"))
+ queryType = QueryType_CQL;
+ else if (!strcmp(arg, "cql2rpn") || !strcmp(arg, "cqlrpn"))
+ queryType = QueryType_CQL2RPN;
+ 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");
+ printf(" cql - CQL\n");
+ printf(" cql2rpn - CQL query converted to RPN\n");
+ return 0;
+ }
+ return 1;
+}
+
+static int cmd_refid(const char *arg)
+{
+ xfree(refid);
+ refid = NULL;
+ if (*arg)
+ refid = xstrdup(arg);
+ return 1;
+}
+
+static int cmd_close(const char *arg)
+{
+ Z_APDU *apdu;
+ Z_Close *req;
+ if (only_z3950())
+ 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(const char* arg)
+{
+ xfree(esPackageName);
+ esPackageName = NULL;
+ if (*arg)
+ esPackageName = xstrdup(arg);
+ return 1;
+}
+
+static int cmd_proxy(const char* arg)
+{
+ xfree(yazProxy);
+ yazProxy = 0;
+ if (*arg)
+ yazProxy = xstrdup(arg);
+ return 1;
+}
+
+static int cmd_marccharset(const char *arg)
+{
+ char l1[30];
+
+ *l1 = 0;
+ if (sscanf(arg, "%29s", l1) < 1)
+ {
+ printf("MARC character set is `%s'\n",
+ marcCharset ? marcCharset: "none");
+ return 1;
+ }
+ xfree(marcCharset);
+ marcCharset = 0;
+ if (strcmp(l1, "-") && strcmp(l1, "none"))
+ marcCharset = xstrdup(l1);
+ return 1;
+}
+
+static int cmd_querycharset(const char *arg)
+{
+ char l1[30];
+
+ *l1 = 0;
+ if (sscanf(arg, "%29s", l1) < 1)
+ {
+ printf("Query character set is `%s'\n",
+ queryCharset ? queryCharset: "none");
+ return 1;
+ }
+ xfree(queryCharset);
+ queryCharset = 0;
+ if (strcmp(l1, "-") && strcmp(l1, "none"))
+ queryCharset = xstrdup(l1);
+ return 1;
+}
+
+static int cmd_displaycharset(const char *arg)
+{
+ char l1[30];
+
+ *l1 = 0;
+ if (sscanf(arg, "%29s", l1) < 1)
+ {
+ printf("Display character set is `%s'\n",
+ outputCharset ? outputCharset: "none");
+ }
+ else
+ {
+ xfree(outputCharset);
+ outputCharset = 0;
+ if (!strcmp(l1, "auto") && codeset)
+ {
+ if (codeset)
+ {
+ printf("Display character set: %s\n", codeset);
+ outputCharset = xstrdup(codeset);
+ }
+ else
+ printf("No codeset found on this system\n");
+ }
+ else if (strcmp(l1, "-") && strcmp(l1, "none"))
+ outputCharset = xstrdup(l1);
+ }
+ return 1;
+}
+
+static int cmd_negcharset(const char *arg)
+{
+ char l1[30];
+
+ *l1 = 0;
+ if (sscanf(arg, "%29s %d %d", l1, &negotiationCharsetRecords,
+ &negotiationCharsetVersion) < 1)
+ {
+ printf("Negotiation character set `%s'\n",
+ negotiationCharset ? negotiationCharset: "none");
+ if (negotiationCharset)
+ {
+ printf("Records in charset %s\n", negotiationCharsetRecords ?
+ "yes" : "no");
+ printf("Charneg version %d\n", negotiationCharsetVersion);
+ }
+ }
+ else
+ {
+ xfree(negotiationCharset);
+ negotiationCharset = NULL;
+ if (*l1 && strcmp(l1, "-") && strcmp(l1, "none"))
+ {
+ negotiationCharset = xstrdup(l1);
+ printf("Character set negotiation : %s\n", negotiationCharset);
+ }
+ }
+ return 1;
+}
+
+static int cmd_charset(const char* arg)
+{
+ char l1[30], l2[30], l3[30], l4[30];
+
+ *l1 = *l2 = *l3 = *l4 = '\0';
+ if (sscanf(arg, "%29s %29s %29s %29s", l1, l2, l3, l4) < 1)
+ {
+ cmd_negcharset("");
+ cmd_displaycharset("");
+ cmd_marccharset("");
+ cmd_querycharset("");
+ }
+ else
+ {
+ cmd_negcharset(l1);
+ if (*l2)
+ cmd_displaycharset(l2);
+ if (*l3)
+ cmd_marccharset(l3);
+ if (*l4)
+ cmd_querycharset(l4);
+ }
+ return 1;
+}
+
+static int cmd_lang(const char* arg)
+{
+ if (*arg == '\0')
+ {
+ printf("Current language is `%s'\n", yazLang ? yazLang : "none");
+ return 1;
+ }
+ xfree(yazLang);
+ yazLang = NULL;
+ if (*arg)
+ yazLang = xstrdup(arg);
+ return 1;
+}
+
+static int cmd_source(const char* arg, int echo )
+{
+ /* first should open the file and read one line at a time.. */
+ FILE* includeFile;
+ char line[102400], *cp;
+
+ 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 (fgets(line, sizeof(line), includeFile))
+ {
+ if (strlen(line) < 2)
+ continue;
+ if (line[0] == '#')
+ continue;
+
+ if ((cp = strrchr(line, '\n')))
+ *cp = '\0';
+
+ if (echo)
+ printf("processing line: %s\n", line);
+ process_cmd_line(line);
+ }
+
+ if (fclose(includeFile))
+ {
+ perror("unable to close include file");
+ exit(1);
+ }
+ return 1;
+}
+
+static int cmd_source_echo(const char* arg)
+{
+ cmd_source(arg, 1);
+ return 1;
+}
+
+static int cmd_subshell(const char* args)
+{
+ int ret = system(strlen(args) ? args : getenv("SHELL"));
+ printf("\n");
+ if (ret)
+ {
+ printf("Exit %d\n", ret);
+ }
+ return 1;
+}
+
+static int cmd_set_berfile(const char *arg)
+{
+ if (ber_file && ber_file != stdout && ber_file != stderr)
+ fclose(ber_file);
+ if (!strcmp(arg, ""))
+ ber_file = 0;
+ else if (!strcmp(arg, "-"))
+ ber_file = stdout;
+ else
+ ber_file = fopen(arg, "a");
+ return 1;
+}
+
+static int cmd_set_apdufile(const char *arg)
+{
+ if (apdu_file && apdu_file != stderr && apdu_file != stderr)
+ fclose(apdu_file);
+ if (!strcmp(arg, ""))
+ apdu_file = 0;
+ else if (!strcmp(arg, "-"))
+ apdu_file = stderr;
+ else
+ {
+ apdu_file = fopen(arg, "a");
+ if (!apdu_file)
+ perror("unable to open apdu log file");
+ }
+ if (apdu_file)
+ odr_setprint(print, apdu_file);
+ return 1;
+}
+
+static int cmd_set_cclfile(const char* arg)
+{
+ FILE *inf;
+
+ bibset = ccl_qual_mk();
+ inf = fopen(arg, "r");
+ if (!inf)
+ perror("unable to open CCL file");
+ else
+ {
+ ccl_qual_file(bibset, inf);
+ fclose(inf);
+ }
+ strcpy(ccl_fields,arg);
+ return 0;
+}
+
+static int cmd_set_cqlfile(const char* arg)
+{
+ cql_transform_t newcqltrans;
+
+ if ((newcqltrans = cql_transform_open_fname(arg)) == 0)
+ {
+ perror("unable to open CQL file");
+ return 0;
+ }
+ if (cqltrans != 0)
+ cql_transform_close(cqltrans);
+
+ cqltrans = newcqltrans;
+ strcpy(cql_fields, arg);
+ return 0;
+}
+
+static int cmd_set_auto_reconnect(const char* 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;
+}
+
+static int cmd_set_auto_wait(const char* arg)
+{
+ if (strlen(arg)==0)
+ auto_wait = ! auto_wait;
+ else if (strcmp(arg,"on")==0)
+ auto_wait = 1;
+ else if (strcmp(arg,"off")==0)
+ auto_wait = 0;
+ else
+ {
+ printf("Error use on or off\n");
+ return 1;
+ }
+
+ if (auto_wait)
+ printf("Set auto wait enabled.\n");
+ else
+ printf("Set auto wait disabled.\n");
+
+ return 0;
+}
+
+static int cmd_set_marcdump(const char* arg)
+{
+ if (marc_file && marc_file != stderr)
+ { /* don't close stdout*/
+ fclose(marc_file);
+ }
+
+ if (!strcmp(arg, ""))
+ marc_file = 0;
+ else if (!strcmp(arg, "-"))
+ marc_file = stderr;
+ else
+ {
+ marc_file = fopen(arg, "a");
+ if (!marc_file)
+ perror("unable to open marc log file");
+ }
+ return 1;
+}
+
+static void marc_file_write(const char *buf, size_t sz)
+{
+ if (marc_file)
+ {
+ if (fwrite(buf, 1, sz, marc_file) != sz)
+ {
+ perror("marcfile write");
+ }
+ }
+}
+/*
+ this command takes 3 arge {name class oid}
+*/
+static int cmd_register_oid(const 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];
+ int i;
+ oid_class oidclass = CLASS_GENERAL;
+ Odr_oid oid[OID_SIZE];
+
+ if (sscanf(args, "%100[^ ] %100[^ ] %100s",
+ oname_str,oclass_str, oid_str) < 1)
+ {
+ printf("Error in register 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("Unknown oid class %s\n",oclass_str);
+ return 0;
+ }
+
+ oid_dotstring_to_oid(oid_str, oid);
+
+ if (yaz_oid_add(yaz_oid_std(), oidclass, oname_str, oid))
+ {
+ printf("oid %s already exists, registration failed\n",
+ oname_str);