X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=server%2Fseshigh.c;h=113b2582dc76a73a241f09bafbf4e147230afca4;hb=87ef7657b92bc53bd98e18ef5046ae3698a7fb01;hp=24a835dbb02b401dc71a39f008c1cae6f6578bf7;hpb=f94999cca65bd3464c1c6db8b5046e0a010b0c7f;p=yaz-moved-to-github.git diff --git a/server/seshigh.c b/server/seshigh.c index 24a835d..113b258 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -4,7 +4,41 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: seshigh.c,v $ - * Revision 1.74 1998-03-31 15:13:20 adam + * Revision 1.85 1998-11-17 09:52:59 adam + * Fixed minor bug (introduced by previous commit). + * + * Revision 1.84 1998/11/16 16:02:32 adam + * Added loggin utilies, log_rpn_query and log_scan_term. These used + * to be part of Zebra. + * + * Revision 1.83 1998/11/03 10:09:36 adam + * Fixed bug regarding YC. + * + * Revision 1.82 1998/10/20 14:00:30 quinn + * Fixed Scan + * + * Revision 1.81 1998/10/13 16:12:24 adam + * Added support for Surrogate Diagnostics for Scan Term entries. + * + * Revision 1.80 1998/09/02 12:41:53 adam + * Added decode stream in bend search structures. + * + * Revision 1.79 1998/08/19 16:10:08 adam + * Changed som member names of DeleteResultSetRequest/Response. + * + * 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 * Development towards compiled ASN.1. * * Revision 1.73 1998/03/31 11:07:45 adam @@ -278,6 +312,7 @@ #include #include #include +#include #include #include @@ -296,6 +331,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; @@ -392,12 +429,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)); @@ -420,6 +457,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 @@ -513,7 +555,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) @@ -570,7 +613,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); @@ -579,7 +621,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) @@ -592,6 +633,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; @@ -679,13 +729,13 @@ static int process_response(association *assoc, request *req, Z_APDU *res) req->response = odr_getbuf(assoc->encode, &req->len_response, &req->size_response); odr_setbuf(assoc->encode, 0, 0, 0); /* don'txfree if we abort later */ - odr_reset(assoc->encode); if (assoc->print && !z_APDU(assoc->print, &res, 0)) { logf(LOG_WARN, "ODR print error: %s", odr_errmsg(odr_geterror(assoc->print))); odr_reset(assoc->print); } + odr_reset(assoc->encode); req->state = REQUEST_IDLE; request_enq(&assoc->outgoing, req); /* turn the work over to the ir_session handler */ @@ -732,6 +782,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."); @@ -747,6 +798,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'; @@ -761,7 +814,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"); @@ -787,7 +840,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"); @@ -849,11 +902,15 @@ static void set_addinfo (Z_DefaultDiagFormat *dr, char *addinfo) static Z_Records *diagrec(association *assoc, int error, char *addinfo) { int oid[OID_SIZE]; - Z_Records *rec = (Z_Records *)odr_malloc (assoc->encode, sizeof(*rec)); + Z_Records *rec = (Z_Records *) + odr_malloc (assoc->encode, sizeof(*rec)); oident bib1; - int *err = (int *)odr_malloc (assoc->encode, sizeof(*err)); - Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (assoc->encode, sizeof(*drec)); - Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)odr_malloc (assoc->encode, sizeof(*dr)); + int *err = (int *) + odr_malloc (assoc->encode, sizeof(*err)); + Z_DiagRec *drec = (Z_DiagRec *) + odr_malloc (assoc->encode, sizeof(*drec)); + Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) + odr_malloc (assoc->encode, sizeof(*dr)); bib1.proto = assoc->proto; bib1.oclass = CLASS_DIAGSET; @@ -885,7 +942,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)); @@ -926,7 +983,7 @@ static Z_DiagRecs *diagrecs(association *assoc, int error, char *addinfo) Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (assoc->encode, sizeof(*drec)); Z_DefaultDiagFormat *rec = (Z_DefaultDiagFormat *)odr_malloc (assoc->encode, sizeof(*rec)); - logf(LOG_DEBUG, "DiagRecs: %d -- %s", error, addinfo); + logf(LOG_DEBUG, "DiagRecs: %d -- %s", error, addinfo ? addinfo : ""); bib1.proto = assoc->proto; bib1.oclass = CLASS_DIAGSET; bib1.value = VAL_BIB1; @@ -958,9 +1015,12 @@ static Z_Records *pack_records(association *a, char *setname, int start, { int oid[OID_SIZE]; int recno, total_length = 0, toget = *num, dumped_records = 0; - Z_Records *records = (Z_Records *)odr_malloc (a->encode, sizeof(*records)); - Z_NamePlusRecordList *reclist = (Z_NamePlusRecordList *)odr_malloc (a->encode, sizeof(*reclist)); - Z_NamePlusRecord **list = (Z_NamePlusRecord **)odr_malloc (a->encode, sizeof(*list) * toget); + Z_Records *records = + (Z_Records *) odr_malloc (a->encode, sizeof(*records)); + Z_NamePlusRecordList *reclist = + (Z_NamePlusRecordList *) odr_malloc (a->encode, sizeof(*reclist)); + Z_NamePlusRecord **list = + (Z_NamePlusRecord **) odr_malloc (a->encode, sizeof(*list) * toget); oident recform; records->which = Z_Records_DBOSD; @@ -971,7 +1031,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, *num = 0; *next = 0; - logf(LOG_DEBUG, "Request to pack %d+%d", start, toget); + logf(LOG_LOG, "Request to pack %d+%d", start, toget); logf(LOG_DEBUG, "pms=%d, mrs=%d", a->preferredMessageSize, a->maximumRecordSize); for (recno = start; reclist->num_records < toget; recno++) @@ -980,7 +1040,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 @@ -993,6 +1053,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; @@ -1002,8 +1063,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; @@ -1046,6 +1116,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, @@ -1129,14 +1200,28 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb, int *fd) { Z_SearchRequest *req = reqb->request->u.searchRequest; - bend_search_rr *bsrr = (bend_search_rr *)nmem_malloc (reqb->request_mem, sizeof(*bsrr)); - + bend_search_rr *bsrr = + (bend_search_rr *)nmem_malloc (reqb->request_mem, sizeof(*bsrr)); + logf(LOG_LOG, "Got SearchRequest."); save_referenceId (reqb, req->referenceId); /* store ref id in request */ bsrr->fd = fd; bsrr->request = reqb; bsrr->association = assoc; + + logf (LOG_LOG, "ResultSet '%s'", req->resultSetName); + if (req->databaseNames) + { + int i; + for (i = 0; i < req->num_databaseNames; i++) + logf (LOG_LOG, "Database '%s'", req->databaseNames[i]); + } + switch (req->query->which) + { + case Z_Query_type_1: case Z_Query_type_101: + log_rpn_query (req->query->u.type_1); + } if (assoc->bend_search) { bsrr->setname = req->resultSetName; @@ -1145,10 +1230,12 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb, bsrr->basenames = req->databaseNames; bsrr->query = req->query; bsrr->stream = assoc->encode; + bsrr->decode = assoc->decode; bsrr->errcode = 0; bsrr->hits = 0; bsrr->errstring = NULL; - ((int (*)(void *, bend_search_rr *))(assoc->bend_search))(assoc->backend, bsrr); + ((int (*)(void *, bend_search_rr *))(assoc->bend_search)) + (assoc->backend, bsrr); if (!bsrr->request) return 0; } @@ -1163,6 +1250,7 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb, bsrq.basenames = req->databaseNames; bsrq.query = req->query; bsrq.stream = assoc->encode; + bsrq.decode = assoc->decode; if (!(bsrt = bend_search(assoc->backend, &bsrq, fd))) return 0; bsrr->hits = bsrt->hits; @@ -1391,14 +1479,10 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) res->numberOfEntriesReturned = numberOfEntriesReturned; res->positionOfTerm = 0; res->entries = ents; -#if ASN_COMPILED ents->num_entries = 0; ents->entries = NULL; ents->num_nonsurrogateDiagnostics = 0; ents->nonsurrogateDiagnostics = NULL; -#else - ents->which = Z_ListEntries_entries; -#endif res->attributeSet = 0; res->otherInfo = 0; @@ -1410,10 +1494,12 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) diagrecs_p = diagrecs(assoc, 205, 0); else { - if (req->termListAndStartPoint->term->which == Z_Term_general) - logf(LOG_DEBUG, " term: '%.*s'", - req->termListAndStartPoint->term->u.general->len, - req->termListAndStartPoint->term->u.general->buf); + if (req->databaseNames) + { + int i; + for (i = 0; i < req->num_databaseNames; i++) + logf (LOG_LOG, "Database '%s'", req->databaseNames[i]); + } srq.num_bases = req->num_databaseNames; srq.basenames = req->databaseNames; srq.num_entries = *req->numberOfTermsRequested; @@ -1424,6 +1510,7 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) srq.attributeset = VAL_NONE; else srq.attributeset = attset->value; + log_scan_term (req->termListAndStartPoint, attset->value); srq.term_position = req->preferredPositionInResponse ? *req->preferredPositionInResponse : 1; if (!(srs = bend_scan(assoc->backend, &srq, 0))) @@ -1433,11 +1520,6 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) else { int i; -#ifdef ASN_COMPILED -#else - Z_Entries *list = (Z_Entries *) - odr_malloc (assoc->encode, sizeof(*list)); -#endif Z_Entry **tab = (Z_Entry **) odr_malloc (assoc->encode, sizeof(*tab) * srs->num_entries); @@ -1445,16 +1527,9 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) *scanStatus = Z_Scan_partial_5; else *scanStatus = Z_Scan_success; -#ifdef ASN_COMPILED ents->entries = tab; ents->num_entries = srs->num_entries; res->numberOfEntriesReturned = &ents->num_entries; -#else - ents->u.entries = list; - list->entries = tab; - list->num_entries = srs->num_entries; - res->numberOfEntriesReturned = &list->num_entries; -#endif res->positionOfTerm = &srs->term_position; for (i = 0; i < srs->num_entries; i++) { @@ -1463,35 +1538,46 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) Odr_oct *o; tab[i] = e = (Z_Entry *)odr_malloc(assoc->encode, sizeof(*e)); - e->which = Z_Entry_termInfo; - e->u.termInfo = t = (Z_TermInfo *)odr_malloc(assoc->encode, sizeof(*t)); - t->suggestedAttributes = 0; - t->displayTerm = 0; - t->alternativeTerm = 0; - t->byAttributes = 0; - t->otherTermInfo = 0; - t->globalOccurrences = &srs->entries[i].occurrences; - t->term = (Z_Term *)odr_malloc(assoc->encode, sizeof(*t->term)); - t->term->which = Z_Term_general; - t->term->u.general = o = (Odr_oct *)odr_malloc(assoc->encode, - sizeof(Odr_oct)); - o->buf = (unsigned char *)odr_malloc(assoc->encode, o->len = o->size = - strlen(srs->entries[i].term)); - memcpy(o->buf, srs->entries[i].term, o->len); - logf(LOG_DEBUG, " term #%d: '%s' (%d)", i, - srs->entries[i].term, srs->entries[i].occurrences); + if (srs->entries[i].occurrences >= 0) + { + e->which = Z_Entry_termInfo; + e->u.termInfo = t = (Z_TermInfo *) + odr_malloc(assoc->encode, sizeof(*t)); + t->suggestedAttributes = 0; + t->displayTerm = 0; + t->alternativeTerm = 0; + t->byAttributes = 0; + t->otherTermInfo = 0; + t->globalOccurrences = &srs->entries[i].occurrences; + t->term = (Z_Term *) + odr_malloc(assoc->encode, sizeof(*t->term)); + t->term->which = Z_Term_general; + t->term->u.general = o = + (Odr_oct *)odr_malloc(assoc->encode, sizeof(Odr_oct)); + o->buf = (unsigned char *) + odr_malloc(assoc->encode, o->len = o->size = + strlen(srs->entries[i].term)); + memcpy(o->buf, srs->entries[i].term, o->len); + logf(LOG_DEBUG, " term #%d: '%s' (%d)", i, + srs->entries[i].term, srs->entries[i].occurrences); + } + else + { + Z_DiagRecs *drecs = diagrecs (assoc, + srs->entries[i].errcode, + srs->entries[i].errstring); + assert (drecs->num_diagRecs == 1); + e->which = Z_Entry_surrogateDiagnostic; + assert (drecs->diagRecs[0]); + e->u.surrogateDiagnostic = drecs->diagRecs[0]; + } } } } if (diagrecs_p) { -#ifdef ASN_COMPILED ents->num_nonsurrogateDiagnostics = diagrecs_p->num_diagRecs; ents->nonsurrogateDiagnostics = diagrecs_p->diagRecs; -#else - ents->u.nonSurrogateDiagnostics = diagrecs_p; - ents->which = Z_ListEntries_nonSurrogateDiagnostics; -#endif } return apdu; } @@ -1552,6 +1638,43 @@ 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_resultSetList; + 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->deleteListStatuses = 0; + res->numberNotDeleted = 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; @@ -1574,7 +1697,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) @@ -1654,11 +1778,12 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) esrequest.stream = assoc->encode; esrequest.errcode = 0; esrequest.errstring = NULL; - esrequest.request = reqb; - esrequest.association = assoc; - - (*assoc->bend_esrequest)(assoc->backend, &esrequest, fd); - + esrequest.request = reqb; + esrequest.association = assoc; + + ((int (*)(void *, bend_esrequest_rr *))(*assoc->bend_esrequest))(assoc->backend, + &esrequest); + /* If the response is being delayed, return NULL */ if (esrequest.request == NULL) return(NULL);