wallet-rpc: added IPs to error logging in simple_http_connection_handler

This commit is contained in:
jcktm 2018-04-17 19:30:18 +10:00
parent 62f3f0480a
commit b43b9a1304
2 changed files with 18 additions and 18 deletions

View File

@ -69,7 +69,7 @@ namespace net_utils
typedef t_connection_context connection_context;//t_connection_context net_utils::connection_context_base connection_context; typedef t_connection_context connection_context;//t_connection_context net_utils::connection_context_base connection_context;
typedef http_server_config config_type; typedef http_server_config config_type;
simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config); simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context);
virtual ~simple_http_connection_handler(){} virtual ~simple_http_connection_handler(){}
bool release_protocol() bool release_protocol()
@ -144,6 +144,7 @@ namespace net_utils
size_t m_newlines; size_t m_newlines;
protected: protected:
i_service_endpoint* m_psnd_hndlr; i_service_endpoint* m_psnd_hndlr;
t_connection_context& m_conn_context;
}; };
template<class t_connection_context> template<class t_connection_context>
@ -175,9 +176,8 @@ namespace net_utils
typedef custum_handler_config<t_connection_context> config_type; typedef custum_handler_config<t_connection_context> config_type;
http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context) http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context)
: simple_http_connection_handler<t_connection_context>(psnd_hndlr, config), : simple_http_connection_handler<t_connection_context>(psnd_hndlr, config, conn_context),
m_config(config), m_config(config),
m_conn_context(conn_context),
m_auth(m_config.m_user ? http_server_auth{*m_config.m_user, config.rng} : http_server_auth{}) m_auth(m_config.m_user ? http_server_auth{*m_config.m_user, config.rng} : http_server_auth{})
{} {}
inline bool handle_request(const http_request_info& query_info, http_response_info& response) inline bool handle_request(const http_request_info& query_info, http_response_info& response)
@ -197,7 +197,7 @@ namespace net_utils
response.m_response_comment = "OK"; response.m_response_comment = "OK";
response.m_body.clear(); response.m_body.clear();
return m_config.m_phandler->handle_http_request(query_info, response, m_conn_context); return m_config.m_phandler->handle_http_request(query_info, response, this->m_conn_context);
} }
virtual bool thread_init() virtual bool thread_init()
@ -219,7 +219,6 @@ namespace net_utils
private: private:
//simple_http_connection_handler::config_type m_stub_config; //simple_http_connection_handler::config_type m_stub_config;
config_type& m_config; config_type& m_config;
t_connection_context& m_conn_context;
http_server_auth m_auth; http_server_auth m_auth;
}; };
} }

View File

@ -196,7 +196,7 @@ namespace net_utils
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
template<class t_connection_context> 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_state(http_state_retriving_comand_line),
m_body_transfer_type(http_body_transfer_undefined), m_body_transfer_type(http_body_transfer_undefined),
m_is_stop_handling(false), m_is_stop_handling(false),
@ -205,7 +205,8 @@ namespace net_utils
m_config(config), m_config(config),
m_want_close(false), m_want_close(false),
m_newlines(0), m_newlines(0),
m_psnd_hndlr(psnd_hndlr) m_psnd_hndlr(psnd_hndlr),
m_conn_context(conn_context)
{ {
} }
@ -281,7 +282,7 @@ namespace net_utils
m_is_stop_handling = true; m_is_stop_handling = true;
if(m_cache.size() > HTTP_MAX_URI_LEN) 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; m_state = http_state_error;
return false; return false;
} }
@ -295,7 +296,7 @@ namespace net_utils
m_is_stop_handling = true; m_is_stop_handling = true;
if(m_cache.size() > HTTP_MAX_HEADER_LEN) 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; m_state = http_state_error;
return false; return false;
} }
@ -310,10 +311,10 @@ namespace net_utils
case http_state_connection_close: case http_state_connection_close:
return false; return false;
default: 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; return false;
case http_state_error: 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; return false;
} }
@ -375,7 +376,7 @@ namespace net_utils
}else }else
{ {
m_state = http_state_error; 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; return false;
} }
@ -406,7 +407,7 @@ namespace net_utils
if(!parse_cached_header(m_query_info.m_header_info, m_cache, pos)) 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; m_state = http_state_error;
return false; return false;
} }
@ -422,7 +423,7 @@ namespace net_utils
m_body_transfer_type = http_body_transfer_measure; 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)) 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; m_state = http_state_error;
return false; return false;
} }
@ -455,7 +456,7 @@ namespace net_utils
case http_body_transfer_multipart: case http_body_transfer_multipart:
case http_body_transfer_undefined: case http_body_transfer_undefined:
default: 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; m_state = http_state_error;
return false; return false;
} }
@ -536,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])); body_info.m_etc_fields.push_back(std::pair<std::string, std::string>(result[field_etc_name], result[field_val]));
else 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; it_current_bound = result[(int)result.size()-1]. first;