X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=a224fcd25b63c5d05f072853ced2c88186ccf3b4;hb=fc2093cfd23eda0ee8384b18dc7e7b8adffd073a;hp=5623f464387fbd8849928fbc7fc667907076df4a;hpb=5e81facdf5baf68e33e3370bbc3aa6226dac5bc2;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index 5623f46..a224fcd 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,29 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.85 1999-06-16 11:55:24 adam + * Revision 1.92 1999-12-21 16:24:48 adam + * More robust ISO2709 handling (in case of real bad formats). + * + * Revision 1.91 1999/12/16 23:36:19 adam + * Implemented ILL protocol. Minor updates ASN.1 compiler. + * + * Revision 1.90 1999/11/30 13:47:11 adam + * Improved installation. Moved header files to include/yaz. + * + * Revision 1.89 1999/11/04 14:58:44 adam + * Added status elements for backend delete result set handler. + * Updated delete result result set command for client. + * + * Revision 1.88 1999/10/11 10:00:29 adam + * Modified printing of records. + * + * Revision 1.87 1999/08/27 09:40:32 adam + * Renamed logf function to yaz_log. Removed VC++ project files. + * + * Revision 1.86 1999/07/06 12:13:35 adam + * Added "schema" command. + * + * Revision 1.85 1999/06/16 11:55:24 adam * Added APDU log to client. * * Revision 1.84 1999/06/01 14:29:11 adam @@ -285,21 +307,25 @@ #include #include -#include +#include -#include +#include #ifdef USE_XTIMOSI -#include +#include #endif -#include -#include -#include +#include +#include +#include + +#include -#include +#ifdef ASN_COMPILED +#include +#endif #if CCL2RPN -#include +#include #endif #if HAVE_READLINE_READLINE_H @@ -326,6 +352,7 @@ static Z_ElementSetNames *elementSetNames = 0; static int setno = 1; /* current set offset */ static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */ static enum oid_value recordsyntax = VAL_USMARC; +static enum oid_value schema = VAL_NONE; static int sent_close = 0; static NMEM session_mem = NULL; /* memory handle for init-response */ static Z_InitResponse *session = 0; /* session parameters */ @@ -411,6 +438,7 @@ static void send_initRequest() ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3); *req->maximumRecordSize = 1024*1024; + *req->preferredMessageSize = 1024*1024; req->idAuthentication = auth; @@ -655,6 +683,19 @@ static void display_grs1(Z_GenericRecord *r, int level) } } +static void print_record(const unsigned char *buf, size_t len) +{ + size_t i; + for (i = 0; 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') + fputc ('\n', stdout); +} + static void display_record(Z_DatabaseRecord *p) { Z_External *r = (Z_External*) p; @@ -707,23 +748,21 @@ static void display_record(Z_DatabaseRecord *p) } } if (ent && ent->value == VAL_SOIF) - printf("%.*s", r->u.octet_aligned->len, r->u.octet_aligned->buf); + print_record(r->u.octet_aligned->buf, r->u.octet_aligned->len); else if (r->which == Z_External_octet && p->u.octet_aligned->len) { const char *octet_buf = (char*)p->u.octet_aligned->buf; if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML || ent->value == VAL_HTML) - { - int i; - for (i = 0; iu.octet_aligned->len; i++) - if (octet_buf[i] > 126 || octet_buf[i] < 7) - printf ("<%02X>", octet_buf[i]); - else - fputc (octet_buf[i], stdout); - printf ("\n"); - } + print_record(octet_buf, p->u.octet_aligned->len); else - marc_display (octet_buf, NULL); + { + if (marc_display (octet_buf, NULL) <= 0) + { + printf ("ISO2709 decoding failed, dumping record as is:\n"); + print_record(octet_buf, p->u.octet_aligned->len); + } + } if (marcdump) fwrite (octet_buf, 1, p->u.octet_aligned->len, marcdump); } @@ -734,7 +773,7 @@ static void display_record(Z_DatabaseRecord *p) printf("Expecting single SUTRS type for SUTRS.\n"); return; } - printf("%.*s", r->u.sutrs->len, r->u.sutrs->buf); + print_record(r->u.sutrs->buf, r->u.sutrs->len); } else if (ent && ent->value == VAL_GRS1) { @@ -836,18 +875,35 @@ static void display_records(Z_Records *p) static int send_deleteResultSetRequest(char *arg) { + char names[8][32]; + int i; + Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest); Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest; req->referenceId = set_refid (out); - req->num_resultSetList = 1; - req->resultSetList = (char **) - odr_malloc (out, sizeof(*req->resultSetList)); - *req->resultSetList = arg; + req->num_resultSetList = + sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s", + names[0], names[1], names[2], names[3], + names[4], names[5], names[6], names[7]); + req->deleteFunction = (int *) odr_malloc (out, sizeof(*req->deleteFunction)); - *req->deleteFunction = Z_DeleteRequest_list; + if (req->num_resultSetList > 0) + { + *req->deleteFunction = Z_DeleteRequest_list; + req->resultSetList = (char **) + odr_malloc (out, sizeof(*req->resultSetList)* + req->num_resultSetList); + for (i = 0; inum_resultSetList; i++) + req->resultSetList[i] = names[i]; + } + else + { + *req->deleteFunction = Z_DeleteRequest_all; + req->resultSetList = 0; + } send_apdu(apdu); printf("Sent deleteResultSetRequest.\n"); @@ -1156,6 +1212,46 @@ void process_ESResponse(Z_ExtendedServicesResponse *res) } } +#ifdef ASN_COMPILED +static Z_External *create_external_itemRequest() +{ + ILL_ItemRequest *req = ill_get_ItemRequest(out); + Z_External *r = 0; + + if (!ill_ItemRequest (out, &req, 0, 0)) + return 0; + else + { + oident oid; + int itemRequest_size = 0; + char *itemRequest_buf = odr_getbuf (out, &itemRequest_size, 0); + + oid.proto = PROTO_GENERAL; + oid.oclass = CLASS_GENERAL; + oid.value = VAL_ISO_ILL_1; + + r = (Z_External *) odr_malloc (out, sizeof(*r)); + r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid)); + r->indirect_reference = 0; + r->descriptor = 0; + r->which = Z_External_single; + + r->u.single_ASN1_type = (Odr_oct *) + odr_malloc (out, sizeof(*r->u.single_ASN1_type)); + r->u.single_ASN1_type->buf = odr_malloc (out, itemRequest_size); + r->u.single_ASN1_type->len = itemRequest_size; + r->u.single_ASN1_type->size = itemRequest_size; + memcpy (r->u.single_ASN1_type->buf, itemRequest_buf, itemRequest_size); + printf ("len = %d\n", itemRequest_size); + } + return r; +} +#else +static Z_External *create_external_itemRequest() +{ + return 0; +} +#endif static Z_External *CreateItemOrderExternal(int itemno) { Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External)); @@ -1203,7 +1299,8 @@ static Z_External *CreateItemOrderExternal(int itemno) (int *) odr_malloc(out, sizeof(int)); *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno; - r->u.itemOrder->u.esRequest->notToKeep->itemRequest = NULL; + r->u.itemOrder->u.esRequest->notToKeep->itemRequest = + create_external_itemRequest(); return r; } @@ -1321,11 +1418,6 @@ static int cmd_find(char *arg) static int cmd_delete(char *arg) { - if (!*arg) - { - printf("Delete what?\n"); - return 0; - } if (!conn) { printf("Not connected yet\n"); @@ -1423,9 +1515,53 @@ static int send_presentRequest(char *arg) prefsyn.proto = protocol; prefsyn.oclass = CLASS_RECSYN; prefsyn.value = recordsyntax; - req->preferredRecordSyntax = oid_ent_to_oid(&prefsyn, oid); - - if (elementSetNames) + req->preferredRecordSyntax = + odr_oiddup (out, oid_ent_to_oid(&prefsyn, oid)); + + if (schema != VAL_NONE) + { + oident prefschema; + + prefschema.proto = protocol; + prefschema.oclass = CLASS_SCHEMA; + prefschema.value = schema; + + req->recordComposition = &compo; + compo.which = Z_RecordComp_complex; + compo.u.complex = (Z_CompSpec *) + odr_malloc(out, sizeof(*compo.u.complex)); + compo.u.complex->selectAlternativeSyntax = (bool_t *) + odr_malloc(out, sizeof(bool_t)); + *compo.u.complex->selectAlternativeSyntax = 0; + + compo.u.complex->generic = (Z_Specification *) + odr_malloc(out, sizeof(*compo.u.complex->generic)); + compo.u.complex->generic->schema = (Odr_oid *) + odr_oiddup(out, oid_ent_to_oid(&prefschema, oid)); + if (!compo.u.complex->generic->schema) + { + /* OID wasn't a schema! Try record syntax instead. */ + prefschema.oclass = CLASS_RECSYN; + compo.u.complex->generic->schema = (Odr_oid *) + odr_oiddup(out, oid_ent_to_oid(&prefschema, oid)); + } + if (!elementSetNames) + compo.u.complex->generic->elementSpec = 0; + else + { + compo.u.complex->generic->elementSpec = (Z_ElementSpec *) + odr_malloc(out, sizeof(Z_ElementSpec)); + compo.u.complex->generic->elementSpec->which = + Z_ElementSpec_elementSetName; + compo.u.complex->generic->elementSpec->u.elementSetName = + elementSetNames->u.generic; + } + compo.u.complex->num_dbSpecific = 0; + compo.u.complex->dbSpecific = 0; + compo.u.complex->num_recordSyntax = 0; + compo.u.complex->recordSyntax = 0; + } + else if (elementSetNames) { req->recordComposition = &compo; compo.which = Z_RecordComp_simple; @@ -1747,6 +1883,21 @@ void process_sortResponse(Z_SortResponse *res) #endif } +void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res) +{ + printf("Got deleteResultSetResponse status=%d\n", + *res->deleteOperationStatus); + if (res->deleteListStatuses) + { + int i; + for (i = 0; i < res->deleteListStatuses->num; i++) + { + printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id, + *res->deleteListStatuses->elements[i]->status); + } + } +} + int cmd_sort_generic(char *arg, int newset) { if (!conn) @@ -1801,6 +1952,22 @@ int cmd_scan(char *arg) return 2; } +int cmd_schema(char *arg) +{ + if (!arg || !*arg) + { + schema = VAL_NONE; + return 1; + } + schema = oid_getvalbyname (arg); + if (schema == VAL_NONE) + { + printf ("unknown schema\n"); + return 0; + } + return 1; +} + int cmd_format(char *arg) { if (!arg || !*arg) @@ -1824,8 +1991,8 @@ int cmd_elements(char *arg) if (!arg || !*arg) { - printf("Usage: elements \n"); - return 0; + elementSetNames = 0; + return 1; } strcpy(what, arg); esn.which = Z_ElementSetNames_generic; @@ -1856,7 +2023,7 @@ int cmd_querytype (char *arg) { if (!strcmp (arg, "ccl")) queryType = QueryType_CCL; - else if (!strcmp (arg, "prefix")) + else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn")) queryType = QueryType_Prefix; #if CCL2RPN else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn")) @@ -1956,6 +2123,7 @@ static int client(int wait) {"setnames", cmd_setnames, ""}, {"cancel", cmd_cancel, ""}, {"format", cmd_format, ""}, + {"schema", cmd_schema, ""}, {"elements", cmd_elements, ""}, {"close", cmd_close, ""}, {"attributeset", cmd_attributeset, ""}, @@ -2115,9 +2283,8 @@ static int client(int wait) (apdu->u.resourceControlRequest); break; case Z_APDU_deleteResultSetResponse: - printf("Got deleteResultSetResponse status=%d\n", - *apdu->u.deleteResultSetResponse-> - deleteOperationStatus); + process_deleteResultSetResponse(apdu->u. + deleteResultSetResponse); break; default: printf("Received unknown APDU type (%d).\n",