std::string cert_fname;
int max_recv_bytes;
};
+ class FrontendNet::IP_Pattern {
+ friend class Rep;
+ friend class FrontendNet;
+ std::string pattern;
+ int value;
+ };
class FrontendNet::Rep {
friend class FrontendNet;
int m_listen_duration;
int m_session_timeout;
int m_connect_max;
- int m_http_req_max;
+ std::list<IP_Pattern> http_req_max;
std::string m_msg_config;
std::string m_stat_req;
yazpp_1::SocketManager mySocketManager;
m_limit_connect.add_connect(peername.c_str());
m_limit_connect.cleanup(false);
int con_sz = m_limit_connect.get_total(peername.c_str());
-
- if (m_p->m_http_req_max && con_sz >= m_p->m_http_req_max)
+ std::list<IP_Pattern>::const_iterator it = m_p->http_req_max.begin();
+ for (; it != m_p->http_req_max.end(); it++)
{
- mp::odr o;
- Z_GDU *gdu_res = o.create_HTTP_Response(m_session, hreq, 500);
- int len;
- send_GDU(gdu_res, &len);
- return;
+ if (mp::util::match_ip(it->pattern, peername))
+ {
+ if (con_sz < it->value)
+ break;
+ mp::odr o;
+ Z_GDU *gdu_res = o.create_HTTP_Response(m_session, hreq, 500);
+ int len;
+ send_GDU(gdu_res, &len);
+ return;
+ }
}
}
m_listen_duration = 0;
m_session_timeout = 300; // 5 minutes
m_connect_max = 0;
- m_http_req_max = 0;
az = 0;
size_t i;
for (i = 0; i < 22; i++)
}
else if (!strcmp((const char *) ptr->name, "http-req-max"))
{
- m_p->m_http_req_max = mp::xml::get_int(ptr, 0);
+ const char *names[2] = {"ip", 0};
+ std::string values[1];
+
+ mp::xml::parse_attr(ptr, names, values);
+ IP_Pattern m;
+ m.value = mp::xml::get_int(ptr, 0);
+ m.pattern = values[0];
+ m_p->http_req_max.push_back(m);
}
else if (!strcmp((const char *) ptr->name, "message"))
{
#include <yaz/querytowrbuf.h>
#include <yaz/oid_db.h>
#include <yaz/srw.h>
+#include <yaz/match_glob.h>
+
+#include <boost/algorithm/string.hpp>
#include <iostream>
return wrbuf_cstr_null(m_wrbuf);
}
+bool mp::util::match_ip(const std::string &pattern, const std::string &value)
+{
+ std::vector<std::string> globitems;
+ boost::split(globitems, pattern, boost::is_any_of(" "));
+ std::vector<std::string>::const_iterator it = globitems.begin();
+ bool ret_value = true; // for now (if only empty values)
+ for (; it != globitems.end(); it++)
+ {
+ const char *c_str = (*it).c_str();
+ if (*c_str)
+ {
+ ret_value = false; // at least one non-empty value
+ if (yaz_match_glob(c_str, value.c_str()))
+ return true;
+ }
+ }
+ return ret_value;
+}
+
/*
* Local variables:
* c-basic-offset: 4
}+,
element mp:timeout { xsd:integer }?,
element mp:connect-max { xsd:integer }?,
- element mp:http-req-max { xsd:integer }?,
+ element mp:http-req-max {
+ attribute ip { xsd:string }?,
+ xsd:integer
+ }*,
element mp:message { xsd:string }?,
element mp:stat-req { xsd:string }?