- if (len < 0)
- {
- yaz_log(YLOG_WARN|YLOG_ERRNO, "Error reading from %s",
- client_get_url(cl));
- connection_destroy(co);
- return;
- }
- else if (len == 0)
- {
- yaz_log(YLOG_WARN, "EOF reading from %s", client_get_url(cl));
- connection_destroy(co);
- return;
- }
- else if (len > 1) // We discard input if we have no connection
- {
- co->state = Conn_Open;
-
- if (client_is_our_response(cl))
- {
- Z_APDU *a;
- struct session_database *sdb = client_get_database(cl);
- const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG);
-
- odr_reset(global_parameters.odr_in);
- odr_setbuf(global_parameters.odr_in, co->ibuf, len, 0);
- if (!z_APDU(global_parameters.odr_in, &a, 0, 0))
- {
- client_fatal(cl);
- return;
- }
-
- if (apdulog && *apdulog && *apdulog != '0')
- {
- ODR p = odr_createmem(ODR_PRINT);
- yaz_log(YLOG_LOG, "recv APDU %s", client_get_url(cl));
-
- odr_setprint(p, yaz_log_file());
- z_APDU(p, &a, 0, 0);
- odr_setprint(p, stderr);
- odr_destroy(p);
- }
- switch (a->which)
- {
- case Z_APDU_initResponse:
- client_init_response(cl, a);
- break;
- case Z_APDU_searchResponse:
- client_search_response(cl, a);
- break;
- case Z_APDU_presentResponse:
- client_present_response(cl, a);
- break;
- case Z_APDU_close:
- client_close_response(cl, a);
- break;
- default:
- yaz_log(YLOG_WARN,
- "Unexpected Z39.50 response from %s",
- client_get_url(cl));
- client_fatal(cl);
- return;
- }
- // We aren't expecting staggered output from target
- // if (cs_more(t->link))
- // iochan_setevent(i, EVENT_INPUT);
- }
- else // we throw away response and go to idle mode
- {
- yaz_log(YLOG_DEBUG, "Ignoring result of expired operation");
- client_set_state(cl, Client_Idle);
- }
- }
- /* if len==1 we do nothing but wait for more input */