X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=server%2Fseshigh.c;h=3233f0518e74a2e4bea818abc1e40450244bd33e;hp=20670236c6f1b221912d6e8f9984f134abfc3282;hb=adfa93d3033913d04c134941f7035f00fd2f080b;hpb=fa0ebb67bb67a5f57b8a198e3e477cd84c064d26 diff --git a/server/seshigh.c b/server/seshigh.c index 2067023..3233f05 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -4,7 +4,16 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: seshigh.c,v $ - * Revision 1.75 1998-05-18 10:13:07 adam + * Revision 1.78 1998-08-03 10:23:55 adam + * Fixed bug regarding Options for Sort. + * + * Revision 1.77 1998/07/20 12:38:42 adam + * Implemented delete result set service to server API. + * + * Revision 1.76 1998/05/27 16:57:07 adam + * Support for surrogate diagnostic records added for bend_fetch. + * + * Revision 1.75 1998/05/18 10:13:07 adam * Fixed call to es_request handler - extra argument was passed. * * Revision 1.74 1998/03/31 15:13:20 adam @@ -299,6 +308,8 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd); static Z_APDU *process_sortRequest(association *assoc, request *reqb, int *fd); static void process_close(association *assoc, request *reqb); void save_referenceId (request *reqb, Z_ReferenceId *refid); +static Z_APDU *process_deleteRequest(association *assoc, request *reqb, + int *fd); static FILE *apduf = 0; /* for use in static mode */ static statserv_options_block *control_block = 0; @@ -395,12 +406,12 @@ void destroy_association(association *h) xfree(h); } -static void do_close(association *a, int reason, char *message) +static void do_close_req(association *a, int reason, char *message, + request *req) { Z_APDU apdu; Z_Close *cls = zget_Close(a->encode); - request *req = request_get(&a->outgoing); - + /* Purge request queue */ while (request_deq(&a->incoming)); while (request_deq(&a->outgoing)); @@ -423,6 +434,11 @@ static void do_close(association *a, int reason, char *message) a->state = ASSOC_DEAD; } +static void do_close(association *a, int reason, char *message) +{ + do_close_req (a, reason, message, request_get(&a->outgoing)); +} + /* * This is where PDUs from the client are read and the further * processing is initiated. Flow of control moves down through the @@ -516,7 +532,8 @@ void ir_session(IOCHAN h, int event) { request_deq(&assoc->incoming); if (process_request(assoc, req) < 0) - do_close(assoc, Z_Close_systemProblem, "Unknown error"); + do_close_req(assoc, Z_Close_systemProblem, "Unknown error", + req); } } if (event & EVENT_OUTPUT) @@ -573,7 +590,6 @@ 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; -/* Chas: Added in from DALI */ case Z_APDU_extendedServicesRequest: if (assoc->bend_esrequest) res = process_ESRequest(assoc, req, &fd); @@ -582,7 +598,6 @@ static int process_request(association *assoc, request *req) 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) @@ -595,6 +610,15 @@ static int process_request(association *assoc, request *req) break; case Z_APDU_close: process_close(assoc, req); return 0; + case Z_APDU_deleteResultSetRequest: + if (assoc->bend_delete) + res = process_deleteRequest(assoc, req, &fd); + else + { + logf (LOG_WARN, "Cannot handle Delete APDU"); + return -1; + } + break; default: logf(LOG_WARN, "Bad APDU received"); return -1; @@ -735,6 +759,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) binitreq.bend_search = NULL; binitreq.bend_present = NULL; binitreq.bend_esrequest = NULL; + binitreq.bend_delete = NULL; if (!(binitres = bend_init(&binitreq))) { logf(LOG_WARN, "Bad response from backend."); @@ -750,6 +775,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) logf (LOG_DEBUG, "Present handler installed"); if ((assoc->bend_esrequest = (int (*)())binitreq.bend_esrequest)) logf (LOG_DEBUG, "ESRequest handler installed"); + if ((assoc->bend_delete = (int (*)())binitreq.bend_delete)) + logf (LOG_DEBUG, "Delete handler installed"); resp->referenceId = req->referenceId; *options = '\0'; @@ -764,7 +791,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) ODR_MASK_SET(resp->options, Z_Options_present); strcat(options, " prst"); } - if (ODR_MASK_GET(req->options, Z_Options_delSet)) + if (ODR_MASK_GET(req->options, Z_Options_delSet) && binitreq.bend_delete) { ODR_MASK_SET(resp->options, Z_Options_delSet); strcat(options, " del"); @@ -790,7 +817,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) ODR_MASK_SET(resp->options, Z_Options_concurrentOperations); strcat(options, " concurop"); } - if (ODR_MASK_GET(req->options, Z_Options_sort && binitreq.bend_sort)) + if (ODR_MASK_GET(req->options, Z_Options_sort) && binitreq.bend_sort) { ODR_MASK_SET(resp->options, Z_Options_sort); strcat(options, " sort"); @@ -888,7 +915,7 @@ static Z_Records *diagrec(association *assoc, int error, char *addinfo) * surrogate diagnostic. */ static Z_NamePlusRecord *surrogatediagrec(association *assoc, char *dbname, - int error, char *addinfo) + int error, char *addinfo) { int oid[OID_SIZE]; Z_NamePlusRecord *rec = (Z_NamePlusRecord *)odr_malloc (assoc->encode, sizeof(*rec)); @@ -983,7 +1010,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, bend_fetchresult *fres; Z_NamePlusRecord *thisrec; Z_DatabaseRecord *thisext; - int this_length; + int this_length = 0; /* * we get the number of bytes allocated on the stream before any @@ -996,6 +1023,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, freq.comp = comp; freq.format = format; freq.stream = a->encode; + freq.surrogate_flag = 0; if (!(fres = bend_fetch(a->backend, &freq, 0))) { *pres = Z_PRES_FAILURE; @@ -1005,8 +1033,17 @@ static Z_Records *pack_records(association *a, char *setname, int start, or only pertaining to current record */ if (fres->errcode) { - *pres = Z_PRES_FAILURE; - return diagrec(a, fres->errcode, fres->errstring); + if (!freq.surrogate_flag) + { + *pres = Z_PRES_FAILURE; + return diagrec(a, fres->errcode, fres->errstring); + } + reclist->records[reclist->num_records] = + surrogatediagrec(a, fres->basename, fres->errcode, + fres->errstring); + reclist->num_records++; + *next = fres->last_in_set ? 0 : recno + 1; + continue; } if (fres->len >= 0) this_length = fres->len; @@ -1049,6 +1086,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, continue; } } + if (!(thisrec = (Z_NamePlusRecord *)odr_malloc(a->encode, sizeof(*thisrec)))) return 0; if (!(thisrec->databaseName = (char *)odr_malloc(a->encode, @@ -1555,6 +1593,45 @@ static Z_APDU *process_sortRequest(association *assoc, request *reqb, return apdu; } +static Z_APDU *process_deleteRequest(association *assoc, request *reqb, + int *fd) +{ + Z_DeleteResultSetRequest *req = reqb->request->u.deleteResultSetRequest; + Z_DeleteResultSetResponse *res = (Z_DeleteResultSetResponse *) + odr_malloc (assoc->encode, sizeof(*res)); + bend_delete_rr *bdrr = (bend_delete_rr *) + odr_malloc (assoc->encode, sizeof(*bdrr)); + Z_APDU *apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu)); + + logf(LOG_LOG, "Got DeleteRequest."); + + bdrr->num_setnames = req->num_ids; + bdrr->setnames = req->resultSetList; + bdrr->stream = assoc->encode; + bdrr->function = *req->deleteFunction; + + ((int (*)(void *, bend_delete_rr *)) + (*assoc->bend_delete))(assoc->backend, bdrr); + + res->referenceId = req->referenceId; + + res->deleteOperationStatus = (int *) + odr_malloc (assoc->encode, sizeof(*res->deleteOperationStatus)); + *res->deleteOperationStatus = bdrr->delete_status; + + res->num_statuses = 0; + res->deleteListStatuses = 0; + res->numberNotDeleted = 0; + res->num_bulkStatuses = 0; + res->bulkStatuses = 0; + res->deleteMessage = 0; + res->otherInfo = 0; + + apdu->which = Z_APDU_deleteResultSetResponse; + apdu->u.deleteResultSetResponse = res; + return apdu; +} + static void process_close(association *assoc, request *reqb) { Z_Close *req = reqb->request->u.close; @@ -1577,7 +1654,8 @@ static void process_close(association *assoc, request *reqb) req->diagnosticInformation : "NULL"); if (assoc->version < 3) /* to make do_force respond with close */ assoc->version = 3; - do_close(assoc, Z_Close_finished, "Association terminated by client"); + do_close_req(assoc, Z_Close_finished, "Association terminated by client", + reqb); } void save_referenceId (request *reqb, Z_ReferenceId *refid)