- default: /* data! */
- assoc->input_apdu_len = res;
- if (process_apdu(h) < 0)
- {
- cs_close(conn);
- destroy_association(assoc);
- iochan_destroy(h);
- }
- else if (cs_more(conn)) /* arrange to be called again */
- iochan_setevent(h, EVENT_INPUT);
+ }
+ else if (res == 1) /* incomplete read - wait for more */
+ return;
+ if (cs_more(conn)) /* more stuff - call us again later, please */
+ iochan_setevent(h, EVENT_INPUT);
+
+ /* we got a complete PDU. Let's decode it */
+ logf(LOG_DEBUG, "Got PDU, %d bytes", res);
+ req = request_get(); /* get a new request structure */
+ odr_reset(assoc->decode);
+ odr_setbuf(assoc->decode, assoc->input_buffer, res, 0);
+ if (!z_APDU(assoc->decode, &req->request, 0))
+ {
+ logf(LOG_WARN, "ODR error: %s",
+ odr_errlist[odr_geterror(assoc->decode)]);
+ cs_close(conn);
+ destroy_association(assoc);
+ iochan_destroy(h);
+ return;
+ }
+ req->request_mem = odr_extract_mem(assoc->decode);
+ if (assoc->print && !z_APDU(assoc->print, &req->request, 0))
+ {
+ logf(LOG_WARN, "ODR print error: %s",
+ odr_errlist[odr_geterror(assoc->print)]);
+ odr_reset(assoc->print);
+ }
+ request_enq(&assoc->incoming, req);