X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=d652ee2b6ecdf807f96f447fd731a79ce8a032a9;hb=ec28e95aa1800749663124d88106bc86b28b8ada;hp=f1537008ccd9d40b98077f3333133bd07d053d7d;hpb=4ae699c927bc26f3550d1a8ca911e8d1fe75dbfc;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index f153700..d652ee2 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,13 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.29 1996-01-02 08:57:25 quinn + * Revision 1.31 1996-02-20 12:51:54 quinn + * Fixed problems with EXTERNAL. + * + * Revision 1.30 1996/02/12 18:18:09 quinn + * Fidgeting. + * + * Revision 1.29 1996/01/02 08:57:25 quinn * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass * * Revision 1.28 1995/12/14 11:09:31 quinn @@ -149,6 +155,8 @@ static Z_InitResponse *session = 0; /* session parameters */ static char last_scan[512] = "0"; static char last_cmd[100] = "?"; static oid_value attributeset = VAL_BIB1; +static FILE *marcdump = 0; +static char marcdump_file[512] = "marc.out"; #ifdef RPN_QUERY #ifndef PREFIX_QUERY @@ -167,7 +175,7 @@ static void send_apdu(Z_APDU *a) exit(1); } buf = odr_getbuf(out, &len, 0); - odr_reset(out); /* release the APDU */ + odr_reset(out); /* release the APDU structure */ if (cs_put(conn, buf, len) < 0) { fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn))); @@ -391,6 +399,9 @@ static void display_record(Z_DatabaseRecord *p) Z_External *r = (Z_External*) p; oident *ent = oid_getentbyoid(r->direct_reference); + /* + * Tell the user what we got. + */ if (r->direct_reference) { printf("Record type: "); @@ -402,6 +413,38 @@ static void display_record(Z_DatabaseRecord *p) odr_reset(print); } } + + /* Check if this is a known, ASN.1 type tucked away in an octet string */ + if (ent && r->which == Z_External_octet) + { + Z_ext_typeent *type = z_ext_getentbyref(ent->value); + void *rr; + + if (type) + { + /* + * Call the given decoder to process the record. + */ + odr_setbuf(in, (char*)p->u.octet_aligned->buf, + p->u.octet_aligned->len, 0); + if (!(*type->fun)(in, &rr, 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); + fprintf(stderr, "---------\n"); + exit(1); + } + /* + * Note: we throw away the original, BER-encoded record here. + * Do something else with it if you want to keep it. + */ + r->u.sutrs = rr; /* we don't actually check the type here. */ + r->which = type->what; + } + } if (r->which == Z_External_octet && p->u.octet_aligned->len) marc_display ((char*)p->u.octet_aligned->buf, stdout); else if (ent->value == VAL_SUTRS) @@ -1147,5 +1190,10 @@ int main(int argc, char **argv) cmd_open(argv[1]); else printf(C_PROMPT); + if (*marcdump_file && !(marcdump = fopen(marcdump_file, "a"))) + { + perror(marcdump_file); + exit(1); + } return client(); }