/*
- * Copyright (c) 1995-2001, Index Data
+ * Copyright (c) 1995-2002, Index Data
* See the file LICENSE for details.
*
- * $Id: seshigh.c,v 1.122 2001-11-22 09:45:03 adam Exp $
+ * $Id: seshigh.c,v 1.132 2002-09-25 12:37:07 adam Exp $
*/
/*
#include <yaz/log.h>
#include <yaz/logrpn.h>
#include <yaz/statserv.h>
+#include <yaz/diagbib1.h>
+#include <yaz/charneg.h>
+#include <yaz/otherinfo.h>
#include <yaz/backend.h>
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)
request_delq(&h->incoming);
request_delq(&h->outgoing);
xfree(h);
+ xmalloc_trav("session closed");
if (control_block && control_block->one_shot)
exit (0);
}
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)
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));
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;
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));
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);
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)
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 *)
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;
rec->u.nonSurrogateDiagnostic = dr;
dr->diagnosticSetId =
{
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] =
}
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++;
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;
resp->presentStatus = 0;
}
}
+ resp->additionalSearchInfo = bsrt->search_info;
return apdu;
}
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;
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)
{
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;
}