X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=d82a8ffc5f12e13b5ab2e75d7f62e40f354a31f8;hb=32226dbfb020481e8589fad8f5f349eff63e3273;hp=3189faf78d17b85850c3aa969706356176ab67fa;hpb=42d3d8a6486c495357574e5db0fc736834d8ba40;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index 3189faf..d82a8ff 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,19 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.14 1995-06-19 12:37:41 quinn + * Revision 1.18 1995-08-28 12:21:27 quinn + * Client can now ask for simple element set names. + * + * Revision 1.17 1995/08/17 12:45:02 quinn + * Fixed minor problems with GRS-1. Added support in c&s. + * + * Revision 1.16 1995/08/15 12:00:04 quinn + * Updated External + * + * 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 @@ -90,6 +102,7 @@ static int setnumber = 0; /* current result set number */ static int smallSetUpperBound = 0; static int largeSetLowerBound = 1; static int mediumSetPresentNumber = 0; +static Z_ElementSetNames *elementSetNames = 0; static int setno = 1; /* current set offset */ static int protocol = PROTO_Z3950; /* current app protocol */ static int recordsyntax = VAL_USMARC; @@ -163,7 +176,7 @@ static int process_initResponse(Z_InitResponse *res) if (res->userInformationField) { printf("UserInformationfield:\n"); - if (!odr_external(print, (Odr_external**)&res-> userInformationField, + if (!z_External(print, (Z_External**)&res-> userInformationField, 0)) { odr_perror(print, "Printing userinfo\n"); @@ -261,9 +274,42 @@ int cmd_authentication(char *arg) /* SEARCH SERVICE ------------------------------ */ +void display_grs1(Z_GenericRecord *r, int level) +{ + int i; + + if (!r) + return; + for (i = 0; i < r->num_elements; i++) + { + Z_TaggedElement *t; + + printf("%*s", level * 4, ""); + t = r->elements[i]; + printf("("); + if (t->tagType) + printf("%d,", *t->tagType); + else + printf("?,"); + if (t->tagValue->which == Z_StringOrNumeric_numeric) + printf("%d) ", *t->tagValue->u.numeric); + else + printf("%s) ", t->tagValue->u.string); + if (t->content->which == Z_ElementData_subtree) + { + printf("\n"); + display_grs1(t->content->u.subtree, level+1); + } + else if (t->content->which == Z_ElementData_string) + printf("%s\n", t->content->u.string); + else + printf("??????\n"); + } +} + void display_record(Z_DatabaseRecord *p) { - Odr_external *r = (Odr_external*) p; + Z_External *r = (Z_External*) p; oident *ent = oid_getentbyoid(r->direct_reference); if (r->direct_reference) @@ -281,20 +327,26 @@ void display_record(Z_DatabaseRecord *p) marc_display ((char*)p->u.octet_aligned->buf, stdout); else if (ent->value == VAL_SUTRS) { - Odr_oct *rc; - - if (!z_SUTRS(in, &rc, 0)) + if (r->which != Z_External_sutrs) { - odr_perror(in, "decoding SUTRS"); - odr_reset(in); + printf("Expecting single SUTRS type for SUTRS.\n"); + return; } - else - printf("%.*s", rc->len, rc->buf); + printf("%.*s", r->u.sutrs->len, r->u.sutrs->buf); + } + else if (ent->value == VAL_GRS1) + { + if (r->which != Z_External_grs1) + { + printf("Expecting single GRS type for GRS.\n"); + return; + } + display_grs1(r->u.grs1, 0); } else { printf("Unknown record representation.\n"); - if (!odr_external(print, &r, 0)) + if (!z_External(print, &r, 0)) { odr_perror(print, "Printing external"); odr_reset(print); @@ -415,6 +467,8 @@ static int send_searchRequest(char *arg) prefsyn.class = CLASS_RECSYN; prefsyn.value = recordsyntax; req->preferredRecordSyntax = odr_oiddup(out, oid_getoidbyent(&prefsyn)); + req->smallSetElementSetNames = + req->mediumSetElementSetNames = elementSetNames; } req->num_databaseNames = 1; req->databaseNames = &databaseNames; @@ -546,6 +600,7 @@ static int send_presentRequest(char *arg) { Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest); Z_PresentRequest *req = apdu->u.presentRequest; + Z_RecordComposition compo; oident prefsyn; int nos = 1; char *p; @@ -570,6 +625,12 @@ static int send_presentRequest(char *arg) prefsyn.class = CLASS_RECSYN; prefsyn.value = recordsyntax; req->preferredRecordSyntax = oid_getoidbyent(&prefsyn); + if (elementSetNames) + { + req->recordComposition = &compo; + compo.which = Z_RecordComp_simple; + compo.u.simple = elementSetNames; + } send_apdu(apdu); printf("Sent presentRequest (%d+%d).\n", setno, nos); return 2; @@ -721,13 +782,36 @@ int cmd_format(char *arg) recordsyntax = VAL_DANMARC; return 1; } + else if (!strcmp(arg, "grs1")) + { + printf("Preferred format is GRS1\n"); + recordsyntax = VAL_GRS1; + return 1; + } else { - printf("Specify one of {sutrs,usmarc,danmarc}.\n"); + printf("Specify one of {sutrs,usmarc,danmarc,grs1}.\n"); return 0; } } +int cmd_elements(char *arg) +{ + static Z_ElementSetNames esn; + static char what[100]; + + if (!arg || !*arg) + { + printf("Usage: elements \n"); + return 0; + } + strcpy(what, arg); + esn.which = Z_ElementSetNames_generic; + esn.u.generic = what; + elementSetNames = &esn; + return 1; +} + static void initialize(void) { #ifdef RPN_QUERY @@ -779,6 +863,7 @@ static int client(void) {"setnames", cmd_setnames, ""}, {"cancel", cmd_cancel, ""}, {"format", cmd_format, ""}, + {"elements", cmd_elements, ""}, {0,0} }; char *netbuffer= 0;