/*
- * Copyright (c) 1995-2000, Index Data
+ * Copyright (c) 1995-2001, Index Data
* See the file LICENSE for details.
*
* $Log: seshigh.c,v $
- * Revision 1.109 2000-10-02 11:07:44 adam
+ * Revision 1.115 2001-03-25 21:55:12 adam
+ * Added odr_intdup. Ztest server returns TaskPackage for ItemUpdate.
+ *
+ * Revision 1.114 2001/02/21 13:46:53 adam
+ * C++ fixes.
+ *
+ * Revision 1.113 2001/01/30 21:34:17 adam
+ * Added step-size for Scan backend interface.
+ *
+ * Revision 1.112 2001/01/29 09:38:22 adam
+ * Fixed bug that made the frontend server crash when no attribute set
+ * was specified for scan.
+ *
+ * Revision 1.111 2000/11/23 10:58:32 adam
+ * SSL comstack support. Separate POSIX thread support library.
+ *
+ * Revision 1.110 2000/10/02 13:05:32 adam
+ * Fixed bug introduced by previous commit.
+ *
+ * Revision 1.109 2000/10/02 11:07:44 adam
* Added peer_name member for bend_init handler. Changed the YAZ
* client so that tcp: can be avoided in target spec.
*
anew->init = 0;
anew->client_chan = channel;
anew->client_link = link;
+ anew->cs_get_mask = 0;
+ anew->cs_put_mask = 0;
+ anew->cs_accept_mask = 0;
if (!(anew->decode = odr_createmem(ODR_DECODE)) ||
!(anew->encode = odr_createmem(ODR_ENCODE)))
return 0;
}
return;
}
- if (event & EVENT_INPUT || event & EVENT_WORK) /* input */
+ if (event & assoc->cs_accept_mask)
+ {
+ yaz_log (LOG_DEBUG, "ir_session (accept)");
+ if (!cs_accept (conn))
+ {
+ yaz_log (LOG_LOG, "accept failed");
+ destroy_association(assoc);
+ iochan_destroy(h);
+ }
+ iochan_clearflag (h, EVENT_OUTPUT|EVENT_OUTPUT);
+ if (conn->io_pending)
+ { /* cs_accept didn't complete */
+ assoc->cs_accept_mask =
+ ((conn->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) |
+ ((conn->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0);
+
+ iochan_setflag (h, assoc->cs_accept_mask);
+ }
+ else
+ { /* cs_accept completed. Prepare for reading (cs_get) */
+ assoc->cs_accept_mask = 0;
+ assoc->cs_get_mask = EVENT_INPUT;
+ iochan_setflag (h, assoc->cs_get_mask);
+ }
+ return;
+ }
+ if ((event & assoc->cs_get_mask) || (event & EVENT_WORK)) /* input */
{
- if (event & EVENT_INPUT)
+ if ((assoc->cs_put_mask & EVENT_INPUT) == 0 && (event & assoc->cs_get_mask))
{
yaz_log(LOG_DEBUG, "ir_session (input)");
- assert(assoc && conn);
/* We aren't speaking to this fellow */
if (assoc->state == ASSOC_DEAD)
{
iochan_destroy(h);
return;
}
+ assoc->cs_get_mask = EVENT_INPUT;
if ((res = cs_get(conn, &assoc->input_buffer,
&assoc->input_buffer_len)) <= 0)
{
return;
}
else if (res == 1) /* incomplete read - wait for more */
+ {
+ if (conn->io_pending & CS_WANT_WRITE)
+ assoc->cs_get_mask |= EVENT_OUTPUT;
+ iochan_setflag(h, assoc->cs_get_mask);
return;
+ }
if (cs_more(conn)) /* more stuff - call us again later, please */
iochan_setevent(h, EVENT_INPUT);
if (!z_APDU(assoc->decode, &req->request, 0, 0))
{
yaz_log(LOG_LOG, "ODR error on incoming PDU: %s [near byte %d] ",
- odr_errmsg(odr_geterror(assoc->decode)),
- odr_offset(assoc->decode));
+ odr_errmsg(odr_geterror(assoc->decode)),
+ odr_offset(assoc->decode));
yaz_log(LOG_LOG, "PDU dump:");
odr_dumpBER(yaz_log_file(), assoc->input_buffer, res);
do_close(assoc, Z_Close_protocolError, "Malformed package");
do_close_req(assoc, Z_Close_systemProblem, msg, req);
}
}
- if (event & EVENT_OUTPUT)
+ if (event & assoc->cs_put_mask)
{
request *req = request_head(&assoc->outgoing);
+ assoc->cs_put_mask = 0;
yaz_log(LOG_DEBUG, "ir_session (output)");
req->state = REQUEST_PENDING;
switch (res = cs_put(conn, req->response, req->len_response))
{
- case -1:
- yaz_log(LOG_LOG, "Connection closed by client");
- cs_close(conn);
- destroy_association(assoc);
- iochan_destroy(h);
- break;
- case 0: /* all sent - release the request structure */
- yaz_log(LOG_DEBUG, "Wrote PDU, %d bytes", req->len_response);
- nmem_destroy(req->request_mem);
- request_deq(&assoc->outgoing);
- request_release(req);
- if (!request_head(&assoc->outgoing))
- iochan_clearflag(h, EVENT_OUTPUT);
- break;
- /* value of 1 -- partial send -- is simply ignored */
+ case -1:
+ yaz_log(LOG_LOG, "Connection closed by client");
+ cs_close(conn);
+ destroy_association(assoc);
+ iochan_destroy(h);
+ break;
+ case 0: /* all sent - release the request structure */
+ yaz_log(LOG_DEBUG, "Wrote PDU, %d bytes", req->len_response);
+ nmem_destroy(req->request_mem);
+ request_deq(&assoc->outgoing);
+ request_release(req);
+ if (!request_head(&assoc->outgoing))
+ { /* restore mask for cs_get operation ... */
+ iochan_clearflag(h, EVENT_OUTPUT|EVENT_INPUT);
+ iochan_setflag(h, assoc->cs_get_mask);
+ }
+ break;
+ default:
+ if (conn->io_pending & CS_WANT_WRITE)
+ assoc->cs_put_mask |= EVENT_OUTPUT;
+ if (conn->io_pending & CS_WANT_READ)
+ assoc->cs_put_mask |= EVENT_INPUT;
+ iochan_setflag(h, assoc->cs_put_mask);
}
}
if (event & EVENT_EXCEPT)
{
- yaz_log(LOG_DEBUG, "ir_session (exception)");
+ yaz_log(LOG_LOG, "ir_session (exception)");
cs_close(conn);
destroy_association(assoc);
iochan_destroy(h);
static int process_response(association *assoc, request *req, Z_APDU *res)
{
odr_setbuf(assoc->encode, req->response, req->size_response, 1);
+
+ if (assoc->print && !z_APDU(assoc->print, &res, 0, 0))
+ {
+ yaz_log(LOG_WARN, "ODR print error: %s",
+ odr_errmsg(odr_geterror(assoc->print)));
+ odr_reset(assoc->print);
+ }
if (!z_APDU(assoc->encode, &res, 0, 0))
{
yaz_log(LOG_WARN, "ODR error when encoding response: %s",
odr_errmsg(odr_geterror(assoc->decode)));
- odr_reset(assoc->encode);
return -1;
}
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 */
- if (assoc->print && !z_APDU(assoc->print, &res, 0, 0))
- {
- yaz_log(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 */
iochan_setflag(assoc->client_chan, EVENT_OUTPUT);
+ assoc->cs_put_mask = EVENT_OUTPUT;
/* Is there more work to be done? give that to the input handler too */
#if 1
if (request_head(&assoc->incoming))
char options[100];
xfree (assoc->init);
- assoc->init = xmalloc (sizeof(*assoc->init));
+ assoc->init = (bend_initrequest *) xmalloc (sizeof(*assoc->init));
yaz_log(LOG_LOG, "Got initRequest");
if (req->implementationId)
assoc->init->bend_fetch = NULL;
assoc->init->peer_name =
- odr_strdup (assoc->decode, cs_addrstr(assoc->client_link));
+ odr_strdup (assoc->encode, cs_addrstr(assoc->client_link));
if (!(binitres = (*cb->bend_init)(assoc->init)))
{
yaz_log(LOG_WARN, "Bad response from backend.");
assoc->preferredMessageSize = *req->preferredMessageSize;
if (assoc->preferredMessageSize > assoc->maximumRecordSize)
assoc->preferredMessageSize = assoc->maximumRecordSize;
+
+#if 0
+ assoc->maximumRecordSize = 3000000;
+ assoc->preferredMessageSize = 3000000;
+#endif
+
resp->preferredMessageSize = &assoc->preferredMessageSize;
resp->maximumRecordSize = &assoc->maximumRecordSize;
* These functions should be merged.
*/
-static void set_addinfo (Z_DefaultDiagFormat *dr, char *addinfo)
+static void set_addinfo (Z_DefaultDiagFormat *dr, char *addinfo, ODR odr)
{
#if ASN_COMPILED
dr->which = Z_DefaultDiagFormat_v2Addinfo;
- dr->u.v2Addinfo = addinfo ? addinfo : "";
+ dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
#else
dr->which = Z_DiagForm_v2AddInfo;
- dr->addinfo = addinfo ? addinfo : "";
+ dr->addinfo = odr_strdup (odr, addinfo ? addinfo : "");
#endif
}
Z_Records *rec = (Z_Records *)
odr_malloc (assoc->encode, sizeof(*rec));
oident bib1;
- int *err = (int *)
- odr_malloc (assoc->encode, sizeof(*err));
+ int *err = odr_intdup(assoc->encode, error);
Z_DiagRec *drec = (Z_DiagRec *)
odr_malloc (assoc->encode, sizeof(*drec));
Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
yaz_log(LOG_DEBUG, "Diagnostic: %d -- %s", error, addinfo ? addinfo :
"NULL");
- *err = error;
rec->which = Z_Records_NSD;
#if ASN_COMPILED
rec->u.nonSurrogateDiagnostic = dr;
dr->diagnosticSetId =
odr_oiddup (assoc->encode, oid_ent_to_oid(&bib1, oid));
dr->condition = err;
- set_addinfo (dr, addinfo);
+ set_addinfo (dr, addinfo, assoc->encode);
return rec;
}
int oid[OID_SIZE];
Z_NamePlusRecord *rec = (Z_NamePlusRecord *)
odr_malloc (assoc->encode, sizeof(*rec));
- int *err = (int *)odr_malloc (assoc->encode, sizeof(*err));
+ int *err = odr_intdup(assoc->encode, error);
oident bib1;
Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (assoc->encode, sizeof(*drec));
Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
bib1.value = VAL_BIB1;
yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo);
- *err = error;
rec->databaseName = dbname;
rec->which = Z_NamePlusRecord_surrogateDiagnostic;
rec->u.surrogateDiagnostic = drec;
dr->diagnosticSetId = odr_oiddup (assoc->encode,
oid_ent_to_oid(&bib1, oid));
dr->condition = err;
- set_addinfo (dr, addinfo);
+ set_addinfo (dr, addinfo, assoc->encode);
return rec;
}
{
int oid[OID_SIZE];
Z_DiagRecs *recs = (Z_DiagRecs *)odr_malloc (assoc->encode, sizeof(*recs));
- int *err = (int *)odr_malloc (assoc->encode, sizeof(*err));
+ int *err = odr_intdup(assoc->encode, error);
oident bib1;
Z_DiagRec **recp = (Z_DiagRec **)odr_malloc (assoc->encode, sizeof(*recp));
Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (assoc->encode, sizeof(*drec));
bib1.oclass = CLASS_DIAGSET;
bib1.value = VAL_BIB1;
- *err = error;
recs->num_diagRecs = 1;
recs->diagRecs = recp;
recp[0] = drec;
#ifdef ASN_COMPILED
rec->which = Z_DefaultDiagFormat_v2Addinfo;
- rec->u.v2Addinfo = addinfo ? addinfo : "";
+ rec->u.v2Addinfo = odr_strdup (assoc->encode, addinfo ? addinfo : "");
#else
rec->which = Z_DiagForm_v2AddInfo;
- rec->addinfo = addinfo ? addinfo : "";
+ rec->addinfo = odr_strdup (assoc->encode, addinfo ? addinfo : "");
#endif
return recs;
}
Z_APDU *apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
Z_SearchResponse *resp = (Z_SearchResponse *)
odr_malloc (assoc->encode, sizeof(*resp));
- int *nulint = (int *)odr_malloc (assoc->encode, sizeof(*nulint));
- bool_t *sr = (bool_t *)odr_malloc (assoc->encode, sizeof(*sr));
- int *next = (int *)odr_malloc (assoc->encode, sizeof(*next));
- int *none = (int *)odr_malloc (assoc->encode, sizeof(*none));
-
- *nulint = 0;
- *sr = 1;
- *next = 0;
- *none = Z_RES_NONE;
+ int *nulint = odr_intdup (assoc->encode, 0);
+ bool_t *sr = odr_intdup(assoc->encode, 1);
+ int *next = odr_intdup(assoc->encode, 0);
+ int *none = odr_intdup(assoc->encode, Z_RES_NONE);
apdu->which = Z_APDU_searchResponse;
apdu->u.searchResponse = resp;
}
else
{
- int *toget = (int *)odr_malloc (assoc->encode, sizeof(*toget));
- int *presst = (int *)odr_malloc (assoc->encode, sizeof(*presst));
+ int *toget = odr_intdup(assoc->encode, 0);
+ int *presst = odr_intdup(assoc->encode, 0);
Z_RecordComposition comp, *compp = 0;
- *toget = 0;
- *presst = 0;
resp->records = 0;
resp->resultCount = &bsrt->hits;
}
apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
resp = (Z_PresentResponse *)odr_malloc (assoc->encode, sizeof(*resp));
- presst = (int *)odr_malloc (assoc->encode, sizeof(*presst));
- next = (int *)odr_malloc (assoc->encode, sizeof(*next));
- num = (int *)odr_malloc (assoc->encode, sizeof(*num));
- *presst = 0;
- *next = 0;
- *num = *req->numberOfRecordsRequested;
+ presst = odr_intdup(assoc->encode, 0);
+ next = odr_intdup(assoc->encode, 0);
+ num = odr_intdup(assoc->encode, *req->numberOfRecordsRequested);
apdu->which = Z_APDU_presentResponse;
apdu->u.presentResponse = resp;
return apdu;
}
-#if 0
-static int bend_default_scan (void *handle, bend_scan_rr *rr)
-{
- bend_scanrequest srq;
- bend_scanresult *srs;
-
- srq.num_bases = rr->num_bases;
- srq.basenames = rr->basenames;
- srq.attributeset = rr->attributeset;
- srq.referenceId = rr->referenceId;
- srq.term = rr->term;
- srq.term_position = rr->term_position;
- srq.num_entries = rr->num_entries;
- srq.stream = rr->stream;
- srq.print = rr->print;
-
- srs = bend_scan(handle, &srq, 0);
-
- rr->term_position = srs->term_position;
- rr->num_entries = srs->num_entries;
- rr->entries = srs->entries;
- rr->status = srs->status;
- rr->errcode = srs->errcode;
- rr->errstring = srs->errstring;
- return 0;
-}
-#endif
-
/*
* Scan was implemented rather in a hurry, and with support for only the basic
* elements of the service in the backend API. Suggestions are welcome.
Z_APDU *apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
Z_ScanResponse *res = (Z_ScanResponse *)
odr_malloc (assoc->encode, sizeof(*res));
- int *scanStatus = (int *)
- odr_malloc (assoc->encode, sizeof(*scanStatus));
- int *numberOfEntriesReturned = (int *)
- odr_malloc (assoc->encode, sizeof(*numberOfEntriesReturned));
+ int *scanStatus = odr_intdup(assoc->encode, Z_Scan_failure);
+ int *numberOfEntriesReturned = odr_intdup(assoc->encode, 0);
Z_ListEntries *ents = (Z_ListEntries *)
odr_malloc (assoc->encode, sizeof(*ents));
Z_DiagRecs *diagrecs_p = NULL;
oident *attset;
yaz_log(LOG_LOG, "Got ScanRequest");
- *scanStatus = Z_Scan_failure;
- *numberOfEntriesReturned = 0;
apdu->which = Z_APDU_scanResponse;
apdu->u.scanResponse = res;
res->referenceId = req->referenceId;
- res->stepSize = 0;
+ res->stepSize = odr_intdup(assoc->encode, 0);
+
+ if (req->stepSize)
+ *res->stepSize = *req->stepSize;
res->scanStatus = scanStatus;
res->numberOfEntriesReturned = numberOfEntriesReturned;
res->positionOfTerm = 0;
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, 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_sort)(assoc->backend, bsrr);
res->referenceId = bsrr->referenceId;
- res->sortStatus = (int *)
- odr_malloc (assoc->encode, sizeof(*res->sortStatus));
- *res->sortStatus = bsrr->sort_status;
+ res->sortStatus = odr_intdup(assoc->encode, bsrr->sort_status);
res->resultSetStatus = 0;
if (bsrr->errcode)
{
if (bdrr->num_setnames > 0)
{
int i;
- bdrr->statuses = odr_malloc(assoc->encode, sizeof(*bdrr->statuses) *
- bdrr->num_setnames);
+ bdrr->statuses = (int*)
+ odr_malloc(assoc->encode, sizeof(*bdrr->statuses) *
+ bdrr->num_setnames);
for (i = 0; i < bdrr->num_setnames; i++)
bdrr->statuses[i] = 0;
}
res->referenceId = req->referenceId;
- res->deleteOperationStatus = (int *)
- odr_malloc (assoc->encode, sizeof(*res->deleteOperationStatus));
- *res->deleteOperationStatus = bdrr->delete_status;
+ res->deleteOperationStatus = odr_intdup(assoc->encode,bdrr->delete_status);
res->deleteListStatuses = 0;
if (bdrr->num_setnames > 0)
{
int i;
- res->deleteListStatuses = odr_malloc(assoc->encode,
- sizeof(*res->deleteListStatuses));
+ res->deleteListStatuses = (Z_ListStatuses *)
+ odr_malloc(assoc->encode, sizeof(*res->deleteListStatuses));
res->deleteListStatuses->num = bdrr->num_setnames;
res->deleteListStatuses->elements =
- odr_malloc (assoc->encode,
+ (Z_ListStatus **)
+ odr_malloc (assoc->encode,
sizeof(*res->deleteListStatuses->elements) *
bdrr->num_setnames);
for (i = 0; i<bdrr->num_setnames; i++)
{
res->deleteListStatuses->elements[i] =
+ (Z_ListStatus *)
odr_malloc (assoc->encode,
sizeof(**res->deleteListStatuses->elements));
res->deleteListStatuses->elements[i]->status = bdrr->statuses+i;
esrequest.errstring = NULL;
esrequest.request = reqb;
esrequest.association = assoc;
+ esrequest.taskPackage = 0;
esrequest.referenceId = req->referenceId;
(*assoc->init->bend_esrequest)(assoc->backend, &esrequest);
resp->diagnostics = diagRecs->diagRecs;
}
/* Do something with the members of bend_extendedservice */
-
+ if (esrequest.taskPackage)
+ resp->taskPackage = z_ext_record (assoc->encode, VAL_EXTENDED,
+ (const char *) esrequest.taskPackage,
+ -1);
yaz_log(LOG_DEBUG,"Send the result apdu");
return apdu;
}