2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
5 * $Id: client.c,v 1.201 2003-06-19 21:10:03 adam Exp $
24 #define S_ISREG(x) (x & _S_IFREG)
25 #define S_ISDIR(x) (x & _S_IFDIR)
28 #include <yaz/yaz-util.h>
30 #include <yaz/comstack.h>
32 #include <yaz/proto.h>
33 #include <yaz/marcdisp.h>
34 #include <yaz/diagbib1.h>
35 #include <yaz/otherinfo.h>
36 #include <yaz/charneg.h>
38 #include <yaz/pquery.h>
39 #include <yaz/sortspec.h>
43 #include <yaz/yaz-ccl.h>
46 #if HAVE_READLINE_READLINE_H
47 #include <readline/readline.h>
50 #if HAVE_READLINE_HISTORY_H
51 #include <readline/history.h>
57 #include "tabcomplete.h"
59 #define C_PROMPT "Z> "
61 static char *codeset = 0; /* character set for output */
62 static int hex_dump = 0;
63 static ODR out, in, print; /* encoding and decoding streams */
65 static ODR srw_sr_odr_out = 0;
66 static Z_SRW_PDU *srw_sr = 0;
68 static FILE *apdu_file = 0;
69 static FILE *ber_file = 0;
70 static COMSTACK conn = 0; /* our z-association */
71 static Z_IdAuthentication *auth = 0; /* our current auth definition */
72 char *databaseNames[128];
73 int num_databaseNames = 0;
74 static Z_External *record_last = 0;
75 static int setnumber = -1; /* current result set number */
76 static int smallSetUpperBound = 0;
77 static int largeSetLowerBound = 1;
78 static int mediumSetPresentNumber = 0;
79 static Z_ElementSetNames *elementSetNames = 0;
80 static int setno = 1; /* current set offset */
81 static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */
82 static enum oid_value recordsyntax = VAL_USMARC;
83 static char *schema = 0;
84 static int sent_close = 0;
85 static NMEM session_mem = NULL; /* memory handle for init-response */
86 static Z_InitResponse *session = 0; /* session parameters */
87 static char last_scan_line[512] = "0";
88 static char last_scan_query[512] = "0";
89 static char ccl_fields[512] = "default.bib";
90 /* ### How can I set this path to use wherever YAZ is installed? */
91 static char cql_fields[512] = "/usr/local/share/yaz/etc/pqf.properties";
92 static char *esPackageName = 0;
93 static char *yazProxy = 0;
94 static int kilobytes = 1024;
95 static char *negotiationCharset = 0;
96 static char *outputCharset = 0;
97 static char *marcCharset = 0;
98 static char* yazLang = 0;
100 static char last_cmd[32] = "?";
101 static FILE *marc_file = 0;
102 static char *refid = NULL;
103 static char *last_open_command = NULL;
104 static int auto_reconnect = 0;
114 static QueryType queryType = QueryType_Prefix;
116 static CCL_bibset bibset; /* CCL bibset handle */
117 static cql_transform_t cqltrans; /* CQL qualifier-set handle */
119 #if HAVE_READLINE_COMPLETION_OVER
122 /* readline doesn't have this var. Define it ourselves. */
123 int rl_attempted_completion_over = 0;
126 /* set this one to 1, to avoid decode of unknown MARCs */
127 #define AVOID_MARC_DECODE 1
129 #define maxOtherInfosSupported 10
133 } extraOtherInfos[maxOtherInfosSupported];
136 void process_cmd_line(char* line);
137 char ** readline_completer(char *text, int start, int end);
138 char *command_generator(const char *text, int state);
139 char** curret_global_list=NULL;
140 int cmd_register_tab(const char* arg);
142 static void close_session (void);
144 ODR getODROutputStream()
149 const char* query_type_as_string(QueryType q)
152 case QueryType_Prefix: return "prefix (RPN sent to server)";
153 case QueryType_CCL: return "CCL (CCL sent to server) ";
154 case QueryType_CCL2RPN: return "CCL -> RPN (RPN sent to server)";
155 case QueryType_CQL: return "CQL (CQL sent to server)";
156 case QueryType_CQL2RPN: return "CQL -> RPN (RPN sent to server)";
158 return "unknown Query type internal yaz-client error";
162 static void do_hex_dump(const char* buf, int len)
167 for( i=0; i<len ; i=i+16 )
170 for(x=0 ; i+x<len && x<16; ++x)
172 printf("%2.2X ",(unsigned int)((unsigned char)buf[i+x]));
179 void add_otherInfos(Z_APDU *a)
181 Z_OtherInformation **oi;
185 for(i=0; i<maxOtherInfosSupported; ++i)
187 if(extraOtherInfos[i].oidval != -1)
188 yaz_oi_set_string_oidval(oi, out, extraOtherInfos[i].oidval,
189 1, extraOtherInfos[i].value);
193 int send_apdu(Z_APDU *a)
202 z_APDU(print, &a, 0, 0);
205 if (!z_APDU(out, &a, 0, 0))
207 odr_perror(out, "Encoding APDU");
211 buf = odr_getbuf(out, &len, 0);
213 odr_dumpBER(ber_file, buf, len);
214 /* printf ("sending APDU of size %d\n", len); */
215 if (cs_put(conn, buf, len) < 0)
217 fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn)));
221 do_hex_dump(buf,len);
222 odr_reset(out); /* release the APDU structure */
226 static void print_stringn(const unsigned char *buf, size_t len)
229 for (i = 0; i<len; i++)
230 if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
231 printf ("%c", buf[i]);
233 printf ("\\X%02X", buf[i]);
236 static void print_refid (Z_ReferenceId *id)
240 printf ("Reference Id: ");
241 print_stringn (id->buf, id->len);
246 static Z_ReferenceId *set_refid (ODR out)
251 id = (Z_ReferenceId *) odr_malloc (out, sizeof(*id));
252 id->size = id->len = strlen(refid);
253 id->buf = (unsigned char *) odr_malloc (out, id->len);
254 memcpy (id->buf, refid, id->len);
258 /* INIT SERVICE ------------------------------- */
260 static void send_initRequest(const char* type_and_host)
262 Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest);
263 Z_InitRequest *req = apdu->u.initRequest;
265 ODR_MASK_SET(req->options, Z_Options_search);
266 ODR_MASK_SET(req->options, Z_Options_present);
267 ODR_MASK_SET(req->options, Z_Options_namedResultSets);
268 ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl);
269 ODR_MASK_SET(req->options, Z_Options_scan);
270 ODR_MASK_SET(req->options, Z_Options_sort);
271 ODR_MASK_SET(req->options, Z_Options_extendedServices);
272 ODR_MASK_SET(req->options, Z_Options_delSet);
274 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
275 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
276 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
278 *req->maximumRecordSize = 1024*kilobytes;
279 *req->preferredMessageSize = 1024*kilobytes;
281 req->idAuthentication = auth;
283 req->referenceId = set_refid (out);
286 yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
289 if (negotiationCharset || yazLang) {
290 Z_OtherInformation **p;
291 Z_OtherInformationUnit *p0;
293 yaz_oi_APDU(apdu, &p);
295 if ((p0=yaz_oi_update(p, out, NULL, 0, 0))) {
296 ODR_MASK_SET(req->options, Z_Options_negotiationModel);
298 p0->which = Z_OtherInfo_externallyDefinedInfo;
299 p0->information.externallyDefinedInfo =
300 yaz_set_proposal_charneg(
302 (const char**)&negotiationCharset,
303 negotiationCharset ? 1 : 0,
304 (const char**)&yazLang, yazLang ? 1 : 0, 1);
309 printf("Sent initrequest.\n");
312 static int process_initResponse(Z_InitResponse *res)
315 /* save session parameters for later use */
316 session_mem = odr_extract_mem(in);
319 for (ver = 0; ver<5; ver++)
320 if (!ODR_MASK_GET(res->protocolVersion, ver))
324 printf("Connection rejected by v%d target.\n", ver);
326 printf("Connection accepted by v%d target.\n", ver);
327 if (res->implementationId)
328 printf("ID : %s\n", res->implementationId);
329 if (res->implementationName)
330 printf("Name : %s\n", res->implementationName);
331 if (res->implementationVersion)
332 printf("Version: %s\n", res->implementationVersion);
333 if (res->userInformationField)
335 printf("UserInformationfield:\n");
336 if (!z_External(print, (Z_External**)&res-> userInformationField,
339 odr_perror(print, "Printing userinfo\n");
342 if (res->userInformationField->which == Z_External_octet)
344 printf("Guessing visiblestring:\n");
345 printf("'%s'\n", res->userInformationField->u. octet_aligned->buf);
350 if (ODR_MASK_GET(res->options, Z_Options_search))
352 if (ODR_MASK_GET(res->options, Z_Options_present))
354 if (ODR_MASK_GET(res->options, Z_Options_delSet))
356 if (ODR_MASK_GET(res->options, Z_Options_resourceReport))
357 printf (" resourceReport");
358 if (ODR_MASK_GET(res->options, Z_Options_resourceCtrl))
359 printf (" resourceCtrl");
360 if (ODR_MASK_GET(res->options, Z_Options_accessCtrl))
361 printf (" accessCtrl");
362 if (ODR_MASK_GET(res->options, Z_Options_scan))
364 if (ODR_MASK_GET(res->options, Z_Options_sort))
366 if (ODR_MASK_GET(res->options, Z_Options_extendedServices))
367 printf (" extendedServices");
368 if (ODR_MASK_GET(res->options, Z_Options_level_1Segmentation))
369 printf (" level1Segmentation");
370 if (ODR_MASK_GET(res->options, Z_Options_level_2Segmentation))
371 printf (" level2Segmentation");
372 if (ODR_MASK_GET(res->options, Z_Options_concurrentOperations))
373 printf (" concurrentOperations");
374 if (ODR_MASK_GET(res->options, Z_Options_namedResultSets))
376 printf (" namedResultSets");
379 if (ODR_MASK_GET(res->options, Z_Options_encapsulation))
380 printf (" encapsulation");
381 if (ODR_MASK_GET(res->options, Z_Options_resultCount))
382 printf (" resultCount");
383 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel))
384 printf (" negotiationModel");
385 if (ODR_MASK_GET(res->options, Z_Options_duplicateDetection))
386 printf (" duplicateDetection");
387 if (ODR_MASK_GET(res->options, Z_Options_queryType104))
388 printf (" queryType104");
391 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) {
393 Z_CharSetandLanguageNegotiation *p =
394 yaz_get_charneg_record(res->otherInfo);
398 char *charset=NULL, *lang=NULL;
401 yaz_get_response_charneg(session_mem, p, &charset, &lang,
404 printf("Accepted character set : %s\n", charset);
405 printf("Accepted code language : %s\n", lang ? lang : "none");
406 printf("Accepted records in ...: %d\n", selected );
413 static int set_base(const char *arg)
418 for (i = 0; i<num_databaseNames; i++)
419 xfree (databaseNames[i]);
420 num_databaseNames = 0;
424 if (!(cp = strchr(arg, ' ')))
425 cp = arg + strlen(arg);
428 databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
429 memcpy (databaseNames[num_databaseNames], arg, cp - arg);
430 databaseNames[num_databaseNames][cp - arg] = '\0';
432 for (cp1 = databaseNames[num_databaseNames]; *cp1 ; cp1++)
441 if (num_databaseNames == 0)
443 num_databaseNames = 1;
444 databaseNames[0] = xstrdup("");
449 static int cmd_base(const char *arg)
453 printf("Usage: base <database> <database> ...\n");
456 return set_base(arg);
459 void cmd_open_remember_last_open_command(const char* arg, char* new_open_command)
461 if(last_open_command != arg)
463 if(last_open_command) xfree(last_open_command);
464 last_open_command = xstrdup(new_open_command);
468 int session_connect(const char *arg)
471 char type_and_host[101];
472 const char *basep = 0;
479 nmem_destroy (session_mem);
483 cs_get_host_args(arg, &basep);
485 strncpy(type_and_host, arg, sizeof(type_and_host)-1);
486 type_and_host[sizeof(type_and_host)-1] = '\0';
488 cmd_open_remember_last_open_command(arg,type_and_host);
491 conn = cs_create_host(yazProxy, 1, &add);
493 conn = cs_create_host(arg, 1, &add);
496 printf ("Couldn't create comstack\n");
501 if (conn->protocol == PROTO_HTTP)
503 printf ("SRW/HTTP not enabled in this YAZ\n");
509 protocol = conn->protocol;
510 if (conn->protocol == PROTO_HTTP)
514 printf("Connecting...");
516 if (cs_connect(conn, add) < 0)
518 printf ("error = %s\n", cs_strerror(conn));
519 if (conn->cerrno == CSYSERR)
522 yaz_strerror(msg, sizeof(msg));
523 printf ("%s\n", msg);
532 if (protocol == PROTO_Z3950)
534 send_initRequest(type_and_host);
540 int cmd_open(const char *arg)
542 static char cur_host[200];
545 strncpy (cur_host, arg, sizeof(cur_host)-1);
546 cur_host[sizeof(cur_host)-1] = 0;
548 return session_connect(cur_host);
555 if(!( auto_reconnect && last_open_command) ) return ;
557 open_command = (char *) xmalloc (strlen(last_open_command)+6);
558 strcpy (open_command, "open ");
560 strcat (open_command, last_open_command);
562 process_cmd_line(open_command);
567 int cmd_authentication(const char *arg)
569 static Z_IdAuthentication au;
570 static char user[40], group[40], pass[40];
571 static Z_IdPass idPass;
576 printf("Auth field set to null\n");
580 r = sscanf (arg, "%39s %39s %39s", user, group, pass);
583 printf("Auth field set to null\n");
589 au.which = Z_IdAuthentication_open;
595 au.which = Z_IdAuthentication_idPass;
596 au.u.idPass = &idPass;
597 idPass.groupId = NULL;
598 idPass.userId = user;
599 idPass.password = group;
604 au.which = Z_IdAuthentication_idPass;
605 au.u.idPass = &idPass;
606 idPass.groupId = group;
607 idPass.userId = user;
608 idPass.password = pass;
613 /* SEARCH SERVICE ------------------------------ */
614 static void display_record(Z_External *r);
616 static void print_record(const unsigned char *buf, size_t len)
619 print_stringn (buf, len);
620 /* add newline if not already added ... */
621 if (i <= 0 || buf[i-1] != '\n')
625 static void display_record(Z_External *r)
627 oident *ent = oid_getentbyoid(r->direct_reference);
631 * Tell the user what we got.
633 if (r->direct_reference)
635 printf("Record type: ");
637 printf("%s\n", ent->desc);
638 else if (!odr_oid(print, &r->direct_reference, 0, 0))
640 odr_perror(print, "print oid");
644 /* Check if this is a known, ASN.1 type tucked away in an octet string */
645 if (ent && r->which == Z_External_octet)
647 Z_ext_typeent *type = z_ext_getentbyref(ent->value);
653 * Call the given decoder to process the record.
655 odr_setbuf(in, (char*)r->u.octet_aligned->buf,
656 r->u.octet_aligned->len, 0);
657 if (!(*type->fun)(in, (char **)&rr, 0, 0))
659 odr_perror(in, "Decoding constructed record.");
660 fprintf(stdout, "[Near %d]\n", odr_offset(in));
661 fprintf(stdout, "Packet dump:\n---------\n");
662 odr_dumpBER(stdout, (char*)r->u.octet_aligned->buf,
663 r->u.octet_aligned->len);
664 fprintf(stdout, "---------\n");
666 /* note just ignores the error ant print the bytes form the octet_aligned later */
669 * Note: we throw away the original, BER-encoded record here.
670 * Do something else with it if you want to keep it.
672 r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
673 r->which = type->what;
677 if (ent && ent->oclass != CLASS_RECSYN)
679 if (ent && ent->value == VAL_SOIF)
680 print_record((const unsigned char *) r->u.octet_aligned->buf,
681 r->u.octet_aligned->len);
682 else if (r->which == Z_External_octet)
684 const char *octet_buf = (char*)r->u.octet_aligned->buf;
685 if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML ||
686 ent->value == VAL_HTML)
688 print_record((const unsigned char *) octet_buf,
689 r->u.octet_aligned->len);
691 else if (ent->value == VAL_POSTSCRIPT)
693 int size = r->u.octet_aligned->len;
696 print_record((const unsigned char *) octet_buf, size);
701 #if AVOID_MARC_DECODE
702 /* primitive check for a marc OID 5.1-29 except 16 */
703 ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
704 ent->oidsuffix[1] != 16
713 yaz_marc_t mt = yaz_marc_create();
715 if (yaz_marc_decode_buf(mt, octet_buf,r->u.octet_aligned->len,
719 if (marcCharset && !strcmp(marcCharset, "auto"))
721 if (ent->value == VAL_USMARC)
723 if (octet_buf[9] == 'a')
731 else if (marcCharset)
733 if (outputCharset && from)
735 cd = yaz_iconv_open(outputCharset, from);
736 printf ("convert from %s to %s", from,
739 printf (" unsupported\n");
744 fwrite (result, 1, rlen, stdout);
748 size_t inbytesleft = rlen;
749 const char *inp = result;
753 size_t outbytesleft = sizeof(outbuf);
757 r = yaz_iconv (cd, (char**) &inp,
759 &outp, &outbytesleft);
760 if (r == (size_t) (-1))
762 int e = yaz_iconv_error(cd);
763 if (e != YAZ_ICONV_E2BIG)
766 fwrite (outbuf, outp - outbuf, 1, stdout);
772 printf ("bad MARC. Dumping as it is:\n");
773 print_record((const unsigned char*) octet_buf,
774 r->u.octet_aligned->len);
776 yaz_marc_destroy(mt);
782 print_record((const unsigned char*) octet_buf,
783 r->u.octet_aligned->len);
787 fwrite (octet_buf, 1, r->u.octet_aligned->len, marc_file);
789 else if (ent && ent->value == VAL_SUTRS)
791 if (r->which != Z_External_sutrs)
793 printf("Expecting single SUTRS type for SUTRS.\n");
796 print_record(r->u.sutrs->buf, r->u.sutrs->len);
798 else if (ent && ent->value == VAL_GRS1)
801 if (r->which != Z_External_grs1)
803 printf("Expecting single GRS type for GRS.\n");
807 yaz_display_grs1(w, r->u.grs1, 0);
813 printf("Unknown record representation.\n");
814 if (!z_External(print, &r, 0, 0))
816 odr_perror(print, "Printing external");
822 static void display_diagrecs(Z_DiagRec **pp, int num)
826 Z_DefaultDiagFormat *r;
828 printf("Diagnostic message(s) from database:\n");
829 for (i = 0; i<num; i++)
831 Z_DiagRec *p = pp[i];
832 if (p->which != Z_DiagRec_defaultFormat)
834 printf("Diagnostic record not in default format.\n");
838 r = p->u.defaultFormat;
839 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
840 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
841 printf("Missing or unknown diagset\n");
842 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
845 case Z_DefaultDiagFormat_v2Addinfo:
846 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
848 case Z_DefaultDiagFormat_v3Addinfo:
849 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
856 static void display_nameplusrecord(Z_NamePlusRecord *p)
859 printf("[%s]", p->databaseName);
860 if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
861 display_diagrecs(&p->u.surrogateDiagnostic, 1);
862 else if (p->which == Z_NamePlusRecord_databaseRecord)
863 display_record(p->u.databaseRecord);
866 static void display_records(Z_Records *p)
870 if (p->which == Z_Records_NSD)
872 Z_DiagRec dr, *dr_p = &dr;
873 dr.which = Z_DiagRec_defaultFormat;
874 dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
875 display_diagrecs (&dr_p, 1);
877 else if (p->which == Z_Records_multipleNSD)
878 display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
879 p->u.multipleNonSurDiagnostics->num_diagRecs);
882 printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
883 for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
884 display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
888 static int send_deleteResultSetRequest(const char *arg)
893 Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
894 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
896 req->referenceId = set_refid (out);
898 req->num_resultSetList =
899 sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
900 names[0], names[1], names[2], names[3],
901 names[4], names[5], names[6], names[7]);
903 req->deleteFunction = (int *)
904 odr_malloc (out, sizeof(*req->deleteFunction));
905 if (req->num_resultSetList > 0)
907 *req->deleteFunction = Z_DeleteRequest_list;
908 req->resultSetList = (char **)
909 odr_malloc (out, sizeof(*req->resultSetList)*
910 req->num_resultSetList);
911 for (i = 0; i<req->num_resultSetList; i++)
912 req->resultSetList[i] = names[i];
916 *req->deleteFunction = Z_DeleteRequest_all;
917 req->resultSetList = 0;
921 printf("Sent deleteResultSetRequest.\n");
926 static int send_srw(Z_SRW_PDU *sr)
928 const char *charset = negotiationCharset;
929 const char *host_port = 0;
932 Z_SOAP_Handler h[2] = {
933 {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec},
936 ODR o = odr_createmem(ODR_ENCODE);
938 Z_SOAP *p = odr_malloc(o, sizeof(*p));
941 path = odr_malloc(out, strlen(databaseNames[0])+2);
943 strcpy(path+1, databaseNames[0]);
945 gdu = z_get_HTTP_Request(out);
946 gdu->u.HTTP_Request->path = odr_strdup(out, path);
950 const char *cp0 = strstr(host_port, "://");
957 cp1 = strchr(cp0, '/');
959 cp1 = cp0+strlen(cp0);
963 char *h = odr_malloc(out, cp1 - cp0 + 1);
964 memcpy (h, cp0, cp1 - cp0);
966 z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
971 strcpy(ctype, "text/xml");
972 if (charset && strlen(charset) < 20)
974 strcat(ctype, "; charset=");
975 strcat(ctype, charset);
977 z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
978 "Content-Type", ctype);
979 z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
980 "SOAPAction", "\"\"");
981 p->which = Z_SOAP_generic;
982 p->u.generic = odr_malloc(o, sizeof(*p->u.generic));
983 p->u.generic->no = 0;
984 p->u.generic->ns = 0;
985 p->u.generic->p = sr;
986 p->ns = "http://schemas.xmlsoap.org/soap/envelope/";
988 ret = z_soap_codec_enc(o, &p,
989 &gdu->u.HTTP_Request->content_buf,
990 &gdu->u.HTTP_Request->content_len, h,
993 if (z_GDU(out, &gdu, 0, 0))
999 buf_out = odr_getbuf(out, &len_out, 0);
1001 /* we don't odr_reset(out), since we may need the buffer again */
1003 r = cs_put(conn, buf_out, len_out);
1015 static int send_SRW_searchRequest(const char *arg)
1021 assert(srw_sr_odr_out == 0);
1022 srw_sr_odr_out = odr_createmem(ODR_ENCODE);
1024 odr_reset(srw_sr_odr_out);
1028 /* save this for later .. when fetching individual records */
1029 srw_sr = sr = yaz_srw_get(srw_sr_odr_out, Z_SRW_searchRetrieve_request);
1030 sr->u.request->query_type = Z_SRW_query_type_cql;
1031 sr->u.request->query.cql = odr_strdup(srw_sr_odr_out, arg);
1033 sr = yaz_srw_get(out, Z_SRW_searchRetrieve_request);
1034 sr->u.request->query_type = Z_SRW_query_type_cql;
1035 sr->u.request->query.cql = odr_strdup(out, arg);
1037 sr->u.request->recordSchema = schema;
1038 return send_srw(sr);
1042 static int send_searchRequest(const char *arg)
1044 Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
1045 Z_SearchRequest *req = apdu->u.searchRequest;
1048 struct ccl_rpn_node *rpn = NULL;
1050 char setstring[100];
1051 Z_RPNQuery *RPNquery;
1053 YAZ_PQF_Parser pqf_parser;
1055 QueryType myQueryType = queryType;
1058 if (myQueryType == QueryType_CCL2RPN)
1060 rpn = ccl_find_str(bibset, arg, &error, &pos);
1063 printf("CCL ERROR: %s\n", ccl_err_msg(error));
1066 } else if (myQueryType == QueryType_CQL2RPN) {
1067 /* ### All this code should be wrapped in a utility function */
1069 struct cql_node *node;
1070 const char *addinfo;
1071 if (cqltrans == 0) {
1072 printf("Can't use CQL: no translation file. Try set_cqlfile\n");
1075 parser = cql_parser_create();
1076 if ((error = cql_parser_string(parser, arg)) != 0) {
1077 printf("Can't parse CQL: must be a syntax error\n");
1080 node = cql_parser_result(parser);
1081 if ((error = cql_transform_buf(cqltrans, node, pqfbuf,
1082 sizeof pqfbuf)) != 0) {
1083 error = cql_transform_error(cqltrans, &addinfo);
1084 printf ("Can't convert CQL to PQF: %s (addinfo=%s)\n",
1085 cql_strerror(error), addinfo);
1089 myQueryType = QueryType_Prefix;
1092 req->referenceId = set_refid (out);
1093 if (!strcmp(arg, "@big")) /* strictly for troublemaking */
1095 static unsigned char big[2100];
1096 static Odr_oct bigo;
1098 /* send a very big referenceid to test transport stack etc. */
1099 memset(big, 'A', 2100);
1100 bigo.len = bigo.size = 2100;
1102 req->referenceId = &bigo;
1107 sprintf(setstring, "%d", ++setnumber);
1108 req->resultSetName = setstring;
1110 *req->smallSetUpperBound = smallSetUpperBound;
1111 *req->largeSetLowerBound = largeSetLowerBound;
1112 *req->mediumSetPresentNumber = mediumSetPresentNumber;
1113 if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
1114 mediumSetPresentNumber > 0))
1118 prefsyn.proto = protocol;
1119 prefsyn.oclass = CLASS_RECSYN;
1120 prefsyn.value = recordsyntax;
1121 req->preferredRecordSyntax =
1122 odr_oiddup(out, oid_ent_to_oid(&prefsyn, oid));
1123 req->smallSetElementSetNames =
1124 req->mediumSetElementSetNames = elementSetNames;
1126 req->num_databaseNames = num_databaseNames;
1127 req->databaseNames = databaseNames;
1129 req->query = &query;
1131 switch (myQueryType)
1133 case QueryType_Prefix:
1134 query.which = Z_Query_type_1;
1135 pqf_parser = yaz_pqf_create ();
1136 RPNquery = yaz_pqf_parse (pqf_parser, out, arg);
1139 const char *pqf_msg;
1141 int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
1142 printf("%*s^\n", off+4, "");
1143 printf("Prefix query error: %s (code %d)\n", pqf_msg, code);
1145 yaz_pqf_destroy (pqf_parser);
1148 yaz_pqf_destroy (pqf_parser);
1149 query.u.type_1 = RPNquery;
1152 query.which = Z_Query_type_2;
1153 query.u.type_2 = &ccl_query;
1154 ccl_query.buf = (unsigned char*) arg;
1155 ccl_query.len = strlen(arg);
1157 case QueryType_CCL2RPN:
1158 query.which = Z_Query_type_1;
1159 RPNquery = ccl_rpn_query(out, rpn);
1162 printf ("Couldn't convert from CCL to RPN\n");
1165 query.u.type_1 = RPNquery;
1166 ccl_rpn_delete (rpn);
1169 query.which = Z_Query_type_104;
1170 ext = (Z_External *) odr_malloc(out, sizeof(*ext));
1171 ext->direct_reference = odr_getoidbystr(out, "1.2.840.10003.16.2");
1172 ext->indirect_reference = 0;
1173 ext->descriptor = 0;
1174 ext->which = Z_External_CQL;
1175 ext->u.cql = odr_strdup(out, arg);
1176 query.u.type_104 = ext;
1179 printf ("Unsupported query type\n");
1182 if (send_apdu(apdu))
1183 printf("Sent searchRequest.\n");
1188 /* display Query Expression as part of searchResult-1 */
1189 static void display_queryExpression (Z_QueryExpression *qe)
1193 if (qe->which == Z_QueryExpression_term)
1195 if (qe->u.term->queryTerm)
1197 Z_Term *term = qe->u.term->queryTerm;
1198 switch (term->which)
1200 case Z_Term_general:
1201 printf (" %.*s", term->u.general->len, term->u.general->buf);
1203 case Z_Term_characterString:
1204 printf (" %s", term->u.characterString);
1206 case Z_Term_numeric:
1207 printf (" %d", *term->u.numeric);
1217 /* see if we can find USR:SearchResult-1 */
1218 static void display_searchResult (Z_OtherInformation *o)
1223 for (i = 0; i < o->num_elements; i++)
1225 if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
1227 Z_External *ext = o->list[i]->information.externallyDefinedInfo;
1229 if (ext->which == Z_External_searchResult1)
1232 Z_SearchInfoReport *sr = ext->u.searchResult1;
1233 printf ("SearchResult-1:");
1234 for (j = 0; j < sr->num; j++)
1236 if (!sr->elements[j]->subqueryExpression)
1238 display_queryExpression (
1239 sr->elements[j]->subqueryExpression);
1240 display_queryExpression (
1241 sr->elements[j]->subqueryInterpretation);
1242 display_queryExpression (
1243 sr->elements[j]->subqueryRecommendation);
1244 if (sr->elements[j]->subqueryCount)
1245 printf ("(%d)", *sr->elements[j]->subqueryCount);
1253 static int process_searchResponse(Z_SearchResponse *res)
1255 printf ("Received SearchResponse.\n");
1256 print_refid (res->referenceId);
1257 if (*res->searchStatus)
1258 printf("Search was a success.\n");
1260 printf("Search was a bloomin' failure.\n");
1261 printf("Number of hits: %d", *res->resultCount);
1263 printf (", setno %d", setnumber);
1265 display_searchResult (res->additionalSearchInfo);
1266 printf("records returned: %d\n",
1267 *res->numberOfRecordsReturned);
1268 setno += *res->numberOfRecordsReturned;
1270 display_records(res->records);
1274 static void print_level(int iLevel)
1277 for (i = 0; i < iLevel * 4; i++)
1281 static void print_int(int iLevel, const char *pTag, int *pInt)
1285 print_level(iLevel);
1286 printf("%s: %d\n", pTag, *pInt);
1290 static void print_string(int iLevel, const char *pTag, const char *pString)
1292 if (pString != NULL)
1294 print_level(iLevel);
1295 printf("%s: %s\n", pTag, pString);
1299 static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
1305 print_level(iLevel);
1306 printf("%s:", pTag);
1307 for (; *pInt != -1; pInt++)
1308 printf(" %d", *pInt);
1313 static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
1315 if (referenceId != NULL)
1319 print_level(iLevel);
1320 printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
1321 for (i = 0; i < referenceId->len; i++)
1322 printf("%c", referenceId->buf[i]);
1327 static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
1329 if (pStringNumeric != NULL)
1331 switch (pStringNumeric->which)
1333 case Z_StringOrNumeric_string:
1334 print_string(iLevel, pTag, pStringNumeric->u.string);
1337 case Z_StringOrNumeric_numeric:
1338 print_int(iLevel, pTag, pStringNumeric->u.numeric);
1342 print_level(iLevel);
1343 printf("%s: valid type for Z_StringOrNumeric\n", pTag);
1349 static void print_universe_report_duplicate(
1351 Z_UniverseReportDuplicate *pUniverseReportDuplicate)
1353 if (pUniverseReportDuplicate != NULL)
1355 print_level(iLevel);
1356 printf("Universe Report Duplicate: \n");
1358 print_string_or_numeric(iLevel, "Hit No",
1359 pUniverseReportDuplicate->hitno);
1363 static void print_universe_report_hits(
1365 Z_UniverseReportHits *pUniverseReportHits)
1367 if (pUniverseReportHits != NULL)
1369 print_level(iLevel);
1370 printf("Universe Report Hits: \n");
1372 print_string_or_numeric(iLevel, "Database",
1373 pUniverseReportHits->database);
1374 print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
1378 static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
1380 if (pUniverseReport != NULL)
1382 print_level(iLevel);
1383 printf("Universe Report: \n");
1385 print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
1386 switch (pUniverseReport->which)
1388 case Z_UniverseReport_databaseHits:
1389 print_universe_report_hits(iLevel,
1390 pUniverseReport->u.databaseHits);
1393 case Z_UniverseReport_duplicate:
1394 print_universe_report_duplicate(iLevel,
1395 pUniverseReport->u.duplicate);
1399 print_level(iLevel);
1400 printf("Type: %d\n", pUniverseReport->which);
1406 static void print_external(int iLevel, Z_External *pExternal)
1408 if (pExternal != NULL)
1410 print_level(iLevel);
1411 printf("External: \n");
1413 print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
1414 print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
1415 print_string(iLevel, "Descriptor", pExternal->descriptor);
1416 switch (pExternal->which)
1418 case Z_External_universeReport:
1419 print_universe_report(iLevel, pExternal->u.universeReport);
1423 print_level(iLevel);
1424 printf("Type: %d\n", pExternal->which);
1430 static int process_resourceControlRequest (Z_ResourceControlRequest *req)
1432 printf ("Received ResourceControlRequest.\n");
1433 print_referenceId(1, req->referenceId);
1434 print_int(1, "Suspended Flag", req->suspendedFlag);
1435 print_int(1, "Partial Results Available", req->partialResultsAvailable);
1436 print_int(1, "Response Required", req->responseRequired);
1437 print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
1438 print_external(1, req->resourceReport);
1442 void process_ESResponse(Z_ExtendedServicesResponse *res)
1445 switch (*res->operationStatus)
1447 case Z_ExtendedServicesResponse_done:
1450 case Z_ExtendedServicesResponse_accepted:
1451 printf ("accepted\n");
1453 case Z_ExtendedServicesResponse_failure:
1454 printf ("failure\n");
1455 display_diagrecs(res->diagnostics, res->num_diagnostics);
1458 printf ("unknown\n");
1460 if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
1461 (res->num_diagnostics != 0) ) {
1462 display_diagrecs(res->diagnostics, res->num_diagnostics);
1464 print_refid (res->referenceId);
1465 if (res->taskPackage &&
1466 res->taskPackage->which == Z_External_extendedService)
1468 Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1469 Odr_oct *id = taskPackage->targetReference;
1470 Z_External *ext = taskPackage->taskSpecificParameters;
1474 printf ("Target Reference: ");
1475 print_stringn (id->buf, id->len);
1478 if (ext->which == Z_External_update)
1480 Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
1481 if (utp && utp->targetPart)
1483 Z_IUTargetPart *targetPart = utp->targetPart;
1486 for (i = 0; i<targetPart->num_taskPackageRecords; i++)
1489 Z_IUTaskPackageRecordStructure *tpr =
1490 targetPart->taskPackageRecords[i];
1491 printf ("task package record %d\n", i+1);
1492 if (tpr->which == Z_IUTaskPackageRecordStructure_record)
1494 display_record (tpr->u.record);
1498 printf ("other type\n");
1506 const char *get_ill_element (void *clientData, const char *element)
1511 static Z_External *create_external_itemRequest()
1513 struct ill_get_ctl ctl;
1514 ILL_ItemRequest *req;
1516 int item_request_size = 0;
1517 char *item_request_buf = 0;
1521 ctl.f = get_ill_element;
1523 req = ill_get_ItemRequest(&ctl, "ill", 0);
1525 printf ("ill_get_ItemRequest failed\n");
1527 if (!ill_ItemRequest (out, &req, 0, 0))
1531 ill_ItemRequest(print, &req, 0, 0);
1534 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1535 if (item_request_buf)
1536 odr_setbuf (out, item_request_buf, item_request_size, 1);
1537 printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
1544 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1545 oid.proto = PROTO_GENERAL;
1546 oid.oclass = CLASS_GENERAL;
1547 oid.value = VAL_ISO_ILL_1;
1549 r = (Z_External *) odr_malloc (out, sizeof(*r));
1550 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1551 r->indirect_reference = 0;
1553 r->which = Z_External_single;
1555 r->u.single_ASN1_type = (Odr_oct *)
1556 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1557 r->u.single_ASN1_type->buf = (unsigned char *)
1558 odr_malloc (out, item_request_size);
1559 r->u.single_ASN1_type->len = item_request_size;
1560 r->u.single_ASN1_type->size = item_request_size;
1561 memcpy (r->u.single_ASN1_type->buf, item_request_buf,
1564 do_hex_dump(item_request_buf,item_request_size);
1569 static Z_External *create_external_ILL_APDU(int which)
1571 struct ill_get_ctl ctl;
1574 int ill_request_size = 0;
1575 char *ill_request_buf = 0;
1579 ctl.f = get_ill_element;
1581 ill_apdu = ill_get_APDU(&ctl, "ill", 0);
1583 if (!ill_APDU (out, &ill_apdu, 0, 0))
1587 printf ("-------------------\n");
1588 ill_APDU(print, &ill_apdu, 0, 0);
1590 printf ("-------------------\n");
1592 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1593 if (ill_request_buf)
1594 odr_setbuf (out, ill_request_buf, ill_request_size, 1);
1595 printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
1601 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1603 oid.proto = PROTO_GENERAL;
1604 oid.oclass = CLASS_GENERAL;
1605 oid.value = VAL_ISO_ILL_1;
1607 r = (Z_External *) odr_malloc (out, sizeof(*r));
1608 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1609 r->indirect_reference = 0;
1611 r->which = Z_External_single;
1613 r->u.single_ASN1_type = (Odr_oct *)
1614 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1615 r->u.single_ASN1_type->buf = (unsigned char *)
1616 odr_malloc (out, ill_request_size);
1617 r->u.single_ASN1_type->len = ill_request_size;
1618 r->u.single_ASN1_type->size = ill_request_size;
1619 memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
1620 /* printf ("len = %d\n", ill_request_size); */
1621 /* do_hex_dump(ill_request_buf,ill_request_size); */
1622 /* printf("--- end of extenal\n"); */
1629 static Z_External *create_ItemOrderExternal(const char *type, int itemno)
1631 Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
1632 oident ItemOrderRequest;
1634 ItemOrderRequest.proto = PROTO_Z3950;
1635 ItemOrderRequest.oclass = CLASS_EXTSERV;
1636 ItemOrderRequest.value = VAL_ITEMORDER;
1638 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1639 r->indirect_reference = 0;
1642 r->which = Z_External_itemOrder;
1644 r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder));
1645 memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder));
1646 r->u.itemOrder->which=Z_IOItemOrder_esRequest;
1648 r->u.itemOrder->u.esRequest = (Z_IORequest *)
1649 odr_malloc(out,sizeof(Z_IORequest));
1650 memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest));
1652 r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
1653 odr_malloc(out,sizeof(Z_IOOriginPartToKeep));
1654 memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep));
1655 r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
1656 odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep));
1657 memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep));
1659 r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL;
1660 r->u.itemOrder->u.esRequest->toKeep->contact = NULL;
1661 r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL;
1663 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem =
1664 (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem));
1665 memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem));
1666 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1";
1668 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item =
1669 (int *) odr_malloc(out, sizeof(int));
1670 *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
1672 if (!strcmp (type, "item") || !strcmp(type, "2"))
1674 printf ("using item-request\n");
1675 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1676 create_external_itemRequest();
1678 else if (!strcmp(type, "ill") || !strcmp(type, "1"))
1680 printf ("using ILL-request\n");
1681 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1682 create_external_ILL_APDU(ILL_APDU_ILL_Request);
1684 else if (!strcmp(type, "xml") || !strcmp(type, "3"))
1686 const char *xml_buf =
1688 " <type>request</type>\n"
1689 " <libraryNo>000200</libraryNo>\n"
1690 " <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
1692 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1693 z_ext_record (out, VAL_TEXT_XML, xml_buf, strlen(xml_buf));
1696 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1701 static int send_itemorder(const char *type, int itemno)
1703 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
1704 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1705 oident ItemOrderRequest;
1707 ItemOrderRequest.proto = PROTO_Z3950;
1708 ItemOrderRequest.oclass = CLASS_EXTSERV;
1709 ItemOrderRequest.value = VAL_ITEMORDER;
1710 req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1711 req->packageName = esPackageName;
1713 req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
1719 static int only_z3950()
1721 if (protocol == PROTO_HTTP)
1723 printf ("Not supported by SRW\n");
1729 static int cmd_update(const char *arg)
1731 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
1732 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1735 Z_IUOriginPartToKeep *toKeep;
1736 Z_IUSuppliedRecords *notToKeep;
1738 char action[20], recid[20], fname[80];
1740 Z_External *record_this = 0;
1747 sscanf (arg, "%19s %19s %79s", action, recid, fname);
1749 if (!strcmp (action, "insert"))
1750 action_no = Z_IUOriginPartToKeep_recordInsert;
1751 else if (!strcmp (action, "replace"))
1752 action_no = Z_IUOriginPartToKeep_recordReplace;
1753 else if (!strcmp (action, "delete"))
1754 action_no = Z_IUOriginPartToKeep_recordDelete;
1755 else if (!strcmp (action, "update"))
1756 action_no = Z_IUOriginPartToKeep_specialUpdate;
1759 printf ("Bad action: %s\n", action);
1760 printf ("Possible values: insert, replace, delete, update\n");
1768 stat (fname, &status);
1769 if (S_ISREG(status.st_mode) && (inf = fopen(fname, "r")))
1771 size_t len = status.st_size;
1772 char *buf = (char *) xmalloc (len);
1774 fread (buf, 1, len, inf);
1778 record_this = z_ext_record (out, VAL_TEXT_XML, buf, len);
1784 printf ("File %s doesn't exist\n", fname);
1792 printf ("No last record (update ignored)\n");
1795 record_this = record_last;
1798 update_oid.proto = PROTO_Z3950;
1799 update_oid.oclass = CLASS_EXTSERV;
1800 update_oid.value = VAL_DBUPDATE;
1801 oid_ent_to_oid (&update_oid, oid);
1802 req->packageType = odr_oiddup(out,oid);
1803 req->packageName = esPackageName;
1805 req->referenceId = set_refid (out);
1807 r = req->taskSpecificParameters = (Z_External *)
1808 odr_malloc (out, sizeof(*r));
1809 r->direct_reference = odr_oiddup(out,oid);
1810 r->indirect_reference = 0;
1812 r->which = Z_External_update;
1813 r->u.update = (Z_IUUpdate *) odr_malloc(out, sizeof(*r->u.update));
1814 r->u.update->which = Z_IUUpdate_esRequest;
1815 r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
1816 odr_malloc(out, sizeof(*r->u.update->u.esRequest));
1817 toKeep = r->u.update->u.esRequest->toKeep = (Z_IUOriginPartToKeep *)
1818 odr_malloc(out, sizeof(*r->u.update->u.esRequest->toKeep));
1819 toKeep->databaseName = databaseNames[0];
1821 toKeep->elementSetName = 0;
1822 toKeep->actionQualifier = 0;
1823 toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
1824 *toKeep->action = action_no;
1826 notToKeep = r->u.update->u.esRequest->notToKeep = (Z_IUSuppliedRecords *)
1827 odr_malloc(out, sizeof(*r->u.update->u.esRequest->notToKeep));
1829 notToKeep->elements = (Z_IUSuppliedRecords_elem **)
1830 odr_malloc(out, sizeof(*notToKeep->elements));
1831 notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
1832 odr_malloc(out, sizeof(**notToKeep->elements));
1833 notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
1836 notToKeep->elements[0]->u.opaque = (Odr_oct *)
1837 odr_malloc (out, sizeof(Odr_oct));
1838 notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid;
1839 notToKeep->elements[0]->u.opaque->size = strlen(recid);
1840 notToKeep->elements[0]->u.opaque->len = strlen(recid);
1843 notToKeep->elements[0]->u.opaque = 0;
1844 notToKeep->elements[0]->supplementalId = 0;
1845 notToKeep->elements[0]->correlationInfo = 0;
1846 notToKeep->elements[0]->record = record_this;
1853 static int cmd_itemorder(const char *arg)
1860 if (sscanf (arg, "%10s %d", type, &itemno) != 2)
1863 printf("Item order request\n");
1865 send_itemorder(type, itemno);
1869 static int cmd_find(const char *arg)
1873 printf("Find what?\n");
1876 if (protocol == PROTO_HTTP)
1881 if (!send_SRW_searchRequest(arg))
1894 printf("Not connected yet\n");
1898 if (!send_searchRequest(arg))
1904 static int cmd_delete(const char *arg)
1908 printf("Not connected yet\n");
1913 if (!send_deleteResultSetRequest(arg))
1918 static int cmd_ssub(const char *arg)
1920 if (!(smallSetUpperBound = atoi(arg)))
1925 static int cmd_lslb(const char *arg)
1929 if (!(largeSetLowerBound = atoi(arg)))
1934 static int cmd_mspn(const char *arg)
1938 if (!(mediumSetPresentNumber = atoi(arg)))
1943 static int cmd_status(const char *arg)
1945 printf("smallSetUpperBound: %d\n", smallSetUpperBound);
1946 printf("largeSetLowerBound: %d\n", largeSetLowerBound);
1947 printf("mediumSetPresentNumber: %d\n", mediumSetPresentNumber);
1951 static int cmd_setnames(const char *arg)
1953 if (*arg == '1') /* enable ? */
1955 else if (*arg == '0') /* disable ? */
1957 else if (setnumber < 0) /* no args, toggle .. */
1963 printf("Set numbering enabled.\n");
1965 printf("Set numbering disabled.\n");
1969 /* PRESENT SERVICE ----------------------------- */
1971 static void parse_show_args(const char *arg_c, char *setstring,
1972 int *start, int *number)
1977 strncpy(arg, arg_c, sizeof(arg)-1);
1978 arg[sizeof(arg)-1] = '\0';
1980 if ((p = strchr(arg, '+')))
1982 *number = atoi(p + 1);
1987 if (p && (p=strchr(p+1, '+')))
1988 strcpy (setstring, p+1);
1989 else if (setnumber >= 0)
1990 sprintf(setstring, "%d", setnumber);
1995 static int send_presentRequest(const char *arg)
1997 Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
1998 Z_PresentRequest *req = apdu->u.presentRequest;
1999 Z_RecordComposition compo;
2003 char setstring[100];
2005 req->referenceId = set_refid (out);
2007 parse_show_args(arg, setstring, &setno, &nos);
2009 req->resultSetId = setstring;
2011 req->resultSetStartPoint = &setno;
2012 req->numberOfRecordsRequested = &nos;
2013 prefsyn.proto = protocol;
2014 prefsyn.oclass = CLASS_RECSYN;
2015 prefsyn.value = recordsyntax;
2016 req->preferredRecordSyntax =
2017 odr_oiddup (out, oid_ent_to_oid(&prefsyn, oid));
2023 prefschema.proto = protocol;
2024 prefschema.oclass = CLASS_SCHEMA;
2025 prefschema.value = oid_getvalbyname(schema);
2027 req->recordComposition = &compo;
2028 compo.which = Z_RecordComp_complex;
2029 compo.u.complex = (Z_CompSpec *)
2030 odr_malloc(out, sizeof(*compo.u.complex));
2031 compo.u.complex->selectAlternativeSyntax = (bool_t *)
2032 odr_malloc(out, sizeof(bool_t));
2033 *compo.u.complex->selectAlternativeSyntax = 0;
2035 compo.u.complex->generic = (Z_Specification *)
2036 odr_malloc(out, sizeof(*compo.u.complex->generic));
2037 compo.u.complex->generic->which = Z_Schema_oid;
2038 compo.u.complex->generic->schema.oid = (Odr_oid *)
2039 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
2040 if (!compo.u.complex->generic->schema.oid)
2042 /* OID wasn't a schema! Try record syntax instead. */
2043 prefschema.oclass = CLASS_RECSYN;
2044 compo.u.complex->generic->schema.oid = (Odr_oid *)
2045 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
2047 if (!elementSetNames)
2048 compo.u.complex->generic->elementSpec = 0;
2051 compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
2052 odr_malloc(out, sizeof(Z_ElementSpec));
2053 compo.u.complex->generic->elementSpec->which =
2054 Z_ElementSpec_elementSetName;
2055 compo.u.complex->generic->elementSpec->u.elementSetName =
2056 elementSetNames->u.generic;
2058 compo.u.complex->num_dbSpecific = 0;
2059 compo.u.complex->dbSpecific = 0;
2060 compo.u.complex->num_recordSyntax = 0;
2061 compo.u.complex->recordSyntax = 0;
2063 else if (elementSetNames)
2065 req->recordComposition = &compo;
2066 compo.which = Z_RecordComp_simple;
2067 compo.u.simple = elementSetNames;
2070 printf("Sent presentRequest (%d+%d).\n", setno, nos);
2075 static int send_SRW_presentRequest(const char *arg)
2077 char setstring[100];
2079 Z_SRW_PDU *sr = srw_sr;
2083 parse_show_args(arg, setstring, &setno, &nos);
2084 sr->u.request->startRecord = odr_intdup(out, setno);
2085 sr->u.request->maximumRecords = odr_intdup(out, nos);
2087 sr->u.request->recordSchema = schema;
2088 return send_srw(sr);
2092 static void close_session (void)
2099 nmem_destroy (session_mem);
2108 void process_close(Z_Close *req)
2110 Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
2111 Z_Close *res = apdu->u.close;
2113 static char *reasons[] =
2118 "cost limit reached",
2120 "security violation",
2127 printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
2128 req->diagnosticInformation ? req->diagnosticInformation : "NULL");
2133 *res->closeReason = Z_Close_finished;
2135 printf("Sent response.\n");
2140 static int cmd_show(const char *arg)
2142 if (protocol == PROTO_HTTP)
2147 if (!send_SRW_presentRequest(arg))
2157 printf("Not connected yet\n");
2160 if (!send_presentRequest(arg))
2166 int cmd_quit(const char *arg)
2168 printf("See you later, alligator.\n");
2174 int cmd_cancel(const char *arg)
2176 Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
2177 Z_TriggerResourceControlRequest *req =
2178 apdu->u.triggerResourceControlRequest;
2183 printf("Session not initialized yet\n");
2188 if (!ODR_MASK_GET(session->options, Z_Options_triggerResourceCtrl))
2190 printf("Target doesn't support cancel (trigger resource ctrl)\n");
2193 *req->requestedAction = Z_TriggerResourceCtrl_cancel;
2194 req->resultSetWanted = &rfalse;
2197 printf("Sent cancel request\n");
2201 int send_scanrequest(const char *query, int pp, int num, const char *term)
2203 Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
2204 Z_ScanRequest *req = apdu->u.scanRequest;
2209 if (queryType == QueryType_CCL2RPN)
2213 struct ccl_rpn_node *rpn;
2215 rpn = ccl_find_str (bibset, query, &error, &pos);
2218 printf("CCL ERROR: %s\n", ccl_err_msg(error));
2221 bib1.proto = PROTO_Z3950;
2222 bib1.oclass = CLASS_ATTSET;
2223 bib1.value = VAL_BIB1;
2224 req->attributeSet = oid_ent_to_oid (&bib1, oid);
2225 if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
2227 printf("Couldn't convert CCL to Scan term\n");
2230 ccl_rpn_delete (rpn);
2234 YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
2236 if (!(req->termListAndStartPoint =
2237 yaz_pqf_scan(pqf_parser, out, &req->attributeSet, query)))
2239 const char *pqf_msg;
2241 int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
2242 printf("%*s^\n", off+7, "");
2243 printf("Prefix query error: %s (code %d)\n", pqf_msg, code);
2244 yaz_pqf_destroy (pqf_parser);
2247 yaz_pqf_destroy (pqf_parser);
2251 if (req->termListAndStartPoint->term &&
2252 req->termListAndStartPoint->term->which == Z_Term_general &&
2253 req->termListAndStartPoint->term->u.general)
2255 req->termListAndStartPoint->term->u.general->buf =
2256 (unsigned char *) odr_strdup(out, term);
2257 req->termListAndStartPoint->term->u.general->len =
2258 req->termListAndStartPoint->term->u.general->size =
2262 req->referenceId = set_refid (out);
2263 req->num_databaseNames = num_databaseNames;
2264 req->databaseNames = databaseNames;
2265 req->numberOfTermsRequested = #
2266 req->preferredPositionInResponse = &pp;
2271 int send_sortrequest(const char *arg, int newset)
2273 Z_APDU *apdu = zget_APDU(out, Z_APDU_sortRequest);
2274 Z_SortRequest *req = apdu->u.sortRequest;
2275 Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
2276 odr_malloc (out, sizeof(*sksl));
2282 sprintf (setstring, "%d", setnumber);
2284 sprintf (setstring, "default");
2286 req->referenceId = set_refid (out);
2288 req->num_inputResultSetNames = 1;
2289 req->inputResultSetNames = (Z_InternationalString **)
2290 odr_malloc (out, sizeof(*req->inputResultSetNames));
2291 req->inputResultSetNames[0] = odr_strdup (out, setstring);
2293 if (newset && setnumber >= 0)
2294 sprintf (setstring, "%d", ++setnumber);
2296 req->sortedResultSetName = odr_strdup (out, setstring);
2298 req->sortSequence = yaz_sort_spec (out, arg);
2299 if (!req->sortSequence)
2301 printf ("Missing sort specifications\n");
2308 void display_term(Z_TermInfo *t)
2310 if (t->term->which == Z_Term_general)
2312 printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
2313 sprintf(last_scan_line, "%.*s", t->term->u.general->len,
2314 t->term->u.general->buf);
2317 printf("Term (not general)");
2318 if (t->globalOccurrences)
2319 printf (" (%d)\n", *t->globalOccurrences);
2324 void process_scanResponse(Z_ScanResponse *res)
2327 Z_Entry **entries = NULL;
2328 int num_entries = 0;
2330 printf("Received ScanResponse\n");
2331 print_refid (res->referenceId);
2332 printf("%d entries", *res->numberOfEntriesReturned);
2333 if (res->positionOfTerm)
2334 printf (", position=%d", *res->positionOfTerm);
2336 if (*res->scanStatus != Z_Scan_success)
2337 printf("Scan returned code %d\n", *res->scanStatus);
2340 if ((entries = res->entries->entries))
2341 num_entries = res->entries->num_entries;
2342 for (i = 0; i < num_entries; i++)
2344 int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
2345 if (entries[i]->which == Z_Entry_termInfo)
2347 printf("%c ", i + 1 == pos_term ? '*' : ' ');
2348 display_term(entries[i]->u.termInfo);
2351 display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1);
2353 if (res->entries->nonsurrogateDiagnostics)
2354 display_diagrecs (res->entries->nonsurrogateDiagnostics,
2355 res->entries->num_nonsurrogateDiagnostics);
2358 void process_sortResponse(Z_SortResponse *res)
2360 printf("Received SortResponse: status=");
2361 switch (*res->sortStatus)
2363 case Z_SortStatus_success:
2364 printf ("success"); break;
2365 case Z_SortStatus_partial_1:
2366 printf ("partial"); break;
2367 case Z_SortStatus_failure:
2368 printf ("failure"); break;
2370 printf ("unknown (%d)", *res->sortStatus);
2373 print_refid (res->referenceId);
2374 if (res->diagnostics)
2375 display_diagrecs(res->diagnostics,
2376 res->num_diagnostics);
2379 void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res)
2381 printf("Got deleteResultSetResponse status=%d\n",
2382 *res->deleteOperationStatus);
2383 if (res->deleteListStatuses)
2386 for (i = 0; i < res->deleteListStatuses->num; i++)
2388 printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id,
2389 *res->deleteListStatuses->elements[i]->status);
2394 int cmd_sort_generic(const char *arg, int newset)
2398 printf("Session not initialized yet\n");
2403 if (!ODR_MASK_GET(session->options, Z_Options_sort))
2405 printf("Target doesn't support sort\n");
2410 if (send_sortrequest(arg, newset) < 0)
2417 int cmd_sort(const char *arg)
2419 return cmd_sort_generic (arg, 0);
2422 int cmd_sort_newset (const char *arg)
2424 return cmd_sort_generic (arg, 1);
2427 int cmd_scan(const char *arg)
2436 printf("Session not initialized yet\n");
2440 if (!ODR_MASK_GET(session->options, Z_Options_scan))
2442 printf("Target doesn't support scan\n");
2447 strcpy (last_scan_query, arg);
2448 if (send_scanrequest(arg, 1, 20, 0) < 0)
2453 if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0)
2459 int cmd_schema(const char *arg)
2464 schema = xstrdup(arg);
2468 int cmd_format(const char *arg)
2473 printf("Usage: format <recordsyntax>\n");
2476 nsyntax = oid_getvalbyname (arg);
2477 if (strcmp(arg, "none") && nsyntax == VAL_NONE)
2479 printf ("unknown record syntax\n");
2482 recordsyntax = nsyntax;
2486 int cmd_elements(const char *arg)
2488 static Z_ElementSetNames esn;
2489 static char what[100];
2493 elementSetNames = 0;
2497 esn.which = Z_ElementSetNames_generic;
2498 esn.u.generic = what;
2499 elementSetNames = &esn;
2503 int cmd_attributeset(const char *arg)
2509 printf("Usage: attributeset <setname>\n");
2512 sscanf(arg, "%s", what);
2513 if (p_query_attset (what))
2515 printf("Unknown attribute set name\n");
2521 int cmd_querytype (const char *arg)
2523 if (!strcmp (arg, "ccl"))
2524 queryType = QueryType_CCL;
2525 else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn"))
2526 queryType = QueryType_Prefix;
2527 else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
2528 queryType = QueryType_CCL2RPN;
2529 else if (!strcmp(arg, "cql"))
2530 queryType = QueryType_CQL;
2531 else if (!strcmp (arg, "cql2rpn") || !strcmp (arg, "cqlrpn"))
2532 queryType = QueryType_CQL2RPN;
2535 printf ("Querytype must be one of:\n");
2536 printf (" prefix - Prefix query\n");
2537 printf (" ccl - CCL query\n");
2538 printf (" ccl2rpn - CCL query converted to RPN\n");
2539 printf (" cql - CQL\n");
2540 printf (" cql2rpn - CQL query converted to RPN\n");
2546 int cmd_refid (const char *arg)
2552 refid = (char *) xmalloc (strlen(arg)+1);
2553 strcpy (refid, arg);
2558 int cmd_close(const char *arg)
2567 apdu = zget_APDU(out, Z_APDU_close);
2568 req = apdu->u.close;
2569 *req->closeReason = Z_Close_finished;
2571 printf("Sent close request.\n");
2576 int cmd_packagename(const char* arg)
2578 xfree (esPackageName);
2579 esPackageName = NULL;
2581 esPackageName = xstrdup(arg);
2585 int cmd_proxy(const char* arg)
2590 yazProxy = xstrdup (arg);
2594 int cmd_marccharset(const char *arg)
2599 if (sscanf(arg, "%29s", l1) < 1)
2601 xfree (marcCharset);
2603 if (strcmp(l1, "-"))
2604 marcCharset = xstrdup(l1);
2608 int cmd_charset(const char* arg)
2610 char l1[30], l2[30];
2613 if (sscanf(arg, "%29s %29s", l1, l2) < 1)
2615 printf("Current negotiation character set is `%s'\n",
2616 negotiationCharset ? negotiationCharset: "none");
2617 printf("Current output character set is `%s'\n",
2618 outputCharset ? outputCharset: "none");
2621 xfree (negotiationCharset);
2622 negotiationCharset = NULL;
2623 if (*l1 && strcmp(l1, "-"))
2625 negotiationCharset = xstrdup(l1);
2626 printf ("Character set negotiation : %s\n", negotiationCharset);
2629 printf ("Character set negotiation disabled\n");
2632 xfree (outputCharset);
2634 if (!strcmp(l2, "auto") && codeset)
2638 printf ("output charset: %s\n", codeset);
2639 outputCharset = xstrdup(codeset);
2644 printf ("No codeset found on this system\n");
2646 else if (strcmp(l2, "-"))
2647 outputCharset = xstrdup(l2);
2649 printf ("Output charset conversion disabled\n");
2651 if (outputCharset && negotiationCharset)
2653 odr_set_charset (out, negotiationCharset, outputCharset);
2654 odr_set_charset (in, outputCharset, negotiationCharset);
2658 odr_set_charset (out, 0, 0);
2659 odr_set_charset (in, 0, 0);
2664 int cmd_lang(const char* arg)
2667 printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
2674 yazLang = (char *) xmalloc (strlen(arg)+1);
2675 strcpy (yazLang, arg);
2680 int cmd_source(const char* arg)
2682 /* first should open the file and read one line at a time.. */
2684 char line[1024], *cp;
2687 fprintf(stderr,"Error in source command use a filename\n");
2691 includeFile = fopen (arg, "r");
2694 fprintf(stderr,"Unable to open file %s for reading\n",arg);
2698 while(!feof(includeFile)) {
2699 memset(line,0,sizeof(line));
2700 fgets(line,sizeof(line),includeFile);
2702 if(strlen(line) < 2) continue;
2703 if(line[0] == '#') continue;
2705 if ((cp = strrchr (line, '\n')))
2708 process_cmd_line(line);
2711 if(fclose(includeFile)<0) {
2712 perror("unable to close include file");
2718 int cmd_subshell(const char* args)
2723 system(getenv("SHELL"));
2729 int cmd_set_berfile(const char *arg)
2731 if (ber_file && ber_file != stdout && ber_file != stderr)
2733 if (!strcmp(arg, ""))
2735 else if (!strcmp(arg, "-"))
2738 ber_file = fopen(arg, "a");
2742 int cmd_set_apdufile(const char *arg)
2744 if(apdu_file && apdu_file != stderr && apdu_file != stderr)
2746 if (!strcmp(arg, ""))
2748 else if (!strcmp(arg, "-"))
2752 apdu_file = fopen(arg, "a");
2754 perror("unable to open apdu log file");
2757 odr_setprint(print, apdu_file);
2761 int cmd_set_cclfile(const char* arg)
2765 bibset = ccl_qual_mk ();
2766 inf = fopen (arg, "r");
2768 perror("unable to open CCL file");
2771 ccl_qual_file (bibset, inf);
2774 strcpy(ccl_fields,arg);
2778 int cmd_set_cqlfile(const char* arg)
2780 cql_transform_t newcqltrans;
2782 if ((newcqltrans = cql_transform_open_fname(arg)) == 0) {
2783 perror("unable to open CQL file");
2787 cql_transform_close(cqltrans);
2789 cqltrans = newcqltrans;
2790 strcpy(cql_fields, arg);
2794 int cmd_set_auto_reconnect(const char* arg)
2796 if(strlen(arg)==0) {
2797 auto_reconnect = ! auto_reconnect;
2798 } else if(strcmp(arg,"on")==0) {
2800 } else if(strcmp(arg,"off")==0) {
2803 printf("Error use on or off\n");
2808 printf("Set auto reconnect enabled.\n");
2810 printf("Set auto reconnect disabled.\n");
2815 int cmd_set_marcdump(const char* arg)
2817 if(marc_file && marc_file != stderr) { /* don't close stdout*/
2821 if (!strcmp(arg, ""))
2823 else if (!strcmp(arg, "-"))
2827 marc_file = fopen(arg, "a");
2829 perror("unable to open marc log file");
2835 this command takes 3 arge {name class oid}
2837 int cmd_register_oid(const char* args) {
2842 {"appctx",CLASS_APPCTX},
2843 {"absyn",CLASS_ABSYN},
2844 {"attset",CLASS_ATTSET},
2845 {"transyn",CLASS_TRANSYN},
2846 {"diagset",CLASS_DIAGSET},
2847 {"recsyn",CLASS_RECSYN},
2848 {"resform",CLASS_RESFORM},
2849 {"accform",CLASS_ACCFORM},
2850 {"extserv",CLASS_EXTSERV},
2851 {"userinfo",CLASS_USERINFO},
2852 {"elemspec",CLASS_ELEMSPEC},
2853 {"varset",CLASS_VARSET},
2854 {"schema",CLASS_SCHEMA},
2855 {"tagset",CLASS_TAGSET},
2856 {"general",CLASS_GENERAL},
2857 {0,(enum oid_class) 0}
2859 char oname_str[101], oclass_str[101], oid_str[101];
2862 oid_class oidclass = CLASS_GENERAL;
2863 int val = 0, oid[OID_SIZE];
2864 struct oident * new_oident=NULL;
2866 if (sscanf (args, "%100[^ ] %100[^ ] %100s",
2867 oname_str,oclass_str, oid_str) < 1) {
2868 printf("Error in regristrate command \n");
2872 for (i = 0; oid_classes[i].className; i++) {
2873 if (!strcmp(oid_classes[i].className, oclass_str))
2875 oidclass=oid_classes[i].oclass;
2880 if(!(oid_classes[i].className)) {
2881 printf("Unknonwn oid class %s\n",oclass_str);
2889 while (isdigit (*name))
2891 val = val*10 + (*name - '0');
2904 new_oident=oid_addent (oid,PROTO_GENERAL,oidclass,oname_str,VAL_DYNAMIC);
2905 if(strcmp(new_oident->desc,oname_str)) {
2906 fprintf(stderr,"oid is already named as %s, regristration faild\n",
2912 int cmd_push_command(const char* arg)
2914 #if HAVE_READLINE_HISTORY_H
2918 fprintf(stderr,"Not compiled with the readline/history module\n");
2923 void source_rcfile()
2925 /* Look for a $HOME/.yazclientrc and source it if it exists */
2926 struct stat statbuf;
2928 char* homedir=getenv("HOME");
2930 if(!homedir) return;
2932 sprintf(buffer,"%s/.yazclientrc",homedir);
2934 if(stat(buffer,&statbuf)==0) {
2938 if(stat(".yazclientrc",&statbuf)==0) {
2939 cmd_source(".yazclientrc");
2944 static void initialize(void)
2949 if (!(out = odr_createmem(ODR_ENCODE)) ||
2950 !(in = odr_createmem(ODR_DECODE)) ||
2951 !(print = odr_createmem(ODR_PRINT)))
2953 fprintf(stderr, "failed to allocate ODR streams\n");
2958 setvbuf(stdout, 0, _IONBF, 0);
2960 odr_setprint(print, apdu_file);
2962 bibset = ccl_qual_mk ();
2963 inf = fopen (ccl_fields, "r");
2966 ccl_qual_file (bibset, inf);
2970 cqltrans = cql_transform_open_fname(cql_fields);
2971 /* If this fails, no problem: we detect cqltrans == 0 later */
2973 #if HAVE_READLINE_READLINE_H
2974 rl_attempted_completion_function = (CPPFunction*)readline_completer;
2978 for(i=0; i<maxOtherInfosSupported; ++i) {
2979 extraOtherInfos[i].oidval = -1;
2986 #if HAVE_GETTIMEOFDAY
2987 struct timeval tv_start, tv_end;
2991 static void handle_srw_response(Z_SRW_searchRetrieveResponse *res)
2995 printf ("Received SRW SearchRetrieve Response\n");
2997 for (i = 0; i<res->num_diagnostics; i++)
2999 printf ("SRW diagnostic %d %s\n",
3000 *res->diagnostics[i].code,
3001 yaz_diag_srw_str(*res->diagnostics[i].code));
3003 if (res->diagnostics[i].details)
3004 printf ("Details: %s\n", res->diagnostics[i].details);
3006 if (res->numberOfRecords)
3007 printf ("Number of hits: %d\n", *res->numberOfRecords);
3008 for (i = 0; i<res->num_records; i++)
3010 Z_SRW_record *rec = res->records + i;
3012 if (rec->recordPosition)
3014 printf ("pos=%d", *rec->recordPosition);
3015 setno = *rec->recordPosition + 1;
3017 if (rec->recordSchema)
3018 printf (" schema=%s", rec->recordSchema);
3020 if (rec->recordData_buf && rec->recordData_len)
3022 fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout);
3028 static void http_response(Z_HTTP_Response *hres)
3031 const char *content_type = z_HTTP_header_lookup(hres->headers,
3033 const char *connection_head = z_HTTP_header_lookup(hres->headers,
3035 if (content_type && !yaz_strcmp_del("text/xml", content_type, "; "))
3037 Z_SOAP *soap_package = 0;
3038 ODR o = odr_createmem(ODR_DECODE);
3039 Z_SOAP_Handler soap_handlers[2] = {
3040 {"http://www.loc.gov/zing/srw/v1.0/", 0,
3041 (Z_SOAP_fun) yaz_srw_codec},
3044 ret = z_soap_codec(o, &soap_package,
3045 &hres->content_buf, &hres->content_len,
3047 if (!ret && soap_package->which == Z_SOAP_generic &&
3048 soap_package->u.generic->no == 0)
3050 Z_SRW_PDU *sr = soap_package->u.generic->p;
3051 if (sr->which == Z_SRW_searchRetrieve_response)
3052 handle_srw_response(sr->u.response);
3056 else if (!ret && (soap_package->which == Z_SOAP_fault
3057 || soap_package->which == Z_SOAP_error))
3059 printf ("HTTP Error Status=%d\n", hres->code);
3060 printf ("SOAP Fault code %s\n",
3061 soap_package->u.fault->fault_code);
3062 printf ("SOAP Fault string %s\n",
3063 soap_package->u.fault->fault_string);
3071 if (hres->code != 200)
3073 printf ("HTTP Error Status=%d\n", hres->code);
3077 printf ("Decoding of SRW package failed\n");
3081 if (!strcmp(hres->version, "1.0"))
3083 /* HTTP 1.0: only if Keep-Alive we stay alive.. */
3084 if (!connection_head || strcmp(connection_head, "Keep-Alive"))
3089 /* HTTP 1.1: only if no close we stay alive .. */
3090 if (connection_head && !strcmp(connection_head, "close"))
3096 void wait_and_handle_response()
3098 int reconnect_ok = 1;
3101 int netbufferlen = 0;
3106 res = cs_get(conn, &netbuffer, &netbufferlen);
3107 if (reconnect_ok && res <= 0 && protocol == PROTO_HTTP)
3118 buf_out = odr_getbuf(out, &len_out, 0);
3120 cs_put(conn, buf_out, len_out);
3128 printf("Target closed connection\n");
3133 odr_reset(in); /* release APDU from last round */
3135 do_hex_dump(netbuffer, res);
3136 odr_setbuf(in, netbuffer, res, 0);
3138 if (!z_GDU(in, &gdu, 0, 0))
3140 FILE *f = ber_file ? ber_file : stdout;
3141 odr_perror(in, "Decoding incoming APDU");
3142 fprintf(f, "[Near %d]\n", odr_offset(in));
3143 fprintf(f, "Packet dump:\n---------\n");
3144 odr_dumpBER(f, netbuffer, res);
3145 fprintf(f, "---------\n");
3147 z_GDU(print, &gdu, 0, 0);
3148 if (conn && cs_more(conn))
3153 odr_dumpBER(ber_file, netbuffer, res);
3154 if (apdu_file && !z_GDU(print, &gdu, 0, 0))
3156 odr_perror(print, "Failed to print incoming APDU");
3160 if (gdu->which == Z_GDU_Z3950)
3162 Z_APDU *apdu = gdu->u.z3950;
3165 case Z_APDU_initResponse:
3166 process_initResponse(apdu->u.initResponse);
3168 case Z_APDU_searchResponse:
3169 process_searchResponse(apdu->u.searchResponse);
3171 case Z_APDU_scanResponse:
3172 process_scanResponse(apdu->u.scanResponse);
3174 case Z_APDU_presentResponse:
3175 print_refid (apdu->u.presentResponse->referenceId);
3177 *apdu->u.presentResponse->numberOfRecordsReturned;
3178 if (apdu->u.presentResponse->records)
3179 display_records(apdu->u.presentResponse->records);
3181 printf("No records.\n");
3182 printf ("nextResultSetPosition = %d\n",
3183 *apdu->u.presentResponse->nextResultSetPosition);
3185 case Z_APDU_sortResponse:
3186 process_sortResponse(apdu->u.sortResponse);
3188 case Z_APDU_extendedServicesResponse:
3189 printf("Got extended services response\n");
3190 process_ESResponse(apdu->u.extendedServicesResponse);
3193 printf("Target has closed the association.\n");
3194 process_close(apdu->u.close);
3196 case Z_APDU_resourceControlRequest:
3197 process_resourceControlRequest
3198 (apdu->u.resourceControlRequest);
3200 case Z_APDU_deleteResultSetResponse:
3201 process_deleteResultSetResponse(apdu->u.
3202 deleteResultSetResponse);
3205 printf("Received unknown APDU type (%d).\n",
3211 else if (gdu->which == Z_GDU_HTTP_Response)
3213 http_response(gdu->u.HTTP_Response);
3216 if (conn && !cs_more(conn))
3221 #if HAVE_GETTIMEOFDAY
3222 gettimeofday (&tv_end, 0);
3224 printf ("S/U S/U=%ld/%ld %ld/%ld",
3225 (long) tv_start.tv_sec,
3226 (long) tv_start.tv_usec,
3227 (long) tv_end.tv_sec,
3228 (long) tv_end.tv_usec);
3230 printf ("Elapsed: %.6f\n",
3231 (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
3232 ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
3239 int cmd_cclparse(const char* arg)
3242 struct ccl_rpn_node *rpn=NULL;
3245 rpn = ccl_find_str (bibset, arg, &error, &pos);
3248 printf ("%*s^ - ", 3+strlen(last_cmd)+1+pos, " ");
3249 printf ("%s\n", ccl_err_msg (error));
3255 ccl_pr_tree(rpn, stdout);
3259 ccl_rpn_delete(rpn);
3267 int cmd_set_otherinfo(const char* args)
3269 char oid[101], otherinfoString[101];
3274 sscan_res = sscanf (args, "%d %100[^ ] %100s", &otherinfoNo, oid, otherinfoString);
3276 /* reset this otherinfo */
3277 if(otherinfoNo>=maxOtherInfosSupported) {
3278 printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
3280 extraOtherInfos[otherinfoNo].oidval = -1;
3281 if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
3285 printf("Error in set_otherinfo command \n");
3289 if(otherinfoNo>=maxOtherInfosSupported) {
3290 printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
3294 oidval = oid_getvalbyname (oid);
3296 printf("Error in set_otherinfo command unknown oid %s \n",oid);
3299 extraOtherInfos[otherinfoNo].oidval = oidval;
3300 if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
3301 extraOtherInfos[otherinfoNo].value = strdup(otherinfoString);
3306 int cmd_list_otherinfo(const char* args)
3310 if(strlen(args)>0) {
3312 if( i >= maxOtherInfosSupported ) {
3313 printf("Error otherinfo index to large (%d>%d)\n",i,maxOtherInfosSupported);
3317 if(extraOtherInfos[i].oidval != -1)
3318 printf(" otherinfo %d %s %s\n",
3320 yaz_z3950_oid_value_to_str(
3321 (enum oid_value) extraOtherInfos[i].oidval,
3323 extraOtherInfos[i].value);
3326 for(i=0; i<maxOtherInfosSupported; ++i) {
3327 if(extraOtherInfos[i].oidval != -1)
3328 printf(" otherinfo %d %s %s\n",
3330 yaz_z3950_oid_value_to_str(
3331 (enum oid_value) extraOtherInfos[i].oidval,
3333 extraOtherInfos[i].value);
3341 int cmd_list_all(const char* args) {
3344 /* connection options */
3346 printf("Connected to : %s\n",last_open_command);
3348 if(last_open_command)
3349 printf("Not connected to : %s\n",last_open_command);
3351 printf("Not connected : \n");
3354 if(yazProxy) printf("using proxy : %s\n",yazProxy);
3356 printf("auto_reconnect : %s\n",auto_reconnect?"on":"off");
3359 printf("Authentication : none\n");
3361 switch(auth->which) {
3362 case Z_IdAuthentication_idPass:
3363 printf("Authentication : IdPass\n");
3364 printf(" Login User : %s\n",auth->u.idPass->userId?auth->u.idPass->userId:"");
3365 printf(" Login Group : %s\n",auth->u.idPass->groupId?auth->u.idPass->groupId:"");
3366 printf(" Password : %s\n",auth->u.idPass->password?auth->u.idPass->password:"");
3368 case Z_IdAuthentication_open:
3369 printf("Authentication : psOpen\n");
3370 printf(" Open string : %s\n",auth->u.open);
3373 printf("Authentication : Unknown\n");
3376 if (negotiationCharset)
3377 printf("Neg. Character set : `%s'\n", negotiationCharset);
3381 for (i = 0; i<num_databaseNames; i++) printf("%s ",databaseNames[i]);
3385 printf("CCL file : %s\n",ccl_fields);
3386 printf("CQL file : %s\n",cql_fields);
3387 printf("Query type : %s\n",query_type_as_string(queryType));
3389 printf("Named Result Sets : %s\n",setnumber==-1?"off":"on");
3391 /* piggy back options */
3392 printf("ssub/lslb/mspn : %d/%d/%d\n",smallSetUpperBound,largeSetLowerBound,mediumSetPresentNumber);
3394 /* print present related options */
3395 printf("Format : %s\n",yaz_z3950_oid_value_to_str(recordsyntax,CLASS_RECSYN));
3396 printf("Schema : %s\n",schema);
3397 printf("Elements : %s\n",elementSetNames?elementSetNames->u.generic:"");
3399 /* loging options */
3400 printf("APDU log : %s\n",apdu_file?"on":"off");
3401 printf("Record log : %s\n",marc_file?"on":"off");
3404 printf("Other Info: \n");
3405 cmd_list_otherinfo("");
3410 int cmd_clear_otherinfo(const char* args)
3412 if(strlen(args)>0) {
3414 otherinfoNo = atoi(args);
3415 if( otherinfoNo >= maxOtherInfosSupported ) {
3416 printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
3420 if(extraOtherInfos[otherinfoNo].oidval != -1) {
3421 /* only clear if set. */
3422 extraOtherInfos[otherinfoNo].oidval=-1;
3423 free(extraOtherInfos[otherinfoNo].value);
3428 for(i=0; i<maxOtherInfosSupported; ++i) {
3429 if (extraOtherInfos[i].oidval!=-1 ) {
3430 extraOtherInfos[i].oidval=-1;
3431 free(extraOtherInfos[i].value);
3438 static int cmd_help (const char *line);
3440 typedef char *(*completerFunctionType)(const char *text, int state);
3444 int (*fun)(const char *arg);
3446 completerFunctionType rl_completerfunction;
3447 int complete_filenames;
3448 char **local_tabcompletes;
3450 {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0,NULL},
3451 {"quit", cmd_quit, "",NULL,0,NULL},
3452 {"find", cmd_find, "<query>",NULL,0,NULL},
3453 {"delete", cmd_delete, "<setname>",NULL,0,NULL},
3454 {"base", cmd_base, "<base-name>",NULL,0,NULL},
3455 {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0,NULL},
3456 {"scan", cmd_scan, "<term>",NULL,0,NULL},
3457 {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
3458 {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
3459 {"authentication", cmd_authentication, "<acctstring>",NULL,0,NULL},
3460 {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0,NULL},
3461 {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0,NULL},
3462 {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0,NULL},
3463 {"status", cmd_status, "",NULL,0,NULL},
3464 {"setnames", cmd_setnames, "",NULL,0,NULL},
3465 {"cancel", cmd_cancel, "",NULL,0,NULL},
3466 {"format", cmd_format, "<recordsyntax>",complete_format,0,NULL},
3467 {"schema", cmd_schema, "<schema>",complete_schema,0,NULL},
3468 {"elements", cmd_elements, "<elementSetName>",NULL,0,NULL},
3469 {"close", cmd_close, "",NULL,0,NULL},
3470 {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0,NULL},
3471 {"querytype", cmd_querytype, "<type>",complete_querytype,0,NULL},
3472 {"refid", cmd_refid, "<id>",NULL,0,NULL},
3473 {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0,NULL},
3474 {"update", cmd_update, "<action> <recid> [<file>]",NULL,0,NULL},
3475 {"packagename", cmd_packagename, "<packagename>",NULL,0,NULL},
3476 {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0,NULL},
3477 {"charset", cmd_charset, "<nego_charset> <output_charset>",NULL,0,NULL},
3478 {"marccharset", cmd_marccharset, "<charset_name>",NULL,0,NULL},
3479 {"lang", cmd_lang, "<language_code>",NULL,0,NULL},
3480 {".", cmd_source, "<filename>",NULL,1,NULL},
3481 {"!", cmd_subshell, "Subshell command",NULL,1,NULL},
3482 {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,1,NULL},
3483 {"set_berfile", cmd_set_berfile, "<filename>",NULL,1,NULL},
3484 {"set_marcdump", cmd_set_marcdump," <filename>",NULL,1,NULL},
3485 {"set_cclfile", cmd_set_cclfile," <filename>",NULL,1,NULL},
3486 {"set_cqlfile", cmd_set_cqlfile," <filename>",NULL,1,NULL},
3487 {"set_auto_reconnect", cmd_set_auto_reconnect," on|off",complete_auto_reconnect,1,NULL},
3488 {"set_otherinfo", cmd_set_otherinfo,"<otherinfoinddex> <oid> <string>",NULL,0,NULL},
3489 {"register_oid", cmd_register_oid,"<name> <class> <oid>",NULL,0,NULL},
3490 {"push_command", cmd_push_command,"<command>",command_generator,0,NULL},
3491 {"register_tab", cmd_register_tab,"<commandname> <tab>",command_generator,0,NULL},
3492 {"cclparse", cmd_cclparse,"<ccl find command>",NULL,0,NULL},
3493 {"list_otherinfo",cmd_list_otherinfo,"[otherinfoinddex]",NULL,0,NULL},
3494 {"list_all",cmd_list_all,"",NULL,0,NULL},
3495 {"clear_otherinfo",cmd_clear_otherinfo,"",NULL,0,NULL},
3496 /* Server Admin Functions */
3497 {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0,NULL},
3498 {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0,NULL},
3499 {"adm-create", cmd_adm_create, "",NULL,0,NULL},
3500 {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0,NULL},
3501 {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0,NULL},
3502 {"adm-refresh", cmd_adm_refresh, "",NULL,0,NULL},
3503 {"adm-commit", cmd_adm_commit, "",NULL,0,NULL},
3504 {"adm-shutdown", cmd_adm_shutdown, "",NULL,0,NULL},
3505 {"adm-startup", cmd_adm_startup, "",NULL,0,NULL},
3506 {"help", cmd_help, "", NULL,0,NULL},
3510 static int cmd_help (const char *line)
3516 sscanf (line, "%20s", topic);
3519 printf("Commands:\n");
3520 for (i = 0; cmd_array[i].cmd; i++)
3521 if (*topic == 0 || strcmp (topic, cmd_array[i].cmd) == 0)
3522 printf(" %s %s\n", cmd_array[i].cmd, cmd_array[i].ad);
3523 if (strcmp (topic, "find") == 0)
3526 printf (" \"term\" Simple Term\n");
3527 printf (" @attr [attset] type=value op Attribute\n");
3528 printf (" @and opl opr And\n");
3529 printf (" @or opl opr Or\n");
3530 printf (" @not opl opr And-Not\n");
3531 printf (" @set set Result set\n");
3533 printf ("Bib-1 attribute types\n");
3535 printf ("4=Title 7=ISBN 8=ISSN 30=Date 62=Abstract 1003=Author 1016=Any\n");
3536 printf ("2=Relation: ");
3537 printf ("1< 2<= 3= 4>= 5> 6!= 102=Relevance\n");
3538 printf ("3=Position: ");
3539 printf ("1=First in Field 2=First in subfield 3=Any position\n");
3540 printf ("4=Structure: ");
3541 printf ("1=Phrase 2=Word 3=Key 4=Year 5=Date 6=WordList\n");
3542 printf ("5=Truncation: ");
3543 printf ("1=Right 2=Left 3=L&R 100=No 101=# 102=Re-1 103=Re-2\n");
3544 printf ("6=Completeness:");
3545 printf ("1=Incomplete subfield 2=Complete subfield 3=Complete field\n");
3550 int cmd_register_tab(const char* arg) {
3552 char command[101], tabargument[101];
3557 if (sscanf (arg, "%100s %100s", command, tabargument) < 1) {
3561 /* locate the amdn in the list */
3562 for (i = 0; cmd_array[i].cmd; i++) {
3563 if (!strncmp(cmd_array[i].cmd, command, strlen(command))) {
3568 if(!cmd_array[i].cmd) {
3569 fprintf(stderr,"Unknown command %s\n",command);
3574 if(!cmd_array[i].local_tabcompletes)
3575 cmd_array[i].local_tabcompletes = (char **) calloc(1,sizeof(char**));
3579 tabslist = cmd_array[i].local_tabcompletes;
3580 for(;tabslist && *tabslist;tabslist++) {
3584 cmd_array[i].local_tabcompletes = (char **)
3585 realloc(cmd_array[i].local_tabcompletes,(num_of_tabs+2)*sizeof(char**));
3586 tabslist=cmd_array[i].local_tabcompletes;
3587 tabslist[num_of_tabs]=strdup(tabargument);
3588 tabslist[num_of_tabs+1]=NULL;
3593 void process_cmd_line(char* line)
3596 char word[32], arg[1024];
3598 #if HAVE_GETTIMEOFDAY
3599 gettimeofday (&tv_start, 0);
3602 if ((res = sscanf(line, "%31s %1023[^;]", word, arg)) <= 0)
3604 strcpy(word, last_cmd);
3609 strcpy(last_cmd, word);
3611 /* removed tailing spaces from the arg command */
3614 char* lastnonspace=NULL;
3622 *(++lastnonspace) = 0;
3625 for (i = 0; cmd_array[i].cmd; i++)
3626 if (!strncmp(cmd_array[i].cmd, word, strlen(word)))
3628 res = (*cmd_array[i].fun)(arg);
3632 if (!cmd_array[i].cmd) /* dump our help-screen */
3634 printf("Unknown command: %s.\n", word);
3635 printf("use help for list of commands\n");
3636 /* cmd_help (""); */
3640 if(apdu_file) fflush(apdu_file);
3643 wait_and_handle_response();
3652 char *command_generator(const char *text, int state)
3658 for( ; cmd_array[idx].cmd; ++idx) {
3659 if (!strncmp(cmd_array[idx].cmd,text,strlen(text))) {
3660 ++idx; /* skip this entry on the next run */
3661 return strdup(cmd_array[idx-1].cmd);
3669 This function only known how to complete on the first word
3671 char ** readline_completer(char *text, int start, int end) {
3672 #if HAVE_READLINE_READLINE_H
3674 completerFunctionType completerToUse;
3677 #if HAVE_READLINE_RL_COMPLETION_MATCHES
3678 char** res=rl_completion_matches(text,
3681 char** res=completion_matches(text,
3682 (CPFunction*)command_generator);
3684 rl_attempted_completion_over = 1;
3687 char arg[1024],word[32];
3689 if ((res = sscanf(rl_line_buffer, "%31s %1023[^;]", word, arg)) <= 0) {
3690 rl_attempted_completion_over = 1;
3694 for (i = 0; cmd_array[i].cmd; i++) {
3695 if (!strncmp(cmd_array[i].cmd, word, strlen(word))) {
3700 if(!cmd_array[i].cmd) return NULL;
3702 curret_global_list = cmd_array[i].local_tabcompletes;
3704 completerToUse = cmd_array[i].rl_completerfunction;
3705 if(completerToUse==NULL) /* if no pr. command completer is defined use the default completer */
3706 completerToUse = default_completer;
3708 if(completerToUse) {
3709 #ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
3711 rl_completion_matches(text,
3715 completion_matches(text,
3716 (CPFunction*)completerToUse);
3718 if(!cmd_array[i].complete_filenames)
3719 rl_attempted_completion_over = 1;
3722 if(!cmd_array[i].complete_filenames)
3723 rl_attempted_completion_over = 1;
3733 static void client(void)
3739 #if HAVE_GETTIMEOFDAY
3740 gettimeofday (&tv_start, 0);
3745 char *line_in = NULL;
3746 #if HAVE_READLINE_READLINE_H
3749 line_in=readline(C_PROMPT);
3752 #if HAVE_READLINE_HISTORY_H
3754 add_history(line_in);
3756 strncpy(line, line_in, 1023);
3765 if (!fgets(line, 1023, stdin))
3767 if ((end_p = strchr (line, '\n')))
3770 process_cmd_line(line);
3774 static void show_version(void)
3778 yaz_version(vstr, 0);
3779 printf ("YAZ version: %s\n", YAZ_VERSION);
3780 if (strcmp(vstr, YAZ_VERSION))
3781 printf ("YAZ DLL/SO: %s\n", vstr);
3785 int main(int argc, char **argv)
3788 char *open_command = 0;
3789 char *auth_command = 0;
3794 if (!setlocale(LC_CTYPE, ""))
3795 fprintf (stderr, "setlocale failed\n");
3799 codeset = nl_langinfo(CODESET);
3803 outputCharset = xstrdup(codeset);
3805 while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vx", argv, argc, &arg)) != -2)
3812 open_command = (char *) xmalloc (strlen(arg)+6);
3813 strcpy (open_command, "open ");
3814 strcat (open_command, arg);
3818 kilobytes = atoi(arg);
3821 if (!(marc_file = fopen (arg, "a")))
3828 outputCharset = xstrdup(arg);
3831 strncpy (ccl_fields, arg, sizeof(ccl_fields)-1);
3832 ccl_fields[sizeof(ccl_fields)-1] = '\0';
3835 strncpy (cql_fields, arg, sizeof(cql_fields)-1);
3836 cql_fields[sizeof(cql_fields)-1] = '\0';
3839 if (!strcmp(arg, "-"))
3842 ber_file=fopen(arg, "a");
3845 if (!strcmp(arg, "-"))
3848 apdu_file=fopen(arg, "a");
3854 yazProxy=strdup(arg);
3859 auth_command = (char *) xmalloc (strlen(arg)+6);
3860 strcpy (auth_command, "auth ");
3861 strcat (auth_command, arg);
3865 yaz_log_init(yaz_log_mask_str(arg), "", 0);
3871 fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
3872 "[-b berdump] [-c cclfields] \n"
3873 "[-q cqlfields] [-p <proxy-addr>] [-u <auth>] "
3874 "[-k size] [-V] [<server-addr>]\n",
3882 #ifdef HAVE_GETTIMEOFDAY
3883 gettimeofday (&tv_start, 0);
3885 process_cmd_line (auth_command);
3886 #if HAVE_READLINE_HISTORY_H
3887 add_history(auth_command);
3889 xfree(auth_command);
3893 #ifdef HAVE_GETTIMEOFDAY
3894 gettimeofday (&tv_start, 0);
3896 process_cmd_line (open_command);
3897 #if HAVE_READLINE_HISTORY_H
3898 add_history(open_command);
3900 xfree(open_command);
3911 * vim600: sw=4 ts=8 fdm=marker
3912 * vim<600: sw=4 ts=8