X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=cabebb9e63f1f8d5c493f1b87e813996a0162553;hb=016a7b8249c7914dc028829009a7ea7574e29e51;hp=199af39067a0048215567b9b33d4744b4008092d;hpb=189fa86838b242b5f37e5ea2db92a84935050a81;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index 199af39..cabebb9 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,19 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.11 1995-06-14 15:26:40 quinn + * Revision 1.15 1995-06-22 09:28:03 quinn + * Fixed bug in SUTRS processing. + * + * Revision 1.14 1995/06/19 12:37:41 quinn + * Added BER dumper. + * + * Revision 1.13 1995/06/16 10:29:11 quinn + * *** empty log message *** + * + * Revision 1.12 1995/06/15 07:44:57 quinn + * Moving to v3. + * + * Revision 1.11 1995/06/14 15:26:40 quinn * *** empty log message *** * * Revision 1.10 1995/06/06 14:56:58 quinn @@ -60,8 +72,8 @@ #endif #include - #include +#include #ifdef RPN_QUERY #ifdef PREFIX_QUERY @@ -83,6 +95,7 @@ static int largeSetLowerBound = 1; static int mediumSetPresentNumber = 0; static int setno = 1; /* current set offset */ static int protocol = PROTO_Z3950; /* current app protocol */ +static int recordsyntax = VAL_USMARC; static ODR_MEM session_mem; /* memory handle for init-response */ static Z_InitResponse *session = 0; /* session parameters */ static char last_scan[512] = "0"; @@ -254,11 +267,10 @@ int cmd_authentication(char *arg) void display_record(Z_DatabaseRecord *p) { Odr_external *r = (Odr_external*) p; + oident *ent = oid_getentbyoid(r->direct_reference); if (r->direct_reference) { - oident *ent = oid_getentbyoid(r->direct_reference); - printf("Record type: "); if (ent) printf("%s\n", ent->desc); @@ -268,20 +280,28 @@ void display_record(Z_DatabaseRecord *p) odr_reset(print); } } -#if 1 if (r->which == ODR_EXTERNAL_octet && p->u.octet_aligned->len) - { -#if 1 marc_display ((char*)p->u.octet_aligned->buf, stdout); -#else - FILE *ofi = fopen("dump", "a"); - assert(ofi); - fwrite(p->u.octet_aligned->buf, 1, p->u.octet_aligned->len, ofi); - fclose(ofi); - printf("dumped record\n"); -#endif + else if (ent->value == VAL_SUTRS) + { + Odr_oct *rc; + + if (r->which != ODR_EXTERNAL_single) + { + printf("Expecting single ASN.1 type for SUTRS.\n"); + return; + } + odr_setbuf(in, (char*)r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len, 0); + if (!z_SUTRS(in, &rc, 0)) + { + odr_perror(in, "decoding SUTRS"); + odr_reset(in); + } + else + printf("%.*s", rc->len, rc->buf); } - else + else { printf("Unknown record representation.\n"); if (!odr_external(print, &r, 0)) @@ -290,19 +310,35 @@ void display_record(Z_DatabaseRecord *p) odr_reset(print); } } -#endif } static void display_diagrec(Z_DiagRec *p) { oident *ent; +#ifdef Z_95 + Z_DefaultDiagFormat *r; +#else + Z_DiagRec *r = p; +#endif - printf("Diagnostic message from database.\n"); - if (!(ent = oid_getentbyoid(p->diagnosticSetId)) || + printf("Diagnostic message from database:\n"); +#ifdef Z_95 + if (p->which != Z_DiagRec_defaultFormat) + { + printf("Diagnostic record not in default format.\n"); + return; + } + else + r = p->u.defaultFormat; +#endif + if (!(ent = oid_getentbyoid(r->diagnosticSetId)) || ent->class != CLASS_DIAGSET || ent->value != VAL_BIB1) printf("Missing or unknown diagset\n"); - printf("Error condition: %d", *p->condition); - printf(" -- %s\n", p->addinfo ? p->addinfo : ""); + printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition)); + if (r->addinfo && *r->addinfo) + printf(" -- %s\n", r->addinfo); + else + printf("\n"); } static void display_nameplusrecord(Z_NamePlusRecord *p) @@ -380,6 +416,16 @@ static int send_searchRequest(char *arg) *req->smallSetUpperBound = smallSetUpperBound; *req->largeSetLowerBound = largeSetLowerBound; *req->mediumSetPresentNumber = mediumSetPresentNumber; + if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 && + mediumSetPresentNumber > 0)) + { + oident prefsyn; + + prefsyn.proto = protocol; + prefsyn.class = CLASS_RECSYN; + prefsyn.value = recordsyntax; + req->preferredRecordSyntax = odr_oiddup(out, oid_getoidbyent(&prefsyn)); + } req->num_databaseNames = 1; req->databaseNames = &databaseNames; @@ -510,6 +556,7 @@ static int send_presentRequest(char *arg) { Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest); Z_PresentRequest *req = apdu->u.presentRequest; + oident prefsyn; int nos = 1; char *p; char setstring[100]; @@ -529,6 +576,10 @@ static int send_presentRequest(char *arg) } req->resultSetStartPoint = &setno; req->numberOfRecordsRequested = &nos; + prefsyn.proto = protocol; + prefsyn.class = CLASS_RECSYN; + prefsyn.value = recordsyntax; + req->preferredRecordSyntax = oid_getoidbyent(&prefsyn); send_apdu(apdu); printf("Sent presentRequest (%d+%d).\n", setno, nos); return 2; @@ -646,15 +697,47 @@ int cmd_scan(char *arg) } if (*arg) { - if (send_scanrequest(arg, 5, 19) < 0) + if (send_scanrequest(arg, 5, 20) < 0) return 0; } else - if (send_scanrequest(last_scan, 1, 19) < 0) + if (send_scanrequest(last_scan, 1, 20) < 0) return 0; return 2; } +int cmd_format(char *arg) +{ + if (!arg || !*arg) + { + printf("Usage: format \n"); + return 0; + } + if (!strcmp(arg, "sutrs")) + { + printf("Preferred format is SUTRS.\n"); + recordsyntax = VAL_SUTRS; + return 1; + } + else if (!strcmp(arg, "usmarc")) + { + printf("Preferred format is USMARC\n"); + recordsyntax = VAL_USMARC; + return 1; + } + else if (!strcmp(arg, "danmarc")) + { + printf("Preferred format is DANMARC\n"); + recordsyntax = VAL_DANMARC; + return 1; + } + else + { + printf("Specify one of {sutrs,usmarc,danmarc}.\n"); + return 0; + } +} + static void initialize(void) { #ifdef RPN_QUERY @@ -705,6 +788,7 @@ static int client(void) {"status", cmd_status, ""}, {"setnames", cmd_setnames, ""}, {"cancel", cmd_cancel, ""}, + {"format", cmd_format, ""}, {0,0} }; char *netbuffer= 0; @@ -778,6 +862,9 @@ static int client(void) if (!z_APDU(in, &apdu, 0)) { odr_perror(in, "Decoding incoming APDU"); + fprintf(stderr, "Packet dump:\n---------\n"); + odr_dumpBER(stderr, netbuffer, res); + fprintf(stderr, "---------\n"); exit(1); } #if 0