2 * Copyright (c) 1998-2000, Index Data.
3 * See the file LICENSE for details.
5 * $Log: yaz-my-client.cpp,v $
6 * Revision 1.9 2001-04-26 17:51:56 heikki
7 * better ursula request (doesn't crash)
9 * Revision 1.8 2001/04/26 17:30:07 heikki
10 * Ursularequest got more default data
12 * Revision 1.7 2001/04/26 12:17:49 heikki
13 * Ursula stuff, mostly in the test client
15 * Revision 1.6 2001/04/17 16:21:21 heikki
16 * Working on UrsulaRenewal, Request, and Update
18 * Revision 1.5 2001/04/10 10:48:08 adam
19 * Fixed problem where proxy could cash bad result sets.
21 * Revision 1.4 2001/04/05 15:12:24 adam
24 * Revision 1.3 2001/04/05 13:09:44 adam
25 * Removed ursula dependancy.
27 * Revision 1.2 2001/04/04 14:02:49 adam
28 * URSULA / Z-ruth service.
30 * Revision 1.1 2001/03/27 14:47:45 adam
31 * New server facility scheme.
33 * Revision 1.17 2001/03/26 14:43:49 adam
34 * New threaded PDU association.
36 * Revision 1.16 2000/11/01 14:22:59 adam
37 * Added fd parameter for method IYaz_PDU_Observer::clone.
39 * Revision 1.15 2000/10/11 11:58:16 adam
40 * Moved header files to include/yaz++. Switched to libtool and automake.
41 * Configure script creates yaz++-config script.
43 * Revision 1.14 2000/09/08 10:23:42 adam
44 * Added skeleton of yaz-z-server.
46 * Revision 1.13 2000/09/06 14:23:45 adam
49 * Revision 1.12 2000/09/04 08:59:16 adam
50 * Changed call to logging functions (yaz_ added).
52 * Revision 1.11 2000/07/04 13:48:49 adam
53 * Implemented upper-limit on proxy-to-target sessions.
55 * Revision 1.10 2000/05/30 03:12:27 ian
56 * minor change to stop g++ 2.95.2 complaining about taking the address
57 * of a member function.
59 * Revision 1.9 1999/12/06 13:52:45 adam
60 * Modified for new location of YAZ header files. Experimental threaded
63 * Revision 1.8 1999/11/10 10:02:34 adam
66 * Revision 1.7 1999/04/21 12:09:01 adam
67 * Many improvements. Modified to proxy server to work with "sessions"
70 * Revision 1.6 1999/04/20 10:30:05 adam
71 * Implemented various stuff for client and proxy. Updated calls
72 * to ODR to reflect new name parameter.
74 * Revision 1.5 1999/04/09 11:46:57 adam
75 * Added object Yaz_Z_Assoc. Much more functional client.
77 * Revision 1.4 1999/03/23 14:17:57 adam
78 * More work on timeout handling. Work on yaz-client.
80 * Revision 1.3 1999/02/02 14:01:18 adam
81 * First WIN32 port of YAZ++.
83 * Revision 1.2 1999/01/28 13:08:42 adam
84 * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
85 * yaz-socket-manager.cc.
87 * Revision 1.1.1.1 1999/01/28 09:41:07 adam
88 * First implementation of YAZ++.
93 #include <yaz/options.h>
94 #include <yaz/diagbib1.h>
95 #include <yaz/marcdisp.h>
96 #include <yaz++/yaz-ir-assoc.h>
97 #include <yaz++/yaz-pdu-assoc.h>
98 #include <yaz++/yaz-socket-manager.h>
100 #if HAVE_YAZ_URSULA_H
101 #include <yaz/zes-ursula.h>
105 #if HAVE_READLINE_READLINE_H
106 #include <readline/readline.h>
108 #if HAVE_READLINE_HISTORY_H
109 #include <readline/history.h>
113 class YAZ_EXPORT MyClient : public Yaz_IR_Assoc {
115 int m_interactive_flag;
116 char m_thisCommand[1024];
117 char m_lastCommand[1024];
119 Yaz_SocketManager *m_socketManager;
121 MyClient(IYaz_PDU_Observable *the_PDU_Observable,
122 Yaz_SocketManager *the_SocketManager);
123 IYaz_PDU_Observer *sessionNotify(
124 IYaz_PDU_Observable *the_PDU_Observable, int fd);
125 int args(Yaz_SocketManager *socketManager, int argc, char **argv);
126 int interactive(Yaz_SocketManager *socketManager);
128 void recv_initResponse(Z_InitResponse *initResponse);
129 void recv_searchResponse(Z_SearchResponse *searchResponse);
130 void recv_presentResponse(Z_PresentResponse *presentResponse);
131 void recv_records (Z_Records *records);
132 void recv_diagrecs(Z_DiagRec **pp, int num);
133 void recv_namePlusRecord (Z_NamePlusRecord *zpr, int offset);
134 void recv_record(Z_DatabaseRecord *record, int offset,
135 const char *databaseName);
136 void recv_textRecord(int type, const char *buf, size_t len);
137 void recv_genericRecord(Z_GenericRecord *r);
138 #if HAVE_YAZ_URSULA_H
139 void recv_extendedServicesResponse(Z_ExtendedServicesResponse *extendedServicesResponse);
141 void display_genericRecord(Z_GenericRecord *r, int level);
142 void display_variant(Z_Variant *v, int level);
143 void connectNotify();
145 void timeoutNotify();
146 char *get_cookie (Z_OtherInformation **oi);
147 int processCommand(const char *cmd);
148 const char *MyClient::getCommand();
149 int cmd_open(char *host);
150 int cmd_connect(char *host);
151 int cmd_quit(char *args);
152 int cmd_close(char *args);
153 int cmd_find(char *args);
154 int cmd_show(char *args);
155 int cmd_cookie(char *args);
156 int cmd_init(char *args);
157 int cmd_format(char *args);
158 int cmd_proxy(char *args);
159 #if HAVE_YAZ_URSULA_H
160 int cmd_ursula(char *args);
161 int cmd_ursula_renew(char *args);
166 void MyClient::connectNotify()
168 printf ("Connection accepted by target\n");
169 set_lastReceived(-1);
172 void MyClient::timeoutNotify()
174 printf ("Connection timeout\n");
178 void MyClient::failNotify()
180 printf ("Connection closed by target\n");
181 set_lastReceived(-1);
184 IYaz_PDU_Observer *MyClient::sessionNotify(
185 IYaz_PDU_Observable *the_PDU_Observable, int fd)
187 return new MyClient(the_PDU_Observable, m_socketManager);
190 MyClient::MyClient(IYaz_PDU_Observable *the_PDU_Observable,
191 Yaz_SocketManager *the_socketManager) :
192 Yaz_IR_Assoc (the_PDU_Observable)
195 m_interactive_flag = 1;
196 m_thisCommand[0] = '\0';
197 m_lastCommand[0] = '\0';
198 m_socketManager = the_socketManager;
201 void usage(char *prog)
203 fprintf (stderr, "%s: [-v log] [-c cookie] [-p proxy] [zurl]\n", prog);
207 char *MyClient::get_cookie(Z_OtherInformation **otherInfo)
210 Z_OtherInformationUnit *oi;
212 ent.proto = PROTO_Z3950;
213 ent.oclass = CLASS_USERINFO;
214 ent.value = (oid_value) VAL_COOKIE;
216 if (oid_ent_to_oid (&ent, oid) &&
217 (oi = update_otherInformation(otherInfo, 0, oid, 1, 1)) &&
218 oi->which == Z_OtherInfo_characterInfo)
219 return oi->information.characterInfo;
223 void MyClient::recv_initResponse(Z_InitResponse *initResponse)
225 printf ("Got InitResponse. Status ");
226 if (*initResponse->result)
230 const char *p = get_cookie (&initResponse->otherInfo);
233 printf ("cookie = %s\n", p);
241 void MyClient::recv_diagrecs(Z_DiagRec **pp, int num)
245 Z_DefaultDiagFormat *r;
247 printf("Diagnostic message(s) from database:\n");
248 for (i = 0; i<num; i++)
250 Z_DiagRec *p = pp[i];
251 if (p->which != Z_DiagRec_defaultFormat)
253 printf("Diagnostic record not in default format.\n");
257 r = p->u.defaultFormat;
258 if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
259 ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
260 printf("Missing or unknown diagset\n");
261 printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition));
265 case Z_DefaultDiagFormat_v2Addinfo:
266 printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
268 case Z_DefaultDiagFormat_v3Addinfo:
269 printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
273 if (r->addinfo && *r->addinfo)
274 printf(" -- '%s'\n", r->addinfo);
281 void MyClient::recv_textRecord(int type, const char *buf, size_t len)
283 fwrite (buf, 1, len, stdout);
284 fputc ('\n', stdout);
287 void MyClient::display_variant(Z_Variant *v, int level)
291 for (i = 0; i < v->num_triples; i++)
293 printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
294 *v->triples[i]->type);
295 if (v->triples[i]->which == Z_Triple_internationalString)
296 printf(",value=%s\n", v->triples[i]->value.internationalString);
302 void MyClient::display_genericRecord(Z_GenericRecord *r, int level)
308 for (i = 0; i < r->num_elements; i++)
312 printf("%*s", level * 4, "");
316 printf("%d,", *t->tagType);
319 if (t->tagValue->which == Z_StringOrNumeric_numeric)
320 printf("%d) ", *t->tagValue->u.numeric);
322 printf("%s) ", t->tagValue->u.string);
323 if (t->content->which == Z_ElementData_subtree)
326 display_genericRecord(t->content->u.subtree, level+1);
328 else if (t->content->which == Z_ElementData_string)
329 printf("%s\n", t->content->u.string);
330 else if (t->content->which == Z_ElementData_numeric)
331 printf("%d\n", *t->content->u.numeric);
332 else if (t->content->which == Z_ElementData_oid)
334 int *ip = t->content->u.oid;
337 if ((oent = oid_getentbyoid(t->content->u.oid)))
338 printf("OID: %s\n", oent->desc);
342 while (ip && *ip >= 0)
343 printf(" %d", *(ip++));
347 else if (t->content->which == Z_ElementData_noDataRequested)
348 printf("[No data requested]\n");
349 else if (t->content->which == Z_ElementData_elementEmpty)
350 printf("[Element empty]\n");
351 else if (t->content->which == Z_ElementData_elementNotThere)
352 printf("[Element not there]\n");
355 if (t->appliedVariant)
356 display_variant(t->appliedVariant, level+1);
357 if (t->metaData && t->metaData->supportedVariants)
361 printf("%*s---- variant list\n", (level+1)*4, "");
362 for (c = 0; c < t->metaData->num_supportedVariants; c++)
364 printf("%*svariant #%d\n", (level+1)*4, "", c);
365 display_variant(t->metaData->supportedVariants[c], level + 2);
371 void MyClient::recv_genericRecord(Z_GenericRecord *r)
373 display_genericRecord(r, 0);
376 void MyClient::recv_record(Z_DatabaseRecord *record, int offset,
377 const char *databaseName)
379 Z_External *r = (Z_External*) record;
380 oident *ent = oid_getentbyoid(r->direct_reference);
383 * Tell the user what we got.
385 if (r->direct_reference)
387 printf("Record type: ");
389 printf("%s\n", ent->desc);
391 /* Check if this is a known, ASN.1 type tucked away in an octet string */
392 Z_ext_typeent *etype = z_ext_getentbyref(ent->value);
393 if (ent && (r->which == Z_External_octet || r->which == Z_External_single)
394 && (etype = z_ext_getentbyref(ent->value)))
399 * Call the given decoder to process the record.
401 odr_setbuf(odr_decode(), (char*)record->u.octet_aligned->buf,
402 record->u.octet_aligned->len, 0);
403 if (!(*etype->fun)(odr_decode(), (char **)&rr, 0, 0))
405 odr_perror(odr_decode(), "Decoding constructed record.");
406 fprintf(stderr, "[Near %d]\n", odr_offset(odr_decode()));
407 fprintf(stderr, "Packet dump:\n---------\n");
408 odr_dumpBER(stderr, (char*)record->u.octet_aligned->buf,
409 record->u.octet_aligned->len);
410 fprintf(stderr, "---------\n");
412 if (etype->what == Z_External_sutrs)
414 Z_SUTRS *sutrs = (Z_SUTRS *) rr;
415 recv_textRecord ((int) VAL_SUTRS, (const char *) sutrs->buf,
416 (size_t) sutrs->len);
420 if (r->which == Z_External_octet && record->u.octet_aligned->len)
446 marc_display((char*) record->u.octet_aligned->buf,0);
449 recv_textRecord((int) ent->value,
450 (const char *) record->u.octet_aligned->buf,
451 (size_t) record->u.octet_aligned->len);
454 else if (ent && ent->value == VAL_SUTRS && r->which == Z_External_sutrs)
455 recv_textRecord((int) VAL_SUTRS, (const char *) r->u.sutrs->buf,
456 (size_t) r->u.sutrs->len);
457 else if (ent && ent->value == VAL_GRS1 && r->which == Z_External_grs1)
458 recv_genericRecord(r->u.grs1);
461 printf("Unknown record representation.\n");
462 if (!z_External(odr_print(), &r, 0, 0))
464 odr_perror(odr_print(), "Printing external");
465 odr_reset(odr_print());
470 void MyClient::recv_namePlusRecord (Z_NamePlusRecord *zpr, int offset)
472 if (zpr->databaseName)
473 printf("[%s]", zpr->databaseName);
474 if (zpr->which == Z_NamePlusRecord_surrogateDiagnostic)
475 recv_diagrecs(&zpr->u.surrogateDiagnostic, 1);
477 recv_record(zpr->u.databaseRecord, offset, zpr->databaseName);
480 void MyClient::recv_records (Z_Records *records)
483 Z_DiagRec dr, *dr_p = &dr;
488 switch (records->which)
490 case Z_Records_DBOSD:
491 for (i = 0; i < records->u.databaseOrSurDiagnostics->num_records; i++)
492 recv_namePlusRecord(records->u.databaseOrSurDiagnostics->
493 records[i], i + m_setOffset);
494 m_setOffset += records->u.databaseOrSurDiagnostics->num_records;
498 dr.which = Z_DiagRec_defaultFormat;
499 dr.u.defaultFormat = records->u.nonSurrogateDiagnostic;
500 recv_diagrecs (&dr_p, 1);
502 recv_diagrecs (&records->u.nonSurrogateDiagnostic, 1);
505 case Z_Records_multipleNSD:
506 recv_diagrecs (records->u.multipleNonSurDiagnostics->diagRecs,
507 records->u.multipleNonSurDiagnostics->num_diagRecs);
512 void MyClient::recv_searchResponse(Z_SearchResponse *searchResponse)
514 printf ("Got SearchResponse. Status ");
515 if (!*searchResponse->searchStatus)
522 printf ("Hits: %d\n", *searchResponse->resultCount);
524 recv_records (searchResponse->records);
527 void MyClient::recv_presentResponse(Z_PresentResponse *presentResponse)
529 printf ("Got PresentResponse\n");
530 recv_records (presentResponse->records);
533 #if HAVE_YAZ_URSULA_H
534 void MyClient::recv_extendedServicesResponse(Z_ExtendedServicesResponse *extendedServicesResponse)
536 printf("Got ESresponse\n");
537 printf(" OperationStatus=%d with %d diagnostics:\n",
538 *extendedServicesResponse->operationStatus,
539 extendedServicesResponse->num_diagnostics);
540 recv_diagrecs(extendedServicesResponse->diagnostics,
541 extendedServicesResponse->num_diagnostics);
542 //TODO: Add more info !
549 while (m_socketManager->processEvent() > 0)
551 if (get_lastReceived())
558 #define C_PROMPT "Z>"
560 int MyClient::cmd_connect(char *host)
569 int MyClient::cmd_open(char *host)
580 int MyClient::cmd_init(char *args)
582 if (send_initRequest() >= 0)
589 int MyClient::cmd_quit(char *args)
594 int MyClient::cmd_close(char *args)
600 int MyClient::cmd_find(char *args)
604 if (query.set_rpn(args) <= 0)
606 printf ("Bad RPN query\n");
609 if (send_searchRequest(&query) >= 0)
612 printf ("Not connected\n");
616 int MyClient::cmd_show(char *args)
618 int start = m_setOffset, number = 1;
620 sscanf (args, "%d %d", &start, &number);
622 if (send_presentRequest(start, number) >= 0)
625 printf ("Not connected\n");
629 int MyClient::cmd_cookie(char *args)
631 set_cookie(*args ? args : 0);
635 int MyClient::cmd_format(char *args)
637 set_preferredRecordSyntax(args);
641 int MyClient::cmd_proxy(char *args)
647 #if HAVE_YAZ_URSULA_H
648 int MyClient::cmd_ursula(char *args)
650 Z_APDU *apdu = create_Z_PDU(Z_APDU_extendedServicesRequest);
651 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
653 req->packageType = odr_getoidbystr(odr_encode(), "1.2.840.10003");
654 // req->packageType = odr_getoidbystr(odr_encode(), "1.2.840.10003.9.1000.105.3");
656 Z_External *ext = (Z_External *) odr_malloc(odr_encode(), sizeof(*ext));
657 req->taskSpecificParameters = ext;
658 ext->direct_reference = req->packageType;
660 ext->indirect_reference = 0;
662 ext->which = Z_External_octet;
663 ext->u.single_ASN1_type = (Odr_oct *)
664 odr_malloc (odr_encode(), sizeof(Odr_oct));
666 Z_UrsPDU *pdu = (Z_UrsPDU *) odr_malloc (odr_encode(), sizeof(*pdu));
667 pdu->which = Z_UrsPDU_request;
668 pdu->u.request = (Z_UrsRequest *)
669 odr_malloc (odr_encode(), sizeof(*pdu->u.request));
670 pdu->u.request->libraryNo = odr_strdup(odr_encode(), "000200");
671 pdu->u.request->borrowerTickerNo = odr_strdup(odr_encode(),"1234567973");
672 pdu->u.request->disposalType = 0;
673 pdu->u.request->lastUseDate = odr_strdup(odr_encode(),"20011224");
675 pdu->u.request->num_items = 0;
676 pdu->u.request->items = (Z_UrsRequestItem **) odr_nullval();
678 pdu->u.request->num_items = 1;
679 pdu->u.request->items = (Z_UrsRequestItem **)
680 odr_malloc(odr_encode(), 1 * sizeof(Z_UrsRequestItem*) );
681 pdu->u.request->items[0] = (Z_UrsRequestItem*)
682 odr_malloc(odr_encode(), sizeof(Z_UrsRequestItem) );
683 pdu->u.request->items[0]->id = odr_strdup(odr_encode(),"002231336x");
684 pdu->u.request->items[0]->titlePartNo=odr_strdup(odr_encode(),"31");
687 pdu->u.request->counter = odr_strdup(odr_encode(),"HB");
688 pdu->u.request->priority = 0;
689 pdu->u.request->disposalNote = 0;
690 pdu->u.request->overrule=(bool_t*)odr_malloc(odr_encode(),sizeof(bool_t));
691 *pdu->u.request->overrule = false;
693 if (!z_UrsPDU (odr_encode(), &pdu, 0, ""))
695 yaz_log (LOG_LOG, "ursula encoding failed");
699 odr_getbuf (odr_encode(), &ext->u.single_ASN1_type->len, 0);
701 ext->u.single_ASN1_type->buf = (unsigned char*)
702 odr_malloc (odr_encode(), ext->u.single_ASN1_type->len);
703 memcpy (ext->u.single_ASN1_type->buf, buf, ext->u.single_ASN1_type->len);
704 ext->u.single_ASN1_type->size = ext->u.single_ASN1_type->len;
706 if (send_Z_PDU(apdu) >= 0)
711 int MyClient::cmd_ursula_renew(char *args)
713 Z_APDU *apdu = create_Z_PDU(Z_APDU_extendedServicesRequest);
714 Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
716 req->packageType = odr_getoidbystr(odr_encode(), "1.2.840.10003");
718 Z_External *ext = (Z_External *) odr_malloc(odr_encode(), sizeof(*ext));
719 req->taskSpecificParameters = ext;
720 ext->direct_reference = req->packageType;
722 ext->indirect_reference = 0;
724 ext->which = Z_External_octet;
725 ext->u.single_ASN1_type = (Odr_oct *)
726 odr_malloc (odr_encode(), sizeof(Odr_oct));
728 Z_UrsPDU *pdu = (Z_UrsPDU *) odr_malloc (odr_encode(), sizeof(*pdu));
729 pdu->which = Z_UrsPDU_renewal;
730 pdu->u.renewal = (Z_UrsRenewal *)
731 odr_malloc (odr_encode(), sizeof(*pdu->u.renewal));
732 pdu->u.renewal->libraryNo = odr_strdup(odr_encode(), "000200");
733 pdu->u.renewal->borrowerTicketNo = odr_strdup(odr_encode(),"1234567973");
734 pdu->u.renewal->num_copies=1;
735 pdu->u.renewal->copies = (Z_InternationalString **)
736 odr_malloc(odr_encode(),1* sizeof(Z_InternationalString *) );
737 pdu->u.renewal->copies[0]= odr_strdup(odr_encode(), "000035238");
738 pdu->u.renewal->newReturnDate=odr_strdup(odr_encode(), "20011224");
739 pdu->u.renewal->overrule=(bool_t*)odr_malloc(odr_encode(),sizeof(bool_t));
740 *pdu->u.renewal->overrule=false;
742 if (!z_UrsPDU (odr_encode(), &pdu, 0, ""))
744 yaz_log (LOG_LOG, "ursula encoding failed");
748 odr_getbuf (odr_encode(), &ext->u.single_ASN1_type->len, 0);
750 ext->u.single_ASN1_type->buf = (unsigned char*)
751 odr_malloc (odr_encode(), ext->u.single_ASN1_type->len);
752 memcpy (ext->u.single_ASN1_type->buf, buf, ext->u.single_ASN1_type->len);
753 ext->u.single_ASN1_type->size = ext->u.single_ASN1_type->len;
755 if (send_Z_PDU(apdu) >= 0)
763 int MyClient::processCommand(const char *commandLine)
765 char cmdStr[1024], cmdArgs[1024];
770 int (MyClient::*fun)(char *arg);
773 {"open", &MyClient::cmd_open, "<host>[':'<port>][/<database>]"},
774 {"connect", &MyClient::cmd_connect, "<host>[':'<port>][/<database>]"},
775 {"quit", &MyClient::cmd_quit, ""},
776 {"close", &MyClient::cmd_close, ""},
777 {"find", &MyClient::cmd_find, "<query>"},
778 {"show", &MyClient::cmd_show, "[<start> [<number>]]"},
779 {"cookie", &MyClient::cmd_cookie, "<cookie>"},
780 {"init", &MyClient::cmd_init, ""},
781 {"format", &MyClient::cmd_format, "<record-syntax>"},
782 {"proxy", &MyClient::cmd_proxy, "<host>:[':'<port>]"},
783 #if HAVE_YAZ_URSULA_H
784 {"ursula", &MyClient::cmd_ursula, ""},
785 {"ursula_request", &MyClient::cmd_ursula, ""},
786 {"ursreq", &MyClient::cmd_ursula, ""},
787 {"ursnew", &MyClient::cmd_ursula_renew, ""},
788 {"ursula_renew", &MyClient::cmd_ursula_renew, ""},
793 if (sscanf(commandLine, "%s %[^;]", cmdStr, cmdArgs) < 1)
796 for (i = 0; cmd[i].cmd; i++)
797 if (!strncmp(cmd[i].cmd, cmdStr, strlen(cmdStr)))
801 if (cmd[i].cmd) // Invoke command handler
802 res = (this->*cmd[i].fun)(cmdArgs);
803 else // Dump help screen
805 printf("Unknown command: %s.\n", cmdStr);
806 printf("Currently recognized commands:\n");
807 for (i = 0; cmd[i].cmd; i++)
808 printf(" %s %s\n", cmd[i].cmd, cmd[i].ad);
813 const char *MyClient::getCommand()
815 #if HAVE_READLINE_READLINE_H
816 // Read using GNU readline
818 line_in=readline(C_PROMPT);
821 #if HAVE_READLINE_HISTORY_H
823 add_history(line_in);
825 strncpy(m_thisCommand,line_in, 1023);
826 m_thisCommand[1023] = '\0';
829 // Read using fgets(3)
832 if (!fgets(m_thisCommand, 1023, stdin))
835 // Remove trailing whitespace
836 char *cp = m_thisCommand + strlen(m_thisCommand);
837 while (cp != m_thisCommand && strchr("\t \n", cp[-1]))
841 // Remove leading spaces...
842 while (*cp && strchr ("\t \n", *cp))
844 // Save command if non-empty
846 strcpy (m_lastCommand, cp);
847 return m_lastCommand;
850 int MyClient::interactive(Yaz_SocketManager *socketManager)
853 if (!m_interactive_flag)
855 while ((cmd = getCommand()))
857 if (!processCommand(cmd))
863 int MyClient::args(Yaz_SocketManager *socketManager, int argc, char **argv)
868 char *prog = argv[0];
871 while ((ret = options("c:p:v:q", argv, argc, &arg)) != -2)
895 yaz_log_init_level (yaz_log_mask_str(arg));
898 m_interactive_flag = 0;
917 int main(int argc, char **argv)
919 Yaz_SocketManager mySocketManager;
920 Yaz_PDU_Assoc *some = new Yaz_PDU_Assoc(&mySocketManager);
922 MyClient z(some, &mySocketManager);
924 if (z.args(&mySocketManager, argc, argv))
926 if (z.interactive(&mySocketManager))