X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=server%2Fseshigh.c;h=90b1a7009e6bb6cf934e02dd507412fec0ed6bf1;hb=9287c96097c00d28310becb14ea3dd7cfb9f2ab0;hp=4cb1d35fcd3eb8115c54731d8bb4a98380fad33f;hpb=b81a371f23d16b616e6f7355ec7345cf8a482511;p=yaz-moved-to-github.git diff --git a/server/seshigh.c b/server/seshigh.c index 4cb1d35..90b1a70 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 1995-2001, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.120 2001-10-05 14:43:22 adam Exp $ + * $Id: seshigh.c,v 1.132 2002-09-25 12:37:07 adam Exp $ */ /* @@ -45,6 +45,9 @@ #include #include #include +#include +#include +#include #include @@ -104,7 +107,11 @@ association *create_association(IOCHAN channel, COMSTACK link) strcpy(filename, control_block->apdufile); if (!(anew->print = odr_createmem(ODR_PRINT))) return 0; - if (*control_block->apdufile != '-') + if (*control_block->apdufile == '@') + { + odr_setprint(anew->print, yaz_log_file()); + } + else if (*control_block->apdufile != '-') { strcpy(filename, control_block->apdufile); if (!control_block->dynamic) @@ -166,6 +173,7 @@ void destroy_association(association *h) request_delq(&h->incoming); request_delq(&h->outgoing); xfree(h); + xmalloc_trav("session closed"); if (control_block && control_block->one_shot) exit (0); } @@ -356,6 +364,8 @@ void ir_session(IOCHAN h, int event) iochan_clearflag(h, EVENT_OUTPUT|EVENT_INPUT); iochan_setflag(h, assoc->cs_get_mask); } + else + assoc->cs_put_mask = EVENT_OUTPUT; break; default: if (conn->io_pending & CS_WANT_WRITE) @@ -572,7 +582,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) Z_APDU *apdu = zget_APDU(assoc->encode, Z_APDU_initResponse); Z_InitResponse *resp = apdu->u.initResponse; bend_initresult *binitres; - char options[100]; + + char options[140]; xfree (assoc->init); assoc->init = (bend_initrequest *) xmalloc (sizeof(*assoc->init)); @@ -590,6 +601,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->auth = req->idAuthentication; assoc->init->referenceId = req->referenceId; assoc->init->implementation_version = 0; + assoc->init->implementation_id = 0; assoc->init->implementation_name = 0; assoc->init->bend_sort = NULL; assoc->init->bend_search = NULL; @@ -599,6 +611,17 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->bend_scan = NULL; assoc->init->bend_segment = NULL; assoc->init->bend_fetch = NULL; + assoc->init->charneg_request = NULL; + assoc->init->charneg_response = NULL; + assoc->init->decode = assoc->decode; + + if (ODR_MASK_GET(req->options, Z_Options_negotiationModel)) + { + Z_CharSetandLanguageNegotiation *negotiation = + yaz_get_charneg_record (req->otherInfo); + if (negotiation->which == Z_CharSetandLanguageNegotiation_proposal) + assoc->init->charneg_request = negotiation; + } assoc->init->peer_name = odr_strdup (assoc->encode, cs_addrstr(assoc->client_link)); @@ -662,13 +685,33 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) if (ODR_MASK_GET(req->options, Z_Options_concurrentOperations)) { ODR_MASK_SET(resp->options, Z_Options_concurrentOperations); - strcat(options, " concurop"); + strcat(options, " concurrop"); } if (ODR_MASK_GET(req->options, Z_Options_sort) && assoc->init->bend_sort) { ODR_MASK_SET(resp->options, Z_Options_sort); strcat(options, " sort"); } + + if (ODR_MASK_GET(req->options, Z_Options_negotiationModel) + && assoc->init->charneg_response) + { + Z_OtherInformation **p; + Z_OtherInformationUnit *p0; + + yaz_oi_APDU(apdu, &p); + + if ((p0=yaz_oi_update(p, assoc->encode, NULL, 0, 0))) { + ODR_MASK_SET(resp->options, Z_Options_negotiationModel); + + p0->which = Z_OtherInfo_externallyDefinedInfo; + p0->information.externallyDefinedInfo = + assoc->init->charneg_response; + } + ODR_MASK_SET(resp->options, Z_Options_negotiationModel); + strcat(options, " negotiation"); + } + if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1)) { ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1); @@ -684,6 +727,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3); assoc->version = 3; } + yaz_log(LOG_LOG, "Negotiated to v%d: %s", assoc->version, options); assoc->maximumRecordSize = *req->maximumRecordSize; if (assoc->maximumRecordSize > control_block->maxrecordsize) @@ -702,6 +746,16 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) resp->implementationName = "GFS/YAZ"; + if (assoc->init->implementation_id) + { + char *nv = (char *) + odr_malloc (assoc->encode, + strlen(assoc->init->implementation_id) + 10 + + strlen(resp->implementationId)); + sprintf (nv, "%s / %s", + resp->implementationId, assoc->init->implementation_id); + resp->implementationId = nv; + } if (assoc->init->implementation_name) { char *nv = (char *) @@ -741,13 +795,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) static void set_addinfo (Z_DefaultDiagFormat *dr, char *addinfo, ODR odr) { -#if ASN_COMPILED dr->which = Z_DefaultDiagFormat_v2Addinfo; dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : ""); -#else - dr->which = Z_DiagForm_v2AddInfo; - dr->addinfo = odr_strdup (odr, addinfo ? addinfo : ""); -#endif } /* @@ -763,16 +812,10 @@ static Z_Records *diagrec(association *assoc, int error, char *addinfo) Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) odr_malloc (assoc->encode, sizeof(*dr)); - yaz_log(LOG_DEBUG, "Diagnostic: %d -- %s", error, addinfo ? addinfo : - "NULL"); + yaz_log(LOG_LOG, "[%d] %s %s%s", error, diagbib1_str(error), + addinfo ? " -- " : "", addinfo ? addinfo : ""); rec->which = Z_Records_NSD; -#if ASN_COMPILED rec->u.nonSurrogateDiagnostic = dr; -#else - rec->u.nonSurrogateDiagnostic = drec; - drec->which = Z_DiagRec_defaultFormat; - drec->u.defaultFormat = dr; -#endif dr->diagnosticSetId = yaz_oidval_to_z3950oid (assoc->encode, CLASS_DIAGSET, VAL_BIB1); dr->condition = err; @@ -831,13 +874,8 @@ static Z_DiagRecs *diagrecs(association *assoc, int error, char *addinfo) yaz_oidval_to_z3950oid (assoc->encode, CLASS_DIAGSET, VAL_BIB1); rec->condition = err; -#ifdef ASN_COMPILED rec->which = Z_DefaultDiagFormat_v2Addinfo; rec->u.v2Addinfo = odr_strdup (assoc->encode, addinfo ? addinfo : ""); -#else - rec->which = Z_DiagForm_v2AddInfo; - rec->addinfo = odr_strdup (assoc->encode, addinfo ? addinfo : ""); -#endif return recs; } @@ -863,7 +901,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, *num = 0; *next = 0; - yaz_log(LOG_LOG, "Request to pack %d+%d", start, toget); + yaz_log(LOG_LOG, "Request to pack %d+%d+%s", start, toget, setname); yaz_log(LOG_DEBUG, "pms=%d, mrs=%d", a->preferredMessageSize, a->maximumRecordSize); for (recno = start; reclist->num_records < toget; recno++) @@ -902,7 +940,15 @@ static Z_Records *pack_records(association *a, char *setname, int start, { if (!freq.surrogate_flag) { + char s[20]; *pres = Z_PRES_FAILURE; + /* for 'present request out of range', + set addinfo to record position if not set */ + if (freq.errcode == 13 && freq.errstring == 0) + { + sprintf (s, "%d", recno); + freq.errstring = s; + } return diagrec(a, freq.errcode, freq.errstring); } reclist->records[reclist->num_records] = @@ -944,7 +990,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, } else /* too big entirely */ { - yaz_log(LOG_DEBUG, "Record > maxrcdsz"); + yaz_log(LOG_LOG, "Record > maxrcdsz this=%d max=%d", this_length, a->maximumRecordSize); reclist->records[reclist->num_records] = surrogatediagrec(a, freq.basename, 17, 0); reclist->num_records++; @@ -1019,32 +1065,11 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb, bsrr->errcode = 0; bsrr->hits = 0; bsrr->errstring = NULL; + bsrr->search_info = NULL; (assoc->init->bend_search)(assoc->backend, bsrr); if (!bsrr->request) return 0; } -#if 0 - else - { - bend_searchrequest bsrq; - bend_searchresult *bsrt; - - bsrq.setname = req->resultSetName; - bsrq.replace_set = *req->replaceIndicator; - bsrq.num_bases = req->num_databaseNames; - bsrq.basenames = req->databaseNames; - bsrq.query = req->query; - bsrq.referenceId = req->referenceId; - bsrq.stream = assoc->encode; - bsrq.decode = assoc->decode; - bsrq.print = assoc->print; - if (!(bsrt = bend_search (assoc->backend, &bsrq, fd))) - return 0; - bsrr->hits = bsrt->hits; - bsrr->errcode = bsrt->errcode; - bsrr->errstring = bsrt->errstring; - } -#endif return response_searchRequest(assoc, reqb, bsrr, fd); } @@ -1096,6 +1121,8 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, int *presst = odr_intdup(assoc->encode, 0); Z_RecordComposition comp, *compp = 0; + yaz_log (LOG_LOG, "resultCount: %d", bsrt->hits); + resp->records = 0; resp->resultCount = &bsrt->hits; @@ -1149,6 +1176,7 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, resp->presentStatus = 0; } } + resp->additionalSearchInfo = bsrt->search_info; return apdu; } @@ -1253,18 +1281,21 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) Z_ListEntries *ents = (Z_ListEntries *) odr_malloc (assoc->encode, sizeof(*ents)); Z_DiagRecs *diagrecs_p = NULL; - oident *attent; oident *attset; + bend_scan_rr *bsrr = (bend_scan_rr *) + odr_malloc (assoc->encode, sizeof(*bsrr)); yaz_log(LOG_LOG, "Got ScanRequest"); apdu->which = Z_APDU_scanResponse; apdu->u.scanResponse = res; res->referenceId = req->referenceId; - res->stepSize = odr_intdup(assoc->encode, 0); + /* if step is absent, set it to 0 */ + res->stepSize = odr_intdup(assoc->encode, 0); if (req->stepSize) *res->stepSize = *req->stepSize; + res->scanStatus = scanStatus; res->numberOfEntriesReturned = numberOfEntriesReturned; res->positionOfTerm = 0; @@ -1276,98 +1307,88 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) res->attributeSet = 0; res->otherInfo = 0; - if (req->attributeSet && (!(attent = oid_getentbyoid(req->attributeSet)) || - attent->oclass != CLASS_ATTSET - || attent->value != VAL_BIB1)) - diagrecs_p = diagrecs(assoc, 121, 0); - else if (req->stepSize && *req->stepSize > 0) - diagrecs_p = diagrecs(assoc, 205, 0); + if (req->databaseNames) + { + int i; + for (i = 0; i < req->num_databaseNames; i++) + yaz_log (LOG_LOG, "Database '%s'", req->databaseNames[i]); + } + bsrr->num_bases = req->num_databaseNames; + bsrr->basenames = req->databaseNames; + bsrr->num_entries = *req->numberOfTermsRequested; + bsrr->term = req->termListAndStartPoint; + bsrr->referenceId = req->referenceId; + bsrr->stream = assoc->encode; + bsrr->print = assoc->print; + bsrr->step_size = res->stepSize; + if (req->attributeSet && + (attset = oid_getentbyoid(req->attributeSet)) && + (attset->oclass == CLASS_ATTSET || attset->oclass == CLASS_GENERAL)) + bsrr->attributeset = attset->value; + else + bsrr->attributeset = VAL_NONE; + log_scan_term (req->termListAndStartPoint, bsrr->attributeset); + bsrr->term_position = req->preferredPositionInResponse ? + *req->preferredPositionInResponse : 1; + ((int (*)(void *, bend_scan_rr *)) + (*assoc->init->bend_scan))(assoc->backend, bsrr); + if (bsrr->errcode) + diagrecs_p = diagrecs(assoc, bsrr->errcode, bsrr->errstring); else { - bend_scan_rr *bsrr = (bend_scan_rr *) - odr_malloc (assoc->encode, sizeof(*bsrr)); - if (req->databaseNames) - { - int i; - for (i = 0; i < req->num_databaseNames; i++) - yaz_log (LOG_LOG, "Database '%s'", req->databaseNames[i]); - } - bsrr->num_bases = req->num_databaseNames; - bsrr->basenames = req->databaseNames; - bsrr->num_entries = *req->numberOfTermsRequested; - bsrr->term = req->termListAndStartPoint; - bsrr->referenceId = req->referenceId; - bsrr->stream = assoc->encode; - bsrr->print = assoc->print; - bsrr->step_size = res->stepSize; - if (!(attset = oid_getentbyoid(req->attributeSet)) || - attset->oclass != CLASS_RECSYN) - bsrr->attributeset = VAL_NONE; - else - bsrr->attributeset = attset->value; - log_scan_term (req->termListAndStartPoint, bsrr->attributeset); - bsrr->term_position = req->preferredPositionInResponse ? - *req->preferredPositionInResponse : 1; - ((int (*)(void *, bend_scan_rr *)) - (*assoc->init->bend_scan))(assoc->backend, bsrr); - if (bsrr->errcode) - diagrecs_p = diagrecs(assoc, bsrr->errcode, bsrr->errstring); - else - { - int i; - Z_Entry **tab = (Z_Entry **) - odr_malloc (assoc->encode, sizeof(*tab) * bsrr->num_entries); - - if (bsrr->status == BEND_SCAN_PARTIAL) - *scanStatus = Z_Scan_partial_5; - else - *scanStatus = Z_Scan_success; - ents->entries = tab; - ents->num_entries = bsrr->num_entries; - res->numberOfEntriesReturned = &ents->num_entries; - res->positionOfTerm = &bsrr->term_position; - for (i = 0; i < bsrr->num_entries; i++) - { - Z_Entry *e; - Z_TermInfo *t; - Odr_oct *o; - - tab[i] = e = (Z_Entry *)odr_malloc(assoc->encode, sizeof(*e)); - if (bsrr->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 = &bsrr->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(bsrr->entries[i].term)); - memcpy(o->buf, bsrr->entries[i].term, o->len); - yaz_log(LOG_DEBUG, " term #%d: '%s' (%d)", i, + int i; + Z_Entry **tab = (Z_Entry **) + odr_malloc (assoc->encode, sizeof(*tab) * bsrr->num_entries); + + if (bsrr->status == BEND_SCAN_PARTIAL) + *scanStatus = Z_Scan_partial_5; + else + *scanStatus = Z_Scan_success; + ents->entries = tab; + ents->num_entries = bsrr->num_entries; + res->numberOfEntriesReturned = &ents->num_entries; + res->positionOfTerm = &bsrr->term_position; + for (i = 0; i < bsrr->num_entries; i++) + { + Z_Entry *e; + Z_TermInfo *t; + Odr_oct *o; + + tab[i] = e = (Z_Entry *)odr_malloc(assoc->encode, sizeof(*e)); + if (bsrr->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 = &bsrr->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(bsrr->entries[i].term)); + memcpy(o->buf, bsrr->entries[i].term, o->len); + yaz_log(LOG_DEBUG, " term #%d: '%s' (%d)", i, bsrr->entries[i].term, bsrr->entries[i].occurrences); - } - else - { - Z_DiagRecs *drecs = diagrecs (assoc, - bsrr->entries[i].errcode, - bsrr->entries[i].errstring); - assert (drecs->num_diagRecs == 1); - e->which = Z_Entry_surrogateDiagnostic; - assert (drecs->diagRecs[0]); - e->u.surrogateDiagnostic = drecs->diagRecs[0]; - } - } - } + } + else + { + Z_DiagRecs *drecs = diagrecs (assoc, + bsrr->entries[i].errcode, + bsrr->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) { @@ -1390,13 +1411,8 @@ static Z_APDU *process_sortRequest(association *assoc, request *reqb, yaz_log(LOG_LOG, "Got SortRequest."); -#ifdef ASN_COMPILED bsrr->num_input_setnames = req->num_inputResultSetNames; bsrr->input_setnames = req->inputResultSetNames; -#else - bsrr->num_input_setnames = req->inputResultSetNames->num_strings; - bsrr->input_setnames = req->inputResultSetNames->strings; -#endif bsrr->referenceId = req->referenceId; bsrr->output_setname = req->sortedResultSetName; bsrr->sort_sequence = req->sortSequence; @@ -1415,18 +1431,12 @@ static Z_APDU *process_sortRequest(association *assoc, request *reqb, if (bsrr->errcode) { Z_DiagRecs *dr = diagrecs (assoc, bsrr->errcode, bsrr->errstring); -#ifdef ASN_COMPILED res->diagnostics = dr->diagRecs; res->num_diagnostics = dr->num_diagRecs; -#else - res->diagnostics = dr; -#endif } else { -#ifdef ASN_COMPILED res->num_diagnostics = 0; -#endif res->diagnostics = 0; } res->otherInfo = 0; @@ -1599,15 +1609,15 @@ void *bend_request_getdata(bend_request r) static Z_APDU *process_segmentRequest (association *assoc, request *reqb) { - bend_segment_rr request; + bend_segment_rr req; - request.segment = reqb->apdu_request->u.segmentRequest; - request.stream = assoc->encode; - request.decode = assoc->decode; - request.print = assoc->print; - request.association = assoc; + req.segment = reqb->apdu_request->u.segmentRequest; + req.stream = assoc->encode; + req.decode = assoc->decode; + req.print = assoc->print; + req.association = assoc; - (*assoc->init->bend_segment)(assoc->backend, &request); + (*assoc->init->bend_segment)(assoc->backend, &req); return 0; }