-/* $Id: yaz-proxy.cpp,v 1.47 2006-03-30 14:16:34 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.49 2006-04-06 01:16:55 adam Exp $
Copyright (c) 1998-2006, Index Data.
This file is part of the yazproxy.
#define strncasecmp _strnicmp
#endif
-#undef USE_AUTH_MSG
-#define USE_AUTH_MSG 0
+#define USE_AUTH_MSG 1
#if USE_AUTH_MSG
-#error x
class YAZ_EXPORT Auth_Msg : public IMsg_Thread {
public:
int m_ret;
ISocketObservable *the_socket_observable,
Yaz_Proxy *parent)
:
- Z_Assoc(the_PDU_Observable), m_bw_stat(60), m_pdu_stat(60)
+ Z_Assoc(the_PDU_Observable),
+ m_bw_stat(60), m_pdu_stat(60), m_search_stat(60)
{
m_PDU_Observable = the_PDU_Observable;
m_socket_observable = the_socket_observable;
m_pdu_max = 0;
m_search_max = 0;
m_connect_max = 0;
+ m_limit_connect = 0;
m_timeout_mode = timeout_normal;
m_timeout_gdu = 0;
m_max_record_retrieve = 0;
m_ref_count = 1;
m_main_ptr_dec = false;
m_peername = 0;
+ m_initial_reduce = 0;
}
void Yaz_Proxy::inc_ref()
int r = m_config->read_xml(config);
if (!r)
m_config->get_generic_info(&m_log_mask, &m_max_clients,
- &m_connect_max);
+ &m_connect_max, &m_limit_connect);
return r;
}
{
m_log_mask = 0;
cfg->get_generic_info(&m_log_mask, &m_max_clients,
- &m_connect_max);
+ &m_connect_max, &m_limit_connect);
}
}
else
Yaz_Proxy *new_proxy = new Yaz_Proxy(the_PDU_Observable,
m_socket_observable, this);
+
+ if (m_limit_connect)
+ new_proxy->m_initial_reduce = connect_total / m_limit_connect;
+
new_proxy->m_config = 0;
new_proxy->m_config_fname = 0;
new_proxy->timeout(m_client_idletime);
void Yaz_Proxy::convert_records_charset(Z_NamePlusRecordList *p,
const char *backend_charset)
{
- yaz_log(YLOG_LOG, "%sconvert_to_marc", m_session_str);
int sel = m_charset_converter->get_client_charset_selected();
const char *client_record_charset =
m_charset_converter->get_client_query_charset();
yaz_iconv_close(cd);
yaz_marc_destroy(mt);
}
- else
- {
- yaz_log(YLOG_LOG, "%sSkipping marc convert", m_session_str);
- }
}
void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p,
void Yaz_Proxy::recv_GDU_reduce(GDU *gdu)
{
- int reduce = 0;
+ int reduce = m_initial_reduce; // initial reduce from connect phase..
+ m_initial_reduce = 0; // reset it..
int bw_total = m_bw_stat.get_total();
int pdu_total = m_pdu_stat.get_total();
+ int search_total = m_search_stat.get_total();
assert(m_timeout_mode == timeout_busy);
assert(m_timeout_gdu == 0);
+ if (m_search_max)
+ reduce += search_total / m_search_max;
if (m_bw_max)
- {
- if (bw_total > m_bw_max)
- {
- reduce = (bw_total/m_bw_max);
- }
- }
+ reduce += (bw_total/m_bw_max);
if (m_pdu_max)
{
if (pdu_total > m_pdu_max)
#endif
if (reduce)
{
- yaz_log(YLOG_LOG, "%sdelay=%d bw=%d pdu=%d limit-bw=%d limit-pdu=%d",
- m_session_str, reduce, bw_total, pdu_total,
- m_bw_max, m_pdu_max);
+ yaz_log(YLOG_LOG, "%sdelay=%d bw=%d pdu=%d search=%d limit-bw=%d limit-pdu=%d limit-search=%d",
+ m_session_str, reduce, bw_total, pdu_total, search_total,
+ m_bw_max, m_pdu_max, m_search_max);
m_timeout_mode = timeout_reduce;
m_timeout_gdu = gdu;
if (strcmp(hreq->method, "GET"))
return 0;
if (hreq->path[0] != '/')
- {
- yaz_log(YLOG_WARN, "Bad path: %s", hreq->path);
return 0;
- }
const char *cp = hreq->path;
while (*cp)
{
if (*cp == '/' && strchr("/.", cp[1]))
{
- yaz_log(YLOG_WARN, "Bad path: %s", hreq->path);
+ yaz_log(YLOG_LOG, "%sRejecting path %s", m_session_str,
+ hreq->path);
return 0;
}
cp++;
}
+
+ Yaz_ProxyConfig *cfg = check_reconfigure();
+
+ if (!cfg->get_file_access_info(hreq->path+1))
+ return 0;
+
const char *fname = hreq->path+1;
if (stat(fname, &sbuf))
{
- yaz_log(YLOG_WARN|YLOG_ERRNO, "%s: stat failed", fname);
+ yaz_log(YLOG_LOG|YLOG_ERRNO, "%sstat failed for %s", m_session_str,
+ fname);
return 0;
}
if ((sbuf.st_mode & S_IFMT) != S_IFREG)
{
- yaz_log(YLOG_WARN, "%s: not a regular file", fname);
+ yaz_log(YLOG_LOG, "%sNot a regular file %s", m_session_str, fname);
return 0;
}
if (sbuf.st_size > (off_t) 1000000)
{
- yaz_log(YLOG_WARN, "%s: too large for transfer", fname);
+ yaz_log(YLOG_WARN, "%sFile %s too large for transfer", m_session_str,
+ fname);
return 0;
}
ODR o = odr_encode();
- Yaz_ProxyConfig *cfg = check_reconfigure();
+
const char *ctype = cfg->check_mime_type(fname);
Z_GDU *gdu = z_get_HTTP_Response(o, 200);
Z_HTTP_Response *hres = gdu->u.HTTP_Response;
if (srw_pdu->which == Z_SRW_searchRetrieve_request)
{
+
Z_SRW_searchRetrieveRequest *srw_req = srw_pdu->u.request;
const char *backend_db = srw_req->database;
apdu = m_initRequest_apdu; // but throw an init to the target
}
+ if (apdu->which == Z_APDU_searchRequest)
+ m_search_stat.add_bytes(1);
+
// Determine our client.
Z_OtherInformation **oi;
get_otherInfoAPDU(apdu, &oi);