const int protocol_module_sessionless::COLLECT_STATS_OFF = 0;
const int protocol_module_sessionless::COLLECT_STATS_ON = 1;
-//! constractor
+//! constructor
protocol_module_sessionless::protocol_module_sessionless() :
http_protocol_module_base(MODULE_NAME), forwarded_for(FORWARDED_FOR_OFF)
{
sorry_uri.assign('\0');
sorry_uri[0] = '/';
}
-//! destractor
+//! destructor
protocol_module_sessionless::~protocol_module_sessionless()
{
}
return false;
}
-//! replication interval interrrupt
+//! replication interval interrupt
//! timer thread call this function. from virtualservice.
void protocol_module_sessionless::replication_interrupt()
{
rs_list_end = inlist_end;
//RealServer list next function
rs_list_next = inlist_next;
- //RealServer list lock funtion
+ //RealServer list lock function
rs_list_lock = inlist_lock;
- //RealServer list unlock funtion
+ //RealServer list unlock function
rs_list_unlock = inlist_unlock;
/*-------- DEBUG LOG --------*/
}
/*------DEBUG LOG END------*/
- //RealServer list functions initializtion
+ //RealServer list functions initialization
//RealServer list begin function
rs_list_begin.clear();
//RealServer list end function
}
/*------DEBUG LOG END------*/
- //Replication functions initializtion
- //component memory allcate function
+ //Replication functions initialization
+ //component memory allocate function
replication_pay_memory.clear();
//component memory lock function
replication_area_lock.clear();
}
/*------DEBUG LOG END------*/
- //ScheduleModule's functions initializtion
+ //ScheduleModule's functions initialization
schedule_tcp.clear();
/*-------- DEBUG LOG --------*/
}
/*------DEBUG LOG END------*/
- //Module's option initializtion
+ //Module's option initialization
//forwarded_for
forwarded_for = FORWARDED_FOR_OFF;
//sorry-uri
/*------DEBUG LOG END------*/
- //logger functions initializtion
+ //logger functions initialization
//log level getting function
getloglevel.clear();
//logger(Fatal)
}
//! module parameter check.used by l7vsadm
-//! @param[in] module paramter string list
-//! @return result.flag true is parameter is noproblem.
-//! @return result.flag false is paramter is problem.
+//! @param[in] module parameter string list
+//! @return result.flag true is parameter is no problem.
+//! @return result.flag false is parameter is problem.
protocol_module_base::check_message_result protocol_module_sessionless::check_parameter(const std::vector <
std::string > & args)
{
bool forward_checked = false;
bool sorryuri_checked = false;
bool stats_checked = false;
+
+ // cf RFC 2396 (A. Collected BNF for URI)
sregex sorry_uri_regex
= +('/' >>
- *(alpha |
- digit |
- (set = ';', ':', '@', '&', '=') |
- (set = '$', '-', '_', '.', '+') |
- (set = '!', '*', '\'', '\(', ')', ',') |
- '%' >> repeat<2>(xdigit)));
+ *(
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') |
+ '%' >> repeat<2>(xdigit) |
+ (set = ':', '@', '&', '=', '+', '$', ',')
+ )
+ >>
+ *(';' >>
+ *(
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') | // mark
+ '%' >> repeat<2>(xdigit) | // escaped
+ (set = ':', '@', '&', '=', '+', '$', ',')
+ ) // pchar
+ ) // param
+ ) // segment
+ >>
+ !('?' >>
+ *(
+ (set = ';', '/', '?', ':', '@', '&', '=', '+', '$', ',') | //reserved
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') | // mark
+ '%' >> repeat<2>(xdigit) // escaped
+ ) // uric
+ ) // query
+ >>
+ !('#' >>
+ *(
+ (set = ';', '/', '?', ':', '@', '&', '=', '+', '$', ',') | //reserved
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') | // mark
+ '%' >> repeat<2>(xdigit) // escaped
+ ) // uric
+ ); // fragment
+
typedef std::vector<std::string>::const_iterator vec_str_it;
try {
}
//! parameter set
-//! @param[in] module paramter string list
-//! @return result.flag true is parameter is noproblem.
-//! @return result.flag false is paramter is problem.
+//! @param[in] module parameter string list
+//! @return result.flag true is parameter is no problem.
+//! @return result.flag false is parameter is problem.
protocol_module_base::check_message_result protocol_module_sessionless::set_parameter(const std::vector <
std::string > & args)
{
bool forward_checked = false;
bool sorryuri_checked = false;
bool stats_checked = false;
+
+ // cf RFC 2396 (A. Collected BNF for URI)
sregex sorry_uri_regex
= +('/' >>
- *(alpha |
- digit |
- (set = ';', ':', '@', '&', '=') |
- (set = '$', '-', '_', '.', '+') |
- (set = '!', '*', '\'', '\(', ')', ',') |
- '%' >> repeat<2>(xdigit)));
+ *(
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') |
+ '%' >> repeat<2>(xdigit) |
+ (set = ':', '@', '&', '=', '+', '$', ',')
+ )
+ >>
+ *(';' >>
+ *(
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') | // mark
+ '%' >> repeat<2>(xdigit) | // escaped
+ (set = ':', '@', '&', '=', '+', '$', ',')
+ ) // pchar
+ ) // param
+ ) // segment
+ >>
+ !('?' >>
+ *(
+ (set = ';', '/', '?', ':', '@', '&', '=', '+', '$', ',') | //reserved
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') | // mark
+ '%' >> repeat<2>(xdigit) // escaped
+ ) // uric
+ ) // query
+ >>
+ !('#' >>
+ *(
+ (set = ';', '/', '?', ':', '@', '&', '=', '+', '$', ',') | //reserved
+ alpha | digit |
+ (set = '-', '_', '.', '!', '~', '*', '\'', '(', ')') | // mark
+ '%' >> repeat<2>(xdigit) // escaped
+ ) // uric
+ ); // fragment
typedef std::vector<std::string>::const_iterator vec_str_it;
}
//! parameter add
-//! @param[in] module paramter string list
-//! @return result.flag true is parameter is noproblem.
-//! @return result.flag false is paramter is problem.
+//! @param[in] module parameter string list
+//! @return result.flag true is parameter is no problem.
+//! @return result.flag false is parameter is problem.
protocol_module_base::check_message_result protocol_module_sessionless::add_parameter(const std::vector <
std::string > & args)
{
}
//! get option info
-//! @param[out] module paramter string
+//! @param[out] module parameter string
void protocol_module_sessionless::get_option_info(std::string &option)
{
/*-------- DEBUG LOG --------*/
}
/*------DEBUG LOG END------*/
- boost::format option_formatter("%s--sorry-uri '%s' --statistic '%d'");
+ boost::format option_formatter("%s--sorry-uri '%s' --statistic %d");
option_formatter % (forwarded_for ? "--forwarded-for " : "") % sorry_uri.c_array()
% statistic;
option.assign(option_formatter.str());
/*------DEBUG LOG END------*/
}
-//! TCP/IP scheduled function registation.
+//! TCP/IP scheduled function registration.
//! @param[in] schedule module TCP/IP scheduled function object type
void protocol_module_sessionless::register_schedule(tcp_schedule_func_type inschedule)
{
/*------DEBUG LOG END------*/
}
-//! UDP scheduled function registation
-//! @param[in] schedule module UDP scheduled funtion object type
+//! UDP scheduled function registration
+//! @param[in] schedule module UDP scheduled function object type
void protocol_module_sessionless::register_schedule(udp_schedule_func_type inschedule)
{
/*-------- DEBUG LOG --------*/
/*------DEBUG LOG END------*/
}
-//! called from session initialzie use in upstream_thread
+//! called from session initialize use in upstream_thread
//! @param[in] upstream thread id.
//! @param[in] downstream thread id
//! @return session use EVENT mode.
//set return status
status = SORRYSERVER_SELECT;
}
- //sorry flag on
+ //sorry flag off
else {
//set return status
status = REALSERVER_SELECT;
//! called from after session recv in client socket. use in upstream thread.
//! @param[in] upstream thread id
-//! @param[in] receive buffer refarence.
+//! @param[in] receive buffer reference.
//! @param[in] receive length
//! @return session use EVENT mode.
protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_recv(const boost::thread::id thread_id,
if (recv_data.receive_buffer_max_size < data_remain_size + recvlen) {
//the buffer's size that will be allocated is exceed the upper limit value
if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen) {
- std::cerr << "protocol_module_sessionless::handle_client_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
+ std::cerr << "protocol_module_sessionless::handle_client_recv() : the buffer's size that will be allocated is exceed the upper limit value." << std::endl;
boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
formatter % boost::this_thread::get_id();
putLogError(100030, formatter.str(), __FILE__, __LINE__);
//set new buffer's max size
recv_data.receive_buffer_max_size = buffer_size;
}
- //buffer's max size >= remain data size + requst size
+ //buffer's max size >= remain data size + request size
//buffer isn't need reallocate, but switch
else {
//pointer valid check
}
//using buffer is buffer2
else {
- //buffer1 initializtion
+ //buffer1 initialization
memset(recv_data.receive_buffer1, 0, recv_data.receive_buffer_max_size);
/*-------- DEBUG LOG --------*/
if (unlikely(LOG_LV_DEBUG == getloglevel())) {
}
//status is SEND_NG
else if (it->status == SEND_NG) {
- if (forwarded_for == FORWARDED_FOR_ON) {
+ if (statistic == COLLECT_STATS_ON || forwarded_for == FORWARDED_FOR_ON) {
//check http method
check_result = check_http_method(recv_data.receive_buffer + it->send_offset, data_remain_size);
/*-------- DEBUG LOG --------*/
//add new status to status_list
recv_data.send_status_list.push_back(new_send_state);
std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
- //cacl offset
+ //calc offset
new_send_it->send_offset = recv_data.receive_buffer_max_size - recv_data.receive_buffer_rest_size
- request_data_remain_size;
- if (forwarded_for == FORWARDED_FOR_ON || session_data->sorry_flag == SORRY_FLAG_ON) {
+ if (statistic == COLLECT_STATS_ON || forwarded_for == FORWARDED_FOR_ON || session_data->sorry_flag == SORRY_FLAG_ON) {
//check http method
check_result = check_http_method(recv_data.receive_buffer + new_send_it->send_offset,
request_data_remain_size);
it->edit_division = EDIT_DIVISION_NO_EDIT;
if (send_buffer_remian_size > 0 && it->send_possible_size > 0) {
- //send_buffer_remian_size is larger
+ //send_buffer_remain_size is larger
if (send_buffer_remian_size >= it->send_possible_size) {
copy_size = it->send_possible_size;
/*-------- DEBUG LOG --------*/
}
//edit_data_list is not empty
else {
- //find the item in the list which has mininum insert_posission
+ //find the item in the list which has minimum insert_position
std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
it->edit_data_list.end());
- //send_buffer_remian_size is larger than data that before X-Forwarded-For
+ //send_buffer_remain_size is larger than data that before X-Forwarded-For
if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size) {
//copy data before X-Forwarded-For
copy_size = edit_min->insert_posission - it->send_end_size;
break;
}
}
- //data that before X-Forwarded-For is larger than send_buffer_remian_size
+ //data that before X-Forwarded-For is larger than send_buffer_remain_size
else {
copy_size = send_buffer_remian_size;
/*-------- DEBUG LOG --------*/
}
}
- //set copyed data length
+ //set copied data length
datalen = send_buffer_end_size - send_buffer_remian_size;
status = REALSERVER_SEND;
} catch (int e) {
//offset recalc
it->send_offset += it->send_end_size;
- //insert_posission recalc
+ //insert_position recalc
for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
!= it->edit_data_list.end(); ++list_it) {
list_it->insert_posission -= it->send_end_size;
//! called from after sorryserver select
//! @param[in] upstream thread id
-//! @param[in] sorryserver endpiont reference
+//! @param[in] sorryserver endpoint reference
//! @return session use EVENT mode.
protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_select(
const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint &sorry_endpoint)
}
}
- if (forwarded_for == FORWARDED_FOR_ON || session_data->sorry_flag == SORRY_FLAG_ON) {
+ if (forwarded_for == FORWARDED_FOR_ON) {
//search X-Forwarded-For header
ret = find_http_header(recv_data.receive_buffer + it->send_offset, it->send_possible_size,
str_forword_for.c_str(), header_offset, header_offset_len);
it->edit_division = EDIT_DIVISION_NO_EDIT;
if (send_buffer_remian_size > 0 && it->send_possible_size > 0) {
- //send_buffer_remian_size is larger
+ //send_buffer_remain_size is larger
if (send_buffer_remian_size > it->send_possible_size) {
//copy data from receive_buffer to sendbuffer by sending_possible size
copy_size = it->send_possible_size;
}
//edit_data_list is not empty
else {
- //search item which insert_posission is mininum
+ //search item which insert_position is minimum
std::list<edit_data>::iterator edit_min = std::min_element(it->edit_data_list.begin(),
it->edit_data_list.end());
- //send_buffer_remian_size is larger than data that before X-Forwarded-For/uri
+ //send_buffer_remain_size is larger than data that before X-Forwarded-For/uri
if (send_buffer_remian_size >= edit_min->insert_posission - it->send_end_size) {
//copy data before X-Forwarded-For/url
copy_size = edit_min->insert_posission - it->send_end_size;
break;
}
}
- //data that before X-Forwarded-For/uri is larger than send_buffer_remian_size
+ //data that before X-Forwarded-For/uri is larger than send_buffer_remain_size
else {
copy_size = send_buffer_remian_size;
/*-------- DEBUG LOG --------*/
}
}
- //set copyed data length
+ //set copied data length
datalen = send_buffer_end_size - send_buffer_remian_size;
status = SORRYSERVER_SEND;
//offset recalc
it->send_offset += it->send_end_size;
- //insert_posission recalc
+ //insert_position recalc
for (std::list<edit_data>::iterator list_it = it->edit_data_list.begin(); list_it
!= it->edit_data_list.end(); ++list_it) {
list_it->insert_posission -= it->send_end_size;
}
//sending possible data is not exist
else {
- //can receive from clent continue
+ //can receive from client continue
if (it->send_rest_size > 0) {
//change status from SEND_OK to SEND_CONTINUE
it->status = SEND_CONTINUE;
}
- //can not receive from clent continue
+ //can not receive from client continue
else {
//change status from SEND_OK to SEND_END
it->status = SEND_END;
return STOP;
}
-//! called from after realserver recvive for TCP/IP
+//! called from after realserver receive for TCP/IP
//! @param[in] downstream thread id
//! @param[in] realserver TCP/IP endpoint reference
//! @param[in] realserver receive buffer reference.
if (recv_data.receive_buffer_max_size < data_remain_size + recvlen) {
//the buffer's size that will be allocated is exceed the upper limit value
if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen) {
- std::cerr << "protocol_module_sessionless::handle_realserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
+ std::cerr << "protocol_module_sessionless::handle_realserver_recv() : the buffer's size that will be allocated is exceed the upper limit value." << std::endl;
boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
formatter % boost::this_thread::get_id();
putLogError(100083, formatter.str(), __FILE__, __LINE__);
//set new buffer's max size
recv_data.receive_buffer_max_size = buffer_size;
}
- //buffer's max size >= remain data size + requst size
+ //buffer's max size >= remain data size + request size
//buffer isn't need reallocate, but switch
else {
//pointer valid check
if (recv_data.receive_buffer_max_size < data_remain_size + recvlen) {
//the buffer's size that will be allocated is exceed the upper limit value
if (MAX_SESSIONLESS_MODULE_BUFFER_SIZE < data_remain_size + recvlen) {
- std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : the buffer's size that will be allacted is exceed the upper limit value." << std::endl;
+ std::cerr << "protocol_module_sessionless::handle_sorryserver_recv() : the buffer's size that will be allocated is exceed the upper limit value." << std::endl;
boost::format formatter("The buffer's size that will be allocated is exceed the upper limit value. thread id : %d.");
formatter % boost::this_thread::get_id();
putLogError(100094, formatter.str(), __FILE__, __LINE__);
//set new buffer's max size
recv_data.receive_buffer_max_size = buffer_size;
}
- //buffer's max size >= remain data size + requst size
+ //buffer's max size >= remain data size + request size
//buffer isn't need reallocate, but switch
else {
//pointer valid check
}
//using buffer is buffer2
else {
- //buffer1 initializtion
+ //buffer1 initialization
memset(recv_data.receive_buffer1, 0, recv_data.receive_buffer_max_size);
/*-------- DEBUG LOG --------*/
if (unlikely(LOG_LV_DEBUG == getloglevel())) {
//add new status to status_list
recv_data.send_status_list.push_back(new_send_state);
std::list<send_status>::reverse_iterator new_send_it = recv_data.send_status_list.rbegin();
- //cacl offset
+ //calc offset
new_send_it->send_offset = recv_data.receive_buffer_max_size - recv_data.receive_buffer_rest_size
- request_data_remain_size;
return status;
}
-//! called from UPSTEEARM thread. make module original message.
+//! called from UPSTREAM thread. make module original message.
//! @param[in] downstream thread id.
//! @return session use EVENT mode
protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_response_send_inform(
//! called from after client connection check. use TCP/IP only. create client send message.
//! @param[in] downstream thread id
-//! @param[out] send budffer reference
+//! @param[out] send buffer reference
//! @param[out] send data length
//! @return session use EVENT mode
protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_connection_check(
/*------DEBUG LOG END------*/
//send_end_size recalc
it->send_end_size = it->send_possible_size;
- //set copyed data length
+ //set copied data length
datalen = it->send_possible_size;
//sending_possible size recalc
it->send_possible_size = 0;
it->send_end_size = send_buffer_size;
//sending_possible size recalc
it->send_possible_size -= send_buffer_size;
- //set copyed data length
+ //set copied data length
datalen = send_buffer_size;
}
}
//sending possible data is not exist
else {
- //can receive from clent continue
+ //can receive from client continue
if (it->send_rest_size > 0) {
//change status from SEND_OK to SEND_CONTINUE
it->status = SEND_CONTINUE;
}
- //can not receive from clent continue
+ //can not receive from client continue
else {
//change status from SEND_OK to SEND_END
it->status = SEND_END;
}
/*------DEBUG LOG END------*/
- //sending ng data is exist or send_rest_size > 0
+ //sending NG data is exist or send_rest_size > 0
if (send_disable) {
//set end flag on
session_data->end_flag = END_FLAG_ON;
send_possible = true;
}
- //sending ng data is exist or send_rest_size > 0
+ //sending NG data is exist or send_rest_size > 0
it = find_if(recv_data.send_status_list.begin(), recv_data.send_status_list.end(), data_send_disable());
if (it != recv_data.send_status_list.end()) {
send_disable = true;
putLogDebug(100244, formatter.str(), __FILE__, __LINE__);
}
/*------DEBUG LOG END------*/
- //sending ng data is exist or send_rest_size > 0
+ //sending NG data is exist or send_rest_size > 0
if (send_disable) {
//set end flag on
session_data->end_flag = END_FLAG_ON;
return status;
}
-//! call from sorry server disconnect. use upstraem thread and downstream thread
+//! call from sorry server disconnect. use upstream thread and downstream thread
//! @param[in] upstream and downstream thread id( check! one thread one event )
//! @param[in] disconnect sorryserver endpoint
//! @return session use EVENT mode
: session_data->target_endpoint;
receive_data_map_it receive_data_it = session_data->receive_data_map.find(endpoint);
if (unlikely(receive_data_it == session_data->receive_data_map.end())) {
- boost::format formatter("Invalid endpoint. thread id : %d.");
- formatter % boost::this_thread::get_id();
+ boost::format formatter("Invalid endpoint(%s). thread id: %d.");
+ formatter % endpoint % boost::this_thread::get_id();
putLogError(100125, formatter.str(), __FILE__, __LINE__);
throw - 1;
}