+void bend_request_send (bend_association a, bend_request req, Z_APDU *res)
+{
+ process_response (a, req, res);
+}
+
+bend_request bend_request_mk (bend_association a)
+{
+ request *nreq = request_get (&a->outgoing);
+ nreq->request_mem = nmem_create ();
+ return nreq;
+}
+
+Z_ReferenceId *bend_request_getid (ODR odr, bend_request req)
+{
+ Z_ReferenceId *id;
+ if (!req->refid)
+ return 0;
+ id = (Odr_oct *)odr_malloc (odr, sizeof(*odr));
+ id->buf = (unsigned char *)odr_malloc (odr, req->len_refid);
+ id->len = id->size = req->len_refid;
+ memcpy (id->buf, req->refid, req->len_refid);
+ return id;
+}
+
+void bend_request_destroy (bend_request *req)
+{
+ nmem_destroy((*req)->request_mem);
+ request_release(*req);
+ *req = NULL;
+}
+
+int bend_backend_respond (bend_association a, bend_request req)
+{
+ char *msg;
+ int r;
+ r = process_request (a, req, &msg);
+ if (r < 0)
+ logf (LOG_WARN, "%s", msg);
+ return r;
+}
+
+void bend_request_setdata(bend_request r, void *p)
+{
+ r->clientData = p;
+}
+
+void *bend_request_getdata(bend_request r)
+{
+ return r->clientData;
+}
+
+static Z_APDU *process_segmentRequest (association *assoc, request *reqb)
+{
+ bend_segment_rr req;
+
+ 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, &req);
+
+ return 0;
+}
+
+static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd)
+{
+ bend_esrequest_rr esrequest;
+
+ Z_ExtendedServicesRequest *req = reqb->apdu_request->u.extendedServicesRequest;
+ Z_APDU *apdu = zget_APDU(assoc->encode, Z_APDU_extendedServicesResponse);
+
+ Z_ExtendedServicesResponse *resp = apdu->u.extendedServicesResponse;
+
+ yaz_log(LOG_DEBUG,"inside Process esRequest");
+
+ esrequest.esr = reqb->apdu_request->u.extendedServicesRequest;
+ esrequest.stream = assoc->encode;
+ esrequest.decode = assoc->decode;
+ esrequest.print = assoc->print;
+ esrequest.errcode = 0;
+ esrequest.errstring = NULL;
+ esrequest.request = reqb;
+ esrequest.association = assoc;
+ esrequest.taskPackage = 0;
+ esrequest.referenceId = req->referenceId;
+
+ (*assoc->init->bend_esrequest)(assoc->backend, &esrequest);
+
+ /* If the response is being delayed, return NULL */
+ if (esrequest.request == NULL)
+ return(NULL);
+
+ resp->referenceId = req->referenceId;
+
+ if (esrequest.errcode == -1)
+ {
+ /* Backend service indicates request will be processed */
+ yaz_log(LOG_DEBUG,"Request could be processed...Accepted !");
+ *resp->operationStatus = Z_ExtendedServicesResponse_accepted;
+ }
+ else if (esrequest.errcode == 0)
+ {
+ /* Backend service indicates request will be processed */
+ yaz_log(LOG_DEBUG,"Request could be processed...Done !");
+ *resp->operationStatus = Z_ExtendedServicesResponse_done;
+ }
+ else
+ {
+ Z_DiagRecs *diagRecs = diagrecs (assoc, esrequest.errcode,
+ esrequest.errstring);
+
+ /* Backend indicates error, request will not be processed */
+ yaz_log(LOG_DEBUG,"Request could not be processed...failure !");
+ *resp->operationStatus = Z_ExtendedServicesResponse_failure;
+ resp->num_diagnostics = diagRecs->num_diagRecs;
+ 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;