2 * @file protocol_module_ip.cpp
3 * @brief protocol module of any protocol.
4 * @brief this module never keep session persistence.
6 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
7 * Copyright (C) 2009 NTT COMWARE Corporation.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 **********************************************************************/
30 #include <boost/asio/ip/tcp.hpp>
31 #include <boost/format.hpp>
32 #include <boost/xpressive/xpressive.hpp>
33 #include "protocol_module_ip.h"
34 #include "http_utility.h"
40 const std::string protocol_module_ip::MODULE_NAME = "ip";
41 const int protocol_module_ip::THREAD_DIVISION_UP_STREAM = 0;
42 const int protocol_module_ip::THREAD_DIVISION_DOWN_STREAM = 1;
44 const int protocol_module_ip::END_FLAG_OFF = 0;
45 const int protocol_module_ip::END_FLAG_ON = 1;
47 const int protocol_module_ip::ACCEPT_END_FLAG_OFF = 0;
48 const int protocol_module_ip::ACCEPT_END_FLAG_ON = 1;
50 const int protocol_module_ip::SORRY_FLAG_ON = 1;
51 const int protocol_module_ip::SORRY_FLAG_OFF = 0;
53 const int protocol_module_ip::SWITCH_FLAG_OFF = 0;
54 const int protocol_module_ip::SWITCH_FLAG_ON = 1;
56 const int protocol_module_ip::FORWARDED_FOR_OFF = 0;
57 const int protocol_module_ip::FORWARDED_FOR_ON = 1;
59 using namespace boost::xpressive;
61 protocol_module_ip::protocol_module_ip() :
62 ip_protocol_module_base(MODULE_NAME), forwarded_for(FORWARDED_FOR_OFF)
64 sorry_uri.assign('\0');
68 protocol_module_ip::~protocol_module_ip()
71 //! tcp protocol support check
72 //! @return tcp support is true
73 //! @return tcp not-support is false
74 bool protocol_module_ip::is_tcp()
76 /*-------- DEBUG LOG --------*/
77 if (unlikely(LOG_LV_DEBUG == getloglevel()))
79 putLogDebug(600000, "in/out_function : bool protocol_module_ip::is_tcp() : return_value = true.",
82 /*------DEBUG LOG END------*/
86 //! udp protocol support check
87 //! @return udp support is true
88 //! @return udp not-support is false
89 bool protocol_module_ip::is_udp()
91 /*-------- DEBUG LOG --------*/
92 if (unlikely(LOG_LV_DEBUG == getloglevel()))
94 putLogDebug(600001, "in/out_function : bool protocol_module_ip::is_udp() : return_value = false.",
97 /*------DEBUG LOG END------*/
101 //! replication interval interrrupt
102 //! timer thread call this function. from virtualservice.
103 void protocol_module_ip::replication_interrupt()
105 /*-------- DEBUG LOG --------*/
106 if (unlikely(LOG_LV_DEBUG == getloglevel()))
108 putLogDebug(600002, "in/out_function : void protocol_module_ip::"
109 "replication_interrupt().", __FILE__, __LINE__ );
111 /*------DEBUG LOG END------*/
113 //! initialize function. called from module control. module loaded call
114 //! @param[in] realserver list iterator begin function object type
115 //! @param[in] realserver list iterator end function object type
116 //! @param[in] realserver list iterator next function object type
117 //! @param[in] realserver list mutex lock function object type.
118 //! @param[in] realserver list mutex unlock function object type
119 void protocol_module_ip::initialize(rs_list_itr_func_type inlist_begin,
120 rs_list_itr_func_type inlist_end,
121 rs_list_itr_next_func_type inlist_next,
122 boost::function< void( void ) > inlist_lock,
123 boost::function< void( void ) > inlist_unlock)
125 /*-------- DEBUG LOG --------*/
126 if (unlikely(LOG_LV_DEBUG == getloglevel()))
128 putLogDebug(600003, "in_function : void protocol_module_ip::initialize("
129 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
130 "rs_list_itr_next_func_type inlist_next, boost::function< void(void) > "
131 "inlist_lock, boost::function< void(void) > inlist_unlock).", __FILE__, __LINE__);
133 /*------DEBUG LOG END------*/
135 //RealServer list begin function
136 rs_list_begin = inlist_begin;
137 //RealServer list end function
138 rs_list_end = inlist_end;
139 //RealServer list next function
140 rs_list_next = inlist_next;
141 //RealServer list lock funtion
142 rs_list_lock = inlist_lock;
143 //RealServer list unlock funtion
144 rs_list_unlock = inlist_unlock;
146 /*-------- DEBUG LOG --------*/
147 if (unlikely(LOG_LV_DEBUG == getloglevel()))
149 putLogDebug(600004, "out_function : void protocol_module_ip::initialize("
150 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
151 "rs_list_itr_next_func_type inlist_next, boost::function< void(void) > "
152 "inlist_lock, boost::function< void(void) > inlist_unlock).", __FILE__, __LINE__);
154 /*------DEBUG LOG END------*/
157 //! finalize called from module control. module unloaded call.
158 void protocol_module_ip::finalize()
160 /*-------- DEBUG LOG --------*/
161 if (unlikely(LOG_LV_DEBUG == getloglevel()))
163 putLogDebug(600005, "in_function : void protocol_module_ip::finalize().", __FILE__, __LINE__);
165 /*------DEBUG LOG END------*/
167 //RealServer list functions initializtion
168 //RealServer list begin function
169 rs_list_begin.clear();
170 //RealServer list end function
172 //RealServer list next function
173 rs_list_next.clear();
174 //RealServer list lock function
175 rs_list_lock.clear();
176 //RealServer list unlock function
177 rs_list_unlock.clear();
179 //Replication functions initializtion
180 //component memory allcate function
181 replication_pay_memory.clear();
182 //component memory lock function
183 replication_area_lock.clear();
184 //component memory unlock function
185 replication_area_unlock.clear();
187 /*-------- DEBUG LOG --------*/
188 if (unlikely(LOG_LV_DEBUG == getloglevel()))
190 putLogDebug(600006, "function : void protocol_module_ip::finalize() : "
191 "rs_list_begin.clear(), rs_list_end.clear(), rs_list_next.clear(), "
192 "rs_list_lock.clear(), rs_list_unlock.clear() end.", __FILE__, __LINE__);
194 /*------DEBUG LOG END------*/
196 //ScheduleModule's functions initializtion
197 schedule_tcp.clear();
199 /*-------- DEBUG LOG --------*/
200 if (unlikely(LOG_LV_DEBUG == getloglevel()))
202 putLogDebug(600007, "function : void protocol_module_ip::finalize() : "
203 "schedule_tcp.clear() end.", __FILE__, __LINE__);
205 /*------DEBUG LOG END------*/
207 //Module's option initializtion
209 forwarded_for = FORWARDED_FOR_OFF;
211 sorry_uri.assign('\0');
217 // replication initialize
218 if (replication_data_processor)
220 /*-------- DEBUG LOG --------*/
221 if (unlikely(LOG_LV_DEBUG == getloglevel()))
223 boost::format formatter("delete : address = &(%d).");
224 formatter % static_cast<void*>(replication_data_processor);
225 putLogDebug(600008, formatter.str(), __FILE__, __LINE__);
227 /*------DEBUG LOG END------*/
229 delete replication_data_processor;
230 replication_data_processor = NULL;
233 // session initialize
234 if (ip_data_processor)
236 /*-------- DEBUG LOG --------*/
237 if (unlikely(LOG_LV_DEBUG == getloglevel()))
239 boost::format formatter("delete : address = &(%d).");
240 formatter % static_cast<void*>(ip_data_processor);
241 putLogDebug(600009, formatter.str(), __FILE__, __LINE__);
243 /*------DEBUG LOG END------*/
245 delete ip_data_processor;
246 ip_data_processor = NULL;
249 /*-------- DEBUG LOG --------*/
250 if (unlikely(LOG_LV_DEBUG == getloglevel()))
252 putLogDebug(600010, "out_function : void protocol_module_ip::finalize().", __FILE__, __LINE__);
254 /*------DEBUG LOG END------*/
256 //logger functions initializtion
257 //log level getting function
271 //! sorry support check
272 //! @return true sorry mode is supported.
273 //! @return false sorry mode is unsupported.
274 bool protocol_module_ip::is_use_sorry()
276 /*-------- DEBUG LOG --------*/
277 if (unlikely(LOG_LV_DEBUG == getloglevel()))
279 putLogDebug(600011, "in/out_function : bool protocol_module_ip::is_use_sorry() : return_value = true.",
282 /*------DEBUG LOG END------*/
286 //! realserver list update event
287 void protocol_module_ip::handle_rslist_update()
289 /*-------- DEBUG LOG --------*/
290 if (unlikely(LOG_LV_DEBUG == getloglevel()))
292 putLogDebug(600012, "in/out_function : void protocol_module_ip::handle_rslist_update().",
295 /*------DEBUG LOG END------*/
298 //! module parameter check.used by l7vsadm
299 //! @param[in] module paramter string list
300 //! @return result.flag true is parameter is noproblem.
301 //! @return result.flag false is paramter is problem.
302 protocol_module_base::check_message_result protocol_module_ip::check_parameter(const std::vector<
305 /*-------- DEBUG LOG --------*/
306 if (unlikely(LOG_LV_DEBUG == getloglevel()))
308 boost::format formatter("in_function : protocol_module_ip::check_message_result "
309 "protocol_module_ip::check_parameter("
310 "const std::vector<std::string>& args) : args = %s.");
311 std::string argsdump;
312 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
316 formatter % argsdump;
317 putLogDebug(600013, formatter.str(), __FILE__, __LINE__);
319 /*------DEBUG LOG END------*/
321 //set check result true
322 // set check result flag true
323 check_message_result check_result;
324 check_result.flag = true;
325 bool timeout_flag = false;
326 bool reschedule_flag = false;
327 bool no_reschedule_flag = false;
328 bool forward_checked = false;
329 bool sorryuri_checked = false;
330 sregex sorry_uri_regex
334 ( set = ';', ':', '@', '&', '=' ) |
335 ( set = '$', '-', '_', '.', '+' ) |
336 ( set = '!', '*', '\'', '\(', ')', ',' ) |
337 '%' >> repeat<2>(xdigit)));
339 typedef std::vector<std::string>::const_iterator vec_str_it;
343 vec_str_it it = args.begin();
344 vec_str_it it_end = args.end();
345 boost::format formatter;
347 //loop option strings
348 for (; it != it_end;)
350 if (*it == "-T" || *it == "--timeout")
355 // not set timeout option
357 // next parameter exist check
360 // next parameter exist
361 if ((*it).substr(0, 1) == "-" || (*it).substr(0, 2) == "--")
368 unsigned long ultimeout = 0;
369 ultimeout = boost::lexical_cast<unsigned long>(*it);
370 // int maxvalue check
371 if (ultimeout > INT_MAX)
373 check_result.flag = false;
374 formatter.parse("'-T/--timeout' option value '%s' is too large.");
376 check_result.message = formatter.str();
377 putLogError(600000, check_result.message, __FILE__, __LINE__);
387 catch (boost::bad_lexical_cast& e)
389 // not numeric character
390 check_result.flag = false;
391 formatter.parse("'-T/--timeout' option value '%s' is not numeric character.");
393 check_result.message = formatter.str();
394 putLogError(600001, check_result.message, __FILE__, __LINE__);
405 // already set timeout
406 check_result.flag = false;
407 check_result.message = "Cannot set multiple option '-T/--timeout'.";
408 putLogError(600002, check_result.message, __FILE__, __LINE__);
412 else if (*it == "-R" || *it == "--reschedule")
415 if (!no_reschedule_flag)
417 // not set no-reschedule flag
418 reschedule_flag = true;
422 // already set no-reschedule flag
423 check_result.flag = false;
424 check_result.message = "You have to choose either of reschedule or no-reschedule.";
425 putLogError(600003, check_result.message, __FILE__, __LINE__);
429 else if (*it == "-N" || *it == "--no-reschedule")
432 if (!reschedule_flag)
434 // not set reschedule flag
435 no_reschedule_flag = true;
439 // already set reshcedule flag
440 check_result.flag = false;
441 check_result.message = "You have to choose either of reschedule or no-reschedule.";
442 putLogError(600004, check_result.message, __FILE__, __LINE__);
446 //option string = "-F"
447 else if (*it == "-F" || *it == "--forwarded-for")
449 //set forward flag ON
450 forward_checked = true;
452 //option string = "-S"
453 else if (*it == "-S" || *it == "--sorry-uri")
455 //set sorryURI flag OFF
456 if (!sorryuri_checked)
461 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
463 //set check result flag false
464 check_result.flag = false;
465 //set check result message
466 check_result.message = "You have to set option value '-S/--sorry-uri'.";
467 putLogError(600005, check_result.message, __FILE__, __LINE__ );
471 //next option string's length > 127
472 if (it->size() > MAX_OPTION_SIZE - 1)
474 std::ostringstream ostr;
475 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
477 //set check result flag false
478 check_result.flag = false;
479 //set check result message
480 check_result.message = ostr.str();
481 putLogError(600006, check_result.message, __FILE__, __LINE__ );
485 //next option string's length <= 127
489 if (regex_match(*it, sorry_uri_regex ))
492 //set sorryURI flag ON
493 sorryuri_checked = true;
498 std::ostringstream ostr;
499 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
501 //set check result flag false
502 check_result.flag = false;
503 //set check result message
504 check_result.message = ostr.str();
505 putLogError(600007, check_result.message, __FILE__, __LINE__ );
510 //next item is not exist
513 //set check flag false
514 check_result.flag = false;
515 //set check result message
516 check_result.message = "You have to set option value '-S/--sorry-uri'.";
517 putLogError(600008, check_result.message, __FILE__,
526 //set check result flag false
527 check_result.flag = false;
528 //set check result message
529 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
530 putLogError(600009, check_result.message, __FILE__,
536 //other option string
539 //set check result flag false
540 check_result.flag = false;
541 //set check result message
542 check_result.message = "Option error.";
543 putLogError(600010, check_result.message, __FILE__, __LINE__ );
551 catch (const std::exception& ex)
553 check_result.flag = false;
554 std::cerr << "protocol_module_ip::check_parameter() : exception : error = " << ex.what() << "." << std::endl;
555 boost::format formatter("function : protocol_module_base::check_message_result "
556 "protocol_module_ip::check_parameter() exception : "
558 formatter % ex.what();
559 putLogError(600011, formatter.str(), __FILE__, __LINE__ );
563 check_result.flag = false;
564 std::cerr << "protocol_module_ip::check_parameter() : Unknown exception." << std::endl;
565 putLogError(600012, "function : protocol_module_base::check_message_result "
566 "protocol_module_ip::check_parameter() : "
567 "Unknown exception.", __FILE__, __LINE__ );
570 /*-------- DEBUG LOG --------*/
571 if (unlikely(LOG_LV_DEBUG == getloglevel()))
573 boost::format formatter("out_function : protocol_module_base::check_message_result "
574 "protocol_module_ip::check_parameter("
575 "const std::vector<std::string>& args) : return_value = ("
576 "check_message_result.flag = %d, check_message_result.message = %s).");
577 formatter % check_result.flag % check_result.message;
578 putLogDebug(600014, formatter.str(), __FILE__, __LINE__ );
580 /*------DEBUG LOG END------*/
586 //! @param[in] module paramter string list
587 //! @return result.flag true is parameter is noproblem.
588 //! @return result.flag false is paramter is problem.
589 protocol_module_base::check_message_result protocol_module_ip::set_parameter(const std::vector<
592 /*-------- DEBUG LOG --------*/
593 if (unlikely(LOG_LV_DEBUG == getloglevel()))
595 boost::format formatter("in_function : protocol_module_base::check_message_result "
596 "protocol_module_ip::set_parameter("
597 "const std::vector<std::string>& args) : args = %s.");
598 std::string argsdump;
599 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
604 formatter % argsdump;
605 putLogDebug(600015, formatter.str(), __FILE__, __LINE__ );
607 /*------DEBUG LOG END------*/
609 //set check result flag true
610 check_message_result check_result;
611 check_result.flag = true;
612 bool timeout_flag = false;
613 bool reschedule_flag = false;
614 bool no_reschedule_flag = false;
615 bool forward_checked = false;
616 bool sorryuri_checked = false;
617 boost::format formatter;
618 sregex sorry_uri_regex
622 ( set = ';', ':', '@', '&', '=' ) |
623 ( set = '$', '-', '_', '.', '+' ) |
624 ( set = '!', '*', '\'', '\(', ')', ',' ) |
625 '%' >> repeat<2>(xdigit)));
627 typedef std::vector<std::string>::const_iterator vec_str_it;
629 //set forwarded flag true
634 vec_str_it it = args.begin();
635 vec_str_it it_end = args.end();
637 for (; it != it_end;)
640 if (*it == "-T" || *it == "--timeout")
645 // not set timeout option
647 // next parameter exist check
650 // next parameter exist
651 if ((*it).substr(0, 1) == "-" || (*it).substr(0, 2) == "--")
658 unsigned long ultimeout = 0;
659 ultimeout = boost::lexical_cast<unsigned long>(*it);
660 // int maxvalue check
661 if (ultimeout > INT_MAX)
663 check_result.flag = false;
664 formatter.parse("'-T/--timeout' option value '%s' is too large.");
666 check_result.message = formatter.str();
667 putLogError(600013, check_result.message, __FILE__, __LINE__);
678 catch (boost::bad_lexical_cast& e)
680 // not numeric character
681 check_result.flag = false;
682 formatter.parse("'-T/--timeout' option value '%s' is not numeric character.");
684 check_result.message = formatter.str();
685 putLogError(600014, check_result.message, __FILE__, __LINE__);
696 // already set timeout
697 check_result.flag = false;
698 check_result.message = "Cannot set multiple option '-T/--timeout'.";
699 putLogError(600015, check_result.message, __FILE__, __LINE__);
704 else if (*it == "-R" || *it == "--reschedule")
707 if (!no_reschedule_flag)
709 // not set no-reschedule flag
710 reschedule_flag = true;
715 // already set no-reschedule flag
716 check_result.flag = false;
717 check_result.message = "You have to choose either of reschedule or no-reschedule.";
718 putLogError(600016, check_result.message, __FILE__, __LINE__);
722 else if (*it == "-N" || *it == "--no-reschedule")
725 if (!reschedule_flag)
727 // not set reschedule flag
728 no_reschedule_flag = true;
734 // already set reshcedule flag
735 check_result.flag = false;
736 check_result.message = "You have to choose either of reschedule or no-reschedule.";
737 putLogError(600017, check_result.message, __FILE__, __LINE__);
741 //option string = "-F"
742 else if (*it == "-F" || *it == "--forwarded-for")
744 //set forwarded flag ON
745 forward_checked = true;
746 forwarded_for = FORWARDED_FOR_ON;
748 //option string = "-S"
749 else if (*it == "-S" || *it == "--sorry-uri")
751 //sorryURI flag = OFF
752 if (!sorryuri_checked)
757 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
759 //set check result flag false
760 check_result.flag = false;
761 //set check result message
762 check_result.message = "You have to set option value '-S/--sorry-uri'.";
766 //next option string's length > 127
767 if (it->size() > MAX_OPTION_SIZE - 1)
769 std::ostringstream ostr;
770 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
772 //set check result flag false
773 check_result.flag = false;
774 //set check result message
775 check_result.message = ostr.str();
776 putLogError(600018, check_result.message, __FILE__,
781 //next option string's length <= 127
786 if (regex_match(*it, sorry_uri_regex))
788 sorryuri_checked = true;
789 memcpy(sorry_uri.data(), it->c_str(), it->size());
794 std::ostringstream ostr;
795 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
797 //set check result flag false
798 check_result.flag = false;
799 //set check result message
800 check_result.message = ostr.str();
801 putLogError(600019, check_result.message, __FILE__,
807 //next item not exist
810 //set check result flag false
811 check_result.flag = false;
812 //set check result message
813 check_result.message = "You have to set option value '-S/--sorry-uri'.";
814 putLogError(600020, check_result.message, __FILE__,
822 //set check result flag false
823 check_result.flag = false;
824 //set check result message
825 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
826 putLogError(600021, check_result.message, __FILE__,
834 //set check result flag false
835 check_result.flag = false;
836 //set check result message
837 check_result.message = "Option error.";
838 putLogError(600022, check_result.message, __FILE__, __LINE__);
846 if (check_result.flag)
848 // set timeout's default value
854 // set reschedule's default value
855 if (!reschedule_flag)
860 if (!forward_checked)
866 /*-------- DEBUG LOG --------*/
867 if (unlikely(LOG_LV_DEBUG == getloglevel()))
869 boost::format formatter("function : protocol_module_ip::check_message_result "
870 "protocol_module_ip::set_parameter(const std::vector<std::string>& args) : "
871 "timeout = %d, reschedule = %d.");
872 formatter % timeout % reschedule;
873 putLogDebug(600016, formatter.str(), __FILE__, __LINE__);
875 /*------DEBUG LOG END------*/
877 unsigned int data_size = 0;
878 void* data_addr = NULL;
879 data_addr = replication_pay_memory(get_name(), &data_size);
881 /*-------- DEBUG LOG --------*/
882 if (unlikely(LOG_LV_DEBUG == getloglevel()))
884 putLogDebug(600017, "function : protocol_module_ip::check_message_result protocol_module_ip::"
885 "set_parameter() : replication_pay_memory() end.", __FILE__, __LINE__);
886 boost::format formatter("function : protocol_module_ip::check_message_result protocol_module_ip::"
887 "set_parameter() : data_addr = &(%d), data_size = %d.");
888 formatter % data_addr % data_size;
889 putLogDebug(600018, formatter.str(), __FILE__, __LINE__);
892 /*------DEBUG LOG END------*/
893 if (data_addr == NULL || data_size <= 0)
895 // replication area is null
896 putLogError(600023, "Replication area is null.", __FILE__, __LINE__);
898 /*-------- DEBUG LOG --------*/
899 if (unlikely(LOG_LV_DEBUG == getloglevel()))
901 putLogDebug(600019, "function : protocol_module_ip::check_message_result "
902 "protocol_module_ip::set_parameter() : "
903 "Replication area is null.", __FILE__, __LINE__);
905 /*------DEBUG LOG END------*/
908 // create ip_replication_data_processor
909 replication_data_processor = new ip_replication_data_processor(
910 static_cast<char*>(data_addr),
912 virtual_service_endpoint_tcp,
920 /*-------- DEBUG LOG --------*/
921 if (unlikely(LOG_LV_DEBUG == getloglevel()))
923 boost::format formatter("new : address = &(%d), size = %lu.");
924 formatter % static_cast<void*>(replication_data_processor)
925 % sizeof(ip_replication_data_processor);
926 putLogDebug(600020, formatter.str(), __FILE__, __LINE__);
928 /*------DEBUG LOG END------*/
930 replication_data_processor->register_replication_area_lock(replication_area_lock);
932 /*-------- DEBUG LOG --------*/
933 if (unlikely(LOG_LV_DEBUG == getloglevel()))
935 putLogDebug(600021, "function : protocol_module_ip::check_message_result protocol_module_ip::"
936 "set_parameter() : register_replication_area_lock() end.", __FILE__, __LINE__);
938 /*------DEBUG LOG END------*/
940 replication_data_processor->register_replication_area_unlock(replication_area_unlock);
942 /*-------- DEBUG LOG --------*/
943 if (unlikely(LOG_LV_DEBUG == getloglevel()))
945 putLogDebug(600022, "function : protocol_module_ip::check_message_result protocol_module_ip::"
946 "set_parameter() : register_replication_area_unlock() end.", __FILE__, __LINE__);
948 /*------DEBUG LOG END------*/
950 // create ip_session_data_processor
951 ip_data_processor = new ip_session_data_processor(
953 replication_data_processor,
961 /*-------- DEBUG LOG --------*/
962 if (unlikely(LOG_LV_DEBUG == getloglevel()))
964 boost::format formatter("new : address = &(%d), size = %lu.");
965 formatter % static_cast<void*>(ip_data_processor)
966 % sizeof(ip_session_data_processor);
967 putLogDebug(600023, formatter.str(), __FILE__, __LINE__);
969 /*------DEBUG LOG END------*/
971 // restore data from replication area
972 ip_replication_data* redata = replication_data_processor->get_replication_area();
974 /*-------- DEBUG LOG --------*/
975 if (unlikely(LOG_LV_DEBUG == getloglevel()))
977 putLogDebug(600024, "function : protocol_module_ip::check_message_result protocol_module_ip::"
978 "set_parameter() : get_replication_area() end.", __FILE__, __LINE__);
980 /*------DEBUG LOG END------*/
982 replication_area_lock();
984 /*-------- DEBUG LOG --------*/
985 if (unlikely(LOG_LV_DEBUG == getloglevel()))
987 putLogDebug(600025, "function : protocol_module_ip::check_message_result protocol_module_ip::"
988 "set_parameter() : replication_area_lock() end.", __FILE__, __LINE__);
990 /*------DEBUG LOG END------*/
992 ip_data_processor->read_session_data_from_replication_area(redata);
994 /*-------- DEBUG LOG --------*/
995 if (unlikely(LOG_LV_DEBUG == getloglevel()))
997 putLogDebug(600026, "function : protocol_module_ip::check_message_result protocol_module_ip::"
998 "set_parameter() : read_session_data_from_replication_area() end.", __FILE__, __LINE__);
1000 /*------DEBUG LOG END------*/
1002 replication_area_unlock();
1004 /*-------- DEBUG LOG --------*/
1005 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1007 putLogDebug(600027, "function : protocol_module_ip::check_message_result protocol_module_ip::"
1008 "set_parameter() : replication_area_unlock() end.", __FILE__, __LINE__);
1010 /*------DEBUG LOG END------*/
1013 catch (const std::bad_alloc& ba)
1015 if (replication_data_processor)
1017 delete replication_data_processor;
1018 replication_data_processor = NULL;
1021 if (ip_data_processor)
1023 delete ip_data_processor;
1024 ip_data_processor = NULL;
1027 std::cerr << "protocol_module_ip::set_parameter() : exception : Could not allocate memory." << std::endl;
1028 check_result.flag = false;
1029 check_result.message = "Could not allocate memory.";
1030 putLogError(600024, check_result.message, __FILE__, __LINE__);
1032 catch (const std::exception& ex)
1034 if (replication_data_processor)
1036 delete replication_data_processor;
1037 replication_data_processor = NULL;
1040 if (ip_data_processor)
1042 delete ip_data_processor;
1043 ip_data_processor = NULL;
1046 check_result.flag = false;
1047 std::cerr << "protocol_module_ip::set_parameter() : exception : error = " << ex.what() << std::endl;
1048 boost::format formatter("function : protocol_module_ip::check_message_result "
1049 "protocol_module_ip::set_parameter() : exception : error = %s.");
1050 formatter % ex.what();
1051 putLogError(600025, formatter.str(), __FILE__, __LINE__);
1055 if (replication_data_processor)
1057 delete replication_data_processor;
1058 replication_data_processor = NULL;
1061 if (ip_data_processor)
1063 delete ip_data_processor;
1064 ip_data_processor = NULL;
1067 check_result.flag = false;
1068 std::cerr << "protocol_module_ip::set_parameter() : Unknown exception." << std::endl;
1069 putLogError(600026, "function : protocol_module_ip::check_message_result protocol_module_ip::"
1070 "set_parameter() : Unknown exception.", __FILE__, __LINE__);
1072 /*-------- DEBUG LOG --------*/
1073 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1075 boost::format formatter("out_function : protocol_module_ip::check_message_result "
1076 "protocol_module_ip::set_parameter("
1077 "const std::vector<std::string>& args) : return_value = ("
1078 "check_message_result.flag = %d, check_message_result.message = %s).");
1079 formatter % check_result.flag % check_result.message;
1080 putLogDebug(600028, formatter.str(), __FILE__, __LINE__);
1082 /*------DEBUG LOG END------*/
1083 return check_result;
1087 //! @param[in] module paramter string list
1088 //! @return result.flag true is parameter is noproblem.
1089 //! @return result.flag false is paramter is problem.
1090 protocol_module_base::check_message_result protocol_module_ip::add_parameter(const std::vector<
1093 /*-------- DEBUG LOG --------*/
1094 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1096 boost::format formatter("in_function : protocol_module_ip::check_message_result protocol_module_ip::"
1097 "add_parameter(const std::vector<std::string>& args) : args = %s.");
1098 std::string argsdump;
1099 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
1103 formatter % argsdump;
1104 putLogDebug(600029, formatter.str(), __FILE__, __LINE__);
1106 /*------DEBUG LOG END------*/
1107 check_message_result check_result;
1108 //set check result flag true
1109 check_result.flag = true;
1111 //param list is not empty
1114 //set check result flag false
1115 check_result.flag = false;
1116 //set check result message
1117 check_result.message = "Cannot add option.";
1118 putLogError(600027, check_result.message, __FILE__, __LINE__ );
1121 /*-------- DEBUG LOG --------*/
1122 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1124 boost::format formatter("out_function : protocol_module_ip::check_message_result "
1125 "protocol_module_ip::add_parameter(const std::vector<std::string>& args) : "
1126 "return_value = (check_message_result.flag = %d, check_message_result.message = %s).");
1127 formatter % check_result.flag % check_result.message;
1128 putLogDebug(600030, formatter.str(), __FILE__, __LINE__);
1130 /*------DEBUG LOG END------*/
1131 return check_result;
1135 //! @param[out] module paramter string
1136 void protocol_module_ip::get_option_info(std::string& option)
1138 /*-------- DEBUG LOG --------*/
1139 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1141 putLogDebug(300031, "in_function : void protocol_module_ip::get_option_info("
1142 "std::string& option).", __FILE__, __LINE__);
1144 /*------DEBUG LOG END------*/
1146 boost::format option_formatter("--timeout %d%s %s --sorry-uri '%s'");
1147 option_formatter % timeout % (forwarded_for ? " --forwarded-for" : "") % (reschedule ? "--reschedule" : "--no-reschedule") % sorry_uri.c_array();
1148 option.assign(option_formatter.str());
1150 /*-------- DEBUG LOG --------*/
1151 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1153 boost::format formatter("out_function : void protocol_module_ip::get_option_info("
1154 "std::string& option) : option = %s.");
1156 putLogDebug(300039, formatter.str(), __FILE__, __LINE__);
1158 /*------DEBUG LOG END------*/
1161 //! TCP/IP scheduled function registation.
1162 //! @param[in] schedule module TCP/IP scheduled function object type
1163 void protocol_module_ip::register_schedule(tcp_schedule_func_type inschedule)
1165 /*-------- DEBUG LOG --------*/
1166 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1168 putLogDebug(600031, "in_function : void protocol_module_ip::register_schedule("
1169 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__);
1171 /*------DEBUG LOG END------*/
1172 schedule_tcp = inschedule;
1173 /*-------- DEBUG LOG --------*/
1174 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1176 putLogDebug(600032, "out_function : void protocol_module_ip::register_schedule("
1177 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__);
1179 /*------DEBUG LOG END------*/
1182 //! UDP scheduled function registation
1183 //! @param[in] schedule module UDP scheduled funtion object type
1184 void protocol_module_ip::register_schedule(udp_schedule_func_type inschedule)
1186 /*-------- DEBUG LOG --------*/
1187 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1189 putLogDebug(600033, "in/out_function : void protocol_module_ip::register_schedule("
1190 "udp_schedule_func_type inschedule).", __FILE__, __LINE__);
1192 /*------DEBUG LOG END------*/
1195 //! called from session initialzie use in upstream_thread
1196 //! @param[in] upstream thread id.
1197 //! @param[in] downstream thread id
1198 //! @return session use EVENT mode.
1199 protocol_module_base::EVENT_TAG protocol_module_ip::handle_session_initialize(
1200 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id,
1201 const boost::asio::ip::tcp::endpoint& client_endpoint_tcp,
1202 const boost::asio::ip::udp::endpoint& client_endpoint_udp)
1204 /*-------- DEBUG LOG --------*/
1205 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1207 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1208 "handle_session_initialize(const boost::thread::id up_thread_id, "
1209 "const boost::thread::id down_thread_id, "
1210 "const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
1211 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : "
1212 "up_thread_id = %d, down_thread_id = %d.");
1213 formatter % up_thread_id % down_thread_id;
1214 putLogDebug(600034, formatter.str(), __FILE__, __LINE__);
1216 /*------DEBUG LOG END------*/
1218 EVENT_TAG status = FINALIZE;
1219 unsigned int ip_hash = 0;
1221 //session thread initialization
1224 thread_data_ptr p_up(new session_thread_data_ip);
1225 /*-------- DEBUG LOG --------*/
1226 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1228 boost::format formatter("new : address = &(%d), size = %lu.");
1229 formatter % static_cast<void*>(p_up.get()) % sizeof(session_thread_data_ip);
1230 putLogDebug(600035, formatter.str(), __FILE__, __LINE__);
1232 /*------DEBUG LOG END------*/
1234 //calculate ip address's hash
1235 ip_hash = l7vs_ip_service_calc_hash(client_endpoint_tcp);
1237 p_up->thread_id = up_thread_id;
1238 p_up->thread_division = THREAD_DIVISION_UP_STREAM;
1239 p_up->pair_thread_id = down_thread_id;
1240 p_up->accept_end_flag = ACCEPT_END_FLAG_OFF;
1241 p_up->end_flag = END_FLAG_OFF;
1242 p_up->sorry_flag = SORRY_FLAG_OFF;
1243 p_up->switch_flag = SWITCH_FLAG_OFF;
1244 p_up->last_status = INITIALIZE;
1245 p_up->client_endpoint = client_endpoint_tcp;
1246 p_up->data_buffer = new char[MAX_BUFFER_SIZE];
1247 p_up->data_buffer_size = MAX_BUFFER_SIZE;
1248 p_up->data_length = 0;
1249 p_up->data_offset = 0;
1250 p_up->current_message_rest_size = 0;
1251 p_up->data_state = HTTP_START;
1252 p_up->ip_hash = ip_hash;
1254 /*-------- DEBUG LOG --------*/
1255 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1258 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1259 "handle_session_initialize() : session_thread_data_ip(upthread) : "
1260 "thread_id = %d, thread_division = %d, "
1261 "pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
1262 "sorry_flag = %d, switch_flag = %d, last_status = %d, client_endpoint = [%s]:%d, data_buffer = &(%d), "
1263 "data_buffer_size = %d, data_length = %d, data_offset = %d, current_message_rest_size = %d, data_state = %d, "
1265 formatter % p_up->thread_id
1266 % p_up->thread_division
1267 % p_up->pair_thread_id
1268 % p_up->accept_end_flag
1273 % p_up->client_endpoint.address().to_string()
1274 % p_up->client_endpoint.port()
1276 % p_up->data_buffer_size
1279 % p_up->current_message_rest_size
1284 putLogDebug(600036, formatter.str(), __FILE__, __LINE__);
1286 /*------DEBUG LOG END------*/
1288 thread_data_ptr p_down(new session_thread_data_ip);
1290 /*-------- DEBUG LOG --------*/
1291 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1293 boost::format formatter("new : address = &(%d), size = %lu.");
1294 formatter % static_cast<void*>(p_down.get()) % sizeof(session_thread_data_ip);
1295 putLogDebug(600037, formatter.str(), __FILE__, __LINE__);
1297 /*------DEBUG LOG END------*/
1299 p_down->thread_id = down_thread_id;
1300 p_down->thread_division = THREAD_DIVISION_DOWN_STREAM;
1301 p_down->pair_thread_id = up_thread_id;
1302 p_down->accept_end_flag = ACCEPT_END_FLAG_OFF;
1303 p_down->end_flag = END_FLAG_OFF;
1304 p_down->sorry_flag = SORRY_FLAG_OFF;
1305 p_down->switch_flag = SWITCH_FLAG_OFF;
1306 p_down->last_status = INITIALIZE;
1307 p_down->client_endpoint = client_endpoint_tcp;
1308 p_down->data_buffer = new char[MAX_BUFFER_SIZE];
1309 p_down->data_buffer_size = MAX_BUFFER_SIZE;
1310 p_down->data_length = 0;
1311 p_down->data_offset = 0;
1312 p_down->current_message_rest_size = 0;
1313 p_down->data_state = HTTP_START;
1314 p_down->ip_hash = ip_hash;
1316 /*-------- DEBUG LOG --------*/
1317 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1320 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1321 "handle_session_initialize() : session_thread_data_ip(downthread) : "
1322 "thread_id = %d, thread_division = %d, "
1323 "pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
1324 "sorry_flag = %d, switch_flag = %d, last_status = %d, client_endpoint = [%s]:%d, data_buffer = &(%d), "
1325 "data_buffer_size = %d, data_length = %d, data_offset = %d, current_message_rest_size = %d, data_state = %d, "
1327 formatter % p_down->thread_id
1328 % p_down->thread_division
1329 % p_down->pair_thread_id
1330 % p_down->accept_end_flag
1332 % p_down->sorry_flag
1333 % p_down->switch_flag
1334 % p_down->last_status
1335 % p_down->client_endpoint.address().to_string()
1336 % p_down->client_endpoint.port()
1337 % p_down->data_buffer
1338 % p_down->data_buffer_size
1339 % p_down->data_length
1340 % p_down->data_offset
1341 % p_down->current_message_rest_size
1342 % p_down->data_state
1344 putLogDebug(600038, formatter.str(), __FILE__, __LINE__);
1346 /*------DEBUG LOG END------*/
1349 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1351 session_thread_data_map[up_thread_id] = p_up;
1352 session_thread_data_map[down_thread_id] = p_down;
1357 session_thread_data_map[up_thread_id]->last_status = status;
1358 session_thread_data_map[down_thread_id]->last_status = REALSERVER_RECV;
1360 catch (const std::bad_alloc&)
1362 std::cerr << "protocol_module_ip::handle_session_initialize() : exception : Could not allocate memory." << std::endl;
1363 boost::format formatter("Could not allocate memory. thread id : %d.");
1364 formatter % boost::this_thread::get_id();
1365 putLogError(600028, formatter.str(), __FILE__, __LINE__);
1368 catch (const std::exception& ex)
1370 std::cerr << "protocol_module_ip::handle_session_initialize() : exception : error = " << ex.what() << "." << std::endl;
1371 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1372 "handle_session_initialize() : exception : error = %s. thread id : %d.");
1373 formatter % ex.what() % boost::this_thread::get_id();
1374 putLogError(600029, formatter.str(), __FILE__, __LINE__);
1379 std::cerr << "protocol_module_ip::handle_session_initialize() : Unknown exception." << std::endl;
1380 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1381 "handle_session_initialize() : Unknown exception. thread id : %d.");
1382 formatter % boost::this_thread::get_id();
1383 putLogError(600030, formatter.str(), __FILE__, __LINE__);
1387 /*-------- DEBUG LOG --------*/
1388 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1390 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1391 "handle_session_initialize(const boost::thread::id up_thread_id, "
1392 "const boost::thread::id down_thread_id, "
1393 "const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
1394 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : return_value = %d. "
1396 formatter % status % boost::this_thread::get_id();
1397 putLogDebug(600039, formatter.str(), __FILE__, __LINE__);
1399 /*------DEBUG LOG END------*/
1403 //! called from session finalize use in upstream thread.
1404 //! @param[in] upstream thread id.
1405 //! @param[in] downstream thread id
1406 //! @return session use EVENT mode.
1407 protocol_module_base::EVENT_TAG protocol_module_ip::handle_session_finalize(
1408 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id)
1410 /*-------- DEBUG LOG --------*/
1411 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1413 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1414 "handle_session_finalize(const boost::thread::id up_thread_id, "
1415 "const boost::thread::id down_thread_id) : "
1416 "up_thread_id = %d, down_thread_id = %d.");
1417 formatter % up_thread_id % down_thread_id;
1418 putLogDebug(600040, formatter.str(), __FILE__, __LINE__);
1420 /*------DEBUG LOG END------*/
1421 EVENT_TAG status = STOP;
1422 thread_data_ptr p_up;
1423 thread_data_ptr p_down;
1424 session_thread_data_map_it session_thread_data_it;
1426 //session thread free
1429 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1431 session_thread_data_it = session_thread_data_map.find(up_thread_id);
1432 if (session_thread_data_it != session_thread_data_map.end())
1434 p_up = session_thread_data_it->second;
1435 /*-------- DEBUG LOG --------*/
1436 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1438 boost::format formatter("delete : address = &(%d).");
1439 formatter % static_cast<void*>(p_up->data_buffer);
1440 putLogDebug(600041, formatter.str(), __FILE__, __LINE__);
1442 /*------DEBUG LOG END------*/
1444 delete p_up->data_buffer;
1445 /*-------- DEBUG LOG --------*/
1446 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1448 boost::format formatter("delete : address = &(%d).");
1449 formatter % static_cast<void*>(p_up.get());
1450 putLogDebug(600042, formatter.str(), __FILE__, __LINE__);
1452 /*------DEBUG LOG END------*/
1454 session_thread_data_map.erase(up_thread_id);
1457 session_thread_data_it = session_thread_data_map.find(down_thread_id);
1458 if (session_thread_data_it != session_thread_data_map.end())
1461 p_down = session_thread_data_it->second;
1462 /*-------- DEBUG LOG --------*/
1463 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1465 boost::format formatter("delete : address = &(%d).");
1466 formatter % static_cast<void*>(p_up->data_buffer);
1467 putLogDebug(600043, formatter.str(), __FILE__, __LINE__);
1469 /*------DEBUG LOG END------*/
1471 delete p_down->data_buffer;
1472 /*-------- DEBUG LOG --------*/
1473 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1475 boost::format formatter("delete : address = &(%d).");
1476 formatter % static_cast<void*>(p_down.get());
1477 putLogDebug(600044, formatter.str(), __FILE__, __LINE__);
1479 /*------DEBUG LOG END------*/
1481 session_thread_data_map.erase(down_thread_id);
1487 catch (const std::exception& ex)
1489 std::cerr << "protocol_module_ip::handle_session_finalize() : exception : error = " << ex.what() << "." << std::endl;
1490 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1491 "handle_session_finalize() : exception : error = %s. thread id : %d.");
1492 formatter % ex.what() % boost::this_thread::get_id();
1493 putLogError(600031, formatter.str(), __FILE__, __LINE__ );
1498 std::cerr << "protocol_module_ip::handle_session_finalize() : Unknown exception." << std::endl;
1499 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1500 "handle_session_finalize() : "
1501 "Unknown exception. thread id : %d.");
1502 formatter % boost::this_thread::get_id();
1503 putLogError(600032, formatter.str(), __FILE__, __LINE__ );
1506 /*-------- DEBUG LOG --------*/
1507 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1509 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1510 "handle_session_finalize(const boost::thread::id up_thread_id, "
1511 "const boost::thread::id down_thread_id) : return_value = %d. thread id : %d.");
1512 formatter % status % boost::this_thread::get_id();
1513 putLogDebug(600045, formatter.str(), __FILE__, __LINE__ );
1515 /*------DEBUG LOG END------*/
1519 //! called from after session accept.in client socket use in upstream thread.
1520 //! @param[in] upstream thread id.
1521 //! @return session use EVENT mode.
1522 protocol_module_base::EVENT_TAG protocol_module_ip::handle_accept(const boost::thread::id thread_id)
1524 /*-------- DEBUG LOG --------*/
1525 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1527 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1528 "handle_accept(const boost::thread::id thread_id) : thread_id = %d.");
1529 formatter % thread_id;
1530 putLogDebug(600046, formatter.str(), __FILE__, __LINE__ );
1532 /*------DEBUG LOG END------*/
1534 EVENT_TAG status = FINALIZE;
1535 thread_data_ptr session_data_ptr;
1536 session_thread_data_map_it session_thread_it;
1541 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1543 session_thread_it = session_thread_data_map.find(thread_id);
1544 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1546 boost::format formatter("Invalid thread id. thread id : %d.");
1547 formatter % boost::this_thread::get_id();
1548 putLogError(600033, formatter.str(), __FILE__, __LINE__ );
1552 session_data_ptr = session_thread_it->second;
1555 //set accept end flag ON
1556 session_data_ptr->accept_end_flag = ACCEPT_END_FLAG_ON;
1558 /*-------- DEBUG LOG --------*/
1559 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1561 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1562 "handle_accept(const boost::thread::id thread_id) : ACCEPT_END_FLAG_ON. thread id : %d.");
1563 formatter % boost::this_thread::get_id();
1564 putLogDebug(600047, formatter.str(), __FILE__, __LINE__ );
1566 /*------DEBUG LOG END------*/
1569 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
1572 status = SORRYSERVER_SELECT;
1578 status = REALSERVER_SELECT;
1582 session_data_ptr->last_status = status;
1586 /*-------- DEBUG LOG --------*/
1587 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1589 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1590 "handle_accept() : catch exception e = %d. thread id : %d.");
1591 formatter % e % boost::this_thread::get_id();
1592 putLogDebug(600048, formatter.str(), __FILE__, __LINE__ );
1594 /*------DEBUG LOG END------*/
1597 catch (const std::exception& ex)
1599 std::cerr << "protocol_module_ip::handle_accept() : exception : error = " << ex.what() << "." << std::endl;
1600 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1601 "handle_accept() : exception : error = %s. thread id : %d.");
1602 formatter % ex.what() % boost::this_thread::get_id();
1603 putLogError(600034, formatter.str(), __FILE__, __LINE__ );
1608 std::cerr << "protocol_module_ip::handle_accept() : Unknown exception." << std::endl;
1609 boost::format formatter("function : protocol_module_base::EVENT_TAG "
1610 "protocol_module_ip::handle_accept() : "
1611 "Unknown exception. thread id : %d.");
1612 formatter % boost::this_thread::get_id();
1613 putLogError(600035, formatter.str(), __FILE__, __LINE__ );
1617 /*-------- DEBUG LOG --------*/
1618 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1620 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1621 "handle_accept(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
1622 formatter % status % boost::this_thread::get_id();
1623 putLogDebug(600049, formatter.str(), __FILE__, __LINE__ );
1625 /*------DEBUG LOG END------*/
1630 //! called from after session recv in client socket. use in upstream thread.
1631 //! @param[in] upstream thread id
1632 //! @param[in] recive buffer refarence.
1633 //! @param[in] recive length
1634 //! @return session use EVENT mode.
1635 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_recv(const boost::thread::id thread_id,
1636 const boost::array<char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
1639 /*-------- DEBUG LOG --------*/
1640 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1642 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
1644 dump_memory(recvbuffer.data(), buffer_size, buffer);
1645 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1646 "handle_client_recv(const boost::thread::id thread_id, "
1647 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1648 "const size_t recvlen) : thread_id = %d, recvbuffer = %s, recvlen = %d.");
1649 formatter % thread_id % buffer % recvlen;
1650 putLogDebug(600050, formatter.str(), __FILE__, __LINE__ );
1652 /*------DEBUG LOG END------*/
1654 EVENT_TAG status = FINALIZE;
1655 bool find_ret = false;
1656 size_t http_header_offset = 0;
1657 size_t http_header_len = 0;
1658 size_t http_header_content_length_offset = 0;
1659 size_t http_header_content_length_len = 0;
1660 int content_length_value = 0;
1661 const size_t CR_LF_LEN = 2; //length of "\r\n"
1662 const size_t CR_LF_CR_LF_LEN = 4; //length of "\r\n\r\n"
1663 session_thread_data_map_it session_thread_it;
1664 thread_data_ptr session_data_ptr;
1665 http_utility::CHECK_RESULT_TAG check_ret;
1667 std::string content_length;
1669 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
1672 if (unlikely(recvlen > recvbuffer.size()))
1674 std::cerr << "protocol_module_ip::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1675 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
1676 formatter % boost::this_thread::get_id();
1677 putLogError(600036, formatter.str(), __FILE__, __LINE__ );
1679 /*-------- DEBUG LOG --------*/
1680 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1682 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1683 "handle_client_recv(const boost::thread::id thread_id, "
1684 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1685 "const size_t recvlen) : return_value = %d. thread id : %d.");
1686 formatter % FINALIZE % boost::this_thread::get_id();
1687 putLogDebug(600051, formatter.str(), __FILE__, __LINE__ );
1689 /*------DEBUG LOG END------*/
1696 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1698 session_thread_it = session_thread_data_map.find(thread_id);
1699 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1702 boost::format formatter("Invalid thread id. thread id : %d.");
1703 formatter % boost::this_thread::get_id();
1704 putLogError(600037, formatter.str(), __FILE__, __LINE__ );
1708 session_data_ptr = session_thread_it->second;
1712 if (session_data_ptr->end_flag == END_FLAG_ON)
1715 status = CLIENT_RECV;
1720 //copy data from recvbuffer
1721 if (!get_data_from_recvbuffer(session_data_ptr, recvbuffer, recvlen))
1724 std::cerr << "protocol_module_ip::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1725 boost::format formatter("Data size bigger than buffer size. thread id : % id.");
1726 formatter % boost::this_thread::get_id();
1727 putLogError(600038, formatter.str(), __FILE__, __LINE__);
1732 //data state is HTTP_START
1733 if (session_data_ptr->data_state == HTTP_START)
1735 //search http header
1736 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
1737 session_data_ptr->data_length,
1742 /*-------- DEBUG LOG --------*/
1743 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1745 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1746 "handle_client_recv() : call find_http_header_all : "
1747 "return_value = %d. thread id : %d.");
1748 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
1749 putLogDebug(600052, formatter.str(), __FILE__, __LINE__ );
1751 /*------DEBUG LOG END------*/
1753 //search http header result is NG
1756 //data size bigger than max buffer size
1757 if (session_data_ptr->data_length >= MAX_IP_MODULE_BUFFER_SIZE - recvbuffer.size())
1759 //set data state UNKNOWN
1760 session_data_ptr->data_state = UNKNOWN;
1761 //set current message rest size
1762 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
1765 //search http header result is OK
1768 //check http method and version
1769 check_ret = http_utility::check_http_method_and_version(session_data_ptr->data_buffer,
1770 session_data_ptr->data_length);
1771 /*-------- DEBUG LOG --------*/
1772 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1774 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1775 "handle_client_recv() : call check_http_method_and_version : "
1776 "return_value = %d. thread id : %d.");
1777 formatter % check_ret % boost::this_thread::get_id();
1778 putLogDebug(600053, formatter.str(), __FILE__, __LINE__ );
1780 /*------DEBUG LOG END------*/
1782 //check http method and version result is NG
1783 if (check_ret == http_utility::CHECK_NG)
1785 //set data state UNKNOWN
1786 session_data_ptr->data_state = UNKNOWN;
1787 //set current message rest size
1788 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
1790 //check http method and version result is OK
1793 //search Content_Length header
1794 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
1795 session_data_ptr->data_length,
1796 http_header_content_length_offset,
1797 http_header_content_length_len);
1798 /*-------- DEBUG LOG --------*/
1799 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1801 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1802 "handle_client_recv() : call find_http_header_content_length : "
1803 "return_value = %d. thread id : %d.");
1804 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
1805 putLogDebug(600054, formatter.str(), __FILE__, __LINE__ );
1807 /*------DEBUG LOG END------*/
1809 //search Content_Length result is OK
1812 //set content length string
1813 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
1814 http_header_content_length_len );
1815 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
1817 //"content-length: ddd\r\n"
1820 content_length = content_length.substr(
1821 regex_ret.position(1),
1822 regex_ret.length(1));
1824 //set content length value
1825 content_length_value = boost::lexical_cast<int>(content_length);
1828 //http_header context is "\r\n\r\n" only
1829 if (http_header_len == 0)
1831 //set current message rest size
1832 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_LEN;
1836 //set current message rest size
1837 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_CR_LF_LEN;
1840 //search Content_Length result is NG
1843 //http_header context is "\r\n\r\n" only
1844 if (http_header_len == 0)
1846 //set current message rest size
1847 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_LEN;
1851 //set current message rest size
1852 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_CR_LF_LEN;
1857 //set data state HTTP_HEADER
1858 session_data_ptr->data_state = HTTP_HEADER;
1863 //data state is UNKNOWN
1864 else if (session_data_ptr->data_state == UNKNOWN)
1866 //set current message rest size
1867 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
1874 //data state is HTTP_START
1875 if (session_data_ptr->data_state == HTTP_START )
1877 status = CLIENT_RECV;
1879 //data state is not HTTP_START
1883 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
1886 status = SORRYSERVER_CONNECT;
1892 status = REALSERVER_CONNECT;
1899 session_data_ptr->last_status = status;
1903 /*-------- DEBUG LOG --------*/
1904 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1906 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1907 "handle_client_recv() : catch exception e = %d. thread id : %d.");
1908 formatter % e % boost::this_thread::get_id();
1909 putLogDebug(600055, formatter.str(), __FILE__, __LINE__ );
1911 /*------DEBUG LOG END------*/
1914 catch (const boost::bad_lexical_cast& )
1916 std::cerr << "protocol_module_ip::handle_client_recv() : exception : " << "Content_Length field's value is invalid." << std::endl;
1917 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_recv() : "
1918 "Content_Length field's value is invalid. thread id : %d.");
1919 formatter % boost::this_thread::get_id();
1920 putLogError(600039, formatter.str(), __FILE__, __LINE__ );
1923 catch (const std::exception& ex)
1925 std::cerr << "protocol_module_ip::handle_client_recv() : exception : error = " << ex.what() << "." << std::endl;
1926 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1927 "handle_client_recv() : exception : error = %s. thread id : %d.");
1928 formatter % ex.what() % boost::this_thread::get_id();
1929 putLogError(600040, formatter.str(), __FILE__, __LINE__ );
1934 std::cerr << "protocol_module_ip::handle_client_recv() : Unknown exception." << std::endl;
1935 boost::format formatter("function : protocol_module_base::EVENT_TAG "
1936 "protocol_module_ip::handle_client_recv() : "
1937 "Unknown exception. thread id : %d.");
1938 formatter % boost::this_thread::get_id();
1939 putLogError(600041, formatter.str(), __FILE__, __LINE__ );
1943 /*-------- DEBUG LOG --------*/
1944 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1946 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1947 "handle_client_recv(const boost::thread::id thread_id, "
1948 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1949 "const size_t recvlen) : return_value = %d. thread id : %d.");
1950 formatter % status % boost::this_thread::get_id();
1951 putLogDebug(600056, formatter.str(), __FILE__, __LINE__ );
1953 /*------DEBUG LOG END------*/
1958 //! called from after realserver select.use in upstream thread.
1959 //! @param[in] upstream thread id
1960 //! @param[out] realserver TCP endpoint
1961 //! @return session use EVENT mode.
1962 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_select(
1963 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint & rs_endpoint)
1966 /*-------- DEBUG LOG --------*/
1967 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1969 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1970 "handle_realserver_select(const boost::thread::id thread_id, "
1971 "boost::asio::ip::tcp::endpoint& rs_endpoint) : "
1972 "thread_id = %d, rs_endpoint = [%s]:%d.");
1973 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
1974 putLogDebug(600057, formatter.str(), __FILE__, __LINE__ );
1976 /*------DEBUG LOG END------*/
1978 EVENT_TAG status = FINALIZE;
1979 boost::asio::ip::tcp::endpoint init_endpoint;
1980 thread_data_ptr session_data_ptr;
1981 session_thread_data_map_it session_thread_it;
1982 session_thread_data_map_it session_thread_it_end;
1983 realserverlist_type::iterator rs_list_itr;
1985 if (unlikely(schedule_tcp.empty()))
1987 std::cerr << "protocol_module_ip::handle_realserver_select() : Schedule_tcp function is empty." << std::endl;
1988 boost::format formatter("Schedule_tcp function is empty. thread id : %d.");
1989 formatter % boost::this_thread::get_id();
1990 putLogError(600042, formatter.str(), __FILE__, __LINE__ );
1992 /*-------- DEBUG LOG --------*/
1993 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1995 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1996 "handle_realserver_select(const boost::thread::id thread_id, "
1997 "boost::asio::ip::tcp::endpoint& rs_endpoint)"
1998 " : return_value = %d. thread id : %d.");
1999 formatter % FINALIZE % boost::this_thread::get_id();
2000 putLogDebug(600058, formatter.str(), __FILE__, __LINE__ );
2002 /*------DEBUG LOG END------*/
2010 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2012 session_thread_it = session_thread_data_map.find(thread_id);
2013 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2015 boost::format formatter("Invalid thread id. thread id : %d.");
2016 formatter % boost::this_thread::get_id();
2017 putLogError(600043, formatter.str(), __FILE__, __LINE__ );
2021 session_data_ptr = session_thread_it->second;
2024 //initialize realserver endpoint
2025 rs_endpoint = init_endpoint;
2027 boost::mutex::scoped_lock lock(session_data_mutex);
2029 //get endpoint data from the ip data
2030 int ret = ip_data_processor->get_endpoint_from_session_data(session_data_ptr->ip_hash,
2033 /*-------- DEBUG LOG --------*/
2034 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2036 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2037 "protocol_module_ip::handle_realserver_select() : "
2038 "get_endpoint_from_session_data() end. thread id : %d.");
2039 formatter % boost::this_thread::get_id();
2040 putLogDebug(600059, formatter.str(), __FILE__, __LINE__);
2042 /*------DEBUG LOG END------*/
2044 //endpoint is matched
2047 //find the rs_endpoint in rs_list
2050 rs_list_itr = rs_list_begin();
2053 while ( rs_list_itr != rs_list_end())
2056 if ( rs_list_itr->tcp_endpoint == rs_endpoint )
2062 rs_list_itr = rs_list_next( rs_list_itr );
2067 //endpoint is matched in the list
2070 //data state is HTTP_START
2071 if (session_data_ptr->data_state == HTTP_START)
2074 status = CLIENT_RECV;
2076 //data state is not HTTP_START
2080 status = REALSERVER_CONNECT;
2083 //endpoint is not matched in the list
2086 //if reschedule is on then try multi times connect
2087 if (reschedule == 1)
2090 rs_endpoint = init_endpoint;
2092 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2093 /*-------- DEBUG LOG --------*/
2094 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2096 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2097 "handle_realserver_select() : call schedule_tcp : "
2098 "rs_endpoint = [%s]:%d. thread id : %d.");
2099 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2100 putLogDebug(600060, formatter.str(), __FILE__, __LINE__ );
2102 /*------DEBUG LOG END------*/
2104 //get the endpoint by schedule successfully
2105 if (init_endpoint != rs_endpoint)
2107 time_t init_time = 0;
2109 //write data to session table
2110 ip_data_processor->write_session_data(session_data_ptr->ip_hash, rs_endpoint, init_time);
2111 /*-------- DEBUG LOG --------*/
2112 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2114 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2115 "protocol_module_ip::handle_realserver_select() : "
2116 "write_session_data() end. thread id : %d.");
2117 formatter % boost::this_thread::get_id();
2118 putLogDebug(600061, formatter.str(), __FILE__, __LINE__);
2120 /*------DEBUG LOG END------*/
2122 //data state is HTTP_START
2123 if (session_data_ptr->data_state == HTTP_START)
2126 status = CLIENT_RECV;
2128 //data state is not HTTP_START
2132 status = REALSERVER_CONNECT;
2135 //get the endpoint by schedule unsuccessfully
2139 status = CLIENT_DISCONNECT;
2146 status = CLIENT_DISCONNECT;
2150 //endpoint is not matched
2154 rs_endpoint = init_endpoint;
2156 //call schedule_module's schedule function, get realserver endpoint
2157 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2159 /*-------- DEBUG LOG --------*/
2160 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2162 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2163 "handle_realserver_select() : call schedule_tcp : "
2164 "rs_endpoint = [%s]:%d. thread id : %d.");
2165 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2166 putLogDebug(600062, formatter.str(), __FILE__, __LINE__ );
2168 /*------DEBUG LOG END------*/
2170 //get the endpoint by schedule successfully
2171 if (init_endpoint != rs_endpoint)
2173 time_t init_time = 0;
2175 //write data to session table
2176 ip_data_processor->write_session_data(session_data_ptr->ip_hash, rs_endpoint, init_time);
2177 /*-------- DEBUG LOG --------*/
2178 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2180 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2181 "protocol_module_ip::handle_realserver_select() : "
2182 "write_session_data() end. thread id : %d.");
2183 formatter % boost::this_thread::get_id();
2184 putLogDebug(600063, formatter.str(), __FILE__, __LINE__);
2186 /*------DEBUG LOG END------*/
2188 //data state is HTTP_START
2189 if (session_data_ptr->data_state == HTTP_START)
2192 status = CLIENT_RECV;
2194 //data state is not HTTP_START
2198 status = REALSERVER_CONNECT;
2201 //get the endpoint by schedule unsuccessfully
2205 status = CLIENT_DISCONNECT;
2210 session_data_ptr->last_status = status;
2214 /*-------- DEBUG LOG --------*/
2215 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2217 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2218 "handle_realserver_select() : catch exception e = %d. thread id : %d.");
2219 formatter % e % boost::this_thread::get_id();
2220 putLogDebug(600066, formatter.str(), __FILE__, __LINE__ );
2222 /*------DEBUG LOG END------*/
2225 catch (const std::exception& ex)
2227 std::cerr << "protocol_module_ip::handle_realserver_select() : exception : error = " << ex.what() << "." << std::endl;
2228 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2229 "handle_realserver_select() : exception : error = %s. thread id : %d.");
2230 formatter % ex.what() % boost::this_thread::get_id();
2231 putLogError(600044, formatter.str(), __FILE__, __LINE__ );
2236 std::cerr << "protocol_module_ip::handle_realserver_select() : Unknown exception." << std::endl;
2237 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2238 "protocol_module_ip::handle_realserver_select() : "
2239 "Unknown exception. thread id : %d.");
2240 formatter % boost::this_thread::get_id();
2241 putLogError(600045, formatter.str(), __FILE__, __LINE__ );
2245 /*-------- DEBUG LOG --------*/
2246 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2248 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2249 "handle_realserver_select(const boost::thread::id thread_id, "
2250 "boost::asio::ip::tcp::endpoint& rs_endpoint)"
2251 " : return_value = %d. thread id : %d.");
2252 formatter % status % boost::this_thread::get_id();
2253 putLogDebug(600067, formatter.str(), __FILE__, __LINE__ );
2255 /*------DEBUG LOG END------*/
2259 //! called from after realserver select
2260 //! @param[in] upstream thread id
2261 //! @param[out] realserver UDP endpoint
2262 //! @param[out] sendbuffer reference
2263 //! @param[out] send data length
2264 //! @return session use EVENT mode.
2265 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_select(
2266 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,
2267 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2269 /*-------- DEBUG LOG --------*/
2270 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2272 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2273 "handle_realserver_select(const boost::thread::id thread_id, "
2274 "boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2275 "size_t& datalen) : "
2276 "return_value = %d. thread id : %d.");
2277 formatter % STOP % boost::this_thread::get_id();
2278 putLogDebug(600068, formatter.str(), __FILE__, __LINE__ );
2280 /*------DEBUG LOG END------*/
2283 //! called from after realserver connect
2284 //! @param[in] upstream thread id
2285 //! @param[out] sendbuffer reference
2286 //! @param[out] send data length
2287 //! @return session use EVENT mode.
2288 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_connect(
2289 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2291 /*-------- DEBUG LOG --------*/
2292 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2294 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2295 "handle_realserver_connect(const boost::thread::id thread_id, "
2296 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
2298 formatter % thread_id;
2299 putLogDebug(600069, formatter.str(), __FILE__, __LINE__ );
2301 /*------DEBUG LOG END------*/
2303 EVENT_TAG status = FINALIZE;
2304 size_t send_possible_size = 0;
2305 size_t x_forwarded_for_insert_pos = 0;
2306 thread_data_ptr session_data_ptr;
2307 session_thread_data_map_it session_thread_it;
2308 std::pair<char*, size_t> buffer_element;
2309 std::string x_forwarded_for_context;
2314 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2317 session_thread_it = session_thread_data_map.find(thread_id);
2318 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2320 boost::format formatter("Invalid thread id. thread id : %d.");
2321 formatter % boost::this_thread::get_id();
2322 putLogError(600046, formatter.str(), __FILE__, __LINE__ );
2326 session_data_ptr = session_thread_it->second;
2329 send_possible_size = std::min(session_data_ptr->current_message_rest_size,
2330 session_data_ptr->data_length
2333 //buffer sequence is empty
2334 if (session_data_ptr->buffer_sequence.empty())
2336 //data state is HTTP_HEADER
2337 if (session_data_ptr->data_state == HTTP_HEADER)
2339 //forwarded_for flag is on
2340 if (forwarded_for == FORWARDED_FOR_ON)
2342 //search X-Forwarded-For header
2343 create_x_forwarded_for(session_data_ptr->client_endpoint.address().to_string(),
2344 session_data_ptr->data_buffer + session_data_ptr->data_offset,
2345 session_data_ptr->data_length,
2346 x_forwarded_for_insert_pos,
2347 x_forwarded_for_context);
2349 //put buffer data to buffer_sequence
2350 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
2351 buffer_element.second = x_forwarded_for_insert_pos;
2352 session_data_ptr->buffer_sequence.push_back(buffer_element);
2354 session_data_ptr->forwarded_for_buffer.assign(0);
2356 /*-------- DEBUG LOG --------*/
2357 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2359 std::string datadump;
2360 dump_memory(x_forwarded_for_context.c_str(),
2361 x_forwarded_for_context.size(), datadump);
2362 boost::format formatter(
2363 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2364 "handle_realserver_connect() : before memcpy (data dump) : "
2365 "data begin = 0, data_size = %d, data = %s");
2366 formatter % x_forwarded_for_context.size() % datadump;
2367 putLogDebug(600070, formatter.str(), __FILE__, __LINE__ );
2369 /*------DEBUG LOG END------*/
2371 memcpy(session_data_ptr->forwarded_for_buffer.data(),
2372 x_forwarded_for_context.c_str(),
2373 x_forwarded_for_context.size());
2375 /*-------- DEBUG LOG --------*/
2376 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2378 std::string datadump;
2379 dump_memory(x_forwarded_for_context.c_str(),
2380 x_forwarded_for_context.size(), datadump);
2381 boost::format formatter(
2382 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2383 "handle_realserver_connect() : after memcpy (data dump) : "
2384 "data begin = 0, data_size = %d, data = %s");
2385 formatter % x_forwarded_for_context.size() % datadump;
2386 putLogDebug(600071, formatter.str(), __FILE__, __LINE__ );
2388 /*------DEBUG LOG END------*/
2390 //set buffer's position
2391 buffer_element.first = session_data_ptr->forwarded_for_buffer.data();
2392 buffer_element.second = x_forwarded_for_context.size();
2394 //set data to buffer_sequence
2395 session_data_ptr->buffer_sequence.push_back(buffer_element);
2397 //set buffer's position
2398 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset + x_forwarded_for_insert_pos;
2399 buffer_element.second = send_possible_size - x_forwarded_for_insert_pos;
2401 //set data to buffer_sequence
2402 session_data_ptr->buffer_sequence.push_back(buffer_element);
2404 //forwarded_for flag is off
2407 //set buffer's position
2408 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
2409 buffer_element.second = send_possible_size;
2411 //set data to buffer_sequence
2412 session_data_ptr->buffer_sequence.push_back(buffer_element);
2414 session_data_ptr->data_state = HTTP_BODY;
2416 //data state is not HTTP_HEADER
2420 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
2421 buffer_element.second = send_possible_size;
2423 //set data to buffer_sequence
2424 session_data_ptr->buffer_sequence.push_back(buffer_element);
2429 //put buffer_sequence data into sendbuffer
2430 put_data_into_sendbuffer(session_data_ptr, sendbuffer, datalen);
2433 status = REALSERVER_SEND;
2436 session_data_ptr->last_status = status;
2440 /*-------- DEBUG LOG --------*/
2441 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2443 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2444 "handle_realserver_connect() : catch exception e = %d. thread id : %d.");
2445 formatter % e % boost::this_thread::get_id();
2446 putLogDebug(600072, formatter.str(), __FILE__, __LINE__ );
2448 /*------DEBUG LOG END------*/
2453 catch (std::exception& ex)
2455 std::cerr << "protocol_module_ip::handle_realserver_connect() : exception : error = " << ex.what() << "." << std::endl;
2456 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2457 "handle_realserver_connect() : exception : error = %s. thread id : %d.");
2458 formatter % ex.what() % boost::this_thread::get_id();
2459 putLogError(600047, formatter.str(), __FILE__, __LINE__ );
2466 std::cerr << "protocol_module_ip::handle_realserver_connect() : Unknown exception." << std::endl;
2467 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2468 "handle_realserver_connect() : Unknown exception. thread id : %d.");
2469 formatter % boost::this_thread::get_id();
2470 putLogError(600048, formatter.str(), __FILE__, __LINE__ );
2476 /*-------- DEBUG LOG --------*/
2477 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2479 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2480 "handle_realserver_connect(const boost::thread::id thread_id, "
2481 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2482 "size_t& datalen) : return_value = %d. thread id : %d.");
2483 formatter % status % boost::this_thread::get_id();
2484 putLogDebug(600073, formatter.str(), __FILE__, __LINE__ );
2486 /*------DEBUG LOG END------*/
2491 //! called from after realserver connection fail
2492 //! @param[in] upstream thread id
2493 //! @param[in] fail realserver endpoint reference
2494 //! @return session use EVENT mode.
2495 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_connection_fail(
2496 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
2498 /*-------- DEBUG LOG --------*/
2499 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2501 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2502 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2503 "const boost::asio::ip::tcp::endpoint& rs_endpoint) : "
2504 "thread_id = %d, rs_endpoint = [%s]:%d.");
2505 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2506 putLogDebug(600074, formatter.str(), __FILE__, __LINE__ );
2508 /*------DEBUG LOG END------*/
2510 EVENT_TAG status = FINALIZE;
2511 thread_data_ptr session_data_ptr;
2512 session_thread_data_map_it session_thread_it;
2516 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2518 session_thread_it = session_thread_data_map.find(thread_id);
2519 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2521 boost::format formatter("Invalid thread id. thread id : %d.");
2522 formatter % boost::this_thread::get_id();
2523 putLogError(600049, formatter.str(), __FILE__, __LINE__ );
2527 session_data_ptr = session_thread_it->second;
2530 session_data_ptr->end_flag = END_FLAG_ON;
2532 /*-------- DEBUG LOG --------*/
2533 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2535 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2536 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2537 "const boost::asio::ip::tcp::endpoint& rs_endpoint) : END_FLAG_ON. "
2538 "thread_id = %d, rs_endpoint = [%s]:%d.");
2539 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2540 putLogDebug(600075, formatter.str(), __FILE__, __LINE__ );
2542 /*------DEBUG LOG END------*/
2545 status = CLIENT_DISCONNECT;
2548 session_data_ptr->last_status = status;
2552 /*-------- DEBUG LOG --------*/
2553 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2555 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2556 "handle_realserver_connection_fail() : catch exception e = %d. thread id : %d.");
2557 formatter % e % boost::this_thread::get_id();
2558 putLogDebug(600076, formatter.str(), __FILE__, __LINE__ );
2560 /*------DEBUG LOG END------*/
2565 catch (const std::exception& ex)
2567 std::cerr << "protocol_module_ip::handle_realserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
2568 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2569 "handle_realserver_connection_fail() : exception : error = %s. thread id : %d.");
2570 formatter % ex.what() % boost::this_thread::get_id();
2571 putLogError(600050, formatter.str(), __FILE__, __LINE__ );
2578 std::cerr << "protocol_module_ip::handle_realserver_connection_fail() : Unknown exception." << std::endl;
2579 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2580 "protocol_module_ip::handle_realserver_connection_fail() : "
2581 "Unknown exception. thread id : %d.");
2582 formatter % boost::this_thread::get_id();
2583 putLogError(600051, formatter.str(), __FILE__, __LINE__ );
2589 /*-------- DEBUG LOG --------*/
2590 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2592 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2593 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2594 "const boost::asio::ip::tcp::endpoint& rs_endpoint) : return_value = %d. thread id : %d.");
2595 formatter % status % boost::this_thread::get_id();
2596 putLogDebug(600077, formatter.str(), __FILE__, __LINE__ );
2598 /*------DEBUG LOG END------*/
2602 //! called from after realserver send.
2603 //! @param[in] upstream thread id
2604 //! @return session use EVENT mode.
2605 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_send(
2606 const boost::thread::id thread_id)
2608 /*-------- DEBUG LOG --------*/
2609 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2611 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2612 "handle_realserver_send(const boost::thread::id thread_id) : thread_id = %d.");
2613 formatter % thread_id;
2614 putLogDebug(600078, formatter.str(), __FILE__, __LINE__ );
2616 /*------DEBUG LOG END------*/
2618 EVENT_TAG status = FINALIZE;
2619 size_t http_header_all_offset = 0;
2620 size_t http_header_all_len = 0;
2621 size_t http_header_content_length_offset = 0;
2622 size_t http_header_content_length_len = 0;
2623 const size_t CR_LF_LEN = 2;
2624 const size_t CR_LF_CR_LF_LEN = 4;
2625 int content_length_value = 0;
2627 std::string content_length;
2629 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
2632 bool find_ret = false;
2633 http_utility::CHECK_RESULT_TAG check_ret;
2635 thread_data_ptr session_data_ptr;
2636 session_thread_data_map_it session_thread_it;
2641 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2644 session_thread_it = session_thread_data_map.find(thread_id);
2645 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2647 boost::format formatter("Invalid thread id. thread id : %d.");
2648 formatter % boost::this_thread::get_id();
2649 putLogError(600052, formatter.str(), __FILE__, __LINE__ );
2653 session_data_ptr = session_thread_it->second;
2656 //current_message_rest_size > 0
2657 if (session_data_ptr->current_message_rest_size > 0)
2660 if (session_data_ptr->data_length > 0)
2663 status = REALSERVER_CONNECT;
2669 session_data_ptr->data_offset = 0;
2672 status = CLIENT_RECV;
2675 //current_message_rest_size is 0
2679 if (session_data_ptr->data_length > 0)
2681 //data state is HTTP_BODY
2682 if (session_data_ptr->data_state == HTTP_BODY)
2684 //search whole http header, get whole http header's offset and length
2685 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
2686 session_data_ptr->data_length,
2687 http_header_all_offset,
2691 /*-------- DEBUG LOG --------*/
2692 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2694 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2695 "handle_realserver_send() : call find_http_header_all : "
2696 "return_value = %d. thread id : %d.");
2697 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
2698 putLogDebug(600079, formatter.str(), __FILE__, __LINE__ );
2700 /*------DEBUG LOG END------*/
2702 //search http header result is NG
2705 //set data state HTTP_START
2706 session_data_ptr->data_state = HTTP_START;
2709 status = CLIENT_RECV;
2711 //search http header result is OK
2714 //check http method and version
2715 check_ret = http_utility::check_http_method_and_version(session_data_ptr->data_buffer + session_data_ptr->data_offset,
2716 session_data_ptr->data_length);
2718 /*-------- DEBUG LOG --------*/
2719 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2721 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2722 "handle_realserver_send() : call check_http_method_and_version : "
2723 "return_value = %d. thread id : %d.");
2724 formatter % check_ret % boost::this_thread::get_id();
2725 putLogDebug(600080, formatter.str(), __FILE__, __LINE__ );
2727 /*------DEBUG LOG END------*/
2729 //check method and version result is NG
2730 if (check_ret == http_utility::CHECK_NG)
2732 //set current message rest size
2733 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
2735 //set data state UNKNOWN
2736 session_data_ptr->data_state = UNKNOWN;
2738 //check method and version result is OK
2741 //search Content_Length header
2742 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
2743 session_data_ptr->data_length,
2744 http_header_content_length_offset,
2745 http_header_content_length_len);
2747 /*-------- DEBUG LOG --------*/
2748 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2750 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2751 "handle_realserver_send() : call find_http_header_content_length : "
2752 "return_value = %d. thread id : %d.");
2753 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
2754 putLogDebug(600081, formatter.str(), __FILE__, __LINE__ );
2756 /*------DEBUG LOG END------*/
2758 //search Content_Length result is OK
2761 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
2762 http_header_content_length_len );
2763 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
2765 //"content-length: ddd\r\n"
2768 content_length = content_length.substr(
2769 regex_ret.position(1),
2770 regex_ret.length(1));
2772 //set content length value
2773 content_length_value = boost::lexical_cast<int>(content_length);
2776 //http_header context is "\r\n\r\n" only
2777 if (http_header_all_len == 0)
2779 //set current message rest size
2780 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_LEN;
2784 //set current message rest size
2785 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_CR_LF_LEN;
2788 //search Content_Length result is OK
2791 //http_header context is "\r\n\r\n" only
2792 if (http_header_all_len == 0)
2794 //set current message rest size
2795 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_LEN;
2799 //set current message rest size
2800 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_CR_LF_LEN;
2805 //set data state HTTP_HEADER
2806 session_data_ptr->data_state = HTTP_HEADER;
2810 status = REALSERVER_CONNECT;
2813 //data state is UNKNOWN
2814 else if (session_data_ptr->data_state == UNKNOWN)
2817 status = REALSERVER_CONNECT;
2824 //data state is HTTP_BODY
2825 if (session_data_ptr->data_state == HTTP_BODY)
2827 //set data state HTTP_START
2828 session_data_ptr->data_state = HTTP_START;
2832 session_data_ptr->data_offset = 0;
2835 status = CLIENT_RECV;
2839 session_data_ptr->last_status = status;
2843 /*-------- DEBUG LOG --------*/
2844 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2846 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2847 "handle_realserver_send() : catch exception e = %d. thread id : %d.");
2848 formatter % e % boost::this_thread::get_id();
2849 putLogDebug(600082, formatter.str(), __FILE__, __LINE__ );
2851 /*------DEBUG LOG END------*/
2856 catch (const boost::bad_lexical_cast& )
2858 std::cerr << "protocol_module_ip::handle_realserver_send() : exception : " << "Content_Length field's value is invalid." << std::endl;
2859 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_send() : "
2860 "Content_Length field's value is invalid. thread id : %d.");
2861 formatter % boost::this_thread::get_id();
2862 putLogError(600053, formatter.str(), __FILE__, __LINE__ );
2867 catch (const std::exception& ex)
2869 std::cerr << "protocol_module_ip::handle_realserver_send() : exception : error = " << ex.what() << "." << std::endl; //set data state HTTP_HEADER
2870 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2871 "handle_realserver_send() : exception : error = %s. thread id : %d.");
2872 formatter % ex.what() % boost::this_thread::get_id();
2873 putLogError(600054, formatter.str(), __FILE__, __LINE__ );
2880 std::cerr << "protocol_module_ip::handle_realserver_send() : Unknown exception." << std::endl;
2881 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2882 "protocol_module_ip::handle_realserver_send() : "
2883 "Unknown exception. thread id : %d.");
2884 formatter % boost::this_thread::get_id();
2885 putLogError(600055, formatter.str(), __FILE__, __LINE__ );
2891 /*-------- DEBUG LOG --------*/
2892 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2894 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2895 "handle_realserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
2896 formatter % status % boost::this_thread::get_id();
2897 putLogDebug(600083, formatter.str(), __FILE__, __LINE__ );
2899 /*------DEBUG LOG END------*/
2904 //! called from after sorryserver select
2905 //! @param[in] upstream thread id
2906 //! @param[in] sorryserver endpiont reference
2907 //! @return session use EVENT mode.
2908 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_select(
2909 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint)
2911 /*-------- DEBUG LOG --------*/
2912 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2914 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2915 "handle_sorryserver_select(const boost::thread::id thread_id, "
2916 "boost::asio::ip::tcp::endpoint& sorry_endpoint) : "
2917 "thread_id = %d, sorry_endpoint = [%s]:%d.");
2918 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
2919 putLogDebug(600084, formatter.str(), __FILE__, __LINE__ );
2921 /*------DEBUG LOG END------*/
2923 EVENT_TAG status = FINALIZE;
2924 boost::asio::ip::tcp::endpoint tmp_endpoint;
2925 thread_data_ptr session_data_ptr;
2926 session_thread_data_map_it session_thread_it;
2927 session_thread_data_map_it session_thread_it_end;
2932 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2934 session_thread_it = session_thread_data_map.find(thread_id);
2935 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2937 boost::format formatter("Invalid thread id. thread id : %d.");
2938 formatter % boost::this_thread::get_id();
2939 putLogError(600056, formatter.str(), __FILE__, __LINE__ );
2943 session_data_ptr = session_thread_it->second;
2946 //data state is HTTP_START
2947 if (session_data_ptr->data_state == HTTP_START)
2950 status = CLIENT_RECV;
2952 //data state is not HTTP_START
2956 status = SORRYSERVER_CONNECT;
2960 session_data_ptr->last_status = status;
2964 /*-------- DEBUG LOG --------*/
2965 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2967 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2968 "handle_sorryserver_select() : catch exception e = %d. thread id : %d.");
2969 formatter % e % boost::this_thread::get_id();
2970 putLogDebug(600085, formatter.str(), __FILE__, __LINE__ );
2972 /*------DEBUG LOG END------*/
2977 catch (const std::exception& ex)
2979 std::cerr << "protocol_module_ip::handle_sorryserver_select() : exception : error = " << ex.what() << "." << std::endl;
2980 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2981 "handle_sorryserver_select() : exception : error = %s. thread id : %d.");
2982 formatter % ex.what() % boost::this_thread::get_id();
2983 putLogError(600057, formatter.str(), __FILE__, __LINE__ );
2990 std::cerr << "protocol_module_ip::handle_sorryserver_select() : Unknown exception." << std::endl;
2991 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2992 "protocol_module_ip::handle_sorryserver_select() : "
2993 "Unknown exception. thread id : %d.");
2994 formatter % boost::this_thread::get_id();
2995 putLogError(600058, formatter.str(), __FILE__, __LINE__ );
3001 /*-------- DEBUG LOG --------*/
3002 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3004 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3005 "handle_sorryserver_select(const boost::thread::id thread_id, "
3006 "boost::asio::ip::tcp::endpoint& sorry_endpoint)"
3007 " : return_value = %d. thread id : %d.");
3008 formatter % status % boost::this_thread::get_id();
3009 putLogDebug(600086, formatter.str(), __FILE__, __LINE__ );
3011 /*------DEBUG LOG END------*/
3016 //! called from after sorryserver connect
3017 //! @param[in] upstream thread id
3018 //! @param[out] send buffer reference.
3019 //! @param[out] send length
3020 //! @return session use EVENT mode.
3021 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_connect(
3022 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
3024 /*-------- DEBUG LOG --------*/
3025 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3027 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3028 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3029 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
3031 formatter % thread_id;
3032 putLogDebug(600087, formatter.str(), __FILE__, __LINE__ );
3034 /*------DEBUG LOG END------*/
3036 EVENT_TAG status = FINALIZE;
3037 size_t send_possible_size = 0;
3038 size_t uri_offset = 0;
3040 size_t x_forwarded_for_insert_pos = 0;
3041 thread_data_ptr session_data_ptr;
3042 session_thread_data_map_it session_thread_it;
3043 std::pair<char*, size_t> buffer_element;
3044 std::string x_forwarded_for_context;
3049 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3052 session_thread_it = session_thread_data_map.find(thread_id);
3053 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3055 boost::format formatter("Invalid thread id. thread id : %d.");
3056 formatter % boost::this_thread::get_id();
3057 putLogError(600059, formatter.str(), __FILE__, __LINE__ );
3061 session_data_ptr = session_thread_it->second;
3063 //set send possible data size
3064 send_possible_size = std::min(session_data_ptr->current_message_rest_size,
3065 session_data_ptr->data_length
3068 if (session_data_ptr->buffer_sequence.empty())
3070 //data state is HTTP_HEADER
3071 if (session_data_ptr->data_state == HTTP_HEADER)
3074 http_utility::find_uri(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3075 session_data_ptr->data_length, uri_offset, uri_len);
3077 //set buffer's position
3078 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
3079 buffer_element.second = uri_offset;
3081 //put buffer data to buffer_sequence
3082 session_data_ptr->buffer_sequence.push_back(buffer_element);
3084 //set buffer's position
3085 buffer_element.first = sorry_uri.data();
3086 buffer_element.second = strlen(sorry_uri.data());
3088 //put buffer data to buffer_sequence
3089 session_data_ptr->buffer_sequence.push_back(buffer_element);
3091 //forwarded_for flag is on
3092 if (forwarded_for == FORWARDED_FOR_ON)
3094 create_x_forwarded_for(session_data_ptr->client_endpoint.address().to_string(),
3095 session_data_ptr->data_buffer + session_data_ptr->data_offset,
3096 session_data_ptr->data_length,
3097 x_forwarded_for_insert_pos,
3098 x_forwarded_for_context);
3100 //set buffer's position
3101 buffer_element.first = session_data_ptr->data_buffer
3102 + session_data_ptr->data_offset
3105 buffer_element.second = x_forwarded_for_insert_pos - uri_offset - uri_len;
3107 //put buffer data to buffer_sequence
3108 session_data_ptr->buffer_sequence.push_back(buffer_element);
3110 session_data_ptr->forwarded_for_buffer.assign(0);
3112 /*-------- DEBUG LOG --------*/
3113 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3115 std::string datadump;
3116 dump_memory(x_forwarded_for_context.c_str(),
3117 x_forwarded_for_context.size(), datadump);
3118 boost::format formatter(
3119 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3120 "handle_sorryserver_connect() : before memcpy (data dump) : "
3121 "data begin = 0, data_size = %d, data = %s");
3122 formatter % x_forwarded_for_context.size() % datadump;
3123 putLogDebug(600088, formatter.str(), __FILE__, __LINE__ );
3125 /*------DEBUG LOG END------*/
3127 memcpy(session_data_ptr->forwarded_for_buffer.data(),
3128 x_forwarded_for_context.c_str(),
3129 x_forwarded_for_context.size());
3131 /*-------- DEBUG LOG --------*/
3132 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3134 std::string datadump;
3135 dump_memory(x_forwarded_for_context.c_str(),
3136 x_forwarded_for_context.size(), datadump);
3137 boost::format formatter(
3138 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3139 "handle_sorryserver_connect() : after memcpy (data dump) : "
3140 "data begin = 0, data_size = %d, data = %s");
3141 formatter % x_forwarded_for_context.size() % datadump;
3142 putLogDebug(600089, formatter.str(), __FILE__, __LINE__ );
3144 /*------DEBUG LOG END------*/
3146 //set buffer's position
3147 buffer_element.first = session_data_ptr->forwarded_for_buffer.data();
3148 buffer_element.second = x_forwarded_for_context.size();
3149 //put buffer data to buffer_sequence
3150 session_data_ptr->buffer_sequence.push_back(buffer_element);
3152 //set buffer's position
3153 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset + x_forwarded_for_insert_pos;
3154 buffer_element.second = send_possible_size - x_forwarded_for_insert_pos;
3155 //put buffer data to buffer_sequence
3156 session_data_ptr->buffer_sequence.push_back(buffer_element);
3158 //forwarded_for flag is on
3161 //set buffer's position
3162 buffer_element.first = session_data_ptr->data_buffer
3163 + session_data_ptr->data_offset
3166 buffer_element.second = send_possible_size - uri_offset - uri_len;
3167 //put buffer data to buffer_sequence
3168 session_data_ptr->buffer_sequence.push_back(buffer_element);
3171 //set data state HTTP_BODY
3172 session_data_ptr->data_state = HTTP_BODY;
3174 //data state is not HTTP_HEADER
3177 //set buffer's position
3178 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
3179 buffer_element.second = send_possible_size;
3180 //put buffer data to buffer_sequence
3181 session_data_ptr->buffer_sequence.push_back(buffer_element);
3185 //put buffer_sequence data into sendbuffer
3186 put_data_into_sendbuffer(session_data_ptr, sendbuffer, datalen);
3189 status = SORRYSERVER_SEND;
3192 session_data_ptr->last_status = status;
3197 /*-------- DEBUG LOG --------*/
3198 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3200 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3201 "handle_sorryserver_connect() : catch exception e = %d. thread id : %d.");
3202 formatter % e % boost::this_thread::get_id();
3203 putLogDebug(600090, formatter.str(), __FILE__, __LINE__ );
3205 /*------DEBUG LOG END------*/
3210 catch (const std::exception& ex)
3212 std::cerr << "protocol_module_ip::handle_sorryserver_connect() : exception : error = " << ex.what() << "." << std::endl;
3213 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3214 "handle_sorryserver_connect() : exception : error = %s. thread id : %d.");
3215 formatter % ex.what() % boost::this_thread::get_id();
3216 putLogError(600060, formatter.str(), __FILE__, __LINE__ );
3223 std::cerr << "protocol_module_ip::handle_sorryserver_connect() : Unknown exception." << std::endl;
3224 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3225 "handle_sorryserver_connect() : Unknown exception. thread id : %d.");
3226 formatter % boost::this_thread::get_id();
3227 putLogError(600061, formatter.str(), __FILE__, __LINE__ );
3233 /*-------- DEBUG LOG --------*/
3234 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3236 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3237 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3238 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3239 "size_t& datalen) : return_value = %d. thread id : %d.");
3240 formatter % status % boost::this_thread::get_id();
3241 putLogDebug(600091, formatter.str(), __FILE__, __LINE__ );
3243 /*------DEBUG LOG END------*/
3247 //! called from after sorryserver connection fail
3248 //! @param[in] upstream thread id
3249 //! @param[in] sorryserver endpoint reference.
3250 //! @return session use EVENT mode.
3251 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_connection_fail(
3252 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
3254 /*-------- DEBUG LOG --------*/
3255 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3257 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3258 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
3259 "const boost::asio::ip::tcp::endpoint& sorry_endpoint) : "
3260 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3261 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3262 putLogDebug(600092, formatter.str(), __FILE__, __LINE__ );
3264 /*------DEBUG LOG END------*/
3266 EVENT_TAG status = FINALIZE;
3267 thread_data_ptr session_data_ptr;
3268 session_thread_data_map_it session_thread_it;
3272 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3274 session_thread_it = session_thread_data_map.find(thread_id);
3275 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3277 boost::format formatter("Invalid thread id. thread id : %d.");
3278 formatter % boost::this_thread::get_id();
3279 putLogError(600062, formatter.str(), __FILE__, __LINE__ );
3283 session_data_ptr = session_thread_it->second;
3286 status = CLIENT_DISCONNECT;
3289 session_data_ptr->last_status = status;
3293 /*-------- DEBUG LOG --------*/
3294 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3296 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3297 "handle_sorryserver_connection_fail() : catch exception e = %d. thread id : %d.");
3298 formatter % e % boost::this_thread::get_id();
3299 putLogDebug(600093, formatter.str(), __FILE__, __LINE__ );
3301 /*------DEBUG LOG END------*/
3306 catch (const std::exception& ex)
3308 std::cerr << "protocol_module_ip::handle_sorryserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
3309 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3310 "handle_sorryserver_connection_fail() : exception : error = %s. thread id : %d.");
3311 formatter % ex.what() % boost::this_thread::get_id();
3312 putLogError(600063, formatter.str(), __FILE__, __LINE__ );
3319 std::cerr << "protocol_module_ip::handle_sorryserver_connection_fail() : Unknown exception." << std::endl;
3320 boost::format formatter("function : protocol_module_base::EVENT_TAG "
3321 "protocol_module_ip::handle_sorryserver_connection_fail() : "
3322 "Unknown exception. thread id : %d.");
3323 formatter % boost::this_thread::get_id();
3324 putLogError(600064, formatter.str(), __FILE__, __LINE__ );
3330 /*-------- DEBUG LOG --------*/
3331 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3333 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3334 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
3335 "const boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d. thread id : %d.");
3336 formatter % status % boost::this_thread::get_id();
3337 putLogDebug(600094, formatter.str(), __FILE__, __LINE__ );
3339 /*------DEBUG LOG END------*/
3344 //! called from after sorryserver send
3345 //! @param[in] upstream thread id
3346 //! @return session use EVENT mode.
3347 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_send(
3348 const boost::thread::id thread_id)
3350 /*-------- DEBUG LOG --------*/
3351 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3353 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3354 "handle_sorryserver_send(const boost::thread::id thread_id) : thread_id = %d.");
3355 formatter % thread_id;
3356 putLogDebug(600095, formatter.str(), __FILE__, __LINE__ );
3358 /*------DEBUG LOG END------*/
3360 EVENT_TAG status = FINALIZE;
3361 size_t http_header_all_offset = 0;
3362 size_t http_header_all_len = 0;
3363 size_t http_header_content_length_offset = 0;
3364 size_t http_header_content_length_len = 0;
3365 const size_t CR_LF_LEN = 2;
3366 const size_t CR_LF_CR_LF_LEN = 4;
3367 int content_length_value = 0;
3369 std::string content_length;
3371 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
3374 bool find_ret = false;
3375 http_utility::CHECK_RESULT_TAG check_ret;
3377 thread_data_ptr session_data_ptr;
3378 session_thread_data_map_it session_thread_it;
3383 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3386 session_thread_it = session_thread_data_map.find(thread_id);
3387 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3389 boost::format formatter("Invalid thread id. thread id : %d.");
3390 formatter % boost::this_thread::get_id();
3391 putLogError(600065, formatter.str(), __FILE__, __LINE__ );
3395 session_data_ptr = session_thread_it->second;
3398 //current_message_rest_size > 0
3399 if (session_data_ptr->current_message_rest_size > 0)
3402 if (session_data_ptr->data_length > 0)
3405 status = SORRYSERVER_CONNECT;
3411 session_data_ptr->data_offset = 0;
3414 status = CLIENT_RECV;
3417 //current_message_rest_size is 0
3421 if (session_data_ptr->data_length> 0)
3423 //data state is HTTP_BODY
3424 if (session_data_ptr->data_state == HTTP_BODY)
3426 //search whole http header, get whole http header's offset and length
3427 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3428 session_data_ptr->data_length,
3429 http_header_all_offset,
3433 /*-------- DEBUG LOG --------*/
3434 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3436 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3437 "handle_sorryserver_send() : call find_http_header_all : "
3438 "return_value = %d. thread id : %d.");
3439 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3440 putLogDebug(600096, formatter.str(), __FILE__, __LINE__ );
3442 /*------DEBUG LOG END------*/
3444 //search http header result is NG
3447 //set data state HTTP_START
3448 session_data_ptr->data_state = HTTP_START;
3451 status = CLIENT_RECV;
3453 //check method and version result is OK
3456 //search Content_Length header
3457 check_ret = http_utility::check_http_method_and_version(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3458 session_data_ptr->data_length);
3460 /*-------- DEBUG LOG --------*/
3461 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3463 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3464 "handle_sorryserver_send() : call check_http_method_and_version : "
3465 "return_value = %d. thread id : %d.");
3466 formatter % check_ret % boost::this_thread::get_id();
3467 putLogDebug(600097, formatter.str(), __FILE__, __LINE__ );
3469 /*------DEBUG LOG END------*/
3471 //check method and version result is NG
3472 if (check_ret == http_utility::CHECK_NG)
3474 //set current message rest size
3475 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3477 //set data state UNKNOWN
3478 session_data_ptr->data_state = UNKNOWN;
3480 //check method and version result is OK
3483 //search Content_Length header
3484 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
3485 session_data_ptr->data_length,
3486 http_header_content_length_offset,
3487 http_header_content_length_len);
3489 /*-------- DEBUG LOG --------*/
3490 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3492 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3493 "handle_sorryserver_send() : call find_http_header_content_length : "
3494 "return_value = %d. thread id : %d.");
3495 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3496 putLogDebug(600098, formatter.str(), __FILE__, __LINE__ );
3498 /*------DEBUG LOG END------*/
3500 //search Content_Length result is OK
3503 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
3504 http_header_content_length_len );
3505 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
3507 //"content-length: ddd\r\n"
3510 content_length = content_length.substr(
3511 regex_ret.position(1),
3512 regex_ret.length(1));
3514 //set content length value
3515 content_length_value = boost::lexical_cast<int>(content_length);
3518 //http_header context is "\r\n\r\n" only
3519 if (http_header_all_len == 0)
3521 //set current message rest size
3522 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_LEN;
3526 //set current message rest size
3527 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_CR_LF_LEN;
3530 //search Content_Length result is OK
3533 //http_header context is "\r\n\r\n" only
3534 if (http_header_all_len == 0)
3536 //set current message rest size
3537 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_LEN;
3541 //set current message rest size
3542 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_CR_LF_LEN;
3547 //set data state HTTP_HEADER
3548 session_data_ptr->data_state = HTTP_HEADER;
3552 status = SORRYSERVER_CONNECT;
3555 //data state is UNKNOWN
3556 else if (session_data_ptr->data_state == UNKNOWN)
3559 status = SORRYSERVER_CONNECT;
3566 //data state is HTTP_BODY
3567 if (session_data_ptr->data_state == HTTP_BODY)
3569 //set data state HTTP_START
3570 session_data_ptr->data_state = HTTP_START;
3574 session_data_ptr->data_offset = 0;
3577 status = CLIENT_RECV;
3582 session_data_ptr->last_status = status;
3586 /*-------- DEBUG LOG --------*/
3587 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3589 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3590 "handle_sorryserver_send() : catch exception e = %d. thread id : %d.");
3591 formatter % e % boost::this_thread::get_id();
3592 putLogDebug(600099, formatter.str(), __FILE__, __LINE__ );
3594 /*------DEBUG LOG END------*/
3599 catch (const boost::bad_lexical_cast& )
3601 std::cerr << "protocol_module_ip::handle_sorryserver_send() : exception : " << "Content_Length field's value is invalid." << std::endl;
3602 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_send() : "
3603 "Content_Length field's value is invalid. thread id : %d.");
3604 formatter % boost::this_thread::get_id();
3605 putLogError(600066, formatter.str(), __FILE__, __LINE__ );
3610 catch (const std::exception& ex)
3612 std::cerr << "protocol_module_ip::handle_sorryserver_send() : exception : error = " << ex.what() << "." << std::endl;
3613 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3614 "handle_sorryserver_send() : exception : error = %s. thread id : %d.");
3615 formatter % ex.what() % boost::this_thread::get_id();
3616 putLogError(600067, formatter.str(), __FILE__, __LINE__ );
3623 std::cerr << "protocol_module_ip::handle_sorryserver_send() : Unknown exception." << std::endl;
3624 boost::format formatter("function : protocol_module_base::EVENT_TAG "
3625 "protocol_module_ip::handle_sorryserver_send() : "
3626 "Unknown exception. thread id : %d.");
3627 formatter % boost::this_thread::get_id();
3628 putLogError(600068, formatter.str(), __FILE__, __LINE__ );
3634 /*-------- DEBUG LOG --------*/
3635 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3637 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3638 "handle_sorryserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
3639 formatter % status % boost::this_thread::get_id();
3640 putLogDebug(600100, formatter.str(), __FILE__, __LINE__ );
3642 /*------DEBUG LOG END------*/
3647 //! called from after realserver recive.for UDP
3648 //! @param[in] downstream thread id
3649 //! @param[in] realserver UDP endpoint reference
3650 //! @param[in] recive from realserver buffer reference
3651 //! @param[in] recv data length
3652 //! @return session use EVENT mode.
3653 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_recv(
3654 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,
3655 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
3657 /*-------- DEBUG LOG --------*/
3658 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3660 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3661 "handle_realserver_recv(const boost::thread::id thread_id, "
3662 "const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3663 "const size_t& recvlen) : "
3664 "return_value = %d. thread id : %d.");
3665 formatter % STOP % boost::this_thread::get_id();
3666 putLogDebug(600101, formatter.str(), __FILE__, __LINE__ );
3668 /*------DEBUG LOG END------*/
3672 //! called from after realserver recvive for TCP/IP
3673 //! @param[in] downstream thread id
3674 //! @param[in] realserver TCP/IP endpoint reference
3675 //! @param[in] realserver recive buffer reference.
3676 //! @param[in] recv data length
3677 //! @return session use EVENT mode.
3678 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_recv(
3679 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& rs_endpoint, const boost::array<char,
3680 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
3682 /*-------- DEBUG LOG --------*/
3683 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3685 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
3687 dump_memory(recvbuffer.data(), buffer_size, buffer);
3688 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3689 "handle_realserver_recv(const boost::thread::id thread_id, "
3690 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
3691 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3692 "const size_t recvlen) : thread_id = %d, rs_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
3693 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port()
3695 putLogDebug(600102, formatter.str(), __FILE__, __LINE__ );
3697 /*------DEBUG LOG END------*/
3699 EVENT_TAG status = FINALIZE;
3701 bool find_ret = false;
3702 size_t http_header_offset = 0;
3703 size_t http_header_len = 0;
3704 size_t http_header_content_length_offset = 0;
3705 size_t http_header_content_length_len = 0;
3706 int content_length_value = 0;
3707 const size_t CR_LF_LEN = 2; //length of "\r\n"
3708 const size_t CR_LF_CR_LF_LEN = 4; //length of "\r\n\r\n"
3710 session_thread_data_map_it session_thread_it;
3711 thread_data_ptr session_data_ptr;
3712 http_utility::CHECK_RESULT_TAG check_ret;
3714 std::string content_length;
3716 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
3718 if (unlikely(recvlen > recvbuffer.size()))
3720 std::cerr << "protocol_module_ip::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
3721 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
3722 formatter % boost::this_thread::get_id();
3723 putLogError(600069, formatter.str(), __FILE__, __LINE__ );
3725 /*-------- DEBUG LOG --------*/
3726 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3728 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3729 "handle_realserver_recv(const boost::thread::id thread_id, "
3730 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
3731 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3732 "const size_t recvlen) : return_value = %d. thread id : %d.");
3733 formatter % FINALIZE % boost::this_thread::get_id();
3734 putLogDebug(600103, formatter.str(), __FILE__, __LINE__ );
3736 /*------DEBUG LOG END------*/
3744 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3746 session_thread_it = session_thread_data_map.find(thread_id);
3747 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3749 boost::format formatter("Invalid thread id. thread id : %d.");
3750 formatter % boost::this_thread::get_id();
3751 putLogError(600070, formatter.str(), __FILE__, __LINE__ );
3755 session_data_ptr = session_thread_it->second;
3758 //set switch flag off
3759 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
3761 /*-------- DEBUG LOG --------*/
3762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3764 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3765 "handle_realserver_recv(const boost::thread::id thread_id, "
3766 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
3767 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3768 "const size_t recvlen) : SWITCH_FLAG_OFF. "
3769 "thread_id = %d, rs_endpoint = [%s]:%d.");
3770 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
3771 putLogDebug(600104, formatter.str(), __FILE__, __LINE__ );
3773 /*------DEBUG LOG END------*/
3775 //copy data from recvbuffer
3776 if (!get_data_from_recvbuffer(session_data_ptr, recvbuffer, recvlen))
3779 std::cerr << "protocol_module_ip::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
3780 boost::format formatter("Data size bigger than buffer size. thread id : % id.");
3781 formatter % boost::this_thread::get_id();
3782 putLogError(600071, formatter.str(), __FILE__, __LINE__);
3787 //data state is HTTP_START
3788 if (session_data_ptr->data_state == HTTP_START)
3790 //search http header
3791 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3792 session_data_ptr->data_length,
3797 /*-------- DEBUG LOG --------*/
3798 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3800 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3801 "handle_realserver_recv() : call find_http_header_all : "
3802 "return_value = %d. thread id : %d.");
3803 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3804 putLogDebug(600105, formatter.str(), __FILE__, __LINE__ );
3806 /*------DEBUG LOG END------*/
3808 //search http header result is NG
3811 //data size bigger than max buffer size
3812 if (session_data_ptr->data_length >= MAX_IP_MODULE_BUFFER_SIZE - recvbuffer.size())
3814 //set data state UNKNOWN
3815 session_data_ptr->data_state = UNKNOWN;
3816 //set current message rest size
3817 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3820 //search http header result is OK
3823 //check http version and status code
3824 check_ret = http_utility::check_http_version_and_status_code(session_data_ptr->data_buffer,
3825 session_data_ptr->data_length);
3827 /*-------- DEBUG LOG --------*/
3828 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3830 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3831 "handle_realserver_recv() : call check_http_version_and_status_code : "
3832 "return_value = %d. thread id : %d.");
3833 formatter % check_ret % boost::this_thread::get_id();
3834 putLogDebug(600106, formatter.str(), __FILE__, __LINE__ );
3836 /*------DEBUG LOG END------*/
3838 //check http version and status code result is NG
3839 if (check_ret == http_utility::CHECK_NG)
3841 //set data state UNKNOWN
3842 session_data_ptr->data_state = UNKNOWN;
3843 //set current message rest size
3844 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3846 //check http version and status code result is OK
3849 //search Content_Length header
3850 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
3851 session_data_ptr->data_length,
3852 http_header_content_length_offset,
3853 http_header_content_length_len);
3855 /*-------- DEBUG LOG --------*/
3856 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3858 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3859 "handle_realserver_recv() : call find_http_header_content_length : "
3860 "return_value = %d. thread id : %d.");
3861 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3862 putLogDebug(600107, formatter.str(), __FILE__, __LINE__ );
3864 /*------DEBUG LOG END------*/
3866 //search Content_Length result is OK
3869 //set content length string
3870 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
3871 http_header_content_length_len );
3872 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
3874 //"content-length: ddd\r\n"
3877 content_length = content_length.substr(
3878 regex_ret.position(1),
3879 regex_ret.length(1));
3881 //set content length value
3882 content_length_value = boost::lexical_cast<int>(content_length);
3885 //http_header context is "\r\n\r\n" only
3886 if (http_header_len == 0)
3888 //set current message rest size
3889 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_LEN;
3893 //set current message rest size
3894 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_CR_LF_LEN;
3897 //search Content_Length result is NG
3900 //http_header context is "\r\n\r\n" only
3901 if (http_header_len == 0)
3903 //set current message rest size
3904 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_LEN;
3908 //set current message rest size
3909 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_CR_LF_LEN;
3914 //set data state HTTP_HEADER
3915 session_data_ptr->data_state = HTTP_HEADER;
3919 //data state is UNKNOWN
3920 else if (session_data_ptr->data_state == UNKNOWN)
3922 //set current message rest size
3923 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3930 //data state is HTTP_START
3931 if (session_data_ptr->data_state == HTTP_START)
3934 status = REALSERVER_RECV;
3936 //data state is not HTTP_START
3940 status = CLIENT_CONNECTION_CHECK;
3945 session_data_ptr->last_status = status;
3949 /*-------- DEBUG LOG --------*/
3950 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3952 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3953 "handle_realserver_recv() : catch exception e = %d. thread id : %d.");
3954 formatter % e % boost::this_thread::get_id();
3955 putLogDebug(600108, formatter.str(), __FILE__, __LINE__ );
3957 /*------DEBUG LOG END------*/
3962 catch (const boost::bad_lexical_cast& )
3964 std::cerr << "protocol_module_ip::handle_realserver_recv() : exception : " << "Content_Length field's value is invalid." << std::endl;
3965 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_recv() : "
3966 "Content_Length field's value is invalid. thread id : %d.");
3967 formatter % boost::this_thread::get_id();
3968 putLogError(600072, formatter.str(), __FILE__, __LINE__ );
3973 catch (const std::exception& ex)
3975 std::cerr << "protocol_module_ip::handle_realserver_recv() : exception : error = " << ex.what() << "." << std::endl;
3976 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3977 "handle_realserver_recv() : exception : error = %s. thread id : %d.");
3978 formatter % ex.what() % boost::this_thread::get_id();
3979 putLogError(600073, formatter.str(), __FILE__, __LINE__ );
3986 std::cerr << "protocol_module_ip::handle_realserver_recv() : Unknown exception." << std::endl;
3987 boost::format formatter("function : protocol_module_base::EVENT_TAG "
3988 "protocol_module_ip::handle_realserver_recv() : "
3989 "Unknown exception. thread id : %d.");
3990 formatter % boost::this_thread::get_id();
3991 putLogError(600074, formatter.str(), __FILE__, __LINE__ );
3997 /*-------- DEBUG LOG --------*/
3998 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4000 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4001 "handle_realserver_recv(const boost::thread::id thread_id, "
4002 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
4003 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4004 "const size_t recvlen) : return_value = %d. thread id : %d.");
4005 formatter % FINALIZE % boost::this_thread::get_id();
4006 putLogDebug(600109, formatter.str(), __FILE__, __LINE__ );
4008 /*------DEBUG LOG END------*/
4015 //! called from after sorryserver recive
4016 //! @param[in] downstream thread id
4017 //! @param[in] sorryserver endpoint reference
4018 //! @param[in] recive from realserver buffer reference.
4019 //! @param[in] recv data length
4020 //! @return session use EVENT mode
4021 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_recv(
4022 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& sorry_endpoint, const boost::array<
4023 char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4025 /*-------- DEBUG LOG --------*/
4026 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4028 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
4030 dump_memory(recvbuffer.data(), buffer_size, buffer);
4031 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4032 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4033 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4034 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4035 "const size_t recvlen) : thread_id = %d, sorry_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
4036 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port()
4038 putLogDebug(600110, formatter.str(), __FILE__, __LINE__ );
4040 /*------DEBUG LOG END------*/
4042 EVENT_TAG status = FINALIZE;
4043 bool find_ret = false;
4044 size_t http_header_offset = 0;
4045 size_t http_header_len = 0;
4046 size_t http_header_content_length_offset = 0;
4047 size_t http_header_content_length_len = 0;
4048 int content_length_value = 0;
4049 const size_t CR_LF_LEN = 2; //length of "\r\n"
4050 const size_t CR_LF_CR_LF_LEN = 4; //length of "\r\n\r\n"
4052 session_thread_data_map_it session_thread_it;
4053 thread_data_ptr session_data_ptr;
4054 http_utility::CHECK_RESULT_TAG check_ret;
4055 std::string content_length;
4057 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
4059 if (unlikely(recvlen > recvbuffer.size()))
4061 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
4062 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
4063 formatter % boost::this_thread::get_id();
4064 putLogError(600075, formatter.str(), __FILE__, __LINE__ );
4066 /*-------- DEBUG LOG --------*/
4067 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4069 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4070 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4071 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4072 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4073 "const size_t recvlen) : return_value = %d. thread id : %d.");
4074 formatter % FINALIZE % boost::this_thread::get_id();
4075 putLogDebug(600111, formatter.str(), __FILE__, __LINE__ );
4077 /*------DEBUG LOG END------*/
4085 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
4087 session_thread_it = session_thread_data_map.find(thread_id);
4088 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4090 boost::format formatter("Invalid thread id. thread id : %d.");
4091 formatter % boost::this_thread::get_id();
4092 putLogError(600076, formatter.str(), __FILE__, __LINE__ );
4096 session_data_ptr = session_thread_it->second;
4099 //set switch flag off
4100 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
4102 /*-------- DEBUG LOG --------*/
4103 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4105 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4106 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4107 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4108 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4109 "const size_t recvlen) : SWITCH_FLAG_OFF. "
4110 "thread_id = %d, rs_endpoint = [%s]:%d.");
4111 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
4112 putLogDebug(600112, formatter.str(), __FILE__, __LINE__ );
4114 /*------DEBUG LOG END------*/
4116 //copy data from recvbuffer
4117 if (!get_data_from_recvbuffer(session_data_ptr, recvbuffer, recvlen))
4120 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
4121 boost::format formatter("Data size bigger than buffer size. thread id : % id.");
4122 formatter % boost::this_thread::get_id();
4123 putLogError(600077, formatter.str(), __FILE__, __LINE__);
4129 //data state is HTTP_START
4130 if (session_data_ptr->data_state == HTTP_START)
4132 //search http header
4133 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
4134 session_data_ptr->data_length,
4139 /*-------- DEBUG LOG --------*/
4140 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4142 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4143 "handle_sorryserver_recv() : call find_http_header_all : "
4144 "return_value = %d. thread id : %d.");
4145 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4146 putLogDebug(600113, formatter.str(), __FILE__, __LINE__ );
4148 /*------DEBUG LOG END------*/
4150 //search http header result is NG
4153 //data size bigger than max buffer size
4154 if (session_data_ptr->data_length >= MAX_IP_MODULE_BUFFER_SIZE - recvbuffer.size())
4156 //set data state UNKNOWN
4157 session_data_ptr->data_state = UNKNOWN;
4158 //set current message rest size
4159 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4162 //search http header result is OK
4165 //check http version and status code
4166 check_ret = http_utility::check_http_version_and_status_code(session_data_ptr->data_buffer,
4167 session_data_ptr->data_length);
4169 /*-------- DEBUG LOG --------*/
4170 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4172 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4173 "handle_sorryserver_recv() : call check_http_version_and_status_code : "
4174 "return_value = %d. thread id : %d.");
4175 formatter % check_ret % boost::this_thread::get_id();
4176 putLogDebug(600114, formatter.str(), __FILE__, __LINE__ );
4178 /*------DEBUG LOG END------*/
4180 //check http version and status code result is NG
4181 if (check_ret == http_utility::CHECK_NG)
4183 //set data state UNKNOWN
4184 session_data_ptr->data_state = UNKNOWN;
4185 //set current message rest size
4186 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4188 //check http version and status code result is OK
4191 //search Content_Length header
4192 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
4193 session_data_ptr->data_length,
4194 http_header_content_length_offset,
4195 http_header_content_length_len);
4197 /*-------- DEBUG LOG --------*/
4198 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4200 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4201 "handle_sorryserver_recv() : call find_http_header_content_length : "
4202 "return_value = %d. thread id : %d.");
4203 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4204 putLogDebug(600115, formatter.str(), __FILE__, __LINE__ );
4206 /*------DEBUG LOG END------*/
4208 //search Content_Length result is OK
4211 ////set content length string
4212 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
4213 http_header_content_length_len );
4214 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
4216 //"content-length: ddd\r\n"
4219 content_length = content_length.substr(
4220 regex_ret.position(1),
4221 regex_ret.length(1));
4223 //set content length value
4224 content_length_value = boost::lexical_cast<int>(content_length);
4227 //http_header context is "\r\n\r\n" only
4228 if (http_header_len == 0)
4230 //set current message rest size
4231 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_LEN;
4235 //set current message rest size
4236 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_CR_LF_LEN;
4239 //search Content_Length result is NG
4242 //http_header context is "\r\n\r\n" only
4243 if (http_header_len == 0)
4245 //set current message rest size
4246 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_LEN;
4250 //set current message rest size
4251 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_CR_LF_LEN;
4256 //set data state HTTP_HEADER
4257 session_data_ptr->data_state = HTTP_HEADER;
4262 //data state is UNKNOWN
4263 else if (session_data_ptr->data_state == UNKNOWN)
4265 //set current message rest size
4266 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4273 //data state is HTTP_START
4274 if (session_data_ptr->data_state == HTTP_START)
4277 status = SORRYSERVER_RECV;
4279 //data state is not HTTP_START
4283 status = CLIENT_CONNECTION_CHECK;
4288 session_data_ptr->last_status = status;
4292 /*-------- DEBUG LOG --------*/
4293 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4295 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4296 "handle_sorryserver_recv() : catch exception e = %d. thread id : %d.");
4297 formatter % e % boost::this_thread::get_id();
4298 putLogDebug(600116, formatter.str(), __FILE__, __LINE__ );
4300 /*------DEBUG LOG END------*/
4305 catch (const boost::bad_lexical_cast& )
4307 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : exception : " << "Content_Length field's value is invalid." << std::endl;
4308 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_recv() : "
4309 "Content_Length field's value is invalid. thread id : %d.");
4310 formatter % boost::this_thread::get_id();
4311 putLogError(600078, formatter.str(), __FILE__, __LINE__ );
4316 catch (const std::exception& ex)
4318 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : exception : error = " << ex.what() << "." << std::endl;
4319 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4320 "handle_sorryserver_recv() : exception : error = %s. thread id : %d.");
4321 formatter % ex.what() % boost::this_thread::get_id();
4322 putLogError(600079, formatter.str(), __FILE__, __LINE__ );
4329 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : Unknown exception." << std::endl;
4330 boost::format formatter("function : protocol_module_base::EVENT_TAG "
4331 "protocol_module_ip::handle_sorryserver_recv() : "
4332 "Unknown exception. thread id : %d.");
4333 formatter % boost::this_thread::get_id();
4334 putLogError(600080, formatter.str(), __FILE__, __LINE__ );
4340 /*-------- DEBUG LOG --------*/
4341 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4343 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4344 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4345 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4346 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4347 "const size_t recvlen) : return_value = %d. thread id : %d.");
4348 formatter % FINALIZE % boost::this_thread::get_id();
4349 putLogDebug(600117, formatter.str(), __FILE__, __LINE__ );
4351 /*------DEBUG LOG END------*/
4357 //! called from UPSTEEARM thread. make module original message.
4358 //! @param[in] downstream thread id.
4359 //! @return session use EVENT mode
4360 protocol_module_base::EVENT_TAG protocol_module_ip::handle_response_send_inform(
4361 const boost::thread::id thread_id)
4363 /*-------- DEBUG LOG --------*/
4364 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4366 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4367 "handle_response_send_inform(const boost::thread::id thread_id) : "
4368 "return_value = %d. thread id : %d.");
4369 formatter % STOP % boost::this_thread::get_id();
4370 putLogDebug(600118, formatter.str(), __FILE__, __LINE__ );
4372 /*------DEBUG LOG END------*/
4377 //! called from after client connection check. use TCP/IP only. create client send message.
4378 //! @param[in] downstream thread id
4379 //! @param[out] send budffer reference
4380 //! @param[out] send data length
4381 //! @return session use EVENT mode
4382 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_connection_check(
4383 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
4385 /*-------- DEBUG LOG --------*/
4386 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4388 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4389 "handle_client_connection_check(const boost::thread::id thread_id, "
4390 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
4392 formatter % thread_id;
4393 putLogDebug(600119, formatter.str(), __FILE__, __LINE__ );
4395 /*------DEBUG LOG END------*/
4397 EVENT_TAG status = FINALIZE;
4398 thread_data_ptr session_data_ptr;
4399 size_t send_possible_size = 0;
4404 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
4406 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
4407 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4409 boost::format formatter("Invalid thread id. thread id : %d.");
4410 formatter % boost::this_thread::get_id();
4411 putLogError(600081, formatter.str(), __FILE__, __LINE__ );
4415 session_data_ptr = session_thread_it->second;
4418 //data state is HTTP_HEADER
4419 if (session_data_ptr->data_state == HTTP_HEADER)
4421 //set data HTTP_BODY
4422 session_data_ptr->data_state = HTTP_BODY;
4425 //set send possible data size
4426 send_possible_size = std::min(std::min(sendbuffer.size(), session_data_ptr->current_message_rest_size),
4427 session_data_ptr->data_length
4429 //set send data size
4430 datalen = send_possible_size;
4432 /*-------- DEBUG LOG --------*/
4433 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4435 std::string datadump;
4436 dump_memory(session_data_ptr->data_buffer + session_data_ptr->data_offset, send_possible_size, datadump);
4438 boost::format formatter(
4439 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4440 "handle_client_connection_check() : before memcpy (data dump) : "
4441 "data begin = %d, data_size = %d, data = %s");
4442 formatter % session_data_ptr->data_offset % send_possible_size % datadump;
4443 putLogDebug(600120, formatter.str(), __FILE__, __LINE__ );
4445 /*------DEBUG LOG END------*/
4447 //copy send possible data to sendbuffer
4448 memcpy(sendbuffer.data(), session_data_ptr->data_buffer + session_data_ptr->data_offset,
4449 send_possible_size);
4451 /*-------- DEBUG LOG --------*/
4452 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4454 std::string datadump;
4455 dump_memory(sendbuffer.data(), send_possible_size, datadump);
4457 boost::format formatter(
4458 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4459 "handle_client_connection_check() : after memcpy (data dump) : "
4460 "data begin = 0, data_size = %d, data = %s");
4461 formatter % send_possible_size % datadump;
4462 putLogDebug(600121, formatter.str(), __FILE__, __LINE__ );
4464 /*------DEBUG LOG END------*/
4466 //set current message rest size
4467 session_data_ptr->current_message_rest_size -= send_possible_size;
4469 //set buffer's position
4470 session_data_ptr->data_offset += send_possible_size;
4471 session_data_ptr->data_length -= send_possible_size;
4473 //current message rest size is 0
4474 if (session_data_ptr->current_message_rest_size == 0)
4476 boost::mutex::scoped_lock lock(session_data_mutex);
4479 boost::asio::ip::tcp::endpoint init_endpoint;
4481 //write session data to session table
4482 ip_data_processor->write_session_data(session_data_ptr->ip_hash,
4489 status = CLIENT_SEND;
4492 session_data_ptr->last_status = status;
4496 /*-------- DEBUG LOG --------*/
4497 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4499 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4500 "handle_client_connection_check() : catch exception e = %d. thread id : %d.");
4501 formatter % e % boost::this_thread::get_id();
4502 putLogDebug(600122, formatter.str(), __FILE__, __LINE__ );
4504 /*------DEBUG LOG END------*/
4509 catch (const std::exception& ex)
4511 std::cerr << "protocol_module_ip::handle_client_connection_check() : exception : error = " << ex.what() << "." << std::endl;
4512 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4513 "handle_client_connection_check() : exception : error = %s. thread id : %d.");
4514 formatter % ex.what() % boost::this_thread::get_id();
4515 putLogError(600082, formatter.str(), __FILE__, __LINE__ );
4522 std::cerr << "protocol_module_ip::handle_client_connection_check() : Unknown exception." << std::endl;
4523 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4524 "handle_client_connection_check() : Unknown exception. thread id : %d.");
4525 formatter % boost::this_thread::get_id();
4526 putLogError(600083, formatter.str(), __FILE__, __LINE__ );
4532 /*-------- DEBUG LOG --------*/
4533 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4535 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4536 "handle_client_connection_check(const boost::thread::id thread_id, "
4537 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : return_value = %d. thread id : %d.");
4538 formatter % status % boost::this_thread::get_id();
4539 putLogDebug(600123, formatter.str(), __FILE__, __LINE__ );
4541 /*------DEBUG LOG END------*/
4546 //! called from after client select. use UDP only
4547 //! @param[in] downstream thread id
4548 //! @param[in] client udp endpoint
4549 //! @param[out] send buffer reference
4550 //! @param[out] send data length
4551 //! @return session use EVENT mode
4552 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_select(
4553 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,
4554 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
4556 /*-------- DEBUG LOG --------*/
4557 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4559 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4560 "handle_client_select(const boost::thread::id thread_id, "
4561 "boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
4562 "const size_t& datalen) : "
4563 "return_value = %d. thread id : %d.");
4564 formatter % STOP % boost::this_thread::get_id();
4565 putLogDebug(600124, formatter.str(), __FILE__, __LINE__ );
4567 /*------DEBUG LOG END------*/
4571 //! called from after client send
4572 //! @param[in] downstream thread id
4573 //! @return session use EVENT mode
4574 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_send(
4575 const boost::thread::id thread_id)
4577 /*-------- DEBUG LOG --------*/
4578 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4580 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4581 "handle_client_send(const boost::thread::id thread_id) : thread_id = %d.");
4582 formatter % thread_id;
4583 putLogDebug(600125, formatter.str(), __FILE__, __LINE__ );
4585 /*------DEBUG LOG END------*/
4587 EVENT_TAG status = FINALIZE;
4588 size_t http_header_all_offset = 0;
4589 size_t http_header_all_len = 0;
4590 size_t http_header_content_length_offset= 0;
4591 size_t http_header_content_length_len = 0;
4592 const size_t CR_LF_LEN = 2;
4593 const size_t CR_LF_CR_LF_LEN = 4;
4594 int content_length_value = 0;
4596 std::string content_length;
4598 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
4601 bool find_ret = false;
4602 http_utility::CHECK_RESULT_TAG check_ret;
4604 thread_data_ptr session_data_ptr;
4605 session_thread_data_map_it session_thread_it;
4610 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
4613 session_thread_it = session_thread_data_map.find(thread_id);
4614 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4616 boost::format formatter("Invalid thread id. thread id : %d.");
4617 formatter % boost::this_thread::get_id();
4618 putLogError(600084, formatter.str(), __FILE__, __LINE__ );
4622 session_data_ptr = session_thread_it->second;
4625 //current_message_rest_size > 0
4626 if (session_data_ptr->current_message_rest_size > 0)
4629 if (session_data_ptr->data_length > 0)
4632 status = CLIENT_CONNECTION_CHECK;
4638 session_data_ptr->data_offset = 0;
4641 status = REALSERVER_RECV;
4644 //current_message_rest_size is 0
4648 if (session_data_ptr->data_length > 0)
4650 //data state is HTTP_BODY
4651 if (session_data_ptr->data_state == HTTP_BODY)
4653 //search whole http header, get whole http header's offset and length
4654 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
4655 session_data_ptr->data_length,
4656 http_header_all_offset,
4660 /*-------- DEBUG LOG --------*/
4661 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4663 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4664 "handle_client_send() : call find_http_header_all : "
4665 "return_value = %d. thread id : %d.");
4666 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4667 putLogDebug(600126, formatter.str(), __FILE__, __LINE__ );
4669 /*------DEBUG LOG END------*/
4671 //search http header result is NG
4674 //set data state HTTP_START
4675 session_data_ptr->data_state = HTTP_START;
4678 status = REALSERVER_RECV;
4680 //search http header result is OK
4683 //check http version and status code
4684 check_ret = http_utility::check_http_version_and_status_code(session_data_ptr->data_buffer + session_data_ptr->data_offset,
4685 session_data_ptr->data_length);
4687 /*-------- DEBUG LOG --------*/
4688 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4690 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4691 "handle_client_send() : call check_http_version_and_status_code : "
4692 "return_value = %d. thread id : %d.");
4693 formatter % check_ret % boost::this_thread::get_id();
4694 putLogDebug(600127, formatter.str(), __FILE__, __LINE__ );
4696 /*------DEBUG LOG END------*/
4698 //check version and status code result is NG
4699 if (check_ret == http_utility::CHECK_NG)
4701 //set current message rest size
4702 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4704 //set data state UNKNOWN
4705 session_data_ptr->data_state = UNKNOWN;
4707 //check version and status code result is OK
4710 //search Content_Length header
4711 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
4712 session_data_ptr->data_length,
4713 http_header_content_length_offset,
4714 http_header_content_length_len);
4716 /*-------- DEBUG LOG --------*/
4717 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4719 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4720 "handle_client_send() : call find_http_header_content_length : "
4721 "return_value = %d. thread id : %d.");
4722 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4723 putLogDebug(600128, formatter.str(), __FILE__, __LINE__ );
4725 /*------DEBUG LOG END------*/
4727 //search Content_Length result is OK
4730 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
4731 http_header_content_length_len );
4732 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
4734 //"content-length: ddd\r\n"
4737 content_length = content_length.substr(
4738 regex_ret.position(1),
4739 regex_ret.length(1));
4741 //set content length value
4742 content_length_value = boost::lexical_cast<int>(content_length);
4745 //http_header context is "\r\n\r\n" only
4746 if (http_header_all_len == 0)
4748 //set current message rest size
4749 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_LEN;
4753 //set current message rest size
4754 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_CR_LF_LEN;
4757 //search Content_Length result is OK
4760 //http_header context is "\r\n\r\n" only
4761 if (http_header_all_len == 0)
4763 //set current message rest size
4764 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_LEN;
4768 //set current message rest size
4769 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_CR_LF_LEN;
4774 //set data state HTTP_HEADER
4775 session_data_ptr->data_state = HTTP_HEADER;
4779 status = CLIENT_CONNECTION_CHECK;
4782 //data state is UNKNOWN
4783 else if (session_data_ptr->data_state == UNKNOWN)
4786 status = CLIENT_CONNECTION_CHECK;
4792 //data state is HTTP_BODY
4793 if (session_data_ptr->data_state == HTTP_BODY)
4795 //set data state HTTP_START
4796 session_data_ptr->data_state = HTTP_START;
4800 session_data_ptr->data_offset = 0;
4803 status = REALSERVER_RECV;
4807 //switch flag is on and status is REALSERVER_RECV
4808 if (session_data_ptr->switch_flag == SWITCH_FLAG_ON
4809 && status == REALSERVER_RECV)
4812 status = CLIENT_DISCONNECT;
4814 //sorry flag is on and and status is REALSERVER_RECV
4815 else if (session_data_ptr->sorry_flag == SORRY_FLAG_ON
4816 && status == REALSERVER_RECV)
4819 status = SORRYSERVER_RECV;
4827 session_data_ptr->last_status = status;
4831 /*-------- DEBUG LOG --------*/
4832 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4834 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4835 "handle_client_send() : catch exception e = %d. thread id : %d.");
4836 formatter % e % boost::this_thread::get_id();
4837 putLogDebug(600129, formatter.str(), __FILE__, __LINE__ );
4839 /*------DEBUG LOG END------*/
4844 catch (const boost::bad_lexical_cast& )
4846 std::cerr << "protocol_module_ip::handle_client_send() : exception : " << "Content_Length field's value is invalid." << std::endl;
4847 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_send() : "
4848 "Content_Length field's value is invalid. thread id : %d.");
4849 formatter % boost::this_thread::get_id();
4850 putLogError(600085, formatter.str(), __FILE__, __LINE__ );
4855 catch (const std::exception& ex)
4857 std::cerr << "protocol_module_ip::handle_client_send() : exception : error = " << ex.what() << "." << std::endl;
4858 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4859 "handle_client_send() : exception : error = %s. thread id : %d.");
4860 formatter % ex.what() % boost::this_thread::get_id();
4861 putLogError(600086, formatter.str(), __FILE__, __LINE__ );
4868 std::cerr << "protocol_module_ip::handle_client_send() : Unknown exception." << std::endl;
4869 boost::format formatter("function : protocol_module_base::EVENT_TAG "
4870 "protocol_module_ip::handle_client_send() : "
4871 "Unknown exception. thread id : %d.");
4872 formatter % boost::this_thread::get_id();
4873 putLogError(600087, formatter.str(), __FILE__, __LINE__ );
4879 /*-------- DEBUG LOG --------*/
4880 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4882 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4883 "handle_client_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4884 formatter % status % boost::this_thread::get_id();
4885 putLogDebug(600130, formatter.str(), __FILE__, __LINE__ );
4887 /*------DEBUG LOG END------*/
4892 //! call from client disconnect event. use upstream thread and downstream thread.
4893 //! @param[in] upstream and downstream thread id( check! one thread one event! )
4894 //! @return session use EVENT mode
4895 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_disconnect(
4896 const boost::thread::id thread_id)
4898 /*-------- DEBUG LOG --------*/
4899 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4901 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4902 "handle_client_disconnect(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4903 formatter % FINALIZE % boost::this_thread::get_id();
4904 putLogDebug(600131, formatter.str(), __FILE__, __LINE__ );
4906 /*------DEBUG LOG END------*/
4910 //! call from sorry mode event. use upstream thread and downstream thread
4911 //! @param[in] upstream and downstream thread id( check! one thread one event and first time call pattern )
4912 //! @return session use EVENT mode
4913 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorry_enable(
4914 const boost::thread::id thread_id)
4916 /*-------- DEBUG LOG --------*/
4917 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4919 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4920 "handle_sorry_enable(const boost::thread::id thread_id) : thread_id = %d.");
4921 formatter % boost::this_thread::get_id();
4922 putLogDebug(600132, formatter.str(), __FILE__, __LINE__ );
4924 /*------DEBUG LOG END------*/
4926 EVENT_TAG status = FINALIZE;
4927 thread_data_ptr session_data_ptr;
4932 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
4934 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
4935 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4937 boost::format formatter("Invalid thread id. thread id : %d.");
4938 formatter % boost::this_thread::get_id();
4939 putLogError(600088, formatter.str(), __FILE__, __LINE__ );
4943 session_data_ptr = session_thread_it->second;
4948 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
4950 //accept_end_flag is off
4951 if (session_data_ptr->accept_end_flag == ACCEPT_END_FLAG_OFF)
4956 //accept_end_flag is on
4960 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
4962 //data state is HTTP_START or HTTP_HEADER
4963 if (session_data_ptr->data_state == HTTP_START
4964 || session_data_ptr->data_state ==HTTP_HEADER)
4966 //set switch flag on
4967 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
4969 /*-------- DEBUG LOG --------*/
4970 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4972 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4973 "handle_sorry_enable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
4974 formatter % boost::this_thread::get_id();
4975 putLogDebug(600133, formatter.str(), __FILE__, __LINE__ );
4977 /*------DEBUG LOG END------*/
4980 status = SORRYSERVER_DISCONNECT;
4982 //data state is HTTP_BODY or UNKNOWN
4986 status = session_data_ptr->last_status;
4992 //data state is HTTP_START or HTTP_HEADER
4993 if (session_data_ptr->data_state == HTTP_START
4994 || session_data_ptr->data_state ==HTTP_HEADER)
4996 //set switch flag on
4997 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
4999 /*-------- DEBUG LOG --------*/
5000 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5002 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5003 "handle_sorry_enable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5004 formatter % boost::this_thread::get_id();
5005 putLogDebug(600134, formatter.str(), __FILE__, __LINE__ );
5007 /*------DEBUG LOG END------*/
5009 //data state is HTTP_BODY or UNKNOWN
5013 session_data_ptr->end_flag = END_FLAG_ON;
5015 /*-------- DEBUG LOG --------*/
5016 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5018 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5019 "handle_sorry_enable(const boost::thread::id thread_id) : END_FLAG_ON. thread id : %d.");
5020 formatter % boost::this_thread::get_id();
5021 putLogDebug(600135, formatter.str(), __FILE__, __LINE__ );
5023 /*------DEBUG LOG END------*/
5027 status = REALSERVER_DISCONNECT;
5035 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5038 status = session_data_ptr->last_status;
5043 //data state is HTTP_START and data size is 0
5044 if (session_data_ptr->data_state == HTTP_START
5045 && session_data_ptr->data_length == 0)
5048 status = SORRYSERVER_RECV;
5050 //data state is HTTP_START and data size > 0
5051 else if (session_data_ptr->data_state == HTTP_START
5052 && session_data_ptr->data_length > 0)
5055 status = REALSERVER_DISCONNECT;
5057 //data state is HTTP_HEADER or HTTP_BODY
5058 else if (session_data_ptr->data_state == HTTP_HEADER
5059 || session_data_ptr->data_state == HTTP_BODY)
5061 //set switch flag on
5062 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5064 /*-------- DEBUG LOG --------*/
5065 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5067 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5068 "handle_sorry_enable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5069 formatter % boost::this_thread::get_id();
5070 putLogDebug(600136, formatter.str(), __FILE__, __LINE__ );
5072 /*------DEBUG LOG END------*/
5075 status = session_data_ptr->last_status;
5081 status = REALSERVER_DISCONNECT;
5087 session_data_ptr->sorry_flag = SORRY_FLAG_ON;
5089 /*-------- DEBUG LOG --------*/
5090 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5092 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5093 "handle_sorry_enable(const boost::thread::id thread_id) : SORRY_FLAG_ON. thread id : %d.");
5094 formatter % boost::this_thread::get_id();
5095 putLogDebug(600137, formatter.str(), __FILE__, __LINE__ );
5097 /*------DEBUG LOG END------*/
5100 session_data_ptr->last_status = status;
5105 /*-------- DEBUG LOG --------*/
5106 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5108 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5109 "handle_sorry_enable() : catch exception e = %d. thread id : %d.");
5110 formatter % e % boost::this_thread::get_id();
5111 putLogDebug(600138, formatter.str(), __FILE__, __LINE__ );
5113 /*------DEBUG LOG END------*/
5118 catch (std::exception& ex)
5120 std::cerr << "protocol_module_ip::handle_sorry_enable() : exception : error = " << ex.what() << "." << std::endl;
5121 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5122 "handle_sorry_enable() : exception : error = %s. thread id : %d.");
5123 formatter % ex.what() % boost::this_thread::get_id();
5124 putLogError(600089, formatter.str(), __FILE__, __LINE__ );
5131 std::cerr << "protocol_module_ip::handle_sorry_enable() : Unknown exception." << std::endl;
5132 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5133 "protocol_module_ip::handle_sorry_enable() : "
5134 "Unknown exception. thread id : %d.");
5135 formatter % boost::this_thread::get_id();
5136 putLogError(600090, formatter.str(), __FILE__, __LINE__ );
5142 /*-------- DEBUG LOG --------*/
5143 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5145 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5146 "handle_sorry_enable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
5147 formatter % status % boost::this_thread::get_id();
5148 putLogDebug(600139, formatter.str(), __FILE__, __LINE__ );
5150 /*------DEBUG LOG END------*/
5155 //! call from sorry mode disable. use upstream thread and downstream thread.
5156 //! @param[in] upstream and downstream thread id( check! one thread one event )
5157 //! @return session use EVENT mode
5158 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorry_disable(
5159 const boost::thread::id thread_id)
5161 /*-------- DEBUG LOG --------*/
5162 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5164 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5165 "handle_sorry_disable(const boost::thread::id thread_id) : thread_id = %d.");
5166 formatter % boost::this_thread::get_id();
5167 putLogDebug(600140, formatter.str(), __FILE__, __LINE__ );
5169 /*------DEBUG LOG END------*/
5171 EVENT_TAG status = FINALIZE;
5172 thread_data_ptr session_data_ptr;
5177 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
5179 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
5180 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5182 boost::format formatter("Invalid thread id. thread id : %d.");
5183 formatter % boost::this_thread::get_id();
5184 putLogError(600091, formatter.str(), __FILE__, __LINE__ );
5188 session_data_ptr = session_thread_it->second;
5192 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
5194 //accept_end_flag is off
5195 if (session_data_ptr->accept_end_flag == ACCEPT_END_FLAG_OFF)
5200 //accept_end_flag is on
5204 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5206 ///data state is HTTP_START or HTTP_HEADER
5207 if (session_data_ptr->data_state == HTTP_START
5208 || session_data_ptr->data_state ==HTTP_HEADER)
5210 //set switch flag on
5211 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5213 /*-------- DEBUG LOG --------*/
5214 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5216 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5217 "handle_sorry_disable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5218 formatter % boost::this_thread::get_id();
5219 putLogDebug(600141, formatter.str(), __FILE__, __LINE__ );
5221 /*------DEBUG LOG END------*/
5224 //data state is HTTP_BODY or UNKNOWN
5228 session_data_ptr->end_flag = END_FLAG_ON;
5230 /*-------- DEBUG LOG --------*/
5231 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5233 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5234 "handle_sorry_disable(const boost::thread::id thread_id) : END_FLAG_ON. thread id : %d.");
5235 formatter % boost::this_thread::get_id();
5236 putLogDebug(600142, formatter.str(), __FILE__, __LINE__ );
5238 /*------DEBUG LOG END------*/
5242 status = SORRYSERVER_DISCONNECT;
5248 //data state is HTTP_START or HTTP_HEADER
5249 if (session_data_ptr->data_state == HTTP_START
5250 || session_data_ptr->data_state ==HTTP_HEADER)
5252 //set switch flag on
5253 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5255 /*-------- DEBUG LOG --------*/
5256 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5258 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5259 "handle_sorry_disable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5260 formatter % boost::this_thread::get_id();
5261 putLogDebug(600143, formatter.str(), __FILE__, __LINE__ );
5263 /*------DEBUG LOG END------*/
5266 status = REALSERVER_DISCONNECT;
5268 //data state is HTTP_BODY or UNKNOWN
5272 status = session_data_ptr->last_status;
5281 if (session_data_ptr->sorry_flag == SORRY_FLAG_OFF)
5284 status = session_data_ptr->last_status;
5289 //data state is HTTP_START and data size is 0
5290 if (session_data_ptr->data_state == HTTP_START
5291 && session_data_ptr->data_length == 0)
5294 status = REALSERVER_RECV;
5296 //data state is HTTP_START and data size > 0
5297 else if (session_data_ptr->data_state == HTTP_START
5298 && session_data_ptr->data_length > 0)
5301 status = SORRYSERVER_DISCONNECT;
5303 //data state is HTTP_HEADER or HTTP_BODY
5304 else if (session_data_ptr->data_state == HTTP_HEADER
5305 || session_data_ptr->data_state == HTTP_BODY)
5307 //set switch flag on
5308 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5310 /*-------- DEBUG LOG --------*/
5311 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5313 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5314 "handle_sorry_disable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5315 formatter % boost::this_thread::get_id();
5316 putLogDebug(600144, formatter.str(), __FILE__, __LINE__ );
5318 /*------DEBUG LOG END------*/
5321 status = session_data_ptr->last_status;
5327 status = SORRYSERVER_DISCONNECT;
5332 //set sorry flag off
5333 session_data_ptr->sorry_flag = SORRY_FLAG_OFF;
5335 /*-------- DEBUG LOG --------*/
5336 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5338 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5339 "handle_sorry_disable(const boost::thread::id thread_id) : SORRY_FLAG_OFF. thread id : %d.");
5340 formatter % boost::this_thread::get_id();
5341 putLogDebug(600145, formatter.str(), __FILE__, __LINE__ );
5343 /*------DEBUG LOG END------*/
5346 session_data_ptr->last_status = status;
5350 /*-------- DEBUG LOG --------*/
5351 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5353 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5354 "handle_sorry_disable() : catch exception e = %d. thread id : %d.");
5355 formatter % e % boost::this_thread::get_id();
5356 putLogDebug(600146, formatter.str(), __FILE__, __LINE__ );
5358 /*------DEBUG LOG END------*/
5363 catch (std::exception& ex)
5365 std::cerr << "protocol_module_ip::handle_sorry_disable() : exception : error = " << ex.what() << "." << std::endl;
5366 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5367 "handle_sorry_disable() : exception : error = %s. thread id : %d.");
5368 formatter % ex.what() % boost::this_thread::get_id();
5369 putLogError(600092, formatter.str(), __FILE__, __LINE__ );
5376 std::cerr << "protocol_module_ip::handle_sorry_disable() : Unknown exception." << std::endl;
5377 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5378 "protocol_module_ip::handle_sorry_disable() : "
5379 "Unknown exception. thread id : %d.");
5380 formatter % boost::this_thread::get_id();
5381 putLogError(600093, formatter.str(), __FILE__, __LINE__ );
5387 /*-------- DEBUG LOG --------*/
5388 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5390 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5391 "handle_sorry_disable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
5392 formatter % status % boost::this_thread::get_id();
5393 putLogDebug(600147, formatter.str(), __FILE__, __LINE__ );
5395 /*------DEBUG LOG END------*/
5400 //! call from realserver disconnect. use upstream thread and downstream thread
5401 //! @param[in] upstream and downstream thread id( check! one thread one event )
5402 //! @param[in] disconnected realserver endpoint.
5403 //! @return session use EVENT mode
5404 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_disconnect(
5405 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
5407 /*-------- DEBUG LOG --------*/
5408 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5410 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5411 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& rs_endpoint) : "
5412 "thread_id = %d, rs_endpoint = [%s]:%d.");
5413 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
5414 putLogDebug(600148, formatter.str(), __FILE__, __LINE__ );
5416 /*------DEBUG LOG END------*/
5418 EVENT_TAG status = FINALIZE;
5419 thread_data_ptr session_data_ptr;
5424 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
5426 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
5427 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5429 boost::format formatter("Invalid thread id. thread id : %d.");
5430 formatter % boost::this_thread::get_id();
5431 putLogError(600094, formatter.str(), __FILE__, __LINE__ );
5435 session_data_ptr = session_thread_it->second;
5440 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
5443 if (session_data_ptr->end_flag == END_FLAG_ON)
5446 status = CLIENT_RECV;
5452 if (session_data_ptr->switch_flag == SWITCH_FLAG_ON)
5455 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5458 status = SORRYSERVER_SELECT;
5464 status = REALSERVER_SELECT;
5467 //set switch flag off
5468 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
5470 /*-------- DEBUG LOG --------*/
5471 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5473 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5474 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint &" "rs_endpoint) : SWITCH_FLAG_OFF. thread id : %d.");
5475 formatter % boost::this_thread::get_id();
5476 putLogDebug(600149, formatter.str(), __FILE__, __LINE__ );
5478 /*------DEBUG LOG END------*/
5480 //switch flag is off
5484 status = CLIENT_RECV;
5492 status = CLIENT_DISCONNECT;
5496 session_data_ptr->last_status = status;
5500 /*-------- DEBUG LOG --------*/
5501 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5503 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5504 "handle_realserver_disconnect() : catch exception e = %d. thread id : %d.");
5505 formatter % e % boost::this_thread::get_id();
5506 putLogDebug(600150, formatter.str(), __FILE__, __LINE__ );
5508 /*------DEBUG LOG END------*/
5513 catch (std::exception& ex)
5515 std::cerr << "protocol_module_ip::handle_realserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
5516 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5517 "handle_realserver_disconnect() : exception : error = %s. thread id : %d.");
5518 formatter % ex.what() % boost::this_thread::get_id();
5519 putLogError(600095, formatter.str(), __FILE__, __LINE__ );
5526 std::cerr << "protocol_module_ip::handle_realserver_disconnect() : Unknown exception." << std::endl;
5527 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5528 "protocol_module_ip::handle_realserver_disconnect() : "
5529 "Unknown exception. thread id : %d.");
5530 formatter % boost::this_thread::get_id();
5531 putLogError(600096, formatter.str(), __FILE__, __LINE__ );
5537 /*-------- DEBUG LOG --------*/
5538 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5540 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5541 "handle_realserver_disconnect(const boost::thread::id thread_id, "
5542 "const boost::asio::ip::tcp::endpoint& rs_endpoint) : return_value = %d. thread id : %d.");
5543 formatter % status % boost::this_thread::get_id();
5544 putLogDebug(600151, formatter.str(), __FILE__, __LINE__ );
5546 /*------DEBUG LOG END------*/
5551 //! call from sorry server disconnect. use upstraem thread and downstream thread
5552 //! @param[in] upstream and downstream thread id( check! one thread one event )
5553 //! @param[in] disconnect sorryserver endpoint
5554 //! @return session use EVENT mode
5555 //! @return session use EVENT mode
5556 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_disconnect(
5557 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
5560 /*-------- DEBUG LOG --------*/
5561 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5563 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5564 "handle_sorryserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& sorry_endpoint) : "
5565 "thread_id = %d, sorry_endpoint = [%s]:%d.");
5566 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
5567 putLogDebug(600152, formatter.str(), __FILE__, __LINE__ );
5569 /*------DEBUG LOG END------*/
5571 EVENT_TAG status = FINALIZE;
5572 thread_data_ptr session_data_ptr;
5577 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
5579 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
5580 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5582 boost::format formatter("Invalid thread id. thread id : %d.");
5583 formatter % boost::this_thread::get_id();
5584 putLogError(600097, formatter.str(), __FILE__, __LINE__ );
5588 session_data_ptr = session_thread_it->second;
5592 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
5595 if (session_data_ptr->end_flag == END_FLAG_ON)
5598 status = CLIENT_RECV;
5604 if (session_data_ptr->switch_flag == SWITCH_FLAG_ON)
5607 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5610 status = SORRYSERVER_SELECT;
5616 status = REALSERVER_SELECT;
5619 //set switch flag off
5620 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
5622 /*-------- DEBUG LOG --------*/
5623 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5625 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5626 "handle_sorryserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint &" "sorry_endpoint) : SWITCH_FLAG_OFF. thread id : %d.");
5627 formatter % boost::this_thread::get_id();
5628 putLogDebug(600153, formatter.str(), __FILE__, __LINE__ );
5630 /*------DEBUG LOG END------*/
5633 //switch flag is off
5637 status = CLIENT_RECV;
5645 status = CLIENT_DISCONNECT;
5649 session_data_ptr->last_status = status;
5654 /*-------- DEBUG LOG --------*/
5655 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5657 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5658 "handle_sorryserver_disconnect() : catch exception e = %d. thread id : %d.");
5659 formatter % e % boost::this_thread::get_id();
5660 putLogDebug(600154, formatter.str(), __FILE__, __LINE__ );
5662 /*------DEBUG LOG END------*/
5668 catch (std::exception& ex)
5670 std::cerr << "protocol_module_ip::handle_sorryserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
5671 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5672 "handle_sorryserver_disconnect() : exception : error = %s. thread id : %d.");
5673 formatter % ex.what() % boost::this_thread::get_id();
5674 putLogError(600098, formatter.str(), __FILE__, __LINE__ );
5681 std::cerr << "protocol_module_ip::handle_sorryserver_disconnect() : Unknown exception." << std::endl;
5682 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5683 "protocol_module_ip::handle_sorryserver_disconnect() : "
5684 "Unknown exception. thread id : %d.");
5685 formatter % boost::this_thread::get_id();
5686 putLogError(600099, formatter.str(), __FILE__, __LINE__ );
5692 /*-------- DEBUG LOG --------*/
5693 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5695 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5696 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
5697 "const boost::asio::ip::tcp::endpoint& sorry_endpoint) : return_value = %d. thread id : %d.");
5698 formatter % status % boost::this_thread::get_id();
5699 putLogDebug(600155, formatter.str(), __FILE__, __LINE__ );
5701 /*------DEBUG LOG END------*/
5706 //! call from realserver disconnect. use upstream thread and downstream thread.
5707 //! @param[in] upstream and downstream thread id( check! one thread one event )
5708 //! @param[in] disconnect realserver endpoint
5709 //! @return session use EVENT mode.
5710 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_close(
5711 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint & rs_endpoint)
5713 /*-------- DEBUG LOG --------*/
5714 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5716 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5717 "handle_realserver_close(const boost::thread::id thread_id, "
5718 "boost::asio::ip::udp::endpoint& rs_endpoint) : "
5719 "return_value = %d. thread id : %d.");
5720 formatter % STOP % boost::this_thread::get_id();
5721 putLogDebug(600156, formatter.str(), __FILE__, __LINE__ );
5723 /*------DEBUG LOG END------*/
5729 bool protocol_module_ip::get_data_from_recvbuffer(
5730 thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
5732 /*-------- DEBUG LOG --------*/
5733 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5735 boost::format formatter("in_function : bool protocol_module_ip::get_data_from_recvbuffer("
5736 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5737 "const size_t& recvlen) : thread_id = %d.");
5738 formatter % boost::this_thread::get_id();
5739 putLogDebug(600157, formatter.str(), __FILE__, __LINE__);
5741 /*------DEBUG LOG END------*/
5743 char* tmpbuffer = NULL;
5745 //pointer volidate check
5746 if (unlikely(data_ptr == NULL || data_ptr->data_buffer == NULL))
5748 boost::format formatter("Invalid pointer. thread id : %d.");
5749 formatter % boost::this_thread::get_id();
5750 putLogError(600100, formatter.str(), __FILE__, __LINE__ );
5752 /*-------- DEBUG LOG --------*/
5753 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5755 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5756 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5757 "const size_t& recvlen) : return_value = false. thread id : %d.");
5758 formatter % boost::this_thread::get_id();
5759 putLogDebug(600158, formatter.str(), __FILE__, __LINE__ );
5761 /*------DEBUG LOG END------*/
5767 //the new data can append to buffer directly
5768 if (data_ptr->data_buffer_size - data_ptr->data_length - data_ptr->data_offset >= recvlen)
5771 /*-------- DEBUG LOG --------*/
5772 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5774 std::string datadump;
5775 dump_memory(recvbuffer.data(), recvlen, datadump);
5776 boost::format formatter(
5777 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5778 "get_data_from_recvbuffer() : before memcpy (data dump) : "
5779 "data begin = 0, data_size = %d, data = %s");
5780 formatter % recvlen % datadump;
5781 putLogDebug(600159, formatter.str(), __FILE__, __LINE__ );
5783 /*------DEBUG LOG END------*/
5785 memcpy(data_ptr->data_buffer + data_ptr->data_offset + data_ptr->data_length, recvbuffer.data(), recvlen);
5787 /*-------- DEBUG LOG --------*/
5788 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5790 std::string datadump;
5791 dump_memory(data_ptr->data_buffer + data_ptr->data_offset + data_ptr->data_length, recvlen, datadump);
5792 boost::format formatter(
5793 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5794 "get_data_from_recvbuffer() : after memcpy (data dump) : "
5795 "data begin = 0, data_size = %d, data = %s");
5796 formatter % recvlen % datadump;
5797 putLogDebug(600160, formatter.str(), __FILE__, __LINE__ );
5799 /*------DEBUG LOG END------*/
5801 data_ptr->data_length += recvlen;
5803 /*-------- DEBUG LOG --------*/
5804 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5806 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5807 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5808 "const size_t& recvlen) : return_value = true. thread id : %d.");
5809 formatter % boost::this_thread::get_id();
5810 putLogDebug(600161, formatter.str(), __FILE__, __LINE__ );
5812 /*------DEBUG LOG END------*/
5817 //the new data can append to buffer through moving orignal data
5818 if (data_ptr->data_buffer_size - data_ptr->data_length >= recvlen)
5820 memmove(data_ptr->data_buffer, data_ptr->data_buffer + data_ptr->data_offset, data_ptr->data_length);
5821 /*-------- DEBUG LOG --------*/
5822 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5824 std::string datadump;
5825 dump_memory(recvbuffer.data(), recvlen, datadump);
5826 boost::format formatter(
5827 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5828 "get_data_from_recvbuffer() : before memcpy (data dump) : "
5829 "data begin = 0, data_size = %d, data = %s");
5830 formatter % recvlen % datadump;
5831 putLogDebug(600162, formatter.str(), __FILE__, __LINE__ );
5833 /*------DEBUG LOG END------*/
5835 memcpy(data_ptr->data_buffer + data_ptr->data_length, recvbuffer.data(), recvlen);
5837 /*-------- DEBUG LOG --------*/
5838 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5840 std::string datadump;
5841 dump_memory(data_ptr->data_buffer + data_ptr->data_length, recvlen, datadump);
5842 boost::format formatter(
5843 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5844 "get_data_from_recvbuffer() : after memcpy (data dump) : "
5845 "data begin = 0, data_size = %d, data = %s");
5846 formatter % recvlen % datadump;
5847 putLogDebug(600163, formatter.str(), __FILE__, __LINE__ );
5849 /*------DEBUG LOG END------*/
5851 data_ptr->data_offset = 0;
5852 data_ptr->data_length += recvlen;
5854 /*-------- DEBUG LOG --------*/
5855 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5857 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5858 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5859 "const size_t& recvlen) : return_value = true. thread id : %d.");
5860 formatter % boost::this_thread::get_id();
5861 putLogDebug(600164, formatter.str(), __FILE__, __LINE__ );
5863 /*------DEBUG LOG END------*/
5869 //not allowed to realloc new buffer who's size is larger than the max size
5870 if (data_ptr->data_buffer_size >= MAX_IP_MODULE_BUFFER_SIZE
5871 || data_ptr->data_buffer_size + recvlen >= MAX_IP_MODULE_BUFFER_SIZE)
5873 boost::format formatter("Buffer size is bigger than Max size. thread id : %d.");
5874 formatter % boost::this_thread::get_id();
5875 putLogError(600101, formatter.str(), __FILE__, __LINE__ );
5877 /*-------- DEBUG LOG --------*/
5878 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5880 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5881 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5882 "const size_t& recvlen) : return_value = false. thread id : %d.");
5883 formatter % boost::this_thread::get_id();
5884 putLogDebug(600165, formatter.str(), __FILE__, __LINE__ );
5886 /*------DEBUG LOG END------*/
5894 /*-------- DEBUG LOG --------*/
5895 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5897 boost::format formatter("new : address = &(%d), size = %lu.");
5898 formatter % static_cast<void*>(tmpbuffer) % MAX_IP_MODULE_BUFFER_SIZE;
5899 putLogDebug(600166, formatter.str(), __FILE__, __LINE__);
5901 /*------DEBUG LOG END------*/
5903 //alloc a new buffer who's size is max
5904 tmpbuffer = new char[MAX_IP_MODULE_BUFFER_SIZE];
5906 catch (const std::bad_alloc&) //memory alloc fail
5908 std::cerr << "protocol_module_ip::get_data_from_recvbuffer() : exception : Could not allocate memory." << std::endl;
5909 boost::format formatter("Could not allocate memory. thread id : %d.");
5910 formatter % boost::this_thread::get_id();
5911 putLogError(600102, formatter.str(), __FILE__, __LINE__);
5913 /*-------- DEBUG LOG --------*/
5914 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5916 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5917 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5918 "const size_t& recvlen) : return_value = false. thread id : %d.");
5919 formatter % boost::this_thread::get_id();
5920 putLogDebug(600167, formatter.str(), __FILE__, __LINE__ );
5922 /*------DEBUG LOG END------*/
5927 memset(tmpbuffer, 0, MAX_IP_MODULE_BUFFER_SIZE);
5929 /*-------- DEBUG LOG --------*/
5930 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5932 std::string datadump;
5933 dump_memory(data_ptr->data_buffer+data_ptr->data_offset, data_ptr->data_length, datadump);
5934 boost::format formatter(
5935 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5936 "get_data_from_recvbuffer() : before memcpy (data dump) : "
5937 "data begin = 0, data_size = %d, data = %s");
5938 formatter % data_ptr->data_length % datadump;
5939 putLogDebug(600168, formatter.str(), __FILE__, __LINE__ );
5941 /*------DEBUG LOG END------*/
5943 //copy old data to new buffer
5944 memcpy(tmpbuffer, data_ptr->data_buffer+data_ptr->data_offset, data_ptr->data_length);
5946 /*-------- DEBUG LOG --------*/
5947 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5949 std::string datadump;
5950 dump_memory(tmpbuffer, data_ptr->data_length, datadump);
5951 boost::format formatter(
5952 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5953 "get_data_from_recvbuffer() : after memcpy (data dump) : "
5954 "data begin = 0, data_size = %d, data = %s");
5955 formatter % data_ptr->data_length % datadump;
5956 putLogDebug(600169, formatter.str(), __FILE__, __LINE__ );
5958 /*------DEBUG LOG END------*/
5960 /*-------- DEBUG LOG --------*/
5961 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5963 boost::format formatter("delete : address = &(%d).");
5964 formatter % static_cast<void*>(data_ptr->data_buffer);
5965 putLogDebug(600170, formatter.str(), __FILE__, __LINE__);
5967 /*------DEBUG LOG END------*/
5969 //release old memory
5970 delete [] data_ptr->data_buffer;
5971 data_ptr->data_buffer = tmpbuffer;
5972 data_ptr->data_offset = 0;
5974 /*-------- DEBUG LOG --------*/
5975 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5977 std::string datadump;
5978 dump_memory(recvbuffer.data(), recvlen, datadump);
5979 boost::format formatter(
5980 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5981 "get_data_from_recvbuffer() : before memcpy (data dump) : "
5982 "data begin = 0, data_size = %d, data = %s");
5983 formatter % recvlen % datadump;
5984 putLogDebug(600171, formatter.str(), __FILE__, __LINE__ );
5986 /*------DEBUG LOG END------*/
5989 memcpy(data_ptr->data_buffer+data_ptr->data_length, recvbuffer.data(), recvlen);
5991 /*-------- DEBUG LOG --------*/
5992 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5994 std::string datadump;
5995 dump_memory(data_ptr->data_buffer+data_ptr->data_length, recvlen, datadump);
5996 boost::format formatter(
5997 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5998 "get_data_from_recvbuffer() : after memcpy (data dump) : "
5999 "data begin = 0, data_size = %d, data = %s");
6000 formatter % recvlen % datadump;
6001 putLogDebug(600172, formatter.str(), __FILE__, __LINE__ );
6003 /*------DEBUG LOG END------*/
6005 data_ptr->data_length += recvlen;
6006 data_ptr->data_buffer_size = MAX_IP_MODULE_BUFFER_SIZE ;
6008 /*-------- DEBUG LOG --------*/
6009 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6011 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
6012 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
6013 "const size_t& recvlen) : return_value = true. thread id : %d.");
6014 formatter % boost::this_thread::get_id();
6015 putLogDebug(600173, formatter.str(), __FILE__, __LINE__ );
6017 /*------DEBUG LOG END------*/
6026 bool protocol_module_ip::put_data_into_sendbuffer(
6027 thread_data_ptr data_ptr, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6029 /*-------- DEBUG LOG --------*/
6030 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6032 boost::format formatter("in_function : bool protocol_module_ip::put_data_to_sendbuffer("
6033 "thread_data_ptr data_ptr, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6034 "size_t& datalen) : thread_id = %d.");
6035 formatter % boost::this_thread::get_id();
6036 putLogDebug(600174, formatter.str(), __FILE__, __LINE__);
6038 /*------DEBUG LOG END------*/
6040 size_t sendbuffer_rest_size = 0;
6041 size_t new_offset = 0;
6043 if (unlikely(data_ptr == NULL || data_ptr->data_buffer == NULL || data_ptr->buffer_sequence.empty()))
6045 boost::format formatter("Invalid pointer. thread id : %d.");
6046 formatter % boost::this_thread::get_id();
6047 putLogError(600103, formatter.str(), __FILE__, __LINE__ );
6049 /*-------- DEBUG LOG --------*/
6050 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6052 boost::format formatter("out_function : bool protocol_module_ip::put_data_to_sendbuffer("
6053 "thread_data_ptr data_ptr, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6054 "size_t& datalen) : return_value = false. thread_id = %d.");
6055 formatter % boost::this_thread::get_id();
6056 putLogDebug(600175, formatter.str(), __FILE__, __LINE__);
6058 /*------DEBUG LOG END------*/
6063 sendbuffer_rest_size = sendbuffer.size();
6066 //buffer_sequence loop
6067 //copy data to send buffer until send buffer is full
6068 while (data_ptr->buffer_sequence.size() > 0)
6070 std::pair<char*, size_t> buffer_element = data_ptr->buffer_sequence.front();
6071 //sendbuffer rest size id bigger than copy possible size
6072 if (buffer_element.second <= sendbuffer_rest_size)
6074 /*-------- DEBUG LOG --------*/
6075 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6077 std::string datadump;
6078 dump_memory(buffer_element.first, buffer_element.second, datadump);
6079 boost::format formatter(
6080 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6081 "put_data_to_sendbuffer() : before memcpy (data dump) : "
6082 "data begin = 0, data_size = %d, data = %s");
6083 formatter % buffer_element.second % datadump;
6084 putLogDebug(600176, formatter.str(), __FILE__, __LINE__ );
6086 /*------DEBUG LOG END------*/
6088 //copy data to send buffer
6089 memcpy(sendbuffer.c_array() + datalen, buffer_element.first, buffer_element.second);
6091 /*-------- DEBUG LOG --------*/
6092 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6094 std::string datadump;
6095 dump_memory(sendbuffer.c_array() + datalen, buffer_element.second, datadump);
6096 boost::format formatter(
6097 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6098 "put_data_to_sendbuffer() : after memcpy (data dump) : "
6099 "data begin = 0, data_size = %d, data = %s");
6100 formatter % buffer_element.second % datadump;
6101 putLogDebug(600177, formatter.str(), __FILE__, __LINE__ );
6103 /*------DEBUG LOG END------*/
6105 datalen += buffer_element.second;
6106 sendbuffer_rest_size -= buffer_element.second;
6108 //it is the last item of the sequence
6109 if (data_ptr->buffer_sequence.size() == 1)
6112 new_offset = buffer_element.first + buffer_element.second - data_ptr->data_buffer;
6113 data_ptr->current_message_rest_size -= (new_offset - data_ptr->data_offset);
6114 data_ptr->data_length -= (new_offset - data_ptr->data_offset);
6115 data_ptr->data_offset = new_offset;
6120 data_ptr->buffer_sequence.pop_front();
6122 //sendbuffer rest size is too small
6125 /*-------- DEBUG LOG --------*/
6126 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6128 std::string datadump;
6129 dump_memory(buffer_element.first, sendbuffer_rest_size, datadump);
6130 boost::format formatter(
6131 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6132 "put_data_to_sendbuffer() : before memcpy (data dump) : "
6133 "data begin = 0, data_size = %d, data = %s");
6134 formatter % sendbuffer_rest_size % datadump;
6135 putLogDebug(600178, formatter.str(), __FILE__, __LINE__ );
6137 /*------DEBUG LOG END------*/
6139 //copy data to send buffer
6140 memcpy(sendbuffer.c_array() + datalen, buffer_element.first, sendbuffer_rest_size);
6142 /*-------- DEBUG LOG --------*/
6143 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6145 std::string datadump;
6146 dump_memory(sendbuffer.c_array() + datalen, sendbuffer_rest_size, datadump);
6147 boost::format formatter(
6148 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6149 "put_data_to_sendbuffer() : after memcpy (data dump) : "
6150 "data begin = 0, data_size = %d, data = %s");
6151 formatter % sendbuffer_rest_size % datadump;
6152 putLogDebug(600179, formatter.str(), __FILE__, __LINE__ );
6154 /*------DEBUG LOG END------*/
6156 datalen += sendbuffer_rest_size;
6159 buffer_element.first += sendbuffer_rest_size;
6160 buffer_element.second -= sendbuffer_rest_size;
6161 sendbuffer_rest_size = 0;
6166 /*-------- DEBUG LOG --------*/
6167 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6169 boost::format formatter("out_function : bool protocol_module_ip::put_data_to_sendbuffer("
6170 "thread_data_ptr data_ptr, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6171 "size_t& datalen) : return_value = true. thread_id = %d.");
6172 formatter % boost::this_thread::get_id();
6173 putLogDebug(600180, formatter.str(), __FILE__, __LINE__);
6175 /*------DEBUG LOG END------*/
6183 //! call from put_data_to_buffer_with_x_forwarded_for(). get x_forwarded_for header's offset and length
6184 //! if the buffer isn't include x_forwarded_for header, create a new one
6185 //! @param[in] buffer
6186 //! @param[in] buffer_len
6187 //! @param[out] x_forwarded_for_insert_pos
6188 //! @param[out] x_forwarded_for_context
6189 //! @return true:create a new x_forwarded_for header
6190 //! false: edit old one
6191 bool protocol_module_ip::create_x_forwarded_for(const std::string& client_endpoint,
6193 const size_t buffer_len,
6194 size_t& x_forwarded_for_insert_pos,
6195 std::string& x_forwarded_for_context)
6197 /*-------- DEBUG LOG --------*/
6198 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6200 boost::format formatter("in_function : bool protocol_module_ip::create_x_forwarded_for("
6201 "const std::string& client_endpoint, const char* buffer, const size_t buffer_len, "
6202 "size_t& x_forwarded_for_insert_pos, std::string& x_forwarded_for_context) : thread_id = %d.");
6203 formatter % boost::this_thread::get_id();
6204 putLogDebug(600181, formatter.str(), __FILE__, __LINE__);
6206 /*------DEBUG LOG END------*/
6208 bool find_ret = false;
6209 size_t x_forwarded_for_offset = 0;
6210 size_t x_forwarded_for_len = 0;
6211 size_t http_header_all_offset = 0;
6212 size_t http_header_all_len = 0;
6213 const char* X_FORWARDED_FOR = "X-Forwarded-For";
6215 //search "X-Forwared-For" header
6216 find_ret = http_utility::find_http_header_x_forwarded_for(buffer, buffer_len,
6217 x_forwarded_for_offset, x_forwarded_for_len);
6219 /*-------- DEBUG LOG --------*/
6220 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6222 boost::format formatter("function : bool protocol_module_ip::create_x_forwarded_for() : "
6223 "call find_http_header_x_forwarded_for : "
6224 "return_value = %d. thread id : %d.");
6225 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
6226 putLogDebug(600182, formatter.str(), __FILE__, __LINE__ );
6228 /*------DEBUG LOG END------*/
6230 //search "X-Forwared-For" result is OK
6233 //create "X-Forwared-For" string
6234 x_forwarded_for_insert_pos = x_forwarded_for_offset + x_forwarded_for_len;
6235 x_forwarded_for_context = ", ";
6236 x_forwarded_for_context += client_endpoint;
6238 /*-------- DEBUG LOG --------*/
6239 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6241 boost::format formatter("out_function : bool protocol_module_ip::create_x_forwarded_for("
6242 "const std::string& client_endpoint, const char* buffer, const size_t buffer_len, "
6243 "size_t& x_forwarded_for_insert_pos, std::string& x_forwarded_for_context) : return_value = false. thread_id = %d.");
6244 formatter % boost::this_thread::get_id();
6245 putLogDebug(600183, formatter.str(), __FILE__, __LINE__);
6247 /*------DEBUG LOG END------*/
6253 //because state is HTTP_HEADER, find_http_header_all must be return true
6254 http_utility::find_http_header_all(buffer, buffer_len, http_header_all_offset, http_header_all_len);
6256 /*-------- DEBUG LOG --------*/
6257 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6259 boost::format formatter("function : bool protocol_module_ip::create_x_forwarded_for() : "
6260 "call find_http_header_all : "
6261 "return_value = true. thread id : %d.");
6262 formatter % boost::this_thread::get_id();
6263 putLogDebug(600184, formatter.str(), __FILE__, __LINE__ );
6265 /*------DEBUG LOG END------*/
6267 //create "X-Forwared-For" string
6268 x_forwarded_for_insert_pos = http_header_all_offset;
6269 x_forwarded_for_context = X_FORWARDED_FOR;
6270 x_forwarded_for_context += ": ";
6271 x_forwarded_for_context += client_endpoint;
6272 x_forwarded_for_context += "\r\n";
6274 /*-------- DEBUG LOG --------*/
6275 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6277 boost::format formatter("out_function : bool protocol_module_ip::create_x_forwarded_for("
6278 "const std::string& client_endpoint, const char* buffer, const size_t buffer_len, "
6279 "size_t& x_forwarded_for_insert_pos, std::string& x_forwarded_for_context) : return_value = true. thread_id = %d.");
6280 formatter % boost::this_thread::get_id();
6281 putLogDebug(600185, formatter.str(), __FILE__, __LINE__);
6283 /*------DEBUG LOG END------*/
6292 extern "C" l7vs::protocol_module_base*
6295 return dynamic_cast<l7vs::protocol_module_base*>(new l7vs::protocol_module_ip());
6299 destroy_module( l7vs::protocol_module_base* in )