-/* $Id: yaz-proxy.cpp,v 1.35 2005-08-15 12:53:08 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.41 2005-11-30 11:38:46 adam Exp $
Copyright (c) 1998-2005, Index Data.
This file is part of the yaz-proxy.
{
yaz_log(YLOG_LOG, "Auth_Msg:result proxy ok buf=%p len=%d",
m_apdu_buf, m_apdu_len);
- odr_setbuf(m_proxy->odr_decode(), m_apdu_buf, m_apdu_len, 0);
- Z_APDU *apdu = 0;
- int r = z_APDU(m_proxy->odr_decode(), &apdu, 0, 0);
- if (r)
- yaz_log(YLOG_LOG, "Auth_Msg::result z_APDU OK");
- else
- yaz_log(YLOG_LOG, "Auth_Msg::result z_APDU failed");
- if (m_proxy->dec_ref())
+ if (m_proxy->dec_ref(false))
yaz_log(YLOG_LOG, "Auth_Msg::proxy deleted meanwhile");
else
{
yaz_log(YLOG_LOG, "Auth_Msg::proxy still alive");
+ odr_setbuf(m_proxy->odr_decode(), m_apdu_buf, m_apdu_len, 0);
+ Z_APDU *apdu = 0;
+ int r = z_APDU(m_proxy->odr_decode(), &apdu, 0, 0);
+ if (r)
+ yaz_log(YLOG_LOG, "Auth_Msg::result z_APDU OK");
+ else
+ yaz_log(YLOG_LOG, "Auth_Msg::result z_APDU failed");
m_proxy->result_authentication(apdu, m_ret);
}
delete this;
Z_APDU *apdu_reject = zget_APDU(odr_encode(), Z_APDU_initResponse);
*apdu_reject->u.initResponse->result = 0;
send_to_client(apdu_reject);
- dec_ref();
+ dec_ref(false);
}
else
handle_incoming_Z_PDU_2(apdu);
m_session_no = 0;
m_bytes_sent = 0;
m_bytes_recv = 0;
- m_bw_hold_PDU = 0;
m_bw_max = 0;
m_pdu_max = 0;
+ m_search_max = 0;
+ m_connect_max = 0;
m_timeout_mode = timeout_normal;
m_timeout_gdu = 0;
m_max_record_retrieve = 0;
low_socket_open();
m_my_thread = 0;
m_ref_count = 1;
+ m_main_ptr_dec = false;
m_peername = 0;
}
m_proxy_negotiation_lang);
// create thread object the first time we get an incoming connection
if (!m_my_thread)
- m_my_thread = new Msg_Thread(m_socket_observable);
+ m_my_thread = new Msg_Thread(m_socket_observable, 1);
new_proxy->m_my_thread = m_my_thread;
return new_proxy;
}
int pre_init = 0;
cfg->get_target_info(proxy_host, url, &m_bw_max,
&m_pdu_max, &m_max_record_retrieve,
+ &m_search_max, &m_connect_max,
&m_target_idletime, &client_idletime,
&parent->m_max_clients,
&m_keepalive_limit_bw,
m_bytes_sent += len;
m_bw_stat.add_bytes(len);
logtime();
+
+ recv_GDU_more(true);
+
return r;
}
m_bytes_sent += len;
m_bw_stat.add_bytes(len);
logtime();
+
+ recv_GDU_more(true);
+
return r;
}
int Yaz_Proxy::send_to_srw_client_error(int srw_error, const char *add)
{
ODR o = odr_encode();
- Z_SRW_PDU *srw_pdu = yaz_srw_get(o, Z_SRW_searchRetrieve_response);
- Z_SRW_searchRetrieveResponse *srw_res = srw_pdu->u.response;
-
- srw_res->num_diagnostics = 1;
- srw_res->diagnostics = (Z_SRW_diagnostic *)
- odr_malloc(o, sizeof(*srw_res->diagnostics));
- yaz_mk_std_diagnostic(o, srw_res->diagnostics, srw_error, add);
- return send_srw_response(srw_pdu);
+ Z_SRW_diagnostic *diagnostic = (Z_SRW_diagnostic *)
+ odr_malloc(o, sizeof(*diagnostic));
+ int num_diagnostic = 1;
+ yaz_mk_std_diagnostic(o, diagnostic, srw_error, add);
+ return send_srw_search_response(diagnostic, num_diagnostic);
}
int Yaz_Proxy::z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
}
+int Yaz_Proxy::send_srw_search_response(Z_SRW_diagnostic *diagnostics,
+ int num_diagnostics)
+{
+ ODR o = odr_encode();
+ Z_SRW_PDU *srw_pdu = yaz_srw_get(o, Z_SRW_searchRetrieve_response);
+ Z_SRW_searchRetrieveResponse *srw_res = srw_pdu->u.response;
+
+ srw_res->num_diagnostics = num_diagnostics;
+ srw_res->diagnostics = diagnostics;
+ return send_srw_response(srw_pdu);
+}
+
int Yaz_Proxy::send_srw_explain_response(Z_SRW_diagnostic *diagnostics,
int num_diagnostics)
{
/* uncomment to force a big reduce */
m_timeout_mode = timeout_reduce;
m_timeout_gdu = gdu;
- // m_bw_hold_PDU = apdu; // save PDU and signal "on hold"
timeout(3); // call us reduce seconds later
return;
#endif
m_timeout_mode = timeout_reduce;
m_timeout_gdu = gdu;
- // m_bw_hold_PDU = apdu; // save PDU and signal "on hold"
timeout(reduce); // call us reduce seconds later
}
else
void Yaz_Proxy::recv_GDU_normal(GDU *gdu)
{
- Z_GDU *apdu = gdu->get();
- gdu->extract_odr_to(odr_decode());
+ Z_GDU *apdu = 0;
+ gdu->move_away_gdu(odr_decode(), &apdu);
delete gdu;
if (apdu->which == Z_GDU_Z3950)
{
ODR_MASK_SET(initResponse->options,
Z_Options_negotiationModel);
- ODR_MASK_SET(m_initRequest_options,
- Z_Options_negotiationModel);
-
+ if (m_initRequest_options)
+ ODR_MASK_SET(m_initRequest_options,
+ Z_Options_negotiationModel);
+
oi->which = Z_OtherInfo_externallyDefinedInfo;
oi->information.externallyDefinedInfo =
yaz_set_response_charneg(
}
int len;
send_GDU(gdu, &len);
+ recv_GDU_more(true);
return 1;
}
const char *pqf_msg;
size_t off;
int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
- yaz_log(YLOG_LOG, "%*s^\n", off+4, "");
+ int ioff = off;
+ yaz_log(YLOG_LOG, "%*s^\n", ioff+4, "");
yaz_log(YLOG_LOG, "Bad PQF: %s (code %d)\n", pqf_msg, code);
send_to_srw_client_error(10, 0);
m_parent->pre_init();
}
-bool Yaz_Proxy::dec_ref()
+bool Yaz_Proxy::dec_ref(bool main_ptr)
{
yaz_log(YLOG_LOG, "%sdec_ref count=%d", m_session_str, m_ref_count);
+
assert(m_ref_count > 0);
+ if (main_ptr)
+ {
+ if (m_main_ptr_dec)
+ return false;
+ m_main_ptr_dec = true;
+ }
+
+ m_http_keepalive = 0;
--m_ref_count;
if (m_ref_count > 0)
if (m_server)
{
m_waiting = 1; // ensure it's released from Proxy in releaseClient
- m_server->dec_ref();
+ m_server->dec_ref(true);
}
else
delete this;
inc_request_no();
yaz_log (YLOG_LOG, "%sConnection closed by client",
get_session_str());
- dec_ref();
+ dec_ref(true);
}
+void Yaz_Proxy::send_response_fail_client(const char *addr)
+{
+ yaz_log(YLOG_LOG, "%ssend_close_response", get_session_str());
+ if (m_http_version)
+ {
+ Z_SRW_diagnostic *diagnostic = 0;
+ int num_diagnostic = 0;
+
+ yaz_add_srw_diagnostic(odr_encode(),
+ &diagnostic, &num_diagnostic,
+ YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, addr);
+ if (m_s2z_search_apdu)
+ send_srw_search_response(diagnostic, num_diagnostic);
+ else
+ send_srw_explain_response(diagnostic, num_diagnostic);
+ }
+}
void Yaz_ProxyClient::failNotify()
{
if (m_server)
m_server->inc_request_no();
yaz_log (YLOG_LOG, "%sConnection closed by target %s",
get_session_str(), get_hostname());
+
+ if (m_server)
+ m_server->send_response_fail_client(get_hostname());
shutdown();
}
int i;
const char *name = 0;
const char *zurl_in_use[MAX_ZURL_PLEX];
- int limit_bw, limit_pdu, limit_req;
+ int limit_bw, limit_pdu, limit_req, limit_search, limit_connect;
int target_idletime, client_idletime;
int max_clients;
int keepalive_limit_bw, keepalive_limit_pdu;
for (i = 0; cfg && cfg->get_target_no(i, &name, zurl_in_use,
&limit_bw, &limit_pdu, &limit_req,
+ &limit_search, &limit_connect,
&target_idletime, &client_idletime,
&max_clients,
&keepalive_limit_bw,
inc_request_no();
m_in_queue.clear();
yaz_log (YLOG_LOG, "%sTimeout (client to proxy)", m_session_str);
- dec_ref();
+ dec_ref(true);
break;
case timeout_reduce:
timeout(m_client_idletime);
yaz_log (YLOG_LOG, "%sTimeout (proxy to target) %s", get_session_str(),
get_hostname());
- m_waiting = 1;
- m_root->pre_init();
- if (m_server && m_init_flag)
- {
- // target timed out in a session that was properly initialized
- // server object stay alive but we mark it as invalid so it
- // gets initialized again
- m_server->markInvalid();
- m_server = 0;
- }
+
+ if (m_server)
+ m_server->send_response_fail_client(get_hostname());
shutdown();
+
+ m_root->pre_init();
}
Yaz_ProxyClient::Yaz_ProxyClient(IPDU_Observable *the_PDU_Observable,