OSDN Git Service

bug fix. Can not get statistic when option -c only.
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / module / protocol / protocol_module_sessionless.cpp
index 6b0ee4e..27ef5dc 100644 (file)
@@ -300,14 +300,45 @@ protocol_module_base::check_message_result protocol_module_sessionless::check_pa
         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 {
@@ -512,14 +543,44 @@ protocol_module_base::check_message_result protocol_module_sessionless::set_para
         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;
 
@@ -1096,7 +1157,7 @@ protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_accept(const
                         //set return status
                         status = SORRYSERVER_SELECT;
                 }
-                //sorry flag on
+                //sorry flag off
                 else {
                         //set return status
                         status = REALSERVER_SELECT;
@@ -1686,7 +1747,7 @@ protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_recv(
                                 }
                                 //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 --------*/
@@ -1897,7 +1958,7 @@ protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_client_recv(
                                 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);
@@ -3270,7 +3331,7 @@ protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_
                                         }
                                 }
 
-                                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);
@@ -6996,8 +7057,8 @@ protocol_module_base::EVENT_TAG protocol_module_sessionless::handle_sorryserver_
                            : 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;
                 }