2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: client.c,v 1.156 2002-06-02 21:34:45 adam 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>
30 #include <yaz/yaz-ccl.h>
32 #if HAVE_READLINE_READLINE_H
33 #include <readline/readline.h>
35 #if HAVE_READLINE_HISTORY_H
36 #include <readline/history.h>
43 #include "tabcomplete.h"
45 #define C_PROMPT "Z> "
47 static ODR out, in, print; /* encoding and decoding streams */
48 static FILE *apdu_file = 0;
49 static COMSTACK conn = 0; /* our z-association */
50 static Z_IdAuthentication *auth = 0; /* our current auth definition */
51 char *databaseNames[128];
52 int num_databaseNames = 0;
53 static Z_External *record_last = 0;
54 static int setnumber = -1; /* current result set number */
55 static int smallSetUpperBound = 0;
56 static int largeSetLowerBound = 1;
57 static int mediumSetPresentNumber = 0;
58 static Z_ElementSetNames *elementSetNames = 0;
59 static int setno = 1; /* current set offset */
60 static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */
61 static enum oid_value recordsyntax = VAL_USMARC;
62 static enum oid_value schema = VAL_NONE;
63 static int sent_close = 0;
64 static NMEM session_mem = NULL; /* memory handle for init-response */
65 static Z_InitResponse *session = 0; /* session parameters */
66 static char last_scan_line[512] = "0";
67 static char last_scan_query[512] = "0";
68 static char ccl_fields[512] = "default.bib";
69 static char* esPackageName = 0;
70 static char* yazProxy = 0;
71 static int kilobytes = 1024;
72 static char* yazCharset = 0;
73 static char* yazLang = 0;
75 static char last_cmd[32] = "?";
76 static FILE *marcdump = 0;
77 static char *refid = NULL;
85 static QueryType queryType = QueryType_Prefix;
87 static CCL_bibset bibset; /* CCL bibset handle */
89 #if HAVE_READLINE_COMPLETION_OVER
92 /* readline doesn't have this var. Define it ourselves. */
93 int rl_attempted_completion_over = 0;
96 /* set this one to 1, to avoid decode of unknown MARCs */
97 #define AVOID_MARC_DECODE 1
99 /* nice helper macro as extensive tabbing gives spaces at the en of the args lines */
100 #define REMOVE_TAILING_BLANKS(a) {\
101 char* args_end=(a)+strlen(a)-1; \
102 while(isspace(*args_end)) {*args_end=0;--args_end;}; \
106 void process_cmd_line(char* line);
107 char ** readline_completer(char *text, int start, int end);
108 char *command_generator(const char *text, int state);
111 ODR getODROutputStream()
116 void send_apdu(Z_APDU *a)
123 z_APDU(print, &a, 0, 0);
126 if (!z_APDU(out, &a, 0, 0))
128 odr_perror(out, "Encoding APDU");
131 buf = odr_getbuf(out, &len, 0);
132 /* printf ("sending APDU of size %d\n", len); */
133 if (cs_put(conn, buf, len) < 0)
135 fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn)));
138 odr_reset(out); /* release the APDU structure */
141 static void print_stringn(const unsigned char *buf, size_t len)
144 for (i = 0; i<len; i++)
145 if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
146 printf ("%c", buf[i]);
148 printf ("\\X%02X", buf[i]);
151 static void print_refid (Z_ReferenceId *id)
155 printf ("Reference Id: ");
156 print_stringn (id->buf, id->len);
161 static Z_ReferenceId *set_refid (ODR out)
166 id = (Z_ReferenceId *) odr_malloc (out, sizeof(*id));
167 id->size = id->len = strlen(refid);
168 id->buf = (unsigned char *) odr_malloc (out, id->len);
169 memcpy (id->buf, refid, id->len);
173 /* INIT SERVICE ------------------------------- */
175 static void send_initRequest(const char* type_and_host)
177 Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest);
178 Z_InitRequest *req = apdu->u.initRequest;
180 ODR_MASK_SET(req->options, Z_Options_search);
181 ODR_MASK_SET(req->options, Z_Options_present);
182 ODR_MASK_SET(req->options, Z_Options_namedResultSets);
183 ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl);
184 ODR_MASK_SET(req->options, Z_Options_scan);
185 ODR_MASK_SET(req->options, Z_Options_sort);
186 ODR_MASK_SET(req->options, Z_Options_extendedServices);
187 ODR_MASK_SET(req->options, Z_Options_delSet);
189 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
190 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
191 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
193 *req->maximumRecordSize = 1024*kilobytes;
194 *req->preferredMessageSize = 1024*kilobytes;
196 req->idAuthentication = auth;
198 req->referenceId = set_refid (out);
201 yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
204 if (yazCharset || yazLang) {
205 Z_OtherInformation **p;
206 Z_OtherInformationUnit *p0;
208 yaz_oi_APDU(apdu, &p);
210 if (p0=yaz_oi_update(p, out, NULL, 0, 0)) {
211 ODR_MASK_SET(req->options, Z_Options_negotiationModel);
213 p0->which = Z_OtherInfo_externallyDefinedInfo;
214 p0->information.externallyDefinedInfo =
215 yaz_set_proposal_charneg(out,
216 (const char**)&yazCharset, (yazCharset)?1:0,
217 (const char**)&yazLang, (yazLang)?1:0, 1);
222 printf("Sent initrequest.\n");
225 static int process_initResponse(Z_InitResponse *res)
227 /* save session parameters for later use */
228 session_mem = odr_extract_mem(in);
232 printf("Connection rejected by target.\n");
234 printf("Connection accepted by target.\n");
235 if (res->implementationId)
236 printf("ID : %s\n", res->implementationId);
237 if (res->implementationName)
238 printf("Name : %s\n", res->implementationName);
239 if (res->implementationVersion)
240 printf("Version: %s\n", res->implementationVersion);
241 if (res->userInformationField)
243 printf("UserInformationfield:\n");
244 if (!z_External(print, (Z_External**)&res-> userInformationField,
247 odr_perror(print, "Printing userinfo\n");
250 if (res->userInformationField->which == Z_External_octet)
252 printf("Guessing visiblestring:\n");
253 printf("'%s'\n", res->userInformationField->u. octet_aligned->buf);
258 if (ODR_MASK_GET(res->options, Z_Options_search))
260 if (ODR_MASK_GET(res->options, Z_Options_present))
262 if (ODR_MASK_GET(res->options, Z_Options_delSet))
264 if (ODR_MASK_GET(res->options, Z_Options_resourceReport))
265 printf (" resourceReport");
266 if (ODR_MASK_GET(res->options, Z_Options_resourceCtrl))
267 printf (" resourceCtrl");
268 if (ODR_MASK_GET(res->options, Z_Options_accessCtrl))
269 printf (" accessCtrl");
270 if (ODR_MASK_GET(res->options, Z_Options_scan))
272 if (ODR_MASK_GET(res->options, Z_Options_sort))
274 if (ODR_MASK_GET(res->options, Z_Options_extendedServices))
275 printf (" extendedServices");
276 if (ODR_MASK_GET(res->options, Z_Options_level_1Segmentation))
277 printf (" level1Segmentation");
278 if (ODR_MASK_GET(res->options, Z_Options_level_2Segmentation))
279 printf (" level2Segmentation");
280 if (ODR_MASK_GET(res->options, Z_Options_concurrentOperations))
281 printf (" concurrentOperations");
282 if (ODR_MASK_GET(res->options, Z_Options_namedResultSets))
284 printf (" namedResultSets");
287 if (ODR_MASK_GET(res->options, Z_Options_encapsulation))
288 printf (" encapsulation");
289 if (ODR_MASK_GET(res->options, Z_Options_resultCount))
290 printf (" resultCount");
291 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel))
292 printf (" negotiationModel");
293 if (ODR_MASK_GET(res->options, Z_Options_duplicateDetection))
294 printf (" duplicateDetection");
295 if (ODR_MASK_GET(res->options, Z_Options_queryType104))
296 printf (" queryType104");
299 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) {
301 Z_CharSetandLanguageNegotiation *p =
302 yaz_get_charneg_record(res->otherInfo);
306 char *charset=NULL, *lang=NULL;
309 yaz_get_response_charneg(session_mem, p, &charset, &lang, &selected);
311 printf("Accepted character set : `%s'\n", charset);
312 printf("Accepted code language : `%s'\n", lang);
313 printf("Accepted records in ...: %d\n", selected );
320 static int cmd_base(char *arg)
327 printf("Usage: base <database> <database> ...\n");
330 for (i = 0; i<num_databaseNames; i++)
331 xfree (databaseNames[i]);
332 num_databaseNames = 0;
335 if (!(cp = strchr(arg, ' ')))
336 cp = arg + strlen(arg);
339 databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
340 memcpy (databaseNames[num_databaseNames], arg, cp - arg);
341 databaseNames[num_databaseNames++][cp - arg] = '\0';
349 int cmd_open(char *arg)
352 char type_and_host[101], base[101];
357 printf("Already connected.\n");
363 nmem_destroy (session_mem);
369 if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1)
373 conn = cs_create_host(yazProxy, 1, &add);
375 conn = cs_create_host(type_and_host, 1, &add);
379 printf ("Couldn't create comstack\n");
382 printf("Connecting...");
384 if (cs_connect(conn, add) < 0)
386 printf ("error = %s\n", cs_strerror(conn));
387 if (conn->cerrno == CSYSERR)
395 send_initRequest(type_and_host);
401 int cmd_authentication(char *arg)
403 static Z_IdAuthentication au;
404 static char user[40], group[40], pass[40];
405 static Z_IdPass idPass;
410 printf("Auth field set to null\n");
414 r = sscanf (arg, "%39s %39s %39s", user, group, pass);
417 printf("Auth field set to null\n");
423 au.which = Z_IdAuthentication_open;
429 au.which = Z_IdAuthentication_idPass;
430 au.u.idPass = &idPass;
431 idPass.groupId = group;
432 idPass.userId = user;
433 idPass.password = pass;
438 /* SEARCH SERVICE ------------------------------ */
439 static void display_record(Z_External *r);
441 static void display_variant(Z_Variant *v, int level)
445 for (i = 0; i < v->num_triples; i++)
447 printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
448 *v->triples[i]->type);
449 if (v->triples[i]->which == Z_Triple_internationalString)
450 printf(",value=%s\n", v->triples[i]->value.internationalString);
456 static void display_grs1(Z_GenericRecord *r, int level)
464 for (i = 0; i < r->num_elements; i++)
468 printf("%*s", level * 4, "");
472 printf("%d,", *t->tagType);
475 if (t->tagValue->which == Z_StringOrNumeric_numeric)
476 printf("%d) ", *t->tagValue->u.numeric);
478 printf("%s) ", t->tagValue->u.string);
479 if (t->content->which == Z_ElementData_subtree)
481 if (!t->content->u.subtree)
482 printf (" (no subtree)\n");
486 display_grs1(t->content->u.subtree, level+1);
489 else if (t->content->which == Z_ElementData_string)
490 printf("%s\n", t->content->u.string);
491 else if (t->content->which == Z_ElementData_numeric)
492 printf("%d\n", *t->content->u.numeric);
493 else if (t->content->which == Z_ElementData_oid)
495 int *ip = t->content->u.oid;
498 if ((oent = oid_getentbyoid(t->content->u.oid)))
499 printf("OID: %s\n", oent->desc);
503 while (ip && *ip >= 0)
504 printf(" %d", *(ip++));
508 else if (t->content->which == Z_ElementData_noDataRequested)
509 printf("[No data requested]\n");
510 else if (t->content->which == Z_ElementData_elementEmpty)
511 printf("[Element empty]\n");
512 else if (t->content->which == Z_ElementData_elementNotThere)
513 printf("[Element not there]\n");
514 else if (t->content->which == Z_ElementData_date)
515 printf("Date: %s\n", t->content->u.date);
516 else if (t->content->which == Z_ElementData_ext)
518 printf ("External\n");
519 display_record (t->content->u.ext);
522 printf("? type = %d\n",t->content->which);
523 if (t->appliedVariant)
524 display_variant(t->appliedVariant, level+1);
525 if (t->metaData && t->metaData->supportedVariants)
529 printf("%*s---- variant list\n", (level+1)*4, "");
530 for (c = 0; c < t->metaData->num_supportedVariants; c++)
532 printf("%*svariant #%d\n", (level+1)*4, "", c);
533 display_variant(t->metaData->supportedVariants[c], level + 2);
540 static void print_record(const unsigned char *buf, size_t len)
543 print_stringn (buf, len);
544 /* add newline if not already added ... */
545 if (i <= 0 || buf[i-1] != '\n')
549 static void display_record(Z_External *r)
551 oident *ent = oid_getentbyoid(r->direct_reference);
555 * Tell the user what we got.
557 if (r->direct_reference)
559 printf("Record type: ");
561 printf("%s\n", ent->desc);
562 else if (!odr_oid(print, &r->direct_reference, 0, 0))
564 odr_perror(print, "print oid");
568 /* Check if this is a known, ASN.1 type tucked away in an octet string */
569 if (ent && r->which == Z_External_octet)
571 Z_ext_typeent *type = z_ext_getentbyref(ent->value);
577 * Call the given decoder to process the record.
579 odr_setbuf(in, (char*)r->u.octet_aligned->buf,
580 r->u.octet_aligned->len, 0);
581 if (!(*type->fun)(in, (char **)&rr, 0, 0))
583 odr_perror(in, "Decoding constructed record.");
584 fprintf(stderr, "[Near %d]\n", odr_offset(in));
585 fprintf(stderr, "Packet dump:\n---------\n");
586 odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf,
587 r->u.octet_aligned->len);
588 fprintf(stderr, "---------\n");
592 * Note: we throw away the original, BER-encoded record here.
593 * Do something else with it if you want to keep it.
595 r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
596 r->which = type->what;
599 if (ent && ent->oclass != CLASS_RECSYN)
601 if (ent && ent->value == VAL_SOIF)
602 print_record((const unsigned char *) r->u.octet_aligned->buf,
603 r->u.octet_aligned->len);
604 else if (r->which == Z_External_octet && r->u.octet_aligned->len)
606 const char *octet_buf = (char*)r->u.octet_aligned->buf;
607 if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML ||
608 ent->value == VAL_HTML)
610 print_record((const unsigned char *) octet_buf,
611 r->u.octet_aligned->len);
613 else if (ent->value == VAL_POSTSCRIPT)
615 int size = r->u.octet_aligned->len;
618 print_record((const unsigned char *) octet_buf, size);
623 #if AVOID_MARC_DECODE
624 /* primitive check for a marc OID 5.1-29 except 16 */
625 ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
626 ent->oidsuffix[1] != 16
632 if (marc_display_exl (octet_buf, NULL, 0 /* debug */,
633 r->u.octet_aligned->len) <= 0)
635 printf ("bad MARC. Dumping as it is:\n");
636 print_record((const unsigned char*) octet_buf,
637 r->u.octet_aligned->len);
642 print_record((const unsigned char*) octet_buf,
643 r->u.octet_aligned->len);
647 fwrite (octet_buf, 1, r->u.octet_aligned->len, marcdump);
649 else if (ent && ent->value == VAL_SUTRS)
651 if (r->which != Z_External_sutrs)
653 printf("Expecting single SUTRS type for SUTRS.\n");
656 print_record(r->u.sutrs->buf, r->u.sutrs->len);
658 else if (ent && ent->value == VAL_GRS1)
660 if (r->which != Z_External_grs1)
662 printf("Expecting single GRS type for GRS.\n");
665 display_grs1(r->u.grs1, 0);
669 printf("Unknown record representation.\n");
670 if (!z_External(print, &r, 0, 0))
672 odr_perror(print, "Printing external");
678 static void display_diagrecs(Z_DiagRec **pp, int num)
682 Z_DefaultDiagFormat *r;
684 printf("Diagnostic message(s) from database:\n");
685 for (i = 0; i<num; i++)
687 Z_DiagRec *p = pp[i];
688 if (p->which != Z_DiagRec_defaultFormat)
690 printf("Diagnostic record not in default format.\n");
694 r = p->u.defaultFormat;
695 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
696 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
697 printf("Missing or unknown diagset\n");
698 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
701 case Z_DefaultDiagFormat_v2Addinfo:
702 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
704 case Z_DefaultDiagFormat_v3Addinfo:
705 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
712 static void display_nameplusrecord(Z_NamePlusRecord *p)
715 printf("[%s]", p->databaseName);
716 if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
717 display_diagrecs(&p->u.surrogateDiagnostic, 1);
718 else if (p->which == Z_NamePlusRecord_databaseRecord)
719 display_record(p->u.databaseRecord);
722 static void display_records(Z_Records *p)
726 if (p->which == Z_Records_NSD)
728 Z_DiagRec dr, *dr_p = &dr;
729 dr.which = Z_DiagRec_defaultFormat;
730 dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
731 display_diagrecs (&dr_p, 1);
733 else if (p->which == Z_Records_multipleNSD)
734 display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
735 p->u.multipleNonSurDiagnostics->num_diagRecs);
738 printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
739 for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
740 display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
744 static int send_deleteResultSetRequest(char *arg)
749 Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
750 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
752 req->referenceId = set_refid (out);
754 req->num_resultSetList =
755 sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
756 names[0], names[1], names[2], names[3],
757 names[4], names[5], names[6], names[7]);
759 req->deleteFunction = (int *)
760 odr_malloc (out, sizeof(*req->deleteFunction));
761 if (req->num_resultSetList > 0)
763 *req->deleteFunction = Z_DeleteRequest_list;
764 req->resultSetList = (char **)
765 odr_malloc (out, sizeof(*req->resultSetList)*
766 req->num_resultSetList);
767 for (i = 0; i<req->num_resultSetList; i++)
768 req->resultSetList[i] = names[i];
772 *req->deleteFunction = Z_DeleteRequest_all;
773 req->resultSetList = 0;
777 printf("Sent deleteResultSetRequest.\n");
781 static int send_searchRequest(char *arg)
783 Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
784 Z_SearchRequest *req = apdu->u.searchRequest;
787 struct ccl_rpn_node *rpn = NULL;
790 Z_RPNQuery *RPNquery;
793 if (queryType == QueryType_CCL2RPN)
795 rpn = ccl_find_str(bibset, arg, &error, &pos);
798 printf("CCL ERROR: %s\n", ccl_err_msg(error));
802 req->referenceId = set_refid (out);
803 if (!strcmp(arg, "@big")) /* strictly for troublemaking */
805 static unsigned char big[2100];
808 /* send a very big referenceid to test transport stack etc. */
809 memset(big, 'A', 2100);
810 bigo.len = bigo.size = 2100;
812 req->referenceId = &bigo;
817 sprintf(setstring, "%d", ++setnumber);
818 req->resultSetName = setstring;
820 *req->smallSetUpperBound = smallSetUpperBound;
821 *req->largeSetLowerBound = largeSetLowerBound;
822 *req->mediumSetPresentNumber = mediumSetPresentNumber;
823 if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
824 mediumSetPresentNumber > 0))
828 prefsyn.proto = protocol;
829 prefsyn.oclass = CLASS_RECSYN;
830 prefsyn.value = recordsyntax;
831 req->preferredRecordSyntax =
832 odr_oiddup(out, oid_ent_to_oid(&prefsyn, oid));
833 req->smallSetElementSetNames =
834 req->mediumSetElementSetNames = elementSetNames;
836 req->num_databaseNames = num_databaseNames;
837 req->databaseNames = databaseNames;
843 case QueryType_Prefix:
844 query.which = Z_Query_type_1;
845 RPNquery = p_query_rpn (out, protocol, arg);
848 printf("Prefix query error\n");
851 query.u.type_1 = RPNquery;
854 query.which = Z_Query_type_2;
855 query.u.type_2 = &ccl_query;
856 ccl_query.buf = (unsigned char*) arg;
857 ccl_query.len = strlen(arg);
859 case QueryType_CCL2RPN:
860 query.which = Z_Query_type_1;
861 RPNquery = ccl_rpn_query(out, rpn);
864 printf ("Couldn't convert from CCL to RPN\n");
867 query.u.type_1 = RPNquery;
868 ccl_rpn_delete (rpn);
871 printf ("Unsupported query type\n");
876 printf("Sent searchRequest.\n");
880 /* display Query Expression as part of searchResult-1 */
881 static void display_queryExpression (Z_QueryExpression *qe)
885 if (qe->which == Z_QueryExpression_term)
887 if (qe->u.term->queryTerm)
889 Z_Term *term = qe->u.term->queryTerm;
890 if (term->which == Z_Term_general)
891 printf (" %.*s", term->u.general->len, term->u.general->buf);
897 /* see if we can find USR:SearchResult-1 */
898 static void display_searchResult (Z_OtherInformation *o)
903 for (i = 0; i < o->num_elements; i++)
905 if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
907 Z_External *ext = o->list[i]->information.externallyDefinedInfo;
909 if (ext->which == Z_External_searchResult1)
912 Z_SearchInfoReport *sr = ext->u.searchResult1;
913 printf ("SearchResult-1:");
914 for (j = 0; j < sr->num; j++)
916 if (!sr->elements[j]->subqueryExpression)
918 display_queryExpression (
919 sr->elements[j]->subqueryExpression);
920 display_queryExpression (
921 sr->elements[j]->subqueryInterpretation);
922 display_queryExpression (
923 sr->elements[j]->subqueryRecommendation);
924 if (sr->elements[j]->subqueryCount)
925 printf ("(%d)", *sr->elements[j]->subqueryCount);
933 static int process_searchResponse(Z_SearchResponse *res)
935 printf ("Received SearchResponse.\n");
936 print_refid (res->referenceId);
937 if (*res->searchStatus)
938 printf("Search was a success.\n");
940 printf("Search was a bloomin' failure.\n");
941 printf("Number of hits: %d", *res->resultCount);
943 printf (", setno %d", setnumber);
945 display_searchResult (res->additionalSearchInfo);
946 printf("records returned: %d\n",
947 *res->numberOfRecordsReturned);
948 setno += *res->numberOfRecordsReturned;
950 display_records(res->records);
954 static void print_level(int iLevel)
957 for (i = 0; i < iLevel * 4; i++)
961 static void print_int(int iLevel, const char *pTag, int *pInt)
966 printf("%s: %d\n", pTag, *pInt);
970 static void print_string(int iLevel, const char *pTag, const char *pString)
975 printf("%s: %s\n", pTag, pString);
979 static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
987 for (; *pInt != -1; pInt++)
988 printf(" %d", *pInt);
993 static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
995 if (referenceId != NULL)
1000 printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
1001 for (i = 0; i < referenceId->len; i++)
1002 printf("%c", referenceId->buf[i]);
1007 static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
1009 if (pStringNumeric != NULL)
1011 switch (pStringNumeric->which)
1013 case Z_StringOrNumeric_string:
1014 print_string(iLevel, pTag, pStringNumeric->u.string);
1017 case Z_StringOrNumeric_numeric:
1018 print_int(iLevel, pTag, pStringNumeric->u.numeric);
1022 print_level(iLevel);
1023 printf("%s: valid type for Z_StringOrNumeric\n", pTag);
1029 static void print_universe_report_duplicate(int iLevel, Z_UniverseReportDuplicate *pUniverseReportDuplicate)
1031 if (pUniverseReportDuplicate != NULL)
1033 print_level(iLevel);
1034 printf("Universe Report Duplicate: \n");
1036 print_string_or_numeric(iLevel, "Hit No",
1037 pUniverseReportDuplicate->hitno);
1042 print_universe_report_hits(int iLevel,
1043 Z_UniverseReportHits *pUniverseReportHits)
1045 if (pUniverseReportHits != NULL)
1047 print_level(iLevel);
1048 printf("Universe Report Hits: \n");
1050 print_string_or_numeric(iLevel, "Database",
1051 pUniverseReportHits->database);
1052 print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
1056 static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
1058 if (pUniverseReport != NULL)
1060 print_level(iLevel);
1061 printf("Universe Report: \n");
1063 print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
1064 switch (pUniverseReport->which)
1066 case Z_UniverseReport_databaseHits:
1067 print_universe_report_hits(iLevel, pUniverseReport->u.databaseHits);
1070 case Z_UniverseReport_duplicate:
1071 print_universe_report_duplicate(iLevel, pUniverseReport->u.duplicate);
1075 print_level(iLevel);
1076 printf("Type: %d\n", pUniverseReport->which);
1082 static void print_external(int iLevel, Z_External *pExternal)
1084 if (pExternal != NULL)
1086 print_level(iLevel);
1087 printf("External: \n");
1089 print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
1090 print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
1091 print_string(iLevel, "Descriptor", pExternal->descriptor);
1092 switch (pExternal->which)
1094 case Z_External_universeReport:
1095 print_universe_report(iLevel, pExternal->u.universeReport);
1099 print_level(iLevel);
1100 printf("Type: %d\n", pExternal->which);
1106 static int process_resourceControlRequest (Z_ResourceControlRequest *req)
1108 printf ("Received ResourceControlRequest.\n");
1109 print_referenceId(1, req->referenceId);
1110 print_int(1, "Suspended Flag", req->suspendedFlag);
1111 print_int(1, "Partial Results Available", req->partialResultsAvailable);
1112 print_int(1, "Response Required", req->responseRequired);
1113 print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
1114 print_external(1, req->resourceReport);
1118 void process_ESResponse(Z_ExtendedServicesResponse *res)
1121 switch (*res->operationStatus)
1123 case Z_ExtendedServicesResponse_done:
1126 case Z_ExtendedServicesResponse_accepted:
1127 printf ("accepted\n");
1129 case Z_ExtendedServicesResponse_failure:
1130 printf ("failure\n");
1131 display_diagrecs(res->diagnostics, res->num_diagnostics);
1134 printf ("unknown\n");
1136 if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
1137 (res->num_diagnostics != 0) ) {
1138 display_diagrecs(res->diagnostics, res->num_diagnostics);
1140 print_refid (res->referenceId);
1141 if (res->taskPackage &&
1142 res->taskPackage->which == Z_External_extendedService)
1144 Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1145 Odr_oct *id = taskPackage->targetReference;
1146 Z_External *ext = taskPackage->taskSpecificParameters;
1150 printf ("Target Reference: ");
1151 print_stringn (id->buf, id->len);
1154 if (ext->which == Z_External_update)
1156 Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
1157 if (utp && utp->targetPart)
1159 Z_IUTargetPart *targetPart = utp->targetPart;
1162 for (i = 0; i<targetPart->num_taskPackageRecords; i++)
1165 Z_IUTaskPackageRecordStructure *tpr =
1166 targetPart->taskPackageRecords[i];
1167 printf ("task package record %d\n", i+1);
1168 if (tpr->which == Z_IUTaskPackageRecordStructure_record)
1170 display_record (tpr->u.record);
1174 printf ("other type\n");
1182 const char *get_ill_element (void *clientData, const char *element)
1187 static Z_External *create_external_itemRequest()
1189 struct ill_get_ctl ctl;
1190 ILL_ItemRequest *req;
1192 int item_request_size = 0;
1193 char *item_request_buf = 0;
1197 ctl.f = get_ill_element;
1199 req = ill_get_ItemRequest(&ctl, "ill", 0);
1201 printf ("ill_get_ItemRequest failed\n");
1203 if (!ill_ItemRequest (out, &req, 0, 0))
1207 ill_ItemRequest(print, &req, 0, 0);
1210 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1211 if (item_request_buf)
1212 odr_setbuf (out, item_request_buf, item_request_size, 1);
1213 printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
1220 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1221 oid.proto = PROTO_GENERAL;
1222 oid.oclass = CLASS_GENERAL;
1223 oid.value = VAL_ISO_ILL_1;
1225 r = (Z_External *) odr_malloc (out, sizeof(*r));
1226 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1227 r->indirect_reference = 0;
1229 r->which = Z_External_single;
1231 r->u.single_ASN1_type = (Odr_oct *)
1232 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1233 r->u.single_ASN1_type->buf = (unsigned char *)
1234 odr_malloc (out, item_request_size);
1235 r->u.single_ASN1_type->len = item_request_size;
1236 r->u.single_ASN1_type->size = item_request_size;
1237 memcpy (r->u.single_ASN1_type->buf, item_request_buf,
1239 printf ("len = %d\n", item_request_size);
1244 static Z_External *create_external_ILL_APDU(int which)
1246 struct ill_get_ctl ctl;
1249 int ill_request_size = 0;
1250 char *ill_request_buf = 0;
1254 ctl.f = get_ill_element;
1256 ill_apdu = ill_get_APDU(&ctl, "ill", 0);
1258 if (!ill_APDU (out, &ill_apdu, 0, 0))
1262 printf ("-------------------\n");
1263 ill_APDU(print, &ill_apdu, 0, 0);
1265 printf ("-------------------\n");
1267 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1268 if (ill_request_buf)
1269 odr_setbuf (out, ill_request_buf, ill_request_size, 1);
1270 printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
1276 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1278 oid.proto = PROTO_GENERAL;
1279 oid.oclass = CLASS_GENERAL;
1280 oid.value = VAL_ISO_ILL_1;
1282 r = (Z_External *) odr_malloc (out, sizeof(*r));
1283 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1284 r->indirect_reference = 0;
1286 r->which = Z_External_single;
1288 r->u.single_ASN1_type = (Odr_oct *)
1289 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1290 r->u.single_ASN1_type->buf = (unsigned char *)
1291 odr_malloc (out, ill_request_size);
1292 r->u.single_ASN1_type->len = ill_request_size;
1293 r->u.single_ASN1_type->size = ill_request_size;
1294 memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
1295 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);