/*
- * Copyright (c) 1995-2001, Index Data
+ * Copyright (c) 1995-2002, Index Data
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.132 2001-11-21 11:13:13 adam Exp $
+ * $Id: client.c,v 1.136 2002-01-23 22:40:36 adam Exp $
*/
#include <stdio.h>
static char ccl_fields[512] = "default.bib";
static char* esPackageName = 0;
static char* yazProxy = 0;
+static int kilobytes = 1024;
static char last_cmd[32] = "?";
static FILE *marcdump = 0;
/* set this one to 1, to avoid decode of unknown MARCs */
-#define AVOID_MARC_DECODE 0
+#define AVOID_MARC_DECODE 1
void process_cmd_line(char* line);
odr_reset(out); /* release the APDU structure */
}
+static void print_stringn(const unsigned char *buf, size_t len)
+{
+ size_t i;
+ for (i = 0; i<len; i++)
+ if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
+ fputc (buf[i], stdout);
+ else
+ printf ("\\X%02X", buf[i]);
+}
+
static void print_refid (Z_ReferenceId *id)
{
if (id)
{
- printf ("ReferenceId: '%.*s'\n", id->len, id->buf);
+ printf ("Reference Id: ");
+ print_stringn (id->buf, id->len);
+ printf ("\n");
}
}
ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
- *req->maximumRecordSize = 1024*1024;
- *req->preferredMessageSize = 1024*1024;
+ *req->maximumRecordSize = 1024*kilobytes;
+ *req->preferredMessageSize = 1024*kilobytes;
req->idAuthentication = auth;
}
}
+
static void print_record(const unsigned char *buf, size_t len)
{
- size_t i;
- for (i = 0; i<len; i++)
- if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
- fputc (buf[i], stdout);
- else
- printf ("\\X%02X", buf[i]);
- /* add newline if not already added ... */
- if (i <= 0 || buf[i-1] != '\n')
+ size_t i = len;
+ print_stringn (buf, len);
+ /* add newline if not already added ... */
+ if (i <= 0 || buf[i-1] != '\n')
fputc ('\n', stdout);
}
-static void display_record(Z_DatabaseRecord *p)
+static void display_record(Z_External *r)
{
- Z_External *r = (Z_External*) p;
oident *ent = oid_getentbyoid(r->direct_reference);
record_last = r;
/*
* Call the given decoder to process the record.
*/
- odr_setbuf(in, (char*)p->u.octet_aligned->buf,
- p->u.octet_aligned->len, 0);
+ odr_setbuf(in, (char*)r->u.octet_aligned->buf,
+ r->u.octet_aligned->len, 0);
if (!(*type->fun)(in, (char **)&rr, 0, 0))
{
odr_perror(in, "Decoding constructed record.");
fprintf(stderr, "[Near %d]\n", odr_offset(in));
fprintf(stderr, "Packet dump:\n---------\n");
- odr_dumpBER(stderr, (char*)p->u.octet_aligned->buf,
- p->u.octet_aligned->len);
+ odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf,
+ r->u.octet_aligned->len);
fprintf(stderr, "---------\n");
exit(1);
}
if (ent && ent->value == VAL_SOIF)
print_record((const unsigned char *) r->u.octet_aligned->buf,
r->u.octet_aligned->len);
- else if (r->which == Z_External_octet && p->u.octet_aligned->len)
+ else if (r->which == Z_External_octet && r->u.octet_aligned->len)
{
- const char *octet_buf = (char*)p->u.octet_aligned->buf;
+ const char *octet_buf = (char*)r->u.octet_aligned->buf;
if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML ||
ent->value == VAL_HTML)
+ {
print_record((const unsigned char *) octet_buf,
- p->u.octet_aligned->len);
+ r->u.octet_aligned->len);
+ }
+ else if (ent->value == VAL_POSTSCRIPT)
+ {
+ int size = r->u.octet_aligned->len;
+ if (size > 100)
+ size = 100;
+ print_record((const unsigned char *) octet_buf, size);
+ }
else
{
if (
#if AVOID_MARC_DECODE
/* primitive check for a marc OID 5.1-29 */
- ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
+ ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30
+#else
+ 1
#endif
- marc_display_exl (octet_buf, NULL, 0 /* debug */,
- p->u.octet_aligned->len) <= 0)
+ )
+ {
+ if (marc_display_exl (octet_buf, NULL, 0 /* debug */,
+ r->u.octet_aligned->len) <= 0)
+ {
+ printf ("bad MARC. Dumping as it is:\n");
+ print_record((const unsigned char*) octet_buf,
+ r->u.octet_aligned->len);
+ }
+ }
+ else
{
- printf ("Hmm.. doesn't look like a MARC.\n");
print_record((const unsigned char*) octet_buf,
- p->u.octet_aligned->len);
- } else {
- print_record((const unsigned char*) octet_buf,
- p->u.octet_aligned->len);
+ r->u.octet_aligned->len);
}
}
if (marcdump)
- fwrite (octet_buf, 1, p->u.octet_aligned->len, marcdump);
+ fwrite (octet_buf, 1, r->u.octet_aligned->len, marcdump);
}
else if (ent && ent->value == VAL_SUTRS)
{
void process_ESResponse(Z_ExtendedServicesResponse *res)
{
- printf("process_ESResponse status=");
+ printf("Status: ");
switch (*res->operationStatus)
{
case Z_ExtendedServicesResponse_done:
printf ("failure\n");
display_diagrecs(res->diagnostics, res->num_diagnostics);
break;
+ default:
+ printf ("unknown\n");
}
if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
(res->num_diagnostics != 0) ) {
display_diagrecs(res->diagnostics, res->num_diagnostics);
}
-
+ print_refid (res->referenceId);
+ if (res->taskPackage &&
+ res->taskPackage->which == Z_External_extendedService)
+ {
+ Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
+ Odr_oct *id = taskPackage->targetReference;
+ Z_External *ext = taskPackage->taskSpecificParameters;
+
+ if (id)
+ {
+ printf ("Target Reference: ");
+ print_stringn (id->buf, id->len);
+ printf ("\n");
+ }
+ if (ext->which == Z_External_update)
+ {
+ Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
+ if (utp && utp->targetPart)
+ {
+ Z_IUTargetPart *targetPart = utp->targetPart;
+ int i;
+
+ for (i = 0; i<targetPart->num_taskPackageRecords; i++)
+ {
+
+ Z_IUTaskPackageRecordStructure *tpr =
+ targetPart->taskPackageRecords[i];
+ printf ("task package record %d\n", i+1);
+ if (tpr->which == Z_IUTaskPackageRecordStructure_record)
+ {
+ display_record (tpr->u.record);
+ }
+ else
+ {
+ printf ("other type\n");
+ }
+ }
+ }
+ }
+ }
}
#if YAZ_MODULE_ill
const char *get_ill_element (void *clientData, const char *element)
{
- printf ("%s\n", element);
return 0;
}
{
char *prog = *argv;
char *open_command = 0;
+ char *auth_command = 0;
char *arg;
int ret;
- while ((ret = options("c:a:m:v:p:", argv, argc, &arg)) != -2)
+ while ((ret = options("k:c:a:m:v:p:u:", argv, argc, &arg)) != -2)
{
switch (ret)
{
strcat (open_command, arg);
}
break;
+ case 'k':
+ kilobytes = atoi(arg);
+ break;
case 'm':
if (!(marcdump = fopen (arg, "a")))
{
case 'p':
yazProxy=strdup(arg);
break;
+ case 'u':
+ if (!auth_command)
+ {
+ auth_command = xmalloc (strlen(arg)+6);
+ strcpy (auth_command, "auth ");
+ strcat (auth_command, arg);
+ }
+ break;
case 'v':
yaz_log_init (yaz_log_mask_str(arg), "", NULL);
break;
default:
fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
- "[-c cclfields] [-p <proxy-addr>] [<server-addr>]\n",
+ "[-c cclfields]\n [-p <proxy-addr>] [-u <auth>] "
+ "[<server-addr>]\n",
prog);
exit (1);
}
}
initialize();
+ if (auth_command)
+ {
+#ifdef HAVE_GETTIMEOFDAY
+ gettimeofday (&tv_start, 0);
+#endif
+ process_cmd_line (auth_command);
+#if HAVE_READLINE_HISTORY_H
+ add_history(auth_command);
+#endif
+ xfree(auth_command);
+ }
if (open_command)
{
#ifdef HAVE_GETTIMEOFDAY