X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=ztest%2Fztest.c;h=a2164d77fce0aee74209e1ffc6ca3ae9e3ae63cf;hb=62bcf7a811cd3151ac10f93317c9ddfa6b16f539;hp=0064e695e4e56d7b32f7b42f4ba0099447649c44;hpb=2c185557bb24fa795cee97d813074932e8cc6f78;p=yaz-moved-to-github.git diff --git a/ztest/ztest.c b/ztest/ztest.c index 0064e69..a2164d7 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -1,13 +1,33 @@ /* - * Copyright (c) 1995-1998, Index Data. + * Copyright (c) 1995-2000, Index Data. * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss * * NT Service interface by * Chas Woodfield, Fretwell Downing Datasystems. * * $Log: ztest.c,v $ - * Revision 1.23 1999-05-27 13:02:20 adam + * Revision 1.30 2000-01-13 23:05:50 adam + * Fixed tagging for member requester-CHECKED-IN in ILL ASN.1 spec. + * + * Revision 1.29 2000/01/12 14:36:07 adam + * Added printing stream (ODR) for backend functions. + * + * Revision 1.28 1999/12/16 23:36:19 adam + * Implemented ILL protocol. Minor updates ASN.1 compiler. + * + * Revision 1.27 1999/11/30 13:47:12 adam + * Improved installation. Moved header files to include/yaz. + * + * Revision 1.26 1999/08/27 09:40:32 adam + * Renamed logf function to yaz_log. Removed VC++ project files. + * + * Revision 1.25 1999/06/01 14:29:12 adam + * Work on Extended Services. + * + * Revision 1.24 1999/05/27 13:07:54 adam + * Fix. + * + * Revision 1.23 1999/05/27 13:02:20 adam * Assigned OID for old DB Update (VAL_DBUPDATE0). * * Revision 1.22 1999/05/26 13:49:12 adam @@ -88,9 +108,12 @@ #include #include -#include -#include -#include +#include +#include + +#ifdef ASN_COMPILED +#include +#endif Z_GenericRecord *read_grs1(FILE *f, ODR o); @@ -129,19 +152,19 @@ int ztest_present (void *handle, bend_present_rr *rr) int ztest_esrequest (void *handle, bend_esrequest_rr *rr) { - logf(LOG_LOG, "function: %d", *rr->esr->function); + yaz_log(LOG_LOG, "function: %d", *rr->esr->function); if (rr->esr->packageName) - logf(LOG_LOG, "packagename: %s", rr->esr->packageName); - logf(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction); + yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName); + yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction); if (!rr->esr->taskSpecificParameters) { - logf (LOG_WARN, "No task specific parameters"); + yaz_log (LOG_WARN, "No task specific parameters"); } else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder) { Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder; - logf (LOG_LOG, "Received ItemOrder"); + yaz_log (LOG_LOG, "Received ItemOrder"); switch (it->which) { #ifdef ASN_COMPILED @@ -157,23 +180,95 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) if (k && k->contact) { if (k->contact->name) - logf(LOG_LOG, "contact name %s", k->contact->name); + yaz_log(LOG_LOG, "contact name %s", k->contact->name); if (k->contact->phone) - logf(LOG_LOG, "contact phone %s", k->contact->phone); + yaz_log(LOG_LOG, "contact phone %s", k->contact->phone); if (k->contact->email) - logf(LOG_LOG, "contact email %s", k->contact->email); + yaz_log(LOG_LOG, "contact email %s", k->contact->email); } if (k->addlBilling) { - logf(LOG_LOG, "Billing info (not shown)"); + yaz_log(LOG_LOG, "Billing info (not shown)"); } if (n->resultSetItem) { - logf(LOG_LOG, "resultsetItem"); - logf(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId); - logf(LOG_LOG, "item: %d", *n->resultSetItem->item); + yaz_log(LOG_LOG, "resultsetItem"); + yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId); + yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item); + } +#ifdef ASN_COMPILED + if (n->itemRequest) + { + Z_External *r = (Z_External*) n->itemRequest; + ILL_ItemRequest *item_req = 0; + ILL_Request *ill_req = 0; + if (r->direct_reference) + { + oident *ent = oid_getentbyoid(r->direct_reference); + if (ent) + yaz_log(LOG_LOG, "OID %s", ent->desc); + if (ent && ent->value == VAL_ISO_ILL_1) + { + yaz_log (LOG_LOG, "ItemRequest"); + if (r->which == ODR_EXTERNAL_single) + { + odr_setbuf(rr->decode, + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len, 0); + + if (!ill_ItemRequest (rr->decode, &item_req, 0, 0)) + { + yaz_log (LOG_LOG, + "Couldn't decode ItemRequest %s near %d", + odr_errmsg(odr_geterror(rr->decode)), + odr_offset(rr->decode)); + yaz_log(LOG_LOG, "PDU dump:"); + odr_dumpBER(log_file(), + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len); + } + if (rr->print) + { + ill_ItemRequest (rr->print, &item_req, 0, + "ItemRequest"); + odr_reset (rr->print); + } + } + if (!item_req && r->which == ODR_EXTERNAL_single) + { + yaz_log (LOG_LOG, "ILLRequest"); + odr_setbuf(rr->decode, + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len, 0); + + if (!ill_Request (rr->decode, &ill_req, 0, 0)) + { + yaz_log (LOG_LOG, + "Couldn't decode ILLRequest %s near %d", + odr_errmsg(odr_geterror(rr->decode)), + odr_offset(rr->decode)); + yaz_log(LOG_LOG, "PDU dump:"); + odr_dumpBER(log_file(), + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len); + } + if (rr->print) + { + ill_Request (rr->print, &ill_req, 0, + "ILLRequest"); + odr_reset (rr->print); + } + } + } + } + if (item_req) + { + yaz_log (LOG_LOG, "ILL protocol version = %d", + *item_req->protocol_version_num); + } } +#endif } break; } @@ -181,39 +276,48 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) else if (rr->esr->taskSpecificParameters->which == Z_External_update) { Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update; - logf (LOG_LOG, "Received DB Update"); + yaz_log (LOG_LOG, "Received DB Update"); if (up->which == Z_IUUpdate_esRequest) { Z_IUUpdateEsRequest *esRequest = up->u.esRequest; Z_IUOriginPartToKeep *toKeep = esRequest->toKeep; Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep; - logf (LOG_LOG, "action"); + yaz_log (LOG_LOG, "action"); if (toKeep->action) { switch (*toKeep->action) { case Z_IUOriginPartToKeep_recordInsert: - logf (LOG_LOG, " recordInsert"); + yaz_log (LOG_LOG, " recordInsert"); break; case Z_IUOriginPartToKeep_recordReplace: - logf (LOG_LOG, " recordUpdate"); + yaz_log (LOG_LOG, " recordUpdate"); break; case Z_IUOriginPartToKeep_recordDelete: - logf (LOG_LOG, " recordDelete"); + yaz_log (LOG_LOG, " recordDelete"); break; case Z_IUOriginPartToKeep_elementUpdate: - logf (LOG_LOG, " elementUpdate"); + yaz_log (LOG_LOG, " elementUpdate"); break; case Z_IUOriginPartToKeep_specialUpdate: - logf (LOG_LOG, " specialUpdate"); + yaz_log (LOG_LOG, " specialUpdate"); break; default: - logf (LOG_LOG, " unknown (%d)", *toKeep->action); + yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action); } } - logf (LOG_LOG, "database: %s", - (toKeep->databaseName ? toKeep->databaseName : "")); + if (toKeep->databaseName) + { + yaz_log (LOG_LOG, "database: %s", toKeep->databaseName); + if (!strcmp(toKeep->databaseName, "fault")) + { + rr->errcode = 109; + rr->errstring = toKeep->databaseName; + } + if (!strcmp(toKeep->databaseName, "accept")) + rr->errcode = -1; + } if (notToKeep) { int i; @@ -226,29 +330,30 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) struct oident *oident; oident = oid_getentbyoid(rec->direct_reference); if (oident) - logf (LOG_LOG, "record %d type %s", i, - oident->desc); + yaz_log (LOG_LOG, "record %d type %s", i, + oident->desc); } switch (rec->which) { case Z_External_sutrs: if (rec->u.octet_aligned->len > 170) - logf (LOG_LOG, "%d bytes:\n%.168s ...", - rec->u.sutrs->len, - rec->u.sutrs->buf); + yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", + rec->u.sutrs->len, + rec->u.sutrs->buf); else - logf (LOG_LOG, "%d bytes:\n%s", - rec->u.sutrs->len, - rec->u.sutrs->buf); + yaz_log (LOG_LOG, "%d bytes:\n%s", + rec->u.sutrs->len, + rec->u.sutrs->buf); + break; case Z_External_octet : if (rec->u.octet_aligned->len > 170) - logf (LOG_LOG, "%d bytes:\n%.168s ...", - rec->u.octet_aligned->len, - rec->u.octet_aligned->buf); + yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); else - logf (LOG_LOG, "%d bytes\n%s", - rec->u.octet_aligned->len, - rec->u.octet_aligned->buf); + yaz_log (LOG_LOG, "%d bytes\n%s", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); } } } @@ -256,11 +361,10 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) } else { - logf (LOG_WARN, "Unknown Extended Service(%d)", - rr->esr->taskSpecificParameters->which); + yaz_log (LOG_WARN, "Unknown Extended Service(%d)", + rr->esr->taskSpecificParameters->which); } - rr->errcode = 0; return 0; } @@ -325,7 +429,7 @@ char *marc_read(FILE *inf, ODR odr) static char *dummy_database_record (int num, ODR odr) { FILE *inf = fopen ("dummy-records", "r"); - char *buf; + char *buf = 0; if (!inf) return NULL;