2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: client.c,v 1.296 2005-08-24 11:25:34 heikki Exp $
14 #include <sys/types.h>
32 #if HAVE_OPENSSL_SSL_H
33 #include <openssl/bio.h>
34 #include <openssl/crypto.h>
35 #include <openssl/x509.h>
36 #include <openssl/pem.h>
37 #include <openssl/ssl.h>
38 #include <openssl/err.h>
45 #define S_ISREG(x) (x & _S_IFREG)
46 #define S_ISDIR(x) (x & _S_IFDIR)
49 #include <yaz/yaz-util.h>
51 #include <yaz/comstack.h>
53 #include <yaz/proto.h>
54 #include <yaz/marcdisp.h>
55 #include <yaz/diagbib1.h>
56 #include <yaz/otherinfo.h>
57 #include <yaz/charneg.h>
59 #include <yaz/pquery.h>
60 #include <yaz/sortspec.h>
64 #include <yaz/yaz-ccl.h>
68 #if HAVE_READLINE_READLINE_H
69 #include <readline/readline.h>
71 #if HAVE_READLINE_HISTORY_H
72 #include <readline/history.h>
77 #include "tabcomplete.h"
79 #define C_PROMPT "Z> "
81 static char *codeset = 0; /* character set for output */
82 static int hex_dump = 0;
83 static char *dump_file_prefix = 0;
84 static ODR out, in, print; /* encoding and decoding streams */
86 static ODR srw_sr_odr_out = 0;
87 static Z_SRW_PDU *srw_sr = 0;
89 static FILE *apdu_file = 0;
90 static FILE *ber_file = 0;
91 static COMSTACK conn = 0; /* our z-association */
92 static Z_IdAuthentication *auth = 0; /* our current auth definition */
93 char *databaseNames[128];
94 int num_databaseNames = 0;
95 static Z_External *record_last = 0;
96 static int setnumber = -1; /* current result set number */
97 static int smallSetUpperBound = 0;
98 static int largeSetLowerBound = 1;
99 static int mediumSetPresentNumber = 0;
100 static Z_ElementSetNames *elementSetNames = 0;
101 static int setno = 1; /* current set offset */
102 static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */
103 static enum oid_value recordsyntax = VAL_USMARC;
104 static char *record_schema = 0;
105 static int sent_close = 0;
106 static NMEM session_mem = NULL; /* memory handle for init-response */
107 static Z_InitResponse *session_initResponse = 0; /* session parameters */
108 static char last_scan_line[512] = "0";
109 static char last_scan_query[512] = "0";
110 static char ccl_fields[512] = "default.bib";
111 /* ### How can I set this path to use wherever YAZ is installed? */
112 static char cql_fields[512] = "/usr/local/share/yaz/etc/pqf.properties";
113 static char *esPackageName = 0;
114 static char *yazProxy = 0;
115 static int kilobytes = 1024;
116 static char *negotiationCharset = 0;
117 static int negotiationCharsetRecords = 1;
118 static int negotiationCharsetVersion = 3;
119 static char *outputCharset = 0;
120 static char *marcCharset = 0;
121 static char* yazLang = 0;
122 static char* http_version = "1.1";
124 static char last_cmd[32] = "?";
125 static FILE *marc_file = 0;
126 static char *refid = NULL;
127 static char *last_open_command = NULL;
128 static int auto_reconnect = 0;
129 static int auto_wait = 1;
130 static Odr_bitmask z3950_options;
131 static int z3950_version = 3;
132 static int scan_stepSize = 0;
133 static int scan_position = 1;
134 static int scan_size = 20;
135 static char cur_host[200];
136 static int last_hit_count = 0;
146 static QueryType queryType = QueryType_Prefix;
148 static CCL_bibset bibset; /* CCL bibset handle */
149 static cql_transform_t cqltrans; /* CQL context-set handle */
151 #if HAVE_READLINE_COMPLETION_OVER
154 /* readline doesn't have this var. Define it ourselves. */
155 int rl_attempted_completion_over = 0;
158 /* set this one to 1, to avoid decode of unknown MARCs */
159 #define AVOID_MARC_DECODE 1
161 #define maxOtherInfosSupported 10
165 } extraOtherInfos[maxOtherInfosSupported];
168 void process_cmd_line(char* line);
169 char ** readline_completer(char *text, int start, int end);
170 char *command_generator(const char *text, int state);
171 char** curret_global_list=NULL;
172 int cmd_register_tab(const char* arg);
174 static void close_session (void);
176 ODR getODROutputStream()
181 const char* query_type_as_string(QueryType q)
184 case QueryType_Prefix: return "prefix (RPN sent to server)";
185 case QueryType_CCL: return "CCL (CCL sent to server) ";
186 case QueryType_CCL2RPN: return "CCL -> RPN (RPN sent to server)";
187 case QueryType_CQL: return "CQL (CQL sent to server)";
188 case QueryType_CQL2RPN: return "CQL -> RPN (RPN sent to server)";
190 return "unknown Query type internal yaz-client error";
194 static void do_hex_dump(const char* buf, int len)
199 for( i=0; i<len ; i=i+16 )
202 for(x=0 ; i+x<len && x<16; ++x)
204 printf("%2.2X ",(unsigned int)((unsigned char)buf[i+x]));
209 if (dump_file_prefix)
212 if (++no < 1000 && strlen(dump_file_prefix) < 500)
216 sprintf (fname, "%s.%03d.raw", dump_file_prefix, no);
217 of = fopen(fname, "wb");
219 fwrite (buf, 1, len, of);
226 void add_otherInfos(Z_APDU *a)
228 Z_OtherInformation **oi;
232 for(i=0; i<maxOtherInfosSupported; ++i)
234 if(extraOtherInfos[i].oidval != -1)
235 yaz_oi_set_string_oidval(oi, out, extraOtherInfos[i].oidval,
236 1, extraOtherInfos[i].value);
240 int send_apdu(Z_APDU *a)
249 z_APDU(print, &a, 0, 0);
252 if (!z_APDU(out, &a, 0, 0))
254 odr_perror(out, "Encoding APDU");
258 buf = odr_getbuf(out, &len, 0);
260 odr_dumpBER(ber_file, buf, len);
261 /* printf ("sending APDU of size %d\n", len); */
262 do_hex_dump(buf, len);
263 if (cs_put(conn, buf, len) < 0)
265 fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn)));
269 odr_reset(out); /* release the APDU structure */
273 static void print_stringn(const unsigned char *buf, size_t len)
276 for (i = 0; i<len; i++)
277 if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
278 printf ("%c", buf[i]);
280 printf ("\\X%02X", buf[i]);
283 static void print_refid (Z_ReferenceId *id)
287 printf ("Reference Id: ");
288 print_stringn (id->buf, id->len);
293 static Z_ReferenceId *set_refid (ODR out)
298 id = (Z_ReferenceId *) odr_malloc (out, sizeof(*id));
299 id->size = id->len = strlen(refid);
300 id->buf = (unsigned char *) odr_malloc (out, id->len);
301 memcpy (id->buf, refid, id->len);
305 /* INIT SERVICE ------------------------------- */
307 static void send_initRequest(const char* type_and_host)
309 Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest);
310 Z_InitRequest *req = apdu->u.initRequest;
313 req->options = &z3950_options;
315 ODR_MASK_ZERO(req->protocolVersion);
316 for (i = 0; i<z3950_version; i++)
317 ODR_MASK_SET(req->protocolVersion, i);
319 *req->maximumRecordSize = 1024*kilobytes;
320 *req->preferredMessageSize = 1024*kilobytes;
322 req->idAuthentication = auth;
324 req->referenceId = set_refid (out);
326 if (yazProxy && type_and_host)
327 yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
330 if (negotiationCharset || yazLang) {
331 Z_OtherInformation **p;
332 Z_OtherInformationUnit *p0;
334 yaz_oi_APDU(apdu, &p);
336 if ((p0=yaz_oi_update(p, out, NULL, 0, 0))) {
337 ODR_MASK_SET(req->options, Z_Options_negotiationModel);
339 p0->which = Z_OtherInfo_externallyDefinedInfo;
340 p0->information.externallyDefinedInfo =
341 yaz_set_proposal_charneg(
343 (const char**)&negotiationCharset,
344 negotiationCharset ? 1 : 0,
345 (const char**)&yazLang, yazLang ? 1 : 0,
346 negotiationCharsetRecords);
351 printf("Sent initrequest.\n");
355 /* These two are used only from process_initResponse() */
356 static void render_initUserInfo(Z_OtherInformation *ui1);
357 static void render_diag(Z_DiagnosticFormat *diag);
359 static void pr_opt(const char *opt, void *clientData)
364 static int process_initResponse(Z_InitResponse *res)
367 /* save session parameters for later use */
368 session_mem = odr_extract_mem(in);
369 session_initResponse = res;
371 for (ver = 0; ver < 8; ver++)
372 if (!ODR_MASK_GET(res->protocolVersion, ver))
376 printf("Connection rejected by v%d target.\n", ver);
378 printf("Connection accepted by v%d target.\n", ver);
379 if (res->implementationId)
380 printf("ID : %s\n", res->implementationId);
381 if (res->implementationName)
382 printf("Name : %s\n", res->implementationName);
383 if (res->implementationVersion)
384 printf("Version: %s\n", res->implementationVersion);
385 if (res->userInformationField)
387 Z_External *uif = res->userInformationField;
388 if (uif->which == Z_External_userInfo1) {
389 render_initUserInfo(uif->u.userInfo1);
391 printf("UserInformationfield:\n");
392 if (!z_External(print, (Z_External**)&uif, 0, 0))
394 odr_perror(print, "Printing userinfo\n");
397 if (uif->which == Z_External_octet) {
398 printf("Guessing visiblestring:\n");
399 printf("'%.*s'\n", uif->u.octet_aligned->len,
400 uif->u.octet_aligned->buf);
402 else if (uif->which == Z_External_single)
404 Odr_any *sat = uif->u.single_ASN1_type;
405 oident *oid = oid_getentbyoid(uif->direct_reference);
406 if (oid->value == VAL_OCLCUI) {
407 Z_OCLC_UserInformation *oclc_ui;
408 ODR decode = odr_createmem(ODR_DECODE);
409 odr_setbuf(decode, (char *) sat->buf, sat->len, 0);
410 if (!z_OCLC_UserInformation(decode, &oclc_ui, 0, 0))
411 printf ("Bad OCLC UserInformation:\n");
413 printf ("OCLC UserInformation:\n");
414 if (!z_OCLC_UserInformation(print, &oclc_ui, 0, 0))
415 printf ("Bad OCLC UserInformation spec\n");
420 /* Peek at any private Init-diagnostic APDUs */
421 printf("### NAUGHTY: External is '%.*s'\n",
429 yaz_init_opt_decode(res->options, pr_opt, 0);
432 if (ODR_MASK_GET(res->options, Z_Options_namedResultSets))
435 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) {
437 Z_CharSetandLanguageNegotiation *p =
438 yaz_get_charneg_record(res->otherInfo);
442 char *charset=NULL, *lang=NULL;
445 yaz_get_response_charneg(session_mem, p, &charset, &lang,
448 if (outputCharset && negotiationCharset) {
449 odr_set_charset (out, charset, outputCharset);
450 odr_set_charset (in, outputCharset, charset);
453 odr_set_charset (out, 0, 0);
454 odr_set_charset (in, 0, 0);
457 printf("Accepted character set : %s\n", charset);
458 printf("Accepted code language : %s\n", lang ? lang : "none");
459 printf("Accepted records in ...: %d\n", selected );
467 static void render_initUserInfo(Z_OtherInformation *ui1) {
469 printf("Init response contains %d otherInfo unit%s:\n",
470 ui1->num_elements, ui1->num_elements == 1 ? "" : "s");
472 for (i = 0; i < ui1->num_elements; i++) {
473 Z_OtherInformationUnit *unit = ui1->list[i];
474 printf(" %d: otherInfo unit contains ", i+1);
475 if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
476 unit->information.externallyDefinedInfo &&
477 unit->information.externallyDefinedInfo->which ==
479 render_diag(unit->information.externallyDefinedInfo->u.diag1);
481 else if (unit->which != Z_OtherInfo_externallyDefinedInfo)
483 printf("unsupported otherInfo unit->which = %d\n", unit->which);
487 printf("unsupported otherInfo unit external %d\n",
488 unit->information.externallyDefinedInfo ?
489 unit->information.externallyDefinedInfo->which : -2);
495 /* ### should this share code with display_diagrecs()? */
496 static void render_diag(Z_DiagnosticFormat *diag) {
499 printf("%d diagnostic%s:\n", diag->num, diag->num == 1 ? "" : "s");
500 for (i = 0; i < diag->num; i++) {
501 Z_DiagnosticFormat_s *ds = diag->elements[i];
502 printf(" %d: ", i+1);
504 case Z_DiagnosticFormat_s_defaultDiagRec: {
505 Z_DefaultDiagFormat *dd = ds->u.defaultDiagRec;
506 /* ### should check `dd->diagnosticSetId' */
507 printf("code=%d (%s)", *dd->condition,
508 diagbib1_str(*dd->condition));
509 /* Both types of addinfo are the same, so use type-pun */
510 if (dd->u.v2Addinfo != 0)
511 printf(",\n\taddinfo='%s'", dd->u.v2Addinfo);
514 case Z_DiagnosticFormat_s_explicitDiagnostic:
515 printf("Explicit diagnostic (not supported)");
518 printf("Unrecognised diagnostic type %d", ds->which);
522 if (ds->message != 0)
523 printf(", message='%s'", ds->message);
529 static int set_base(const char *arg)
534 for (i = 0; i<num_databaseNames; i++)
535 xfree (databaseNames[i]);
536 num_databaseNames = 0;
540 if (!(cp = strchr(arg, ' ')))
541 cp = arg + strlen(arg);
544 databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
545 memcpy (databaseNames[num_databaseNames], arg, cp - arg);
546 databaseNames[num_databaseNames][cp - arg] = '\0';
548 for (cp1 = databaseNames[num_databaseNames]; *cp1 ; cp1++)
557 if (num_databaseNames == 0)
559 num_databaseNames = 1;
560 databaseNames[0] = xstrdup("");
565 static int parse_cmd_doc(const char **arg, ODR out, char **buf,
569 while (**arg && strchr(" \t\n\r\f", **arg))
571 if ((*arg)[0] == '\"' && (sep=strchr(*arg+1, '"')))
575 *buf = odr_strdupn(out, *arg, *len);
579 else if ((*arg)[0] && (*arg)[0] != '\"')
583 const char *fname = *arg;
585 while (**arg != '\0' && **arg != ' ')
588 inf = fopen(fname, "rb");
591 printf("Couldn't open %s\n", fname);
594 if (fseek(inf, 0L, SEEK_END) == -1)
596 printf("Couldn't seek in %s\n", fname);
601 if (fseek(inf, 0L, SEEK_SET) == -1)
603 printf("Couldn't seek in %s\n", fname);
608 *buf = odr_malloc(out, fsize);
609 if (fread(*buf, 1, fsize, inf) != fsize)
611 printf("Unable to read %s\n", fname);
618 else if (**arg == '\0')
626 printf("Missing doc argument\n");
629 printf("Bad doc argument %s\n", *arg);
633 static int cmd_base(const char *arg)
637 printf("Usage: base <database> <database> ...\n");
640 return set_base(arg);
643 void cmd_open_remember_last_open_command(const char* arg, char* new_open_command)
645 if(last_open_command != arg)
647 if(last_open_command) xfree(last_open_command);
648 last_open_command = xstrdup(new_open_command);
652 int session_connect(const char *arg)
655 char type_and_host[101];
656 const char *basep = 0;
657 #if HAVE_OPENSSL_SSL_H
667 nmem_destroy (session_mem);
669 session_initResponse = 0;
671 cs_get_host_args(arg, &basep);
673 strncpy(type_and_host, arg, sizeof(type_and_host)-1);
674 type_and_host[sizeof(type_and_host)-1] = '\0';
676 cmd_open_remember_last_open_command(arg, type_and_host);
679 conn = cs_create_host(yazProxy, 1, &add);
681 conn = cs_create_host(arg, 1, &add);
684 printf ("Couldn't create comstack\n");
688 if (conn->protocol == PROTO_HTTP)
689 queryType = QueryType_CQL;
691 if (conn->protocol == PROTO_HTTP)
693 printf ("SRW/HTTP not enabled in this YAZ\n");
699 protocol = conn->protocol;
700 if (conn->protocol == PROTO_HTTP)
704 printf("Connecting...");
706 if (cs_connect(conn, add) < 0)
708 printf ("error = %s\n", cs_strerror(conn));
709 if (conn->cerrno == CSYSERR)
712 yaz_strerror(msg, sizeof(msg));
713 printf ("%s\n", msg);
720 #if HAVE_OPENSSL_SSL_H
721 if ((ssl = (SSL *) cs_get_ssl(conn)))
723 X509 *server_cert = SSL_get_peer_certificate (ssl);
729 BIO *bio = BIO_new(BIO_s_mem());
731 /* get PEM buffer in memory */
732 PEM_write_bio_X509(bio, server_cert);
733 pem_len = BIO_get_mem_data(bio, &pem_buf);
734 fwrite(pem_buf, pem_len, 1, stdout);
736 /* print all info on screen .. */
737 X509_print_fp(stdout, server_cert);
740 X509_free (server_cert);
746 if (protocol == PROTO_Z3950)
748 send_initRequest(type_and_host);
754 int cmd_open(const char *arg)
758 strncpy (cur_host, arg, sizeof(cur_host)-1);
759 cur_host[sizeof(cur_host)-1] = 0;
761 return session_connect(cur_host);
768 if(!( auto_reconnect && last_open_command) ) return ;
770 open_command = (char *) xmalloc (strlen(last_open_command)+6);
771 strcpy (open_command, "open ");
773 strcat (open_command, last_open_command);
775 process_cmd_line(open_command);
780 int cmd_authentication(const char *arg)
782 static Z_IdAuthentication au;
783 static char user[40], group[40], pass[40];
784 static Z_IdPass idPass;
789 printf("Auth field set to null\n");
793 r = sscanf (arg, "%39s %39s %39s", user, group, pass);
796 printf("Authentication set to null\n");
802 if (!strcmp(user, "-")) {
803 au.which = Z_IdAuthentication_anonymous;
804 printf("Authentication set to Anonymous\n");
806 au.which = Z_IdAuthentication_open;
808 printf("Authentication set to Open (%s)\n", user);
814 au.which = Z_IdAuthentication_idPass;
815 au.u.idPass = &idPass;
816 idPass.groupId = NULL;
817 idPass.userId = user;
818 idPass.password = group;
819 printf("Authentication set to User (%s), Pass (%s)\n", user, group);
824 au.which = Z_IdAuthentication_idPass;
825 au.u.idPass = &idPass;
826 idPass.groupId = group;
827 idPass.userId = user;
828 idPass.password = pass;
829 printf("Authentication set to User (%s), Group (%s), Pass (%s)\n",
835 /* SEARCH SERVICE ------------------------------ */
836 static void display_record(Z_External *r);
838 static void print_record(const unsigned char *buf, size_t len)
841 print_stringn (buf, len);
842 /* add newline if not already added ... */
843 if (i <= 0 || buf[i-1] != '\n')
847 static void display_record(Z_External *r)
849 oident *ent = oid_getentbyoid(r->direct_reference);
853 * Tell the user what we got.
855 if (r->direct_reference)
857 printf("Record type: ");
859 printf("%s\n", ent->desc);
860 else if (!odr_oid(print, &r->direct_reference, 0, 0))
862 odr_perror(print, "print oid");
866 /* Check if this is a known, ASN.1 type tucked away in an octet string */
867 if (ent && r->which == Z_External_octet)
869 Z_ext_typeent *type = z_ext_getentbyref(ent->value);
875 * Call the given decoder to process the record.
877 odr_setbuf(in, (char*)r->u.octet_aligned->buf,
878 r->u.octet_aligned->len, 0);
879 if (!(*type->fun)(in, &rr, 0, 0))
881 odr_perror(in, "Decoding constructed record.");
882 fprintf(stdout, "[Near %d]\n", odr_offset(in));
883 fprintf(stdout, "Packet dump:\n---------\n");
884 odr_dumpBER(stdout, (char*)r->u.octet_aligned->buf,
885 r->u.octet_aligned->len);
886 fprintf(stdout, "---------\n");
888 /* note just ignores the error ant print the bytes form the octet_aligned later */
891 * Note: we throw away the original, BER-encoded record here.
892 * Do something else with it if you want to keep it.
894 r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
895 r->which = type->what;
899 if (ent && ent->value == VAL_SOIF)
901 print_record((const unsigned char *) r->u.octet_aligned->buf,
902 r->u.octet_aligned->len);
904 fwrite (r->u.octet_aligned->buf, 1, r->u.octet_aligned->len, marc_file);
906 else if (r->which == Z_External_octet)
908 const char *octet_buf = (char*)r->u.octet_aligned->buf;
909 if (ent->oclass == CLASS_RECSYN &&
910 (ent->value == VAL_TEXT_XML ||
911 ent->value == VAL_APPLICATION_XML ||
912 ent->value == VAL_HTML))
914 print_record((const unsigned char *) octet_buf,
915 r->u.octet_aligned->len);
917 else if (ent->value == VAL_POSTSCRIPT)
919 int size = r->u.octet_aligned->len;
922 print_record((const unsigned char *) octet_buf, size);
927 #if AVOID_MARC_DECODE
928 /* primitive check for a marc OID 5.1-29 except 16 */
929 ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
930 ent->oidsuffix[1] != 16
939 yaz_marc_t mt = yaz_marc_create();
941 if (yaz_marc_decode_buf(mt, octet_buf,r->u.octet_aligned->len,
945 if (marcCharset && !strcmp(marcCharset, "auto"))
947 if (ent->value == VAL_USMARC)
949 if (octet_buf[9] == 'a')
957 else if (marcCharset)
959 if (outputCharset && from)
961 cd = yaz_iconv_open(outputCharset, from);
962 printf ("convert from %s to %s", from,
965 printf (" unsupported\n");
970 fwrite (result, 1, rlen, stdout);
974 size_t inbytesleft = rlen;
975 const char *inp = result;
979 size_t outbytesleft = sizeof(outbuf);
983 r = yaz_iconv (cd, (char**) &inp,
985 &outp, &outbytesleft);
986 if (r == (size_t) (-1))
988 int e = yaz_iconv_error(cd);
989 if (e != YAZ_ICONV_E2BIG)
992 fwrite (outbuf, outp - outbuf, 1, stdout);
998 printf ("bad MARC. Dumping as it is:\n");
999 print_record((const unsigned char*) octet_buf,
1000 r->u.octet_aligned->len);
1002 yaz_marc_destroy(mt);
1004 yaz_iconv_close(cd);
1008 print_record((const unsigned char*) octet_buf,
1009 r->u.octet_aligned->len);
1013 fwrite (octet_buf, 1, r->u.octet_aligned->len, marc_file);
1015 else if (ent && ent->value == VAL_SUTRS)
1017 if (r->which != Z_External_sutrs)
1019 printf("Expecting single SUTRS type for SUTRS.\n");
1022 print_record(r->u.sutrs->buf, r->u.sutrs->len);
1024 fwrite (r->u.sutrs->buf, 1, r->u.sutrs->len, marc_file);
1026 else if (ent && ent->value == VAL_GRS1)
1029 if (r->which != Z_External_grs1)
1031 printf("Expecting single GRS type for GRS.\n");
1035 yaz_display_grs1(w, r->u.grs1, 0);
1036 puts (wrbuf_buf(w));
1039 else if (ent && ent->value == VAL_OPAC)
1042 if (r->u.opac->bibliographicRecord)
1043 display_record(r->u.opac->bibliographicRecord);
1044 for (i = 0; i<r->u.opac->num_holdingsData; i++)
1046 Z_HoldingsRecord *h = r->u.opac->holdingsData[i];
1047 if (h->which == Z_HoldingsRecord_marcHoldingsRecord)
1049 printf ("MARC holdings %d\n", i);
1050 display_record(h->u.marcHoldingsRecord);
1052 else if (h->which == Z_HoldingsRecord_holdingsAndCirc)
1056 Z_HoldingsAndCircData *data = h->u.holdingsAndCirc;
1058 printf ("Data holdings %d\n", i);
1059 if (data->typeOfRecord)
1060 printf ("typeOfRecord: %s\n", data->typeOfRecord);
1061 if (data->encodingLevel)
1062 printf ("encodingLevel: %s\n", data->encodingLevel);
1063 if (data->receiptAcqStatus)
1064 printf ("receiptAcqStatus: %s\n", data->receiptAcqStatus);
1065 if (data->generalRetention)
1066 printf ("generalRetention: %s\n", data->generalRetention);
1067 if (data->completeness)
1068 printf ("completeness: %s\n", data->completeness);
1069 if (data->dateOfReport)
1070 printf ("dateOfReport: %s\n", data->dateOfReport);
1072 printf ("nucCode: %s\n", data->nucCode);
1073 if (data->localLocation)
1074 printf ("localLocation: %s\n", data->localLocation);
1075 if (data->shelvingLocation)
1076 printf ("shelvingLocation: %s\n", data->shelvingLocation);
1077 if (data->callNumber)
1078 printf ("callNumber: %s\n", data->callNumber);
1079 if (data->shelvingData)
1080 printf ("shelvingData: %s\n", data->shelvingData);
1081 if (data->copyNumber)
1082 printf ("copyNumber: %s\n", data->copyNumber);
1083 if (data->publicNote)
1084 printf ("publicNote: %s\n", data->publicNote);
1085 if (data->reproductionNote)
1086 printf ("reproductionNote: %s\n", data->reproductionNote);
1087 if (data->termsUseRepro)
1088 printf ("termsUseRepro: %s\n", data->termsUseRepro);
1089 if (data->enumAndChron)
1090 printf ("enumAndChron: %s\n", data->enumAndChron);
1091 for (j = 0; j<data->num_volumes; j++)
1093 printf ("volume %d\n", j);
1094 if (data->volumes[j]->enumeration)
1095 printf (" enumeration: %s\n",
1096 data->volumes[j]->enumeration);
1097 if (data->volumes[j]->chronology)
1098 printf (" chronology: %s\n",
1099 data->volumes[j]->chronology);
1100 if (data->volumes[j]->enumAndChron)
1101 printf (" enumAndChron: %s\n",
1102 data->volumes[j]->enumAndChron);
1104 for (j = 0; j<data->num_circulationData; j++)
1106 printf ("circulation %d\n", j);
1107 if (data->circulationData[j]->availableNow)
1108 printf (" availableNow: %d\n",
1109 *data->circulationData[j]->availableNow);
1110 if (data->circulationData[j]->availablityDate)
1111 printf (" availabiltyDate: %s\n",
1112 data->circulationData[j]->availablityDate);
1113 if (data->circulationData[j]->availableThru)
1114 printf (" availableThru: %s\n",
1115 data->circulationData[j]->availableThru);
1116 if (data->circulationData[j]->restrictions)
1117 printf (" restrictions: %s\n",
1118 data->circulationData[j]->restrictions);
1119 if (data->circulationData[j]->itemId)
1120 printf (" itemId: %s\n",
1121 data->circulationData[j]->itemId);
1122 if (data->circulationData[j]->renewable)
1123 printf (" renewable: %d\n",
1124 *data->circulationData[j]->renewable);
1125 if (data->circulationData[j]->onHold)
1126 printf (" onHold: %d\n",
1127 *data->circulationData[j]->onHold);
1128 if (data->circulationData[j]->enumAndChron)
1129 printf (" enumAndChron: %s\n",
1130 data->circulationData[j]->enumAndChron);
1131 if (data->circulationData[j]->midspine)
1132 printf (" midspine: %s\n",
1133 data->circulationData[j]->midspine);
1134 if (data->circulationData[j]->temporaryLocation)
1135 printf (" temporaryLocation: %s\n",
1136 data->circulationData[j]->temporaryLocation);
1143 printf("Unknown record representation.\n");
1144 if (!z_External(print, &r, 0, 0))
1146 odr_perror(print, "Printing external");
1152 static void display_diagrecs(Z_DiagRec **pp, int num)
1156 Z_DefaultDiagFormat *r;
1158 printf("Diagnostic message(s) from database:\n");
1159 for (i = 0; i<num; i++)
1161 Z_DiagRec *p = pp[i];
1162 if (p->which != Z_DiagRec_defaultFormat)
1164 printf("Diagnostic record not in default format.\n");
1168 r = p->u.defaultFormat;
1169 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
1170 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
1171 printf("Missing or unknown diagset\n");
1172 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
1175 case Z_DefaultDiagFormat_v2Addinfo:
1176 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
1178 case Z_DefaultDiagFormat_v3Addinfo:
1179 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
1186 static void display_nameplusrecord(Z_NamePlusRecord *p)
1188 if (p->databaseName)
1189 printf("[%s]", p->databaseName);
1190 if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
1191 display_diagrecs(&p->u.surrogateDiagnostic, 1);
1192 else if (p->which == Z_NamePlusRecord_databaseRecord)
1193 display_record(p->u.databaseRecord);
1196 static void display_records(Z_Records *p)
1200 if (p->which == Z_Records_NSD)
1202 Z_DiagRec dr, *dr_p = &dr;
1203 dr.which = Z_DiagRec_defaultFormat;
1204 dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
1205 display_diagrecs (&dr_p, 1);
1207 else if (p->which == Z_Records_multipleNSD)
1208 display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
1209 p->u.multipleNonSurDiagnostics->num_diagRecs);
1212 printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
1213 for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
1214 display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
1218 static int send_deleteResultSetRequest(const char *arg)
1223 Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
1224 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
1226 req->referenceId = set_refid (out);
1228 req->num_resultSetList =
1229 sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
1230 names[0], names[1], names[2], names[3],
1231 names[4], names[5], names[6], names[7]);
1233 req->deleteFunction = (int *)
1234 odr_malloc (out, sizeof(*req->deleteFunction));
1235 if (req->num_resultSetList > 0)
1237 *req->deleteFunction = Z_DeleteResultSetRequest_list;
1238 req->resultSetList = (char **)
1239 odr_malloc (out, sizeof(*req->resultSetList)*
1240 req->num_resultSetList);
1241 for (i = 0; i<req->num_resultSetList; i++)
1242 req->resultSetList[i] = names[i];
1246 *req->deleteFunction = Z_DeleteResultSetRequest_all;
1247 req->resultSetList = 0;
1251 printf("Sent deleteResultSetRequest.\n");
1256 static int send_srw(Z_SRW_PDU *sr)
1258 const char *charset = negotiationCharset;
1259 const char *host_port = cur_host;
1262 Z_SOAP_Handler h[2] = {
1263 {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec},
1266 ODR o = odr_createmem(ODR_ENCODE);
1268 Z_SOAP *p = odr_malloc(o, sizeof(*p));
1271 path = odr_malloc(out, strlen(databaseNames[0])+2);
1273 strcpy(path+1, databaseNames[0]);
1275 gdu = z_get_HTTP_Request(out);
1276 gdu->u.HTTP_Request->version = http_version;
1277 gdu->u.HTTP_Request->path = odr_strdup(out, path);
1281 const char *cp0 = strstr(host_port, "://");
1282 const char *cp1 = 0;
1288 cp1 = strchr(cp0, '/');
1290 cp1 = cp0+strlen(cp0);
1294 char *h = odr_malloc(out, cp1 - cp0 + 1);
1295 memcpy (h, cp0, cp1 - cp0);
1297 z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
1302 strcpy(ctype, "text/xml");
1303 if (charset && strlen(charset) < 20)
1305 strcat(ctype, "; charset=");
1306 strcat(ctype, charset);
1308 z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
1309 "Content-Type", ctype);
1310 z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
1311 "SOAPAction", "\"\"");
1312 p->which = Z_SOAP_generic;
1313 p->u.generic = odr_malloc(o, sizeof(*p->u.generic));
1314 p->u.generic->no = 0;
1315 p->u.generic->ns = 0;
1316 p->u.generic->p = sr;
1317 p->ns = "http://schemas.xmlsoap.org/soap/envelope/";
1319 ret = z_soap_codec_enc(o, &p,
1320 &gdu->u.HTTP_Request->content_buf,
1321 &gdu->u.HTTP_Request->content_len, h,
1324 if (z_GDU(out, &gdu, 0, 0))
1332 if (!z_GDU(print, &gdu, 0, 0))
1333 printf ("Failed to print outgoing APDU\n");
1336 buf_out = odr_getbuf(out, &len_out, 0);
1338 /* we don't odr_reset(out), since we may need the buffer again */
1340 do_hex_dump(buf_out, len_out);
1342 r = cs_put(conn, buf_out, len_out);
1354 static char *encode_SRW_term(ODR o, const char *q)
1356 const char *in_charset = "ISO-8859-1";
1357 WRBUF w = wrbuf_alloc();
1361 in_charset = outputCharset;
1362 cd = yaz_iconv_open("UTF-8", in_charset);
1366 return odr_strdup(o, q);
1368 wrbuf_iconv_write(w, cd, q, strlen(q));
1371 int len = wrbuf_len(w);
1372 res = odr_strdupn(o, wrbuf_buf(w), len);
1375 res = odr_strdup(o, q);
1376 yaz_iconv_close(cd);
1382 static int send_SRW_scanRequest(const char *arg, int pos, int num)
1386 /* regular requestse .. */
1387 sr = yaz_srw_get(out, Z_SRW_scan_request);
1392 sr->u.scan_request->query_type = Z_SRW_query_type_cql;
1393 sr->u.scan_request->scanClause.cql = encode_SRW_term(out, arg);
1395 case QueryType_Prefix:
1396 sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
1397 sr->u.scan_request->scanClause.pqf = encode_SRW_term(out, arg);
1400 printf ("Only CQL and PQF supported in SRW\n");
1403 sr->u.scan_request->responsePosition = odr_intdup(out, pos);
1404 sr->u.scan_request->maximumTerms = odr_intdup(out, num);
1405 return send_srw(sr);
1408 static int send_SRW_searchRequest(const char *arg)
1414 assert(srw_sr_odr_out == 0);
1415 srw_sr_odr_out = odr_createmem(ODR_ENCODE);
1417 odr_reset(srw_sr_odr_out);
1421 /* save this for later .. when fetching individual records */
1422 srw_sr = yaz_srw_get(srw_sr_odr_out, Z_SRW_searchRetrieve_request);
1424 /* regular request .. */
1425 sr = yaz_srw_get(out, Z_SRW_searchRetrieve_request);
1430 srw_sr->u.request->query_type = Z_SRW_query_type_cql;
1431 srw_sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg);
1433 sr->u.request->query_type = Z_SRW_query_type_cql;
1434 sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg);
1436 case QueryType_Prefix:
1437 srw_sr->u.request->query_type = Z_SRW_query_type_pqf;
1438 srw_sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg);
1440 sr->u.request->query_type = Z_SRW_query_type_pqf;
1441 sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg);
1444 printf ("Only CQL and PQF supported in SRW\n");
1447 sr->u.request->maximumRecords = odr_intdup(out, 0);
1450 sr->u.request->recordSchema = record_schema;
1451 if (recordsyntax == VAL_TEXT_XML)
1452 sr->u.explain_request->recordPacking = "xml";
1453 return send_srw(sr);
1457 static int send_searchRequest(const char *arg)
1459 Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
1460 Z_SearchRequest *req = apdu->u.searchRequest;
1462 struct ccl_rpn_node *rpn = NULL;
1464 char setstring[100];
1465 Z_RPNQuery *RPNquery;
1467 YAZ_PQF_Parser pqf_parser;
1469 QueryType myQueryType = queryType;
1472 if (myQueryType == QueryType_CCL2RPN)
1474 rpn = ccl_find_str(bibset, arg, &error, &pos);
1477 printf("CCL ERROR: %s\n", ccl_err_msg(error));
1480 } else if (myQueryType == QueryType_CQL2RPN) {
1481 /* ### All this code should be wrapped in a utility function */
1483 struct cql_node *node;
1484 const char *addinfo;
1485 if (cqltrans == 0) {
1486 printf("Can't use CQL: no translation file. Try set_cqlfile\n");
1489 parser = cql_parser_create();
1490 if ((error = cql_parser_string(parser, arg)) != 0) {
1491 printf("Can't parse CQL: must be a syntax error\n");
1494 node = cql_parser_result(parser);
1495 if ((error = cql_transform_buf(cqltrans, node, pqfbuf,
1496 sizeof pqfbuf)) != 0) {
1497 error = cql_transform_error(cqltrans, &addinfo);
1498 printf ("Can't convert CQL to PQF: %s (addinfo=%s)\n",
1499 cql_strerror(error), addinfo);
1503 myQueryType = QueryType_Prefix;
1506 req->referenceId = set_refid (out);
1507 if (!strcmp(arg, "@big")) /* strictly for troublemaking */
1509 static unsigned char big[2100];
1510 static Odr_oct bigo;
1512 /* send a very big referenceid to test transport stack etc. */
1513 memset(big, 'A', 2100);
1514 bigo.len = bigo.size = 2100;
1516 req->referenceId = &bigo;
1521 sprintf(setstring, "%d", ++setnumber);
1522 req->resultSetName = setstring;
1524 *req->smallSetUpperBound = smallSetUpperBound;
1525 *req->largeSetLowerBound = largeSetLowerBound;
1526 *req->mediumSetPresentNumber = mediumSetPresentNumber;
1527 if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
1528 mediumSetPresentNumber > 0))
1530 req->preferredRecordSyntax =
1531 yaz_oidval_to_z3950oid(out, CLASS_RECSYN, recordsyntax);
1533 req->smallSetElementSetNames =
1534 req->mediumSetElementSetNames = elementSetNames;
1536 req->num_databaseNames = num_databaseNames;
1537 req->databaseNames = databaseNames;
1539 req->query = &query;
1541 switch (myQueryType)
1543 case QueryType_Prefix:
1544 query.which = Z_Query_type_1;
1545 pqf_parser = yaz_pqf_create ();
1546 RPNquery = yaz_pqf_parse (pqf_parser, out, arg);
1549 const char *pqf_msg;
1551 int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
1552 printf("%*s^\n", off+4, "");
1553 printf("Prefix query error: %s (code %d)\n", pqf_msg, code);
1555 yaz_pqf_destroy (pqf_parser);
1558 yaz_pqf_destroy (pqf_parser);
1559 query.u.type_1 = RPNquery;
1562 query.which = Z_Query_type_2;
1563 query.u.type_2 = &ccl_query;
1564 ccl_query.buf = (unsigned char*) arg;
1565 ccl_query.len = strlen(arg);
1567 case QueryType_CCL2RPN:
1568 query.which = Z_Query_type_1;
1569 RPNquery = ccl_rpn_query(out, rpn);
1572 printf ("Couldn't convert from CCL to RPN\n");
1575 query.u.type_1 = RPNquery;
1576 ccl_rpn_delete (rpn);
1579 query.which = Z_Query_type_104;
1580 ext = (Z_External *) odr_malloc(out, sizeof(*ext));
1581 ext->direct_reference = odr_getoidbystr(out, "1.2.840.10003.16.2");
1582 ext->indirect_reference = 0;
1583 ext->descriptor = 0;
1584 ext->which = Z_External_CQL;
1585 ext->u.cql = odr_strdup(out, arg);
1586 query.u.type_104 = ext;
1589 printf ("Unsupported query type\n");
1592 if (send_apdu(apdu))
1593 printf("Sent searchRequest.\n");
1598 /* display Query Expression as part of searchResult-1 */
1599 static void display_queryExpression (Z_QueryExpression *qe)
1603 if (qe->which == Z_QueryExpression_term)
1605 if (qe->u.term->queryTerm)
1607 Z_Term *term = qe->u.term->queryTerm;
1608 switch (term->which)
1610 case Z_Term_general:
1611 printf (" %.*s", term->u.general->len, term->u.general->buf);
1613 case Z_Term_characterString:
1614 printf (" %s", term->u.characterString);
1616 case Z_Term_numeric:
1617 printf (" %d", *term->u.numeric);
1627 /* see if we can find USR:SearchResult-1 */
1628 static void display_searchResult (Z_OtherInformation *o)
1633 for (i = 0; i < o->num_elements; i++)
1635 if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
1637 Z_External *ext = o->list[i]->information.externallyDefinedInfo;
1639 if (ext->which == Z_External_searchResult1)
1642 Z_SearchInfoReport *sr = ext->u.searchResult1;
1643 printf ("SearchResult-1:");
1644 for (j = 0; j < sr->num; j++)
1646 if (!sr->elements[j]->subqueryExpression)
1648 display_queryExpression (
1649 sr->elements[j]->subqueryExpression);
1650 display_queryExpression (
1651 sr->elements[j]->subqueryInterpretation);
1652 display_queryExpression (
1653 sr->elements[j]->subqueryRecommendation);
1654 if (sr->elements[j]->subqueryCount)
1655 printf ("(%d)", *sr->elements[j]->subqueryCount);
1663 static int process_searchResponse(Z_SearchResponse *res)
1665 printf ("Received SearchResponse.\n");
1666 print_refid (res->referenceId);
1667 if (*res->searchStatus)
1668 printf("Search was a success.\n");
1670 printf("Search was a bloomin' failure.\n");
1671 printf("Number of hits: %d", *res->resultCount);
1672 last_hit_count = *res->resultCount;
1674 printf (", setno %d", setnumber);
1676 display_searchResult (res->additionalSearchInfo);
1677 printf("records returned: %d\n",
1678 *res->numberOfRecordsReturned);
1679 setno += *res->numberOfRecordsReturned;
1681 display_records(res->records);
1685 static void print_level(int iLevel)
1688 for (i = 0; i < iLevel * 4; i++)
1692 static void print_int(int iLevel, const char *pTag, int *pInt)
1696 print_level(iLevel);
1697 printf("%s: %d\n", pTag, *pInt);
1701 static void print_string(int iLevel, const char *pTag, const char *pString)
1703 if (pString != NULL)
1705 print_level(iLevel);
1706 printf("%s: %s\n", pTag, pString);
1710 static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
1716 print_level(iLevel);
1717 printf("%s:", pTag);
1718 for (; *pInt != -1; pInt++)
1719 printf(" %d", *pInt);
1724 static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
1726 if (referenceId != NULL)
1730 print_level(iLevel);
1731 printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
1732 for (i = 0; i < referenceId->len; i++)
1733 printf("%c", referenceId->buf[i]);
1738 static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
1740 if (pStringNumeric != NULL)
1742 switch (pStringNumeric->which)
1744 case Z_StringOrNumeric_string:
1745 print_string(iLevel, pTag, pStringNumeric->u.string);
1748 case Z_StringOrNumeric_numeric:
1749 print_int(iLevel, pTag, pStringNumeric->u.numeric);
1753 print_level(iLevel);
1754 printf("%s: valid type for Z_StringOrNumeric\n", pTag);
1760 static void print_universe_report_duplicate(
1762 Z_UniverseReportDuplicate *pUniverseReportDuplicate)
1764 if (pUniverseReportDuplicate != NULL)
1766 print_level(iLevel);
1767 printf("Universe Report Duplicate: \n");
1769 print_string_or_numeric(iLevel, "Hit No",
1770 pUniverseReportDuplicate->hitno);
1774 static void print_universe_report_hits(
1776 Z_UniverseReportHits *pUniverseReportHits)
1778 if (pUniverseReportHits != NULL)
1780 print_level(iLevel);
1781 printf("Universe Report Hits: \n");
1783 print_string_or_numeric(iLevel, "Database",
1784 pUniverseReportHits->database);
1785 print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
1789 static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
1791 if (pUniverseReport != NULL)
1793 print_level(iLevel);
1794 printf("Universe Report: \n");
1796 print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
1797 switch (pUniverseReport->which)
1799 case Z_UniverseReport_databaseHits:
1800 print_universe_report_hits(iLevel,
1801 pUniverseReport->u.databaseHits);
1804 case Z_UniverseReport_duplicate:
1805 print_universe_report_duplicate(iLevel,
1806 pUniverseReport->u.duplicate);
1810 print_level(iLevel);
1811 printf("Type: %d\n", pUniverseReport->which);
1817 static void print_external(int iLevel, Z_External *pExternal)
1819 if (pExternal != NULL)
1821 print_level(iLevel);
1822 printf("External: \n");
1824 print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
1825 print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
1826 print_string(iLevel, "Descriptor", pExternal->descriptor);
1827 switch (pExternal->which)
1829 case Z_External_universeReport:
1830 print_universe_report(iLevel, pExternal->u.universeReport);
1834 print_level(iLevel);
1835 printf("Type: %d\n", pExternal->which);
1841 static int process_resourceControlRequest (Z_ResourceControlRequest *req)
1843 printf ("Received ResourceControlRequest.\n");
1844 print_referenceId(1, req->referenceId);
1845 print_int(1, "Suspended Flag", req->suspendedFlag);
1846 print_int(1, "Partial Results Available", req->partialResultsAvailable);
1847 print_int(1, "Response Required", req->responseRequired);
1848 print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
1849 print_external(1, req->resourceReport);
1853 void process_ESResponse(Z_ExtendedServicesResponse *res)
1856 switch (*res->operationStatus)
1858 case Z_ExtendedServicesResponse_done:
1861 case Z_ExtendedServicesResponse_accepted:
1862 printf ("accepted\n");
1864 case Z_ExtendedServicesResponse_failure:
1865 printf ("failure\n");
1866 display_diagrecs(res->diagnostics, res->num_diagnostics);
1869 printf ("unknown\n");
1871 if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
1872 (res->num_diagnostics != 0) ) {
1873 display_diagrecs(res->diagnostics, res->num_diagnostics);
1875 print_refid (res->referenceId);
1876 if (res->taskPackage &&
1877 res->taskPackage->which == Z_External_extendedService)
1879 Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1880 Odr_oct *id = taskPackage->targetReference;
1881 Z_External *ext = taskPackage->taskSpecificParameters;
1885 printf ("Target Reference: ");
1886 print_stringn (id->buf, id->len);
1889 if (ext->which == Z_External_update)
1891 Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
1892 if (utp && utp->targetPart)
1894 Z_IUTargetPart *targetPart = utp->targetPart;
1897 for (i = 0; i<targetPart->num_taskPackageRecords; i++)
1900 Z_IUTaskPackageRecordStructure *tpr =
1901 targetPart->taskPackageRecords[i];
1902 printf ("task package record %d\n", i+1);
1903 if (tpr->which == Z_IUTaskPackageRecordStructure_record)
1905 display_record (tpr->u.record);
1909 printf ("other type\n");
1915 if (res->taskPackage && res->taskPackage->which == Z_External_octet)
1917 Odr_oct *doc = res->taskPackage->u.octet_aligned;
1918 printf("%.*s\n", doc->len, doc->buf);
1922 const char *get_ill_element (void *clientData, const char *element)
1927 static Z_External *create_external_itemRequest()
1929 struct ill_get_ctl ctl;
1930 ILL_ItemRequest *req;
1932 int item_request_size = 0;
1933 char *item_request_buf = 0;
1937 ctl.f = get_ill_element;
1939 req = ill_get_ItemRequest(&ctl, "ill", 0);
1941 printf ("ill_get_ItemRequest failed\n");
1943 if (!ill_ItemRequest (out, &req, 0, 0))
1947 ill_ItemRequest(print, &req, 0, 0);
1950 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1951 if (item_request_buf)
1952 odr_setbuf (out, item_request_buf, item_request_size, 1);
1953 printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
1960 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1961 oid.proto = PROTO_GENERAL;
1962 oid.oclass = CLASS_GENERAL;
1963 oid.value = VAL_ISO_ILL_1;
1965 r = (Z_External *) odr_malloc (out, sizeof(*r));
1966 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1967 r->indirect_reference = 0;
1969 r->which = Z_External_single;
1971 r->u.single_ASN1_type = (Odr_oct *)
1972 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1973 r->u.single_ASN1_type->buf = (unsigned char *)
1974 odr_malloc (out, item_request_size);
1975 r->u.single_ASN1_type->len = item_request_size;
1976 r->u.single_ASN1_type->size = item_request_size;
1977 memcpy (r->u.single_ASN1_type->buf, item_request_buf,
1980 do_hex_dump(item_request_buf,item_request_size);
1985 static Z_External *create_external_ILL_APDU(int which)
1987 struct ill_get_ctl ctl;
1990 int ill_request_size = 0;
1991 char *ill_request_buf = 0;
1995 ctl.f = get_ill_element;
1997 ill_apdu = ill_get_APDU(&ctl, "ill", 0);
1999 if (!ill_APDU (out, &ill_apdu, 0, 0))
2003 printf ("-------------------\n");
2004 ill_APDU(print, &ill_apdu, 0, 0);
2006 printf ("-------------------\n");
2008 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
2009 if (ill_request_buf)
2010 odr_setbuf (out, ill_request_buf, ill_request_size, 1);
2011 printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
2017 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
2019 oid.proto = PROTO_GENERAL;
2020 oid.oclass = CLASS_GENERAL;
2021 oid.value = VAL_ISO_ILL_1;
2023 r = (Z_External *) odr_malloc (out, sizeof(*r));
2024 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
2025 r->indirect_reference = 0;
2027 r->which = Z_External_single;
2029 r->u.single_ASN1_type = (Odr_oct *)
2030 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
2031 r->u.single_ASN1_type->buf = (unsigned char *)
2032 odr_malloc (out, ill_request_size);
2033 r->u.single_ASN1_type->len = ill_request_size;
2034 r->u.single_ASN1_type->size = ill_request_size;
2035 memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
2036 /* printf ("len = %d\n", ill_request_size); */
2037 /* do_hex_dump(ill_request_buf,ill_request_size); */
2038 /* printf("--- end of extenal\n"); */
2045 static Z_External *create_ItemOrderExternal(const char *type, int itemno)
2047 Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
2048 oident ItemOrderRequest;
2050 ItemOrderRequest.proto = PROTO_Z3950;
2051 ItemOrderRequest.oclass = CLASS_EXTSERV;
2052 ItemOrderRequest.value = VAL_ITEMORDER;
2054 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
2055 r->indirect_reference = 0;
2058 r->which = Z_External_itemOrder;
2060 r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder));
2061 memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder));
2062 r->u.itemOrder->which=Z_IOItemOrder_esRequest;
2064 r->u.itemOrder->u.esRequest = (Z_IORequest *)
2065 odr_malloc(out,sizeof(Z_IORequest));
2066 memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest));
2068 r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
2069 odr_malloc(out,sizeof(Z_IOOriginPartToKeep));
2070 memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep));
2071 r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
2072 odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep));
2073 memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep));
2075 r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL;
2076 r->u.itemOrder->u.esRequest->toKeep->contact = NULL;
2077 r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL;
2079 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem =
2080 (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem));
2081 memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem));
2082 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1";
2084 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item =
2085 (int *) odr_malloc(out, sizeof(int));
2086 *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
2088 if (!strcmp (type, "item") || !strcmp(type, "2"))
2090 printf ("using item-request\n");
2091 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
2092 create_external_itemRequest();
2094 else if (!strcmp(type, "ill") || !strcmp(type, "1"))
2096 printf ("using ILL-request\n");
2097 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
2098 create_external_ILL_APDU(ILL_APDU_ILL_Request);
2100 else if (!strcmp(type, "xml") || !strcmp(type, "3"))
2102 const char *xml_buf =
2104 " <type>request</type>\n"
2105 " <libraryNo>000200</libraryNo>\n"
2106 " <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
2108 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
2109 z_ext_record (out, VAL_TEXT_XML, xml_buf, strlen(xml_buf));
2112 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
2117 static int send_itemorder(const char *type, int itemno)
2119 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
2120 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
2121 oident ItemOrderRequest;
2123 ItemOrderRequest.proto = PROTO_Z3950;
2124 ItemOrderRequest.oclass = CLASS_EXTSERV;
2125 ItemOrderRequest.value = VAL_ITEMORDER;
2126 req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
2127 req->packageName = esPackageName;
2129 req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
2135 static int only_z3950()
2139 printf ("Not connected yet\n");
2142 if (protocol == PROTO_HTTP)
2144 printf ("Not supported by SRW\n");
2150 static int cmd_update_common(const char *arg, int version);
2152 static int cmd_update(const char *arg)
2154 return cmd_update_common(arg, 1);
2157 static int cmd_update0(const char *arg)
2159 return cmd_update_common(arg, 0);
2162 static int cmd_update_common(const char *arg, int version)
2164 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
2165 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
2167 char action[20], recid[20];
2172 Z_External *record_this = 0;
2178 sscanf (arg, "%19s %19s%n", action, recid, &noread);
2181 printf("Update must be followed by action and recid\n");
2182 printf(" where action is one of insert,replace,delete.update\n");
2183 printf(" recid is some record ID (any string)\n");
2187 if (!strcmp (action, "insert"))
2188 action_no = Z_IUOriginPartToKeep_recordInsert;
2189 else if (!strcmp (action, "replace"))
2190 action_no = Z_IUOriginPartToKeep_recordReplace;
2191 else if (!strcmp (action, "delete"))
2192 action_no = Z_IUOriginPartToKeep_recordDelete;
2193 else if (!strcmp (action, "update"))
2194 action_no = Z_IUOriginPartToKeep_specialUpdate;
2197 printf ("Bad action: %s\n", action);
2198 printf ("Possible values: insert, replace, delete, update\n");
2203 if (parse_cmd_doc(&arg, out, &rec_buf, &rec_len, 1) == 0)
2207 record_this = z_ext_record (out, VAL_TEXT_XML, rec_buf, rec_len);
2212 printf ("No last record (update ignored)\n");
2215 record_this = record_last;
2219 yaz_oidval_to_z3950oid(out, CLASS_EXTSERV,
2220 version == 0 ? VAL_DBUPDATE0 : VAL_DBUPDATE);
2222 req->packageName = esPackageName;
2224 req->referenceId = set_refid (out);
2226 r = req->taskSpecificParameters = (Z_External *)
2227 odr_malloc (out, sizeof(*r));
2228 r->direct_reference = req->packageType;
2229 r->indirect_reference = 0;
2233 Z_IU0OriginPartToKeep *toKeep;
2234 Z_IU0SuppliedRecords *notToKeep;
2236 r->which = Z_External_update0;
2237 r->u.update0 = (Z_IU0Update *) odr_malloc(out, sizeof(*r->u.update0));
2238 r->u.update0->which = Z_IUUpdate_esRequest;
2239 r->u.update0->u.esRequest = (Z_IU0UpdateEsRequest *)
2240 odr_malloc(out, sizeof(*r->u.update0->u.esRequest));
2241 toKeep = r->u.update0->u.esRequest->toKeep = (Z_IU0OriginPartToKeep *)
2242 odr_malloc(out, sizeof(*r->u.update0->u.esRequest->toKeep));
2244 toKeep->databaseName = databaseNames[0];
2246 toKeep->elementSetName = 0;
2248 toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
2249 *toKeep->action = action_no;
2251 notToKeep = r->u.update0->u.esRequest->notToKeep = (Z_IU0SuppliedRecords *)
2252 odr_malloc(out, sizeof(*r->u.update0->u.esRequest->notToKeep));
2254 notToKeep->elements = (Z_IU0SuppliedRecords_elem **)
2255 odr_malloc(out, sizeof(*notToKeep->elements));
2256 notToKeep->elements[0] = (Z_IU0SuppliedRecords_elem *)
2257 odr_malloc(out, sizeof(**notToKeep->elements));
2258 notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
2261 notToKeep->elements[0]->u.opaque = (Odr_oct *)
2262 odr_malloc (out, sizeof(Odr_oct));
2263 notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid;
2264 notToKeep->elements[0]->u.opaque->size = strlen(recid);
2265 notToKeep->elements[0]->u.opaque->len = strlen(recid);
2268 notToKeep->elements[0]->u.opaque = 0;
2269 notToKeep->elements[0]->supplementalId = 0;
2270 notToKeep->elements[0]->correlationInfo = 0;
2271 notToKeep->elements[0]->record = record_this;
2275 Z_IUOriginPartToKeep *toKeep;
2276 Z_IUSuppliedRecords *notToKeep;
2278 r->which = Z_External_update;
2279 r->u.update = (Z_IUUpdate *) odr_malloc(out, sizeof(*r->u.update));
2280 r->u.update->which = Z_IUUpdate_esRequest;
2281 r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
2282 odr_malloc(out, sizeof(*r->u.update->u.esRequest));
2283 toKeep = r->u.update->u.esRequest->toKeep = (Z_IUOriginPartToKeep *)
2284 odr_malloc(out, sizeof(*r->u.update->u.esRequest->toKeep));
2286 toKeep->databaseName = databaseNames[0];
2288 toKeep->elementSetName = 0;
2289 toKeep->actionQualifier = 0;
2290 toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
2291 *toKeep->action = action_no;
2293 notToKeep = r->u.update->u.esRequest->notToKeep = (Z_IUSuppliedRecords *)
2294 odr_malloc(out, sizeof(*r->u.update->u.esRequest->notToKeep));
2296 notToKeep->elements = (Z_IUSuppliedRecords_elem **)
2297 odr_malloc(out, sizeof(*notToKeep->elements));
2298 notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
2299 odr_malloc(out, sizeof(**notToKeep->elements));
2300 notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
2303 notToKeep->elements[0]->u.opaque = (Odr_oct *)
2304 odr_malloc (out, sizeof(Odr_oct));
2305 notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid;
2306 notToKeep->elements[0]->u.opaque->size = strlen(recid);
2307 notToKeep->elements[0]->u.opaque->len = strlen(recid);
2310 notToKeep->elements[0]->u.opaque = 0;
2311 notToKeep->elements[0]->supplementalId = 0;
2312 notToKeep->elements[0]->correlationInfo = 0;
2313 notToKeep->elements[0]->record = record_this;
2321 static int cmd_xmles(const char *arg)
2329 int oid_value_xmles = VAL_XMLES;
2330 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
2331 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
2333 Z_External *ext = (Z_External *) odr_malloc(out, sizeof(*ext));
2335 req->taskSpecificParameters = ext;
2336 ext->indirect_reference = 0;
2337 ext->descriptor = 0;
2338 ext->which = Z_External_octet;
2339 ext->u.single_ASN1_type = (Odr_oct *) odr_malloc (out, sizeof(Odr_oct));
2340 sscanf(arg, "%50s%n", oid_str, &noread);
2343 printf("Missing OID for xmles\n");
2347 oid_value_xmles = oid_getvalbyname(oid_str);
2348 if (oid_value_xmles == VAL_NONE)
2350 printf("Bad OID: %s\n", oid_str);
2354 if (parse_cmd_doc(&arg, out, (char **) &ext->u.single_ASN1_type->buf,
2355 &ext->u.single_ASN1_type->len, 0) == 0)
2357 req->packageType = yaz_oidval_to_z3950oid(out, CLASS_EXTSERV,
2360 ext->direct_reference = yaz_oidval_to_z3950oid(out, CLASS_EXTSERV,
2368 static int cmd_itemorder(const char *arg)
2375 if (sscanf (arg, "%10s %d", type, &itemno) != 2)
2378 printf("Item order request\n");
2380 send_itemorder(type, itemno);
2384 static void show_opt(const char *arg, void *clientData)
2386 printf ("%s ", arg);
2389 static int cmd_zversion(const char *arg)
2392 z3950_version = atoi(arg);
2394 printf ("version is %d\n", z3950_version);
2398 static int cmd_options(const char *arg)
2404 r = yaz_init_opt_encode(&z3950_options, arg, &pos);
2406 printf("Unknown option(s) near %s\n", arg+pos);
2410 yaz_init_opt_decode(&z3950_options, show_opt, 0);
2416 static int cmd_explain(const char *arg)
2418 if (protocol != PROTO_HTTP)
2429 /* save this for later .. when fetching individual records */
2430 sr = yaz_srw_get(out, Z_SRW_explain_request);
2431 if (recordsyntax == VAL_TEXT_XML)
2432 sr->u.explain_request->recordPacking = "xml";
2440 static int cmd_init(const char *arg)
2444 strncpy (cur_host, arg, sizeof(cur_host)-1);
2445 cur_host[sizeof(cur_host)-1] = 0;
2449 send_initRequest(cur_host);
2453 static int cmd_find(const char *arg)
2457 printf("Find what?\n");
2460 if (protocol == PROTO_HTTP)
2467 if (!send_SRW_searchRequest(arg))
2480 printf("Not connected yet\n");
2484 if (!send_searchRequest(arg))
2490 static int cmd_delete(const char *arg)
2494 if (!send_deleteResultSetRequest(arg))
2499 static int cmd_ssub(const char *arg)
2501 if (!(smallSetUpperBound = atoi(arg)))
2506 static int cmd_lslb(const char *arg)
2508 if (!(largeSetLowerBound = atoi(arg)))
2513 static int cmd_mspn(const char *arg)
2515 if (!(mediumSetPresentNumber = atoi(arg)))
2520 static int cmd_status(const char *arg)
2522 printf("smallSetUpperBound: %d\n", smallSetUpperBound);
2523 printf("largeSetLowerBound: %d\n", largeSetLowerBound);
2524 printf("mediumSetPresentNumber: %d\n", mediumSetPresentNumber);
2528 static int cmd_setnames(const char *arg)
2530 if (*arg == '1') /* enable ? */
2532 else if (*arg == '0') /* disable ? */
2534 else if (setnumber < 0) /* no args, toggle .. */
2540 printf("Set numbering enabled.\n");
2542 printf("Set numbering disabled.\n");
2546 /* PRESENT SERVICE ----------------------------- */
2548 static void parse_show_args(const char *arg_c, char *setstring,
2549 int *start, int *number)
2554 strncpy(arg, arg_c, sizeof(arg)-1);
2555 arg[sizeof(arg)-1] = '\0';
2557 if ((p = strchr(arg, '+')))
2559 *number = atoi(p + 1);
2564 if (!strcmp(arg, "all"))
2566 *number = last_hit_count;
2572 if (p && (p=strchr(p+1, '+')))
2573 strcpy (setstring, p+1);
2574 else if (setnumber >= 0)
2575 sprintf(setstring, "%d", setnumber);
2580 static int send_presentRequest(const char *arg)
2582 Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
2583 Z_PresentRequest *req = apdu->u.presentRequest;
2584 Z_RecordComposition compo;
2586 char setstring[100];
2588 req->referenceId = set_refid (out);
2590 parse_show_args(arg, setstring, &setno, &nos);
2592 req->resultSetId = setstring;
2594 req->resultSetStartPoint = &setno;
2595 req->numberOfRecordsRequested = &nos;
2597 req->preferredRecordSyntax =
2598 yaz_oidval_to_z3950oid(out, CLASS_RECSYN, recordsyntax);
2602 req->recordComposition = &compo;
2603 compo.which = Z_RecordComp_complex;
2604 compo.u.complex = (Z_CompSpec *)
2605 odr_malloc(out, sizeof(*compo.u.complex));
2606 compo.u.complex->selectAlternativeSyntax = (bool_t *)
2607 odr_malloc(out, sizeof(bool_t));
2608 *compo.u.complex->selectAlternativeSyntax = 0;
2610 compo.u.complex->generic = (Z_Specification *)
2611 odr_malloc(out, sizeof(*compo.u.complex->generic));
2612 compo.u.complex->generic->which = Z_Schema_oid;
2614 compo.u.complex->generic->schema.oid =
2615 yaz_str_to_z3950oid(out, CLASS_SCHEMA, record_schema);
2617 if (!compo.u.complex->generic->schema.oid)
2619 /* OID wasn't a schema! Try record syntax instead. */
2620 compo.u.complex->generic->schema.oid = (Odr_oid *)
2621 yaz_str_to_z3950oid(out, CLASS_RECSYN, record_schema);
2623 if (!elementSetNames)
2624 compo.u.complex->generic->elementSpec = 0;
2627 compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
2628 odr_malloc(out, sizeof(Z_ElementSpec));
2629 compo.u.complex->generic->elementSpec->which =
2630 Z_ElementSpec_elementSetName;
2631 compo.u.complex->generic->elementSpec->u.elementSetName =
2632 elementSetNames->u.generic;
2634 compo.u.complex->num_dbSpecific = 0;
2635 compo.u.complex->dbSpecific = 0;
2636 compo.u.complex->num_recordSyntax = 0;
2637 compo.u.complex->recordSyntax = 0;
2639 else if (elementSetNames)
2641 req->recordComposition = &compo;
2642 compo.which = Z_RecordComp_simple;
2643 compo.u.simple = elementSetNames;
2646 printf("Sent presentRequest (%d+%d).\n", setno, nos);
2651 static int send_SRW_presentRequest(const char *arg)
2653 char setstring[100];
2655 Z_SRW_PDU *sr = srw_sr;
2659 parse_show_args(arg, setstring, &setno, &nos);
2660 sr->u.request->startRecord = odr_intdup(out, setno);
2661 sr->u.request->maximumRecords = odr_intdup(out, nos);
2663 sr->u.request->recordSchema = record_schema;
2664 if (recordsyntax == VAL_TEXT_XML)
2665 sr->u.request->recordPacking = "xml";
2666 return send_srw(sr);
2670 static void close_session (void)
2682 void process_close(Z_Close *req)
2684 Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
2685 Z_Close *res = apdu->u.close;
2687 static char *reasons[] =
2692 "cost limit reached",
2694 "security violation",
2701 printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
2702 req->diagnosticInformation ? req->diagnosticInformation : "NULL");
2707 *res->closeReason = Z_Close_finished;
2709 printf("Sent response.\n");
2714 static int cmd_show(const char *arg)
2716 if (protocol == PROTO_HTTP)
2723 if (!send_SRW_presentRequest(arg))
2733 printf("Not connected yet\n");
2736 if (!send_presentRequest(arg))
2742 int cmd_quit(const char *arg)
2744 printf("See you later, alligator.\n");
2750 int cmd_cancel(const char *arg)
2752 Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
2753 Z_TriggerResourceControlRequest *req =
2754 apdu->u.triggerResourceControlRequest;
2759 if (session_initResponse &&
2760 !ODR_MASK_GET(session_initResponse->options,
2761 Z_Options_triggerResourceCtrl))
2763 printf("Target doesn't support cancel (trigger resource ctrl)\n");
2766 *req->requestedAction = Z_TriggerResourceControlRequest_cancel;
2767 req->resultSetWanted = &rfalse;
2768 req->referenceId = set_refid (out);
2771 printf("Sent cancel request\n");
2776 int cmd_cancel_find(const char *arg) {
2780 return cmd_cancel("");
2785 int send_scanrequest(const char *query, int pp, int num, const char *term)
2787 Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
2788 Z_ScanRequest *req = apdu->u.scanRequest;
2792 if (queryType == QueryType_CCL2RPN)
2795 struct ccl_rpn_node *rpn;
2797 rpn = ccl_find_str (bibset, query, &error, &pos);
2800 printf("CCL ERROR: %s\n", ccl_err_msg(error));
2804 yaz_oidval_to_z3950oid(out, CLASS_ATTSET, VAL_BIB1);
2805 if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
2807 printf("Couldn't convert CCL to Scan term\n");
2810 ccl_rpn_delete (rpn);
2814 YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
2816 if (!(req->termListAndStartPoint =
2817 yaz_pqf_scan(pqf_parser, out, &req->attributeSet, query)))
2819 const char *pqf_msg;
2821 int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
2822 printf("%*s^\n", off+7, "");
2823 printf("Prefix query error: %s (code %d)\n", pqf_msg, code);
2824 yaz_pqf_destroy (pqf_parser);
2827 yaz_pqf_destroy (pqf_parser);
2831 if (req->termListAndStartPoint->term &&
2832 req->termListAndStartPoint->term->which == Z_Term_general &&
2833 req->termListAndStartPoint->term->u.general)
2835 req->termListAndStartPoint->term->u.general->buf =
2836 (unsigned char *) odr_strdup(out, term);
2837 req->termListAndStartPoint->term->u.general->len =
2838 req->termListAndStartPoint->term->u.general->size =
2842 req->referenceId = set_refid (out);
2843 req->num_databaseNames = num_databaseNames;
2844 req->databaseNames = databaseNames;
2845 req->numberOfTermsRequested = #
2846 req->preferredPositionInResponse = &pp;
2847 req->stepSize = odr_intdup(out, scan_stepSize);
2852 int send_sortrequest(const char *arg, int newset)
2854 Z_APDU *apdu = zget_APDU(out, Z_APDU_sortRequest);
2855 Z_SortRequest *req = apdu->u.sortRequest;
2856 Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
2857 odr_malloc (out, sizeof(*sksl));
2863 sprintf (setstring, "%d", setnumber);
2865 sprintf (setstring, "default");
2867 req->referenceId = set_refid (out);
2869 req->num_inputResultSetNames = 1;
2870 req->inputResultSetNames = (Z_InternationalString **)
2871 odr_malloc (out, sizeof(*req->inputResultSetNames));
2872 req->inputResultSetNames[0] = odr_strdup (out, setstring);
2874 if (newset && setnumber >= 0)
2875 sprintf (setstring, "%d", ++setnumber);
2877 req->sortedResultSetName = odr_strdup (out, setstring);
2879 req->sortSequence = yaz_sort_spec (out, arg);
2880 if (!req->sortSequence)
2882 printf ("Missing sort specifications\n");
2889 void display_term(Z_TermInfo *t)
2892 printf("%s", t->displayTerm);
2893 else if (t->term->which == Z_Term_general)
2895 printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
2896 sprintf(last_scan_line, "%.*s", t->term->u.general->len,
2897 t->term->u.general->buf);
2900 printf("Term (not general)");
2901 if (t->globalOccurrences)
2902 printf (" (%d)\n", *t->globalOccurrences);
2907 void process_scanResponse(Z_ScanResponse *res)
2910 Z_Entry **entries = NULL;
2911 int num_entries = 0;
2913 printf("Received ScanResponse\n");
2914 print_refid (res->referenceId);
2915 printf("%d entries", *res->numberOfEntriesReturned);
2916 if (res->positionOfTerm)
2917 printf (", position=%d", *res->positionOfTerm);
2919 if (*res->scanStatus != Z_Scan_success)
2920 printf("Scan returned code %d\n", *res->scanStatus);
2923 if ((entries = res->entries->entries))
2924 num_entries = res->entries->num_entries;
2925 for (i = 0; i < num_entries; i++)
2927 int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
2928 if (entries[i]->which == Z_Entry_termInfo)
2930 printf("%c ", i + 1 == pos_term ? '*' : ' ');
2931 display_term(entries[i]->u.termInfo);
2934 display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1);
2936 if (res->entries->nonsurrogateDiagnostics)
2937 display_diagrecs (res->entries->nonsurrogateDiagnostics,
2938 res->entries->num_nonsurrogateDiagnostics);
2941 void process_sortResponse(Z_SortResponse *res)
2943 printf("Received SortResponse: status=");
2944 switch (*res->sortStatus)
2946 case Z_SortResponse_success:
2947 printf ("success"); break;
2948 case Z_SortResponse_partial_1:
2949 printf ("partial"); break;
2950 case Z_SortResponse_failure:
2951 printf ("failure"); break;
2953 printf ("unknown (%d)", *res->sortStatus);
2956 print_refid (res->referenceId);
2957 if (res->diagnostics)
2958 display_diagrecs(res->diagnostics,
2959 res->num_diagnostics);
2962 void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res)
2964 printf("Got deleteResultSetResponse status=%d\n",
2965 *res->deleteOperationStatus);
2966 if (res->deleteListStatuses)
2969 for (i = 0; i < res->deleteListStatuses->num; i++)
2971 printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id,
2972 *res->deleteListStatuses->elements[i]->status);
2977 int cmd_sort_generic(const char *arg, int newset)
2981 if (session_initResponse &&
2982 !ODR_MASK_GET(session_initResponse->options, Z_Options_sort))
2984 printf("Target doesn't support sort\n");
2989 if (send_sortrequest(arg, newset) < 0)
2996 int cmd_sort(const char *arg)
2998 return cmd_sort_generic (arg, 0);
3001 int cmd_sort_newset (const char *arg)
3003 return cmd_sort_generic (arg, 1);
3006 int cmd_scanstep(const char *arg)
3008 scan_stepSize = atoi(arg);
3012 int cmd_scanpos(const char *arg)
3014 int r = sscanf(arg, "%d", &scan_position);
3020 int cmd_scansize(const char *arg)
3022 int r = sscanf(arg, "%d", &scan_size);
3028 int cmd_scan(const char *arg)
3030 if (protocol == PROTO_HTTP)
3039 if (send_SRW_scanRequest(arg, scan_position, scan_size) < 0)
3044 if (send_SRW_scanRequest(last_scan_line, 1, scan_size) < 0)
3059 printf("Session not initialized yet\n");
3063 if (session_initResponse &&
3064 !ODR_MASK_GET(session_initResponse->options, Z_Options_scan))
3066 printf("Target doesn't support scan\n");
3071 strcpy (last_scan_query, arg);
3072 if (send_scanrequest(arg, scan_position, scan_size, 0) < 0)
3077 if (send_scanrequest(last_scan_query, 1, scan_size, last_scan_line) < 0)
3084 int cmd_schema(const char *arg)
3086 xfree(record_schema);
3089 record_schema = xstrdup(arg);
3093 int cmd_format(const char *arg)
3098 printf("Usage: format <recordsyntax>\n");
3101 nsyntax = oid_getvalbyname (arg);
3102 if (strcmp(arg, "none") && nsyntax == VAL_NONE)
3104 printf ("unknown record syntax\n");
3107 recordsyntax = nsyntax;
3111 int cmd_elements(const char *arg)
3113 static Z_ElementSetNames esn;
3114 static char what[100];
3118 elementSetNames = 0;
3122 esn.which = Z_ElementSetNames_generic;
3123 esn.u.generic = what;
3124 elementSetNames = &esn;
3128 int cmd_attributeset(const char *arg)
3134 printf("Usage: attributeset <setname>\n");
3137 sscanf(arg, "%s", what);
3138 if (p_query_attset (what))
3140 printf("Unknown attribute set name\n");
3146 int cmd_querytype (const char *arg)
3148 if (!strcmp (arg, "ccl"))
3149 queryType = QueryType_CCL;
3150 else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn"))
3151 queryType = QueryType_Prefix;
3152 else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
3153 queryType = QueryType_CCL2RPN;
3154 else if (!strcmp(arg, "cql"))
3155 queryType = QueryType_CQL;
3156 else if (!strcmp (arg, "cql2rpn") || !strcmp (arg, "cqlrpn"))
3157 queryType = QueryType_CQL2RPN;
3160 printf ("Querytype must be one of:\n");
3161 printf (" prefix - Prefix query\n");
3162 printf (" ccl - CCL query\n");
3163 printf (" ccl2rpn - CCL query converted to RPN\n");
3164 printf (" cql - CQL\n");
3165 printf (" cql2rpn - CQL query converted to RPN\n");
3171 int cmd_refid (const char *arg)
3176 refid = xstrdup (arg);
3180 int cmd_close(const char *arg)
3186 apdu = zget_APDU(out, Z_APDU_close);
3187 req = apdu->u.close;
3188 *req->closeReason = Z_Close_finished;
3190 printf("Sent close request.\n");
3195 int cmd_packagename(const char* arg)
3197 xfree (esPackageName);
3198 esPackageName = NULL;
3200 esPackageName = xstrdup(arg);
3204 int cmd_proxy(const char* arg)
3209 yazProxy = xstrdup (arg);
3213 int cmd_marccharset(const char *arg)
3218 if (sscanf(arg, "%29s", l1) < 1)
3220 printf("MARC character set is `%s'\n",
3221 marcCharset ? marcCharset: "none");
3224 xfree (marcCharset);
3226 if (strcmp(l1, "-"))
3227 marcCharset = xstrdup(l1);
3231 int cmd_displaycharset(const char *arg)
3236 if (sscanf(arg, "%29s", l1) < 1)
3238 printf("Display character set is `%s'\n",
3239 outputCharset ? outputCharset: "none");
3243 xfree (outputCharset);
3245 if (!strcmp(l1, "auto") && codeset)
3249 printf ("Display character set: %s\n", codeset);
3250 outputCharset = xstrdup(codeset);
3253 printf ("No codeset found on this system\n");
3255 else if (strcmp(l1, "-") && strcmp(l1, "none"))
3256 outputCharset = xstrdup(l1);
3261 int cmd_negcharset(const char *arg)
3266 if (sscanf(arg, "%29s %d %d", l1, &negotiationCharsetRecords,
3267 &negotiationCharsetVersion) < 1)
3269 printf("Current negotiation character set is `%s'\n",
3270 negotiationCharset ? negotiationCharset: "none");
3271 printf("Records in charset %s\n", negotiationCharsetRecords ?
3273 printf("Charneg version %d\n", negotiationCharsetVersion);
3277 xfree (negotiationCharset);
3278 negotiationCharset = NULL;
3279 if (*l1 && strcmp(l1, "-") && strcmp(l1, "none"))
3281 negotiationCharset = xstrdup(l1);
3282 printf ("Character set negotiation : %s\n", negotiationCharset);
3288 int cmd_charset(const char* arg)
3290 char l1[30], l2[30], l3[30];
3292 *l1 = *l2 = *l3 = 0;
3293 if (sscanf(arg, "%29s %29s %29s", l1, l2, l3) < 1)
3296 cmd_displaycharset("");
3297 cmd_marccharset("");
3303 cmd_displaycharset(l2);
3305 cmd_marccharset(l3);
3310 int cmd_lang(const char* arg)
3313 printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
3319 yazLang = xstrdup(arg);
3323 int cmd_source(const char* arg, int echo )
3325 /* first should open the file and read one line at a time.. */
3327 char line[102400], *cp;
3330 fprintf(stderr,"Error in source command use a filename\n");
3334 includeFile = fopen (arg, "r");
3337 fprintf(stderr,"Unable to open file %s for reading\n",arg);
3341 while(!feof(includeFile)) {
3342 memset(line,0,sizeof(line));
3343 fgets(line,sizeof(line),includeFile);
3345 if(strlen(line) < 2) continue;
3346 if(line[0] == '#') continue;
3348 if ((cp = strrchr (line, '\n')))
3352 printf( "processing line: %s\n",line );
3354 process_cmd_line(line);
3357 if(fclose(includeFile)<0) {
3358 perror("unable to close include file");
3364 int cmd_source_echo(const char* arg)
3370 int cmd_source_noecho(const char* arg)
3377 int cmd_subshell(const char* args)
3382 system(getenv("SHELL"));
3388 int cmd_set_berfile(const char *arg)
3390 if (ber_file && ber_file != stdout && ber_file != stderr)
3392 if (!strcmp(arg, ""))
3394 else if (!strcmp(arg, "-"))
3397 ber_file = fopen(arg, "a");
3401 int cmd_set_apdufile(const char *arg)
3403 if(apdu_file && apdu_file != stderr && apdu_file != stderr)
3405 if (!strcmp(arg, ""))
3407 else if (!strcmp(arg, "-"))
3411 apdu_file = fopen(arg, "a");
3413 perror("unable to open apdu log file");
3416 odr_setprint(print, apdu_file);
3420 int cmd_set_cclfile(const char* arg)
3424 bibset = ccl_qual_mk ();
3425 inf = fopen (arg, "r");
3427 perror("unable to open CCL file");
3430 ccl_qual_file (bibset, inf);
3433 strcpy(ccl_fields,arg);
3437 int cmd_set_cqlfile(const char* arg)
3439 cql_transform_t newcqltrans;
3441 if ((newcqltrans = cql_transform_open_fname(arg)) == 0) {
3442 perror("unable to open CQL file");
3446 cql_transform_close(cqltrans);
3448 cqltrans = newcqltrans;
3449 strcpy(cql_fields, arg);
3453 int cmd_set_auto_reconnect(const char* arg)
3455 if(strlen(arg)==0) {
3456 auto_reconnect = ! auto_reconnect;
3457 } else if(strcmp(arg,"on")==0) {
3459 } else if(strcmp(arg,"off")==0) {
3462 printf("Error use on or off\n");
3467 printf("Set auto reconnect enabled.\n");
3469 printf("Set auto reconnect disabled.\n");
3475 int cmd_set_auto_wait(const char* arg)
3477 if(strlen(arg)==0) {
3478 auto_wait = ! auto_wait;
3479 } else if(strcmp(arg,"on")==0) {
3481 } else if(strcmp(arg,"off")==0) {
3484 printf("Error use on or off\n");
3489 printf("Set auto wait enabled.\n");
3491 printf("Set auto wait disabled.\n");
3496 int cmd_set_marcdump(const char* arg)
3498 if(marc_file && marc_file != stderr) { /* don't close stdout*/
3502 if (!strcmp(arg, ""))
3504 else if (!strcmp(arg, "-"))
3508 marc_file = fopen(arg, "a");
3510 perror("unable to open marc log file");
3516 this command takes 3 arge {name class oid}
3518 int cmd_register_oid(const char* args) {
3523 {"appctx",CLASS_APPCTX},
3524 {"absyn",CLASS_ABSYN},
3525 {"attset",CLASS_ATTSET},
3526 {"transyn",CLASS_TRANSYN},
3527 {"diagset",CLASS_DIAGSET},
3528 {"recsyn",CLASS_RECSYN},
3529 {"resform",CLASS_RESFORM},
3530 {"accform",CLASS_ACCFORM},
3531 {"extserv",CLASS_EXTSERV},
3532 {"userinfo",CLASS_USERINFO},
3533 {"elemspec",CLASS_ELEMSPEC},
3534 {"varset",CLASS_VARSET},
3535 {"schema",CLASS_SCHEMA},
3536 {"tagset",CLASS_TAGSET},
3537 {"general",CLASS_GENERAL},
3538 {0,(enum oid_class) 0}
3540 char oname_str[101], oclass_str[101], oid_str[101];
3543 oid_class oidclass = CLASS_GENERAL;
3544 int val = 0, oid[OID_SIZE];
3545 struct oident * new_oident=NULL;
3547 if (sscanf (args, "%100[^ ] %100[^ ] %100s",
3548 oname_str,oclass_str, oid_str) < 1) {
3549 printf("Error in register command \n");
3553 for (i = 0; oid_classes[i].className; i++) {
3554 if (!strcmp(oid_classes[i].className, oclass_str))
3556 oidclass=oid_classes[i].oclass;
3561 if(!(oid_classes[i].className)) {
3562 printf("Unknown oid class %s\n",oclass_str);
3570 while (isdigit (*(unsigned char *) name))
3572 val = val*10 + (*name - '0');
3585 new_oident = oid_addent (oid, PROTO_GENERAL, oidclass, oname_str,
3587 if(strcmp(new_oident->desc,oname_str))
3589 fprintf(stderr,"oid is already named as %s, registration failed\n",
3595 int cmd_push_command(const char* arg)
3597 #if HAVE_READLINE_HISTORY_H
3601 fprintf(stderr,"Not compiled with the readline/history module\n");
3606 void source_rcfile()
3608 /* Look for a $HOME/.yazclientrc and source it if it exists */
3609 struct stat statbuf;
3611 char* homedir=getenv("HOME");
3615 sprintf(buffer,"%s/.yazclientrc",homedir);
3617 if(stat(buffer,&statbuf)==0) {
3618 cmd_source(buffer, 0 );
3623 if(stat(".yazclientrc",&statbuf)==0) {
3624 cmd_source(".yazclientrc", 0 );
3629 static void initialize(void)
3634 if (!(out = odr_createmem(ODR_ENCODE)) ||
3635 !(in = odr_createmem(ODR_DECODE)) ||
3636 !(print = odr_createmem(ODR_PRINT)))
3638 fprintf(stderr, "failed to allocate ODR streams\n");
3643 setvbuf(stdout, 0, _IONBF, 0);
3645 odr_setprint(print, apdu_file);
3647 bibset = ccl_qual_mk ();
3648 inf = fopen (ccl_fields, "r");
3651 ccl_qual_file (bibset, inf);
3655 cqltrans = cql_transform_open_fname(cql_fields);
3656 /* If this fails, no problem: we detect cqltrans == 0 later */
3658 #if HAVE_READLINE_READLINE_H
3659 rl_attempted_completion_function = (CPPFunction*)readline_completer;
3663 for(i=0; i<maxOtherInfosSupported; ++i) {
3664 extraOtherInfos[i].oidval = -1;
3671 #if HAVE_GETTIMEOFDAY
3672 struct timeval tv_start;
3676 static void handle_srw_record(Z_SRW_record *rec)
3678 if (rec->recordPosition)
3680 printf ("pos=%d", *rec->recordPosition);
3681 setno = *rec->recordPosition + 1;
3683 if (rec->recordSchema)
3684 printf (" schema=%s", rec->recordSchema);
3686 if (rec->recordData_buf && rec->recordData_len)
3688 fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout);
3690 fwrite (rec->recordData_buf, 1, rec->recordData_len, marc_file);
3693 printf ("No data!");
3697 static void handle_srw_explain_response(Z_SRW_explainResponse *res)
3699 handle_srw_record(&res->record);
3702 static void handle_srw_response(Z_SRW_searchRetrieveResponse *res)
3706 printf ("Received SRW SearchRetrieve Response\n");
3708 for (i = 0; i<res->num_diagnostics; i++)
3710 if (res->diagnostics[i].uri)
3711 printf ("SRW diagnostic %s\n",
3712 res->diagnostics[i].uri);
3714 printf ("SRW diagnostic missing or could not be decoded\n");
3715 if (res->diagnostics[i].message)
3716 printf ("Message: %s\n", res->diagnostics[i].message);
3717 if (res->diagnostics[i].details)
3718 printf ("Details: %s\n", res->diagnostics[i].details);
3720 if (res->numberOfRecords)
3721 printf ("Number of hits: %d\n", *res->numberOfRecords);
3722 for (i = 0; i<res->num_records; i++)
3723 handle_srw_record(res->records + i);
3726 static void handle_srw_scan_term(Z_SRW_scanTerm *term)
3728 if (term->displayTerm)
3729 printf("%s:", term->displayTerm);
3730 else if (term->value)
3731 printf("%s:", term->value);
3733 printf("No value:");
3734 if (term->numberOfRecords)
3735 printf(" %d", *term->numberOfRecords);
3736 if (term->whereInList)
3737 printf(" %s", term->whereInList);
3738 if (term->value && term->displayTerm)
3739 printf(" %s", term->value);
3741 strcpy(last_scan_line, term->value);
3745 static void handle_srw_scan_response(Z_SRW_scanResponse *res)
3749 printf ("Received SRW Scan Response\n");
3751 for (i = 0; i<res->num_diagnostics; i++)
3753 if (res->diagnostics[i].uri)
3754 printf ("SRW diagnostic %s\n",
3755 res->diagnostics[i].uri);
3757 printf ("SRW diagnostic missing or could not be decoded\n");
3758 if (res->diagnostics[i].message)
3759 printf ("Message: %s\n", res->diagnostics[i].message);
3760 if (res->diagnostics[i].details)
3761 printf ("Details: %s\n", res->diagnostics[i].details);
3764 for (i = 0; i<res->num_terms; i++)
3765 handle_srw_scan_term(res->terms + i);
3768 static void http_response(Z_HTTP_Response *hres)
3771 const char *content_type = z_HTTP_header_lookup(hres->headers,
3773 const char *connection_head = z_HTTP_header_lookup(hres->headers,
3775 if (content_type && !yaz_strcmp_del("text/xml", content_type, "; "))
3777 Z_SOAP *soap_package = 0;
3778 ODR o = odr_createmem(ODR_DECODE);
3779 Z_SOAP_Handler soap_handlers[2] = {
3780 {"http://www.loc.gov/zing/srw/", 0,
3781 (Z_SOAP_fun) yaz_srw_codec},
3784 ret = z_soap_codec(o, &soap_package,
3785 &hres->content_buf, &hres->content_len,
3787 if (!ret && soap_package->which == Z_SOAP_generic &&
3788 soap_package->u.generic->no == 0)
3790 Z_SRW_PDU *sr = soap_package->u.generic->p;
3791 if (sr->which == Z_SRW_searchRetrieve_response)
3792 handle_srw_response(sr->u.response);
3793 else if (sr->which == Z_SRW_explain_response)
3794 handle_srw_explain_response(sr->u.explain_response);
3795 else if (sr->which == Z_SRW_scan_response)
3796 handle_srw_scan_response(sr->u.scan_response);
3800 else if (soap_package && (soap_package->which == Z_SOAP_fault
3801 || soap_package->which == Z_SOAP_error))
3803 printf ("HTTP Error Status=%d\n", hres->code);
3804 printf ("SOAP Fault code %s\n",
3805 soap_package->u.fault->fault_code);
3806 printf ("SOAP Fault string %s\n",
3807 soap_package->u.fault->fault_string);
3808 if (soap_package->u.fault->details)
3809 printf ("SOAP Details %s\n",
3810 soap_package->u.fault->details);
3818 if (hres->code != 200)
3820 printf ("HTTP Error Status=%d\n", hres->code);
3824 printf ("Decoding of SRW package failed\n");
3830 if (!strcmp(hres->version, "1.0"))
3832 /* HTTP 1.0: only if Keep-Alive we stay alive.. */
3833 if (!connection_head || strcmp(connection_head, "Keep-Alive"))
3838 /* HTTP 1.1: only if no close we stay alive .. */
3839 if (connection_head && !strcmp(connection_head, "close"))
3846 void wait_and_handle_response(int one_response_only)
3848 int reconnect_ok = 1;
3851 int netbufferlen = 0;
3852 #if HAVE_GETTIMEOFDAY
3854 struct timeval tv_end;
3860 res = cs_get(conn, &netbuffer, &netbufferlen);
3861 if (reconnect_ok && res <= 0 && protocol == PROTO_HTTP)
3872 buf_out = odr_getbuf(out, &len_out, 0);
3874 do_hex_dump(buf_out, len_out);
3876 cs_put(conn, buf_out, len_out);
3884 printf("Target closed connection\n");
3888 #if HAVE_GETTIMEOFDAY
3889 if (got_tv_end == 0)
3890 gettimeofday (&tv_end, 0); /* count first one only */
3894 odr_reset(in); /* release APDU from last round */
3896 do_hex_dump(netbuffer, res);
3897 odr_setbuf(in, netbuffer, res, 0);
3899 if (!z_GDU(in, &gdu, 0, 0))
3901 FILE *f = ber_file ? ber_file : stdout;
3902 odr_perror(in, "Decoding incoming APDU");
3903 fprintf(f, "[Near %d]\n", odr_offset(in));
3904 fprintf(f, "Packet dump:\n---------\n");
3905 odr_dumpBER(f, netbuffer, res);
3906 fprintf(f, "---------\n");
3909 z_GDU(print, &gdu, 0, 0);
3912 if (conn && cs_more(conn))
3917 odr_dumpBER(ber_file, netbuffer, res);
3918 if (apdu_file && !z_GDU(print, &gdu, 0, 0))
3920 odr_perror(print, "Failed to print incoming APDU");
3924 if (gdu->which == Z_GDU_Z3950)
3926 Z_APDU *apdu = gdu->u.z3950;
3929 case Z_APDU_initResponse:
3930 process_initResponse(apdu->u.initResponse);
3932 case Z_APDU_searchResponse:
3933 process_searchResponse(apdu->u.searchResponse);
3935 case Z_APDU_scanResponse:
3936 process_scanResponse(apdu->u.scanResponse);
3938 case Z_APDU_presentResponse:
3939 print_refid (apdu->u.presentResponse->referenceId);
3941 *apdu->u.presentResponse->numberOfRecordsReturned;
3942 if (apdu->u.presentResponse->records)
3943 display_records(apdu->u.presentResponse->records);
3945 printf("No records.\n");
3946 printf ("nextResultSetPosition = %d\n",
3947 *apdu->u.presentResponse->nextResultSetPosition);
3949 case Z_APDU_sortResponse:
3950 process_sortResponse(apdu->u.sortResponse);
3952 case Z_APDU_extendedServicesResponse:
3953 printf("Got extended services response\n");
3954 process_ESResponse(apdu->u.extendedServicesResponse);
3957 printf("Target has closed the association.\n");
3958 process_close(apdu->u.close);
3960 case Z_APDU_resourceControlRequest:
3961 process_resourceControlRequest
3962 (apdu->u.resourceControlRequest);
3964 case Z_APDU_deleteResultSetResponse:
3965 process_deleteResultSetResponse(apdu->u.
3966 deleteResultSetResponse);
3969 printf("Received unknown APDU type (%d).\n",
3975 else if (gdu->which == Z_GDU_HTTP_Response)
3977 http_response(gdu->u.HTTP_Response);
3980 if (one_response_only)
3982 if (conn && !cs_more(conn))
3985 #if HAVE_GETTIMEOFDAY
3989 printf ("S/U S/U=%ld/%ld %ld/%ld",
3990 (long) tv_start.tv_sec,
3991 (long) tv_start.tv_usec,
3992 (long) tv_end.tv_sec,
3993 (long) tv_end.tv_usec);
3995 printf ("Elapsed: %.6f\n",
3996 (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
3997 ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
4004 int cmd_cclparse(const char* arg)
4007 struct ccl_rpn_node *rpn=NULL;
4010 rpn = ccl_find_str (bibset, arg, &error, &pos);
4013 printf ("%*s^ - ", 3+strlen(last_cmd)+1+pos, " ");
4014 printf ("%s\n", ccl_err_msg (error));
4020 ccl_pr_tree(rpn, stdout);
4024 ccl_rpn_delete(rpn);
4032 int cmd_set_otherinfo(const char* args)
4034 char oidstr[101], otherinfoString[101];
4039 sscan_res = sscanf (args, "%d %100[^ ] %100s", &otherinfoNo, oidstr, otherinfoString);
4041 /* reset this otherinfo */
4042 if(otherinfoNo>=maxOtherInfosSupported) {
4043 printf("Error otherinfo index to large (%d>%d)\n",
4044 otherinfoNo,maxOtherInfosSupported);
4046 extraOtherInfos[otherinfoNo].oidval = -1;
4047 if (extraOtherInfos[otherinfoNo].value)
4048 free(extraOtherInfos[otherinfoNo].value);
4052 printf("Error in set_otherinfo command \n");
4056 if (otherinfoNo>=maxOtherInfosSupported) {
4057 printf("Error otherinfo index to large (%d>%d)\n",
4058 otherinfoNo,maxOtherInfosSupported);
4061 oidval = oid_getvalbyname (oidstr);
4062 if (oidval == -1 ) {
4063 printf("Error in set_otherinfo command unknown oid %s \n",oidstr);
4066 extraOtherInfos[otherinfoNo].oidval = oidval;
4067 if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
4068 extraOtherInfos[otherinfoNo].value = strdup(otherinfoString);
4073 int cmd_sleep(const char* args )
4082 printf("Done sleeping %d seconds\n", sec);
4087 int cmd_list_otherinfo(const char* args)
4091 if(strlen(args)>0) {
4093 if( i >= maxOtherInfosSupported ) {
4094 printf("Error otherinfo index to large (%d>%d)\n",i,maxOtherInfosSupported);
4098 if(extraOtherInfos[i].oidval != -1)
4099 printf(" otherinfo %d %s %s\n",
4101 yaz_z3950_oid_value_to_str(
4102 (enum oid_value) extraOtherInfos[i].oidval,
4104 extraOtherInfos[i].value);
4107 for(i=0; i<maxOtherInfosSupported; ++i) {
4108 if(extraOtherInfos[i].oidval != -1)
4109 printf(" otherinfo %d %s %s\n",
4111 yaz_z3950_oid_value_to_str(
4112 (enum oid_value) extraOtherInfos[i].oidval,
4114 extraOtherInfos[i].value);
4122 int cmd_list_all(const char* args) {
4125 /* connection options */
4127 printf("Connected to : %s\n",last_open_command);
4129 if(last_open_command)
4130 printf("Not connected to : %s\n",last_open_command);
4132 printf("Not connected : \n");
4135 if(yazProxy) printf("using proxy : %s\n",yazProxy);
4137 printf("auto_reconnect : %s\n",auto_reconnect?"on":"off");
4138 printf("auto_wait : %s\n",auto_wait?"on":"off");
4141 printf("Authentication : none\n");
4143 switch(auth->which) {
4144 case Z_IdAuthentication_idPass:
4145 printf("Authentication : IdPass\n");
4146 printf(" Login User : %s\n",auth->u.idPass->userId?auth->u.idPass->userId:"");
4147 printf(" Login Group : %s\n",auth->u.idPass->groupId?auth->u.idPass->groupId:"");
4148 printf(" Password : %s\n",auth->u.idPass->password?auth->u.idPass->password:"");
4150 case Z_IdAuthentication_open:
4151 printf("Authentication : psOpen\n");
4152 printf(" Open string : %s\n",auth->u.open);
4155 printf("Authentication : Unknown\n");
4158 if (negotiationCharset)
4159 printf("Neg. Character set : `%s'\n", negotiationCharset);
4163 for (i = 0; i<num_databaseNames; i++) printf("%s ",databaseNames[i]);
4167 printf("CCL file : %s\n",ccl_fields);
4168 printf("CQL file : %s\n",cql_fields);
4169 printf("Query type : %s\n",query_type_as_string(queryType));
4171 printf("Named Result Sets : %s\n",setnumber==-1?"off":"on");
4173 /* piggy back options */
4174 printf("ssub/lslb/mspn : %d/%d/%d\n",smallSetUpperBound,largeSetLowerBound,mediumSetPresentNumber);
4176 /* print present related options */
4177 printf("Format : %s\n",yaz_z3950_oid_value_to_str(recordsyntax,CLASS_RECSYN));
4178 printf("Schema : %s\n",record_schema ? record_schema : "not set");
4179 printf("Elements : %s\n",elementSetNames?elementSetNames->u.generic:"");
4181 /* loging options */
4182 printf("APDU log : %s\n",apdu_file?"on":"off");
4183 printf("Record log : %s\n",marc_file?"on":"off");
4186 printf("Other Info: \n");
4187 cmd_list_otherinfo("");
4192 int cmd_clear_otherinfo(const char* args)
4194 if(strlen(args)>0) {
4196 otherinfoNo = atoi(args);
4197 if( otherinfoNo >= maxOtherInfosSupported ) {
4198 printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
4202 if(extraOtherInfos[otherinfoNo].oidval != -1) {
4203 /* only clear if set. */
4204 extraOtherInfos[otherinfoNo].oidval=-1;
4205 free(extraOtherInfos[otherinfoNo].value);
4210 for(i=0; i<maxOtherInfosSupported; ++i) {
4211 if (extraOtherInfos[i].oidval!=-1 ) {
4212 extraOtherInfos[i].oidval=-1;
4213 free(extraOtherInfos[i].value);
4220 int cmd_wait_response(const char *arg)
4222 int wait_for = atoi(arg);
4224 if( wait_for < 1 ) {
4228 for( i=0 ; i < wait_for ; ++i ) {
4229 wait_and_handle_response(1);
4234 static int cmd_help (const char *line);
4236 typedef char *(*completerFunctionType)(const char *text, int state);
4240 int (*fun)(const char *arg);
4242 completerFunctionType rl_completerfunction;
4243 int complete_filenames;
4244 char **local_tabcompletes;
4246 {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0,NULL},
4247 {"quit", cmd_quit, "",NULL,0,NULL},
4248 {"exit", cmd_quit, "",NULL,0,NULL},
4249 {"find", cmd_find, "<query>",NULL,0,NULL},
4250 {"delete", cmd_delete, "<setname>",NULL,0,NULL},
4251 {"base", cmd_base, "<base-name>",NULL,0,NULL},
4252 {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0,NULL},
4253 {"scan", cmd_scan, "<term>",NULL,0,NULL},
4254 {"scanstep", cmd_scanstep, "<size>",NULL,0,NULL},
4255 {"scanpos", cmd_scanpos, "<size>",NULL,0,NULL},
4256 {"scansize", cmd_scansize, "<size>",NULL,0,NULL},
4257 {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
4258 {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
4259 {"authentication", cmd_authentication, "<acctstring>",NULL,0,NULL},
4260 {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0,NULL},
4261 {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0,NULL},
4262 {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0,NULL},
4263 {"status", cmd_status, "",NULL,0,NULL},
4264 {"setnames", cmd_setnames, "",NULL,0,NULL},
4265 {"cancel", cmd_cancel, "",NULL,0,NULL},
4266 {"cancel_find", cmd_cancel_find, "<query>",NULL,0,NULL},
4267 {"format", cmd_format, "<recordsyntax>",complete_format,0,NULL},
4268 {"schema", cmd_schema, "<schema>",complete_schema,0,NULL},
4269 {"elements", cmd_elements, "<elementSetName>",NULL,0,NULL},
4270 {"close", cmd_close, "",NULL,0,NULL},
4271 {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0,NULL},
4272 {"querytype", cmd_querytype, "<type>",complete_querytype,0,NULL},
4273 {"refid", cmd_refid, "<id>",NULL,0,NULL},
4274 {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0,NULL},
4275 {"update", cmd_update, "<action> <recid> [<doc>]",NULL,0,NULL},
4276 {"update0", cmd_update0, "<action> <recid> [<doc>]",NULL,0,NULL},
4277 {"xmles", cmd_xmles, "<OID> <doc>",NULL,0,NULL},
4278 {"packagename", cmd_packagename, "<packagename>",NULL,0,NULL},
4279 {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0,NULL},
4280 {"charset", cmd_charset, "<nego_charset> <output_charset>",NULL,0,NULL},
4281 {"negcharset", cmd_negcharset, "<nego_charset>",NULL,0,NULL},
4282 {"displaycharset", cmd_displaycharset, "<output_charset>",NULL,0,NULL},
4283 {"marccharset", cmd_marccharset, "<charset_name>",NULL,0,NULL},
4284 {"lang", cmd_lang, "<language_code>",NULL,0,NULL},
4285 {".", cmd_source_echo, "<filename>",NULL,1,NULL},
4286 {"!", cmd_subshell, "Subshell command",NULL,1,NULL},
4287 {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,1,NULL},
4288 {"set_berfile", cmd_set_berfile, "<filename>",NULL,1,NULL},
4289 {"set_marcdump", cmd_set_marcdump," <filename>",NULL,1,NULL},
4290 {"set_cclfile", cmd_set_cclfile," <filename>",NULL,1,NULL},
4291 {"set_cqlfile", cmd_set_cqlfile," <filename>",NULL,1,NULL},
4292 {"set_auto_reconnect", cmd_set_auto_reconnect," on|off",complete_auto_reconnect,1,NULL},
4293 {"set_auto_wait", cmd_set_auto_wait," on|off",complete_auto_reconnect,1,NULL},
4294 {"set_otherinfo", cmd_set_otherinfo,"<otherinfoinddex> <oid> <string>",NULL,0,NULL},
4295 {"sleep", cmd_sleep,"<seconds>",NULL,0,NULL},
4296 {"register_oid", cmd_register_oid,"<name> <class> <oid>",NULL,0,NULL},
4297 {"push_command", cmd_push_command,"<command>",command_generator,0,NULL},
4298 {"register_tab", cmd_register_tab,"<commandname> <tab>",command_generator,0,NULL},
4299 {"cclparse", cmd_cclparse,"<ccl find command>",NULL,0,NULL},
4300 {"list_otherinfo",cmd_list_otherinfo,"[otherinfoinddex]",NULL,0,NULL},
4301 {"list_all",cmd_list_all,"",NULL,0,NULL},
4302 {"clear_otherinfo",cmd_clear_otherinfo,"",NULL,0,NULL},
4303 {"wait_response",cmd_wait_response,"<number>",NULL,0,NULL},
4304 /* Server Admin Functions */
4305 {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0,NULL},
4306 {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0,NULL},
4307 {"adm-create", cmd_adm_create, "",NULL,0,NULL},
4308 {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0,NULL},
4309 {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0,NULL},
4310 {"adm-refresh", cmd_adm_refresh, "",NULL,0,NULL},
4311 {"adm-commit", cmd_adm_commit, "",NULL,0,NULL},
4312 {"adm-shutdown", cmd_adm_shutdown, "",NULL,0,NULL},
4313 {"adm-startup", cmd_adm_startup, "",NULL,0,NULL},
4314 {"explain", cmd_explain, "", NULL, 0, NULL},
4315 {"options", cmd_options, "", NULL, 0, NULL},
4316 {"zversion", cmd_zversion, "", NULL, 0, NULL},
4317 {"help", cmd_help, "", NULL,0,NULL},
4318 {"init", cmd_init, "", NULL,0,NULL},
4322 static int cmd_help (const char *line)
4328 sscanf (line, "%20s", topic);
4331 printf("Commands:\n");
4332 for (i = 0; cmd_array[i].cmd; i++)
4333 if (*topic == 0 || strcmp (topic, cmd_array[i].cmd) == 0)
4334 printf(" %s %s\n", cmd_array[i].cmd, cmd_array[i].ad);
4335 if (!strcmp(topic, "find"))
4338 printf(" \"term\" Simple Term\n");
4339 printf(" @attr [attset] type=value op Attribute\n");
4340 printf(" @and opl opr And\n");
4341 printf(" @or opl opr Or\n");
4342 printf(" @not opl opr And-Not\n");
4343 printf(" @set set Result set\n");
4344 printf(" @prox exl dist ord rel uc ut Proximity. Use help prox\n");
4346 printf("Bib-1 attribute types\n");
4348 printf("4=Title 7=ISBN 8=ISSN 30=Date 62=Abstract 1003=Author 1016=Any\n");
4349 printf("2=Relation: ");
4350 printf("1< 2<= 3= 4>= 5> 6!= 102=Relevance\n");
4351 printf("3=Position: ");
4352 printf("1=First in Field 2=First in subfield 3=Any position\n");
4353 printf("4=Structure: ");
4354 printf("1=Phrase 2=Word 3=Key 4=Year 5=Date 6=WordList\n");
4355 printf("5=Truncation: ");
4356 printf("1=Right 2=Left 3=L&R 100=No 101=# 102=Re-1 103=Re-2\n");
4357 printf("6=Completeness:");
4358 printf("1=Incomplete subfield 2=Complete subfield 3=Complete field\n");
4360 if (!strcmp(topic, "prox"))
4362 printf("Proximity:\n");
4363 printf(" @prox exl dist ord rel uc ut\n");
4364 printf(" exl: exclude flag . 0=include, 1=exclude.\n");
4365 printf(" dist: distance integer.\n");
4366 printf(" ord: order flag. 0=unordered, 1=ordered.\n");
4367 printf(" rel: relation integer. 1< 2<= 3= 4>= 5> 6!= .\n");
4368 printf(" uc: unit class. k=known, p=private.\n");
4369 printf(" ut: unit type. 1=character, 2=word, 3=sentence,\n");
4370 printf(" 4=paragraph, 5=section, 6=chapter, 7=document,\n");
4371 printf(" 8=element, 9=subelement, 10=elementType, 11=byte.\n");
4372 printf("\nExamples:\n");
4373 printf(" Search for a and b in-order at most 3 words apart:\n");
4374 printf(" @prox 0 3 1 2 k 2 a b\n");
4375 printf(" Search for any order of a and b next to each other:\n");
4376 printf(" @prox 0 1 0 3 k 2 a b\n");
4381 int cmd_register_tab(const char* arg) {
4383 char command[101], tabargument[101];
4388 if (sscanf (arg, "%100s %100s", command, tabargument) < 1) {
4392 /* locate the amdn in the list */
4393 for (i = 0; cmd_array[i].cmd; i++) {
4394 if (!strncmp(cmd_array[i].cmd, command, strlen(command))) {
4399 if(!cmd_array[i].cmd) {
4400 fprintf(stderr,"Unknown command %s\n",command);
4405 if(!cmd_array[i].local_tabcompletes)
4406 cmd_array[i].local_tabcompletes = (char **) calloc(1,sizeof(char**));
4410 tabslist = cmd_array[i].local_tabcompletes;
4411 for(;tabslist && *tabslist;tabslist++) {
4415 cmd_array[i].local_tabcompletes = (char **)
4416 realloc(cmd_array[i].local_tabcompletes,(num_of_tabs+2)*sizeof(char**));
4417 tabslist=cmd_array[i].local_tabcompletes;
4418 tabslist[num_of_tabs]=strdup(tabargument);
4419 tabslist[num_of_tabs+1]=NULL;
4424 void process_cmd_line(char* line)
4427 char word[32], arg[10240];
4429 #if HAVE_GETTIMEOFDAY
4430 gettimeofday (&tv_start, 0);
4433 if ((res = sscanf(line, "%31s %10239[^;]", word, arg)) <= 0)
4435 strcpy(word, last_cmd);
4440 strcpy(last_cmd, word);
4442 /* removed tailing spaces from the arg command */
4445 char* lastnonspace=NULL;
4448 if(!isspace(*(unsigned char *) p)) {
4453 *(++lastnonspace) = 0;
4456 for (i = 0; cmd_array[i].cmd; i++)
4457 if (!strncmp(cmd_array[i].cmd, word, strlen(word)))
4459 res = (*cmd_array[i].fun)(arg);
4463 if (!cmd_array[i].cmd) /* dump our help-screen */
4465 printf("Unknown command: %s.\n", word);
4466 printf("Type 'help' for list of commands\n");
4470 if(apdu_file) fflush(apdu_file);
4472 if (res >= 2 && auto_wait)
4473 wait_and_handle_response(0);
4482 char *command_generator(const char *text, int state)
4488 for( ; cmd_array[idx].cmd; ++idx) {
4489 if (!strncmp(cmd_array[idx].cmd,text,strlen(text))) {
4490 ++idx; /* skip this entry on the next run */
4491 return strdup(cmd_array[idx-1].cmd);
4499 This function only known how to complete on the first word
4501 char ** readline_completer(char *text, int start, int end) {
4502 #if HAVE_READLINE_READLINE_H
4504 completerFunctionType completerToUse;
4507 #if HAVE_READLINE_RL_COMPLETION_MATCHES
4508 char** res=rl_completion_matches(text,
4511 char** res=completion_matches(text,
4512 (CPFunction*)command_generator);
4514 rl_attempted_completion_over = 1;
4517 char arg[10240],word[32];
4519 if ((res = sscanf(rl_line_buffer, "%31s %10239[^;]", word, arg)) <= 0) {
4520 rl_attempted_completion_over = 1;
4524 for (i = 0; cmd_array[i].cmd; i++) {
4525 if (!strncmp(cmd_array[i].cmd, word, strlen(word))) {
4530 if(!cmd_array[i].cmd) return NULL;
4532 curret_global_list = cmd_array[i].local_tabcompletes;
4534 completerToUse = cmd_array[i].rl_completerfunction;
4535 if(completerToUse==NULL) /* if no pr. command completer is defined use the default completer */
4536 completerToUse = default_completer;
4538 if(completerToUse) {
4539 #ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
4541 rl_completion_matches(text,
4545 completion_matches(text,
4546 (CPFunction*)completerToUse);
4548 if(!cmd_array[i].complete_filenames)
4549 rl_attempted_completion_over = 1;
4552 if(!cmd_array[i].complete_filenames)
4553 rl_attempted_completion_over = 1;
4563 static void client(void)
4569 #if HAVE_GETTIMEOFDAY
4570 gettimeofday (&tv_start, 0);
4575 char *line_in = NULL;
4576 #if HAVE_READLINE_READLINE_H
4579 line_in=readline(C_PROMPT);
4582 #if HAVE_READLINE_HISTORY_H
4584 add_history(line_in);
4586 strncpy(line, line_in, 10239);
4595 if (!fgets(line, 10239, stdin))
4597 if ((end_p = strchr (line, '\n')))
4600 process_cmd_line(line);
4604 static void show_version(void)
4608 yaz_version(vstr, 0);
4609 printf ("YAZ version: %s\n", YAZ_VERSION);
4610 if (strcmp(vstr, YAZ_VERSION))
4611 printf ("YAZ DLL/SO: %s\n", vstr);
4615 int main(int argc, char **argv)
4618 char *open_command = 0;
4619 char *auth_command = 0;
4624 if (!setlocale(LC_CTYPE, ""))
4625 fprintf (stderr, "setlocale failed\n");
4629 codeset = nl_langinfo(CODESET);
4633 outputCharset = xstrdup(codeset);
4635 ODR_MASK_SET(&z3950_options, Z_Options_search);
4636 ODR_MASK_SET(&z3950_options, Z_Options_present);
4637 ODR_MASK_SET(&z3950_options, Z_Options_namedResultSets);
4638 ODR_MASK_SET(&z3950_options, Z_Options_triggerResourceCtrl);
4639 ODR_MASK_SET(&z3950_options, Z_Options_scan);
4640 ODR_MASK_SET(&z3950_options, Z_Options_sort);
4641 ODR_MASK_SET(&z3950_options, Z_Options_extendedServices);
4642 ODR_MASK_SET(&z3950_options, Z_Options_delSet);
4644 while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vxd:", argv, argc, &arg)) != -2)
4651 open_command = (char *) xmalloc (strlen(arg)+6);
4652 strcpy (open_command, "open ");
4653 strcat (open_command, arg);
4657 fprintf(stderr, "%s: Specify at most one server address\n",
4663 dump_file_prefix = arg;
4666 kilobytes = atoi(arg);
4669 if (!(marc_file = fopen (arg, "a")))
4676 outputCharset = xstrdup(arg);
4679 strncpy (ccl_fields, arg, sizeof(ccl_fields)-1);
4680 ccl_fields[sizeof(ccl_fields)-1] = '\0';
4683 strncpy (cql_fields, arg, sizeof(cql_fields)-1);
4684 cql_fields[sizeof(cql_fields)-1] = '\0';
4687 if (!strcmp(arg, "-"))
4690 ber_file=fopen(arg, "a");
4693 if (!strcmp(arg, "-"))
4696 apdu_file=fopen(arg, "a");
4702 yazProxy=strdup(arg);
4707 auth_command = (char *) xmalloc (strlen(arg)+6);
4708 strcpy (auth_command, "auth ");
4709 strcat (auth_command, arg);
4713 yaz_log_init(yaz_log_mask_str(arg), "", 0);
4719 fprintf (stderr, "Usage: %s "
4726 " [-p <proxy-addr>]"
4730 " [<server-addr>]\n",
4738 #ifdef HAVE_GETTIMEOFDAY
4739 gettimeofday (&tv_start, 0);
4741 process_cmd_line (auth_command);
4742 #if HAVE_READLINE_HISTORY_H
4743 add_history(auth_command);
4745 xfree(auth_command);
4749 #ifdef HAVE_GETTIMEOFDAY
4750 gettimeofday (&tv_start, 0);
4752 process_cmd_line (open_command);
4753 #if HAVE_READLINE_HISTORY_H
4754 add_history(open_command);
4756 xfree(open_command);
4764 * indent-tabs-mode: nil
4766 * vim: shiftwidth=4 tabstop=8 expandtab