From b436ce38e1e619d2225c7c75c1f0de841aa13bad Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 31 Mar 1998 11:07:44 +0000 Subject: [PATCH] Furhter work on UNIverse resource report. Added Extended Services handling in frontend server. --- CHANGELOG | 2 + asn/prt-ext.c | 7 +- client/client.c | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++++- include/backend.h | 20 +++- include/proto.h | 8 +- include/prt-ext.h | 2 +- server/seshigh.c | 85 ++++++++++++++++- server/session.h | 7 +- ztest/ztest.c | 38 +++----- 9 files changed, 394 insertions(+), 38 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3c06e80..8f603e4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ Possible compatibility problems with earlier versions marked with '*'. +Added Extended Services to server (backend.h). Thanks to Charles Woodfield. + Added EXTERNAL: UNIverse Resource Report. Implemened odr_enum and odr_set_of functions to handle ASN.1 types diff --git a/asn/prt-ext.c b/asn/prt-ext.c index 5e83c10..edfead6 100644 --- a/asn/prt-ext.c +++ b/asn/prt-ext.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: prt-ext.c,v $ - * Revision 1.17 1998-03-20 14:46:06 adam + * Revision 1.18 1998-03-31 11:07:44 adam + * Furhter work on UNIverse resource report. + * Added Extended Services handling in frontend server. + * + * Revision 1.17 1998/03/20 14:46:06 adam * Added UNIverse Resource Reports. * * Revision 1.16 1998/02/11 11:53:32 adam @@ -83,6 +87,7 @@ static Z_ext_typeent type_table[] = {VAL_SEARCHRES1, Z_External_searchResult1, (Odr_fun)z_SearchInfoReport}, {VAL_DBUPDATE, Z_External_update, (Odr_fun)z_IUUpdate}, {VAL_DATETIME, Z_External_dateTime, (Odr_fun)z_DateTime}, + {VAL_UNIVERSE_REPORT, Z_External_universeReport, (Odr_fun)z_UniverseReport}, {VAL_NONE, 0, 0} }; diff --git a/client/client.c b/client/client.c index f727e5c..25c719c 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.63 1998-03-05 08:05:10 adam + * Revision 1.64 1998-03-31 11:07:44 adam + * Furhter work on UNIverse resource report. + * Added Extended Services handling in frontend server. + * + * Revision 1.63 1998/03/05 08:05:10 adam * Added a few casts to make C++ happy. * * Revision 1.62 1998/02/11 11:53:33 adam @@ -319,6 +323,7 @@ static void send_initRequest() ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl); ODR_MASK_SET(req->options, Z_Options_scan); ODR_MASK_SET(req->options, Z_Options_sort); + ODR_MASK_SET(req->options, Z_Options_extendedServices); ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2); @@ -796,13 +801,260 @@ static int process_searchResponse(Z_SearchResponse *res) return 0; } +static void print_level(int iLevel) +{ + int i; + for (i = 0; i < iLevel * 4; i++) + printf(" "); +} + +static void print_int(int iLevel, const char *pTag, int *pInt) +{ + if (pInt != NULL) + { + print_level(iLevel); + printf("%s: %d\n", pTag, *pInt); + } +} + +static void print_string(int iLevel, const char *pTag, const char *pString) +{ + if (pString != NULL) + { + print_level(iLevel); + printf("%s: %s\n", pTag, pString); + } +} + +static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid) +{ + if (pOid != NULL) + { + int *pInt = pOid; + + print_level(iLevel); + printf("%s:", pTag); + for (; *pInt != -1; pInt++) + printf(" %d", *pInt); + printf("\n"); + } +} + +static void print_referenceId(int iLevel, Z_ReferenceId *referenceId) +{ + if (referenceId != NULL) + { + int i; + + print_level(iLevel); + printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size); + for (i = 0; i < referenceId->len; i++) + printf("%c", referenceId->buf[i]); + printf("\n"); + } +} + +static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric) +{ + if (pStringNumeric != NULL) + { + switch (pStringNumeric->which) + { + case Z_StringOrNumeric_string: + print_string(iLevel, pTag, pStringNumeric->u.string); + break; + + case Z_StringOrNumeric_numeric: + print_int(iLevel, pTag, pStringNumeric->u.numeric); + break; + + default: + print_level(iLevel); + printf("%s: valid type for Z_StringOrNumeric\n", pTag); + break; + } + } +} + +static void print_universe_report_duplicate(int iLevel, Z_UniverseReportDuplicate *pUniverseReportDuplicate) +{ + if (pUniverseReportDuplicate != NULL) + { + print_level(iLevel); + printf("Universe Report Duplicate: \n"); + iLevel++; + print_string_or_numeric(iLevel, "Hit No", pUniverseReportDuplicate->hitno); + } +} + +static void print_universe_report_hits(int iLevel, Z_UniverseReportHits *pUniverseReportHits) +{ + if (pUniverseReportHits != NULL) + { + print_level(iLevel); + printf("Universe Report Hits: \n"); + iLevel++; + print_string_or_numeric(iLevel, "Database", pUniverseReportHits->database); + print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits); + } +} + +static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport) +{ + if (pUniverseReport != NULL) + { + print_level(iLevel); + printf("Universe Report: \n"); + iLevel++; + print_int(iLevel, "Total Hits", pUniverseReport->totalHits); + switch (pUniverseReport->which) + { + case Z_UniverseReport_databaseHits: + print_universe_report_hits(iLevel, pUniverseReport->u.databaseHits); + break; + + case Z_UniverseReport_duplicate: + print_universe_report_duplicate(iLevel, pUniverseReport->u.duplicate); + break; + + default: + print_level(iLevel); + printf("Type: %d\n", pUniverseReport->which); + break; + } + } +} + +static void print_external(int iLevel, Z_External *pExternal) +{ + if (pExternal != NULL) + { + print_level(iLevel); + printf("External: \n"); + iLevel++; + print_oid(iLevel, "Direct Reference", pExternal->direct_reference); + print_int(iLevel, "InDirect Reference", pExternal->indirect_reference); + print_string(iLevel, "Descriptor", pExternal->descriptor); + switch (pExternal->which) + { + case Z_External_universeReport: + print_universe_report(iLevel, pExternal->u.universeReport); + break; + + default: + print_level(iLevel); + printf("Type: %d\n", pExternal->which); + break; + } + } +} + static int process_resourceControlRequest (Z_ResourceControlRequest *req) { printf ("Received ResourceControlRequest.\n"); - print_refid (req->referenceId); + print_referenceId(1, req->referenceId); + print_int(1, "Suspended Flag", req->suspendedFlag); + print_int(1, "Partial Results Available", req->partialResultsAvailable); + print_int(1, "Response Required", req->responseRequired); + print_int(1, "Triggered Request Flag", req->triggeredRequestFlag); + print_external(1, req->resourceReport); + return 0; +} + +void process_ESResponse(Z_ExtendedServicesResponse *res) +{ + printf("process_ESResponse\n"); +} + +static Z_External *CreateItemOrderExternal(int itemno) +{ + Z_External *r = odr_malloc(out, sizeof(Z_External)); + oident ItemOrderRequest; + + ItemOrderRequest.proto = PROTO_Z3950; + ItemOrderRequest.oclass = CLASS_EXTSERV; + ItemOrderRequest.value = VAL_ITEMORDER; + + r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest)); + r->indirect_reference = odr_malloc(out,sizeof(int)); + *r->indirect_reference = 0; + + r->descriptor = "Extended services item order"; + + r->which = Z_External_itemOrder; + + r->u.itemOrder = odr_malloc(out,sizeof(Z_ItemOrder)); + memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder)); + r->u.itemOrder->which=Z_ItemOrder_esRequest; + + r->u.itemOrder->u.esRequest = odr_malloc(out,sizeof(Z_IORequest)); + memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest)); + + r->u.itemOrder->u.esRequest->toKeep = odr_malloc(out,sizeof(Z_IOOriginPartToKeep)); + memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep)); + r->u.itemOrder->u.esRequest->notToKeep = odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep)); + memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep)); + + r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL; + r->u.itemOrder->u.esRequest->toKeep->contact = NULL; + r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL; + + r->u.itemOrder->u.esRequest->notToKeep->resultSetItem = odr_malloc(out, sizeof(Z_IOResultSetItem)); + memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem)); + r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1"; + + r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = odr_malloc(out, sizeof(int)); + *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno; + + r->u.itemOrder->u.esRequest->notToKeep->itemRequest = NULL; + return r; +} + +/* II : Added to do DALI Item Order Extended services request */ +static int send_itemorder(char *arg) +{ + int itemno = -1; + Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest ); + Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest; + oident ItemOrderRequest; + + if (*arg) + itemno = atoi(arg); + + /* Set up item order request */ + + /* Function being performed by this extended services request */ + req->function = odr_malloc(out, sizeof(int)); + *req->function = Z_ExtendedServicesRequest_create; + + /* Package type, Using protocol ILL ( But that's not in the oid.h file yet */ + /* create an object of class Extended Service, value Item Order */ + ItemOrderRequest.proto = PROTO_Z3950; + ItemOrderRequest.oclass = CLASS_EXTSERV; + ItemOrderRequest.value = VAL_ITEMORDER; + req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest)); + req->packageName = "1.Extendedserveq"; + + /* ** taskSpecificParameters ** */ + req->taskSpecificParameters = CreateItemOrderExternal(itemno); + + /* waitAction - Create the ILL request and that's it */ + *req->waitAction = Z_ExtendedServicesRequest_wait; + + send_apdu(apdu); return 0; } +/* II : Added to do DALI Item Order Extended services request */ +static int cmd_itemorder(char *arg) +{ + printf("Item order request\n"); + fflush(stdout); + + send_itemorder(arg); + return(1); +} + static int cmd_find(char *arg) { if (!*arg) @@ -1430,6 +1682,7 @@ static int client(int wait) {"attributeset", cmd_attributeset, ""}, {"querytype", cmd_querytype, ""}, {"refid", cmd_refid, ""}, + {"itemorder", cmd_itemorder, ""}, {0,0} }; char *netbuffer= 0; @@ -1555,6 +1808,10 @@ static int client(int wait) case Z_APDU_sortResponse: process_sortResponse(apdu->u.sortResponse); break; + case Z_APDU_extendedServicesResponse: + printf("Got extended services response\n"); + process_ESResponse(apdu->u.extendedServicesResponse); + break; case Z_APDU_close: printf("Target has closed the association.\n"); process_close(apdu->u.close); @@ -1612,3 +1869,5 @@ int main(int argc, char **argv) printf (C_PROMPT); return client (opened); } + + diff --git a/include/backend.h b/include/backend.h index e07c216..d4dd0b5 100644 --- a/include/backend.h +++ b/include/backend.h @@ -24,7 +24,11 @@ * OF THIS SOFTWARE. * * $Log: backend.h,v $ - * Revision 1.18 1998-02-10 11:03:56 adam + * Revision 1.19 1998-03-31 11:07:45 adam + * Furhter work on UNIverse resource report. + * Added Extended Services handling in frontend server. + * + * Revision 1.18 1998/02/10 11:03:56 adam * Added support for extended handlers in backend server interface. * * Revision 1.17 1998/01/29 13:15:35 adam @@ -195,6 +199,18 @@ typedef struct bend_sort_rr char *errstring; } bend_sort_rr; +/* extended services handler. Added in from DALI */ +typedef struct bend_esrequest_rr +{ + int ItemNo; + Z_ExtendedServicesRequest *esr; + ODR stream; /* encoding stream */ + bend_request request; + bend_association association; + int errcode; /* 0==success */ + char *errstring; /* system error string or NULL */ +} bend_esrequest_rr; + typedef struct bend_initrequest { char *configname; @@ -204,6 +220,7 @@ typedef struct bend_initrequest int (*bend_sort) (void *handle, bend_sort_rr *rr); int (*bend_search) (void *handle, bend_search_rr *rr); int (*bend_present) (void *handle, bend_present_rr *rr); + int (*bend_esrequest) (void *handle, bend_esrequest_rr *rr); } bend_initrequest; typedef struct bend_initresult @@ -227,6 +244,7 @@ YAZ_EXPORT int bend_backend_respond (bend_association a, bend_request req); YAZ_EXPORT void bend_request_setdata(bend_request r, void *p); YAZ_EXPORT void *bend_request_getdata(bend_request r); + #ifdef __cplusplus } #endif diff --git a/include/proto.h b/include/proto.h index b2e095a..6ed2a1d 100644 --- a/include/proto.h +++ b/include/proto.h @@ -24,7 +24,11 @@ * OF THIS SOFTWARE. * * $Log: proto.h,v $ - * Revision 1.42 1998-03-20 14:46:06 adam + * Revision 1.43 1998-03-31 11:07:45 adam + * Furhter work on UNIverse resource report. + * Added Extended Services handling in frontend server. + * + * Revision 1.42 1998/03/20 14:46:06 adam * Added UNIverse Resource Reports. * * Revision 1.41 1998/02/10 15:31:52 adam @@ -1388,8 +1392,8 @@ YAZ_EXPORT int z_Query(ODR o, Z_Query **p, int opt); #include #include -#include #include #include +#include #endif diff --git a/include/prt-ext.h b/include/prt-ext.h index a21de65..63c38f2 100644 --- a/include/prt-ext.h +++ b/include/prt-ext.h @@ -33,7 +33,6 @@ #define PRT_EXT_H #include -#include #ifdef __cplusplus extern "C" { @@ -100,6 +99,7 @@ struct Z_External Z_SearchInfoReport *searchResult1; Z_IUUpdate *update; Z_DateTime *dateTime; + Z_UniverseReport *universeReport; } u; }; diff --git a/server/seshigh.c b/server/seshigh.c index e69a42d..fd86e0f 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: seshigh.c,v $ - * Revision 1.72 1998-02-11 11:53:35 adam + * Revision 1.73 1998-03-31 11:07:45 adam + * Furhter work on UNIverse resource report. + * Added Extended Services handling in frontend server. + * + * Revision 1.72 1998/02/11 11:53:35 adam * Changed code so that it compiles as C++. * * Revision 1.71 1998/02/10 11:03:57 adam @@ -293,6 +297,10 @@ void save_referenceId (request *reqb, Z_ReferenceId *refid); static FILE *apduf = 0; /* for use in static mode */ static statserv_options_block *control_block = 0; +/* Chas: Added in from DALI */ +static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd); +/* Chas: End of addition from DALI */ + /* * Create and initialize a new association-handle. * channel : iochannel for the current line. @@ -559,7 +567,18 @@ static int process_request(association *assoc, request *req) res = process_presentRequest(assoc, req, &fd); break; case Z_APDU_scanRequest: res = process_scanRequest(assoc, req, &fd); break; - case Z_APDU_sortRequest: +/* Chas: Added in from DALI */ + case Z_APDU_extendedServicesRequest: + if (assoc->bend_esrequest) + res = process_ESRequest(assoc, req, &fd); + else + { + logf(LOG_WARN, "Cannot handle EXTENDED SERVICES APDU"); + return -1; + } +/* Chas: End of addition from DALI */ + break; + case Z_APDU_sortRequest: if (assoc->bend_sort) res = process_sortRequest(assoc, req, &fd); else @@ -709,6 +728,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) binitreq.bend_sort = NULL; binitreq.bend_search = NULL; binitreq.bend_present = NULL; + binitreq.bend_esrequest = NULL; if (!(binitres = bend_init(&binitreq))) { logf(LOG_WARN, "Bad response from backend."); @@ -722,6 +742,9 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) logf (LOG_DEBUG, "Search handler installed"); if ((assoc->bend_present = (int (*)())binitreq.bend_present)) logf (LOG_DEBUG, "Present handler installed"); + if ((assoc->bend_esrequest = (int (*)())binitreq.bend_esrequest)) + logf (LOG_DEBUG, "ESRequest handler installed"); + resp->referenceId = req->referenceId; *options = '\0'; /* let's tell the client what we can do */ @@ -735,13 +758,17 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) ODR_MASK_SET(resp->options, Z_Options_present); strcat(options, " prst"); } -#if 0 if (ODR_MASK_GET(req->options, Z_Options_delSet)) { - ODR_MASK_SET(&options, Z_Options_delSet); + ODR_MASK_SET(resp->options, Z_Options_delSet); strcat(options, " del"); } -#endif + if (ODR_MASK_GET(req->options, Z_Options_extendedServices) && + binitreq.bend_esrequest) + { + ODR_MASK_SET(resp->options, Z_Options_extendedServices); + strcat (options, " extendedServices"); + } if (ODR_MASK_GET(req->options, Z_Options_namedResultSets)) { ODR_MASK_SET(resp->options, Z_Options_namedResultSets); @@ -1536,3 +1563,51 @@ void *bend_request_getdata(bend_request r) { return r->clientData; } + +/* Chas: Added in from DALI */ +static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) +{ + bend_esrequest_rr esrequest; + + Z_ExtendedServicesRequest *req = reqb->request->u.extendedServicesRequest; + Z_APDU *apdu = zget_APDU(assoc->encode, Z_APDU_extendedServicesResponse); + + Z_ExtendedServicesResponse *resp = apdu->u.extendedServicesResponse; + + logf(LOG_DEBUG,"inside Process esRequest"); + + esrequest.esr = reqb->request->u.extendedServicesRequest; + esrequest.stream = assoc->encode; + esrequest.errcode = 0; + esrequest.errstring = NULL; + esrequest.request = reqb; + esrequest.association = assoc; + + (*assoc->bend_esrequest)(assoc->backend, &esrequest, fd); + + /* If the response is being delayed, return NULL */ + if (esrequest.request == NULL) + return(NULL); + + resp->referenceId = req->referenceId; + + if ( esrequest.errcode == 0 ) + { + /* Backend service indicates request will be processed */ + logf(LOG_DEBUG,"Request will be processed...Good !"); + *resp->operationStatus = Z_ExtendedServicesResponse_done; + } + else + { + /* Backend indicates error, request will not be processed */ + logf(LOG_DEBUG,"Request will not be processed...BAD !"); + *resp->operationStatus = Z_ExtendedServicesResponse_failure; + } + /* Do something with the members of bend_extendedservice */ + + logf(LOG_DEBUG,"Send the result apdu"); + + return apdu; +} + +/* Chas: End of addition from DALI */ diff --git a/server/session.h b/server/session.h index f0f96eb..251b89e 100644 --- a/server/session.h +++ b/server/session.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: session.h,v $ - * Revision 1.15 1998-02-11 11:53:36 adam + * Revision 1.16 1998-03-31 11:07:45 adam + * Furhter work on UNIverse resource report. + * Added Extended Services handling in frontend server. + * + * Revision 1.15 1998/02/11 11:53:36 adam * Changed code so that it compiles as C++. * * Revision 1.14 1998/02/10 11:03:57 adam @@ -133,6 +137,7 @@ typedef struct association int (*bend_sort) (); int (*bend_search) (); int (*bend_present) (); + int (*bend_esrequest) (); } association; association *create_association(IOCHAN channel, COMSTACK link); diff --git a/ztest/ztest.c b/ztest/ztest.c index c637b9e..8a16997 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -7,7 +7,11 @@ * Chas Woodfield, Fretwell Downing Datasystems. * * $Log: ztest.c,v $ - * Revision 1.8 1998-02-11 11:53:36 adam + * 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 @@ -52,6 +56,7 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o); 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); bend_initresult *bend_init(bend_initrequest *q) { @@ -64,6 +69,7 @@ bend_initresult *bend_init(bend_initrequest *q) q->bend_sort = ztest_sort; /* register sort handler */ q->bend_search = ztest_search; /* register search handler */ q->bend_present = ztest_present; /* register present handle */ + q->bend_esrequest = ztest_esrequest; return r; } @@ -78,6 +84,12 @@ int ztest_present (void *handle, bend_present_rr *rr) return 0; } +int ztest_esrequest (void *handle, bend_esrequest_rr *rr) +{ + rr->errcode = 0; + return 0; +} + /* Obsolete bend_search, never called because handler is registered */ bend_searchresult *bend_search(void *handle, bend_searchrequest *q, int *fd) { @@ -226,28 +238,6 @@ bend_deleteresult *bend_delete(void *handle, bend_deleterequest *q, int *num) return 0; } -#if 0 -bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) -{ - static struct scan_entry list[200]; - static char buf[200][200]; - static bend_scanresult r; - int i; - - r.term_position = q->term_position; - r.num_entries = q->num_entries; - r.entries = list; - for (i = 0; i < r.num_entries; i++) - { - list[i].term = buf[i]; - sprintf(list[i].term, "term-%d", i+1); - list[i].occurrences = rand() % 100000; - } - r.errcode = 0; - r.errstring = 0; - return &r; -} -#else /* * silly dummy-scan what reads words from a file. */ @@ -328,8 +318,6 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) return r; } -#endif - void bend_close(void *handle) { return; -- 1.7.10.4