aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/net/http_protocol_handler.inl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include/net/http_protocol_handler.inl')
-rw-r--r--contrib/epee/include/net/http_protocol_handler.inl44
1 files changed, 29 insertions, 15 deletions
diff --git a/contrib/epee/include/net/http_protocol_handler.inl b/contrib/epee/include/net/http_protocol_handler.inl
index c18f7f706..b35bcb670 100644
--- a/contrib/epee/include/net/http_protocol_handler.inl
+++ b/contrib/epee/include/net/http_protocol_handler.inl
@@ -38,6 +38,7 @@
#define HTTP_MAX_URI_LEN 9000
#define HTTP_MAX_HEADER_LEN 100000
+#define HTTP_MAX_STARTING_NEWLINES 8
namespace epee
{
@@ -195,15 +196,17 @@ namespace net_utils
//--------------------------------------------------------------------------------------------
template<class t_connection_context>
- simple_http_connection_handler<t_connection_context>::simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config):
+ simple_http_connection_handler<t_connection_context>::simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context):
m_state(http_state_retriving_comand_line),
m_body_transfer_type(http_body_transfer_undefined),
- m_is_stop_handling(false),
+ m_is_stop_handling(false),
m_len_summary(0),
m_len_remain(0),
- m_config(config),
+ m_config(config),
m_want_close(false),
- m_psnd_hndlr(psnd_hndlr)
+ m_newlines(0),
+ m_psnd_hndlr(psnd_hndlr),
+ m_conn_context(conn_context)
{
}
@@ -216,6 +219,7 @@ namespace net_utils
m_body_transfer_type = http_body_transfer_undefined;
m_query_info.clear();
m_len_summary = 0;
+ m_newlines = 0;
return true;
}
//--------------------------------------------------------------------------------------------
@@ -236,6 +240,8 @@ namespace net_utils
bool simple_http_connection_handler<t_connection_context>::handle_buff_in(std::string& buf)
{
+ size_t ndel;
+
if(m_cache.size())
m_cache += buf;
else
@@ -253,11 +259,19 @@ namespace net_utils
break;
//check_and_handle_fake_response();
- if((m_cache[0] == '\r' || m_cache[0] == '\n'))
+ ndel = m_cache.find_first_not_of("\r\n");
+ if (ndel != 0)
{
//some times it could be that before query line cold be few line breaks
//so we have to be calm without panic with assers
- m_cache.erase(0, 1);
+ m_newlines += std::string::npos == ndel ? m_cache.size() : ndel;
+ if (m_newlines > HTTP_MAX_STARTING_NEWLINES)
+ {
+ LOG_ERROR("simple_http_connection_handler::handle_buff_out: Too many starting newlines");
+ m_state = http_state_error;
+ return false;
+ }
+ m_cache.erase(0, ndel);
break;
}
@@ -268,7 +282,7 @@ namespace net_utils
m_is_stop_handling = true;
if(m_cache.size() > HTTP_MAX_URI_LEN)
{
- LOG_ERROR("simple_http_connection_handler::handle_buff_out: Too long URI line");
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler::handle_buff_out: Too long URI line");
m_state = http_state_error;
return false;
}
@@ -282,7 +296,7 @@ namespace net_utils
m_is_stop_handling = true;
if(m_cache.size() > HTTP_MAX_HEADER_LEN)
{
- LOG_ERROR("simple_http_connection_handler::handle_buff_in: Too long header area");
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler::handle_buff_in: Too long header area");
m_state = http_state_error;
return false;
}
@@ -297,10 +311,10 @@ namespace net_utils
case http_state_connection_close:
return false;
default:
- LOG_ERROR("simple_http_connection_handler::handle_char_out: Wrong state: " << m_state);
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler::handle_char_out: Wrong state: " << m_state);
return false;
case http_state_error:
- LOG_ERROR("simple_http_connection_handler::handle_char_out: Error state!!!");
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler::handle_char_out: Error state!!!");
return false;
}
@@ -362,7 +376,7 @@ namespace net_utils
}else
{
m_state = http_state_error;
- LOG_ERROR("simple_http_connection_handler<t_connection_context>::handle_invoke_query_line(): Failed to match first line: " << m_cache);
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler<t_connection_context>::handle_invoke_query_line(): Failed to match first line: " << m_cache);
return false;
}
@@ -393,7 +407,7 @@ namespace net_utils
if(!parse_cached_header(m_query_info.m_header_info, m_cache, pos))
{
- LOG_ERROR("simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(): failed to anilize request header: " << m_cache);
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(): failed to anilize request header: " << m_cache);
m_state = http_state_error;
return false;
}
@@ -409,7 +423,7 @@ namespace net_utils
m_body_transfer_type = http_body_transfer_measure;
if(!get_len_from_content_lenght(m_query_info.m_header_info.m_content_length, m_len_summary))
{
- LOG_ERROR("simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(): Failed to get_len_from_content_lenght();, m_query_info.m_content_length="<<m_query_info.m_header_info.m_content_length);
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(): Failed to get_len_from_content_lenght();, m_query_info.m_content_length="<<m_query_info.m_header_info.m_content_length);
m_state = http_state_error;
return false;
}
@@ -442,7 +456,7 @@ namespace net_utils
case http_body_transfer_multipart:
case http_body_transfer_undefined:
default:
- LOG_ERROR("simple_http_connection_handler<t_connection_context>::handle_retriving_query_body(): Unexpected m_body_query_type state:" << m_body_transfer_type);
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler<t_connection_context>::handle_retriving_query_body(): Unexpected m_body_query_type state:" << m_body_transfer_type);
m_state = http_state_error;
return false;
}
@@ -523,7 +537,7 @@ namespace net_utils
body_info.m_etc_fields.push_back(std::pair<std::string, std::string>(result[field_etc_name], result[field_val]));
else
{
- LOG_ERROR("simple_http_connection_handler<t_connection_context>::parse_cached_header() not matched last entry in:"<<m_cache_to_process);
+ LOG_ERROR_CC(m_conn_context, "simple_http_connection_handler<t_connection_context>::parse_cached_header() not matched last entry in:" << m_cache_to_process);
}
it_current_bound = result[(int)result.size()-1]. first;