+/*
+ * Encode response, and transfer the request structure to the outgoing queue.
+ */
+static int process_response(association *assoc, request *req, Z_APDU *res)
+{
+ odr_setbuf(assoc->encode, req->response, req->size_response, 1);
+ if (!z_APDU(assoc->encode, &res, 0))
+ {
+ logf(LOG_WARN, "ODR error when encoding response: %s",
+ odr_errlist[odr_geterror(assoc->decode)]);
+ return -1;
+ }
+ req->response = odr_getbuf(assoc->encode, &req->len_response,
+ &req->size_response);
+ odr_setbuf(assoc->encode, 0, 0, 0); /* don't free 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_errlist[odr_geterror(assoc->print)]);
+ odr_reset(assoc->print);
+ }
+ /* change this when we make the backend reentrant */
+ assert(req == request_head(&assoc->incoming));
+ req->state = REQUEST_IDLE;
+ request_deq(&assoc->incoming);
+ request_enq(&assoc->outgoing, req);
+ /* turn the work over to the ir_session handler */
+ iochan_setflag(assoc->client_chan, EVENT_OUTPUT);
+ /* Is there more work to be done? give that to the input handler too */
+ if (request_head(&assoc->incoming))
+ iochan_setevent(assoc->client_chan, EVENT_WORK);
+ return 0;
+}
+
+/*
+ * Handle init request.
+ * At the moment, we don't check the protocol version or the options
+ * anywhere else in the code - we just don't do anything that would
+ * break a naive client.
+ */
+static Z_APDU *process_initRequest(association *assoc, request *reqb)