2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: client.c,v 1.159 2002-06-17 14:57:34 ja7 Exp $
12 #include <yaz/yaz-util.h>
14 #include <yaz/tcpip.h>
16 #include <yaz/xmosi.h>
19 #include <yaz/proto.h>
20 #include <yaz/marcdisp.h>
21 #include <yaz/diagbib1.h>
22 #include <yaz/otherinfo.h>
23 #include <yaz/charneg.h>
25 #include <yaz/pquery.h>
26 #include <yaz/sortspec.h>
30 #include <yaz/yaz-ccl.h>
32 #if HAVE_READLINE_READLINE_H
33 #include <readline/readline.h>
35 #if HAVE_READLINE_HISTORY_H
36 #include <readline/history.h>
43 #include "tabcomplete.h"
45 #define C_PROMPT "Z> "
47 static ODR out, in, print; /* encoding and decoding streams */
48 static FILE *apdu_file = 0;
49 static COMSTACK conn = 0; /* our z-association */
50 static Z_IdAuthentication *auth = 0; /* our current auth definition */
51 char *databaseNames[128];
52 int num_databaseNames = 0;
53 static Z_External *record_last = 0;
54 static int setnumber = -1; /* current result set number */
55 static int smallSetUpperBound = 0;
56 static int largeSetLowerBound = 1;
57 static int mediumSetPresentNumber = 0;
58 static Z_ElementSetNames *elementSetNames = 0;
59 static int setno = 1; /* current set offset */
60 static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */
61 static enum oid_value recordsyntax = VAL_USMARC;
62 static enum oid_value schema = VAL_NONE;
63 static int sent_close = 0;
64 static NMEM session_mem = NULL; /* memory handle for init-response */
65 static Z_InitResponse *session = 0; /* session parameters */
66 static char last_scan_line[512] = "0";
67 static char last_scan_query[512] = "0";
68 static char ccl_fields[512] = "default.bib";
69 static char* esPackageName = 0;
70 static char* yazProxy = 0;
71 static int kilobytes = 1024;
72 static char* yazCharset = 0;
73 static char* yazLang = 0;
76 static char last_cmd[32] = "?";
77 static FILE *marcdump = 0;
78 static char *refid = NULL;
86 static QueryType queryType = QueryType_Prefix;
88 static CCL_bibset bibset; /* CCL bibset handle */
90 #if HAVE_READLINE_COMPLETION_OVER
93 /* readline doesn't have this var. Define it ourselves. */
94 int rl_attempted_completion_over = 0;
97 /* set this one to 1, to avoid decode of unknown MARCs */
98 #define AVOID_MARC_DECODE 1
100 /* nice helper macro as extensive tabbing gives spaces at the en of the args lines */
101 #define REMOVE_TAILING_BLANKS(a) {\
102 char* args_end=(a)+strlen(a)-1; \
103 while(isspace(*args_end)) {*args_end=0;--args_end;}; \
107 void process_cmd_line(char* line);
108 char ** readline_completer(char *text, int start, int end);
109 char *command_generator(const char *text, int state);
110 char** curret_global_list=NULL;
111 int cmd_register_tab(char* arg);
113 ODR getODROutputStream()
118 void send_apdu(Z_APDU *a)
125 z_APDU(print, &a, 0, 0);
128 if (!z_APDU(out, &a, 0, 0))
130 odr_perror(out, "Encoding APDU");
133 buf = odr_getbuf(out, &len, 0);
134 /* printf ("sending APDU of size %d\n", len); */
135 if (cs_put(conn, buf, len) < 0)
137 fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn)));
140 odr_reset(out); /* release the APDU structure */
143 static void print_stringn(const unsigned char *buf, size_t len)
146 for (i = 0; i<len; i++)
147 if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
148 printf ("%c", buf[i]);
150 printf ("\\X%02X", buf[i]);
153 static void print_refid (Z_ReferenceId *id)
157 printf ("Reference Id: ");
158 print_stringn (id->buf, id->len);
163 static Z_ReferenceId *set_refid (ODR out)
168 id = (Z_ReferenceId *) odr_malloc (out, sizeof(*id));
169 id->size = id->len = strlen(refid);
170 id->buf = (unsigned char *) odr_malloc (out, id->len);
171 memcpy (id->buf, refid, id->len);
175 /* INIT SERVICE ------------------------------- */
177 static void send_initRequest(const char* type_and_host)
179 Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest);
180 Z_InitRequest *req = apdu->u.initRequest;
182 ODR_MASK_SET(req->options, Z_Options_search);
183 ODR_MASK_SET(req->options, Z_Options_present);
184 ODR_MASK_SET(req->options, Z_Options_namedResultSets);
185 ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl);
186 ODR_MASK_SET(req->options, Z_Options_scan);
187 ODR_MASK_SET(req->options, Z_Options_sort);
188 ODR_MASK_SET(req->options, Z_Options_extendedServices);
189 ODR_MASK_SET(req->options, Z_Options_delSet);
191 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
192 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
193 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
195 *req->maximumRecordSize = 1024*kilobytes;
196 *req->preferredMessageSize = 1024*kilobytes;
198 req->idAuthentication = auth;
200 req->referenceId = set_refid (out);
203 yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
206 if (yazCharset || yazLang) {
207 Z_OtherInformation **p;
208 Z_OtherInformationUnit *p0;
210 yaz_oi_APDU(apdu, &p);
212 if (p0=yaz_oi_update(p, out, NULL, 0, 0)) {
213 ODR_MASK_SET(req->options, Z_Options_negotiationModel);
215 p0->which = Z_OtherInfo_externallyDefinedInfo;
216 p0->information.externallyDefinedInfo =
217 yaz_set_proposal_charneg(out,
218 (const char**)&yazCharset, (yazCharset)?1:0,
219 (const char**)&yazLang, (yazLang)?1:0, 1);
224 printf("Sent initrequest.\n");
227 static int process_initResponse(Z_InitResponse *res)
229 /* save session parameters for later use */
230 session_mem = odr_extract_mem(in);
234 printf("Connection rejected by target.\n");
236 printf("Connection accepted by target.\n");
237 if (res->implementationId)
238 printf("ID : %s\n", res->implementationId);
239 if (res->implementationName)
240 printf("Name : %s\n", res->implementationName);
241 if (res->implementationVersion)
242 printf("Version: %s\n", res->implementationVersion);
243 if (res->userInformationField)
245 printf("UserInformationfield:\n");
246 if (!z_External(print, (Z_External**)&res-> userInformationField,
249 odr_perror(print, "Printing userinfo\n");
252 if (res->userInformationField->which == Z_External_octet)
254 printf("Guessing visiblestring:\n");
255 printf("'%s'\n", res->userInformationField->u. octet_aligned->buf);
260 if (ODR_MASK_GET(res->options, Z_Options_search))
262 if (ODR_MASK_GET(res->options, Z_Options_present))
264 if (ODR_MASK_GET(res->options, Z_Options_delSet))
266 if (ODR_MASK_GET(res->options, Z_Options_resourceReport))
267 printf (" resourceReport");
268 if (ODR_MASK_GET(res->options, Z_Options_resourceCtrl))
269 printf (" resourceCtrl");
270 if (ODR_MASK_GET(res->options, Z_Options_accessCtrl))
271 printf (" accessCtrl");
272 if (ODR_MASK_GET(res->options, Z_Options_scan))
274 if (ODR_MASK_GET(res->options, Z_Options_sort))
276 if (ODR_MASK_GET(res->options, Z_Options_extendedServices))
277 printf (" extendedServices");
278 if (ODR_MASK_GET(res->options, Z_Options_level_1Segmentation))
279 printf (" level1Segmentation");
280 if (ODR_MASK_GET(res->options, Z_Options_level_2Segmentation))
281 printf (" level2Segmentation");
282 if (ODR_MASK_GET(res->options, Z_Options_concurrentOperations))
283 printf (" concurrentOperations");
284 if (ODR_MASK_GET(res->options, Z_Options_namedResultSets))
286 printf (" namedResultSets");
289 if (ODR_MASK_GET(res->options, Z_Options_encapsulation))
290 printf (" encapsulation");
291 if (ODR_MASK_GET(res->options, Z_Options_resultCount))
292 printf (" resultCount");
293 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel))
294 printf (" negotiationModel");
295 if (ODR_MASK_GET(res->options, Z_Options_duplicateDetection))
296 printf (" duplicateDetection");
297 if (ODR_MASK_GET(res->options, Z_Options_queryType104))
298 printf (" queryType104");
301 if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) {
303 Z_CharSetandLanguageNegotiation *p =
304 yaz_get_charneg_record(res->otherInfo);
308 char *charset=NULL, *lang=NULL;
311 yaz_get_response_charneg(session_mem, p, &charset, &lang, &selected);
313 printf("Accepted character set : `%s'\n", charset);
314 printf("Accepted code language : `%s'\n", lang);
315 printf("Accepted records in ...: %d\n", selected );
322 static int cmd_base(char *arg)
329 printf("Usage: base <database> <database> ...\n");
332 for (i = 0; i<num_databaseNames; i++)
333 xfree (databaseNames[i]);
334 num_databaseNames = 0;
337 if (!(cp = strchr(arg, ' ')))
338 cp = arg + strlen(arg);
341 databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
342 memcpy (databaseNames[num_databaseNames], arg, cp - arg);
343 databaseNames[num_databaseNames++][cp - arg] = '\0';
351 int cmd_open(char *arg)
354 char type_and_host[101], base[101];
359 printf("Already connected.\n");
365 nmem_destroy (session_mem);
369 if (strncmp (arg, "unix:", 5) == 0)
372 conn = cs_create_host(arg, 1, &add);
378 if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1)
382 conn = cs_create_host(yazProxy, 1, &add);
384 conn = cs_create_host(type_and_host, 1, &add);
389 printf ("Couldn't create comstack\n");
392 printf("Connecting...");
394 if (cs_connect(conn, add) < 0)
396 printf ("error = %s\n", cs_strerror(conn));
397 if (conn->cerrno == CSYSERR)
405 send_initRequest(type_and_host);
411 int cmd_authentication(char *arg)
413 static Z_IdAuthentication au;
414 static char user[40], group[40], pass[40];
415 static Z_IdPass idPass;
420 printf("Auth field set to null\n");
424 r = sscanf (arg, "%39s %39s %39s", user, group, pass);
427 printf("Auth field set to null\n");
433 au.which = Z_IdAuthentication_open;
439 au.which = Z_IdAuthentication_idPass;
440 au.u.idPass = &idPass;
441 idPass.groupId = NULL;
442 idPass.userId = user;
443 idPass.password = group;
448 au.which = Z_IdAuthentication_idPass;
449 au.u.idPass = &idPass;
450 idPass.groupId = group;
451 idPass.userId = user;
452 idPass.password = pass;
457 /* SEARCH SERVICE ------------------------------ */
458 static void display_record(Z_External *r);
460 static void display_variant(Z_Variant *v, int level)
464 for (i = 0; i < v->num_triples; i++)
466 printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
467 *v->triples[i]->type);
468 if (v->triples[i]->which == Z_Triple_internationalString)
469 printf(",value=%s\n", v->triples[i]->value.internationalString);
475 static void display_grs1(Z_GenericRecord *r, int level)
483 for (i = 0; i < r->num_elements; i++)
487 printf("%*s", level * 4, "");
491 printf("%d,", *t->tagType);
494 if (t->tagValue->which == Z_StringOrNumeric_numeric)
495 printf("%d) ", *t->tagValue->u.numeric);
497 printf("%s) ", t->tagValue->u.string);
498 if (t->content->which == Z_ElementData_subtree)
500 if (!t->content->u.subtree)
501 printf (" (no subtree)\n");
505 display_grs1(t->content->u.subtree, level+1);
508 else if (t->content->which == Z_ElementData_string)
509 printf("%s\n", t->content->u.string);
510 else if (t->content->which == Z_ElementData_numeric)
511 printf("%d\n", *t->content->u.numeric);
512 else if (t->content->which == Z_ElementData_oid)
514 int *ip = t->content->u.oid;
517 if ((oent = oid_getentbyoid(t->content->u.oid)))
518 printf("OID: %s\n", oent->desc);
522 while (ip && *ip >= 0)
523 printf(" %d", *(ip++));
527 else if (t->content->which == Z_ElementData_noDataRequested)
528 printf("[No data requested]\n");
529 else if (t->content->which == Z_ElementData_elementEmpty)
530 printf("[Element empty]\n");
531 else if (t->content->which == Z_ElementData_elementNotThere)
532 printf("[Element not there]\n");
533 else if (t->content->which == Z_ElementData_date)
534 printf("Date: %s\n", t->content->u.date);
535 else if (t->content->which == Z_ElementData_ext)
537 printf ("External\n");
538 display_record (t->content->u.ext);
541 printf("? type = %d\n",t->content->which);
542 if (t->appliedVariant)
543 display_variant(t->appliedVariant, level+1);
544 if (t->metaData && t->metaData->supportedVariants)
548 printf("%*s---- variant list\n", (level+1)*4, "");
549 for (c = 0; c < t->metaData->num_supportedVariants; c++)
551 printf("%*svariant #%d\n", (level+1)*4, "", c);
552 display_variant(t->metaData->supportedVariants[c], level + 2);
559 static void print_record(const unsigned char *buf, size_t len)
562 print_stringn (buf, len);
563 /* add newline if not already added ... */
564 if (i <= 0 || buf[i-1] != '\n')
568 static void display_record(Z_External *r)
570 oident *ent = oid_getentbyoid(r->direct_reference);
574 * Tell the user what we got.
576 if (r->direct_reference)
578 printf("Record type: ");
580 printf("%s\n", ent->desc);
581 else if (!odr_oid(print, &r->direct_reference, 0, 0))
583 odr_perror(print, "print oid");
587 /* Check if this is a known, ASN.1 type tucked away in an octet string */
588 if (ent && r->which == Z_External_octet)
590 Z_ext_typeent *type = z_ext_getentbyref(ent->value);
596 * Call the given decoder to process the record.
598 odr_setbuf(in, (char*)r->u.octet_aligned->buf,
599 r->u.octet_aligned->len, 0);
600 if (!(*type->fun)(in, (char **)&rr, 0, 0))
602 odr_perror(in, "Decoding constructed record.");
603 fprintf(stderr, "[Near %d]\n", odr_offset(in));
604 fprintf(stderr, "Packet dump:\n---------\n");
605 odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf,
606 r->u.octet_aligned->len);
607 fprintf(stderr, "---------\n");
611 * Note: we throw away the original, BER-encoded record here.
612 * Do something else with it if you want to keep it.
614 r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
615 r->which = type->what;
618 if (ent && ent->oclass != CLASS_RECSYN)
620 if (ent && ent->value == VAL_SOIF)
621 print_record((const unsigned char *) r->u.octet_aligned->buf,
622 r->u.octet_aligned->len);
623 else if (r->which == Z_External_octet && r->u.octet_aligned->len)
625 const char *octet_buf = (char*)r->u.octet_aligned->buf;
626 if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML ||
627 ent->value == VAL_HTML)
629 print_record((const unsigned char *) octet_buf,
630 r->u.octet_aligned->len);
632 else if (ent->value == VAL_POSTSCRIPT)
634 int size = r->u.octet_aligned->len;
637 print_record((const unsigned char *) octet_buf, size);
642 #if AVOID_MARC_DECODE
643 /* primitive check for a marc OID 5.1-29 except 16 */
644 ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
645 ent->oidsuffix[1] != 16
651 if (marc_display_exl (octet_buf, NULL, 0 /* debug */,
652 r->u.octet_aligned->len) <= 0)
654 printf ("bad MARC. Dumping as it is:\n");
655 print_record((const unsigned char*) octet_buf,
656 r->u.octet_aligned->len);
661 print_record((const unsigned char*) octet_buf,
662 r->u.octet_aligned->len);
666 fwrite (octet_buf, 1, r->u.octet_aligned->len, marcdump);
668 else if (ent && ent->value == VAL_SUTRS)
670 if (r->which != Z_External_sutrs)
672 printf("Expecting single SUTRS type for SUTRS.\n");
675 print_record(r->u.sutrs->buf, r->u.sutrs->len);
677 else if (ent && ent->value == VAL_GRS1)
679 if (r->which != Z_External_grs1)
681 printf("Expecting single GRS type for GRS.\n");
684 display_grs1(r->u.grs1, 0);
688 printf("Unknown record representation.\n");
689 if (!z_External(print, &r, 0, 0))
691 odr_perror(print, "Printing external");
697 static void display_diagrecs(Z_DiagRec **pp, int num)
701 Z_DefaultDiagFormat *r;
703 printf("Diagnostic message(s) from database:\n");
704 for (i = 0; i<num; i++)
706 Z_DiagRec *p = pp[i];
707 if (p->which != Z_DiagRec_defaultFormat)
709 printf("Diagnostic record not in default format.\n");
713 r = p->u.defaultFormat;
714 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
715 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
716 printf("Missing or unknown diagset\n");
717 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
720 case Z_DefaultDiagFormat_v2Addinfo:
721 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
723 case Z_DefaultDiagFormat_v3Addinfo:
724 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
731 static void display_nameplusrecord(Z_NamePlusRecord *p)
734 printf("[%s]", p->databaseName);
735 if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
736 display_diagrecs(&p->u.surrogateDiagnostic, 1);
737 else if (p->which == Z_NamePlusRecord_databaseRecord)
738 display_record(p->u.databaseRecord);
741 static void display_records(Z_Records *p)
745 if (p->which == Z_Records_NSD)
747 Z_DiagRec dr, *dr_p = &dr;
748 dr.which = Z_DiagRec_defaultFormat;
749 dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
750 display_diagrecs (&dr_p, 1);
752 else if (p->which == Z_Records_multipleNSD)
753 display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
754 p->u.multipleNonSurDiagnostics->num_diagRecs);
757 printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
758 for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
759 display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
763 static int send_deleteResultSetRequest(char *arg)
768 Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
769 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
771 req->referenceId = set_refid (out);
773 req->num_resultSetList =
774 sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
775 names[0], names[1], names[2], names[3],
776 names[4], names[5], names[6], names[7]);
778 req->deleteFunction = (int *)
779 odr_malloc (out, sizeof(*req->deleteFunction));
780 if (req->num_resultSetList > 0)
782 *req->deleteFunction = Z_DeleteRequest_list;
783 req->resultSetList = (char **)
784 odr_malloc (out, sizeof(*req->resultSetList)*
785 req->num_resultSetList);
786 for (i = 0; i<req->num_resultSetList; i++)
787 req->resultSetList[i] = names[i];
791 *req->deleteFunction = Z_DeleteRequest_all;
792 req->resultSetList = 0;
796 printf("Sent deleteResultSetRequest.\n");
800 static int send_searchRequest(char *arg)
802 Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
803 Z_SearchRequest *req = apdu->u.searchRequest;
806 struct ccl_rpn_node *rpn = NULL;
809 Z_RPNQuery *RPNquery;
812 if (queryType == QueryType_CCL2RPN)
814 rpn = ccl_find_str(bibset, arg, &error, &pos);
817 printf("CCL ERROR: %s\n", ccl_err_msg(error));
821 req->referenceId = set_refid (out);
822 if (!strcmp(arg, "@big")) /* strictly for troublemaking */
824 static unsigned char big[2100];
827 /* send a very big referenceid to test transport stack etc. */
828 memset(big, 'A', 2100);
829 bigo.len = bigo.size = 2100;
831 req->referenceId = &bigo;
836 sprintf(setstring, "%d", ++setnumber);
837 req->resultSetName = setstring;
839 *req->smallSetUpperBound = smallSetUpperBound;
840 *req->largeSetLowerBound = largeSetLowerBound;
841 *req->mediumSetPresentNumber = mediumSetPresentNumber;
842 if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
843 mediumSetPresentNumber > 0))
847 prefsyn.proto = protocol;
848 prefsyn.oclass = CLASS_RECSYN;
849 prefsyn.value = recordsyntax;
850 req->preferredRecordSyntax =
851 odr_oiddup(out, oid_ent_to_oid(&prefsyn, oid));
852 req->smallSetElementSetNames =
853 req->mediumSetElementSetNames = elementSetNames;
855 req->num_databaseNames = num_databaseNames;
856 req->databaseNames = databaseNames;
862 case QueryType_Prefix:
863 query.which = Z_Query_type_1;
864 RPNquery = p_query_rpn (out, protocol, arg);
867 printf("Prefix query error\n");
870 query.u.type_1 = RPNquery;
873 query.which = Z_Query_type_2;
874 query.u.type_2 = &ccl_query;
875 ccl_query.buf = (unsigned char*) arg;
876 ccl_query.len = strlen(arg);
878 case QueryType_CCL2RPN:
879 query.which = Z_Query_type_1;
880 RPNquery = ccl_rpn_query(out, rpn);
883 printf ("Couldn't convert from CCL to RPN\n");
886 query.u.type_1 = RPNquery;
887 ccl_rpn_delete (rpn);
890 printf ("Unsupported query type\n");
895 printf("Sent searchRequest.\n");
899 /* display Query Expression as part of searchResult-1 */
900 static void display_queryExpression (Z_QueryExpression *qe)
904 if (qe->which == Z_QueryExpression_term)
906 if (qe->u.term->queryTerm)
908 Z_Term *term = qe->u.term->queryTerm;
909 if (term->which == Z_Term_general)
910 printf (" %.*s", term->u.general->len, term->u.general->buf);
916 /* see if we can find USR:SearchResult-1 */
917 static void display_searchResult (Z_OtherInformation *o)
922 for (i = 0; i < o->num_elements; i++)
924 if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
926 Z_External *ext = o->list[i]->information.externallyDefinedInfo;
928 if (ext->which == Z_External_searchResult1)
931 Z_SearchInfoReport *sr = ext->u.searchResult1;
932 printf ("SearchResult-1:");
933 for (j = 0; j < sr->num; j++)
935 if (!sr->elements[j]->subqueryExpression)
937 display_queryExpression (
938 sr->elements[j]->subqueryExpression);
939 display_queryExpression (
940 sr->elements[j]->subqueryInterpretation);
941 display_queryExpression (
942 sr->elements[j]->subqueryRecommendation);
943 if (sr->elements[j]->subqueryCount)
944 printf ("(%d)", *sr->elements[j]->subqueryCount);
952 static int process_searchResponse(Z_SearchResponse *res)
954 printf ("Received SearchResponse.\n");
955 print_refid (res->referenceId);
956 if (*res->searchStatus)
957 printf("Search was a success.\n");
959 printf("Search was a bloomin' failure.\n");
960 printf("Number of hits: %d", *res->resultCount);
962 printf (", setno %d", setnumber);
964 display_searchResult (res->additionalSearchInfo);
965 printf("records returned: %d\n",
966 *res->numberOfRecordsReturned);
967 setno += *res->numberOfRecordsReturned;
969 display_records(res->records);
973 static void print_level(int iLevel)
976 for (i = 0; i < iLevel * 4; i++)
980 static void print_int(int iLevel, const char *pTag, int *pInt)
985 printf("%s: %d\n", pTag, *pInt);
989 static void print_string(int iLevel, const char *pTag, const char *pString)
994 printf("%s: %s\n", pTag, pString);
998 static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
1004 print_level(iLevel);
1005 printf("%s:", pTag);
1006 for (; *pInt != -1; pInt++)
1007 printf(" %d", *pInt);
1012 static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
1014 if (referenceId != NULL)
1018 print_level(iLevel);
1019 printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
1020 for (i = 0; i < referenceId->len; i++)
1021 printf("%c", referenceId->buf[i]);
1026 static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
1028 if (pStringNumeric != NULL)
1030 switch (pStringNumeric->which)
1032 case Z_StringOrNumeric_string:
1033 print_string(iLevel, pTag, pStringNumeric->u.string);
1036 case Z_StringOrNumeric_numeric:
1037 print_int(iLevel, pTag, pStringNumeric->u.numeric);
1041 print_level(iLevel);
1042 printf("%s: valid type for Z_StringOrNumeric\n", pTag);
1048 static void print_universe_report_duplicate(int iLevel, Z_UniverseReportDuplicate *pUniverseReportDuplicate)
1050 if (pUniverseReportDuplicate != NULL)
1052 print_level(iLevel);
1053 printf("Universe Report Duplicate: \n");
1055 print_string_or_numeric(iLevel, "Hit No",
1056 pUniverseReportDuplicate->hitno);
1061 print_universe_report_hits(int iLevel,
1062 Z_UniverseReportHits *pUniverseReportHits)
1064 if (pUniverseReportHits != NULL)
1066 print_level(iLevel);
1067 printf("Universe Report Hits: \n");
1069 print_string_or_numeric(iLevel, "Database",
1070 pUniverseReportHits->database);
1071 print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
1075 static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
1077 if (pUniverseReport != NULL)
1079 print_level(iLevel);
1080 printf("Universe Report: \n");
1082 print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
1083 switch (pUniverseReport->which)
1085 case Z_UniverseReport_databaseHits:
1086 print_universe_report_hits(iLevel, pUniverseReport->u.databaseHits);
1089 case Z_UniverseReport_duplicate:
1090 print_universe_report_duplicate(iLevel, pUniverseReport->u.duplicate);
1094 print_level(iLevel);
1095 printf("Type: %d\n", pUniverseReport->which);
1101 static void print_external(int iLevel, Z_External *pExternal)
1103 if (pExternal != NULL)
1105 print_level(iLevel);
1106 printf("External: \n");
1108 print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
1109 print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
1110 print_string(iLevel, "Descriptor", pExternal->descriptor);
1111 switch (pExternal->which)
1113 case Z_External_universeReport:
1114 print_universe_report(iLevel, pExternal->u.universeReport);
1118 print_level(iLevel);
1119 printf("Type: %d\n", pExternal->which);
1125 static int process_resourceControlRequest (Z_ResourceControlRequest *req)
1127 printf ("Received ResourceControlRequest.\n");
1128 print_referenceId(1, req->referenceId);
1129 print_int(1, "Suspended Flag", req->suspendedFlag);
1130 print_int(1, "Partial Results Available", req->partialResultsAvailable);
1131 print_int(1, "Response Required", req->responseRequired);
1132 print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
1133 print_external(1, req->resourceReport);
1137 void process_ESResponse(Z_ExtendedServicesResponse *res)
1140 switch (*res->operationStatus)
1142 case Z_ExtendedServicesResponse_done:
1145 case Z_ExtendedServicesResponse_accepted:
1146 printf ("accepted\n");
1148 case Z_ExtendedServicesResponse_failure:
1149 printf ("failure\n");
1150 display_diagrecs(res->diagnostics, res->num_diagnostics);
1153 printf ("unknown\n");
1155 if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
1156 (res->num_diagnostics != 0) ) {
1157 display_diagrecs(res->diagnostics, res->num_diagnostics);
1159 print_refid (res->referenceId);
1160 if (res->taskPackage &&
1161 res->taskPackage->which == Z_External_extendedService)
1163 Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
1164 Odr_oct *id = taskPackage->targetReference;
1165 Z_External *ext = taskPackage->taskSpecificParameters;
1169 printf ("Target Reference: ");
1170 print_stringn (id->buf, id->len);
1173 if (ext->which == Z_External_update)
1175 Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
1176 if (utp && utp->targetPart)
1178 Z_IUTargetPart *targetPart = utp->targetPart;
1181 for (i = 0; i<targetPart->num_taskPackageRecords; i++)
1184 Z_IUTaskPackageRecordStructure *tpr =
1185 targetPart->taskPackageRecords[i];
1186 printf ("task package record %d\n", i+1);
1187 if (tpr->which == Z_IUTaskPackageRecordStructure_record)
1189 display_record (tpr->u.record);
1193 printf ("other type\n");
1201 const char *get_ill_element (void *clientData, const char *element)
1206 static Z_External *create_external_itemRequest()
1208 struct ill_get_ctl ctl;
1209 ILL_ItemRequest *req;
1211 int item_request_size = 0;
1212 char *item_request_buf = 0;
1216 ctl.f = get_ill_element;
1218 req = ill_get_ItemRequest(&ctl, "ill", 0);
1220 printf ("ill_get_ItemRequest failed\n");
1222 if (!ill_ItemRequest (out, &req, 0, 0))
1226 ill_ItemRequest(print, &req, 0, 0);
1229 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1230 if (item_request_buf)
1231 odr_setbuf (out, item_request_buf, item_request_size, 1);
1232 printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
1239 item_request_buf = odr_getbuf (out, &item_request_size, 0);
1240 oid.proto = PROTO_GENERAL;
1241 oid.oclass = CLASS_GENERAL;
1242 oid.value = VAL_ISO_ILL_1;
1244 r = (Z_External *) odr_malloc (out, sizeof(*r));
1245 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1246 r->indirect_reference = 0;
1248 r->which = Z_External_single;
1250 r->u.single_ASN1_type = (Odr_oct *)
1251 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1252 r->u.single_ASN1_type->buf = (unsigned char *)
1253 odr_malloc (out, item_request_size);
1254 r->u.single_ASN1_type->len = item_request_size;
1255 r->u.single_ASN1_type->size = item_request_size;
1256 memcpy (r->u.single_ASN1_type->buf, item_request_buf,
1258 printf ("len = %d\n", item_request_size);
1263 static Z_External *create_external_ILL_APDU(int which)
1265 struct ill_get_ctl ctl;
1268 int ill_request_size = 0;
1269 char *ill_request_buf = 0;
1273 ctl.f = get_ill_element;
1275 ill_apdu = ill_get_APDU(&ctl, "ill", 0);
1277 if (!ill_APDU (out, &ill_apdu, 0, 0))
1281 printf ("-------------------\n");
1282 ill_APDU(print, &ill_apdu, 0, 0);
1284 printf ("-------------------\n");
1286 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1287 if (ill_request_buf)
1288 odr_setbuf (out, ill_request_buf, ill_request_size, 1);
1289 printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
1295 ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
1297 oid.proto = PROTO_GENERAL;
1298 oid.oclass = CLASS_GENERAL;
1299 oid.value = VAL_ISO_ILL_1;
1301 r = (Z_External *) odr_malloc (out, sizeof(*r));
1302 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
1303 r->indirect_reference = 0;
1305 r->which = Z_External_single;
1307 r->u.single_ASN1_type = (Odr_oct *)
1308 odr_malloc (out, sizeof(*r->u.single_ASN1_type));
1309 r->u.single_ASN1_type->buf = (unsigned char *)
1310 odr_malloc (out, ill_request_size);
1311 r->u.single_ASN1_type->len = ill_request_size;
1312 r->u.single_ASN1_type->size = ill_request_size;
1313 memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
1314 printf ("len = %d\n", ill_request_size);
1320 static Z_External *create_ItemOrderExternal(const char *type, int itemno)
1322 Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
1323 oident ItemOrderRequest;
1325 ItemOrderRequest.proto = PROTO_Z3950;
1326 ItemOrderRequest.oclass = CLASS_EXTSERV;
1327 ItemOrderRequest.value = VAL_ITEMORDER;
1329 r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1330 r->indirect_reference = 0;
1333 r->which = Z_External_itemOrder;
1335 r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder));
1336 memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder));
1337 r->u.itemOrder->which=Z_IOItemOrder_esRequest;
1339 r->u.itemOrder->u.esRequest = (Z_IORequest *)
1340 odr_malloc(out,sizeof(Z_IORequest));
1341 memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest));
1343 r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
1344 odr_malloc(out,sizeof(Z_IOOriginPartToKeep));
1345 memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep));
1346 r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
1347 odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep));
1348 memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep));
1350 r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL;
1351 r->u.itemOrder->u.esRequest->toKeep->contact = NULL;
1352 r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL;
1354 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem =
1355 (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem));
1356 memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem));
1357 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1";
1359 r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item =
1360 (int *) odr_malloc(out, sizeof(int));
1361 *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
1364 if (!strcmp (type, "item") || !strcmp(type, "2"))
1366 printf ("using item-request\n");
1367 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1368 create_external_itemRequest();
1370 else if (!strcmp(type, "ill") || !strcmp(type, "1"))
1372 printf ("using ILL-request\n");
1373 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1374 create_external_ILL_APDU(ILL_APDU_ILL_Request);
1376 else if (!strcmp(type, "xml") || !strcmp(type, "3"))
1378 const char *xml_buf =
1380 " <type>request</type>\n"
1381 " <libraryNo>000200</libraryNo>\n"
1382 " <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
1384 r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
1385 z_ext_record (out, VAL_TEXT_XML, xml_buf, strlen(xml_buf));
1388 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1391 r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
1396 static int send_itemorder(const char *type, int itemno)
1398 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
1399 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1400 oident ItemOrderRequest;
1402 ItemOrderRequest.proto = PROTO_Z3950;
1403 ItemOrderRequest.oclass = CLASS_EXTSERV;
1404 ItemOrderRequest.value = VAL_ITEMORDER;
1405 req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
1406 req->packageName = esPackageName;
1408 req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
1414 static int cmd_update(char *arg)
1416 Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
1417 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
1420 Z_IUOriginPartToKeep *toKeep;
1421 Z_IUSuppliedRecords *notToKeep;
1423 printf ("Update request\n");
1428 update_oid.proto = PROTO_Z3950;
1429 update_oid.oclass = CLASS_EXTSERV;
1430 update_oid.value = VAL_DBUPDATE;
1431 oid_ent_to_oid (&update_oid, oid);
1432 req->packageType = odr_oiddup(out,oid);
1433 req->packageName = esPackageName;
1435 req->referenceId = set_refid (out);
1437 r = req->taskSpecificParameters = (Z_External *)
1438 odr_malloc (out, sizeof(*r));
1439 r->direct_reference = odr_oiddup(out,oid);
1440 r->indirect_reference = 0;
1442 r->which = Z_External_update;
1443 r->u.update = (Z_IUUpdate *) odr_malloc(out, sizeof(*r->u.update));
1444 r->u.update->which = Z_IUUpdate_esRequest;
1445 r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
1446 odr_malloc(out, sizeof(*r->u.update->u.esRequest));
1447 toKeep = r->u.update->u.esRequest->toKeep = (Z_IUOriginPartToKeep *)
1448 odr_malloc(out, sizeof(*r->u.update->u.esRequest->toKeep));
1449 toKeep->databaseName = databaseNames[0];
1451 toKeep->elementSetName = 0;
1452 toKeep->actionQualifier = 0;
1453 toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
1454 *toKeep->action = Z_IUOriginPartToKeep_recordInsert;
1456 notToKeep = r->u.update->u.esRequest->notToKeep = (Z_IUSuppliedRecords *)
1457 odr_malloc(out, sizeof(*r->u.update->u.esRequest->notToKeep));
1459 notToKeep->elements = (Z_IUSuppliedRecords_elem **)
1460 odr_malloc(out, sizeof(*notToKeep->elements));
1461 notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
1462 odr_malloc(out, sizeof(**notToKeep->elements));
1463 notToKeep->elements[0]->u.number = 0;
1464 notToKeep->elements[0]->supplementalId = 0;
1465 notToKeep->elements[0]->correlationInfo = 0;
1466 notToKeep->elements[0]->record = record_last;
1473 static int cmd_itemorder(char *arg)
1478 if (sscanf (arg, "%10s %d", type, &itemno) != 2)
1481 printf("Item order request\n");
1483 send_itemorder(type, itemno);
1487 static int cmd_find(char *arg)
1491 printf("Find what?\n");
1496 printf("Not connected yet\n");
1499 if (!send_searchRequest(arg))
1504 static int cmd_delete(char *arg)
1508 printf("Not connected yet\n");
1511 if (!send_deleteResultSetRequest(arg))
1516 static int cmd_ssub(char *arg)
1518 if (!(smallSetUpperBound = atoi(arg)))
1523 static int cmd_lslb(char *arg)
1525 if (!(largeSetLowerBound = atoi(arg)))
1530 static int cmd_mspn(char *arg)
1532 if (!(mediumSetPresentNumber = atoi(arg)))
1537 static int cmd_status(char *arg)
1539 printf("smallSetUpperBound: %d\n", smallSetUpperBound);
1540 printf("largeSetLowerBound: %d\n", largeSetLowerBound);
1541 printf("mediumSetPresentNumber: %d\n", mediumSetPresentNumber);
1545 static int cmd_setnames(char *arg)
1547 if (*arg == '1') /* enable ? */
1549 else if (*arg == '0') /* disable ? */
1551 else if (setnumber < 0) /* no args, toggle .. */
1557 printf("Set numbering enabled.\n");
1559 printf("Set numbering disabled.\n");
1563 /* PRESENT SERVICE ----------------------------- */
1565 static int send_presentRequest(char *arg)
1567 Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
1568 Z_PresentRequest *req = apdu->u.presentRequest;
1569 Z_RecordComposition compo;
1574 char setstring[100];
1576 req->referenceId = set_refid (out);
1577 if ((p = strchr(arg, '+')))
1584 if (p && (p=strchr(p+1, '+')))
1586 strcpy (setstring, p+1);
1587 req->resultSetId = setstring;
1589 else if (setnumber >= 0)
1591 sprintf(setstring, "%d", setnumber);
1592 req->resultSetId = setstring;
1594 req->resultSetStartPoint = &setno;
1595 req->numberOfRecordsRequested = &nos;
1596 prefsyn.proto = protocol;
1597 prefsyn.oclass = CLASS_RECSYN;
1598 prefsyn.value = recordsyntax;
1599 req->preferredRecordSyntax =
1600 odr_oiddup (out, oid_ent_to_oid(&prefsyn, oid));
1602 if (schema != VAL_NONE)
1606 prefschema.proto = protocol;
1607 prefschema.oclass = CLASS_SCHEMA;
1608 prefschema.value = schema;
1610 req->recordComposition = &compo;
1611 compo.which = Z_RecordComp_complex;
1612 compo.u.complex = (Z_CompSpec *)
1613 odr_malloc(out, sizeof(*compo.u.complex));
1614 compo.u.complex->selectAlternativeSyntax = (bool_t *)
1615 odr_malloc(out, sizeof(bool_t));
1616 *compo.u.complex->selectAlternativeSyntax = 0;
1618 compo.u.complex->generic = (Z_Specification *)
1619 odr_malloc(out, sizeof(*compo.u.complex->generic));
1620 compo.u.complex->generic->schema = (Odr_oid *)
1621 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1622 if (!compo.u.complex->generic->schema)
1624 /* OID wasn't a schema! Try record syntax instead. */
1625 prefschema.oclass = CLASS_RECSYN;
1626 compo.u.complex->generic->schema = (Odr_oid *)
1627 odr_oiddup(out, oid_ent_to_oid(&prefschema, oid));
1629 if (!elementSetNames)
1630 compo.u.complex->generic->elementSpec = 0;
1633 compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
1634 odr_malloc(out, sizeof(Z_ElementSpec));
1635 compo.u.complex->generic->elementSpec->which =
1636 Z_ElementSpec_elementSetName;
1637 compo.u.complex->generic->elementSpec->u.elementSetName =
1638 elementSetNames->u.generic;
1640 compo.u.complex->num_dbSpecific = 0;
1641 compo.u.complex->dbSpecific = 0;
1642 compo.u.complex->num_recordSyntax = 0;
1643 compo.u.complex->recordSyntax = 0;
1645 else if (elementSetNames)
1647 req->recordComposition = &compo;
1648 compo.which = Z_RecordComp_simple;
1649 compo.u.simple = elementSetNames;
1652 printf("Sent presentRequest (%d+%d).\n", setno, nos);
1656 static void close_session (void)
1662 nmem_destroy (session_mem);
1668 void process_close(Z_Close *req)
1670 Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
1671 Z_Close *res = apdu->u.close;
1673 static char *reasons[] =
1678 "cost limit reached",
1680 "security violation",
1687 printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
1688 req->diagnosticInformation ? req->diagnosticInformation : "NULL");
1693 *res->closeReason = Z_Close_finished;
1695 printf("Sent response.\n");
1700 static int cmd_show(char *arg)
1704 printf("Not connected yet\n");
1707 if (!send_presentRequest(arg))
1712 int cmd_quit(char *arg)
1714 printf("See you later, alligator.\n");
1720 int cmd_cancel(char *arg)
1722 Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
1723 Z_TriggerResourceControlRequest *req =
1724 apdu->u.triggerResourceControlRequest;
1729 printf("Session not initialized yet\n");
1732 if (!ODR_MASK_GET(session->options, Z_Options_triggerResourceCtrl))
1734 printf("Target doesn't support cancel (trigger resource ctrl)\n");
1737 *req->requestedAction = Z_TriggerResourceCtrl_cancel;
1738 req->resultSetWanted = &rfalse;
1741 printf("Sent cancel request\n");
1745 int send_scanrequest(const char *query, int pp, int num, const char *term)
1747 Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
1748 Z_ScanRequest *req = apdu->u.scanRequest;
1752 if (queryType == QueryType_CCL2RPN)
1756 struct ccl_rpn_node *rpn;
1758 rpn = ccl_find_str (bibset, query, &error, &pos);
1761 printf("CCL ERROR: %s\n", ccl_err_msg(error));
1765 bib1.proto = PROTO_Z3950;
1766 bib1.oclass = CLASS_ATTSET;
1767 bib1.value = VAL_BIB1;
1768 req->attributeSet = oid_ent_to_oid (&bib1, oid);
1769 if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
1771 printf("Couldn't convert CCL to Scan term\n");
1774 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;
2055 else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
2056 queryType = QueryType_CCL2RPN;
2059 printf ("Querytype must be one of:\n");
2060 printf (" prefix - Prefix query\n");
2061 printf (" ccl - CCL query\n");
2062 printf (" ccl2rpn - CCL query converted to RPN\n");
2068 int cmd_refid (char *arg)
2074 refid = (char *) xmalloc (strlen(arg)+1);
2075 strcpy (refid, arg);
2080 int cmd_close(char *arg)
2087 apdu = zget_APDU(out, Z_APDU_close);
2088 req = apdu->u.close;
2089 *req->closeReason = Z_Close_finished;
2091 printf("Sent close request.\n");
2096 int cmd_packagename(char* arg)
2098 xfree (esPackageName);
2099 esPackageName = NULL;
2102 esPackageName = (char *) xmalloc (strlen(arg)+1);
2103 strcpy (esPackageName, arg);
2108 int cmd_proxy(char* arg)
2111 printf("Current proxy is `%s'\n", (yazCharset)?yazProxy:NULL);
2118 yazProxy = (char *) xmalloc (strlen(arg)+1);
2119 strcpy (yazProxy, arg);
2124 int cmd_charset(char* arg)
2127 printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL);
2134 yazCharset = (char *) xmalloc (strlen(arg)+1);
2135 strcpy (yazCharset, arg);
2140 int cmd_lang(char* arg)
2143 printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
2150 yazLang = (char *) xmalloc (strlen(arg)+1);
2151 strcpy (yazLang, arg);
2156 int cmd_source(char* arg)
2158 /* first should open the file and read one line at a time.. */
2160 char line[1024], *cp;
2163 char* args_end=(arg)+strlen(arg)-1;
2164 while(isspace(*args_end))
2169 REMOVE_TAILING_BLANKS(arg);
2172 fprintf(stderr,"Error in source command use a filename\n");
2176 includeFile = fopen (arg, "r");
2179 fprintf(stderr,"Unable to open file %s for reading\n",arg);
2183 while(!feof(includeFile)) {
2184 memset(line,0,sizeof(line));
2185 fgets(line,sizeof(line),includeFile);
2187 if(strlen(line) < 2) continue;
2188 if(line[0] == '#') continue;
2190 if ((cp = strrchr (line, '\n')))
2193 process_cmd_line(line);
2196 if(fclose(includeFile)<0) {
2197 perror("unable to close include file");
2203 int cmd_subshell(char* args)
2208 system(getenv("SHELL"));
2214 int cmd_set_apdufile(char* arg)
2216 REMOVE_TAILING_BLANKS(arg);
2218 if(apdu_file && apdu_file != stderr) { /* don't close stdout*/
2219 perror("unable to close apdu log file");
2227 if(!strcmp(arg,"-"))
2230 apdu_file=fopen(arg, "a");
2233 perror("unable to open apdu log file no apdu log loaded");
2235 odr_setprint(print, apdu_file);
2241 int cmd_set_cclfields(char* arg)
2245 REMOVE_TAILING_BLANKS(arg);
2247 bibset = ccl_qual_mk ();
2248 inf = fopen (arg, "r");
2251 ccl_qual_file (bibset, inf);
2258 int cmd_set_marcdump(char* arg)
2260 if(marcdump && marcdump != stderr) { /* don't close stdout*/
2261 perror("unable to close apdu log file");
2269 if(!strcmp(arg,"-"))
2272 marcdump=fopen(arg, "a");
2275 perror("unable to open apdu marcdump file no marcdump done\n");
2281 int cmd_set_proxy(char* arg) {
2282 if(yazProxy) free(yazProxy);
2285 if(strlen(arg) > 1) {
2286 yazProxy=strdup(arg);
2292 this command takes 3 arge {name class oid}
2294 int cmd_register_oid(char* args) {
2299 {"appctx",CLASS_APPCTX},
2300 {"absyn",CLASS_ABSYN},
2301 {"attset",CLASS_ATTSET},
2302 {"transyn",CLASS_TRANSYN},
2303 {"diagset",CLASS_DIAGSET},
2304 {"recsyn",CLASS_RECSYN},
2305 {"resform",CLASS_RESFORM},
2306 {"accform",CLASS_ACCFORM},
2307 {"extserv",CLASS_EXTSERV},
2308 {"userinfo",CLASS_USERINFO},
2309 {"elemspec",CLASS_ELEMSPEC},
2310 {"varset",CLASS_VARSET},
2311 {"schema",CLASS_SCHEMA},
2312 {"tagset",CLASS_TAGSET},
2313 {"general",CLASS_GENERAL},
2316 char oname_str[101], oclass_str[101], oid_str[101];
2319 oid_class oidclass = CLASS_GENERAL;
2320 int val = 0, oid[OID_SIZE];
2321 struct oident * new_oident=NULL;
2323 if (sscanf (args, "%100[^ ] %100[^ ] %100s",
2324 oname_str,oclass_str, oid_str) < 1) {
2325 printf("Error in regristrate command \n");
2329 for (i = 0; oid_classes[i].className; i++) {
2330 if (!strcmp(oid_classes[i].className, oclass_str))
2332 oidclass=oid_classes[i].oclass;
2337 if(!(oid_classes[i].className)) {
2338 printf("Unknonwn oid class %s\n",oclass_str);
2346 while (isdigit (*name))
2348 val = val*10 + (*name - '0');
2361 new_oident=oid_addent (oid,PROTO_GENERAL,oidclass,oname_str,VAL_DYNAMIC);
2362 if(strcmp(new_oident->desc,oname_str)) {
2363 fprintf(stderr,"oid is already named as %s, regristration faild\n",
2369 int cmd_push_command(char* arg)
2371 #if HAVE_READLINE_HISTORY_H
2375 fprintf(stderr,"Not compiled with the readline/history module\n");
2380 void source_rcfile()
2382 /* Look for a $HOME/.yazclientrc and source it if it exists */
2383 struct stat statbuf;
2385 char* homedir=getenv("HOME");
2387 if(!homedir) return;
2389 sprintf(buffer,"%s/.yazclientrc",homedir);
2391 if(stat(buffer,&statbuf)==0) {
2395 if(stat(".yazclientrc",&statbuf)==0) {
2396 cmd_source(".yazclientrc");
2401 static void initialize(void)
2406 if (!(out = odr_createmem(ODR_ENCODE)) ||
2407 !(in = odr_createmem(ODR_DECODE)) ||
2408 !(print = odr_createmem(ODR_PRINT)))
2410 fprintf(stderr, "failed to allocate ODR streams\n");
2415 setvbuf(stdout, 0, _IONBF, 0);
2417 odr_setprint(print, apdu_file);
2420 bibset = ccl_qual_mk ();
2421 inf = fopen (ccl_fields, "r");
2424 ccl_qual_file (bibset, inf);
2428 cmd_base("Default");
2430 #if HAVE_READLINE_READLINE_H
2431 rl_attempted_completion_function = (CPPFunction*)readline_completer;
2438 #if HAVE_GETTIMEOFDAY
2439 struct timeval tv_start, tv_end;
2442 void wait_and_handle_responce()
2447 int netbufferlen = 0;
2455 if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
2457 printf("Target closed connection\n");
2463 printf("Target closed connection.\n");
2467 odr_reset(in); /* release APDU from last round */
2469 odr_setbuf(in, netbuffer, res, 0);
2470 if (!z_APDU(in, &apdu, 0, 0))
2472 odr_perror(in, "Decoding incoming APDU");
2473 fprintf(stderr, "[Near %d]\n", odr_offset(in));
2474 fprintf(stderr, "Packet dump:\n---------\n");
2475 odr_dumpBER(stderr, netbuffer, res);
2476 fprintf(stderr, "---------\n");
2478 z_APDU(print, &apdu, 0, 0);
2482 if (apdu_file && !z_APDU(print, &apdu, 0, 0))
2484 odr_perror(print, "Failed to print incoming APDU");
2490 case Z_APDU_initResponse:
2491 process_initResponse(apdu->u.initResponse);
2493 case Z_APDU_searchResponse:
2494 process_searchResponse(apdu->u.searchResponse);
2496 case Z_APDU_scanResponse:
2497 process_scanResponse(apdu->u.scanResponse);
2499 case Z_APDU_presentResponse:
2500 print_refid (apdu->u.presentResponse->referenceId);
2502 *apdu->u.presentResponse->numberOfRecordsReturned;
2503 if (apdu->u.presentResponse->records)
2504 display_records(apdu->u.presentResponse->records);
2506 printf("No records.\n");
2507 printf ("nextResultSetPosition = %d\n",
2508 *apdu->u.presentResponse->nextResultSetPosition);
2510 case Z_APDU_sortResponse:
2511 process_sortResponse(apdu->u.sortResponse);
2513 case Z_APDU_extendedServicesResponse:
2514 printf("Got extended services response\n");
2515 process_ESResponse(apdu->u.extendedServicesResponse);
2518 printf("Target has closed the association.\n");
2519 process_close(apdu->u.close);
2521 case Z_APDU_resourceControlRequest:
2522 process_resourceControlRequest
2523 (apdu->u.resourceControlRequest);
2525 case Z_APDU_deleteResultSetResponse:
2526 process_deleteResultSetResponse(apdu->u.
2527 deleteResultSetResponse);
2530 printf("Received unknown APDU type (%d).\n",
2535 while (conn && cs_more(conn));
2536 #if HAVE_GETTIMEOFDAY
2537 gettimeofday (&tv_end, 0);
2539 printf ("S/U S/U=%ld/%ld %ld/%ld",
2540 (long) tv_start.tv_sec,
2541 (long) tv_start.tv_usec,
2542 (long) tv_end.tv_sec,
2543 (long) tv_end.tv_usec);
2545 printf ("Elapsed: %.6f\n",
2546 (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
2547 ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
2554 static int cmd_help (char *line);
2556 typedef char *(*completerFunctionType)(const char *text, int state);
2560 int (*fun)(char *arg);
2562 completerFunctionType rl_completerfunction;
2563 //char *(*rl_completerfunction)(const char *text, int state);
2564 int complete_filenames;
2565 char **local_tabcompletes;
2567 {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0,NULL},
2568 {"quit", cmd_quit, "",NULL,0,NULL},
2569 {"find", cmd_find, "<query>",NULL,0,NULL},
2570 {"delete", cmd_delete, "<setname>",NULL,0,NULL},
2571 {"base", cmd_base, "<base-name>",NULL,0,NULL},
2572 {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0,NULL},
2573 {"scan", cmd_scan, "<term>",NULL,0,NULL},
2574 {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
2575 {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
2576 {"authentication", cmd_authentication, "<acctstring>",NULL,0,NULL},
2577 {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0,NULL},
2578 {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0,NULL},
2579 {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0,NULL},
2580 {"status", cmd_status, "",NULL,0,NULL},
2581 {"setnames", cmd_setnames, "",NULL,0,NULL},
2582 {"cancel", cmd_cancel, "",NULL,0,NULL},
2583 {"format", cmd_format, "<recordsyntax>",complete_format,0,NULL},
2584 {"schema", cmd_schema, "<schema>",complete_schema,0,NULL},
2585 {"elements", cmd_elements, "<elementSetName>",NULL,0,NULL},
2586 {"close", cmd_close, "",NULL,0,NULL},
2587 {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0,NULL},
2588 {"querytype", cmd_querytype, "<type>",complete_querytype,0,NULL},
2589 {"refid", cmd_refid, "<id>",NULL,0,NULL},
2590 {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0,NULL},
2591 {"update", cmd_update, "<item>",NULL,0,NULL},
2592 {"packagename", cmd_packagename, "<packagename>",NULL,0,NULL},
2593 {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0,NULL},
2594 {"charset", cmd_charset, "<charset_name>",NULL,0,NULL},
2595 {"lang", cmd_lang, "<language_code>",NULL,0,NULL},
2596 {".", cmd_source, "<filename>",NULL,1,NULL},
2597 {"!", cmd_subshell, "Subshell command",NULL,1,NULL},
2598 {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,1,NULL},
2599 {"set_marcdump", cmd_set_marcdump," <filename>",NULL,1,NULL},
2600 {"set_cclfiele", cmd_set_cclfields," <filename>",NULL,1,NULL},
2601 {"register_oid", cmd_register_oid,"<name> <class> <oid>",NULL,0,NULL},
2602 {"push_command", cmd_push_command,"<command>",command_generator,0,NULL},
2603 {"register_tab", cmd_register_tab,"<commandname> <tab>",command_generator,0,NULL},
2604 /* Server Admin Functions */
2605 {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0,NULL},
2606 {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0,NULL},
2607 {"adm-create", cmd_adm_create, "",NULL,0,NULL},
2608 {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0,NULL},
2609 {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0,NULL},
2610 {"adm-refresh", cmd_adm_refresh, "",NULL,0,NULL},
2611 {"adm-commit", cmd_adm_commit, "",NULL,0,NULL},
2612 {"adm-shutdown", cmd_adm_shutdown, "",NULL,0,NULL},
2613 {"adm-startup", cmd_adm_startup, "",NULL,0,NULL},
2614 {"help", cmd_help, "", NULL,0,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 int cmd_register_tab(char* arg) {
2660 char command[101], tabargument[101];
2665 if (sscanf (arg, "%100s %100s", command, tabargument) < 1) {
2669 /* locate the amdn in the list */
2670 for (i = 0; cmd[i].cmd; i++) {
2671 if (!strncmp(cmd[i].cmd, command, strlen(command))) {
2677 fprintf(stderr,"Unknown command %s\n",command);
2683 if(!cmd[i].local_tabcompletes) {
2684 cmd[i].local_tabcompletes = calloc(1,sizeof(char**));
2689 tabslist = cmd[i].local_tabcompletes;
2690 for(;tabslist && *tabslist;tabslist++) {
2694 cmd[i].local_tabcompletes=realloc(cmd[i].local_tabcompletes,(num_of_tabs+2)*sizeof(char**));
2695 tabslist=cmd[i].local_tabcompletes;
2696 tabslist[num_of_tabs]=strdup(tabargument);
2697 tabslist[num_of_tabs+1]=NULL;
2700 void process_cmd_line(char* line)
2703 char word[32], arg[1024];
2705 #if HAVE_GETTIMEOFDAY
2706 gettimeofday (&tv_start, 0);
2709 if ((res = sscanf(line, "%31s %1023[^;]", word, arg)) <= 0)
2711 strcpy(word, last_cmd);
2716 strcpy(last_cmd, word);
2718 /* removed tailing spaces from the arg command */
2721 char* lastnonspace=NULL;
2730 *(++lastnonspace) = 0;
2734 for (i = 0; cmd[i].cmd; i++)
2735 if (!strncmp(cmd[i].cmd, word, strlen(word)))
2737 res = (*cmd[i].fun)(arg);
2741 if (!cmd[i].cmd) /* dump our help-screen */
2743 printf("Unknown command: %s.\n", word);
2748 if(apdu_file) fflush(apdu_file);
2751 wait_and_handle_responce();
2760 char *command_generator(const char *text, int state)
2766 for( ; cmd[idx].cmd; ++idx) {
2767 if (!strncmp(cmd[idx].cmd,text,strlen(text))) {
2768 ++idx; /* skip this entry on the next run */
2769 return strdup(cmd[idx-1].cmd);
2777 This function only known how to complete on the first word
2779 char ** readline_completer(char *text, int start, int end) {
2780 #if HAVE_READLINE_READLINE_H
2782 completerFunctionType completerToUse;
2785 #if HAVE_READLINE_RL_COMPLETION_MATCHES
2786 char** res=rl_completion_matches(text,
2789 char** res=completion_matches(text,
2790 (CPFunction*)command_generator);
2792 rl_attempted_completion_over = 1;
2795 char arg[1024],word[32];
2797 if ((res = sscanf(rl_line_buffer, "%31s %1023[^;]", word, arg)) <= 0) {
2798 rl_attempted_completion_over = 1;
2802 if(start != strlen(word) +1 ) {
2803 rl_attempted_completion_over = 1;
2806 for (i = 0; cmd[i].cmd; i++) {
2807 if (!strncmp(cmd[i].cmd, word, strlen(word))) {
2812 if(!cmd[i].cmd) return NULL;
2815 curret_global_list = cmd[i].local_tabcompletes;
2817 completerToUse = cmd[i].rl_completerfunction;
2818 if(completerToUse==NULL) /* if no pr. command completer is defined use the default completer */
2819 completerToUse = default_completer;
2821 if(completerToUse) {
2822 #ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
2824 rl_completion_matches(text,
2828 completion_matches(text,
2829 (CPFunction*)completerToUse);
2831 if(!cmd[i].complete_filenames)
2832 rl_attempted_completion_over = 1;
2835 if(!cmd[i].complete_filenames)
2836 rl_attempted_completion_over = 1;
2846 static void client(void)
2852 #if HAVE_GETTIMEOFDAY
2853 gettimeofday (&tv_start, 0);
2858 char *line_in = NULL;
2859 #if HAVE_READLINE_READLINE_H
2862 line_in=readline(C_PROMPT);
2865 #if HAVE_READLINE_HISTORY_H
2867 add_history(line_in);
2869 strncpy(line, line_in, 1023);
2878 if (!fgets(line, 1023, stdin))
2880 if ((end_p = strchr (line, '\n')))
2883 process_cmd_line(line);
2887 int main(int argc, char **argv)
2890 char *open_command = 0;
2891 char *auth_command = 0;
2895 while ((ret = options("k:c:a:m:v:p:u:", argv, argc, &arg)) != -2)
2902 open_command = (char *) xmalloc (strlen(arg)+6);
2903 strcpy (open_command, "open ");
2904 strcat (open_command, arg);
2908 kilobytes = atoi(arg);
2911 if (!(marcdump = fopen (arg, "a")))
2918 strncpy (ccl_fields, arg, sizeof(ccl_fields)-1);
2919 ccl_fields[sizeof(ccl_fields)-1] = '\0';
2922 if (!strcmp(arg, "-"))
2925 apdu_file=fopen(arg, "a");
2928 yazProxy=strdup(arg);
2933 auth_command = (char *) xmalloc (strlen(arg)+6);
2934 strcpy (auth_command, "auth ");
2935 strcat (auth_command, arg);
2939 yaz_log_init (yaz_log_mask_str(arg), "", NULL);
2942 fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
2943 "[-c cclfields]\n [-p <proxy-addr>] [-u <auth>] "
2944 "[-k size] [<server-addr>]\n",
2952 #ifdef HAVE_GETTIMEOFDAY
2953 gettimeofday (&tv_start, 0);
2955 process_cmd_line (auth_command);
2956 #if HAVE_READLINE_HISTORY_H
2957 add_history(auth_command);
2959 xfree(auth_command);
2963 #ifdef HAVE_GETTIMEOFDAY
2964 gettimeofday (&tv_start, 0);
2966 process_cmd_line (open_command);
2967 #if HAVE_READLINE_HISTORY_H
2968 add_history(open_command);
2970 xfree(open_command);