X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fztest.c;h=ce3363e10b281989c37d750c5373bb5dfdfc56ec;hp=bb816bb42eafab2ebd45464fffe5d872c2089115;hb=78786494a1fd16e59db481444e042737cabd5cd1;hpb=7057699040b614f56be178f3672b4a2b95301d5f diff --git a/ztest/ztest.c b/ztest/ztest.c index bb816bb..ce3363e 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -1,140 +1,8 @@ /* - * Copyright (c) 1995-2001, Index Data. + * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * NT Service interface by - * Chas Woodfield, Fretwell Downing Datasystems. - * - * $Log: ztest.c,v $ - * Revision 1.42 2001-04-06 12:26:46 adam - * Optional CCL module. Moved atoi_n to marcdisp.h from yaz-util.h. - * - * Revision 1.41 2001/04/05 13:08:48 adam - * New configure options: --enable-module. - * - * Revision 1.40 2001/03/25 21:55:13 adam - * Added odr_intdup. Ztest server returns TaskPackage for ItemUpdate. - * - * Revision 1.39 2001/03/12 14:40:57 adam - * Minor change of print of item update info. - * - * Revision 1.38 2001/02/21 13:46:54 adam - * C++ fixes. - * - * Revision 1.37 2001/02/20 11:25:32 adam - * Added ill_get_APDU and ill_get_Cancel. - * - * Revision 1.36 2001/01/30 21:34:18 adam - * Added step-size for Scan backend interface. - * - * Revision 1.35 2000/11/23 10:58:33 adam - * SSL comstack support. Separate POSIX thread support library. - * - * Revision 1.34 2000/09/04 08:58:15 adam - * Added prefix yaz_ for most logging utility functions. - * - * Revision 1.33 2000/08/10 08:41:26 adam - * Fixes for ILL. - * - * Revision 1.32 2000/04/05 07:39:55 adam - * Added shared library support (libtool). - * - * Revision 1.31 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * 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 - * DB Update implemented in client (very basic). - * - * Revision 1.21 1998/12/15 12:45:42 adam - * Minor change. - * - * Revision 1.20 1998/12/14 14:48:05 adam - * Fixed memory leak - happened when fetching MARC records. - * - * Revision 1.19 1998/10/20 15:16:22 adam - * Minor change to prevent warning. - * - * Revision 1.18 1998/10/20 15:13:45 adam - * Minor fix regarding output for Item Order. - * - * Revision 1.17 1998/10/18 22:33:35 quinn - * Added diagnostic dump of Item Order Eservice. - * - * Revision 1.16 1998/10/15 08:26:23 adam - * Added type cast to make C++ happy. - * - * Revision 1.15 1998/10/13 20:05:57 adam - * Minor change. - * - * Revision 1.14 1998/10/13 16:12:25 adam - * Added support for Surrogate Diagnostics for Scan Term entries. - * - * Revision 1.13 1998/08/19 16:10:09 adam - * Changed som member names of DeleteResultSetRequest/Response. - * - * Revision 1.12 1998/07/20 12:38:44 adam - * Implemented delete result set service to server API. - * - * Revision 1.11 1998/06/09 13:55:08 adam - * Minor changes. - * - * Revision 1.10 1998/05/27 16:55:54 adam - * Minor changes. - * - * Revision 1.9 1998/03/31 11:07:45 adam - * Furhter work on UNIverse resource report. - * Added Extended Services handling in frontend server. - * - * Revision 1.8 1998/02/11 11:53:36 adam - * Changed code so that it compiles as C++. - * - * Revision 1.7 1998/02/10 11:03:57 adam - * Added support for extended handlers in backend server interface. - * - * Revision 1.6 1998/01/29 13:16:02 adam - * Added dummy sort in test server. - * - * Revision 1.5 1997/11/07 13:31:58 adam - * Added NT Service name part of statserv_options_block. Moved NT - * service utility to server library. - * - * Revision 1.4 1997/09/17 12:10:43 adam - * YAZ version 1.4. - * - * Revision 1.3 1997/09/09 10:10:20 adam - * Another MSV5.0 port. Changed projects to include proper - * library/include paths. - * Server starts server in test-mode when no options are given. - * - * Revision 1.2 1997/09/04 13:50:31 adam - * Bug fix in ztest. - * + * $Id: ztest.c,v 1.77 2006-02-19 18:37:20 adam Exp $ */ /* @@ -144,322 +12,422 @@ #include #include #include +#if HAVE_UNISTD_H +#include +#endif +#include #include -#include - -#if YAZ_MODULE_ill #include -#endif -Z_GenericRecord *read_grs1(FILE *f, ODR o); +static int log_level=0; +static int log_level_set=0; -int ztest_search (void *handle, bend_search_rr *rr); -int ztest_sort (void *handle, bend_sort_rr *rr); -int ztest_present (void *handle, bend_present_rr *rr); -int ztest_esrequest (void *handle, bend_esrequest_rr *rr); -int ztest_delete (void *handle, bend_delete_rr *rr); +Z_GenericRecord *dummy_grs_record (int num, ODR o); +char *dummy_marc_record (int num, ODR odr); +char *dummy_xml_record (int num, ODR odr); -int ztest_search (void *handle, bend_search_rr *rr) -{ - rr->hits = rand() % 22; - return 0; -} +int ztest_search(void *handle, bend_search_rr *rr); +int ztest_sort(void *handle, bend_sort_rr *rr); +int ztest_present(void *handle, bend_present_rr *rr); +int ztest_esrequest(void *handle, bend_esrequest_rr *rr); +int ztest_delete(void *handle, bend_delete_rr *rr); -int ztest_present (void *handle, bend_present_rr *rr) +int ztest_search(void *handle, bend_search_rr *rr) { + if (rr->num_bases != 1) + { + rr->errcode = 23; + return 0; + } +#if NMEM_DEBUG + /* if database is stop, stop this process.. For debugging only. */ + if (!yaz_matchstr (rr->basenames[0], "stop")) + { + nmem_print_list_l(YLOG_LOG); + exit(0); + } +#endif + /* Throw Database unavailable if other than Default or Slow */ + if (!yaz_matchstr (rr->basenames[0], "Default")) + ; /* Default is OK in our test */ + else if(!yaz_matchstr (rr->basenames[0], "Slow")) + { +#if HAVE_UNISTD_H + sleep(3); +#endif + ; + } + else + { + rr->errcode = 109; + rr->errstring = rr->basenames[0]; + return 0; + } + rr->hits = rand() % 24; return 0; } + +/* this huge function handles extended services */ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) { - yaz_log(LOG_LOG, "function: %d", *rr->esr->function); + /* user-defined handle - created in bend_init */ + int *counter = (int*) handle; + + yaz_log(log_level, "ESRequest no %d", *counter); + + (*counter)++; + if (rr->esr->packageName) - yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName); - yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction); + yaz_log(log_level, "packagename: %s", rr->esr->packageName); + yaz_log(log_level, "Waitaction: %d", *rr->esr->waitAction); + + + yaz_log(log_level, "function: %d", *rr->esr->function); if (!rr->esr->taskSpecificParameters) { - yaz_log (LOG_WARN, "No task specific parameters"); + yaz_log (log_level, "No task specific parameters"); } else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder) { - Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder; - yaz_log (LOG_LOG, "Received ItemOrder"); - switch (it->which) - { -#ifdef ASN_COMPILED - case Z_IOItemOrder_esRequest: -#else - case Z_ItemOrder_esRequest: -#endif - { - Z_IORequest *ir = it->u.esRequest; - Z_IOOriginPartToKeep *k = ir->toKeep; - Z_IOOriginPartNotToKeep *n = ir->notToKeep; - - if (k && k->contact) - { - if (k->contact->name) - yaz_log(LOG_LOG, "contact name %s", k->contact->name); - if (k->contact->phone) - yaz_log(LOG_LOG, "contact phone %s", k->contact->phone); - if (k->contact->email) - yaz_log(LOG_LOG, "contact email %s", k->contact->email); - } - if (k->addlBilling) - { - yaz_log(LOG_LOG, "Billing info (not shown)"); - } - - if (n->resultSetItem) - { - yaz_log(LOG_LOG, "resultsetItem"); - yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId); - yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item); - } -#if YAZ_MODULE_ill - if (n->itemRequest) - { - Z_External *r = (Z_External*) n->itemRequest; - ILL_ItemRequest *item_req = 0; - ILL_APDU *ill_apdu = 0; - if (r->direct_reference) - { - oident *ent = oid_getentbyoid(r->direct_reference); - if (ent) - yaz_log(LOG_LOG, "OID %s", ent->desc); + Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder; + yaz_log (log_level, "Received ItemOrder"); + if (it->which == Z_IOItemOrder_esRequest) + { + Z_IORequest *ir = it->u.esRequest; + Z_IOOriginPartToKeep *k = ir->toKeep; + Z_IOOriginPartNotToKeep *n = ir->notToKeep; + + if (k && k->contact) + { + if (k->contact->name) + yaz_log(log_level, "contact name %s", k->contact->name); + if (k->contact->phone) + yaz_log(log_level, "contact phone %s", k->contact->phone); + if (k->contact->email) + yaz_log(log_level, "contact email %s", k->contact->email); + } + if (k->addlBilling) + { + yaz_log(log_level, "Billing info (not shown)"); + } + + if (n->resultSetItem) + { + yaz_log(log_level, "resultsetItem"); + yaz_log(log_level, "setId: %s", n->resultSetItem->resultSetId); + yaz_log(log_level, "item: %d", *n->resultSetItem->item); + } + if (n->itemRequest) + { + Z_External *r = (Z_External*) n->itemRequest; + ILL_ItemRequest *item_req = 0; + ILL_APDU *ill_apdu = 0; + if (r->direct_reference) + { + oident *ent = oid_getentbyoid(r->direct_reference); + if (ent) + yaz_log(log_level, "OID %s", ent->desc); if (ent && ent->value == VAL_TEXT_XML) { - yaz_log (LOG_LOG, "ILL XML request"); + yaz_log (log_level, "ILL XML request"); if (r->which == Z_External_octet) - yaz_log (LOG_LOG, "%.*s", r->u.octet_aligned->len, + yaz_log (log_level, "%.*s", r->u.octet_aligned->len, r->u.octet_aligned->buf); } - if (ent && ent->value == VAL_ISO_ILL_1) - { - yaz_log (LOG_LOG, "Decode ItemRequest begin"); - if (r->which == ODR_EXTERNAL_single) - { - odr_setbuf(rr->decode, - (char *) 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, + if (ent && ent->value == VAL_ISO_ILL_1) + { + yaz_log (log_level, "Decode ItemRequest begin"); + if (r->which == ODR_EXTERNAL_single) + { + odr_setbuf(rr->decode, + (char *) 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_level, "Couldn't decode ItemRequest %s near %d", odr_errmsg(odr_geterror(rr->decode)), odr_offset(rr->decode)); -#if 0 - yaz_log(LOG_LOG, "PDU dump:"); - odr_dumpBER(yaz_log_file(), - r->u.single_ASN1_type->buf, - r->u.single_ASN1_type->len); -#endif } - else - yaz_log(LOG_LOG, "Decode ItemRequest OK"); - if (rr->print) - { - ill_ItemRequest (rr->print, &item_req, 0, + else + yaz_log(log_level, "Decode ItemRequest OK"); + 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, "Decode ILL APDU begin"); - odr_setbuf(rr->decode, - (char*) r->u.single_ASN1_type->buf, - r->u.single_ASN1_type->len, 0); - - if (!ill_APDU (rr->decode, &ill_apdu, 0, 0)) - { - yaz_log (LOG_LOG, + odr_reset (rr->print); + } + } + if (!item_req && r->which == ODR_EXTERNAL_single) + { + yaz_log (log_level, "Decode ILL APDU begin"); + odr_setbuf(rr->decode, + (char*) r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len, 0); + + if (!ill_APDU (rr->decode, &ill_apdu, 0, 0)) + { + yaz_log (log_level, "Couldn't decode ILL APDU %s near %d", odr_errmsg(odr_geterror(rr->decode)), odr_offset(rr->decode)); - yaz_log(LOG_LOG, "PDU dump:"); + yaz_log(log_level, "PDU dump:"); odr_dumpBER(yaz_log_file(), (char *) r->u.single_ASN1_type->buf, r->u.single_ASN1_type->len); } - else - yaz_log(LOG_LOG, "Decode ILL APDU OK"); - if (rr->print) + else + yaz_log(log_level, "Decode ILL APDU OK"); + if (rr->print) { - ill_APDU (rr->print, &ill_apdu, 0, + ill_APDU (rr->print, &ill_apdu, 0, "ILL APDU"); - odr_reset (rr->print); - } - } - } - } - if (item_req) - { - yaz_log (LOG_LOG, "ILL protocol version = %d", - *item_req->protocol_version_num); - } - } -#endif - } - break; - } + odr_reset (rr->print); + } + } + } + } + if (item_req) + { + yaz_log (log_level, "ILL protocol version = %d", + *item_req->protocol_version_num); + } + } + if (k) + { + + Z_External *ext = (Z_External *) + odr_malloc (rr->stream, sizeof(*ext)); + Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *) + odr_malloc (rr->stream, sizeof(*keep)); + Z_IOTargetPart *targetPart = (Z_IOTargetPart *) + odr_malloc (rr->stream, sizeof(*targetPart)); + + rr->taskPackage = (Z_TaskPackage *) + odr_malloc (rr->stream, sizeof(*rr->taskPackage)); + rr->taskPackage->packageType = + odr_oiddup (rr->stream, rr->esr->packageType); + rr->taskPackage->packageName = 0; + rr->taskPackage->userId = 0; + rr->taskPackage->retentionTime = 0; + rr->taskPackage->permissions = 0; + rr->taskPackage->description = 0; + rr->taskPackage->targetReference = (Odr_oct *) + odr_malloc (rr->stream, sizeof(Odr_oct)); + rr->taskPackage->targetReference->buf = + (unsigned char *) odr_strdup (rr->stream, "911"); + rr->taskPackage->targetReference->len = + rr->taskPackage->targetReference->size = + strlen((char *) (rr->taskPackage->targetReference->buf)); + rr->taskPackage->creationDateTime = 0; + rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0); + rr->taskPackage->packageDiagnostics = 0; + rr->taskPackage->taskSpecificParameters = ext; + + ext->direct_reference = + odr_oiddup (rr->stream, rr->esr->packageType); + ext->indirect_reference = 0; + ext->descriptor = 0; + ext->which = Z_External_itemOrder; + ext->u.itemOrder = (Z_ItemOrder *) + odr_malloc (rr->stream, sizeof(*ext->u.update)); + ext->u.itemOrder->which = Z_IOItemOrder_taskPackage; + ext->u.itemOrder->u.taskPackage = (Z_IOTaskPackage *) + odr_malloc (rr->stream, sizeof(Z_IOTaskPackage)); + ext->u.itemOrder->u.taskPackage->originPart = k; + ext->u.itemOrder->u.taskPackage->targetPart = targetPart; + + targetPart->itemRequest = 0; + targetPart->statusOrErrorReport = 0; + targetPart->auxiliaryStatus = 0; + } + } } else if (rr->esr->taskSpecificParameters->which == Z_External_update) { - Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.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; - - yaz_log (LOG_LOG, "action"); - if (toKeep->action) - { - switch (*toKeep->action) - { - case Z_IUOriginPartToKeep_recordInsert: - yaz_log (LOG_LOG, " recordInsert"); - break; - case Z_IUOriginPartToKeep_recordReplace: - yaz_log (LOG_LOG, " recordReplace"); - break; - case Z_IUOriginPartToKeep_recordDelete: - yaz_log (LOG_LOG, " recordDelete"); - break; - case Z_IUOriginPartToKeep_elementUpdate: - yaz_log (LOG_LOG, " elementUpdate"); - break; - case Z_IUOriginPartToKeep_specialUpdate: - yaz_log (LOG_LOG, " specialUpdate"); - break; - default: - yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action); - } - } - 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 (toKeep) - { - Z_External *ext = odr_malloc (rr->stream, sizeof(*ext)); - Z_IUOriginPartToKeep *keep = - odr_malloc (rr->stream, sizeof(*keep)); - Z_IUTargetPart *targetPart = - odr_malloc (rr->stream, sizeof(*targetPart)); - rr->taskPackage = odr_malloc (rr->stream, sizeof(*rr->taskPackage)); - rr->taskPackage->packageType = - odr_oiddup (rr->stream, rr->esr->packageType); - rr->taskPackage->packageName = 0; - rr->taskPackage->userId = 0; - rr->taskPackage->retentionTime = 0; - rr->taskPackage->permissions = 0; - rr->taskPackage->description = 0; - rr->taskPackage->targetReference = (Odr_oct *) - odr_malloc (rr->stream, sizeof(Odr_oct)); - rr->taskPackage->targetReference->buf = - odr_strdup (rr->stream, "123"); - rr->taskPackage->targetReference->len = - rr->taskPackage->targetReference->size = - strlen(rr->taskPackage->targetReference->buf); - rr->taskPackage->creationDateTime = 0; - rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0); - rr->taskPackage->packageDiagnostics = 0; - rr->taskPackage->taskSpecificParameters = ext; - - ext->direct_reference = - odr_oiddup (rr->stream, rr->esr->packageType); - ext->indirect_reference = 0; - ext->descriptor = 0; - ext->which = Z_External_update; - ext->u.update = (Z_IUUpdate *) - odr_malloc (rr->stream, sizeof(*ext->u.update)); - ext->u.update->which = Z_IUUpdate_taskPackage; - ext->u.update->u.taskPackage = (Z_IUUpdateTaskPackage *) - odr_malloc (rr->stream, sizeof(Z_IUUpdateTaskPackage)); - ext->u.update->u.taskPackage->originPart = keep; - ext->u.update->u.taskPackage->targetPart = targetPart; - - keep->action = odr_malloc (rr->stream, sizeof(int)); - *keep->action = *toKeep->action; - keep->databaseName = - odr_strdup (rr->stream, toKeep->databaseName); - keep->schema = 0; - keep->elementSetName = 0; - keep->actionQualifier = 0; - - targetPart->updateStatus = odr_intdup (rr->stream, 1); - targetPart->num_globalDiagnostics = 0; - targetPart->globalDiagnostics = odr_nullval(); - targetPart->num_taskPackageRecords = 0; - targetPart->taskPackageRecords = odr_nullval(); - } - if (notToKeep) - { - int i; - for (i = 0; i < notToKeep->num; i++) - { - Z_External *rec = notToKeep->elements[i]->record; - - if (rec->direct_reference) - { - struct oident *oident; - oident = oid_getentbyoid(rec->direct_reference); - if (oident) - 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) - yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", - rec->u.sutrs->len, - rec->u.sutrs->buf); - else - yaz_log (LOG_LOG, "%d bytes:\n%s", - rec->u.sutrs->len, - rec->u.sutrs->buf); + Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update; + yaz_log (log_level, "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; + + yaz_log (log_level, "action"); + if (toKeep->action) + { + switch (*toKeep->action) + { + case Z_IUOriginPartToKeep_recordInsert: + yaz_log (log_level, " recordInsert"); + break; + case Z_IUOriginPartToKeep_recordReplace: + yaz_log (log_level, " recordReplace"); + break; + case Z_IUOriginPartToKeep_recordDelete: + yaz_log (log_level, " recordDelete"); + break; + case Z_IUOriginPartToKeep_elementUpdate: + yaz_log (log_level, " elementUpdate"); + break; + case Z_IUOriginPartToKeep_specialUpdate: + yaz_log (log_level, " specialUpdate"); + break; + default: + yaz_log (log_level, " unknown (%d)", *toKeep->action); + } + } + if (toKeep->databaseName) + { + yaz_log (log_level, "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 (toKeep) + { + Z_External *ext = (Z_External *) + odr_malloc (rr->stream, sizeof(*ext)); + Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *) + odr_malloc (rr->stream, sizeof(*keep)); + Z_IUTargetPart *targetPart = (Z_IUTargetPart *) + odr_malloc (rr->stream, sizeof(*targetPart)); + + rr->taskPackage = (Z_TaskPackage *) + odr_malloc (rr->stream, sizeof(*rr->taskPackage)); + rr->taskPackage->packageType = + odr_oiddup (rr->stream, rr->esr->packageType); + rr->taskPackage->packageName = 0; + rr->taskPackage->userId = 0; + rr->taskPackage->retentionTime = 0; + rr->taskPackage->permissions = 0; + rr->taskPackage->description = 0; + rr->taskPackage->targetReference = (Odr_oct *) + odr_malloc (rr->stream, sizeof(Odr_oct)); + rr->taskPackage->targetReference->buf = + (unsigned char *) odr_strdup (rr->stream, "123"); + rr->taskPackage->targetReference->len = + rr->taskPackage->targetReference->size = + strlen((char *) (rr->taskPackage->targetReference->buf)); + rr->taskPackage->creationDateTime = 0; + rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0); + rr->taskPackage->packageDiagnostics = 0; + rr->taskPackage->taskSpecificParameters = ext; + + ext->direct_reference = + odr_oiddup (rr->stream, rr->esr->packageType); + ext->indirect_reference = 0; + ext->descriptor = 0; + ext->which = Z_External_update; + ext->u.update = (Z_IUUpdate *) + odr_malloc (rr->stream, sizeof(*ext->u.update)); + ext->u.update->which = Z_IUUpdate_taskPackage; + ext->u.update->u.taskPackage = (Z_IUUpdateTaskPackage *) + odr_malloc (rr->stream, sizeof(Z_IUUpdateTaskPackage)); + ext->u.update->u.taskPackage->originPart = keep; + ext->u.update->u.taskPackage->targetPart = targetPart; + + keep->action = (int *) odr_malloc (rr->stream, sizeof(int)); + *keep->action = *toKeep->action; + keep->databaseName = + odr_strdup (rr->stream, toKeep->databaseName); + keep->schema = 0; + keep->elementSetName = 0; + keep->actionQualifier = 0; + + targetPart->updateStatus = odr_intdup (rr->stream, 1); + targetPart->num_globalDiagnostics = 0; + targetPart->globalDiagnostics = (Z_DiagRec **) odr_nullval(); + targetPart->num_taskPackageRecords = 1; + targetPart->taskPackageRecords = + (Z_IUTaskPackageRecordStructure **) + odr_malloc (rr->stream, + sizeof(Z_IUTaskPackageRecordStructure *)); + targetPart->taskPackageRecords[0] = + (Z_IUTaskPackageRecordStructure *) + odr_malloc (rr->stream, + sizeof(Z_IUTaskPackageRecordStructure)); + + targetPart->taskPackageRecords[0]->which = + Z_IUTaskPackageRecordStructure_record; + targetPart->taskPackageRecords[0]->u.record = + z_ext_record (rr->stream, VAL_SUTRS, "test", 4); + targetPart->taskPackageRecords[0]->correlationInfo = 0; + targetPart->taskPackageRecords[0]->recordStatus = + odr_intdup (rr->stream, + Z_IUTaskPackageRecordStructure_success); + targetPart->taskPackageRecords[0]->num_supplementalDiagnostics + = 0; + + targetPart->taskPackageRecords[0]->supplementalDiagnostics = 0; + } + if (notToKeep) + { + int i; + for (i = 0; i < notToKeep->num; i++) + { + Z_External *rec = notToKeep->elements[i]->record; + + if (rec->direct_reference) + { + struct oident *oident; + oident = oid_getentbyoid(rec->direct_reference); + if (oident) + yaz_log (log_level, "record %d type %s", i, + oident->desc); + } + switch (rec->which) + { + case Z_External_sutrs: + if (rec->u.octet_aligned->len > 170) + yaz_log (log_level, "%d bytes:\n%.168s ...", + rec->u.sutrs->len, + rec->u.sutrs->buf); + else + yaz_log (log_level, "%d bytes:\n%s", + rec->u.sutrs->len, + rec->u.sutrs->buf); break; - case Z_External_octet : - if (rec->u.octet_aligned->len > 170) - yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", - rec->u.octet_aligned->len, - rec->u.octet_aligned->buf); - else - yaz_log (LOG_LOG, "%d bytes\n%s", - rec->u.octet_aligned->len, - rec->u.octet_aligned->buf); - } - } - } - } + case Z_External_octet : + if (rec->u.octet_aligned->len > 170) + yaz_log (log_level, "%d bytes:\n%.168s ...", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); + else + yaz_log (log_level, "%d bytes\n%s", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); + } + } + } + } + } + else if (rr->esr->taskSpecificParameters->which == Z_External_update0) + { + yaz_log(log_level, "Received DB Update (version 0)"); } else { - yaz_log (LOG_WARN, "Unknown Extended Service(%d)", - rr->esr->taskSpecificParameters->which); - + yaz_log (YLOG_WARN, "Unknown Extended Service(%d)", + rr->esr->taskSpecificParameters->which); + } return 0; } +/* result set delete */ int ztest_delete (void *handle, bend_delete_rr *rr) { if (rr->num_setnames == 1 && !strcmp (rr->setnames[0], "1")) - rr->delete_status = Z_DeleteStatus_success; + rr->delete_status = Z_DeleteStatus_success; else rr->delete_status = Z_DeleteStatus_resultSetDidNotExist; return 0; @@ -469,136 +437,98 @@ int ztest_delete (void *handle, bend_delete_rr *rr) int ztest_sort (void *handle, bend_sort_rr *rr) { rr->errcode = 0; - rr->sort_status = Z_SortStatus_success; + rr->sort_status = Z_SortResponse_success; return 0; } -static int atoin (const char *buf, int n) -{ - int val = 0; - while (--n >= 0) - { - if (isdigit(*buf)) - val = val*10 + (*buf - '0'); - buf++; - } - return val; -} -char *marc_read(FILE *inf, ODR odr) -{ - char length_str[5]; - size_t size; - char *buf; - - if (fread (length_str, 1, 5, inf) != 5) - return NULL; - size = atoin (length_str, 5); - if (size <= 6) - return NULL; - if (!(buf = (char*) odr_malloc (odr, size+1))) - return NULL; - if (fread (buf+5, 1, size-5, inf) != (size-5)) - { - xfree (buf); - return NULL; - } - memcpy (buf, length_str, 5); - buf[size] = '\0'; - return buf; -} - -static char *dummy_database_record (int num, ODR odr) -{ - FILE *inf = fopen ("dummy-records", "r"); - char *buf = 0; - - if (!inf) - return NULL; - while (--num >= 0) - { - if (num == 98) - { - buf = (char*) odr_malloc(odr, 2101); - memset(buf, 'A', 2100); - buf[2100] = '\0'; - break; - } - else - buf = marc_read (inf, odr); - if (!num || !buf) - break; - } - fclose(inf); - if (num < 0) - return 0; - return buf; -} - -static Z_GenericRecord *dummy_grs_record (int num, ODR o) +/* present request handler */ +int ztest_present (void *handle, bend_present_rr *rr) { - FILE *f = fopen("dummy-grs", "r"); - char line[512]; - Z_GenericRecord *r = 0; - int n; - - if (!f) - return 0; - while (fgets(line, 512, f)) - if (*line == '#' && sscanf(line, "#%d", &n) == 1 && n == num) - { - r = read_grs1(f, o); - break; - } - fclose(f); - return r; + return 0; } +/* retrieval of a single record (present, and piggy back search) */ int ztest_fetch(void *handle, bend_fetch_rr *r) { char *cp; - r->errstring = 0; + r->last_in_set = 0; - r->basename = "DUMMY"; + r->basename = "Default"; r->output_format = r->request_format; if (r->request_format == VAL_SUTRS) { -#if 0 -/* this section returns a huge record (for testing non-blocking write, etc) */ - r->len = 980000; - r->record = odr_malloc (r->stream, r->len); - memset (r->record, 'x', r->len); -#else -/* this section returns a small record */ - char buf[100]; - - sprintf(buf, "This is dummy SUTRS record number %d\n", r->number); - - r->len = strlen(buf); - r->record = (char *) odr_malloc (r->stream, r->len+1); - strcpy(r->record, buf); -#endif + /* this section returns a small record */ + char buf[100]; + + sprintf(buf, "This is dummy SUTRS record number %d\n", r->number); + + r->len = strlen(buf); + r->record = (char *) odr_malloc (r->stream, r->len+1); + strcpy(r->record, buf); } else if (r->request_format == VAL_GRS1) { - r->len = -1; - r->record = (char*) dummy_grs_record(r->number, r->stream); - if (!r->record) - { - r->errcode = 13; - return 0; - } + r->len = -1; + r->record = (char*) dummy_grs_record(r->number, r->stream); + if (!r->record) + { + r->errcode = 13; + return 0; + } } - else if ((cp = dummy_database_record(r->number, r->stream))) + else if (r->request_format == VAL_POSTSCRIPT) { - r->len = strlen(cp); - r->record = cp; - r->output_format = VAL_USMARC; + char fname[20]; + FILE *f; + long size; + + sprintf (fname, "part.%d.ps", r->number); + f = fopen(fname, "rb"); + if (!f) + { + r->errcode = 13; + return 0; + } + fseek (f, 0L, SEEK_END); + size = ftell (f); + if (size <= 0 || size >= 5000000) + { + r->errcode = 14; + return 0; + } + fseek (f, 0L, SEEK_SET); + r->record = (char*) odr_malloc (r->stream, size); + r->len = size; + r->output_format = VAL_POSTSCRIPT; + fread (r->record, size, 1, f); + fclose (f); + } + else if (r->request_format == VAL_TEXT_XML) + { + if ((cp = dummy_xml_record (r->number, r->stream))) + { + r->len = strlen(cp); + r->record = cp; + r->output_format = VAL_TEXT_XML; + } + else + { + r->errcode = 14; + r->surrogate_flag = 1; + return 0; + } + } + else if ((cp = dummy_marc_record(r->number, r->stream))) + { + r->len = strlen(cp); + r->record = cp; + r->output_format = VAL_USMARC; } else { - r->errcode = 13; - return 0; + r->errcode = 13; + return 0; } r->errcode = 0; return 0; @@ -618,98 +548,147 @@ int ztest_scan(void *handle, bend_scan_rr *q) int term_position_req = q->term_position; int num_entries_req = q->num_entries; + /* Throw Database unavailable if other than Default or Slow */ + if (!yaz_matchstr (q->basenames[0], "Default")) + ; /* Default is OK in our test */ + else if(!yaz_matchstr (q->basenames[0], "Slow")) + { +#if HAVE_UNISTD_H + sleep(3); +#endif + ; + } + else + { + q->errcode = 109; + q->errstring = q->basenames[0]; + return 0; + } + q->errcode = 0; q->errstring = 0; q->entries = list; q->status = BEND_SCAN_SUCCESS; if (!f && !(f = fopen("dummy-words", "r"))) { - perror("dummy-words"); - exit(1); + perror("dummy-words"); + exit(1); } - if (q->term->term->which != Z_Term_general) - { - q->errcode = 229; /* unsupported term type */ - return 0; - } - if (*q->step_size != 0) + if (q->num_entries > 200) { - q->errcode = 205; /*Only zero step size supported for Scan */ - return 0; + q->errcode = 31; + return 0; } - if (q->term->term->u.general->len >= 80) + if (q->term) { - q->errcode = 11; /* term too long */ - return 0; + int len; + if (q->term->term->which != Z_Term_general) + { + q->errcode = 229; /* unsupported term type */ + return 0; + } + if (*q->step_size != 0) + { + q->errcode = 205; /*Only zero step size supported for Scan */ + return 0; + } + len = q->term->term->u.general->len; + if (len >= sizeof(term)) + len = sizeof(term)-1; + memcpy(term, q->term->term->u.general->buf, len); + term[len] = '\0'; } - if (q->num_entries > 200) + else if (q->scanClause) { - q->errcode = 31; - return 0; + strncpy(term, q->scanClause, sizeof(term)-1); + term[sizeof(term)-1] = '\0'; } - memcpy(term, q->term->term->u.general->buf, q->term->term->u.general->len); - term[q->term->term->u.general->len] = '\0'; + else + strcpy(term, "0"); + for (p = term; *p; p++) - if (islower(*p)) - *p = toupper(*p); + if (islower(*(unsigned char *) p)) + *p = toupper(*p); fseek(f, 0, SEEK_SET); q->num_entries = 0; for (i = 0, pos = 0; fscanf(f, " %79[^:]:%d", entries[pos], &hits[pos]) == 2; - i++, pos < 199 ? pos++ : (pos = 0)) + i++, pos < 199 ? pos++ : (pos = 0)) { - if (!q->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */ - { - if ((q->term_position = term_position_req) > i + 1) - { - q->term_position = i + 1; - q->status = BEND_SCAN_PARTIAL; - } - for (; q->num_entries < q->term_position; q->num_entries++) - { - int po; - - po = pos - q->term_position + q->num_entries+1; /* find pos */ - if (po < 0) - po += 200; - - if (!strcmp (term, "SD") && q->num_entries == 2) - { - list[q->num_entries].term = entries[pos]; - list[q->num_entries].occurrences = -1; - list[q->num_entries].errcode = 233; - list[q->num_entries].errstring = "SD for Scan Term"; - } - else - { - list[q->num_entries].term = entries[po]; - list[q->num_entries].occurrences = hits[po]; - } - } - } - else if (q->num_entries) - { - list[q->num_entries].term = entries[pos]; - list[q->num_entries].occurrences = hits[pos]; - q->num_entries++; - } - if (q->num_entries >= num_entries_req) - break; + if (!q->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */ + { + if ((q->term_position = term_position_req) > i + 1) + { + q->term_position = i + 1; + q->status = BEND_SCAN_PARTIAL; + } + for (; q->num_entries < q->term_position; q->num_entries++) + { + int po; + + po = pos - q->term_position + q->num_entries+1; /* find pos */ + if (po < 0) + po += 200; + + if (!strcmp (term, "SD") && q->num_entries == 2) + { + list[q->num_entries].term = entries[pos]; + list[q->num_entries].occurrences = -1; + list[q->num_entries].errcode = 233; + list[q->num_entries].errstring = "SD for Scan Term"; + } + else + { + list[q->num_entries].term = entries[po]; + list[q->num_entries].occurrences = hits[po]; + } + } + } + else if (q->num_entries) + { + list[q->num_entries].term = entries[pos]; + list[q->num_entries].occurrences = hits[pos]; + q->num_entries++; + } + if (q->num_entries >= num_entries_req) + break; } if (feof(f)) - q->status = BEND_SCAN_PARTIAL; + q->status = BEND_SCAN_PARTIAL; + return 0; +} + +int ztest_explain(void *handle, bend_explain_rr *rr) +{ + if (rr->database && !strcmp(rr->database, "Default")) + { + rr->explain_buf = "\n" + "\t\n" + "\t\tlocalhost\n" + "\t\t210\n" + "\t\n" + "\n"; + } return 0; } bend_initresult *bend_init(bend_initrequest *q) { - bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r)); - static char *dummy = "Hej fister"; + bend_initresult *r = (bend_initresult *) + odr_malloc (q->stream, sizeof(*r)); + int *counter = (int *) xmalloc (sizeof(int)); + if (!log_level_set) + { + log_level=yaz_log_module_level("ztest"); + log_level_set=1; + } + + *counter = 0; r->errcode = 0; r->errstring = 0; - r->handle = dummy; + r->handle = counter; /* user handle, in this case a simple int */ q->bend_sort = ztest_sort; /* register sort handler */ q->bend_search = ztest_search; /* register search handler */ q->bend_present = ztest_present; /* register present handle */ @@ -717,11 +696,17 @@ bend_initresult *bend_init(bend_initrequest *q) q->bend_delete = ztest_delete; q->bend_fetch = ztest_fetch; q->bend_scan = ztest_scan; +#if 0 + q->bend_explain = ztest_explain; +#endif + q->bend_srw_scan = ztest_scan; + return r; } void bend_close(void *handle) { + xfree (handle); /* release our user-defined handle */ return; } @@ -729,3 +714,11 @@ int main(int argc, char **argv) { return statserv_main(argc, argv, bend_init, bend_close); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +