2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: client.c,v 1.154 2002-05-20 09:13:39 oleg Exp $
12 #include <yaz/yaz-util.h>
14 #include <yaz/tcpip.h>
16 #include <yaz/xmosi.h>
19 #include <yaz/proto.h>
20 #include <yaz/marcdisp.h>
21 #include <yaz/diagbib1.h>
22 #include <yaz/otherinfo.h>
23 #include <yaz/charneg.h>
25 #include <yaz/pquery.h>
26 #include <yaz/sortspec.h>
33 #include <yaz/yaz-ccl.h>
36 #if HAVE_READLINE_READLINE_H
37 #include <readline/readline.h>
39 #if HAVE_READLINE_HISTORY_H
40 #include <readline/history.h>
47 #include "tabcomplete.h"
49 #define C_PROMPT "Z> "
51 static ODR out, in, print; /* encoding and decoding streams */
52 static FILE *apdu_file = 0;
53 static COMSTACK conn = 0; /* our z-association */
54 static Z_IdAuthentication *auth = 0; /* our current auth definition */
55 char *databaseNames[128];
56 int num_databaseNames = 0;
57 static Z_External *record_last = 0;
58 static int setnumber = -1; /* current result set number */
59 static int smallSetUpperBound = 0;
60 static int largeSetLowerBound = 1;
61 static int mediumSetPresentNumber = 0;
62 static Z_ElementSetNames *elementSetNames = 0;
63 static int setno = 1; /* current set offset */
64 static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */
65 static enum oid_value recordsyntax = VAL_USMARC;
66 static enum oid_value schema = VAL_NONE;
67 static int sent_close = 0;
68 static NMEM session_mem = NULL; /* memory handle for init-response */
69 static Z_InitResponse *session = 0; /* session parameters */
70 static char last_scan_line[512] = "0";
71 static char last_scan_query[512] = "0";
72 static char ccl_fields[512] = "default.bib";
73 static char* esPackageName = 0;
74 static char* yazProxy = 0;
75 static int kilobytes = 1024;
76 static char* yazCharset = 0;
77 static char* yazLang = 0;
79 static char last_cmd[32] = "?";
80 static FILE *marcdump = 0;
81 static char *refid = NULL;
89 static QueryType queryType = QueryType_Prefix;
92 static CCL_bibset bibset; /* CCL bibset handle */
95 #if HAVE_READLINE_COMPLETION_OVER
98 /* readline doesn't have this var. Define it ourselves. */
99 int rl_attempted_completion_over = 0;
102 /* set this one to 1, to avoid decode of unknown MARCs */
103 #define AVOID_MARC_DECODE 1
105 /* nice helper macro as extensive tabbing gives spaces at the en of the args lines */
106 #define REMOVE_TAILING_BLANKS(a) {\
107 char* args_end=(a)+strlen(a)-1; \
108 while(isspace(*args_end)) {*args_end=0;--args_end;}; \
112 void process_cmd_line(char* line);
113 char ** readline_completer(char *text, int start, int end);
114 char *command_generator(const char *text, int state);
117 ODR getODROutputStream()
122 void send_apdu(Z_APDU *a)
129 z_APDU(print, &a, 0, 0);
132 if (!z_APDU(out, &a, 0, 0))
134 odr_perror(out, "Encoding APDU");
137 buf = odr_getbuf(out, &len, 0);
138 /* printf ("sending APDU of size %d\n", len); */
139 if (cs_put(conn, buf, len) < 0)
141 fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn)));
144 odr_reset(out); /* release the APDU structure */
147 static void print_stringn(const unsigned char *buf, size_t len)
150 for (i = 0; i<len; i++)
151 if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
152 printf ("%c", buf[i]);
154 printf ("\\X%02X", buf[i]);
157 static void print_refid (Z_ReferenceId *id)
161 printf ("Reference Id: ");
162 print_stringn (id->buf, id->len);
167 static Z_ReferenceId *set_refid (ODR out)
172 id = (Z_ReferenceId *) odr_malloc (out, sizeof(*id));
173 id->size = id->len = strlen(refid);
174 id->buf = (unsigned char *) odr_malloc (out, id->len);
175 memcpy (id->buf, refid, id->len);
179 /* INIT SERVICE ------------------------------- */
181 static void send_initRequest(const char* type_and_host)
183 Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest);
184 Z_InitRequest *req = apdu->u.initRequest;
186 ODR_MASK_SET(req->options, Z_Options_search);
187 ODR_MASK_SET(req->options, Z_Options_present);
188 ODR_MASK_SET(req->options, Z_Options_namedResultSets);
189 ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl);
190 ODR_MASK_SET(req->options, Z_Options_scan);
191 ODR_MASK_SET(req->options, Z_Options_sort);
192 ODR_MASK_SET(req->options, Z_Options_extendedServices);
193 ODR_MASK_SET(req->options, Z_Options_delSet);
195 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
196 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
197 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
199 *req->maximumRecordSize = 1024*kilobytes;
200 *req->preferredMessageSize = 1024*kilobytes;
202 req->idAuthentication = auth;
204 req->referenceId = set_refid (out);
207 yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
210 if (yazCharset || yazLang) {
211 Z_OtherInformation **p;
212 Z_OtherInformationUnit *p0;
214 yaz_oi_APDU(apdu, &p);
216 if (p0=yaz_oi_update(p, out, NULL, 0, 0)) {
217 ODR_MASK_SET(req->options, Z_Options_negotiationModel);
219 p0->which = Z_OtherInfo_externallyDefinedInfo;
220 p0->information.externallyDefinedInfo =
221 yaz_set_proposal_charneg(out,
222 (const char**)&yazCharset, (yazCharset)?1:0,
223 (const char**)&yazLang, (yazLang)?1:0, 1);
228 printf("Sent initrequest.\n");
231 static int process_initResponse(Z_InitResponse *res)
233 /* save session parameters for later use */
234 session_mem = odr_extract_mem(in);
238 printf("Connection rejected by target.\n");
240 printf("Connection accepted by target.\n");
241 if (res->implementationId)
242 printf("ID : %s\n", res->implementationId);
243 if (res->implementationName)
244 printf("Name : %s\n", res->implementationName);
245 if (res->implementationVersion)
246 printf("Version: %s\n", res->implementationVersion);
247 if (res->userInformationField)
249 printf("UserInformationfield:\n");
250 if (!z_External(print, (Z_External**)&res-> userInformationField,
253 odr_perror(print, "Printing userinfo\n");
256 if (res->userInformationField->which == Z_External_octet)
258 printf("Guessing visiblestring:\n");
259 printf("'%s'\n", res->userInformationField->u. octet_aligned->buf);
264 if (ODR_MASK_GET(res->options, Z_Options_search))
266 if (ODR_MASK_GET(res->options, Z_Options_present))
268 if (ODR_MASK_GET(res->options, Z_Options_delSet))
270 if (ODR_MASK_GET(res->options, Z_Options_resourceReport))
271 printf (" resourceReport");
272 if (ODR_MASK_GET(res->options, Z_Options_resourceCtrl))
273 printf (" resourceCtrl");
274 if (ODR_MASK_GET(res->options, Z_Options_accessCtrl))
275 printf (" accessCtrl");
276 if (ODR_MASK_GET(res->options, Z_Options_scan))
278 if (ODR_MASK_GET(res->options, Z_Options_sort))
280 if (ODR_MASK_GET(res->options, Z_Options_extendedServices))
281 printf (" extendedServices");
282 if (ODR_MASK_GET(res->options, Z_Options_level_1Segmentation))
283 printf (" level1Segmentation");
284 if (ODR_MASK_GET(res->options, Z_Options_level_2Segmentation))
285 printf (" level2Segmentation");
286 if (ODR_MASK_GET(res->options, Z_Options_concurrentOperations))
287 printf (" concurrentOperations");
288 if (ODR_MASK_GET(res->options, Z_Options_namedResultSets))
290 printf (" namedResultSets");
293 if (ODR_MASK_GET(res->options, Z_Options_encapsulation))
294 printf (" encapsulation");
295 if (ODR_MASK_GET(res->options, Z_Options_resultCount))
296 printf (" resultCount");
297 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel))
298 printf (" negotiationModel");
299 if (ODR_MASK_GET(res->options, Z_Options_duplicateDetection))
300 printf (" duplicateDetection");
301 if (ODR_MASK_GET(res->options, Z_Options_queryType104))
302 printf (" queryType104");
305 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) {
307 Z_CharSetandLanguageNegotiation *p =
308 yaz_get_charneg_record(res->otherInfo);
312 char *charset=NULL, *lang=NULL;
315 yaz_get_response_charneg(session_mem, p, &charset, &lang, &selected);
317 printf("Accepted character set : `%s'\n", charset);
318 printf("Accepted code language : `%s'\n", lang);
319 printf("Accepted records in ...: %d\n", selected );
326 static int cmd_base(char *arg)
333 printf("Usage: base <database> <database> ...\n");
336 for (i = 0; i<num_databaseNames; i++)
337 xfree (databaseNames[i]);
338 num_databaseNames = 0;
341 if (!(cp = strchr(arg, ' ')))
342 cp = arg + strlen(arg);
345 databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
346 memcpy (databaseNames[num_databaseNames], arg, cp - arg);
347 databaseNames[num_databaseNames++][cp - arg] = '\0';
355 int cmd_open(char *arg)
358 char type_and_host[101], base[101];
363 printf("Already connected.\n");
369 nmem_destroy (session_mem);
375 if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1)
379 conn = cs_create_host(yazProxy, 1, &add);
381 conn = cs_create_host(type_and_host, 1, &add);
385 printf ("Couldn't create comstack\n");
388 printf("Connecting...");
390 if (cs_connect(conn, add) < 0)
392 printf ("error = %s\n", cs_strerror(conn));
393 if (conn->cerrno == CSYSERR)
401 send_initRequest(type_and_host);
407 int cmd_authentication(char *arg)
409 static Z_IdAuthentication au;
410 static char user[40], group[40], pass[40];
411 static Z_IdPass idPass;
416 printf("Auth field set to null\n");
420 r = sscanf (arg, "%39s %39s %39s", user, group, pass);
423 printf("Auth field set to null\n");
429 au.which = Z_IdAuthentication_open;
435 au.which = Z_IdAuthentication_idPass;
436 au.u.idPass = &idPass;
437 idPass.groupId = group;
438 idPass.userId = user;
439 idPass.password = pass;
444 /* SEARCH SERVICE ------------------------------ */
446 static void display_variant(Z_Variant *v, int level)
450 for (i = 0; i < v->num_triples; i++)
452 printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
453 *v->triples[i]->type);
454 if (v->triples[i]->which == Z_Triple_internationalString)
455 printf(",value=%s\n", v->triples[i]->value.internationalString);
461 static void display_grs1(Z_GenericRecord *r, int level)
467 for (i = 0; i < r->num_elements; i++)
471 printf("%*s", level * 4, "");
475 printf("%d,", *t->tagType);
478 if (t->tagValue->which == Z_StringOrNumeric_numeric)
479 printf("%d) ", *t->tagValue->u.numeric);
481 printf("%s) ", t->tagValue->u.string);
482 if (t->content->which == Z_ElementData_subtree)
485 display_grs1(t->content->u.subtree, level+1);
487 else if (t->content->which == Z_ElementData_string)
488 printf("%s\n", t->content->u.string);
489 else if (t->content->which == Z_ElementData_numeric)
490 printf("%d\n", *t->content->u.numeric);
491 else if (t->content->which == Z_ElementData_oid)
493 int *ip = t->content->u.oid;
496 if ((oent = oid_getentbyoid(t->content->u.oid)))
497 printf("OID: %s\n", oent->desc);
501 while (ip && *ip >= 0)
502 printf(" %d", *(ip++));
506 else if (t->content->which == Z_ElementData_noDataRequested)
507 printf("[No data requested]\n");
508 else if (t->content->which == Z_ElementData_elementEmpty)
509 printf("[Element empty]\n");
510 else if (t->content->which == Z_ElementData_elementNotThere)
511 printf("[Element not there]\n");
514 if (t->appliedVariant)
515 display_variant(t->appliedVariant, level+1);
516 if (t->metaData && t->metaData->supportedVariants)
520 printf("%*s---- variant list\n", (level+1)*4, "");
521 for (c = 0; c < t->metaData->num_supportedVariants; c++)
523 printf("%*svariant #%d\n", (level+1)*4, "", c);
524 display_variant(t->metaData->supportedVariants[c], level + 2);
531 static void print_record(const unsigned char *buf, size_t len)
534 print_stringn (buf, len);
535 /* add newline if not already added ... */
536 if (i <= 0 || buf[i-1] != '\n')
540 static void display_record(Z_External *r)
542 oident *ent = oid_getentbyoid(r->direct_reference);
546 * Tell the user what we got.
548 if (r->direct_reference)
550 printf("Record type: ");
552 printf("%s\n", ent->desc);
553 else if (!odr_oid(print, &r->direct_reference, 0, 0))
555 odr_perror(print, "print oid");
559 /* Check if this is a known, ASN.1 type tucked away in an octet string */
560 if (ent && r->which == Z_External_octet)
562 Z_ext_typeent *type = z_ext_getentbyref(ent->value);
568 * Call the given decoder to process the record.
570 odr_setbuf(in, (char*)r->u.octet_aligned->buf,
571 r->u.octet_aligned->len, 0);
572 if (!(*type->fun)(in, (char **)&rr, 0, 0))
574 odr_perror(in, "Decoding constructed record.");
575 fprintf(stderr, "[Near %d]\n", odr_offset(in));
576 fprintf(stderr, "Packet dump:\n---------\n");
577 odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf,
578 r->u.octet_aligned->len);
579 fprintf(stderr, "---------\n");
583 * Note: we throw away the original, BER-encoded record here.
584 * Do something else with it if you want to keep it.
586 r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
587 r->which = type->what;
590 if (ent && ent->value == VAL_SOIF)
591 print_record((const unsigned char *) r->u.octet_aligned->buf,
592 r->u.octet_aligned->len);
593 else if (r->which == Z_External_octet && r->u.octet_aligned->len)
595 const char *octet_buf = (char*)r->u.octet_aligned->buf;
596 if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML ||
597 ent->value == VAL_HTML)
599 print_record((const unsigned char *) octet_buf,
600 r->u.octet_aligned->len);
602 else if (ent->value == VAL_POSTSCRIPT)
604 int size = r->u.octet_aligned->len;
607 print_record((const unsigned char *) octet_buf, size);
612 #if AVOID_MARC_DECODE
613 /* primitive check for a marc OID 5.1-29 except 16 */
614 ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
615 ent->oidsuffix[1] != 16
621 if (marc_display_exl (octet_buf, NULL, 0 /* debug */,
622 r->u.octet_aligned->len) <= 0)
624 printf ("bad MARC. Dumping as it is:\n");
625 print_record((const unsigned char*) octet_buf,
626 r->u.octet_aligned->len);
631 print_record((const unsigned char*) octet_buf,
632 r->u.octet_aligned->len);
636 fwrite (octet_buf, 1, r->u.octet_aligned->len, marcdump);
638 else if (ent && ent->value == VAL_SUTRS)
640 if (r->which != Z_External_sutrs)
642 printf("Expecting single SUTRS type for SUTRS.\n");
645 print_record(r->u.sutrs->buf, r->u.sutrs->len);
647 else if (ent && ent->value == VAL_GRS1)
649 if (r->which != Z_External_grs1)
651 printf("Expecting single GRS type for GRS.\n");
654 display_grs1(r->u.grs1, 0);
658 printf("Unknown record representation.\n");
659 if (!z_External(print, &r, 0, 0))
661 odr_perror(print, "Printing external");
667 static void display_diagrecs(Z_DiagRec **pp, int num)
671 Z_DefaultDiagFormat *r;
673 printf("Diagnostic message(s) from database:\n");
674 for (i = 0; i<num; i++)
676 Z_DiagRec *p = pp[i];
677 if (p->which != Z_DiagRec_defaultFormat)
679 printf("Diagnostic record not in default format.\n");
683 r = p->u.defaultFormat;
684 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
685 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
686 printf("Missing or unknown diagset\n");
687 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
690 case Z_DefaultDiagFormat_v2Addinfo:
691 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
693 case Z_DefaultDiagFormat_v3Addinfo:
694 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
701 static void display_nameplusrecord(Z_NamePlusRecord *p)
704 printf("[%s]", p->databaseName);
705 if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
706 display_diagrecs(&p->u.surrogateDiagnostic, 1);
707 else if (p->which == Z_NamePlusRecord_databaseRecord)
708 display_record(p->u.databaseRecord);
711 static void display_records(Z_Records *p)
715 if (p->which == Z_Records_NSD)
717 Z_DiagRec dr, *dr_p = &dr;
718 dr.which = Z_DiagRec_defaultFormat;
719 dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
720 display_diagrecs (&dr_p, 1);
722 else if (p->which == Z_Records_multipleNSD)
723 display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
724 p->u.multipleNonSurDiagnostics->num_diagRecs);
727 printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
728 for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
729 display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
733 static int send_deleteResultSetRequest(char *arg)
738 Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
739 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
741 req->referenceId = set_refid (out);
743 req->num_resultSetList =
744 sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
745 names[0], names[1], names[2], names[3],
746 names[4], names[5], names[6], names[7]);
748 req->deleteFunction = (int *)
749 odr_malloc (out, sizeof(*req->deleteFunction));
750 if (req->num_resultSetList > 0)
752 *req->deleteFunction = Z_DeleteRequest_list;
753 req->resultSetList = (char **)
754 odr_malloc (out, sizeof(*req->resultSetList)*
755 req->num_resultSetList);
756 for (i = 0; i<req->num_resultSetList; i++)
757 req->resultSetList[i] = names[i];
761 *req->deleteFunction = Z_DeleteRequest_all;
762 req->resultSetList = 0;
766 printf("Sent deleteResultSetRequest.\n");
770 static int send_searchRequest(char *arg)
772 Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
773 Z_SearchRequest *req = apdu->u.searchRequest;
777 struct ccl_rpn_node *rpn = NULL;
781 Z_RPNQuery *RPNquery;
785 if (queryType == QueryType_CCL2RPN)
787 rpn = ccl_find_str(bibset, arg, &error, &pos);
790 printf("CCL ERROR: %s\n", ccl_err_msg(error));
795 req->referenceId = set_refid (out);
796 if (!strcmp(arg, "@big")) /* strictly for troublemaking */
798 static unsigned char big[2100];
801 /* send a very big referenceid to test transport stack etc. */
802 memset(big, 'A', 2100);
803 bigo.len = bigo.size = 2100;
805 req->referenceId = &bigo;
810 sprintf(setstring, "%d", ++setnumber);
811 req->resultSetName = setstring;
813 *req->smallSetUpperBound = smallSetUpperBound;
814 *req->largeSetLowerBound = largeSetLowerBound;
815 *req->mediumSetPresentNumber = mediumSetPresentNumber;
816 if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
817 mediumSetPresentNumber > 0))
821 prefsyn.proto = protocol;
822 prefsyn.oclass = CLASS_RECSYN;
823 prefsyn.value = recordsyntax;
824 req->preferredRecordSyntax =
825 odr_oiddup(out, oid_ent_to_oid(&prefsyn, oid));
826 req->smallSetElementSetNames =
827 req->mediumSetElementSetNames = elementSetNames;
829 req->num_databaseNames = num_databaseNames;
830 req->databaseNames = databaseNames;
836 case QueryType_Prefix:
837 query.which = Z_Query_type_1;
838 RPNquery = p_query_rpn (out, protocol, arg);
841 printf("Prefix query error\n");
844 query.u.type_1 = RPNquery;
847 query.which = Z_Query_type_2;
848 query.u.type_2 = &ccl_query;
849 ccl_query.buf = (unsigned char*) arg;
850 ccl_query.len = strlen(arg);
853 case QueryType_CCL2RPN:
854 query.which = Z_Query_type_1;
855 RPNquery = ccl_rpn_query(out, rpn);
858 printf ("Couldn't convert from CCL to RPN\n");
861 query.u.type_1 = RPNquery;
862 ccl_rpn_delete (rpn);
866 printf ("Unsupported query type\n");
871 printf("Sent searchRequest.\n");
875 /* display Query Expression as part of searchResult-1 */
876 static void display_queryExpression (Z_QueryExpression *qe)
880 if (qe->which == Z_QueryExpression_term)
882 if (qe->u.term->queryTerm)
884 Z_Term *term = qe->u.term->queryTerm;
885 if (term->which == Z_Term_general)
886 printf (" %.*s", term->u.general->len, term->u.general->buf);
892 /* see if we can find USR:SearchResult-1 */
893 static void display_searchResult (Z_OtherInformation *o)
898 for (i = 0; i < o->num_elements; i++)
900 if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
902 Z_External *ext = o->list[i]->information.externallyDefinedInfo;
904 if (ext->which == Z_External_searchResult1)
907 Z_SearchInfoReport *sr = ext->u.searchResult1;
908 printf ("SearchResult-1:");
909 for (j = 0; j < sr->num; j++)
911 if (!sr->elements[j]->subqueryExpression)
913 display_queryExpression (
914 sr->elements[j]->subqueryExpression);
915 display_queryExpression (
916 sr->elements[j]->subqueryInterpretation);
917 display_queryExpression (
918 sr->elements[j]->subqueryRecommendation);
919 if (sr->elements[j]->subqueryCount)
920 printf ("(%d)", *sr->elements[j]->subqueryCount);
928 static int process_searchResponse(Z_SearchResponse *res)
930 printf ("Received SearchResponse.\n");
931 print_refid (res->referenceId);
932 if (*res->searchStatus)
933 printf("Search was a success.\n");
935 printf("Search was a bloomin' failure.\n");
936 printf("Number of hits: %d", *res->resultCount);
938 printf (", setno %d", setnumber);
940 display_searchResult (res->additionalSearchInfo);
941 printf("records returned: %d\n",
942 *res->numberOfRecordsReturned);
943 setno += *res->numberOfRecordsReturned;
945 display_records(res->records);
949 static void print_level(int iLevel)
952 for (i = 0; i < iLevel * 4; i++)
956 static void print_int(int iLevel, const char *pTag, int *pInt)
961 printf("%s: %d\n", pTag, *pInt);
965 static void print_string(int iLevel, const char *pTag, const char *pString)
970 printf("%s: %s\n", pTag, pString);
974 static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
982 for (; *pInt != -1; pInt++)
983 printf(" %d", *pInt);
988 static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
990 if (referenceId != NULL)
995 printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
996 for (i = 0; i < referenceId->len; i++)
997 printf("%c", referenceId->buf[i]);
1002 static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
1004 if (pStringNumeric != NULL)
1006 switch (pStringNumeric->which)
1008 case Z_StringOrNumeric_string:
1009 print_string(iLevel, pTag, pStringNumeric->u.string);
1012 case Z_StringOrNumeric_numeric:
1013 print_int(iLevel, pTag, pStringNumeric->u.numeric);
1017 print_level(iLevel);
1018 printf("%s: valid type for Z_StringOrNumeric\n", pTag);
1024 static void print_universe_report_duplicate(int iLevel, Z_UniverseReportDuplicate *pUniverseReportDuplicate)
1026 if (pUniverseReportDuplicate != NULL)
1028 print_level(iLevel);
1029 printf("Universe Report Duplicate: \n");
1031 print_string_or_numeric(iLevel, "Hit No",
1032 pUniverseReportDuplicate->hitno);
1037 print_universe_report_hits(int iLevel,
1038 Z_UniverseReportHits *pUniverseReportHits)
1040 if (pUniverseReportHits != NULL)
1042 print_level(iLevel);
1043 printf("Universe Report Hits: \n");
1045 print_string_or_numeric(iLevel, "Database",
1046 pUniverseReportHits->database);
1047 print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
1051 static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
1053 if (pUniverseReport != NULL)
1055 print_level(iLevel);
1056 printf("Universe Report: \n");
1058 print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
1059 switch (pUniverseReport->which)
1061 case Z_UniverseReport_databaseHits:
1062 print_universe_report_hits(iLevel, pUniverseReport->u.databaseHits);
1065 case Z_UniverseReport_duplicate:
1066 print_universe_report_duplicate(iLevel, pUniverseReport->u.duplicate);
1070 print_level(iLevel);
1071 printf("Type: %d\n", pUniverseReport->which);
1077 static void print_external(int iLevel, Z_External *pExternal)
1079 if (pExternal != NULL)
1081 print_level(iLevel);
1082 printf("External: \n");
1084 print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
1085 print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
1086 print_string(iLevel, "Descriptor", pExternal->descriptor);
1087 switch (pExternal->which)
1089 case Z_External_universeReport:
1090 print_universe_report(iLevel, pExternal->u.universeReport);
1094 print_level(iLevel);
1095 printf("Type: %d\n", pExternal->which);
1101 static int process_resourceControlRequest (Z_ResourceControlRequest *req)
1103 printf ("Received ResourceControlRequest.\n");
1104 print_referenceId(1, req->referenceId);
1105 print_int(1, "Suspended Flag", req->suspendedFlag);
1106 print_int(1, "Partial Results Available", req->partialResultsAvailable);
1107 print_int(1, "Response Required", req->responseRequired);
1108 print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
1109 print_external(1, req->resourceReport);
1113 void process_ESResponse(Z_ExtendedServicesResponse *res)
1116 switch (*res->operationStatus)
1118 case Z_ExtendedServicesResponse_done:
1121 case Z_ExtendedServicesResponse_accepted:
1122 printf ("accepted\n");
1124 case Z_ExtendedServicesResponse_failure:
1125 printf ("failure\n");
1126 display_diagrecs(res->diagnostics, res->num_diagnostics);
1129 printf ("unknown\n");
1131 if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
1132 (res->num_diagnostics != 0) ) {
1133 display_diagrecs(res->diagnostics, res->num_diagnostics);
1135 print_refid (res->referenceId);
1136 if (res->taskPackage &&
1137 res->taskPackage->which == Z_External_extendedService)
1139 Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1140 Odr_oct *id = taskPackage->targetReference;
1141 Z_External *ext = taskPackage->taskSpecificParameters;
1145 printf ("Target Reference: ");
1146 print_stringn (id->buf, id->len);
1149 if (ext->which == Z_External_update)
1151 Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
1152 if (utp && utp->targetPart)
1154 Z_IUTargetPart *targetPart = utp->targetPart;
1157 for (i = 0; i<targetPart->num_taskPackageRecords; i++)
1160 Z_IUTaskPackageRecordStructure *tpr =
1161 targetPart->taskPackageRecords[i];
1162 printf ("task package record %d\n", i+1);
1163 if (tpr->which == Z_IUTaskPackageRecordStructure_record)
1165 display_record (tpr->u.record);
1169 printf ("other type\n");
1179 const char *get_ill_element (void *clientData, const char *element)
1184 static Z_External *create_external_itemRequest()
1186 struct ill_get_ctl ctl;
1187 ILL_ItemRequest *req;
1189 int item_request_size = 0;
1190 char *item_request_buf = 0;
1194 ctl.f = get_ill_element;
1196 req = ill_get_ItemRequest(&ctl, "ill", 0);
1198 printf ("ill_get_ItemRequest failed\n");
1200 if (!ill_ItemRequest (out, &req, 0, 0))
1204 ill_ItemRequest(print, &req, 0, 0);
1207 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1208 if (item_request_buf)
1209 odr_setbuf (out, item_request_buf, item_request_size, 1);
1210 printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
1217 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1218 oid.proto = PROTO_GENERAL;
1219 oid.oclass = CLASS_GENERAL;
1220 oid.value = VAL_ISO_ILL_1;
1222 r = (Z_External *) odr_malloc (out, sizeof(*r));
1223 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1224 r->indirect_reference = 0;
1226 r->which = Z_External_single;
1228 r->u.single_ASN1_type = (Odr_oct *)
1229 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1230 r->u.single_ASN1_type->buf = (unsigned char *)
1231 odr_malloc (out, item_request_size);
1232 r->u.single_ASN1_type->len = item_request_size;
1233 r->u.single_ASN1_type->size = item_request_size;
1234 memcpy (r->u.single_ASN1_type->buf, item_request_buf,
1236 printf ("len = %d\n", item_request_size);
1242 #ifdef YAZ_MODULE_ill
1243 static Z_External *create_external_ILL_APDU(int which)
1245 struct ill_get_ctl ctl;
1248 int ill_request_size = 0;
1249 char *ill_request_buf = 0;
1253 ctl.f = get_ill_element;
1255 ill_apdu = ill_get_APDU(&ctl, "ill", 0);
1257 if (!ill_APDU (out, &ill_apdu, 0, 0))
1261 printf ("-------------------\n");
1262 ill_APDU(print, &ill_apdu, 0, 0);
1264 printf ("-------------------\n");
1266 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1267 if (ill_request_buf)
1268 odr_setbuf (out, ill_request_buf, ill_request_size, 1);
1269 printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
1275 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1277 oid.proto = PROTO_GENERAL;
1278 oid.oclass = CLASS_GENERAL;
1279 oid.value = VAL_ISO_ILL_1;
1281 r = (Z_External *) odr_malloc (out, sizeof(*r));
1282 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1283 r->indirect_reference = 0;
1285 r->which = Z_External_single;
1287 r->u.single_ASN1_type = (Odr_oct *)
1288 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1289 r->u.single_ASN1_type->buf = (unsigned char *)
1290 odr_malloc (out, ill_request_size);
1291 r->u.single_ASN1_type->len = ill_request_size;
1292 r->u.single_ASN1_type->size = ill_request_size;
1293 memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
1294 printf ("len = %d\n", ill_request_size);
1301 static Z_External *create_ItemOrderExternal(const char *type, int itemno)
1303 Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
1304 oident ItemOrderRequest;
1306 ItemOrderRequest.proto = PROTO_Z3950;
1307 ItemOrderRequest.oclass = CLASS_EXTSERV;
1308 ItemOrderRequest.value = VAL_ITEMORDER;
1310 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1311 r->indirect_reference = 0;
1314 r->which = Z_External_itemOrder;
1316 r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder));
1317 memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder));
1318 r->u.itemOrder->which=Z_IOItemOrder_esRequest;
1320 r->u.itemOrder->u.esRequest = (Z_IORequest *)
1321 odr_malloc(out,sizeof(Z_IORequest));
1322 memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest));
1324 r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
1325 odr_malloc(out,sizeof(Z_IOOriginPartToKeep));
1326 memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep));
1327 r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
1328 odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep));
1329 memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep));
1331 r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL;
1332 r->u.itemOrder->u.esRequest->toKeep->contact = NULL;
1333 r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL;
1335 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem =
1336 (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem));
1337 memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem));
1338 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1";
1340 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item =
1341 (int *) odr_malloc(out, sizeof(int));
1342 *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
1345 if (!strcmp (type, "item") || !strcmp(type, "2"))
1347 printf ("using item-request\n");
1348 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1349 create_external_itemRequest();
1351 else if (!strcmp(type, "ill") || !strcmp(type, "1"))
1353 printf ("using ILL-request\n");
1354 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1355 create_external_ILL_APDU(ILL_APDU_ILL_Request);
1357 else if (!strcmp(type, "xml") || !strcmp(type, "3"))
1359 const char *xml_buf =
1361 " <type>request</type>\n"
1362 " <libraryNo>000200</libraryNo>\n"
1363 " <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
1365 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1366 z_ext_record (out, VAL_TEXT_XML, xml_buf, strlen(xml_buf));
1369 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1372 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1377 static int send_itemorder(const char *type, int itemno)
1379 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
1380 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1381 oident ItemOrderRequest;
1383 ItemOrderRequest.proto = PROTO_Z3950;
1384 ItemOrderRequest.oclass = CLASS_EXTSERV;
1385 ItemOrderRequest.value = VAL_ITEMORDER;
1386 req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1387 req->packageName = esPackageName;
1389 req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
1395 static int cmd_update(char *arg)
1397 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
1398 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1401 Z_IUOriginPartToKeep *toKeep;
1402 Z_IUSuppliedRecords *notToKeep;
1404 printf ("Update request\n");
1409 update_oid.proto = PROTO_Z3950;
1410 update_oid.oclass = CLASS_EXTSERV;
1411 update_oid.value = VAL_DBUPDATE;
1412 oid_ent_to_oid (&update_oid, oid);
1413 req->packageType = odr_oiddup(out,oid);
1414 req->packageName = esPackageName;
1416 req->referenceId = set_refid (out);
1418 r = req->taskSpecificParameters = (Z_External *)
1419 odr_malloc (out, sizeof(*r));
1420 r->direct_reference = odr_oiddup(out,oid);
1421 r->indirect_reference = 0;
1423 r->which = Z_External_update;
1424 r->u.update = (Z_IUUpdate *) odr_malloc(out, sizeof(*r->u.update));
1425 r->u.update->which = Z_IUUpdate_esRequest;
1426 r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
1427 odr_malloc(out, sizeof(*r->u.update->u.esRequest));
1428 toKeep = r->u.update->u.esRequest->toKeep = (Z_IUOriginPartToKeep *)
1429 odr_malloc(out, sizeof(*r->u.update->u.esRequest->toKeep));
1430 toKeep->databaseName = databaseNames[0];
1432 toKeep->elementSetName = 0;
1433 toKeep->actionQualifier = 0;
1434 toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
1435 *toKeep->action = Z_IUOriginPartToKeep_recordInsert;
1437 notToKeep = r->u.update->u.esRequest->notToKeep = (Z_IUSuppliedRecords *)
1438 odr_malloc(out, sizeof(*r->u.update->u.esRequest->notToKeep));
1440 notToKeep->elements = (Z_IUSuppliedRecords_elem **)
1441 odr_malloc(out, sizeof(*notToKeep->elements));
1442 notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
1443 odr_malloc(out, sizeof(**notToKeep->elements));
1444 notToKeep->elements[0]->u.number = 0;
1445 notToKeep->elements[0]->supplementalId = 0;
1446 notToKeep->elements[0]->correlationInfo = 0;
1447 notToKeep->elements[0]->record = record_last;
1454 static int cmd_itemorder(char *arg)
1459 if (sscanf (arg, "%10s %d", type, &itemno) != 2)
1462 printf("Item order request\n");
1464 send_itemorder(type, itemno);
1468 static int cmd_find(char *arg)
1472 printf("Find what?\n");
1477 printf("Not connected yet\n");
1480 if (!send_searchRequest(arg))
1485 static int cmd_delete(char *arg)
1489 printf("Not connected yet\n");
1492 if (!send_deleteResultSetRequest(arg))
1497 static int cmd_ssub(char *arg)
1499 if (!(smallSetUpperBound = atoi(arg)))
1504 static int cmd_lslb(char *arg)
1506 if (!(largeSetLowerBound = atoi(arg)))
1511 static int cmd_mspn(char *arg)
1513 if (!(mediumSetPresentNumber = atoi(arg)))
1518 static int cmd_status(char *arg)
1520 printf("smallSetUpperBound: %d\n", smallSetUpperBound);
1521 printf("largeSetLowerBound: %d\n", largeSetLowerBound);
1522 printf("mediumSetPresentNumber: %d\n", mediumSetPresentNumber);
1526 static int cmd_setnames(char *arg)
1528 if (*arg == '1') /* enable ? */
1530 else if (*arg == '0') /* disable ? */
1532 else if (setnumber < 0) /* no args, toggle .. */
1538 printf("Set numbering enabled.\n");
1540 printf("Set numbering disabled.\n");
1544 /* PRESENT SERVICE ----------------------------- */
1546 static int send_presentRequest(char *arg)
1548 Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
1549 Z_PresentRequest *req = apdu->u.presentRequest;
1550 Z_RecordComposition compo;
1555 char setstring[100];
1557 req->referenceId = set_refid (out);
1558 if ((p = strchr(arg, '+')))
1565 if (p && (p=strchr(p+1, '+')))
1567 strcpy (setstring, p+1);
1568 req->resultSetId = setstring;
1570 else if (setnumber >= 0)
1572 sprintf(setstring, "%d", setnumber);
1573 req->resultSetId = setstring;
1575 req->resultSetStartPoint = &setno;
1576 req->numberOfRecordsRequested = &nos;
1577 prefsyn.proto = protocol;
1578 prefsyn.oclass = CLASS_RECSYN;
1579 prefsyn.value = recordsyntax;
1580 req->preferredRecordSyntax =
1581 odr_oiddup (out, oid_ent_to_oid(&prefsyn, oid));
1583 if (schema != VAL_NONE)
1587 prefschema.proto = protocol;
1588 prefschema.oclass = CLASS_SCHEMA;
1589 prefschema.value = schema;
1591 req->recordComposition = &compo;
1592 compo.which = Z_RecordComp_complex;
1593 compo.u.complex = (Z_CompSpec *)
1594 odr_malloc(out, sizeof(*compo.u.complex));
1595 compo.u.complex->selectAlternativeSyntax = (bool_t *)
1596 odr_malloc(out, sizeof(bool_t));
1597 *compo.u.complex->selectAlternativeSyntax = 0;
1599 compo.u.complex->generic = (Z_Specification *)
1600 odr_malloc(out, sizeof(*compo.u.complex->generic));
1601 compo.u.complex->generic->schema = (Odr_oid *)
1602 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1603 if (!compo.u.complex->generic->schema)
1605 /* OID wasn't a schema! Try record syntax instead. */
1606 prefschema.oclass = CLASS_RECSYN;
1607 compo.u.complex->generic->schema = (Odr_oid *)
1608 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1610 if (!elementSetNames)
1611 compo.u.complex->generic->elementSpec = 0;
1614 compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
1615 odr_malloc(out, sizeof(Z_ElementSpec));
1616 compo.u.complex->generic->elementSpec->which =
1617 Z_ElementSpec_elementSetName;
1618 compo.u.complex->generic->elementSpec->u.elementSetName =
1619 elementSetNames->u.generic;
1621 compo.u.complex->num_dbSpecific = 0;
1622 compo.u.complex->dbSpecific = 0;
1623 compo.u.complex->num_recordSyntax = 0;
1624 compo.u.complex->recordSyntax = 0;
1626 else if (elementSetNames)
1628 req->recordComposition = &compo;
1629 compo.which = Z_RecordComp_simple;
1630 compo.u.simple = elementSetNames;
1633 printf("Sent presentRequest (%d+%d).\n", setno, nos);
1637 static void close_session (void)
1643 nmem_destroy (session_mem);
1649 void process_close(Z_Close *req)
1651 Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
1652 Z_Close *res = apdu->u.close;
1654 static char *reasons[] =
1659 "cost limit reached",
1661 "security violation",
1668 printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
1669 req->diagnosticInformation ? req->diagnosticInformation : "NULL");
1674 *res->closeReason = Z_Close_finished;
1676 printf("Sent response.\n");
1681 static int cmd_show(char *arg)
1685 printf("Not connected yet\n");
1688 if (!send_presentRequest(arg))
1693 int cmd_quit(char *arg)
1695 printf("See you later, alligator.\n");
1701 int cmd_cancel(char *arg)
1703 Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
1704 Z_TriggerResourceControlRequest *req =
1705 apdu->u.triggerResourceControlRequest;
1710 printf("Session not initialized yet\n");
1713 if (!ODR_MASK_GET(session->options, Z_Options_triggerResourceCtrl))
1715 printf("Target doesn't support cancel (trigger resource ctrl)\n");
1718 *req->requestedAction = Z_TriggerResourceCtrl_cancel;
1719 req->resultSetWanted = &rfalse;
1722 printf("Sent cancel request\n");
1726 int send_scanrequest(const char *query, int pp, int num, const char *term)
1728 Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
1729 Z_ScanRequest *req = apdu->u.scanRequest;
1734 if (queryType == QueryType_CCL2RPN)
1738 struct ccl_rpn_node *rpn;
1740 rpn = ccl_find_str (bibset, query, &error, &pos);
1743 printf("CCL ERROR: %s\n", ccl_err_msg(error));
1747 bib1.proto = PROTO_Z3950;
1748 bib1.oclass = CLASS_ATTSET;
1749 bib1.value = VAL_BIB1;
1750 req->attributeSet = oid_ent_to_oid (&bib1, oid);
1751 if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
1753 printf("Couldn't convert CCL to Scan term\n");
1756 ccl_rpn_delete (rpn);
1759 if (use_rpn && !(req->termListAndStartPoint =
1760 p_query_scan(out, protocol, &req->attributeSet, query)))
1762 printf("Prefix query error\n");
1767 if (req->termListAndStartPoint->term &&
1768 req->termListAndStartPoint->term->which == Z_Term_general &&
1769 req->termListAndStartPoint->term->u.general)
1771 req->termListAndStartPoint->term->u.general->buf =
1772 (unsigned char *) odr_strdup(out, term);
1773 req->termListAndStartPoint->term->u.general->len =
1774 req->termListAndStartPoint->term->u.general->size =
1778 req->referenceId = set_refid (out);
1779 req->num_databaseNames = num_databaseNames;
1780 req->databaseNames = databaseNames;
1781 req->numberOfTermsRequested = #
1782 req->preferredPositionInResponse = &pp;
1787 int send_sortrequest(char *arg, int newset)
1789 Z_APDU *apdu = zget_APDU(out, Z_APDU_sortRequest);
1790 Z_SortRequest *req = apdu->u.sortRequest;
1791 Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
1792 odr_malloc (out, sizeof(*sksl));
1796 sprintf (setstring, "%d", setnumber);
1798 sprintf (setstring, "default");
1800 req->referenceId = set_refid (out);
1802 req->num_inputResultSetNames = 1;
1803 req->inputResultSetNames = (Z_InternationalString **)
1804 odr_malloc (out, sizeof(*req->inputResultSetNames));
1805 req->inputResultSetNames[0] = odr_strdup (out, setstring);
1807 if (newset && setnumber >= 0)
1808 sprintf (setstring, "%d", ++setnumber);
1810 req->sortedResultSetName = odr_strdup (out, setstring);
1812 req->sortSequence = yaz_sort_spec (out, arg);
1813 if (!req->sortSequence)
1815 printf ("Missing sort specifications\n");
1822 void display_term(Z_TermInfo *t)
1824 if (t->term->which == Z_Term_general)
1826 printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
1827 sprintf(last_scan_line, "%.*s", t->term->u.general->len,
1828 t->term->u.general->buf);
1831 printf("Term (not general)");
1832 if (t->globalOccurrences)
1833 printf (" (%d)\n", *t->globalOccurrences);
1838 void process_scanResponse(Z_ScanResponse *res)
1841 Z_Entry **entries = NULL;
1842 int num_entries = 0;
1844 printf("Received ScanResponse\n");
1845 print_refid (res->referenceId);
1846 printf("%d entries", *res->numberOfEntriesReturned);
1847 if (res->positionOfTerm)
1848 printf (", position=%d", *res->positionOfTerm);
1850 if (*res->scanStatus != Z_Scan_success)
1851 printf("Scan returned code %d\n", *res->scanStatus);
1854 if ((entries = res->entries->entries))
1855 num_entries = res->entries->num_entries;
1856 for (i = 0; i < num_entries; i++)
1858 int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
1859 if (entries[i]->which == Z_Entry_termInfo)
1861 printf("%c ", i + 1 == pos_term ? '*' : ' ');
1862 display_term(entries[i]->u.termInfo);
1865 display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1);
1867 if (res->entries->nonsurrogateDiagnostics)
1868 display_diagrecs (res->entries->nonsurrogateDiagnostics,
1869 res->entries->num_nonsurrogateDiagnostics);
1872 void process_sortResponse(Z_SortResponse *res)
1874 printf("Received SortResponse: status=");
1875 switch (*res->sortStatus)
1877 case Z_SortStatus_success:
1878 printf ("success"); break;
1879 case Z_SortStatus_partial_1:
1880 printf ("partial"); break;
1881 case Z_SortStatus_failure:
1882 printf ("failure"); break;
1884 printf ("unknown (%d)", *res->sortStatus);
1887 print_refid (res->referenceId);
1888 if (res->diagnostics)
1889 display_diagrecs(res->diagnostics,
1890 res->num_diagnostics);
1893 void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res)
1895 printf("Got deleteResultSetResponse status=%d\n",
1896 *res->deleteOperationStatus);
1897 if (res->deleteListStatuses)
1900 for (i = 0; i < res->deleteListStatuses->num; i++)
1902 printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id,
1903 *res->deleteListStatuses->elements[i]->status);
1908 int cmd_sort_generic(char *arg, int newset)
1912 printf("Session not initialized yet\n");
1915 if (!ODR_MASK_GET(session->options, Z_Options_sort))
1917 printf("Target doesn't support sort\n");
1922 if (send_sortrequest(arg, newset) < 0)
1929 int cmd_sort(char *arg)
1931 return cmd_sort_generic (arg, 0);
1934 int cmd_sort_newset (char *arg)
1936 return cmd_sort_generic (arg, 1);
1939 int cmd_scan(char *arg)
1943 printf("Session not initialized yet\n");
1946 if (!ODR_MASK_GET(session->options, Z_Options_scan))
1948 printf("Target doesn't support scan\n");
1953 strcpy (last_scan_query, arg);
1954 if (send_scanrequest(arg, 1, 20, 0) < 0)
1959 if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0)
1965 int cmd_schema(char *arg)
1972 schema = oid_getvalbyname (arg);
1973 if (schema == VAL_NONE)
1975 printf ("unknown schema\n");
1981 int cmd_format(char *arg)
1985 printf("Usage: format <recordsyntax>\n");
1988 recordsyntax = oid_getvalbyname (arg);
1989 if (recordsyntax == VAL_NONE)
1991 printf ("unknown record syntax\n");
1997 int cmd_elements(char *arg)
1999 static Z_ElementSetNames esn;
2000 static char what[100];
2004 elementSetNames = 0;
2008 esn.which = Z_ElementSetNames_generic;
2009 esn.u.generic = what;
2010 elementSetNames = &esn;
2014 int cmd_attributeset(char *arg)
2020 printf("Usage: attributeset <setname>\n");
2023 sscanf(arg, "%s", what);
2024 if (p_query_attset (what))
2026 printf("Unknown attribute set name\n");
2032 int cmd_querytype (char *arg)
2034 if (!strcmp (arg, "ccl"))
2035 queryType = QueryType_CCL;
2036 else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn"))
2037 queryType = QueryType_Prefix;
2039 else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
2040 queryType = QueryType_CCL2RPN;
2044 printf ("Querytype must be one of:\n");
2045 printf (" prefix - Prefix query\n");
2046 printf (" ccl - CCL query\n");
2048 printf (" ccl2rpn - CCL query converted to RPN\n");
2055 int cmd_refid (char *arg)
2061 refid = (char *) xmalloc (strlen(arg)+1);
2062 strcpy (refid, arg);
2067 int cmd_close(char *arg)
2074 apdu = zget_APDU(out, Z_APDU_close);
2075 req = apdu->u.close;
2076 *req->closeReason = Z_Close_finished;
2078 printf("Sent close request.\n");
2083 int cmd_packagename(char* arg)
2085 xfree (esPackageName);
2086 esPackageName = NULL;
2089 esPackageName = (char *) xmalloc (strlen(arg)+1);
2090 strcpy (esPackageName, arg);
2095 int cmd_proxy(char* arg)
2098 printf("Current proxy is `%s'\n", (yazCharset)?yazProxy:NULL);
2105 yazProxy = (char *) xmalloc (strlen(arg)+1);
2106 strcpy (yazProxy, arg);
2111 int cmd_charset(char* arg)
2114 printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL);
2121 yazCharset = (char *) xmalloc (strlen(arg)+1);
2122 strcpy (yazCharset, arg);
2127 int cmd_lang(char* arg)
2130 printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
2137 yazLang = (char *) xmalloc (strlen(arg)+1);
2138 strcpy (yazLang, arg);
2143 int cmd_source(char* arg)
2145 /* first should open the file and read one line at a time.. */
2147 char line[1024], *cp;
2150 char* args_end=(arg)+strlen(arg)-1;
2151 while(isspace(*args_end))
2156 REMOVE_TAILING_BLANKS(arg);
2159 fprintf(stderr,"Error in source command use a filename\n");
2163 includeFile = fopen (arg, "r");
2166 fprintf(stderr,"Unable to open file %s for reading\n",arg);
2170 while(!feof(includeFile)) {
2171 memset(line,0,sizeof(line));
2172 fgets(line,sizeof(line),includeFile);
2174 if(strlen(line) < 2) continue;
2175 if(line[0] == '#') continue;
2177 if ((cp = strrchr (line, '\n')))
2180 process_cmd_line(line);
2183 if(fclose(includeFile)<0) {
2184 perror("unable to close include file");
2190 int cmd_subshell(char* args)
2195 system(getenv("SHELL"));
2201 int cmd_set_apdufile(char* arg)
2203 REMOVE_TAILING_BLANKS(arg);
2205 if(apdu_file && apdu_file != stderr) { /* don't close stdout*/
2206 perror("unable to close apdu log file");
2214 if(!strcmp(arg,"-"))
2217 apdu_file=fopen(arg, "a");
2220 perror("unable to open apdu log file no apdu log loaded");
2222 odr_setprint(print, apdu_file);
2228 int cmd_set_cclfields(char* arg)
2233 REMOVE_TAILING_BLANKS(arg);
2235 bibset = ccl_qual_mk ();
2236 inf = fopen (arg, "r");
2239 ccl_qual_file (bibset, inf);
2243 fprintf(stderr,"Not compiled with the yaz ccl module\n");
2249 int cmd_set_marcdump(char* arg)
2251 if(marcdump && marcdump != stderr) { /* don't close stdout*/
2252 perror("unable to close apdu log file");
2260 if(!strcmp(arg,"-"))
2263 marcdump=fopen(arg, "a");
2266 perror("unable to open apdu marcdump file no marcdump done\n");
2272 int cmd_set_proxy(char* arg) {
2273 if(yazProxy) free(yazProxy);
2276 if(strlen(arg) > 1) {
2277 yazProxy=strdup(arg);
2283 this command takes 3 arge {name class oid}
2285 int cmd_register_oid(char* args) {
2290 {"appctx",CLASS_APPCTX},
2291 {"absyn",CLASS_ABSYN},
2292 {"attset",CLASS_ATTSET},
2293 {"transyn",CLASS_TRANSYN},
2294 {"diagset",CLASS_DIAGSET},
2295 {"recsyn",CLASS_RECSYN},
2296 {"resform",CLASS_RESFORM},
2297 {"accform",CLASS_ACCFORM},
2298 {"extserv",CLASS_EXTSERV},
2299 {"userinfo",CLASS_USERINFO},
2300 {"elemspec",CLASS_ELEMSPEC},
2301 {"varset",CLASS_VARSET},
2302 {"schema",CLASS_SCHEMA},
2303 {"tagset",CLASS_TAGSET},
2304 {"general",CLASS_GENERAL},
2307 char oname_str[101], oclass_str[101], oid_str[101];
2310 oid_class oidclass = CLASS_GENERAL;
2311 int val = 0, oid[OID_SIZE];
2312 struct oident * new_oident=NULL;
2314 if (sscanf (args, "%100[^ ] %100[^ ] %100s",
2315 oname_str,oclass_str, oid_str) < 1) {
2316 printf("Error in regristrate command \n");
2320 for (i = 0; oid_classes[i].className; i++) {
2321 if (!strcmp(oid_classes[i].className, oclass_str))
2323 oidclass=oid_classes[i].oclass;
2328 if(!(oid_classes[i].className)) {
2329 printf("Unknonwn oid class %s\n",oclass_str);
2337 while (isdigit (*name))
2339 val = val*10 + (*name - '0');
2352 new_oident=oid_addent (oid,PROTO_GENERAL,oidclass,oname_str,VAL_DYNAMIC);
2353 if(strcmp(new_oident->desc,oname_str)) {
2354 fprintf(stderr,"oid is already named as %s, regristration faild\n",
2360 int cmd_push_command(char* arg) {
2361 #if HAVE_READLINE_HISTORY_H
2365 fprintf(stderr,"Not compiled with the readline/history module\n");
2370 void source_rcfile() {
2371 /* Look for a $HOME/.yazclientrc and source it if it exists */
2372 struct stat statbuf;
2374 char* homedir=getenv("HOME");
2375 if(!homedir) return;
2377 sprintf(buffer,"%s/.yazclientrc",homedir);
2379 if(stat(buffer,&statbuf)==0) {
2383 if(stat(".yazclientrc",&statbuf)==0) {
2384 cmd_source(".yazclientrc");
2389 static void initialize(void)
2394 if (!(out = odr_createmem(ODR_ENCODE)) ||
2395 !(in = odr_createmem(ODR_DECODE)) ||
2396 !(print = odr_createmem(ODR_PRINT)))
2398 fprintf(stderr, "failed to allocate ODR streams\n");
2403 setvbuf(stdout, 0, _IONBF, 0);
2405 odr_setprint(print, apdu_file);
2408 bibset = ccl_qual_mk ();
2409 inf = fopen (ccl_fields, "r");
2412 ccl_qual_file (bibset, inf);
2416 cmd_base("Default");
2418 #if HAVE_READLINE_READLINE_H
2419 rl_attempted_completion_function = (CPPFunction*)readline_completer;
2426 #if HAVE_GETTIMEOFDAY
2427 struct timeval tv_start, tv_end;
2430 void wait_and_handle_responce()
2435 int netbufferlen = 0;
2443 if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
2445 printf("Target closed connection\n");
2451 printf("Target closed connection.\n");
2455 odr_reset(in); /* release APDU from last round */
2457 odr_setbuf(in, netbuffer, res, 0);
2458 if (!z_APDU(in, &apdu, 0, 0))
2460 odr_perror(in, "Decoding incoming APDU");
2461 fprintf(stderr, "[Near %d]\n", odr_offset(in));
2462 fprintf(stderr, "Packet dump:\n---------\n");
2463 odr_dumpBER(stderr, netbuffer, res);
2464 fprintf(stderr, "---------\n");
2466 z_APDU(print, &apdu, 0, 0);
2470 if (apdu_file && !z_APDU(print, &apdu, 0, 0))
2472 odr_perror(print, "Failed to print incoming APDU");
2478 case Z_APDU_initResponse:
2479 process_initResponse(apdu->u.initResponse);
2481 case Z_APDU_searchResponse:
2482 process_searchResponse(apdu->u.searchResponse);
2484 case Z_APDU_scanResponse:
2485 process_scanResponse(apdu->u.scanResponse);
2487 case Z_APDU_presentResponse:
2488 print_refid (apdu->u.presentResponse->referenceId);
2490 *apdu->u.presentResponse->numberOfRecordsReturned;
2491 if (apdu->u.presentResponse->records)
2492 display_records(apdu->u.presentResponse->records);
2494 printf("No records.\n");
2495 printf ("nextResultSetPosition = %d\n",
2496 *apdu->u.presentResponse->nextResultSetPosition);
2498 case Z_APDU_sortResponse:
2499 process_sortResponse(apdu->u.sortResponse);
2501 case Z_APDU_extendedServicesResponse:
2502 printf("Got extended services response\n");
2503 process_ESResponse(apdu->u.extendedServicesResponse);
2506 printf("Target has closed the association.\n");
2507 process_close(apdu->u.close);
2509 case Z_APDU_resourceControlRequest:
2510 process_resourceControlRequest
2511 (apdu->u.resourceControlRequest);
2513 case Z_APDU_deleteResultSetResponse:
2514 process_deleteResultSetResponse(apdu->u.
2515 deleteResultSetResponse);
2518 printf("Received unknown APDU type (%d).\n",
2523 while (conn && cs_more(conn));
2524 #if HAVE_GETTIMEOFDAY
2525 gettimeofday (&tv_end, 0);
2527 printf ("S/U S/U=%ld/%ld %ld/%ld",
2528 (long) tv_start.tv_sec,
2529 (long) tv_start.tv_usec,
2530 (long) tv_end.tv_sec,
2531 (long) tv_end.tv_usec);
2533 printf ("Elapsed: %.6f\n",
2534 (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
2535 ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
2542 static int cmd_help (char *line);
2546 int (*fun)(char *arg);
2548 char *(*rl_completerfunction)(const char *text, int state);
2549 int complete_filenames;
2551 {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0},
2552 {"quit", cmd_quit, "",NULL,0},
2553 {"find", cmd_find, "<query>",NULL,0},
2554 {"delete", cmd_delete, "<setname>",NULL,0},
2555 {"base", cmd_base, "<base-name>",NULL,0},
2556 {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0},
2557 {"scan", cmd_scan, "<term>",NULL,0},
2558 {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0},
2559 {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0},
2560 {"authentication", cmd_authentication, "<acctstring>",NULL,0},
2561 {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0},
2562 {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0},
2563 {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0},
2564 {"status", cmd_status, "",NULL,0},
2565 {"setnames", cmd_setnames, "",NULL,0},
2566 {"cancel", cmd_cancel, "",NULL,0},
2567 {"format", cmd_format, "<recordsyntax>",complete_format,0},
2568 {"schema", cmd_schema, "<schema>",complete_schema,0},
2569 {"elements", cmd_elements, "<elementSetName>",NULL,0},
2570 {"close", cmd_close, "",NULL,0},
2571 {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0},
2572 {"querytype", cmd_querytype, "<type>",complete_querytype,0},
2573 {"refid", cmd_refid, "<id>",NULL,0},
2574 {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0},
2575 {"update", cmd_update, "<item>",NULL,0},
2576 {"packagename", cmd_packagename, "<packagename>",NULL,0},
2577 {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0},
2578 {"charset", cmd_charset, "<charset_name>",NULL,0},
2579 {"lang", cmd_lang, "<language_code>",NULL,0},
2580 {".", cmd_source, "<filename>",NULL,1},
2581 {"!", cmd_subshell, "Subshell command",NULL,0},
2582 {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,0},
2583 {"set_marcdump", cmd_set_marcdump," <filename>",NULL,0},
2584 {"set_cclfields", cmd_set_cclfields,"<filename>",NULL,1},
2585 {"register_oid",cmd_register_oid,"<name> <class> <oid>",NULL,0},
2586 {"push_command",cmd_push_command,"<command>",command_generator,0},
2587 /* Server Admin Functions */
2588 {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0},
2589 {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0},
2590 {"adm-create", cmd_adm_create, "",NULL,0},
2591 {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0},
2592 {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0},
2593 {"adm-refresh", cmd_adm_refresh, "",NULL,0},
2594 {"adm-commit", cmd_adm_commit, "",NULL,0},
2595 {"adm-shutdown", cmd_adm_shutdown, "",NULL,0},
2596 {"adm-startup", cmd_adm_startup, "",NULL,0},
2597 {"help", cmd_help, "", NULL},
2601 static int cmd_help (char *line)
2607 sscanf (line, "%20s", topic);
2610 printf("Commands:\n");
2611 for (i = 0; cmd[i].cmd; i++)
2612 if (*topic == 0 || strcmp (topic, cmd[i].cmd) == 0)
2613 printf(" %s %s\n", cmd[i].cmd, cmd[i].ad);
2614 if (strcmp (topic, "find") == 0)
2617 printf (" \"term\" Simple Term\n");
2618 printf (" @attr [attset] type=value op Attribute\n");
2619 printf (" @and opl opr And\n");
2620 printf (" @or opl opr Or\n");
2621 printf (" @not opl opr And-Not\n");
2622 printf (" @set set Result set\n");
2624 printf ("Bib-1 attribute types\n");
2626 printf ("4=Title 7=ISBN 8=ISSN 30=Date 62=Abstract 1003=Author 1016=Any\n");
2627 printf ("2=Relation: ");
2628 printf ("1< 2<= 3= 4>= 5> 6!= 102=Relevance\n");
2629 printf ("3=Position: ");
2630 printf ("1=First in Field 2=First in subfield 3=Any position\n");
2631 printf ("4=Structure: ");
2632 printf ("1=Phrase 2=Word 3=Key 4=Year 5=Date 6=WordList\n");
2633 printf ("5=Truncation: ");
2634 printf ("1=Right 2=Left 3=L&R 100=No 101=# 102=Re-1 103=Re-2\n");
2635 printf ("6=Completeness:");
2636 printf ("1=Incomplete subfield 2=Complete subfield 3=Complete field\n");
2641 void process_cmd_line(char* line)
2644 char word[32], arg[1024];
2646 #if HAVE_GETTIMEOFDAY
2647 gettimeofday (&tv_start, 0);
2650 if ((res = sscanf(line, "%31s %1023[^;]", word, arg)) <= 0)
2652 strcpy(word, last_cmd);
2657 strcpy(last_cmd, word);
2659 /* removed tailing spaces from the arg command */
2662 char* lastnonspace=NULL;
2671 *(++lastnonspace) = 0;
2675 for (i = 0; cmd[i].cmd; i++)
2676 if (!strncmp(cmd[i].cmd, word, strlen(word)))
2678 res = (*cmd[i].fun)(arg);
2682 if (!cmd[i].cmd) /* dump our help-screen */
2684 printf("Unknown command: %s.\n", word);
2689 if(apdu_file) fflush(apdu_file);
2692 wait_and_handle_responce();
2701 char *command_generator(const char *text, int state)
2707 for( ; cmd[idx].cmd; ++idx) {
2708 if (!strncmp(cmd[idx].cmd,text,strlen(text))) {
2709 ++idx; /* skip this entry on the next run */
2710 return strdup(cmd[idx-1].cmd);
2718 This function only known how to complete on the first word
2720 char ** readline_completer(char *text, int start, int end) {
2721 #if HAVE_READLINE_READLINE_H
2724 #if HAVE_READLINE_RL_COMPLETION_MATCHES
2725 char** res=rl_completion_matches(text,
2728 char** res=completion_matches(text,
2729 (CPFunction*)command_generator);
2731 rl_attempted_completion_over = 1;
2734 char arg[1024],word[32];
2736 if ((res = sscanf(rl_line_buffer, "%31s %1023[^;]", word, arg)) <= 0) {
2737 rl_attempted_completion_over = 1;
2741 if(start != strlen(word) +1 ) {
2742 rl_attempted_completion_over = 1;
2745 for (i = 0; cmd[i].cmd; i++) {
2746 if (!strncmp(cmd[i].cmd, word, strlen(word))) {
2752 if(!cmd[i].complete_filenames)
2753 rl_attempted_completion_over = 1;
2754 if(cmd[i].rl_completerfunction) {
2755 #ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
2757 rl_completion_matches(text,
2758 cmd[i].rl_completerfunction);
2761 completion_matches(text,
2762 (CPFunction*)cmd[i].rl_completerfunction);
2764 rl_attempted_completion_over = 1;
2767 rl_attempted_completion_over = 1;
2777 static void client(void)
2783 #if HAVE_GETTIMEOFDAY
2784 gettimeofday (&tv_start, 0);
2789 char *line_in = NULL;
2790 #if HAVE_READLINE_READLINE_H
2793 line_in=readline(C_PROMPT);
2796 #if HAVE_READLINE_HISTORY_H
2798 add_history(line_in);
2800 strncpy(line, line_in, 1023);
2809 if (!fgets(line, 1023, stdin))
2811 if ((end_p = strchr (line, '\n')))
2814 process_cmd_line(line);
2818 int main(int argc, char **argv)
2821 char *open_command = 0;
2822 char *auth_command = 0;
2826 while ((ret = options("k:c:a:m:v:p:u:", argv, argc, &arg)) != -2)
2833 open_command = (char *) xmalloc (strlen(arg)+6);
2834 strcpy (open_command, "open ");
2835 strcat (open_command, arg);
2839 kilobytes = atoi(arg);
2842 if (!(marcdump = fopen (arg, "a")))
2849 strncpy (ccl_fields, arg, sizeof(ccl_fields)-1);
2850 ccl_fields[sizeof(ccl_fields)-1] = '\0';
2853 if (!strcmp(arg, "-"))
2856 apdu_file=fopen(arg, "a");
2859 yazProxy=strdup(arg);
2864 auth_command = (char *) xmalloc (strlen(arg)+6);
2865 strcpy (auth_command, "auth ");
2866 strcat (auth_command, arg);
2870 yaz_log_init (yaz_log_mask_str(arg), "", NULL);
2873 fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
2874 "[-c cclfields]\n [-p <proxy-addr>] [-u <auth>] "
2875 "[-k size] [<server-addr>]\n",
2883 #ifdef HAVE_GETTIMEOFDAY
2884 gettimeofday (&tv_start, 0);
2886 process_cmd_line (auth_command);
2887 #if HAVE_READLINE_HISTORY_H
2888 add_history(auth_command);
2890 xfree(auth_command);
2894 #ifdef HAVE_GETTIMEOFDAY
2895 gettimeofday (&tv_start, 0);
2897 process_cmd_line (open_command);
2898 #if HAVE_READLINE_HISTORY_H
2899 add_history(open_command);
2901 xfree(open_command);