2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: client.c,v 1.160 2002-06-18 21:30:25 adam Exp $
12 #include <yaz/yaz-util.h>
14 #include <yaz/comstack.h>
16 #include <yaz/proto.h>
17 #include <yaz/marcdisp.h>
18 #include <yaz/diagbib1.h>
19 #include <yaz/otherinfo.h>
20 #include <yaz/charneg.h>
22 #include <yaz/pquery.h>
23 #include <yaz/sortspec.h>
27 #include <yaz/yaz-ccl.h>
29 #if HAVE_READLINE_READLINE_H
30 #include <readline/readline.h>
33 #if HAVE_READLINE_HISTORY_H
34 #include <readline/history.h>
41 #include "tabcomplete.h"
43 #define C_PROMPT "Z> "
45 static ODR out, in, print; /* encoding and decoding streams */
46 static FILE *apdu_file = 0;
47 static COMSTACK conn = 0; /* our z-association */
48 static Z_IdAuthentication *auth = 0; /* our current auth definition */
49 char *databaseNames[128];
50 int num_databaseNames = 0;
51 static Z_External *record_last = 0;
52 static int setnumber = -1; /* current result set number */
53 static int smallSetUpperBound = 0;
54 static int largeSetLowerBound = 1;
55 static int mediumSetPresentNumber = 0;
56 static Z_ElementSetNames *elementSetNames = 0;
57 static int setno = 1; /* current set offset */
58 static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */
59 static enum oid_value recordsyntax = VAL_USMARC;
60 static enum oid_value schema = VAL_NONE;
61 static int sent_close = 0;
62 static NMEM session_mem = NULL; /* memory handle for init-response */
63 static Z_InitResponse *session = 0; /* session parameters */
64 static char last_scan_line[512] = "0";
65 static char last_scan_query[512] = "0";
66 static char ccl_fields[512] = "default.bib";
67 static char* esPackageName = 0;
68 static char* yazProxy = 0;
69 static int kilobytes = 1024;
70 static char* yazCharset = 0;
71 static char* yazLang = 0;
74 static char last_cmd[32] = "?";
75 static FILE *marcdump = 0;
76 static char *refid = NULL;
84 static QueryType queryType = QueryType_Prefix;
86 static CCL_bibset bibset; /* CCL bibset handle */
88 #if HAVE_READLINE_COMPLETION_OVER
91 /* readline doesn't have this var. Define it ourselves. */
92 int rl_attempted_completion_over = 0;
95 /* set this one to 1, to avoid decode of unknown MARCs */
96 #define AVOID_MARC_DECODE 1
98 /* nice helper macro as extensive tabbing gives spaces at the en of the args lines */
99 #define REMOVE_TAILING_BLANKS(a) {\
100 char* args_end=(a)+strlen(a)-1; \
101 while(isspace(*args_end)) {*args_end=0;--args_end;}; \
105 void process_cmd_line(char* line);
106 char ** readline_completer(char *text, int start, int end);
107 char *command_generator(const char *text, int state);
108 char** curret_global_list=NULL;
109 int cmd_register_tab(char* arg);
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];
356 printf("Already connected.\n");
362 nmem_destroy (session_mem);
366 if (strncmp (arg, "unix:", 5) == 0)
369 conn = cs_create_host(arg, 1, &add);
374 if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1)
377 conn = cs_create_host(yazProxy, 1, &add);
379 conn = cs_create_host(type_and_host, 1, &add);
383 printf ("Couldn't create comstack\n");
386 printf("Connecting...");
388 if (cs_connect(conn, add) < 0)
390 printf ("error = %s\n", cs_strerror(conn));
391 if (conn->cerrno == CSYSERR)
399 send_initRequest(type_and_host);
405 int cmd_authentication(char *arg)
407 static Z_IdAuthentication au;
408 static char user[40], group[40], pass[40];
409 static Z_IdPass idPass;
414 printf("Auth field set to null\n");
418 r = sscanf (arg, "%39s %39s %39s", user, group, pass);
421 printf("Auth field set to null\n");
427 au.which = Z_IdAuthentication_open;
433 au.which = Z_IdAuthentication_idPass;
434 au.u.idPass = &idPass;
435 idPass.groupId = NULL;
436 idPass.userId = user;
437 idPass.password = group;
442 au.which = Z_IdAuthentication_idPass;
443 au.u.idPass = &idPass;
444 idPass.groupId = group;
445 idPass.userId = user;
446 idPass.password = pass;
451 /* SEARCH SERVICE ------------------------------ */
452 static void display_record(Z_External *r);
454 static void display_variant(Z_Variant *v, int level)
458 for (i = 0; i < v->num_triples; i++)
460 printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
461 *v->triples[i]->type);
462 if (v->triples[i]->which == Z_Triple_internationalString)
463 printf(",value=%s\n", v->triples[i]->value.internationalString);
469 static void display_grs1(Z_GenericRecord *r, int level)
477 for (i = 0; i < r->num_elements; i++)
481 printf("%*s", level * 4, "");
485 printf("%d,", *t->tagType);
488 if (t->tagValue->which == Z_StringOrNumeric_numeric)
489 printf("%d) ", *t->tagValue->u.numeric);
491 printf("%s) ", t->tagValue->u.string);
492 if (t->content->which == Z_ElementData_subtree)
494 if (!t->content->u.subtree)
495 printf (" (no subtree)\n");
499 display_grs1(t->content->u.subtree, level+1);
502 else if (t->content->which == Z_ElementData_string)
503 printf("%s\n", t->content->u.string);
504 else if (t->content->which == Z_ElementData_numeric)
505 printf("%d\n", *t->content->u.numeric);
506 else if (t->content->which == Z_ElementData_oid)
508 int *ip = t->content->u.oid;
511 if ((oent = oid_getentbyoid(t->content->u.oid)))
512 printf("OID: %s\n", oent->desc);
516 while (ip && *ip >= 0)
517 printf(" %d", *(ip++));
521 else if (t->content->which == Z_ElementData_noDataRequested)
522 printf("[No data requested]\n");
523 else if (t->content->which == Z_ElementData_elementEmpty)
524 printf("[Element empty]\n");
525 else if (t->content->which == Z_ElementData_elementNotThere)
526 printf("[Element not there]\n");
527 else if (t->content->which == Z_ElementData_date)
528 printf("Date: %s\n", t->content->u.date);
529 else if (t->content->which == Z_ElementData_ext)
531 printf ("External\n");
532 display_record (t->content->u.ext);
535 printf("? type = %d\n",t->content->which);
536 if (t->appliedVariant)
537 display_variant(t->appliedVariant, level+1);
538 if (t->metaData && t->metaData->supportedVariants)
542 printf("%*s---- variant list\n", (level+1)*4, "");
543 for (c = 0; c < t->metaData->num_supportedVariants; c++)
545 printf("%*svariant #%d\n", (level+1)*4, "", c);
546 display_variant(t->metaData->supportedVariants[c], level + 2);
553 static void print_record(const unsigned char *buf, size_t len)
556 print_stringn (buf, len);
557 /* add newline if not already added ... */
558 if (i <= 0 || buf[i-1] != '\n')
562 static void display_record(Z_External *r)
564 oident *ent = oid_getentbyoid(r->direct_reference);
568 * Tell the user what we got.
570 if (r->direct_reference)
572 printf("Record type: ");
574 printf("%s\n", ent->desc);
575 else if (!odr_oid(print, &r->direct_reference, 0, 0))
577 odr_perror(print, "print oid");
581 /* Check if this is a known, ASN.1 type tucked away in an octet string */
582 if (ent && r->which == Z_External_octet)
584 Z_ext_typeent *type = z_ext_getentbyref(ent->value);
590 * Call the given decoder to process the record.
592 odr_setbuf(in, (char*)r->u.octet_aligned->buf,
593 r->u.octet_aligned->len, 0);
594 if (!(*type->fun)(in, (char **)&rr, 0, 0))
596 odr_perror(in, "Decoding constructed record.");
597 fprintf(stderr, "[Near %d]\n", odr_offset(in));
598 fprintf(stderr, "Packet dump:\n---------\n");
599 odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf,
600 r->u.octet_aligned->len);
601 fprintf(stderr, "---------\n");
605 * Note: we throw away the original, BER-encoded record here.
606 * Do something else with it if you want to keep it.
608 r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
609 r->which = type->what;
612 if (ent && ent->oclass != CLASS_RECSYN)
614 if (ent && ent->value == VAL_SOIF)
615 print_record((const unsigned char *) r->u.octet_aligned->buf,
616 r->u.octet_aligned->len);
617 else if (r->which == Z_External_octet && r->u.octet_aligned->len)
619 const char *octet_buf = (char*)r->u.octet_aligned->buf;
620 if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML ||
621 ent->value == VAL_HTML)
623 print_record((const unsigned char *) octet_buf,
624 r->u.octet_aligned->len);
626 else if (ent->value == VAL_POSTSCRIPT)
628 int size = r->u.octet_aligned->len;
631 print_record((const unsigned char *) octet_buf, size);
636 #if AVOID_MARC_DECODE
637 /* primitive check for a marc OID 5.1-29 except 16 */
638 ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
639 ent->oidsuffix[1] != 16
645 if (marc_display_exl (octet_buf, NULL, 0 /* debug */,
646 r->u.octet_aligned->len) <= 0)
648 printf ("bad MARC. Dumping as it is:\n");
649 print_record((const unsigned char*) octet_buf,
650 r->u.octet_aligned->len);
655 print_record((const unsigned char*) octet_buf,
656 r->u.octet_aligned->len);
660 fwrite (octet_buf, 1, r->u.octet_aligned->len, marcdump);
662 else if (ent && ent->value == VAL_SUTRS)
664 if (r->which != Z_External_sutrs)
666 printf("Expecting single SUTRS type for SUTRS.\n");
669 print_record(r->u.sutrs->buf, r->u.sutrs->len);
671 else if (ent && ent->value == VAL_GRS1)
673 if (r->which != Z_External_grs1)
675 printf("Expecting single GRS type for GRS.\n");
678 display_grs1(r->u.grs1, 0);
682 printf("Unknown record representation.\n");
683 if (!z_External(print, &r, 0, 0))
685 odr_perror(print, "Printing external");
691 static void display_diagrecs(Z_DiagRec **pp, int num)
695 Z_DefaultDiagFormat *r;
697 printf("Diagnostic message(s) from database:\n");
698 for (i = 0; i<num; i++)
700 Z_DiagRec *p = pp[i];
701 if (p->which != Z_DiagRec_defaultFormat)
703 printf("Diagnostic record not in default format.\n");
707 r = p->u.defaultFormat;
708 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
709 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
710 printf("Missing or unknown diagset\n");
711 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
714 case Z_DefaultDiagFormat_v2Addinfo:
715 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
717 case Z_DefaultDiagFormat_v3Addinfo:
718 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
725 static void display_nameplusrecord(Z_NamePlusRecord *p)
728 printf("[%s]", p->databaseName);
729 if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
730 display_diagrecs(&p->u.surrogateDiagnostic, 1);
731 else if (p->which == Z_NamePlusRecord_databaseRecord)
732 display_record(p->u.databaseRecord);
735 static void display_records(Z_Records *p)
739 if (p->which == Z_Records_NSD)
741 Z_DiagRec dr, *dr_p = &dr;
742 dr.which = Z_DiagRec_defaultFormat;
743 dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
744 display_diagrecs (&dr_p, 1);
746 else if (p->which == Z_Records_multipleNSD)
747 display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
748 p->u.multipleNonSurDiagnostics->num_diagRecs);
751 printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
752 for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
753 display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
757 static int send_deleteResultSetRequest(char *arg)
762 Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
763 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
765 req->referenceId = set_refid (out);
767 req->num_resultSetList =
768 sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
769 names[0], names[1], names[2], names[3],
770 names[4], names[5], names[6], names[7]);
772 req->deleteFunction = (int *)
773 odr_malloc (out, sizeof(*req->deleteFunction));
774 if (req->num_resultSetList > 0)
776 *req->deleteFunction = Z_DeleteRequest_list;
777 req->resultSetList = (char **)
778 odr_malloc (out, sizeof(*req->resultSetList)*
779 req->num_resultSetList);
780 for (i = 0; i<req->num_resultSetList; i++)
781 req->resultSetList[i] = names[i];
785 *req->deleteFunction = Z_DeleteRequest_all;
786 req->resultSetList = 0;
790 printf("Sent deleteResultSetRequest.\n");
794 static int send_searchRequest(char *arg)
796 Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
797 Z_SearchRequest *req = apdu->u.searchRequest;
800 struct ccl_rpn_node *rpn = NULL;
803 Z_RPNQuery *RPNquery;
806 if (queryType == QueryType_CCL2RPN)
808 rpn = ccl_find_str(bibset, arg, &error, &pos);
811 printf("CCL ERROR: %s\n", ccl_err_msg(error));
815 req->referenceId = set_refid (out);
816 if (!strcmp(arg, "@big")) /* strictly for troublemaking */
818 static unsigned char big[2100];
821 /* send a very big referenceid to test transport stack etc. */
822 memset(big, 'A', 2100);
823 bigo.len = bigo.size = 2100;
825 req->referenceId = &bigo;
830 sprintf(setstring, "%d", ++setnumber);
831 req->resultSetName = setstring;
833 *req->smallSetUpperBound = smallSetUpperBound;
834 *req->largeSetLowerBound = largeSetLowerBound;
835 *req->mediumSetPresentNumber = mediumSetPresentNumber;
836 if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
837 mediumSetPresentNumber > 0))
841 prefsyn.proto = protocol;
842 prefsyn.oclass = CLASS_RECSYN;
843 prefsyn.value = recordsyntax;
844 req->preferredRecordSyntax =
845 odr_oiddup(out, oid_ent_to_oid(&prefsyn, oid));
846 req->smallSetElementSetNames =
847 req->mediumSetElementSetNames = elementSetNames;
849 req->num_databaseNames = num_databaseNames;
850 req->databaseNames = databaseNames;
856 case QueryType_Prefix:
857 query.which = Z_Query_type_1;
858 RPNquery = p_query_rpn (out, protocol, arg);
861 printf("Prefix query error\n");
864 query.u.type_1 = RPNquery;
867 query.which = Z_Query_type_2;
868 query.u.type_2 = &ccl_query;
869 ccl_query.buf = (unsigned char*) arg;
870 ccl_query.len = strlen(arg);
872 case QueryType_CCL2RPN:
873 query.which = Z_Query_type_1;
874 RPNquery = ccl_rpn_query(out, rpn);
877 printf ("Couldn't convert from CCL to RPN\n");
880 query.u.type_1 = RPNquery;
881 ccl_rpn_delete (rpn);
884 printf ("Unsupported query type\n");
889 printf("Sent searchRequest.\n");
893 /* display Query Expression as part of searchResult-1 */
894 static void display_queryExpression (Z_QueryExpression *qe)
898 if (qe->which == Z_QueryExpression_term)
900 if (qe->u.term->queryTerm)
902 Z_Term *term = qe->u.term->queryTerm;
903 if (term->which == Z_Term_general)
904 printf (" %.*s", term->u.general->len, term->u.general->buf);
910 /* see if we can find USR:SearchResult-1 */
911 static void display_searchResult (Z_OtherInformation *o)
916 for (i = 0; i < o->num_elements; i++)
918 if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
920 Z_External *ext = o->list[i]->information.externallyDefinedInfo;
922 if (ext->which == Z_External_searchResult1)
925 Z_SearchInfoReport *sr = ext->u.searchResult1;
926 printf ("SearchResult-1:");
927 for (j = 0; j < sr->num; j++)
929 if (!sr->elements[j]->subqueryExpression)
931 display_queryExpression (
932 sr->elements[j]->subqueryExpression);
933 display_queryExpression (
934 sr->elements[j]->subqueryInterpretation);
935 display_queryExpression (
936 sr->elements[j]->subqueryRecommendation);
937 if (sr->elements[j]->subqueryCount)
938 printf ("(%d)", *sr->elements[j]->subqueryCount);
946 static int process_searchResponse(Z_SearchResponse *res)
948 printf ("Received SearchResponse.\n");
949 print_refid (res->referenceId);
950 if (*res->searchStatus)
951 printf("Search was a success.\n");
953 printf("Search was a bloomin' failure.\n");
954 printf("Number of hits: %d", *res->resultCount);
956 printf (", setno %d", setnumber);
958 display_searchResult (res->additionalSearchInfo);
959 printf("records returned: %d\n",
960 *res->numberOfRecordsReturned);
961 setno += *res->numberOfRecordsReturned;
963 display_records(res->records);
967 static void print_level(int iLevel)
970 for (i = 0; i < iLevel * 4; i++)
974 static void print_int(int iLevel, const char *pTag, int *pInt)
979 printf("%s: %d\n", pTag, *pInt);
983 static void print_string(int iLevel, const char *pTag, const char *pString)
988 printf("%s: %s\n", pTag, pString);
992 static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
1000 for (; *pInt != -1; pInt++)
1001 printf(" %d", *pInt);
1006 static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
1008 if (referenceId != NULL)
1012 print_level(iLevel);
1013 printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
1014 for (i = 0; i < referenceId->len; i++)
1015 printf("%c", referenceId->buf[i]);
1020 static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
1022 if (pStringNumeric != NULL)
1024 switch (pStringNumeric->which)
1026 case Z_StringOrNumeric_string:
1027 print_string(iLevel, pTag, pStringNumeric->u.string);
1030 case Z_StringOrNumeric_numeric:
1031 print_int(iLevel, pTag, pStringNumeric->u.numeric);
1035 print_level(iLevel);
1036 printf("%s: valid type for Z_StringOrNumeric\n", pTag);
1042 static void print_universe_report_duplicate(int iLevel, Z_UniverseReportDuplicate *pUniverseReportDuplicate)
1044 if (pUniverseReportDuplicate != NULL)
1046 print_level(iLevel);
1047 printf("Universe Report Duplicate: \n");
1049 print_string_or_numeric(iLevel, "Hit No",
1050 pUniverseReportDuplicate->hitno);
1055 print_universe_report_hits(int iLevel,
1056 Z_UniverseReportHits *pUniverseReportHits)
1058 if (pUniverseReportHits != NULL)
1060 print_level(iLevel);
1061 printf("Universe Report Hits: \n");
1063 print_string_or_numeric(iLevel, "Database",
1064 pUniverseReportHits->database);
1065 print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
1069 static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
1071 if (pUniverseReport != NULL)
1073 print_level(iLevel);
1074 printf("Universe Report: \n");
1076 print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
1077 switch (pUniverseReport->which)
1079 case Z_UniverseReport_databaseHits:
1080 print_universe_report_hits(iLevel, pUniverseReport->u.databaseHits);
1083 case Z_UniverseReport_duplicate:
1084 print_universe_report_duplicate(iLevel, pUniverseReport->u.duplicate);
1088 print_level(iLevel);
1089 printf("Type: %d\n", pUniverseReport->which);
1095 static void print_external(int iLevel, Z_External *pExternal)
1097 if (pExternal != NULL)
1099 print_level(iLevel);
1100 printf("External: \n");
1102 print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
1103 print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
1104 print_string(iLevel, "Descriptor", pExternal->descriptor);
1105 switch (pExternal->which)
1107 case Z_External_universeReport:
1108 print_universe_report(iLevel, pExternal->u.universeReport);
1112 print_level(iLevel);
1113 printf("Type: %d\n", pExternal->which);
1119 static int process_resourceControlRequest (Z_ResourceControlRequest *req)
1121 printf ("Received ResourceControlRequest.\n");
1122 print_referenceId(1, req->referenceId);
1123 print_int(1, "Suspended Flag", req->suspendedFlag);
1124 print_int(1, "Partial Results Available", req->partialResultsAvailable);
1125 print_int(1, "Response Required", req->responseRequired);
1126 print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
1127 print_external(1, req->resourceReport);
1131 void process_ESResponse(Z_ExtendedServicesResponse *res)
1134 switch (*res->operationStatus)
1136 case Z_ExtendedServicesResponse_done:
1139 case Z_ExtendedServicesResponse_accepted:
1140 printf ("accepted\n");
1142 case Z_ExtendedServicesResponse_failure:
1143 printf ("failure\n");
1144 display_diagrecs(res->diagnostics, res->num_diagnostics);
1147 printf ("unknown\n");
1149 if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
1150 (res->num_diagnostics != 0) ) {
1151 display_diagrecs(res->diagnostics, res->num_diagnostics);
1153 print_refid (res->referenceId);
1154 if (res->taskPackage &&
1155 res->taskPackage->which == Z_External_extendedService)
1157 Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1158 Odr_oct *id = taskPackage->targetReference;
1159 Z_External *ext = taskPackage->taskSpecificParameters;
1163 printf ("Target Reference: ");
1164 print_stringn (id->buf, id->len);
1167 if (ext->which == Z_External_update)
1169 Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
1170 if (utp && utp->targetPart)
1172 Z_IUTargetPart *targetPart = utp->targetPart;
1175 for (i = 0; i<targetPart->num_taskPackageRecords; i++)
1178 Z_IUTaskPackageRecordStructure *tpr =
1179 targetPart->taskPackageRecords[i];
1180 printf ("task package record %d\n", i+1);
1181 if (tpr->which == Z_IUTaskPackageRecordStructure_record)
1183 display_record (tpr->u.record);
1187 printf ("other type\n");
1195 const char *get_ill_element (void *clientData, const char *element)
1200 static Z_External *create_external_itemRequest()
1202 struct ill_get_ctl ctl;
1203 ILL_ItemRequest *req;
1205 int item_request_size = 0;
1206 char *item_request_buf = 0;
1210 ctl.f = get_ill_element;
1212 req = ill_get_ItemRequest(&ctl, "ill", 0);
1214 printf ("ill_get_ItemRequest failed\n");
1216 if (!ill_ItemRequest (out, &req, 0, 0))
1220 ill_ItemRequest(print, &req, 0, 0);
1223 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1224 if (item_request_buf)
1225 odr_setbuf (out, item_request_buf, item_request_size, 1);
1226 printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
1233 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1234 oid.proto = PROTO_GENERAL;
1235 oid.oclass = CLASS_GENERAL;
1236 oid.value = VAL_ISO_ILL_1;
1238 r = (Z_External *) odr_malloc (out, sizeof(*r));
1239 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1240 r->indirect_reference = 0;
1242 r->which = Z_External_single;
1244 r->u.single_ASN1_type = (Odr_oct *)
1245 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1246 r->u.single_ASN1_type->buf = (unsigned char *)
1247 odr_malloc (out, item_request_size);
1248 r->u.single_ASN1_type->len = item_request_size;
1249 r->u.single_ASN1_type->size = item_request_size;
1250 memcpy (r->u.single_ASN1_type->buf, item_request_buf,
1252 printf ("len = %d\n", item_request_size);
1257 static Z_External *create_external_ILL_APDU(int which)
1259 struct ill_get_ctl ctl;
1262 int ill_request_size = 0;
1263 char *ill_request_buf = 0;
1267 ctl.f = get_ill_element;
1269 ill_apdu = ill_get_APDU(&ctl, "ill", 0);
1271 if (!ill_APDU (out, &ill_apdu, 0, 0))
1275 printf ("-------------------\n");
1276 ill_APDU(print, &ill_apdu, 0, 0);
1278 printf ("-------------------\n");
1280 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1281 if (ill_request_buf)
1282 odr_setbuf (out, ill_request_buf, ill_request_size, 1);
1283 printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
1289 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1291 oid.proto = PROTO_GENERAL;
1292 oid.oclass = CLASS_GENERAL;
1293 oid.value = VAL_ISO_ILL_1;
1295 r = (Z_External *) odr_malloc (out, sizeof(*r));
1296 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1297 r->indirect_reference = 0;
1299 r->which = Z_External_single;
1301 r->u.single_ASN1_type = (Odr_oct *)
1302 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1303 r->u.single_ASN1_type->buf = (unsigned char *)
1304 odr_malloc (out, ill_request_size);
1305 r->u.single_ASN1_type->len = ill_request_size;
1306 r->u.single_ASN1_type->size = ill_request_size;
1307 memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
1308 printf ("len = %d\n", ill_request_size);
1314 static Z_External *create_ItemOrderExternal(const char *type, int itemno)
1316 Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
1317 oident ItemOrderRequest;
1319 ItemOrderRequest.proto = PROTO_Z3950;
1320 ItemOrderRequest.oclass = CLASS_EXTSERV;
1321 ItemOrderRequest.value = VAL_ITEMORDER;
1323 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1324 r->indirect_reference = 0;
1327 r->which = Z_External_itemOrder;
1329 r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder));
1330 memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder));
1331 r->u.itemOrder->which=Z_IOItemOrder_esRequest;
1333 r->u.itemOrder->u.esRequest = (Z_IORequest *)
1334 odr_malloc(out,sizeof(Z_IORequest));
1335 memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest));
1337 r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
1338 odr_malloc(out,sizeof(Z_IOOriginPartToKeep));
1339 memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep));
1340 r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
1341 odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep));
1342 memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep));
1344 r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL;
1345 r->u.itemOrder->u.esRequest->toKeep->contact = NULL;
1346 r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL;
1348 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem =
1349 (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem));
1350 memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem));
1351 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1";
1353 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item =
1354 (int *) odr_malloc(out, sizeof(int));
1355 *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
1357 if (!strcmp (type, "item") || !strcmp(type, "2"))
1359 printf ("using item-request\n");
1360 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1361 create_external_itemRequest();
1363 else if (!strcmp(type, "ill") || !strcmp(type, "1"))
1365 printf ("using ILL-request\n");
1366 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1367 create_external_ILL_APDU(ILL_APDU_ILL_Request);
1369 else if (!strcmp(type, "xml") || !strcmp(type, "3"))
1371 const char *xml_buf =
1373 " <type>request</type>\n"
1374 " <libraryNo>000200</libraryNo>\n"
1375 " <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
1377 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1378 z_ext_record (out, VAL_TEXT_XML, xml_buf, strlen(xml_buf));
1381 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1386 static int send_itemorder(const char *type, int itemno)
1388 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
1389 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1390 oident ItemOrderRequest;
1392 ItemOrderRequest.proto = PROTO_Z3950;
1393 ItemOrderRequest.oclass = CLASS_EXTSERV;
1394 ItemOrderRequest.value = VAL_ITEMORDER;
1395 req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1396 req->packageName = esPackageName;
1398 req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
1404 static int cmd_update(char *arg)
1406 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
1407 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1410 Z_IUOriginPartToKeep *toKeep;
1411 Z_IUSuppliedRecords *notToKeep;
1413 printf ("Update request\n");
1418 update_oid.proto = PROTO_Z3950;
1419 update_oid.oclass = CLASS_EXTSERV;
1420 update_oid.value = VAL_DBUPDATE;
1421 oid_ent_to_oid (&update_oid, oid);
1422 req->packageType = odr_oiddup(out,oid);
1423 req->packageName = esPackageName;
1425 req->referenceId = set_refid (out);
1427 r = req->taskSpecificParameters = (Z_External *)
1428 odr_malloc (out, sizeof(*r));
1429 r->direct_reference = odr_oiddup(out,oid);
1430 r->indirect_reference = 0;
1432 r->which = Z_External_update;
1433 r->u.update = (Z_IUUpdate *) odr_malloc(out, sizeof(*r->u.update));
1434 r->u.update->which = Z_IUUpdate_esRequest;
1435 r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
1436 odr_malloc(out, sizeof(*r->u.update->u.esRequest));
1437 toKeep = r->u.update->u.esRequest->toKeep = (Z_IUOriginPartToKeep *)
1438 odr_malloc(out, sizeof(*r->u.update->u.esRequest->toKeep));
1439 toKeep->databaseName = databaseNames[0];
1441 toKeep->elementSetName = 0;
1442 toKeep->actionQualifier = 0;
1443 toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
1444 *toKeep->action = Z_IUOriginPartToKeep_recordInsert;
1446 notToKeep = r->u.update->u.esRequest->notToKeep = (Z_IUSuppliedRecords *)
1447 odr_malloc(out, sizeof(*r->u.update->u.esRequest->notToKeep));
1449 notToKeep->elements = (Z_IUSuppliedRecords_elem **)
1450 odr_malloc(out, sizeof(*notToKeep->elements));
1451 notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
1452 odr_malloc(out, sizeof(**notToKeep->elements));
1453 notToKeep->elements[0]->u.number = 0;
1454 notToKeep->elements[0]->supplementalId = 0;
1455 notToKeep->elements[0]->correlationInfo = 0;
1456 notToKeep->elements[0]->record = record_last;
1463 static int cmd_itemorder(char *arg)
1468 if (sscanf (arg, "%10s %d", type, &itemno) != 2)
1471 printf("Item order request\n");
1473 send_itemorder(type, itemno);
1477 static int cmd_find(char *arg)
1481 printf("Find what?\n");
1486 printf("Not connected yet\n");
1489 if (!send_searchRequest(arg))
1494 static int cmd_delete(char *arg)
1498 printf("Not connected yet\n");
1501 if (!send_deleteResultSetRequest(arg))
1506 static int cmd_ssub(char *arg)
1508 if (!(smallSetUpperBound = atoi(arg)))
1513 static int cmd_lslb(char *arg)
1515 if (!(largeSetLowerBound = atoi(arg)))
1520 static int cmd_mspn(char *arg)
1522 if (!(mediumSetPresentNumber = atoi(arg)))
1527 static int cmd_status(char *arg)
1529 printf("smallSetUpperBound: %d\n", smallSetUpperBound);
1530 printf("largeSetLowerBound: %d\n", largeSetLowerBound);
1531 printf("mediumSetPresentNumber: %d\n", mediumSetPresentNumber);
1535 static int cmd_setnames(char *arg)
1537 if (*arg == '1') /* enable ? */
1539 else if (*arg == '0') /* disable ? */
1541 else if (setnumber < 0) /* no args, toggle .. */
1547 printf("Set numbering enabled.\n");
1549 printf("Set numbering disabled.\n");
1553 /* PRESENT SERVICE ----------------------------- */
1555 static int send_presentRequest(char *arg)
1557 Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
1558 Z_PresentRequest *req = apdu->u.presentRequest;
1559 Z_RecordComposition compo;
1564 char setstring[100];
1566 req->referenceId = set_refid (out);
1567 if ((p = strchr(arg, '+')))
1574 if (p && (p=strchr(p+1, '+')))
1576 strcpy (setstring, p+1);
1577 req->resultSetId = setstring;
1579 else if (setnumber >= 0)
1581 sprintf(setstring, "%d", setnumber);
1582 req->resultSetId = setstring;
1584 req->resultSetStartPoint = &setno;
1585 req->numberOfRecordsRequested = &nos;
1586 prefsyn.proto = protocol;
1587 prefsyn.oclass = CLASS_RECSYN;
1588 prefsyn.value = recordsyntax;
1589 req->preferredRecordSyntax =
1590 odr_oiddup (out, oid_ent_to_oid(&prefsyn, oid));
1592 if (schema != VAL_NONE)
1596 prefschema.proto = protocol;
1597 prefschema.oclass = CLASS_SCHEMA;
1598 prefschema.value = schema;
1600 req->recordComposition = &compo;
1601 compo.which = Z_RecordComp_complex;
1602 compo.u.complex = (Z_CompSpec *)
1603 odr_malloc(out, sizeof(*compo.u.complex));
1604 compo.u.complex->selectAlternativeSyntax = (bool_t *)
1605 odr_malloc(out, sizeof(bool_t));
1606 *compo.u.complex->selectAlternativeSyntax = 0;
1608 compo.u.complex->generic = (Z_Specification *)
1609 odr_malloc(out, sizeof(*compo.u.complex->generic));
1610 compo.u.complex->generic->schema = (Odr_oid *)
1611 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1612 if (!compo.u.complex->generic->schema)
1614 /* OID wasn't a schema! Try record syntax instead. */
1615 prefschema.oclass = CLASS_RECSYN;
1616 compo.u.complex->generic->schema = (Odr_oid *)
1617 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1619 if (!elementSetNames)
1620 compo.u.complex->generic->elementSpec = 0;
1623 compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
1624 odr_malloc(out, sizeof(Z_ElementSpec));
1625 compo.u.complex->generic->elementSpec->which =
1626 Z_ElementSpec_elementSetName;
1627 compo.u.complex->generic->elementSpec->u.elementSetName =
1628 elementSetNames->u.generic;
1630 compo.u.complex->num_dbSpecific = 0;
1631 compo.u.complex->dbSpecific = 0;
1632 compo.u.complex->num_recordSyntax = 0;
1633 compo.u.complex->recordSyntax = 0;
1635 else if (elementSetNames)
1637 req->recordComposition = &compo;
1638 compo.which = Z_RecordComp_simple;
1639 compo.u.simple = elementSetNames;
1642 printf("Sent presentRequest (%d+%d).\n", setno, nos);
1646 static void close_session (void)
1652 nmem_destroy (session_mem);
1658 void process_close(Z_Close *req)
1660 Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
1661 Z_Close *res = apdu->u.close;
1663 static char *reasons[] =
1668 "cost limit reached",
1670 "security violation",
1677 printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
1678 req->diagnosticInformation ? req->diagnosticInformation : "NULL");
1683 *res->closeReason = Z_Close_finished;
1685 printf("Sent response.\n");
1690 static int cmd_show(char *arg)
1694 printf("Not connected yet\n");
1697 if (!send_presentRequest(arg))
1702 int cmd_quit(char *arg)
1704 printf("See you later, alligator.\n");
1710 int cmd_cancel(char *arg)
1712 Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
1713 Z_TriggerResourceControlRequest *req =
1714 apdu->u.triggerResourceControlRequest;
1719 printf("Session not initialized yet\n");
1722 if (!ODR_MASK_GET(session->options, Z_Options_triggerResourceCtrl))
1724 printf("Target doesn't support cancel (trigger resource ctrl)\n");
1727 *req->requestedAction = Z_TriggerResourceCtrl_cancel;
1728 req->resultSetWanted = &rfalse;
1731 printf("Sent cancel request\n");
1735 int send_scanrequest(const char *query, int pp, int num, const char *term)
1737 Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
1738 Z_ScanRequest *req = apdu->u.scanRequest;
1742 if (queryType == QueryType_CCL2RPN)
1746 struct ccl_rpn_node *rpn;
1748 rpn = ccl_find_str (bibset, query, &error, &pos);
1751 printf("CCL ERROR: %s\n", ccl_err_msg(error));
1755 bib1.proto = PROTO_Z3950;
1756 bib1.oclass = CLASS_ATTSET;
1757 bib1.value = VAL_BIB1;
1758 req->attributeSet = oid_ent_to_oid (&bib1, oid);
1759 if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
1761 printf("Couldn't convert CCL to Scan term\n");
1764 ccl_rpn_delete (rpn);
1766 if (use_rpn && !(req->termListAndStartPoint =
1767 p_query_scan(out, protocol, &req->attributeSet, query)))
1769 printf("Prefix query error\n");
1774 if (req->termListAndStartPoint->term &&
1775 req->termListAndStartPoint->term->which == Z_Term_general &&
1776 req->termListAndStartPoint->term->u.general)
1778 req->termListAndStartPoint->term->u.general->buf =
1779 (unsigned char *) odr_strdup(out, term);
1780 req->termListAndStartPoint->term->u.general->len =
1781 req->termListAndStartPoint->term->u.general->size =
1785 req->referenceId = set_refid (out);
1786 req->num_databaseNames = num_databaseNames;
1787 req->databaseNames = databaseNames;
1788 req->numberOfTermsRequested = #
1789 req->preferredPositionInResponse = &pp;
1794 int send_sortrequest(char *arg, int newset)
1796 Z_APDU *apdu = zget_APDU(out, Z_APDU_sortRequest);
1797 Z_SortRequest *req = apdu->u.sortRequest;
1798 Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
1799 odr_malloc (out, sizeof(*sksl));
1803 sprintf (setstring, "%d", setnumber);
1805 sprintf (setstring, "default");
1807 req->referenceId = set_refid (out);
1809 req->num_inputResultSetNames = 1;
1810 req->inputResultSetNames = (Z_InternationalString **)
1811 odr_malloc (out, sizeof(*req->inputResultSetNames));
1812 req->inputResultSetNames[0] = odr_strdup (out, setstring);
1814 if (newset && setnumber >= 0)
1815 sprintf (setstring, "%d", ++setnumber);
1817 req->sortedResultSetName = odr_strdup (out, setstring);
1819 req->sortSequence = yaz_sort_spec (out, arg);
1820 if (!req->sortSequence)
1822 printf ("Missing sort specifications\n");
1829 void display_term(Z_TermInfo *t)
1831 if (t->term->which == Z_Term_general)
1833 printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
1834 sprintf(last_scan_line, "%.*s", t->term->u.general->len,
1835 t->term->u.general->buf);
1838 printf("Term (not general)");
1839 if (t->globalOccurrences)
1840 printf (" (%d)\n", *t->globalOccurrences);
1845 void process_scanResponse(Z_ScanResponse *res)
1848 Z_Entry **entries = NULL;
1849 int num_entries = 0;
1851 printf("Received ScanResponse\n");
1852 print_refid (res->referenceId);
1853 printf("%d entries", *res->numberOfEntriesReturned);
1854 if (res->positionOfTerm)
1855 printf (", position=%d", *res->positionOfTerm);
1857 if (*res->scanStatus != Z_Scan_success)
1858 printf("Scan returned code %d\n", *res->scanStatus);
1861 if ((entries = res->entries->entries))
1862 num_entries = res->entries->num_entries;
1863 for (i = 0; i < num_entries; i++)
1865 int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
1866 if (entries[i]->which == Z_Entry_termInfo)
1868 printf("%c ", i + 1 == pos_term ? '*' : ' ');
1869 display_term(entries[i]->u.termInfo);
1872 display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1);
1874 if (res->entries->nonsurrogateDiagnostics)
1875 display_diagrecs (res->entries->nonsurrogateDiagnostics,
1876 res->entries->num_nonsurrogateDiagnostics);
1879 void process_sortResponse(Z_SortResponse *res)
1881 printf("Received SortResponse: status=");
1882 switch (*res->sortStatus)
1884 case Z_SortStatus_success:
1885 printf ("success"); break;
1886 case Z_SortStatus_partial_1:
1887 printf ("partial"); break;
1888 case Z_SortStatus_failure:
1889 printf ("failure"); break;
1891 printf ("unknown (%d)", *res->sortStatus);
1894 print_refid (res->referenceId);
1895 if (res->diagnostics)
1896 display_diagrecs(res->diagnostics,
1897 res->num_diagnostics);
1900 void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res)
1902 printf("Got deleteResultSetResponse status=%d\n",
1903 *res->deleteOperationStatus);
1904 if (res->deleteListStatuses)
1907 for (i = 0; i < res->deleteListStatuses->num; i++)
1909 printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id,
1910 *res->deleteListStatuses->elements[i]->status);
1915 int cmd_sort_generic(char *arg, int newset)
1919 printf("Session not initialized yet\n");
1922 if (!ODR_MASK_GET(session->options, Z_Options_sort))
1924 printf("Target doesn't support sort\n");
1929 if (send_sortrequest(arg, newset) < 0)
1936 int cmd_sort(char *arg)
1938 return cmd_sort_generic (arg, 0);
1941 int cmd_sort_newset (char *arg)
1943 return cmd_sort_generic (arg, 1);
1946 int cmd_scan(char *arg)
1950 printf("Session not initialized yet\n");
1953 if (!ODR_MASK_GET(session->options, Z_Options_scan))
1955 printf("Target doesn't support scan\n");
1960 strcpy (last_scan_query, arg);
1961 if (send_scanrequest(arg, 1, 20, 0) < 0)
1966 if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0)
1972 int cmd_schema(char *arg)
1979 schema = oid_getvalbyname (arg);
1980 if (schema == VAL_NONE)
1982 printf ("unknown schema\n");
1988 int cmd_format(char *arg)
1992 printf("Usage: format <recordsyntax>\n");
1995 recordsyntax = oid_getvalbyname (arg);
1996 if (recordsyntax == VAL_NONE)
1998 printf ("unknown record syntax\n");
2004 int cmd_elements(char *arg)
2006 static Z_ElementSetNames esn;
2007 static char what[100];
2011 elementSetNames = 0;
2015 esn.which = Z_ElementSetNames_generic;
2016 esn.u.generic = what;
2017 elementSetNames = &esn;
2021 int cmd_attributeset(char *arg)
2027 printf("Usage: attributeset <setname>\n");
2030 sscanf(arg, "%s", what);
2031 if (p_query_attset (what))
2033 printf("Unknown attribute set name\n");
2039 int cmd_querytype (char *arg)
2041 if (!strcmp (arg, "ccl"))
2042 queryType = QueryType_CCL;
2043 else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn"))
2044 queryType = QueryType_Prefix;
2045 else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
2046 queryType = QueryType_CCL2RPN;
2049 printf ("Querytype must be one of:\n");
2050 printf (" prefix - Prefix query\n");
2051 printf (" ccl - CCL query\n");
2052 printf (" ccl2rpn - CCL query converted to RPN\n");
2058 int cmd_refid (char *arg)
2064 refid = (char *) xmalloc (strlen(arg)+1);
2065 strcpy (refid, arg);
2070 int cmd_close(char *arg)
2077 apdu = zget_APDU(out, Z_APDU_close);
2078 req = apdu->u.close;
2079 *req->closeReason = Z_Close_finished;
2081 printf("Sent close request.\n");
2086 int cmd_packagename(char* arg)
2088 xfree (esPackageName);
2089 esPackageName = NULL;
2092 esPackageName = (char *) xmalloc (strlen(arg)+1);
2093 strcpy (esPackageName, arg);
2098 int cmd_proxy(char* arg)
2101 printf("Current proxy is `%s'\n", (yazCharset)?yazProxy:NULL);
2108 yazProxy = (char *) xmalloc (strlen(arg)+1);
2109 strcpy (yazProxy, arg);
2114 int cmd_charset(char* arg)
2117 printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL);
2124 yazCharset = (char *) xmalloc (strlen(arg)+1);
2125 strcpy (yazCharset, arg);
2130 int cmd_lang(char* arg)
2133 printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
2140 yazLang = (char *) xmalloc (strlen(arg)+1);
2141 strcpy (yazLang, arg);
2146 int cmd_source(char* arg)
2148 /* first should open the file and read one line at a time.. */
2150 char line[1024], *cp;
2153 char* args_end=(arg)+strlen(arg)-1;
2154 while(isspace(*args_end))
2159 REMOVE_TAILING_BLANKS(arg);
2162 fprintf(stderr,"Error in source command use a filename\n");
2166 includeFile = fopen (arg, "r");
2169 fprintf(stderr,"Unable to open file %s for reading\n",arg);
2173 while(!feof(includeFile)) {
2174 memset(line,0,sizeof(line));
2175 fgets(line,sizeof(line),includeFile);
2177 if(strlen(line) < 2) continue;
2178 if(line[0] == '#') continue;
2180 if ((cp = strrchr (line, '\n')))
2183 process_cmd_line(line);
2186 if(fclose(includeFile)<0) {
2187 perror("unable to close include file");
2193 int cmd_subshell(char* args)
2198 system(getenv("SHELL"));
2204 int cmd_set_apdufile(char* arg)
2206 REMOVE_TAILING_BLANKS(arg);
2208 if(apdu_file && apdu_file != stderr) { /* don't close stdout*/
2209 perror("unable to close apdu log file");
2217 if(!strcmp(arg,"-"))
2220 apdu_file=fopen(arg, "a");
2223 perror("unable to open apdu log file no apdu log loaded");
2225 odr_setprint(print, apdu_file);
2231 int cmd_set_cclfields(char* arg)
2235 REMOVE_TAILING_BLANKS(arg);
2237 bibset = ccl_qual_mk ();
2238 inf = fopen (arg, "r");
2241 ccl_qual_file (bibset, inf);
2248 int cmd_set_marcdump(char* arg)
2250 if(marcdump && marcdump != stderr) { /* don't close stdout*/
2251 perror("unable to close apdu log file");
2259 if(!strcmp(arg,"-"))
2262 marcdump=fopen(arg, "a");
2265 perror("unable to open apdu marcdump file no marcdump done\n");
2271 int cmd_set_proxy(char* arg) {
2272 if(yazProxy) free(yazProxy);
2275 if(strlen(arg) > 1) {
2276 yazProxy=strdup(arg);
2282 this command takes 3 arge {name class oid}
2284 int cmd_register_oid(char* args) {
2289 {"appctx",CLASS_APPCTX},
2290 {"absyn",CLASS_ABSYN},
2291 {"attset",CLASS_ATTSET},
2292 {"transyn",CLASS_TRANSYN},
2293 {"diagset",CLASS_DIAGSET},
2294 {"recsyn",CLASS_RECSYN},
2295 {"resform",CLASS_RESFORM},
2296 {"accform",CLASS_ACCFORM},
2297 {"extserv",CLASS_EXTSERV},
2298 {"userinfo",CLASS_USERINFO},
2299 {"elemspec",CLASS_ELEMSPEC},
2300 {"varset",CLASS_VARSET},
2301 {"schema",CLASS_SCHEMA},
2302 {"tagset",CLASS_TAGSET},
2303 {"general",CLASS_GENERAL},
2306 char oname_str[101], oclass_str[101], oid_str[101];
2309 oid_class oidclass = CLASS_GENERAL;
2310 int val = 0, oid[OID_SIZE];
2311 struct oident * new_oident=NULL;
2313 if (sscanf (args, "%100[^ ] %100[^ ] %100s",
2314 oname_str,oclass_str, oid_str) < 1) {
2315 printf("Error in regristrate command \n");
2319 for (i = 0; oid_classes[i].className; i++) {
2320 if (!strcmp(oid_classes[i].className, oclass_str))
2322 oidclass=oid_classes[i].oclass;
2327 if(!(oid_classes[i].className)) {
2328 printf("Unknonwn oid class %s\n",oclass_str);
2336 while (isdigit (*name))
2338 val = val*10 + (*name - '0');
2351 new_oident=oid_addent (oid,PROTO_GENERAL,oidclass,oname_str,VAL_DYNAMIC);
2352 if(strcmp(new_oident->desc,oname_str)) {
2353 fprintf(stderr,"oid is already named as %s, regristration faild\n",
2359 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()
2372 /* Look for a $HOME/.yazclientrc and source it if it exists */
2373 struct stat statbuf;
2375 char* homedir=getenv("HOME");
2377 if(!homedir) return;
2379 sprintf(buffer,"%s/.yazclientrc",homedir);
2381 if(stat(buffer,&statbuf)==0) {
2385 if(stat(".yazclientrc",&statbuf)==0) {
2386 cmd_source(".yazclientrc");
2391 static void initialize(void)
2396 if (!(out = odr_createmem(ODR_ENCODE)) ||
2397 !(in = odr_createmem(ODR_DECODE)) ||
2398 !(print = odr_createmem(ODR_PRINT)))
2400 fprintf(stderr, "failed to allocate ODR streams\n");
2405 setvbuf(stdout, 0, _IONBF, 0);
2407 odr_setprint(print, apdu_file);
2410 bibset = ccl_qual_mk ();
2411 inf = fopen (ccl_fields, "r");
2414 ccl_qual_file (bibset, inf);
2418 cmd_base("Default");
2420 #if HAVE_READLINE_READLINE_H
2421 rl_attempted_completion_function = (CPPFunction*)readline_completer;
2428 #if HAVE_GETTIMEOFDAY
2429 struct timeval tv_start, tv_end;
2432 void wait_and_handle_responce()
2437 int netbufferlen = 0;
2445 if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
2447 printf("Target closed connection\n");
2453 printf("Target closed connection.\n");
2457 odr_reset(in); /* release APDU from last round */
2459 odr_setbuf(in, netbuffer, res, 0);
2460 if (!z_APDU(in, &apdu, 0, 0))
2462 odr_perror(in, "Decoding incoming APDU");
2463 fprintf(stderr, "[Near %d]\n", odr_offset(in));
2464 fprintf(stderr, "Packet dump:\n---------\n");
2465 odr_dumpBER(stderr, netbuffer, res);
2466 fprintf(stderr, "---------\n");
2468 z_APDU(print, &apdu, 0, 0);
2472 if (apdu_file && !z_APDU(print, &apdu, 0, 0))
2474 odr_perror(print, "Failed to print incoming APDU");
2480 case Z_APDU_initResponse:
2481 process_initResponse(apdu->u.initResponse);
2483 case Z_APDU_searchResponse:
2484 process_searchResponse(apdu->u.searchResponse);
2486 case Z_APDU_scanResponse:
2487 process_scanResponse(apdu->u.scanResponse);
2489 case Z_APDU_presentResponse:
2490 print_refid (apdu->u.presentResponse->referenceId);
2492 *apdu->u.presentResponse->numberOfRecordsReturned;
2493 if (apdu->u.presentResponse->records)
2494 display_records(apdu->u.presentResponse->records);
2496 printf("No records.\n");
2497 printf ("nextResultSetPosition = %d\n",
2498 *apdu->u.presentResponse->nextResultSetPosition);
2500 case Z_APDU_sortResponse:
2501 process_sortResponse(apdu->u.sortResponse);
2503 case Z_APDU_extendedServicesResponse:
2504 printf("Got extended services response\n");
2505 process_ESResponse(apdu->u.extendedServicesResponse);
2508 printf("Target has closed the association.\n");
2509 process_close(apdu->u.close);
2511 case Z_APDU_resourceControlRequest:
2512 process_resourceControlRequest
2513 (apdu->u.resourceControlRequest);
2515 case Z_APDU_deleteResultSetResponse:
2516 process_deleteResultSetResponse(apdu->u.
2517 deleteResultSetResponse);
2520 printf("Received unknown APDU type (%d).\n",
2525 while (conn && cs_more(conn));
2526 #if HAVE_GETTIMEOFDAY
2527 gettimeofday (&tv_end, 0);
2529 printf ("S/U S/U=%ld/%ld %ld/%ld",
2530 (long) tv_start.tv_sec,
2531 (long) tv_start.tv_usec,
2532 (long) tv_end.tv_sec,
2533 (long) tv_end.tv_usec);
2535 printf ("Elapsed: %.6f\n",
2536 (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
2537 ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
2544 static int cmd_help (char *line);
2546 typedef char *(*completerFunctionType)(const char *text, int state);
2550 int (*fun)(char *arg);
2552 completerFunctionType rl_completerfunction;
2553 //char *(*rl_completerfunction)(const char *text, int state);
2554 int complete_filenames;
2555 char **local_tabcompletes;
2557 {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0,NULL},
2558 {"quit", cmd_quit, "",NULL,0,NULL},
2559 {"find", cmd_find, "<query>",NULL,0,NULL},
2560 {"delete", cmd_delete, "<setname>",NULL,0,NULL},
2561 {"base", cmd_base, "<base-name>",NULL,0,NULL},
2562 {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0,NULL},
2563 {"scan", cmd_scan, "<term>",NULL,0,NULL},
2564 {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
2565 {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
2566 {"authentication", cmd_authentication, "<acctstring>",NULL,0,NULL},
2567 {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0,NULL},
2568 {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0,NULL},
2569 {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0,NULL},
2570 {"status", cmd_status, "",NULL,0,NULL},
2571 {"setnames", cmd_setnames, "",NULL,0,NULL},
2572 {"cancel", cmd_cancel, "",NULL,0,NULL},
2573 {"format", cmd_format, "<recordsyntax>",complete_format,0,NULL},
2574 {"schema", cmd_schema, "<schema>",complete_schema,0,NULL},
2575 {"elements", cmd_elements, "<elementSetName>",NULL,0,NULL},
2576 {"close", cmd_close, "",NULL,0,NULL},
2577 {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0,NULL},
2578 {"querytype", cmd_querytype, "<type>",complete_querytype,0,NULL},
2579 {"refid", cmd_refid, "<id>",NULL,0,NULL},
2580 {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0,NULL},
2581 {"update", cmd_update, "<item>",NULL,0,NULL},
2582 {"packagename", cmd_packagename, "<packagename>",NULL,0,NULL},
2583 {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0,NULL},
2584 {"charset", cmd_charset, "<charset_name>",NULL,0,NULL},
2585 {"lang", cmd_lang, "<language_code>",NULL,0,NULL},
2586 {".", cmd_source, "<filename>",NULL,1,NULL},
2587 {"!", cmd_subshell, "Subshell command",NULL,1,NULL},
2588 {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,1,NULL},
2589 {"set_marcdump", cmd_set_marcdump," <filename>",NULL,1,NULL},
2590 {"set_cclfiele", cmd_set_cclfields," <filename>",NULL,1,NULL},
2591 {"register_oid", cmd_register_oid,"<name> <class> <oid>",NULL,0,NULL},
2592 {"push_command", cmd_push_command,"<command>",command_generator,0,NULL},
2593 {"register_tab", cmd_register_tab,"<commandname> <tab>",command_generator,0,NULL},
2594 /* Server Admin Functions */
2595 {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0,NULL},
2596 {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0,NULL},
2597 {"adm-create", cmd_adm_create, "",NULL,0,NULL},
2598 {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0,NULL},
2599 {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0,NULL},
2600 {"adm-refresh", cmd_adm_refresh, "",NULL,0,NULL},
2601 {"adm-commit", cmd_adm_commit, "",NULL,0,NULL},
2602 {"adm-shutdown", cmd_adm_shutdown, "",NULL,0,NULL},
2603 {"adm-startup", cmd_adm_startup, "",NULL,0,NULL},
2604 {"help", cmd_help, "", NULL,0,NULL},
2608 static int cmd_help (char *line)
2614 sscanf (line, "%20s", topic);
2617 printf("Commands:\n");
2618 for (i = 0; cmd[i].cmd; i++)
2619 if (*topic == 0 || strcmp (topic, cmd[i].cmd) == 0)
2620 printf(" %s %s\n", cmd[i].cmd, cmd[i].ad);
2621 if (strcmp (topic, "find") == 0)
2624 printf (" \"term\" Simple Term\n");
2625 printf (" @attr [attset] type=value op Attribute\n");
2626 printf (" @and opl opr And\n");
2627 printf (" @or opl opr Or\n");
2628 printf (" @not opl opr And-Not\n");
2629 printf (" @set set Result set\n");
2631 printf ("Bib-1 attribute types\n");
2633 printf ("4=Title 7=ISBN 8=ISSN 30=Date 62=Abstract 1003=Author 1016=Any\n");
2634 printf ("2=Relation: ");
2635 printf ("1< 2<= 3= 4>= 5> 6!= 102=Relevance\n");
2636 printf ("3=Position: ");
2637 printf ("1=First in Field 2=First in subfield 3=Any position\n");
2638 printf ("4=Structure: ");
2639 printf ("1=Phrase 2=Word 3=Key 4=Year 5=Date 6=WordList\n");
2640 printf ("5=Truncation: ");
2641 printf ("1=Right 2=Left 3=L&R 100=No 101=# 102=Re-1 103=Re-2\n");
2642 printf ("6=Completeness:");
2643 printf ("1=Incomplete subfield 2=Complete subfield 3=Complete field\n");
2648 int cmd_register_tab(char* arg) {
2650 char command[101], tabargument[101];
2655 if (sscanf (arg, "%100s %100s", command, tabargument) < 1) {
2659 /* locate the amdn in the list */
2660 for (i = 0; cmd[i].cmd; i++) {
2661 if (!strncmp(cmd[i].cmd, command, strlen(command))) {
2667 fprintf(stderr,"Unknown command %s\n",command);
2673 if(!cmd[i].local_tabcompletes) {
2674 cmd[i].local_tabcompletes = calloc(1,sizeof(char**));
2679 tabslist = cmd[i].local_tabcompletes;
2680 for(;tabslist && *tabslist;tabslist++) {
2684 cmd[i].local_tabcompletes=realloc(cmd[i].local_tabcompletes,(num_of_tabs+2)*sizeof(char**));
2685 tabslist=cmd[i].local_tabcompletes;
2686 tabslist[num_of_tabs]=strdup(tabargument);
2687 tabslist[num_of_tabs+1]=NULL;
2691 void process_cmd_line(char* line)
2694 char word[32], arg[1024];
2696 #if HAVE_GETTIMEOFDAY
2697 gettimeofday (&tv_start, 0);
2700 if ((res = sscanf(line, "%31s %1023[^;]", word, arg)) <= 0)
2702 strcpy(word, last_cmd);
2707 strcpy(last_cmd, word);
2709 /* removed tailing spaces from the arg command */
2712 char* lastnonspace=NULL;
2721 *(++lastnonspace) = 0;
2725 for (i = 0; cmd[i].cmd; i++)
2726 if (!strncmp(cmd[i].cmd, word, strlen(word)))
2728 res = (*cmd[i].fun)(arg);
2732 if (!cmd[i].cmd) /* dump our help-screen */
2734 printf("Unknown command: %s.\n", word);
2739 if(apdu_file) fflush(apdu_file);
2742 wait_and_handle_responce();
2751 char *command_generator(const char *text, int state)
2757 for( ; cmd[idx].cmd; ++idx) {
2758 if (!strncmp(cmd[idx].cmd,text,strlen(text))) {
2759 ++idx; /* skip this entry on the next run */
2760 return strdup(cmd[idx-1].cmd);
2768 This function only known how to complete on the first word
2770 char ** readline_completer(char *text, int start, int end) {
2771 #if HAVE_READLINE_READLINE_H
2773 completerFunctionType completerToUse;
2776 #if HAVE_READLINE_RL_COMPLETION_MATCHES
2777 char** res=rl_completion_matches(text,
2780 char** res=completion_matches(text,
2781 (CPFunction*)command_generator);
2783 rl_attempted_completion_over = 1;
2786 char arg[1024],word[32];
2788 if ((res = sscanf(rl_line_buffer, "%31s %1023[^;]", word, arg)) <= 0) {
2789 rl_attempted_completion_over = 1;
2793 if(start != strlen(word) +1 ) {
2794 rl_attempted_completion_over = 1;
2797 for (i = 0; cmd[i].cmd; i++) {
2798 if (!strncmp(cmd[i].cmd, word, strlen(word))) {
2803 if(!cmd[i].cmd) return NULL;
2806 curret_global_list = cmd[i].local_tabcompletes;
2808 completerToUse = cmd[i].rl_completerfunction;
2809 if(completerToUse==NULL) /* if no pr. command completer is defined use the default completer */
2810 completerToUse = default_completer;
2812 if(completerToUse) {
2813 #ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
2815 rl_completion_matches(text,
2819 completion_matches(text,
2820 (CPFunction*)completerToUse);
2822 if(!cmd[i].complete_filenames)
2823 rl_attempted_completion_over = 1;
2826 if(!cmd[i].complete_filenames)
2827 rl_attempted_completion_over = 1;
2837 static void client(void)
2843 #if HAVE_GETTIMEOFDAY
2844 gettimeofday (&tv_start, 0);
2849 char *line_in = NULL;
2850 #if HAVE_READLINE_READLINE_H
2853 line_in=readline(C_PROMPT);
2856 #if HAVE_READLINE_HISTORY_H
2858 add_history(line_in);
2860 strncpy(line, line_in, 1023);
2869 if (!fgets(line, 1023, stdin))
2871 if ((end_p = strchr (line, '\n')))
2874 process_cmd_line(line);
2878 int main(int argc, char **argv)
2881 char *open_command = 0;
2882 char *auth_command = 0;
2886 while ((ret = options("k:c:a:m:v:p:u:", argv, argc, &arg)) != -2)
2893 open_command = (char *) xmalloc (strlen(arg)+6);
2894 strcpy (open_command, "open ");
2895 strcat (open_command, arg);
2899 kilobytes = atoi(arg);
2902 if (!(marcdump = fopen (arg, "a")))
2909 strncpy (ccl_fields, arg, sizeof(ccl_fields)-1);
2910 ccl_fields[sizeof(ccl_fields)-1] = '\0';
2913 if (!strcmp(arg, "-"))
2916 apdu_file=fopen(arg, "a");
2919 yazProxy=strdup(arg);
2924 auth_command = (char *) xmalloc (strlen(arg)+6);
2925 strcpy (auth_command, "auth ");
2926 strcat (auth_command, arg);
2930 yaz_log_init (yaz_log_mask_str(arg), "", NULL);
2933 fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
2934 "[-c cclfields]\n [-p <proxy-addr>] [-u <auth>] "
2935 "[-k size] [<server-addr>]\n",
2943 #ifdef HAVE_GETTIMEOFDAY
2944 gettimeofday (&tv_start, 0);
2946 process_cmd_line (auth_command);
2947 #if HAVE_READLINE_HISTORY_H
2948 add_history(auth_command);
2950 xfree(auth_command);
2954 #ifdef HAVE_GETTIMEOFDAY
2955 gettimeofday (&tv_start, 0);
2957 process_cmd_line (open_command);
2958 #if HAVE_READLINE_HISTORY_H
2959 add_history(open_command);
2961 xfree(open_command);