X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=d652ee2b6ecdf807f96f447fd731a79ce8a032a9;hp=fd12e2db1cf2149a60cf6795a2303f0feb7930c1;hb=214a19efbb9f3ccb3cfe678b5c9ba805774b3d12;hpb=7c3682d1d90e48dadca5e8c9b482044cbd65e939 diff --git a/client/client.c b/client/client.c index fd12e2d..d652ee2 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,34 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.22 1995-10-11 14:49:12 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 + * Added Explain record syntax to the format command. + * + * Revision 1.27 1995/12/12 16:37:02 quinn + * Added destroy element to data1_node. + * + * Revision 1.26 1995/12/12 14:11:00 quinn + * Minimal. + * + * Revision 1.25 1995/11/13 09:27:22 quinn + * Fiddling with the variant stuff. + * + * Revision 1.24 1995/10/30 12:41:13 quinn + * Added hostname lookup for server. + * + * Revision 1.23 1995/10/18 16:12:30 quinn + * Better diagnostics. + * + * Revision 1.22 1995/10/11 14:49:12 quinn * Smallish. * * Revision 1.21 1995/09/29 17:01:47 quinn @@ -127,6 +154,10 @@ static ODR_MEM session_mem; /* memory handle for init-response */ 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 static CCL_bibset bibset; /* CCL bibset handle */ @@ -144,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))); @@ -169,6 +200,8 @@ static void send_initRequest() ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2); ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3); + *req->maximumRecordSize = 1024*1024; + req->idAuthentication = auth; send_apdu(apdu); @@ -292,7 +325,22 @@ int cmd_authentication(char *arg) /* SEARCH SERVICE ------------------------------ */ -void display_grs1(Z_GenericRecord *r, int level) +static void display_variant(Z_Variant *v, int level) +{ + int i; + + for (i = 0; i < v->num_triples; i++) + { + printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->class, + *v->triples[i]->type); + if (v->triples[i]->which == Z_Triple_internationalString) + printf(",value=%s\n", v->triples[i]->value.internationalString); + else + printf("\n"); + } +} + +static void display_grs1(Z_GenericRecord *r, int level) { int i; @@ -322,16 +370,38 @@ void display_grs1(Z_GenericRecord *r, int level) printf("%s\n", t->content->u.string); else if (t->content->which == Z_ElementData_numeric) printf("%d\n", *t->content->u.numeric); + else if (t->content->which == Z_ElementData_noDataRequested) + printf("[No data requested]\n"); + else if (t->content->which == Z_ElementData_elementEmpty) + printf("[Element empty]\n"); + else if (t->content->which == Z_ElementData_elementNotThere) + printf("[Element not there]\n"); else printf("??????\n"); + if (t->appliedVariant) + display_variant(t->appliedVariant, level+1); + if (t->metaData && t->metaData->supportedVariants) + { + int c; + + printf("%*s---- variant list\n", (level+1)*4, ""); + for (c = 0; c < t->metaData->num_supportedVariants; c++) + { + printf("%*svariant #%d\n", (level+1)*4, "", c); + display_variant(t->metaData->supportedVariants[c], level + 2); + } + } } } -void display_record(Z_DatabaseRecord *p) +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: "); @@ -343,6 +413,38 @@ 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) @@ -394,7 +496,7 @@ static void display_diagrec(Z_DiagRec *p) r = p->u.defaultFormat; #endif if (!(ent = oid_getentbyoid(r->diagnosticSetId)) || - ent->class != CLASS_DIAGSET || ent->value != VAL_BIB1) + ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1) printf("Missing or unknown diagset\n"); printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition)); if (r->addinfo && *r->addinfo) @@ -484,7 +586,7 @@ static int send_searchRequest(char *arg) oident prefsyn; prefsyn.proto = protocol; - prefsyn.class = CLASS_RECSYN; + prefsyn.oclass = CLASS_RECSYN; prefsyn.value = recordsyntax; req->preferredRecordSyntax = odr_oiddup(out, oid_getoidbyent(&prefsyn)); req->smallSetElementSetNames = @@ -509,7 +611,7 @@ static int send_searchRequest(char *arg) } #endif bib1.proto = protocol; - bib1.class = CLASS_ATTSET; + bib1.oclass = CLASS_ATTSET; bib1.value = VAL_BIB1; RPNquery->attributeSetId = oid_getoidbyent(&bib1); query.u.type_1 = RPNquery; @@ -642,7 +744,7 @@ static int send_presentRequest(char *arg) req->resultSetStartPoint = &setno; req->numberOfRecordsRequested = &nos; prefsyn.proto = protocol; - prefsyn.class = CLASS_RECSYN; + prefsyn.oclass = CLASS_RECSYN; prefsyn.value = recordsyntax; req->preferredRecordSyntax = oid_getoidbyent(&prefsyn); if (elementSetNames) @@ -665,13 +767,13 @@ void process_close(Z_Close *req) { "finished", "shutdown", - "systemProblem", - "costLimit", + "system problem", + "cost limit reached", "resources", - "securityViolation", + "security violation", "protocolError", - "lackOfActivity", - "peerAbort", + "lack of activity", + "peer abort", "unspecified" }; @@ -736,7 +838,7 @@ int send_scanrequest(char *string, int pp, int num) req->num_databaseNames = 1; req->databaseNames = &db; attset.proto = protocol; - attset.class = CLASS_ATTSET; + attset.oclass = CLASS_ATTSET; attset.value = VAL_BIB1; req->attributeSet = oid_getoidbyent(&attset); req->termListAndStartPoint = p_query_scan(out, string); @@ -840,6 +942,12 @@ int cmd_format(char *arg) recordsyntax = VAL_GRS1; return 1; } + else if (!strcmp(arg, "explain")) + { + printf("Preferred format is Explain\n"); + recordsyntax = VAL_EXPLAIN; + return 1; + } else { printf("Specify one of {sutrs,usmarc,danmarc,grs1}.\n"); @@ -864,6 +972,26 @@ int cmd_elements(char *arg) return 1; } +int cmd_attributeset(char *arg) +{ + char what[100]; + oid_value v; + + if (!arg || !*arg) + { + printf("Usage: attributeset \n"); + return 0; + } + sscanf(arg, "%s", what); + if ((v = oid_getvalbyname(what)) == VAL_NONE) + { + printf("Unknown attribute set name\n"); + return 0; + } + attributeset = v; + return 1; +} + int cmd_close(char *arg) { Z_APDU *apdu = zget_APDU(out, Z_APDU_close); @@ -929,6 +1057,7 @@ static int client(void) {"format", cmd_format, ""}, {"elements", cmd_elements, ""}, {"close", cmd_close, ""}, + {"attributeset", cmd_attributeset, ""}, {0,0} }; char *netbuffer= 0; @@ -1002,6 +1131,7 @@ static int client(void) if (!z_APDU(in, &apdu, 0)) { odr_perror(in, "Decoding incoming APDU"); + fprintf(stderr, "[Near %d]\n", odr_offset(in)); fprintf(stderr, "Packet dump:\n---------\n"); odr_dumpBER(stderr, netbuffer, res); fprintf(stderr, "---------\n"); @@ -1044,7 +1174,7 @@ static int client(void) apdu->which); exit(1); } - printf("Z> "); + printf(C_PROMPT); fflush(stdout); } while (cs_more(conn)); @@ -1060,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(); }