2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: client.c,v 1.155 2002-06-02 21:29:30 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>
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 ------------------------------ */
445 static void display_record(Z_External *r);
447 static void display_variant(Z_Variant *v, int level)
451 for (i = 0; i < v->num_triples; i++)
453 printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
454 *v->triples[i]->type);
455 if (v->triples[i]->which == Z_Triple_internationalString)
456 printf(",value=%s\n", v->triples[i]->value.internationalString);
462 static void display_grs1(Z_GenericRecord *r, int level)
470 for (i = 0; i < r->num_elements; i++)
474 printf("%*s", level * 4, "");
478 printf("%d,", *t->tagType);
481 if (t->tagValue->which == Z_StringOrNumeric_numeric)
482 printf("%d) ", *t->tagValue->u.numeric);
484 printf("%s) ", t->tagValue->u.string);
485 if (t->content->which == Z_ElementData_subtree)
487 if (!t->content->u.subtree)
488 printf (" (no subtree)\n");
492 display_grs1(t->content->u.subtree, level+1);
495 else if (t->content->which == Z_ElementData_string)
496 printf("%s\n", t->content->u.string);
497 else if (t->content->which == Z_ElementData_numeric)
498 printf("%d\n", *t->content->u.numeric);
499 else if (t->content->which == Z_ElementData_oid)
501 int *ip = t->content->u.oid;
504 if ((oent = oid_getentbyoid(t->content->u.oid)))
505 printf("OID: %s\n", oent->desc);
509 while (ip && *ip >= 0)
510 printf(" %d", *(ip++));
514 else if (t->content->which == Z_ElementData_noDataRequested)
515 printf("[No data requested]\n");
516 else if (t->content->which == Z_ElementData_elementEmpty)
517 printf("[Element empty]\n");
518 else if (t->content->which == Z_ElementData_elementNotThere)
519 printf("[Element not there]\n");
520 else if (t->content->which == Z_ElementData_date)
521 printf("Date: %s\n", t->content->u.date);
522 else if (t->content->which == Z_ElementData_ext)
524 printf ("External\n");
525 display_record (t->content->u.ext);
528 printf("? type = %d\n",t->content->which);
529 if (t->appliedVariant)
530 display_variant(t->appliedVariant, level+1);
531 if (t->metaData && t->metaData->supportedVariants)
535 printf("%*s---- variant list\n", (level+1)*4, "");
536 for (c = 0; c < t->metaData->num_supportedVariants; c++)
538 printf("%*svariant #%d\n", (level+1)*4, "", c);
539 display_variant(t->metaData->supportedVariants[c], level + 2);
546 static void print_record(const unsigned char *buf, size_t len)
549 print_stringn (buf, len);
550 /* add newline if not already added ... */
551 if (i <= 0 || buf[i-1] != '\n')
555 static void display_record(Z_External *r)
557 oident *ent = oid_getentbyoid(r->direct_reference);
561 * Tell the user what we got.
563 if (r->direct_reference)
565 printf("Record type: ");
567 printf("%s\n", ent->desc);
568 else if (!odr_oid(print, &r->direct_reference, 0, 0))
570 odr_perror(print, "print oid");
574 /* Check if this is a known, ASN.1 type tucked away in an octet string */
575 if (ent && r->which == Z_External_octet)
577 Z_ext_typeent *type = z_ext_getentbyref(ent->value);
583 * Call the given decoder to process the record.
585 odr_setbuf(in, (char*)r->u.octet_aligned->buf,
586 r->u.octet_aligned->len, 0);
587 if (!(*type->fun)(in, (char **)&rr, 0, 0))
589 odr_perror(in, "Decoding constructed record.");
590 fprintf(stderr, "[Near %d]\n", odr_offset(in));
591 fprintf(stderr, "Packet dump:\n---------\n");
592 odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf,
593 r->u.octet_aligned->len);
594 fprintf(stderr, "---------\n");
598 * Note: we throw away the original, BER-encoded record here.
599 * Do something else with it if you want to keep it.
601 r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
602 r->which = type->what;
605 if (ent && ent->oclass != CLASS_RECSYN)
607 if (ent && ent->value == VAL_SOIF)
608 print_record((const unsigned char *) r->u.octet_aligned->buf,
609 r->u.octet_aligned->len);
610 else if (r->which == Z_External_octet && r->u.octet_aligned->len)
612 const char *octet_buf = (char*)r->u.octet_aligned->buf;
613 if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML ||
614 ent->value == VAL_HTML)
616 print_record((const unsigned char *) octet_buf,
617 r->u.octet_aligned->len);
619 else if (ent->value == VAL_POSTSCRIPT)
621 int size = r->u.octet_aligned->len;
624 print_record((const unsigned char *) octet_buf, size);
629 #if AVOID_MARC_DECODE
630 /* primitive check for a marc OID 5.1-29 except 16 */
631 ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
632 ent->oidsuffix[1] != 16
638 if (marc_display_exl (octet_buf, NULL, 0 /* debug */,
639 r->u.octet_aligned->len) <= 0)
641 printf ("bad MARC. Dumping as it is:\n");
642 print_record((const unsigned char*) octet_buf,
643 r->u.octet_aligned->len);
648 print_record((const unsigned char*) octet_buf,
649 r->u.octet_aligned->len);
653 fwrite (octet_buf, 1, r->u.octet_aligned->len, marcdump);
655 else if (ent && ent->value == VAL_SUTRS)
657 if (r->which != Z_External_sutrs)
659 printf("Expecting single SUTRS type for SUTRS.\n");
662 print_record(r->u.sutrs->buf, r->u.sutrs->len);
664 else if (ent && ent->value == VAL_GRS1)
666 if (r->which != Z_External_grs1)
668 printf("Expecting single GRS type for GRS.\n");
671 display_grs1(r->u.grs1, 0);
675 printf("Unknown record representation.\n");
676 if (!z_External(print, &r, 0, 0))
678 odr_perror(print, "Printing external");
684 static void display_diagrecs(Z_DiagRec **pp, int num)
688 Z_DefaultDiagFormat *r;
690 printf("Diagnostic message(s) from database:\n");
691 for (i = 0; i<num; i++)
693 Z_DiagRec *p = pp[i];
694 if (p->which != Z_DiagRec_defaultFormat)
696 printf("Diagnostic record not in default format.\n");
700 r = p->u.defaultFormat;
701 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
702 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
703 printf("Missing or unknown diagset\n");
704 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
707 case Z_DefaultDiagFormat_v2Addinfo:
708 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
710 case Z_DefaultDiagFormat_v3Addinfo:
711 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
718 static void display_nameplusrecord(Z_NamePlusRecord *p)
721 printf("[%s]", p->databaseName);
722 if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
723 display_diagrecs(&p->u.surrogateDiagnostic, 1);
724 else if (p->which == Z_NamePlusRecord_databaseRecord)
725 display_record(p->u.databaseRecord);
728 static void display_records(Z_Records *p)
732 if (p->which == Z_Records_NSD)
734 Z_DiagRec dr, *dr_p = &dr;
735 dr.which = Z_DiagRec_defaultFormat;
736 dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
737 display_diagrecs (&dr_p, 1);
739 else if (p->which == Z_Records_multipleNSD)
740 display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
741 p->u.multipleNonSurDiagnostics->num_diagRecs);
744 printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
745 for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
746 display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
750 static int send_deleteResultSetRequest(char *arg)
755 Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
756 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
758 req->referenceId = set_refid (out);
760 req->num_resultSetList =
761 sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
762 names[0], names[1], names[2], names[3],
763 names[4], names[5], names[6], names[7]);
765 req->deleteFunction = (int *)
766 odr_malloc (out, sizeof(*req->deleteFunction));
767 if (req->num_resultSetList > 0)
769 *req->deleteFunction = Z_DeleteRequest_list;
770 req->resultSetList = (char **)
771 odr_malloc (out, sizeof(*req->resultSetList)*
772 req->num_resultSetList);
773 for (i = 0; i<req->num_resultSetList; i++)
774 req->resultSetList[i] = names[i];
778 *req->deleteFunction = Z_DeleteRequest_all;
779 req->resultSetList = 0;
783 printf("Sent deleteResultSetRequest.\n");
787 static int send_searchRequest(char *arg)
789 Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
790 Z_SearchRequest *req = apdu->u.searchRequest;
794 struct ccl_rpn_node *rpn = NULL;
798 Z_RPNQuery *RPNquery;
802 if (queryType == QueryType_CCL2RPN)
804 rpn = ccl_find_str(bibset, arg, &error, &pos);
807 printf("CCL ERROR: %s\n", ccl_err_msg(error));
812 req->referenceId = set_refid (out);
813 if (!strcmp(arg, "@big")) /* strictly for troublemaking */
815 static unsigned char big[2100];
818 /* send a very big referenceid to test transport stack etc. */
819 memset(big, 'A', 2100);
820 bigo.len = bigo.size = 2100;
822 req->referenceId = &bigo;
827 sprintf(setstring, "%d", ++setnumber);
828 req->resultSetName = setstring;
830 *req->smallSetUpperBound = smallSetUpperBound;
831 *req->largeSetLowerBound = largeSetLowerBound;
832 *req->mediumSetPresentNumber = mediumSetPresentNumber;
833 if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
834 mediumSetPresentNumber > 0))
838 prefsyn.proto = protocol;
839 prefsyn.oclass = CLASS_RECSYN;
840 prefsyn.value = recordsyntax;
841 req->preferredRecordSyntax =
842 odr_oiddup(out, oid_ent_to_oid(&prefsyn, oid));
843 req->smallSetElementSetNames =
844 req->mediumSetElementSetNames = elementSetNames;
846 req->num_databaseNames = num_databaseNames;
847 req->databaseNames = databaseNames;
853 case QueryType_Prefix:
854 query.which = Z_Query_type_1;
855 RPNquery = p_query_rpn (out, protocol, arg);
858 printf("Prefix query error\n");
861 query.u.type_1 = RPNquery;
864 query.which = Z_Query_type_2;
865 query.u.type_2 = &ccl_query;
866 ccl_query.buf = (unsigned char*) arg;
867 ccl_query.len = strlen(arg);
870 case QueryType_CCL2RPN:
871 query.which = Z_Query_type_1;
872 RPNquery = ccl_rpn_query(out, rpn);
875 printf ("Couldn't convert from CCL to RPN\n");
878 query.u.type_1 = RPNquery;
879 ccl_rpn_delete (rpn);
883 printf ("Unsupported query type\n");
888 printf("Sent searchRequest.\n");
892 /* display Query Expression as part of searchResult-1 */
893 static void display_queryExpression (Z_QueryExpression *qe)
897 if (qe->which == Z_QueryExpression_term)
899 if (qe->u.term->queryTerm)
901 Z_Term *term = qe->u.term->queryTerm;
902 if (term->which == Z_Term_general)
903 printf (" %.*s", term->u.general->len, term->u.general->buf);
909 /* see if we can find USR:SearchResult-1 */
910 static void display_searchResult (Z_OtherInformation *o)
915 for (i = 0; i < o->num_elements; i++)
917 if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
919 Z_External *ext = o->list[i]->information.externallyDefinedInfo;
921 if (ext->which == Z_External_searchResult1)
924 Z_SearchInfoReport *sr = ext->u.searchResult1;
925 printf ("SearchResult-1:");
926 for (j = 0; j < sr->num; j++)
928 if (!sr->elements[j]->subqueryExpression)
930 display_queryExpression (
931 sr->elements[j]->subqueryExpression);
932 display_queryExpression (
933 sr->elements[j]->subqueryInterpretation);
934 display_queryExpression (
935 sr->elements[j]->subqueryRecommendation);
936 if (sr->elements[j]->subqueryCount)
937 printf ("(%d)", *sr->elements[j]->subqueryCount);
945 static int process_searchResponse(Z_SearchResponse *res)
947 printf ("Received SearchResponse.\n");
948 print_refid (res->referenceId);
949 if (*res->searchStatus)
950 printf("Search was a success.\n");
952 printf("Search was a bloomin' failure.\n");
953 printf("Number of hits: %d", *res->resultCount);
955 printf (", setno %d", setnumber);
957 display_searchResult (res->additionalSearchInfo);
958 printf("records returned: %d\n",
959 *res->numberOfRecordsReturned);
960 setno += *res->numberOfRecordsReturned;
962 display_records(res->records);
966 static void print_level(int iLevel)
969 for (i = 0; i < iLevel * 4; i++)
973 static void print_int(int iLevel, const char *pTag, int *pInt)
978 printf("%s: %d\n", pTag, *pInt);
982 static void print_string(int iLevel, const char *pTag, const char *pString)
987 printf("%s: %s\n", pTag, pString);
991 static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
999 for (; *pInt != -1; pInt++)
1000 printf(" %d", *pInt);
1005 static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
1007 if (referenceId != NULL)
1011 print_level(iLevel);
1012 printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
1013 for (i = 0; i < referenceId->len; i++)
1014 printf("%c", referenceId->buf[i]);
1019 static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
1021 if (pStringNumeric != NULL)
1023 switch (pStringNumeric->which)
1025 case Z_StringOrNumeric_string:
1026 print_string(iLevel, pTag, pStringNumeric->u.string);
1029 case Z_StringOrNumeric_numeric:
1030 print_int(iLevel, pTag, pStringNumeric->u.numeric);
1034 print_level(iLevel);
1035 printf("%s: valid type for Z_StringOrNumeric\n", pTag);
1041 static void print_universe_report_duplicate(int iLevel, Z_UniverseReportDuplicate *pUniverseReportDuplicate)
1043 if (pUniverseReportDuplicate != NULL)
1045 print_level(iLevel);
1046 printf("Universe Report Duplicate: \n");
1048 print_string_or_numeric(iLevel, "Hit No",
1049 pUniverseReportDuplicate->hitno);
1054 print_universe_report_hits(int iLevel,
1055 Z_UniverseReportHits *pUniverseReportHits)
1057 if (pUniverseReportHits != NULL)
1059 print_level(iLevel);
1060 printf("Universe Report Hits: \n");
1062 print_string_or_numeric(iLevel, "Database",
1063 pUniverseReportHits->database);
1064 print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
1068 static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
1070 if (pUniverseReport != NULL)
1072 print_level(iLevel);
1073 printf("Universe Report: \n");
1075 print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
1076 switch (pUniverseReport->which)
1078 case Z_UniverseReport_databaseHits:
1079 print_universe_report_hits(iLevel, pUniverseReport->u.databaseHits);
1082 case Z_UniverseReport_duplicate:
1083 print_universe_report_duplicate(iLevel, pUniverseReport->u.duplicate);
1087 print_level(iLevel);
1088 printf("Type: %d\n", pUniverseReport->which);
1094 static void print_external(int iLevel, Z_External *pExternal)
1096 if (pExternal != NULL)
1098 print_level(iLevel);
1099 printf("External: \n");
1101 print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
1102 print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
1103 print_string(iLevel, "Descriptor", pExternal->descriptor);
1104 switch (pExternal->which)
1106 case Z_External_universeReport:
1107 print_universe_report(iLevel, pExternal->u.universeReport);
1111 print_level(iLevel);
1112 printf("Type: %d\n", pExternal->which);
1118 static int process_resourceControlRequest (Z_ResourceControlRequest *req)
1120 printf ("Received ResourceControlRequest.\n");
1121 print_referenceId(1, req->referenceId);
1122 print_int(1, "Suspended Flag", req->suspendedFlag);
1123 print_int(1, "Partial Results Available", req->partialResultsAvailable);
1124 print_int(1, "Response Required", req->responseRequired);
1125 print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
1126 print_external(1, req->resourceReport);
1130 void process_ESResponse(Z_ExtendedServicesResponse *res)
1133 switch (*res->operationStatus)
1135 case Z_ExtendedServicesResponse_done:
1138 case Z_ExtendedServicesResponse_accepted:
1139 printf ("accepted\n");
1141 case Z_ExtendedServicesResponse_failure:
1142 printf ("failure\n");
1143 display_diagrecs(res->diagnostics, res->num_diagnostics);
1146 printf ("unknown\n");
1148 if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
1149 (res->num_diagnostics != 0) ) {
1150 display_diagrecs(res->diagnostics, res->num_diagnostics);
1152 print_refid (res->referenceId);
1153 if (res->taskPackage &&
1154 res->taskPackage->which == Z_External_extendedService)
1156 Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1157 Odr_oct *id = taskPackage->targetReference;
1158 Z_External *ext = taskPackage->taskSpecificParameters;
1162 printf ("Target Reference: ");
1163 print_stringn (id->buf, id->len);
1166 if (ext->which == Z_External_update)
1168 Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
1169 if (utp && utp->targetPart)
1171 Z_IUTargetPart *targetPart = utp->targetPart;
1174 for (i = 0; i<targetPart->num_taskPackageRecords; i++)
1177 Z_IUTaskPackageRecordStructure *tpr =
1178 targetPart->taskPackageRecords[i];
1179 printf ("task package record %d\n", i+1);
1180 if (tpr->which == Z_IUTaskPackageRecordStructure_record)
1182 display_record (tpr->u.record);
1186 printf ("other type\n");
1196 const char *get_ill_element (void *clientData, const char *element)
1201 static Z_External *create_external_itemRequest()
1203 struct ill_get_ctl ctl;
1204 ILL_ItemRequest *req;
1206 int item_request_size = 0;
1207 char *item_request_buf = 0;
1211 ctl.f = get_ill_element;
1213 req = ill_get_ItemRequest(&ctl, "ill", 0);
1215 printf ("ill_get_ItemRequest failed\n");
1217 if (!ill_ItemRequest (out, &req, 0, 0))
1221 ill_ItemRequest(print, &req, 0, 0);
1224 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1225 if (item_request_buf)
1226 odr_setbuf (out, item_request_buf, item_request_size, 1);
1227 printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
1234 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1235 oid.proto = PROTO_GENERAL;
1236 oid.oclass = CLASS_GENERAL;
1237 oid.value = VAL_ISO_ILL_1;
1239 r = (Z_External *) odr_malloc (out, sizeof(*r));
1240 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1241 r->indirect_reference = 0;
1243 r->which = Z_External_single;
1245 r->u.single_ASN1_type = (Odr_oct *)
1246 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1247 r->u.single_ASN1_type->buf = (unsigned char *)
1248 odr_malloc (out, item_request_size);
1249 r->u.single_ASN1_type->len = item_request_size;
1250 r->u.single_ASN1_type->size = item_request_size;
1251 memcpy (r->u.single_ASN1_type->buf, item_request_buf,
1253 printf ("len = %d\n", item_request_size);
1259 #ifdef YAZ_MODULE_ill
1260 static Z_External *create_external_ILL_APDU(int which)
1262 struct ill_get_ctl ctl;
1265 int ill_request_size = 0;
1266 char *ill_request_buf = 0;
1270 ctl.f = get_ill_element;
1272 ill_apdu = ill_get_APDU(&ctl, "ill", 0);
1274 if (!ill_APDU (out, &ill_apdu, 0, 0))
1278 printf ("-------------------\n");
1279 ill_APDU(print, &ill_apdu, 0, 0);
1281 printf ("-------------------\n");
1283 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1284 if (ill_request_buf)
1285 odr_setbuf (out, ill_request_buf, ill_request_size, 1);
1286 printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
1292 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1294 oid.proto = PROTO_GENERAL;
1295 oid.oclass = CLASS_GENERAL;
1296 oid.value = VAL_ISO_ILL_1;
1298 r = (Z_External *) odr_malloc (out, sizeof(*r));
1299 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1300 r->indirect_reference = 0;
1302 r->which = Z_External_single;
1304 r->u.single_ASN1_type = (Odr_oct *)
1305 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1306 r->u.single_ASN1_type->buf = (unsigned char *)
1307 odr_malloc (out, ill_request_size);
1308 r->u.single_ASN1_type->len = ill_request_size;
1309 r->u.single_ASN1_type->size = ill_request_size;
1310 memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
1311 printf ("len = %d\n", ill_request_size);
1318 static Z_External *create_ItemOrderExternal(const char *type, int itemno)
1320 Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
1321 oident ItemOrderRequest;
1323 ItemOrderRequest.proto = PROTO_Z3950;
1324 ItemOrderRequest.oclass = CLASS_EXTSERV;
1325 ItemOrderRequest.value = VAL_ITEMORDER;
1327 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1328 r->indirect_reference = 0;
1331 r->which = Z_External_itemOrder;
1333 r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder));
1334 memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder));
1335 r->u.itemOrder->which=Z_IOItemOrder_esRequest;
1337 r->u.itemOrder->u.esRequest = (Z_IORequest *)
1338 odr_malloc(out,sizeof(Z_IORequest));
1339 memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest));
1341 r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
1342 odr_malloc(out,sizeof(Z_IOOriginPartToKeep));
1343 memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep));
1344 r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
1345 odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep));
1346 memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep));
1348 r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL;
1349 r->u.itemOrder->u.esRequest->toKeep->contact = NULL;
1350 r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL;
1352 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem =
1353 (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem));
1354 memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem));
1355 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1";
1357 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item =
1358 (int *) odr_malloc(out, sizeof(int));
1359 *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
1362 if (!strcmp (type, "item") || !strcmp(type, "2"))
1364 printf ("using item-request\n");
1365 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1366 create_external_itemRequest();
1368 else if (!strcmp(type, "ill") || !strcmp(type, "1"))
1370 printf ("using ILL-request\n");
1371 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1372 create_external_ILL_APDU(ILL_APDU_ILL_Request);
1374 else if (!strcmp(type, "xml") || !strcmp(type, "3"))
1376 const char *xml_buf =
1378 " <type>request</type>\n"
1379 " <libraryNo>000200</libraryNo>\n"
1380 " <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
1382 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1383 z_ext_record (out, VAL_TEXT_XML, xml_buf, strlen(xml_buf));
1386 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1389 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1394 static int send_itemorder(const char *type, int itemno)
1396 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
1397 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1398 oident ItemOrderRequest;
1400 ItemOrderRequest.proto = PROTO_Z3950;
1401 ItemOrderRequest.oclass = CLASS_EXTSERV;
1402 ItemOrderRequest.value = VAL_ITEMORDER;
1403 req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1404 req->packageName = esPackageName;
1406 req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
1412 static int cmd_update(char *arg)
1414 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
1415 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1418 Z_IUOriginPartToKeep *toKeep;
1419 Z_IUSuppliedRecords *notToKeep;
1421 printf ("Update request\n");
1426 update_oid.proto = PROTO_Z3950;
1427 update_oid.oclass = CLASS_EXTSERV;
1428 update_oid.value = VAL_DBUPDATE;
1429 oid_ent_to_oid (&update_oid, oid);
1430 req->packageType = odr_oiddup(out,oid);
1431 req->packageName = esPackageName;
1433 req->referenceId = set_refid (out);
1435 r = req->taskSpecificParameters = (Z_External *)
1436 odr_malloc (out, sizeof(*r));
1437 r->direct_reference = odr_oiddup(out,oid);
1438 r->indirect_reference = 0;
1440 r->which = Z_External_update;
1441 r->u.update = (Z_IUUpdate *) odr_malloc(out, sizeof(*r->u.update));
1442 r->u.update->which = Z_IUUpdate_esRequest;
1443 r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
1444 odr_malloc(out, sizeof(*r->u.update->u.esRequest));
1445 toKeep = r->u.update->u.esRequest->toKeep = (Z_IUOriginPartToKeep *)
1446 odr_malloc(out, sizeof(*r->u.update->u.esRequest->toKeep));
1447 toKeep->databaseName = databaseNames[0];
1449 toKeep->elementSetName = 0;
1450 toKeep->actionQualifier = 0;
1451 toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
1452 *toKeep->action = Z_IUOriginPartToKeep_recordInsert;
1454 notToKeep = r->u.update->u.esRequest->notToKeep = (Z_IUSuppliedRecords *)
1455 odr_malloc(out, sizeof(*r->u.update->u.esRequest->notToKeep));
1457 notToKeep->elements = (Z_IUSuppliedRecords_elem **)
1458 odr_malloc(out, sizeof(*notToKeep->elements));
1459 notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
1460 odr_malloc(out, sizeof(**notToKeep->elements));
1461 notToKeep->elements[0]->u.number = 0;
1462 notToKeep->elements[0]->supplementalId = 0;
1463 notToKeep->elements[0]->correlationInfo = 0;
1464 notToKeep->elements[0]->record = record_last;
1471 static int cmd_itemorder(char *arg)
1476 if (sscanf (arg, "%10s %d", type, &itemno) != 2)
1479 printf("Item order request\n");
1481 send_itemorder(type, itemno);
1485 static int cmd_find(char *arg)
1489 printf("Find what?\n");
1494 printf("Not connected yet\n");
1497 if (!send_searchRequest(arg))
1502 static int cmd_delete(char *arg)
1506 printf("Not connected yet\n");
1509 if (!send_deleteResultSetRequest(arg))
1514 static int cmd_ssub(char *arg)
1516 if (!(smallSetUpperBound = atoi(arg)))
1521 static int cmd_lslb(char *arg)
1523 if (!(largeSetLowerBound = atoi(arg)))
1528 static int cmd_mspn(char *arg)
1530 if (!(mediumSetPresentNumber = atoi(arg)))
1535 static int cmd_status(char *arg)
1537 printf("smallSetUpperBound: %d\n", smallSetUpperBound);
1538 printf("largeSetLowerBound: %d\n", largeSetLowerBound);
1539 printf("mediumSetPresentNumber: %d\n", mediumSetPresentNumber);
1543 static int cmd_setnames(char *arg)
1545 if (*arg == '1') /* enable ? */
1547 else if (*arg == '0') /* disable ? */
1549 else if (setnumber < 0) /* no args, toggle .. */
1555 printf("Set numbering enabled.\n");
1557 printf("Set numbering disabled.\n");
1561 /* PRESENT SERVICE ----------------------------- */
1563 static int send_presentRequest(char *arg)
1565 Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
1566 Z_PresentRequest *req = apdu->u.presentRequest;
1567 Z_RecordComposition compo;
1572 char setstring[100];
1574 req->referenceId = set_refid (out);
1575 if ((p = strchr(arg, '+')))
1582 if (p && (p=strchr(p+1, '+')))
1584 strcpy (setstring, p+1);
1585 req->resultSetId = setstring;
1587 else if (setnumber >= 0)
1589 sprintf(setstring, "%d", setnumber);
1590 req->resultSetId = setstring;
1592 req->resultSetStartPoint = &setno;
1593 req->numberOfRecordsRequested = &nos;
1594 prefsyn.proto = protocol;
1595 prefsyn.oclass = CLASS_RECSYN;
1596 prefsyn.value = recordsyntax;
1597 req->preferredRecordSyntax =
1598 odr_oiddup (out, oid_ent_to_oid(&prefsyn, oid));
1600 if (schema != VAL_NONE)
1604 prefschema.proto = protocol;
1605 prefschema.oclass = CLASS_SCHEMA;
1606 prefschema.value = schema;
1608 req->recordComposition = &compo;
1609 compo.which = Z_RecordComp_complex;
1610 compo.u.complex = (Z_CompSpec *)
1611 odr_malloc(out, sizeof(*compo.u.complex));
1612 compo.u.complex->selectAlternativeSyntax = (bool_t *)
1613 odr_malloc(out, sizeof(bool_t));
1614 *compo.u.complex->selectAlternativeSyntax = 0;
1616 compo.u.complex->generic = (Z_Specification *)
1617 odr_malloc(out, sizeof(*compo.u.complex->generic));
1618 compo.u.complex->generic->schema = (Odr_oid *)
1619 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1620 if (!compo.u.complex->generic->schema)
1622 /* OID wasn't a schema! Try record syntax instead. */
1623 prefschema.oclass = CLASS_RECSYN;
1624 compo.u.complex->generic->schema = (Odr_oid *)
1625 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1627 if (!elementSetNames)
1628 compo.u.complex->generic->elementSpec = 0;
1631 compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
1632 odr_malloc(out, sizeof(Z_ElementSpec));
1633 compo.u.complex->generic->elementSpec->which =
1634 Z_ElementSpec_elementSetName;
1635 compo.u.complex->generic->elementSpec->u.elementSetName =
1636 elementSetNames->u.generic;
1638 compo.u.complex->num_dbSpecific = 0;
1639 compo.u.complex->dbSpecific = 0;
1640 compo.u.complex->num_recordSyntax = 0;
1641 compo.u.complex->recordSyntax = 0;
1643 else if (elementSetNames)
1645 req->recordComposition = &compo;
1646 compo.which = Z_RecordComp_simple;
1647 compo.u.simple = elementSetNames;
1650 printf("Sent presentRequest (%d+%d).\n", setno, nos);
1654 static void close_session (void)
1660 nmem_destroy (session_mem);
1666 void process_close(Z_Close *req)
1668 Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
1669 Z_Close *res = apdu->u.close;
1671 static char *reasons[] =
1676 "cost limit reached",
1678 "security violation",
1685 printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
1686 req->diagnosticInformation ? req->diagnosticInformation : "NULL");
1691 *res->closeReason = Z_Close_finished;
1693 printf("Sent response.\n");
1698 static int cmd_show(char *arg)
1702 printf("Not connected yet\n");
1705 if (!send_presentRequest(arg))
1710 int cmd_quit(char *arg)
1712 printf("See you later, alligator.\n");
1718 int cmd_cancel(char *arg)
1720 Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
1721 Z_TriggerResourceControlRequest *req =
1722 apdu->u.triggerResourceControlRequest;
1727 printf("Session not initialized yet\n");
1730 if (!ODR_MASK_GET(session->options, Z_Options_triggerResourceCtrl))
1732 printf("Target doesn't support cancel (trigger resource ctrl)\n");
1735 *req->requestedAction = Z_TriggerResourceCtrl_cancel;
1736 req->resultSetWanted = &rfalse;
1739 printf("Sent cancel request\n");
1743 int send_scanrequest(const char *query, int pp, int num, const char *term)
1745 Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
1746 Z_ScanRequest *req = apdu->u.scanRequest;
1751 if (queryType == QueryType_CCL2RPN)
1755 struct ccl_rpn_node *rpn;
1757 rpn = ccl_find_str (bibset, query, &error, &pos);
1760 printf("CCL ERROR: %s\n", ccl_err_msg(error));
1764 bib1.proto = PROTO_Z3950;
1765 bib1.oclass = CLASS_ATTSET;
1766 bib1.value = VAL_BIB1;
1767 req->attributeSet = oid_ent_to_oid (&bib1, oid);
1768 if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
1770 printf("Couldn't convert CCL to Scan term\n");
1773 ccl_rpn_delete (rpn);
1776 if (use_rpn && !(req->termListAndStartPoint =
1777 p_query_scan(out, protocol, &req->attributeSet, query)))
1779 printf("Prefix query error\n");
1784 if (req->termListAndStartPoint->term &&
1785 req->termListAndStartPoint->term->which == Z_Term_general &&
1786 req->termListAndStartPoint->term->u.general)
1788 req->termListAndStartPoint->term->u.general->buf =
1789 (unsigned char *) odr_strdup(out, term);
1790 req->termListAndStartPoint->term->u.general->len =
1791 req->termListAndStartPoint->term->u.general->size =
1795 req->referenceId = set_refid (out);
1796 req->num_databaseNames = num_databaseNames;
1797 req->databaseNames = databaseNames;
1798 req->numberOfTermsRequested = #
1799 req->preferredPositionInResponse = &pp;
1804 int send_sortrequest(char *arg, int newset)
1806 Z_APDU *apdu = zget_APDU(out, Z_APDU_sortRequest);
1807 Z_SortRequest *req = apdu->u.sortRequest;
1808 Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
1809 odr_malloc (out, sizeof(*sksl));
1813 sprintf (setstring, "%d", setnumber);
1815 sprintf (setstring, "default");
1817 req->referenceId = set_refid (out);
1819 req->num_inputResultSetNames = 1;
1820 req->inputResultSetNames = (Z_InternationalString **)
1821 odr_malloc (out, sizeof(*req->inputResultSetNames));
1822 req->inputResultSetNames[0] = odr_strdup (out, setstring);
1824 if (newset && setnumber >= 0)
1825 sprintf (setstring, "%d", ++setnumber);
1827 req->sortedResultSetName = odr_strdup (out, setstring);
1829 req->sortSequence = yaz_sort_spec (out, arg);
1830 if (!req->sortSequence)
1832 printf ("Missing sort specifications\n");
1839 void display_term(Z_TermInfo *t)
1841 if (t->term->which == Z_Term_general)
1843 printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
1844 sprintf(last_scan_line, "%.*s", t->term->u.general->len,
1845 t->term->u.general->buf);
1848 printf("Term (not general)");
1849 if (t->globalOccurrences)
1850 printf (" (%d)\n", *t->globalOccurrences);
1855 void process_scanResponse(Z_ScanResponse *res)
1858 Z_Entry **entries = NULL;
1859 int num_entries = 0;
1861 printf("Received ScanResponse\n");
1862 print_refid (res->referenceId);
1863 printf("%d entries", *res->numberOfEntriesReturned);
1864 if (res->positionOfTerm)
1865 printf (", position=%d", *res->positionOfTerm);
1867 if (*res->scanStatus != Z_Scan_success)
1868 printf("Scan returned code %d\n", *res->scanStatus);
1871 if ((entries = res->entries->entries))
1872 num_entries = res->entries->num_entries;
1873 for (i = 0; i < num_entries; i++)
1875 int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
1876 if (entries[i]->which == Z_Entry_termInfo)
1878 printf("%c ", i + 1 == pos_term ? '*' : ' ');
1879 display_term(entries[i]->u.termInfo);
1882 display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1);
1884 if (res->entries->nonsurrogateDiagnostics)
1885 display_diagrecs (res->entries->nonsurrogateDiagnostics,
1886 res->entries->num_nonsurrogateDiagnostics);
1889 void process_sortResponse(Z_SortResponse *res)
1891 printf("Received SortResponse: status=");
1892 switch (*res->sortStatus)
1894 case Z_SortStatus_success:
1895 printf ("success"); break;
1896 case Z_SortStatus_partial_1:
1897 printf ("partial"); break;
1898 case Z_SortStatus_failure:
1899 printf ("failure"); break;
1901 printf ("unknown (%d)", *res->sortStatus);
1904 print_refid (res->referenceId);
1905 if (res->diagnostics)
1906 display_diagrecs(res->diagnostics,
1907 res->num_diagnostics);
1910 void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res)
1912 printf("Got deleteResultSetResponse status=%d\n",
1913 *res->deleteOperationStatus);
1914 if (res->deleteListStatuses)
1917 for (i = 0; i < res->deleteListStatuses->num; i++)
1919 printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id,
1920 *res->deleteListStatuses->elements[i]->status);
1925 int cmd_sort_generic(char *arg, int newset)
1929 printf("Session not initialized yet\n");
1932 if (!ODR_MASK_GET(session->options, Z_Options_sort))
1934 printf("Target doesn't support sort\n");
1939 if (send_sortrequest(arg, newset) < 0)
1946 int cmd_sort(char *arg)
1948 return cmd_sort_generic (arg, 0);
1951 int cmd_sort_newset (char *arg)
1953 return cmd_sort_generic (arg, 1);
1956 int cmd_scan(char *arg)
1960 printf("Session not initialized yet\n");
1963 if (!ODR_MASK_GET(session->options, Z_Options_scan))
1965 printf("Target doesn't support scan\n");
1970 strcpy (last_scan_query, arg);
1971 if (send_scanrequest(arg, 1, 20, 0) < 0)
1976 if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0)
1982 int cmd_schema(char *arg)
1989 schema = oid_getvalbyname (arg);
1990 if (schema == VAL_NONE)
1992 printf ("unknown schema\n");
1998 int cmd_format(char *arg)
2002 printf("Usage: format <recordsyntax>\n");
2005 recordsyntax = oid_getvalbyname (arg);
2006 if (recordsyntax == VAL_NONE)
2008 printf ("unknown record syntax\n");
2014 int cmd_elements(char *arg)
2016 static Z_ElementSetNames esn;
2017 static char what[100];
2021 elementSetNames = 0;
2025 esn.which = Z_ElementSetNames_generic;
2026 esn.u.generic = what;
2027 elementSetNames = &esn;
2031 int cmd_attributeset(char *arg)
2037 printf("Usage: attributeset <setname>\n");
2040 sscanf(arg, "%s", what);
2041 if (p_query_attset (what))
2043 printf("Unknown attribute set name\n");
2049 int cmd_querytype (char *arg)
2051 if (!strcmp (arg, "ccl"))
2052 queryType = QueryType_CCL;
2053 else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn"))
2054 queryType = QueryType_Prefix;
2056 else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
2057 queryType = QueryType_CCL2RPN;
2061 printf ("Querytype must be one of:\n");
2062 printf (" prefix - Prefix query\n");
2063 printf (" ccl - CCL query\n");
2065 printf (" ccl2rpn - CCL query converted to RPN\n");
2072 int cmd_refid (char *arg)
2078 refid = (char *) xmalloc (strlen(arg)+1);
2079 strcpy (refid, arg);
2084 int cmd_close(char *arg)
2091 apdu = zget_APDU(out, Z_APDU_close);
2092 req = apdu->u.close;
2093 *req->closeReason = Z_Close_finished;
2095 printf("Sent close request.\n");
2100 int cmd_packagename(char* arg)
2102 xfree (esPackageName);
2103 esPackageName = NULL;
2106 esPackageName = (char *) xmalloc (strlen(arg)+1);
2107 strcpy (esPackageName, arg);
2112 int cmd_proxy(char* arg)
2115 printf("Current proxy is `%s'\n", (yazCharset)?yazProxy:NULL);
2122 yazProxy = (char *) xmalloc (strlen(arg)+1);
2123 strcpy (yazProxy, arg);
2128 int cmd_charset(char* arg)
2131 printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL);
2138 yazCharset = (char *) xmalloc (strlen(arg)+1);
2139 strcpy (yazCharset, arg);
2144 int cmd_lang(char* arg)
2147 printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
2154 yazLang = (char *) xmalloc (strlen(arg)+1);
2155 strcpy (yazLang, arg);
2160 int cmd_source(char* arg)
2162 /* first should open the file and read one line at a time.. */
2164 char line[1024], *cp;
2167 char* args_end=(arg)+strlen(arg)-1;
2168 while(isspace(*args_end))
2173 REMOVE_TAILING_BLANKS(arg);
2176 fprintf(stderr,"Error in source command use a filename\n");
2180 includeFile = fopen (arg, "r");
2183 fprintf(stderr,"Unable to open file %s for reading\n",arg);
2187 while(!feof(includeFile)) {
2188 memset(line,0,sizeof(line));
2189 fgets(line,sizeof(line),includeFile);
2191 if(strlen(line) < 2) continue;
2192 if(line[0] == '#') continue;
2194 if ((cp = strrchr (line, '\n')))
2197 process_cmd_line(line);
2200 if(fclose(includeFile)<0) {
2201 perror("unable to close include file");
2207 int cmd_subshell(char* args)
2212 system(getenv("SHELL"));
2218 int cmd_set_apdufile(char* arg)
2220 REMOVE_TAILING_BLANKS(arg);
2222 if(apdu_file && apdu_file != stderr) { /* don't close stdout*/
2223 perror("unable to close apdu log file");
2231 if(!strcmp(arg,"-"))
2234 apdu_file=fopen(arg, "a");
2237 perror("unable to open apdu log file no apdu log loaded");
2239 odr_setprint(print, apdu_file);
2245 int cmd_set_cclfields(char* arg)
2250 REMOVE_TAILING_BLANKS(arg);
2252 bibset = ccl_qual_mk ();
2253 inf = fopen (arg, "r");
2256 ccl_qual_file (bibset, inf);
2260 fprintf(stderr,"Not compiled with the yaz ccl module\n");
2266 int cmd_set_marcdump(char* arg)
2268 if(marcdump && marcdump != stderr) { /* don't close stdout*/
2269 perror("unable to close apdu log file");
2277 if(!strcmp(arg,"-"))
2280 marcdump=fopen(arg, "a");
2283 perror("unable to open apdu marcdump file no marcdump done\n");
2289 int cmd_set_proxy(char* arg) {
2290 if(yazProxy) free(yazProxy);
2293 if(strlen(arg) > 1) {
2294 yazProxy=strdup(arg);
2300 this command takes 3 arge {name class oid}
2302 int cmd_register_oid(char* args) {
2307 {"appctx",CLASS_APPCTX},
2308 {"absyn",CLASS_ABSYN},
2309 {"attset",CLASS_ATTSET},
2310 {"transyn",CLASS_TRANSYN},
2311 {"diagset",CLASS_DIAGSET},
2312 {"recsyn",CLASS_RECSYN},
2313 {"resform",CLASS_RESFORM},
2314 {"accform",CLASS_ACCFORM},
2315 {"extserv",CLASS_EXTSERV},
2316 {"userinfo",CLASS_USERINFO},
2317 {"elemspec",CLASS_ELEMSPEC},
2318 {"varset",CLASS_VARSET},
2319 {"schema",CLASS_SCHEMA},
2320 {"tagset",CLASS_TAGSET},
2321 {"general",CLASS_GENERAL},
2324 char oname_str[101], oclass_str[101], oid_str[101];
2327 oid_class oidclass = CLASS_GENERAL;
2328 int val = 0, oid[OID_SIZE];
2329 struct oident * new_oident=NULL;
2331 if (sscanf (args, "%100[^ ] %100[^ ] %100s",
2332 oname_str,oclass_str, oid_str) < 1) {
2333 printf("Error in regristrate command \n");
2337 for (i = 0; oid_classes[i].className; i++) {
2338 if (!strcmp(oid_classes[i].className, oclass_str))
2340 oidclass=oid_classes[i].oclass;
2345 if(!(oid_classes[i].className)) {
2346 printf("Unknonwn oid class %s\n",oclass_str);
2354 while (isdigit (*name))
2356 val = val*10 + (*name - '0');
2369 new_oident=oid_addent (oid,PROTO_GENERAL,oidclass,oname_str,VAL_DYNAMIC);
2370 if(strcmp(new_oident->desc,oname_str)) {
2371 fprintf(stderr,"oid is already named as %s, regristration faild\n",
2377 int cmd_push_command(char* arg) {
2378 #if HAVE_READLINE_HISTORY_H
2382 fprintf(stderr,"Not compiled with the readline/history module\n");
2387 void source_rcfile() {
2388 /* Look for a $HOME/.yazclientrc and source it if it exists */
2389 struct stat statbuf;
2391 char* homedir=getenv("HOME");
2392 if(!homedir) return;
2394 sprintf(buffer,"%s/.yazclientrc",homedir);
2396 if(stat(buffer,&statbuf)==0) {
2400 if(stat(".yazclientrc",&statbuf)==0) {
2401 cmd_source(".yazclientrc");
2406 static void initialize(void)
2411 if (!(out = odr_createmem(ODR_ENCODE)) ||
2412 !(in = odr_createmem(ODR_DECODE)) ||
2413 !(print = odr_createmem(ODR_PRINT)))
2415 fprintf(stderr, "failed to allocate ODR streams\n");
2420 setvbuf(stdout, 0, _IONBF, 0);
2422 odr_setprint(print, apdu_file);
2425 bibset = ccl_qual_mk ();
2426 inf = fopen (ccl_fields, "r");
2429 ccl_qual_file (bibset, inf);
2433 cmd_base("Default");
2435 #if HAVE_READLINE_READLINE_H
2436 rl_attempted_completion_function = (CPPFunction*)readline_completer;
2443 #if HAVE_GETTIMEOFDAY
2444 struct timeval tv_start, tv_end;
2447 void wait_and_handle_responce()
2452 int netbufferlen = 0;
2460 if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
2462 printf("Target closed connection\n");
2468 printf("Target closed connection.\n");
2472 odr_reset(in); /* release APDU from last round */
2474 odr_setbuf(in, netbuffer, res, 0);
2475 if (!z_APDU(in, &apdu, 0, 0))
2477 odr_perror(in, "Decoding incoming APDU");
2478 fprintf(stderr, "[Near %d]\n", odr_offset(in));
2479 fprintf(stderr, "Packet dump:\n---------\n");
2480 odr_dumpBER(stderr, netbuffer, res);
2481 fprintf(stderr, "---------\n");
2483 z_APDU(print, &apdu, 0, 0);
2487 if (apdu_file && !z_APDU(print, &apdu, 0, 0))
2489 odr_perror(print, "Failed to print incoming APDU");
2495 case Z_APDU_initResponse:
2496 process_initResponse(apdu->u.initResponse);
2498 case Z_APDU_searchResponse:
2499 process_searchResponse(apdu->u.searchResponse);
2501 case Z_APDU_scanResponse:
2502 process_scanResponse(apdu->u.scanResponse);
2504 case Z_APDU_presentResponse:
2505 print_refid (apdu->u.presentResponse->referenceId);
2507 *apdu->u.presentResponse->numberOfRecordsReturned;
2508 if (apdu->u.presentResponse->records)
2509 display_records(apdu->u.presentResponse->records);
2511 printf("No records.\n");
2512 printf ("nextResultSetPosition = %d\n",
2513 *apdu->u.presentResponse->nextResultSetPosition);
2515 case Z_APDU_sortResponse:
2516 process_sortResponse(apdu->u.sortResponse);
2518 case Z_APDU_extendedServicesResponse:
2519 printf("Got extended services response\n");
2520 process_ESResponse(apdu->u.extendedServicesResponse);
2523 printf("Target has closed the association.\n");
2524 process_close(apdu->u.close);
2526 case Z_APDU_resourceControlRequest:
2527 process_resourceControlRequest
2528 (apdu->u.resourceControlRequest);
2530 case Z_APDU_deleteResultSetResponse:
2531 process_deleteResultSetResponse(apdu->u.
2532 deleteResultSetResponse);
2535 printf("Received unknown APDU type (%d).\n",
2540 while (conn && cs_more(conn));
2541 #if HAVE_GETTIMEOFDAY
2542 gettimeofday (&tv_end, 0);
2544 printf ("S/U S/U=%ld/%ld %ld/%ld",
2545 (long) tv_start.tv_sec,
2546 (long) tv_start.tv_usec,
2547 (long) tv_end.tv_sec,
2548 (long) tv_end.tv_usec);
2550 printf ("Elapsed: %.6f\n",
2551 (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
2552 ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
2559 static int cmd_help (char *line);
2563 int (*fun)(char *arg);
2565 char *(*rl_completerfunction)(const char *text, int state);
2566 int complete_filenames;
2568 {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0},
2569 {"quit", cmd_quit, "",NULL,0},
2570 {"find", cmd_find, "<query>",NULL,0},
2571 {"delete", cmd_delete, "<setname>",NULL,0},
2572 {"base", cmd_base, "<base-name>",NULL,0},
2573 {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0},
2574 {"scan", cmd_scan, "<term>",NULL,0},
2575 {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0},
2576 {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0},
2577 {"authentication", cmd_authentication, "<acctstring>",NULL,0},
2578 {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0},
2579 {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0},
2580 {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0},
2581 {"status", cmd_status, "",NULL,0},
2582 {"setnames", cmd_setnames, "",NULL,0},
2583 {"cancel", cmd_cancel, "",NULL,0},
2584 {"format", cmd_format, "<recordsyntax>",complete_format,0},
2585 {"schema", cmd_schema, "<schema>",complete_schema,0},
2586 {"elements", cmd_elements, "<elementSetName>",NULL,0},
2587 {"close", cmd_close, "",NULL,0},
2588 {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0},
2589 {"querytype", cmd_querytype, "<type>",complete_querytype,0},
2590 {"refid", cmd_refid, "<id>",NULL,0},
2591 {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0},
2592 {"update", cmd_update, "<item>",NULL,0},
2593 {"packagename", cmd_packagename, "<packagename>",NULL,0},
2594 {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0},
2595 {"charset", cmd_charset, "<charset_name>",NULL,0},
2596 {"lang", cmd_lang, "<language_code>",NULL,0},
2597 {".", cmd_source, "<filename>",NULL,1},
2598 {"!", cmd_subshell, "Subshell command",NULL,0},
2599 {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,0},
2600 {"set_marcdump", cmd_set_marcdump," <filename>",NULL,0},
2601 {"set_cclfields", cmd_set_cclfields,"<filename>",NULL,1},
2602 {"register_oid",cmd_register_oid,"<name> <class> <oid>",NULL,0},
2603 {"push_command",cmd_push_command,"<command>",command_generator,0},
2604 /* Server Admin Functions */
2605 {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0},
2606 {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0},
2607 {"adm-create", cmd_adm_create, "",NULL,0},
2608 {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0},
2609 {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0},
2610 {"adm-refresh", cmd_adm_refresh, "",NULL,0},
2611 {"adm-commit", cmd_adm_commit, "",NULL,0},
2612 {"adm-shutdown", cmd_adm_shutdown, "",NULL,0},
2613 {"adm-startup", cmd_adm_startup, "",NULL,0},
2614 {"help", cmd_help, "", NULL},
2618 static int cmd_help (char *line)
2624 sscanf (line, "%20s", topic);
2627 printf("Commands:\n");
2628 for (i = 0; cmd[i].cmd; i++)
2629 if (*topic == 0 || strcmp (topic, cmd[i].cmd) == 0)
2630 printf(" %s %s\n", cmd[i].cmd, cmd[i].ad);
2631 if (strcmp (topic, "find") == 0)
2634 printf (" \"term\" Simple Term\n");
2635 printf (" @attr [attset] type=value op Attribute\n");
2636 printf (" @and opl opr And\n");
2637 printf (" @or opl opr Or\n");
2638 printf (" @not opl opr And-Not\n");
2639 printf (" @set set Result set\n");
2641 printf ("Bib-1 attribute types\n");
2643 printf ("4=Title 7=ISBN 8=ISSN 30=Date 62=Abstract 1003=Author 1016=Any\n");
2644 printf ("2=Relation: ");
2645 printf ("1< 2<= 3= 4>= 5> 6!= 102=Relevance\n");
2646 printf ("3=Position: ");
2647 printf ("1=First in Field 2=First in subfield 3=Any position\n");
2648 printf ("4=Structure: ");
2649 printf ("1=Phrase 2=Word 3=Key 4=Year 5=Date 6=WordList\n");
2650 printf ("5=Truncation: ");
2651 printf ("1=Right 2=Left 3=L&R 100=No 101=# 102=Re-1 103=Re-2\n");
2652 printf ("6=Completeness:");
2653 printf ("1=Incomplete subfield 2=Complete subfield 3=Complete field\n");
2658 void process_cmd_line(char* line)
2661 char word[32], arg[1024];
2663 #if HAVE_GETTIMEOFDAY
2664 gettimeofday (&tv_start, 0);
2667 if ((res = sscanf(line, "%31s %1023[^;]", word, arg)) <= 0)
2669 strcpy(word, last_cmd);
2674 strcpy(last_cmd, word);
2676 /* removed tailing spaces from the arg command */
2679 char* lastnonspace=NULL;
2688 *(++lastnonspace) = 0;
2692 for (i = 0; cmd[i].cmd; i++)
2693 if (!strncmp(cmd[i].cmd, word, strlen(word)))
2695 res = (*cmd[i].fun)(arg);
2699 if (!cmd[i].cmd) /* dump our help-screen */
2701 printf("Unknown command: %s.\n", word);
2706 if(apdu_file) fflush(apdu_file);
2709 wait_and_handle_responce();
2718 char *command_generator(const char *text, int state)
2724 for( ; cmd[idx].cmd; ++idx) {
2725 if (!strncmp(cmd[idx].cmd,text,strlen(text))) {
2726 ++idx; /* skip this entry on the next run */
2727 return strdup(cmd[idx-1].cmd);
2735 This function only known how to complete on the first word
2737 char ** readline_completer(char *text, int start, int end) {
2738 #if HAVE_READLINE_READLINE_H
2741 #if HAVE_READLINE_RL_COMPLETION_MATCHES
2742 char** res=rl_completion_matches(text,
2745 char** res=completion_matches(text,
2746 (CPFunction*)command_generator);
2748 rl_attempted_completion_over = 1;
2751 char arg[1024],word[32];
2753 if ((res = sscanf(rl_line_buffer, "%31s %1023[^;]", word, arg)) <= 0) {
2754 rl_attempted_completion_over = 1;
2758 if(start != strlen(word) +1 ) {
2759 rl_attempted_completion_over = 1;
2762 for (i = 0; cmd[i].cmd; i++) {
2763 if (!strncmp(cmd[i].cmd, word, strlen(word))) {
2769 if(!cmd[i].complete_filenames)
2770 rl_attempted_completion_over = 1;
2771 if(cmd[i].rl_completerfunction) {
2772 #ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
2774 rl_completion_matches(text,
2775 cmd[i].rl_completerfunction);
2778 completion_matches(text,
2779 (CPFunction*)cmd[i].rl_completerfunction);
2781 rl_attempted_completion_over = 1;
2784 rl_attempted_completion_over = 1;
2794 static void client(void)
2800 #if HAVE_GETTIMEOFDAY
2801 gettimeofday (&tv_start, 0);
2806 char *line_in = NULL;
2807 #if HAVE_READLINE_READLINE_H
2810 line_in=readline(C_PROMPT);
2813 #if HAVE_READLINE_HISTORY_H
2815 add_history(line_in);
2817 strncpy(line, line_in, 1023);
2826 if (!fgets(line, 1023, stdin))
2828 if ((end_p = strchr (line, '\n')))
2831 process_cmd_line(line);
2835 int main(int argc, char **argv)
2838 char *open_command = 0;
2839 char *auth_command = 0;
2843 while ((ret = options("k:c:a:m:v:p:u:", argv, argc, &arg)) != -2)
2850 open_command = (char *) xmalloc (strlen(arg)+6);
2851 strcpy (open_command, "open ");
2852 strcat (open_command, arg);
2856 kilobytes = atoi(arg);
2859 if (!(marcdump = fopen (arg, "a")))
2866 strncpy (ccl_fields, arg, sizeof(ccl_fields)-1);
2867 ccl_fields[sizeof(ccl_fields)-1] = '\0';
2870 if (!strcmp(arg, "-"))
2873 apdu_file=fopen(arg, "a");
2876 yazProxy=strdup(arg);
2881 auth_command = (char *) xmalloc (strlen(arg)+6);
2882 strcpy (auth_command, "auth ");
2883 strcat (auth_command, arg);
2887 yaz_log_init (yaz_log_mask_str(arg), "", NULL);
2890 fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
2891 "[-c cclfields]\n [-p <proxy-addr>] [-u <auth>] "
2892 "[-k size] [<server-addr>]\n",
2900 #ifdef HAVE_GETTIMEOFDAY
2901 gettimeofday (&tv_start, 0);
2903 process_cmd_line (auth_command);
2904 #if HAVE_READLINE_HISTORY_H
2905 add_history(auth_command);
2907 xfree(auth_command);
2911 #ifdef HAVE_GETTIMEOFDAY
2912 gettimeofday (&tv_start, 0);
2914 process_cmd_line (open_command);
2915 #if HAVE_READLINE_HISTORY_H
2916 add_history(open_command);
2918 xfree(open_command);