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),
63 realserver_connect_failed_max_count(REALSERVER_CONNECT_FAILED_COUNT)
65 sorry_uri.assign('\0');
69 protocol_module_ip::~protocol_module_ip()
72 //! tcp protocol support check
73 //! @return tcp support is true
74 //! @return tcp not-support is false
75 bool protocol_module_ip::is_tcp()
77 /*-------- DEBUG LOG --------*/
78 if (unlikely(LOG_LV_DEBUG == getloglevel()))
80 putLogDebug(600000, "in/out_function : bool protocol_module_ip::is_tcp() : return_value = true.",
83 /*------DEBUG LOG END------*/
87 //! udp protocol support check
88 //! @return udp support is true
89 //! @return udp not-support is false
90 bool protocol_module_ip::is_udp()
92 /*-------- DEBUG LOG --------*/
93 if (unlikely(LOG_LV_DEBUG == getloglevel()))
95 putLogDebug(600001, "in/out_function : bool protocol_module_ip::is_udp() : return_value = false.",
98 /*------DEBUG LOG END------*/
102 //! replication interval interrrupt
103 //! timer thread call this function. from virtualservice.
104 void protocol_module_ip::replication_interrupt()
106 /*-------- DEBUG LOG --------*/
107 if (unlikely(LOG_LV_DEBUG == getloglevel()))
109 putLogDebug(600002, "in/out_function : void protocol_module_ip::"
110 "replication_interrupt().", __FILE__, __LINE__ );
112 /*------DEBUG LOG END------*/
114 //! initialize function. called from module control. module loaded call
115 //! @param[in] realserver list iterator begin function object type
116 //! @param[in] realserver list iterator end function object type
117 //! @param[in] realserver list iterator next function object type
118 //! @param[in] realserver list mutex lock function object type.
119 //! @param[in] realserver list mutex unlock function object type
120 void protocol_module_ip::initialize(rs_list_itr_func_type inlist_begin,
121 rs_list_itr_func_type inlist_end,
122 rs_list_itr_next_func_type inlist_next,
123 boost::function< void( void ) > inlist_lock,
124 boost::function< void( void ) > inlist_unlock)
126 /*-------- DEBUG LOG --------*/
127 if (unlikely(LOG_LV_DEBUG == getloglevel()))
129 putLogDebug(600003, "in_function : void protocol_module_ip::initialize("
130 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
131 "rs_list_itr_next_func_type inlist_next, boost::function< void(void) > "
132 "inlist_lock, boost::function< void(void) > inlist_unlock).", __FILE__, __LINE__);
134 /*------DEBUG LOG END------*/
136 //RealServer list begin function
137 rs_list_begin = inlist_begin;
138 //RealServer list end function
139 rs_list_end = inlist_end;
140 //RealServer list next function
141 rs_list_next = inlist_next;
142 //RealServer list lock funtion
143 rs_list_lock = inlist_lock;
144 //RealServer list unlock funtion
145 rs_list_unlock = inlist_unlock;
147 /*-------- DEBUG LOG --------*/
148 if (unlikely(LOG_LV_DEBUG == getloglevel()))
150 putLogDebug(600004, "out_function : void protocol_module_ip::initialize("
151 "rs_list_itr_func_type inlist_begin, rs_list_itr_func_type inlist_end, "
152 "rs_list_itr_next_func_type inlist_next, boost::function< void(void) > "
153 "inlist_lock, boost::function< void(void) > inlist_unlock).", __FILE__, __LINE__);
155 /*------DEBUG LOG END------*/
158 //! finalize called from module control. module unloaded call.
159 void protocol_module_ip::finalize()
161 /*-------- DEBUG LOG --------*/
162 if (unlikely(LOG_LV_DEBUG == getloglevel()))
164 putLogDebug(600005, "in_function : void protocol_module_ip::finalize().", __FILE__, __LINE__);
166 /*------DEBUG LOG END------*/
168 //RealServer list functions initializtion
169 //RealServer list begin function
170 rs_list_begin.clear();
171 //RealServer list end function
173 //RealServer list next function
174 rs_list_next.clear();
175 //RealServer list lock function
176 rs_list_lock.clear();
177 //RealServer list unlock function
178 rs_list_unlock.clear();
180 //Replication functions initializtion
181 //component memory allcate function
182 replication_pay_memory.clear();
183 //component memory lock function
184 replication_area_lock.clear();
185 //component memory unlock function
186 replication_area_unlock.clear();
188 /*-------- DEBUG LOG --------*/
189 if (unlikely(LOG_LV_DEBUG == getloglevel()))
191 putLogDebug(600006, "function : void protocol_module_ip::finalize() : "
192 "rs_list_begin.clear(), rs_list_end.clear(), rs_list_next.clear(), "
193 "rs_list_lock.clear(), rs_list_unlock.clear() end.", __FILE__, __LINE__);
195 /*------DEBUG LOG END------*/
197 //ScheduleModule's functions initializtion
198 schedule_tcp.clear();
200 /*-------- DEBUG LOG --------*/
201 if (unlikely(LOG_LV_DEBUG == getloglevel()))
203 putLogDebug(600007, "function : void protocol_module_ip::finalize() : "
204 "schedule_tcp.clear() end.", __FILE__, __LINE__);
206 /*------DEBUG LOG END------*/
208 //Module's option initializtion
210 forwarded_for = FORWARDED_FOR_OFF;
212 sorry_uri.assign('\0');
218 // replication initialize
219 if (replication_data_processor)
221 /*-------- DEBUG LOG --------*/
222 if (unlikely(LOG_LV_DEBUG == getloglevel()))
224 boost::format formatter("delete : address = &(%d).");
225 formatter % static_cast<void*>(replication_data_processor);
226 putLogDebug(600008, formatter.str(), __FILE__, __LINE__);
228 /*------DEBUG LOG END------*/
230 delete replication_data_processor;
231 replication_data_processor = NULL;
234 // session initialize
235 if (ip_data_processor)
237 /*-------- DEBUG LOG --------*/
238 if (unlikely(LOG_LV_DEBUG == getloglevel()))
240 boost::format formatter("delete : address = &(%d).");
241 formatter % static_cast<void*>(ip_data_processor);
242 putLogDebug(600009, formatter.str(), __FILE__, __LINE__);
244 /*------DEBUG LOG END------*/
246 delete ip_data_processor;
247 ip_data_processor = NULL;
250 /*-------- DEBUG LOG --------*/
251 if (unlikely(LOG_LV_DEBUG == getloglevel()))
253 putLogDebug(600010, "out_function : void protocol_module_ip::finalize().", __FILE__, __LINE__);
255 /*------DEBUG LOG END------*/
257 //logger functions initializtion
258 //log level getting function
272 //! sorry support check
273 //! @return true sorry mode is supported.
274 //! @return false sorry mode is unsupported.
275 bool protocol_module_ip::is_use_sorry()
277 /*-------- DEBUG LOG --------*/
278 if (unlikely(LOG_LV_DEBUG == getloglevel()))
280 putLogDebug(600011, "in/out_function : bool protocol_module_ip::is_use_sorry() : return_value = true.",
283 /*------DEBUG LOG END------*/
287 //! realserver list update event
288 void protocol_module_ip::handle_rslist_update()
290 /*-------- DEBUG LOG --------*/
291 if (unlikely(LOG_LV_DEBUG == getloglevel()))
293 putLogDebug(600012, "in/out_function : void protocol_module_ip::handle_rslist_update().",
296 /*------DEBUG LOG END------*/
299 //! module parameter check.used by l7vsadm
300 //! @param[in] module paramter string list
301 //! @return result.flag true is parameter is noproblem.
302 //! @return result.flag false is paramter is problem.
303 protocol_module_base::check_message_result protocol_module_ip::check_parameter(const std::vector<
306 /*-------- DEBUG LOG --------*/
307 if (unlikely(LOG_LV_DEBUG == getloglevel()))
309 boost::format formatter("in_function : protocol_module_ip::check_message_result "
310 "protocol_module_ip::check_parameter("
311 "const std::vector<std::string>& args) : args = %s.");
312 std::string argsdump;
313 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
317 formatter % argsdump;
318 putLogDebug(600013, formatter.str(), __FILE__, __LINE__);
320 /*------DEBUG LOG END------*/
322 //set check result true
323 // set check result flag true
324 check_message_result check_result;
325 check_result.flag = true;
326 bool timeout_flag = false;
327 bool reschedule_flag = false;
328 bool no_reschedule_flag = false;
329 bool forward_checked = false;
330 bool sorryuri_checked = false;
331 sregex sorry_uri_regex
335 ( set = ';', ':', '@', '&', '=' ) |
336 ( set = '$', '-', '_', '.', '+' ) |
337 ( set = '!', '*', '\'', '\(', ')', ',' ) |
338 '%' >> repeat<2>(xdigit)));
340 typedef std::vector<std::string>::const_iterator vec_str_it;
344 vec_str_it it = args.begin();
345 vec_str_it it_end = args.end();
346 boost::format formatter;
348 //loop option strings
349 for (; it != it_end;)
351 if (*it == "-T" || *it == "--timeout")
356 // not set timeout option
358 // next parameter exist check
361 // next parameter exist
362 if ((*it).substr(0, 1) == "-" || (*it).substr(0, 2) == "--")
369 unsigned long ultimeout = 0;
370 ultimeout = boost::lexical_cast<unsigned long>(*it);
371 // int maxvalue check
372 if (ultimeout > INT_MAX)
374 check_result.flag = false;
375 formatter.parse("'-T/--timeout' option value '%s' is too large.");
377 check_result.message = formatter.str();
378 putLogError(600000, check_result.message, __FILE__, __LINE__);
388 catch (boost::bad_lexical_cast& e)
390 // not numeric character
391 check_result.flag = false;
392 formatter.parse("'-T/--timeout' option value '%s' is not numeric character.");
394 check_result.message = formatter.str();
395 putLogError(600001, check_result.message, __FILE__, __LINE__);
406 // already set timeout
407 check_result.flag = false;
408 check_result.message = "Cannot set multiple option '-T/--timeout'.";
409 putLogError(600002, check_result.message, __FILE__, __LINE__);
413 else if (*it == "-R" || *it == "--reschedule")
416 if (!no_reschedule_flag)
418 // not set no-reschedule flag
419 reschedule_flag = true;
423 // already set no-reschedule flag
424 check_result.flag = false;
425 check_result.message = "You have to choose either of reschedule or no-reschedule.";
426 putLogError(600003, check_result.message, __FILE__, __LINE__);
430 else if (*it == "-N" || *it == "--no-reschedule")
433 if (!reschedule_flag)
435 // not set reschedule flag
436 no_reschedule_flag = true;
440 // already set reshcedule flag
441 check_result.flag = false;
442 check_result.message = "You have to choose either of reschedule or no-reschedule.";
443 putLogError(600004, check_result.message, __FILE__, __LINE__);
447 //option string = "-F"
448 else if (*it == "-F" || *it == "--forwarded-for")
450 //set forward flag ON
451 forward_checked = true;
453 //option string = "-S"
454 else if (*it == "-S" || *it == "--sorry-uri")
456 //set sorryURI flag OFF
457 if (!sorryuri_checked)
462 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
464 //set check result flag false
465 check_result.flag = false;
466 //set check result message
467 check_result.message = "You have to set option value '-S/--sorry-uri'.";
468 putLogError(600005, check_result.message, __FILE__, __LINE__ );
472 //next option string's length > 127
473 if (it->size() > MAX_OPTION_SIZE - 1)
475 std::ostringstream ostr;
476 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
478 //set check result flag false
479 check_result.flag = false;
480 //set check result message
481 check_result.message = ostr.str();
482 putLogError(600006, check_result.message, __FILE__, __LINE__ );
486 //next option string's length <= 127
490 if (regex_match(*it, sorry_uri_regex ))
493 //set sorryURI flag ON
494 sorryuri_checked = true;
499 std::ostringstream ostr;
500 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
502 //set check result flag false
503 check_result.flag = false;
504 //set check result message
505 check_result.message = ostr.str();
506 putLogError(600007, check_result.message, __FILE__, __LINE__ );
511 //next item is not exist
514 //set check flag false
515 check_result.flag = false;
516 //set check result message
517 check_result.message = "You have to set option value '-S/--sorry-uri'.";
518 putLogError(600008, check_result.message, __FILE__,
527 //set check result flag false
528 check_result.flag = false;
529 //set check result message
530 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
531 putLogError(600009, check_result.message, __FILE__,
537 //other option string
540 //set check result flag false
541 check_result.flag = false;
542 //set check result message
543 check_result.message = "Option error.";
544 putLogError(600010, check_result.message, __FILE__, __LINE__ );
552 catch (const std::exception& ex)
554 check_result.flag = false;
555 std::cerr << "protocol_module_ip::check_parameter() : exception : error = " << ex.what() << "." << std::endl;
556 boost::format formatter("function : protocol_module_base::check_message_result "
557 "protocol_module_ip::check_parameter() exception : "
559 formatter % ex.what();
560 putLogError(600011, formatter.str(), __FILE__, __LINE__ );
564 check_result.flag = false;
565 std::cerr << "protocol_module_ip::check_parameter() : Unknown exception." << std::endl;
566 putLogError(600012, "function : protocol_module_base::check_message_result "
567 "protocol_module_ip::check_parameter() : "
568 "Unknown exception.", __FILE__, __LINE__ );
571 /*-------- DEBUG LOG --------*/
572 if (unlikely(LOG_LV_DEBUG == getloglevel()))
574 boost::format formatter("out_function : protocol_module_base::check_message_result "
575 "protocol_module_ip::check_parameter("
576 "const std::vector<std::string>& args) : return_value = ("
577 "check_message_result.flag = %d, check_message_result.message = %s).");
578 formatter % check_result.flag % check_result.message;
579 putLogDebug(600014, formatter.str(), __FILE__, __LINE__ );
581 /*------DEBUG LOG END------*/
587 //! @param[in] module paramter string list
588 //! @return result.flag true is parameter is noproblem.
589 //! @return result.flag false is paramter is problem.
590 protocol_module_base::check_message_result protocol_module_ip::set_parameter(const std::vector<
593 /*-------- DEBUG LOG --------*/
594 if (unlikely(LOG_LV_DEBUG == getloglevel()))
596 boost::format formatter("in_function : protocol_module_base::check_message_result "
597 "protocol_module_ip::set_parameter("
598 "const std::vector<std::string>& args) : args = %s.");
599 std::string argsdump;
600 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
605 formatter % argsdump;
606 putLogDebug(600015, formatter.str(), __FILE__, __LINE__ );
608 /*------DEBUG LOG END------*/
610 //set check result flag true
611 check_message_result check_result;
612 check_result.flag = true;
613 bool timeout_flag = false;
614 bool reschedule_flag = false;
615 bool no_reschedule_flag = false;
616 bool forward_checked = false;
617 bool sorryuri_checked = false;
618 boost::format formatter;
619 sregex sorry_uri_regex
623 ( set = ';', ':', '@', '&', '=' ) |
624 ( set = '$', '-', '_', '.', '+' ) |
625 ( set = '!', '*', '\'', '\(', ')', ',' ) |
626 '%' >> repeat<2>(xdigit)));
628 typedef std::vector<std::string>::const_iterator vec_str_it;
630 //set forwarded flag true
635 vec_str_it it = args.begin();
636 vec_str_it it_end = args.end();
638 for (; it != it_end;)
641 if (*it == "-T" || *it == "--timeout")
646 // not set timeout option
648 // next parameter exist check
651 // next parameter exist
652 if ((*it).substr(0, 1) == "-" || (*it).substr(0, 2) == "--")
659 unsigned long ultimeout = 0;
660 ultimeout = boost::lexical_cast<unsigned long>(*it);
661 // int maxvalue check
662 if (ultimeout > INT_MAX)
664 check_result.flag = false;
665 formatter.parse("'-T/--timeout' option value '%s' is too large.");
667 check_result.message = formatter.str();
668 putLogError(600013, check_result.message, __FILE__, __LINE__);
679 catch (boost::bad_lexical_cast& e)
681 // not numeric character
682 check_result.flag = false;
683 formatter.parse("'-T/--timeout' option value '%s' is not numeric character.");
685 check_result.message = formatter.str();
686 putLogError(600014, check_result.message, __FILE__, __LINE__);
697 // already set timeout
698 check_result.flag = false;
699 check_result.message = "Cannot set multiple option '-T/--timeout'.";
700 putLogError(600015, check_result.message, __FILE__, __LINE__);
705 else if (*it == "-R" || *it == "--reschedule")
708 if (!no_reschedule_flag)
710 // not set no-reschedule flag
711 reschedule_flag = true;
716 // already set no-reschedule flag
717 check_result.flag = false;
718 check_result.message = "You have to choose either of reschedule or no-reschedule.";
719 putLogError(600016, check_result.message, __FILE__, __LINE__);
723 else if (*it == "-N" || *it == "--no-reschedule")
726 if (!reschedule_flag)
728 // not set reschedule flag
729 no_reschedule_flag = true;
735 // already set reshcedule flag
736 check_result.flag = false;
737 check_result.message = "You have to choose either of reschedule or no-reschedule.";
738 putLogError(600017, check_result.message, __FILE__, __LINE__);
742 //option string = "-F"
743 else if (*it == "-F" || *it == "--forwarded-for")
745 //set forwarded flag ON
746 forward_checked = true;
747 forwarded_for = FORWARDED_FOR_ON;
749 //option string = "-S"
750 else if (*it == "-S" || *it == "--sorry-uri")
752 //sorryURI flag = OFF
753 if (!sorryuri_checked)
758 if (!it->empty() && (it->substr(0, 1) == "-" || it->substr(0, 2) == "--"))
760 //set check result flag false
761 check_result.flag = false;
762 //set check result message
763 check_result.message = "You have to set option value '-S/--sorry-uri'.";
767 //next option string's length > 127
768 if (it->size() > MAX_OPTION_SIZE - 1)
770 std::ostringstream ostr;
771 ostr << "'-S/--sorry-uri' option value '" << *it << "' is too long.";
773 //set check result flag false
774 check_result.flag = false;
775 //set check result message
776 check_result.message = ostr.str();
777 putLogError(600018, check_result.message, __FILE__,
782 //next option string's length <= 127
787 if (regex_match(*it, sorry_uri_regex))
789 sorryuri_checked = true;
790 memcpy(sorry_uri.data(), it->c_str(), it->size());
795 std::ostringstream ostr;
796 ostr << "'-S/--sorry-uri' option value '" << *it << "' is not a valid URI.";
798 //set check result flag false
799 check_result.flag = false;
800 //set check result message
801 check_result.message = ostr.str();
802 putLogError(600019, check_result.message, __FILE__,
808 //next item not exist
811 //set check result flag false
812 check_result.flag = false;
813 //set check result message
814 check_result.message = "You have to set option value '-S/--sorry-uri'.";
815 putLogError(600020, check_result.message, __FILE__,
823 //set check result flag false
824 check_result.flag = false;
825 //set check result message
826 check_result.message = "Cannot set multiple option '-S/--sorry-uri'.";
827 putLogError(600021, check_result.message, __FILE__,
835 //set check result flag false
836 check_result.flag = false;
837 //set check result message
838 check_result.message = "Option error.";
839 putLogError(600022, check_result.message, __FILE__, __LINE__);
847 if (check_result.flag)
849 // set timeout's default value
855 // set reschedule's default value
856 if (!reschedule_flag)
861 if (!forward_checked)
867 /*-------- DEBUG LOG --------*/
868 if (unlikely(LOG_LV_DEBUG == getloglevel()))
870 boost::format formatter("function : protocol_module_ip::check_message_result "
871 "protocol_module_ip::set_parameter(const std::vector<std::string>& args) : "
872 "timeout = %d, reschedule = %d.");
873 formatter % timeout % reschedule;
874 putLogDebug(600016, formatter.str(), __FILE__, __LINE__);
876 /*------DEBUG LOG END------*/
878 unsigned int data_size = 0;
879 void* data_addr = NULL;
880 data_addr = replication_pay_memory(get_name(), &data_size);
882 /*-------- DEBUG LOG --------*/
883 if (unlikely(LOG_LV_DEBUG == getloglevel()))
885 putLogDebug(600017, "function : protocol_module_ip::check_message_result protocol_module_ip::"
886 "set_parameter() : replication_pay_memory() end.", __FILE__, __LINE__);
887 boost::format formatter("function : protocol_module_ip::check_message_result protocol_module_ip::"
888 "set_parameter() : data_addr = &(%d), data_size = %d.");
889 formatter % data_addr % data_size;
890 putLogDebug(600018, formatter.str(), __FILE__, __LINE__);
893 /*------DEBUG LOG END------*/
894 if (data_addr == NULL || data_size <= 0)
896 // replication area is null
897 putLogError(600023, "Replication area is null.", __FILE__, __LINE__);
899 /*-------- DEBUG LOG --------*/
900 if (unlikely(LOG_LV_DEBUG == getloglevel()))
902 putLogDebug(600019, "function : protocol_module_ip::check_message_result "
903 "protocol_module_ip::set_parameter() : "
904 "Replication area is null.", __FILE__, __LINE__);
906 /*------DEBUG LOG END------*/
909 // create ip_replication_data_processor
910 replication_data_processor = new ip_replication_data_processor(
911 static_cast<char*>(data_addr),
913 virtual_service_endpoint_tcp,
921 /*-------- DEBUG LOG --------*/
922 if (unlikely(LOG_LV_DEBUG == getloglevel()))
924 boost::format formatter("new : address = &(%d), size = %lu.");
925 formatter % static_cast<void*>(replication_data_processor)
926 % sizeof(ip_replication_data_processor);
927 putLogDebug(600020, formatter.str(), __FILE__, __LINE__);
929 /*------DEBUG LOG END------*/
931 replication_data_processor->register_replication_area_lock(replication_area_lock);
933 /*-------- DEBUG LOG --------*/
934 if (unlikely(LOG_LV_DEBUG == getloglevel()))
936 putLogDebug(600021, "function : protocol_module_ip::check_message_result protocol_module_ip::"
937 "set_parameter() : register_replication_area_lock() end.", __FILE__, __LINE__);
939 /*------DEBUG LOG END------*/
941 replication_data_processor->register_replication_area_unlock(replication_area_unlock);
943 /*-------- DEBUG LOG --------*/
944 if (unlikely(LOG_LV_DEBUG == getloglevel()))
946 putLogDebug(600022, "function : protocol_module_ip::check_message_result protocol_module_ip::"
947 "set_parameter() : register_replication_area_unlock() end.", __FILE__, __LINE__);
949 /*------DEBUG LOG END------*/
951 // create ip_session_data_processor
952 ip_data_processor = new ip_session_data_processor(
954 replication_data_processor,
962 /*-------- DEBUG LOG --------*/
963 if (unlikely(LOG_LV_DEBUG == getloglevel()))
965 boost::format formatter("new : address = &(%d), size = %lu.");
966 formatter % static_cast<void*>(ip_data_processor)
967 % sizeof(ip_session_data_processor);
968 putLogDebug(600023, formatter.str(), __FILE__, __LINE__);
970 /*------DEBUG LOG END------*/
972 // restore data from replication area
973 ip_replication_data* redata = replication_data_processor->get_replication_area();
975 /*-------- DEBUG LOG --------*/
976 if (unlikely(LOG_LV_DEBUG == getloglevel()))
978 putLogDebug(600024, "function : protocol_module_ip::check_message_result protocol_module_ip::"
979 "set_parameter() : get_replication_area() end.", __FILE__, __LINE__);
981 /*------DEBUG LOG END------*/
983 replication_area_lock();
985 /*-------- DEBUG LOG --------*/
986 if (unlikely(LOG_LV_DEBUG == getloglevel()))
988 putLogDebug(600025, "function : protocol_module_ip::check_message_result protocol_module_ip::"
989 "set_parameter() : replication_area_lock() end.", __FILE__, __LINE__);
991 /*------DEBUG LOG END------*/
993 ip_data_processor->read_session_data_from_replication_area(redata);
995 /*-------- DEBUG LOG --------*/
996 if (unlikely(LOG_LV_DEBUG == getloglevel()))
998 putLogDebug(600026, "function : protocol_module_ip::check_message_result protocol_module_ip::"
999 "set_parameter() : read_session_data_from_replication_area() end.", __FILE__, __LINE__);
1001 /*------DEBUG LOG END------*/
1003 replication_area_unlock();
1005 /*-------- DEBUG LOG --------*/
1006 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1008 putLogDebug(600027, "function : protocol_module_ip::check_message_result protocol_module_ip::"
1009 "set_parameter() : replication_area_unlock() end.", __FILE__, __LINE__);
1011 /*------DEBUG LOG END------*/
1014 catch (const std::bad_alloc& ba)
1016 if (replication_data_processor)
1018 delete replication_data_processor;
1019 replication_data_processor = NULL;
1022 if (ip_data_processor)
1024 delete ip_data_processor;
1025 ip_data_processor = NULL;
1028 std::cerr << "protocol_module_ip::set_parameter() : exception : Could not allocate memory." << std::endl;
1029 check_result.flag = false;
1030 check_result.message = "Could not allocate memory.";
1031 putLogError(600024, check_result.message, __FILE__, __LINE__);
1033 catch (const std::exception& ex)
1035 if (replication_data_processor)
1037 delete replication_data_processor;
1038 replication_data_processor = NULL;
1041 if (ip_data_processor)
1043 delete ip_data_processor;
1044 ip_data_processor = NULL;
1047 check_result.flag = false;
1048 std::cerr << "protocol_module_ip::set_parameter() : exception : error = " << ex.what() << std::endl;
1049 boost::format formatter("function : protocol_module_ip::check_message_result "
1050 "protocol_module_ip::set_parameter() : exception : error = %s.");
1051 formatter % ex.what();
1052 putLogError(600025, formatter.str(), __FILE__, __LINE__);
1056 if (replication_data_processor)
1058 delete replication_data_processor;
1059 replication_data_processor = NULL;
1062 if (ip_data_processor)
1064 delete ip_data_processor;
1065 ip_data_processor = NULL;
1068 check_result.flag = false;
1069 std::cerr << "protocol_module_ip::set_parameter() : Unknown exception." << std::endl;
1070 putLogError(600026, "function : protocol_module_ip::check_message_result protocol_module_ip::"
1071 "set_parameter() : Unknown exception.", __FILE__, __LINE__);
1073 /*-------- DEBUG LOG --------*/
1074 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1076 boost::format formatter("out_function : protocol_module_ip::check_message_result "
1077 "protocol_module_ip::set_parameter("
1078 "const std::vector<std::string>& args) : return_value = ("
1079 "check_message_result.flag = %d, check_message_result.message = %s).");
1080 formatter % check_result.flag % check_result.message;
1081 putLogDebug(600028, formatter.str(), __FILE__, __LINE__);
1083 /*------DEBUG LOG END------*/
1084 return check_result;
1088 //! @param[in] module paramter string list
1089 //! @return result.flag true is parameter is noproblem.
1090 //! @return result.flag false is paramter is problem.
1091 protocol_module_base::check_message_result protocol_module_ip::add_parameter(const std::vector<
1094 /*-------- DEBUG LOG --------*/
1095 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1097 boost::format formatter("in_function : protocol_module_ip::check_message_result protocol_module_ip::"
1098 "add_parameter(const std::vector<std::string>& args) : args = %s.");
1099 std::string argsdump;
1100 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
1104 formatter % argsdump;
1105 putLogDebug(600029, formatter.str(), __FILE__, __LINE__);
1107 /*------DEBUG LOG END------*/
1108 check_message_result check_result;
1109 //set check result flag true
1110 check_result.flag = true;
1112 //param list is not empty
1115 //set check result flag false
1116 check_result.flag = false;
1117 //set check result message
1118 check_result.message = "Cannot add option.";
1119 putLogError(600027, check_result.message, __FILE__, __LINE__ );
1122 /*-------- DEBUG LOG --------*/
1123 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1125 boost::format formatter("out_function : protocol_module_ip::check_message_result "
1126 "protocol_module_ip::add_parameter(const std::vector<std::string>& args) : "
1127 "return_value = (check_message_result.flag = %d, check_message_result.message = %s).");
1128 formatter % check_result.flag % check_result.message;
1129 putLogDebug(600030, formatter.str(), __FILE__, __LINE__);
1131 /*------DEBUG LOG END------*/
1132 return check_result;
1137 //! TCP/IP scheduled function registation.
1138 //! @param[in] schedule module TCP/IP scheduled function object type
1139 void protocol_module_ip::register_schedule(tcp_schedule_func_type inschedule)
1141 /*-------- DEBUG LOG --------*/
1142 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1144 putLogDebug(600031, "in_function : void protocol_module_ip::register_schedule("
1145 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__);
1147 /*------DEBUG LOG END------*/
1148 schedule_tcp = inschedule;
1149 /*-------- DEBUG LOG --------*/
1150 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1152 putLogDebug(600032, "out_function : void protocol_module_ip::register_schedule("
1153 "tcp_schedule_func_type inschedule).", __FILE__, __LINE__);
1155 /*------DEBUG LOG END------*/
1158 //! UDP scheduled function registation
1159 //! @param[in] schedule module UDP scheduled funtion object type
1160 void protocol_module_ip::register_schedule(udp_schedule_func_type inschedule)
1162 /*-------- DEBUG LOG --------*/
1163 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1165 putLogDebug(600033, "in/out_function : void protocol_module_ip::register_schedule("
1166 "udp_schedule_func_type inschedule).", __FILE__, __LINE__);
1168 /*------DEBUG LOG END------*/
1171 //! called from session initialzie use in upstream_thread
1172 //! @param[in] upstream thread id.
1173 //! @param[in] downstream thread id
1174 //! @return session use EVENT mode.
1175 protocol_module_base::EVENT_TAG protocol_module_ip::handle_session_initialize(
1176 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id,
1177 const boost::asio::ip::tcp::endpoint& client_endpoint_tcp,
1178 const boost::asio::ip::udp::endpoint& client_endpoint_udp)
1180 /*-------- DEBUG LOG --------*/
1181 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1183 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1184 "handle_session_initialize(const boost::thread::id up_thread_id, "
1185 "const boost::thread::id down_thread_id, "
1186 "const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
1187 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : "
1188 "up_thread_id = %d, down_thread_id = %d.");
1189 formatter % up_thread_id % down_thread_id;
1190 putLogDebug(600034, formatter.str(), __FILE__, __LINE__);
1192 /*------DEBUG LOG END------*/
1194 EVENT_TAG status = FINALIZE;
1195 unsigned int ip_hash = 0;
1197 //session thread initialization
1200 thread_data_ptr p_up(new session_thread_data_ip);
1201 /*-------- DEBUG LOG --------*/
1202 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1204 boost::format formatter("new : address = &(%d), size = %lu.");
1205 formatter % static_cast<void*>(p_up.get()) % sizeof(session_thread_data_ip);
1206 putLogDebug(600035, formatter.str(), __FILE__, __LINE__);
1208 /*------DEBUG LOG END------*/
1210 //calculate ip address's hash
1211 ip_hash = l7vs_ip_service_calc_hash(client_endpoint_tcp);
1213 p_up->thread_id = up_thread_id;
1214 p_up->thread_division = THREAD_DIVISION_UP_STREAM;
1215 p_up->pair_thread_id = down_thread_id;
1216 p_up->accept_end_flag = ACCEPT_END_FLAG_OFF;
1217 p_up->end_flag = END_FLAG_OFF;
1218 p_up->sorry_flag = SORRY_FLAG_OFF;
1219 p_up->switch_flag = SWITCH_FLAG_OFF;
1220 p_up->last_status = INITIALIZE;
1221 p_up->client_endpoint = client_endpoint_tcp;
1222 p_up->data_buffer = new char[MAX_BUFFER_SIZE];
1223 p_up->data_buffer_size = MAX_BUFFER_SIZE;
1224 p_up->data_length = 0;
1225 p_up->data_offset = 0;
1226 p_up->current_message_rest_size = 0;
1227 p_up->data_state = HTTP_START;
1228 p_up->realserver_connect_failed_count = 0;
1229 p_up->ip_hash = ip_hash;
1231 /*-------- DEBUG LOG --------*/
1232 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1235 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1236 "handle_session_initialize() : session_thread_data_ip(upthread) : "
1237 "thread_id = %d, thread_division = %d, "
1238 "pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
1239 "sorry_flag = %d, switch_flag = %d, last_status = %d, client_endpoint = [%s]:%d, data_buffer = &(%d),"
1240 "data_buffer_size = %d, data_length = %d, data_offset = %d, current_message_rest_size = %d, data_state = %d,"
1241 "realserver_connect_failed_count = %d, ip_hash = %d.");
1242 formatter % p_up->thread_id
1243 % p_up->thread_division
1244 % p_up->pair_thread_id
1245 % p_up->accept_end_flag
1250 % p_up->client_endpoint.address().to_string()
1251 % p_up->client_endpoint.port()
1253 % p_up->data_buffer_size
1256 % p_up->current_message_rest_size
1258 % p_up->realserver_connect_failed_count
1262 putLogDebug(600036, formatter.str(), __FILE__, __LINE__);
1264 /*------DEBUG LOG END------*/
1266 thread_data_ptr p_down(new session_thread_data_ip);
1268 /*-------- DEBUG LOG --------*/
1269 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1271 boost::format formatter("new : address = &(%d), size = %lu.");
1272 formatter % static_cast<void*>(p_down.get()) % sizeof(session_thread_data_ip);
1273 putLogDebug(600037, formatter.str(), __FILE__, __LINE__);
1275 /*------DEBUG LOG END------*/
1277 p_down->thread_id = down_thread_id;
1278 p_down->thread_division = THREAD_DIVISION_DOWN_STREAM;
1279 p_down->pair_thread_id = up_thread_id;
1280 p_down->accept_end_flag = ACCEPT_END_FLAG_OFF;
1281 p_down->end_flag = END_FLAG_OFF;
1282 p_down->sorry_flag = SORRY_FLAG_OFF;
1283 p_down->switch_flag = SWITCH_FLAG_OFF;
1284 p_down->last_status = INITIALIZE;
1285 p_down->client_endpoint = client_endpoint_tcp;
1286 p_down->data_buffer = new char[MAX_BUFFER_SIZE];
1287 p_down->data_buffer_size = MAX_BUFFER_SIZE;
1288 p_down->data_length = 0;
1289 p_down->data_offset = 0;
1290 p_down->current_message_rest_size = 0;
1291 p_down->data_state = HTTP_START;
1292 p_down->realserver_connect_failed_count = 0;
1293 p_down->ip_hash = ip_hash;
1295 /*-------- DEBUG LOG --------*/
1296 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1299 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1300 "handle_session_initialize() : session_thread_data_ip(downthread) : "
1301 "thread_id = %d, thread_division = %d, "
1302 "pair_thread_id = %d, accept_end_flag = %d, end_flag = %d, "
1303 "sorry_flag = %d, switch_flag = %d, last_status = %d, client_endpoint = [%s]:%d, data_buffer = &(%d),"
1304 "data_buffer_size = %d, data_length = %d, data_offset = %d, current_message_rest_size = %d, data_state = %d,"
1305 "realserver_connect_failed_count = %d, ip_hash = %d.");
1306 formatter % p_down->thread_id
1307 % p_down->thread_division
1308 % p_down->pair_thread_id
1309 % p_down->accept_end_flag
1311 % p_down->sorry_flag
1312 % p_down->switch_flag
1313 % p_down->last_status
1314 % p_down->client_endpoint.address().to_string()
1315 % p_down->client_endpoint.port()
1316 % p_down->data_buffer
1317 % p_down->data_buffer_size
1318 % p_down->data_length
1319 % p_down->data_offset
1320 % p_down->current_message_rest_size
1321 % p_down->data_state
1322 % p_down->realserver_connect_failed_count
1324 putLogDebug(600038, formatter.str(), __FILE__, __LINE__);
1326 /*------DEBUG LOG END------*/
1329 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1331 session_thread_data_map[up_thread_id] = p_up;
1332 session_thread_data_map[down_thread_id] = p_down;
1337 session_thread_data_map[up_thread_id]->last_status = status;
1338 session_thread_data_map[down_thread_id]->last_status = REALSERVER_RECV;
1340 catch (const std::bad_alloc&)
1342 std::cerr << "protocol_module_ip::handle_session_initialize() : exception : Could not allocate memory." << std::endl;
1343 boost::format formatter("Could not allocate memory. thread id : %d.");
1344 formatter % boost::this_thread::get_id();
1345 putLogError(600028, formatter.str(), __FILE__, __LINE__);
1348 catch (const std::exception& ex)
1350 std::cerr << "protocol_module_ip::handle_session_initialize() : exception : error = " << ex.what() << "." << std::endl;
1351 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1352 "handle_session_initialize() : exception : error = %s. thread id : %d.");
1353 formatter % ex.what() % boost::this_thread::get_id();
1354 putLogError(600029, formatter.str(), __FILE__, __LINE__);
1359 std::cerr << "protocol_module_ip::handle_session_initialize() : Unknown exception." << std::endl;
1360 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1361 "handle_session_initialize() : Unknown exception. thread id : %d.");
1362 formatter % boost::this_thread::get_id();
1363 putLogError(600030, formatter.str(), __FILE__, __LINE__);
1367 /*-------- DEBUG LOG --------*/
1368 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1370 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1371 "handle_session_initialize(const boost::thread::id up_thread_id, "
1372 "const boost::thread::id down_thread_id, "
1373 "const boost::asio::ip::tcp::endpoint& client_endpoint_tcp, "
1374 "const boost::asio::ip::udp::endpoint& client_endpoint_udp) : return_value = %d. "
1376 formatter % status % boost::this_thread::get_id();
1377 putLogDebug(600039, formatter.str(), __FILE__, __LINE__);
1379 /*------DEBUG LOG END------*/
1383 //! called from session finalize use in upstream thread.
1384 //! @param[in] upstream thread id.
1385 //! @param[in] downstream thread id
1386 //! @return session use EVENT mode.
1387 protocol_module_base::EVENT_TAG protocol_module_ip::handle_session_finalize(
1388 const boost::thread::id up_thread_id, const boost::thread::id down_thread_id)
1390 /*-------- DEBUG LOG --------*/
1391 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1393 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1394 "handle_session_finalize(const boost::thread::id up_thread_id, "
1395 "const boost::thread::id down_thread_id) : "
1396 "up_thread_id = %d, down_thread_id = %d.");
1397 formatter % up_thread_id % down_thread_id;
1398 putLogDebug(600040, formatter.str(), __FILE__, __LINE__);
1400 /*------DEBUG LOG END------*/
1401 EVENT_TAG status = STOP;
1402 thread_data_ptr p_up;
1403 thread_data_ptr p_down;
1404 session_thread_data_map_it session_thread_data_it;
1406 //session thread free
1409 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1411 session_thread_data_it = session_thread_data_map.find(up_thread_id);
1412 if (session_thread_data_it != session_thread_data_map.end())
1414 p_up = session_thread_data_it->second;
1415 /*-------- DEBUG LOG --------*/
1416 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1418 boost::format formatter("delete : address = &(%d).");
1419 formatter % static_cast<void*>(p_up->data_buffer);
1420 putLogDebug(600041, formatter.str(), __FILE__, __LINE__);
1422 /*------DEBUG LOG END------*/
1424 delete p_up->data_buffer;
1425 /*-------- DEBUG LOG --------*/
1426 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1428 boost::format formatter("delete : address = &(%d).");
1429 formatter % static_cast<void*>(p_up.get());
1430 putLogDebug(600042, formatter.str(), __FILE__, __LINE__);
1432 /*------DEBUG LOG END------*/
1434 session_thread_data_map.erase(up_thread_id);
1437 session_thread_data_it = session_thread_data_map.find(down_thread_id);
1438 if (session_thread_data_it != session_thread_data_map.end())
1441 p_down = session_thread_data_it->second;
1442 /*-------- DEBUG LOG --------*/
1443 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1445 boost::format formatter("delete : address = &(%d).");
1446 formatter % static_cast<void*>(p_up->data_buffer);
1447 putLogDebug(600043, formatter.str(), __FILE__, __LINE__);
1449 /*------DEBUG LOG END------*/
1451 delete p_down->data_buffer;
1452 /*-------- DEBUG LOG --------*/
1453 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1455 boost::format formatter("delete : address = &(%d).");
1456 formatter % static_cast<void*>(p_down.get());
1457 putLogDebug(600044, formatter.str(), __FILE__, __LINE__);
1459 /*------DEBUG LOG END------*/
1461 session_thread_data_map.erase(down_thread_id);
1467 catch (const std::exception& ex)
1469 std::cerr << "protocol_module_ip::handle_session_finalize() : exception : error = " << ex.what() << "." << std::endl;
1470 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1471 "handle_session_finalize() : exception : error = %s. thread id : %d.");
1472 formatter % ex.what() % boost::this_thread::get_id();
1473 putLogError(600031, formatter.str(), __FILE__, __LINE__ );
1478 std::cerr << "protocol_module_ip::handle_session_finalize() : Unknown exception." << std::endl;
1479 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1480 "handle_session_finalize() : "
1481 "Unknown exception. thread id : %d.");
1482 formatter % boost::this_thread::get_id();
1483 putLogError(600032, formatter.str(), __FILE__, __LINE__ );
1486 /*-------- DEBUG LOG --------*/
1487 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1489 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1490 "handle_session_finalize(const boost::thread::id up_thread_id, "
1491 "const boost::thread::id down_thread_id) : return_value = %d. thread id : %d.");
1492 formatter % status % boost::this_thread::get_id();
1493 putLogDebug(600045, formatter.str(), __FILE__, __LINE__ );
1495 /*------DEBUG LOG END------*/
1499 //! called from after session accept.in client socket use in upstream thread.
1500 //! @param[in] upstream thread id.
1501 //! @return session use EVENT mode.
1502 protocol_module_base::EVENT_TAG protocol_module_ip::handle_accept(const boost::thread::id thread_id)
1504 /*-------- DEBUG LOG --------*/
1505 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1507 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1508 "handle_accept(const boost::thread::id thread_id) : thread_id = %d.");
1509 formatter % thread_id;
1510 putLogDebug(600046, formatter.str(), __FILE__, __LINE__ );
1512 /*------DEBUG LOG END------*/
1514 EVENT_TAG status = FINALIZE;
1515 thread_data_ptr session_data_ptr;
1516 session_thread_data_map_it session_thread_it;
1521 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1523 session_thread_it = session_thread_data_map.find(thread_id);
1524 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1526 boost::format formatter("Invalid thread id. thread id : %d.");
1527 formatter % boost::this_thread::get_id();
1528 putLogError(600033, formatter.str(), __FILE__, __LINE__ );
1532 session_data_ptr = session_thread_it->second;
1535 //set accept end flag ON
1536 session_data_ptr->accept_end_flag = ACCEPT_END_FLAG_ON;
1538 /*-------- DEBUG LOG --------*/
1539 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1541 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1542 "handle_accept(const boost::thread::id thread_id) : ACCEPT_END_FLAG_ON. thread id : %d.");
1543 formatter % boost::this_thread::get_id();
1544 putLogDebug(600047, formatter.str(), __FILE__, __LINE__ );
1546 /*------DEBUG LOG END------*/
1549 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
1552 status = SORRYSERVER_SELECT;
1558 status = REALSERVER_SELECT;
1562 session_data_ptr->last_status = status;
1566 /*-------- DEBUG LOG --------*/
1567 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1569 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1570 "handle_accept() : catch exception e = %d. thread id : %d.");
1571 formatter % e % boost::this_thread::get_id();
1572 putLogDebug(600048, formatter.str(), __FILE__, __LINE__ );
1574 /*------DEBUG LOG END------*/
1577 catch (const std::exception& ex)
1579 std::cerr << "protocol_module_ip::handle_accept() : exception : error = " << ex.what() << "." << std::endl;
1580 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1581 "handle_accept() : exception : error = %s. thread id : %d.");
1582 formatter % ex.what() % boost::this_thread::get_id();
1583 putLogError(600034, formatter.str(), __FILE__, __LINE__ );
1588 std::cerr << "protocol_module_ip::handle_accept() : Unknown exception." << std::endl;
1589 boost::format formatter("function : protocol_module_base::EVENT_TAG "
1590 "protocol_module_ip::handle_accept() : "
1591 "Unknown exception. thread id : %d.");
1592 formatter % boost::this_thread::get_id();
1593 putLogError(600035, formatter.str(), __FILE__, __LINE__ );
1597 /*-------- DEBUG LOG --------*/
1598 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1600 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1601 "handle_accept(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
1602 formatter % status % boost::this_thread::get_id();
1603 putLogDebug(600049, formatter.str(), __FILE__, __LINE__ );
1605 /*------DEBUG LOG END------*/
1610 //! called from after session recv in client socket. use in upstream thread.
1611 //! @param[in] upstream thread id
1612 //! @param[in] recive buffer refarence.
1613 //! @param[in] recive length
1614 //! @return session use EVENT mode.
1615 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_recv(const boost::thread::id thread_id,
1616 const boost::array<char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
1619 /*-------- DEBUG LOG --------*/
1620 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1622 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
1624 dump_memory(recvbuffer.data(), buffer_size, buffer);
1625 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1626 "handle_client_recv(const boost::thread::id thread_id, "
1627 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1628 "const size_t recvlen) : thread_id = %d, recvbuffer = %s, recvlen = %d.");
1629 formatter % thread_id % buffer % recvlen;
1630 putLogDebug(600050, formatter.str(), __FILE__, __LINE__ );
1632 /*------DEBUG LOG END------*/
1634 EVENT_TAG status = FINALIZE;
1635 bool find_ret = false;
1636 size_t http_header_offset = 0;
1637 size_t http_header_len = 0;
1638 size_t http_header_content_length_offset = 0;
1639 size_t http_header_content_length_len = 0;
1640 int content_length_value = 0;
1641 const size_t CR_LF_LEN = 2; //length of "\r\n"
1642 const size_t CR_LF_CR_LF_LEN = 4; //length of "\r\n\r\n"
1643 session_thread_data_map_it session_thread_it;
1644 thread_data_ptr session_data_ptr;
1645 http_utility::CHECK_RESULT_TAG check_ret;
1647 std::string content_length;
1649 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
1652 if (unlikely(recvlen > recvbuffer.size()))
1654 std::cerr << "protocol_module_ip::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1655 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
1656 formatter % boost::this_thread::get_id();
1657 putLogError(600036, formatter.str(), __FILE__, __LINE__ );
1659 /*-------- DEBUG LOG --------*/
1660 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1662 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1663 "handle_client_recv(const boost::thread::id thread_id, "
1664 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1665 "const size_t recvlen) : return_value = %d. thread id : %d.");
1666 formatter % FINALIZE % boost::this_thread::get_id();
1667 putLogDebug(600051, formatter.str(), __FILE__, __LINE__ );
1669 /*------DEBUG LOG END------*/
1676 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1678 session_thread_it = session_thread_data_map.find(thread_id);
1679 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1682 boost::format formatter("Invalid thread id. thread id : %d.");
1683 formatter % boost::this_thread::get_id();
1684 putLogError(600037, formatter.str(), __FILE__, __LINE__ );
1688 session_data_ptr = session_thread_it->second;
1692 if (session_data_ptr->end_flag == END_FLAG_ON)
1695 status = CLIENT_RECV;
1700 //copy data from recvbuffer
1701 if (!get_data_from_recvbuffer(session_data_ptr, recvbuffer, recvlen))
1704 std::cerr << "protocol_module_ip::handle_client_recv() : Data size bigger than buffer size." << std::endl;
1705 boost::format formatter("Data size bigger than buffer size. thread id : % id.");
1706 formatter % boost::this_thread::get_id();
1707 putLogError(600038, formatter.str(), __FILE__, __LINE__);
1712 //data state is HTTP_START
1713 if (session_data_ptr->data_state == HTTP_START)
1715 //search http header
1716 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
1717 session_data_ptr->data_length,
1722 /*-------- DEBUG LOG --------*/
1723 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1725 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1726 "handle_client_recv() : call find_http_header_all : "
1727 "return_value = %d. thread id : %d.");
1728 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
1729 putLogDebug(600052, formatter.str(), __FILE__, __LINE__ );
1731 /*------DEBUG LOG END------*/
1733 //search http header result is NG
1736 //data size bigger than max buffer size
1737 if (session_data_ptr->data_length >= MAX_IP_MODULE_BUFFER_SIZE - recvbuffer.size())
1739 //set data state UNKNOWN
1740 session_data_ptr->data_state = UNKNOWN;
1741 //set current message rest size
1742 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
1745 //search http header result is OK
1748 //check http method and version
1749 check_ret = http_utility::check_http_method_and_version(session_data_ptr->data_buffer,
1750 session_data_ptr->data_length);
1751 /*-------- DEBUG LOG --------*/
1752 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1754 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1755 "handle_client_recv() : call check_http_method_and_version : "
1756 "return_value = %d. thread id : %d.");
1757 formatter % check_ret % boost::this_thread::get_id();
1758 putLogDebug(600053, formatter.str(), __FILE__, __LINE__ );
1760 /*------DEBUG LOG END------*/
1762 //check http method and version result is NG
1763 if (check_ret == http_utility::CHECK_NG)
1765 //set data state UNKNOWN
1766 session_data_ptr->data_state = UNKNOWN;
1767 //set current message rest size
1768 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
1770 //check http method and version result is OK
1773 //search Content_Length header
1774 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
1775 session_data_ptr->data_length,
1776 http_header_content_length_offset,
1777 http_header_content_length_len);
1778 /*-------- DEBUG LOG --------*/
1779 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1781 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1782 "handle_client_recv() : call find_http_header_content_length : "
1783 "return_value = %d. thread id : %d.");
1784 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
1785 putLogDebug(600054, formatter.str(), __FILE__, __LINE__ );
1787 /*------DEBUG LOG END------*/
1789 //search Content_Length result is OK
1792 //set content length string
1793 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
1794 http_header_content_length_len );
1795 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
1797 //"content-length: ddd\r\n"
1800 content_length = content_length.substr(
1801 regex_ret.position(1),
1802 regex_ret.length(1));
1804 //set content length value
1805 content_length_value = boost::lexical_cast<int>(content_length);
1808 //http_header context is "\r\n\r\n" only
1809 if (http_header_len == 0)
1811 //set current message rest size
1812 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_LEN;
1816 //set current message rest size
1817 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_CR_LF_LEN;
1820 //search Content_Length result is NG
1823 //http_header context is "\r\n\r\n" only
1824 if (http_header_len == 0)
1826 //set current message rest size
1827 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_LEN;
1831 //set current message rest size
1832 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_CR_LF_LEN;
1837 //set data state HTTP_HEADER
1838 session_data_ptr->data_state = HTTP_HEADER;
1843 //data state is UNKNOWN
1844 else if (session_data_ptr->data_state == UNKNOWN)
1846 //set current message rest size
1847 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
1854 //data state is HTTP_START
1855 if (session_data_ptr->data_state == HTTP_START )
1857 status = CLIENT_RECV;
1859 //data state is not HTTP_START
1863 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
1866 status = SORRYSERVER_CONNECT;
1872 status = REALSERVER_CONNECT;
1879 session_data_ptr->last_status = status;
1883 /*-------- DEBUG LOG --------*/
1884 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1886 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1887 "handle_client_recv() : catch exception e = %d. thread id : %d.");
1888 formatter % e % boost::this_thread::get_id();
1889 putLogDebug(600055, formatter.str(), __FILE__, __LINE__ );
1891 /*------DEBUG LOG END------*/
1894 catch (const boost::bad_lexical_cast& )
1896 std::cerr << "protocol_module_ip::handle_client_recv() : exception : " << "Content_Length field's value is invalid." << std::endl;
1897 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_recv() : "
1898 "Content_Length field's value is invalid. thread id : %d.");
1899 formatter % boost::this_thread::get_id();
1900 putLogError(600039, formatter.str(), __FILE__, __LINE__ );
1903 catch (const std::exception& ex)
1905 std::cerr << "protocol_module_ip::handle_client_recv() : exception : error = " << ex.what() << "." << std::endl;
1906 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1907 "handle_client_recv() : exception : error = %s. thread id : %d.");
1908 formatter % ex.what() % boost::this_thread::get_id();
1909 putLogError(600040, formatter.str(), __FILE__, __LINE__ );
1914 std::cerr << "protocol_module_ip::handle_client_recv() : Unknown exception." << std::endl;
1915 boost::format formatter("function : protocol_module_base::EVENT_TAG "
1916 "protocol_module_ip::handle_client_recv() : "
1917 "Unknown exception. thread id : %d.");
1918 formatter % boost::this_thread::get_id();
1919 putLogError(600041, formatter.str(), __FILE__, __LINE__ );
1923 /*-------- DEBUG LOG --------*/
1924 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1926 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1927 "handle_client_recv(const boost::thread::id thread_id, "
1928 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
1929 "const size_t recvlen) : return_value = %d. thread id : %d.");
1930 formatter % status % boost::this_thread::get_id();
1931 putLogDebug(600056, formatter.str(), __FILE__, __LINE__ );
1933 /*------DEBUG LOG END------*/
1938 //! called from after realserver select.use in upstream thread.
1939 //! @param[in] upstream thread id
1940 //! @param[out] realserver TCP endpoint
1941 //! @return session use EVENT mode.
1942 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_select(
1943 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint & rs_endpoint)
1946 /*-------- DEBUG LOG --------*/
1947 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1949 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1950 "handle_realserver_select(const boost::thread::id thread_id, "
1951 "boost::asio::ip::tcp::endpoint & rs_endpoint) : "
1952 "thread_id = %d, rs_endpoint = [%s]:%d.");
1953 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
1954 putLogDebug(600057, formatter.str(), __FILE__, __LINE__ );
1956 /*------DEBUG LOG END------*/
1958 EVENT_TAG status = FINALIZE;
1959 boost::asio::ip::tcp::endpoint init_endpoint;
1960 thread_data_ptr session_data_ptr;
1961 session_thread_data_map_it session_thread_it;
1962 session_thread_data_map_it session_thread_it_end;
1963 realserverlist_type::iterator rs_list_itr;
1965 if (unlikely(schedule_tcp.empty()))
1967 std::cerr << "protocol_module_ip::handle_realserver_select() : Schedule_tcp function is empty." << std::endl;
1968 boost::format formatter("Schedule_tcp function is empty. thread id : %d.");
1969 formatter % boost::this_thread::get_id();
1970 putLogError(600042, formatter.str(), __FILE__, __LINE__ );
1972 /*-------- DEBUG LOG --------*/
1973 if (unlikely(LOG_LV_DEBUG == getloglevel()))
1975 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
1976 "handle_realserver_select(const boost::thread::id thread_id, "
1977 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
1978 " : return_value = %d. thread id : %d.");
1979 formatter % FINALIZE % boost::this_thread::get_id();
1980 putLogDebug(600058, formatter.str(), __FILE__, __LINE__ );
1982 /*------DEBUG LOG END------*/
1990 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
1992 session_thread_it = session_thread_data_map.find(thread_id);
1993 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
1995 boost::format formatter("Invalid thread id. thread id : %d.");
1996 formatter % boost::this_thread::get_id();
1997 putLogError(600043, formatter.str(), __FILE__, __LINE__ );
2001 session_data_ptr = session_thread_it->second;
2004 //initialize realserver endpoint
2005 rs_endpoint = init_endpoint;
2007 boost::mutex::scoped_lock lock(session_data_mutex);
2008 //the first connection or connected successful
2009 if (session_data_ptr->realserver_connect_failed_count <= 0)
2011 //get endpoint data from the ip data
2012 int ret = ip_data_processor->get_endpoint_from_session_data(session_data_ptr->ip_hash,
2015 /*-------- DEBUG LOG --------*/
2016 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2018 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2019 "protocol_module_ip::handle_realserver_select() : "
2020 "get_endpoint_from_session_data() end. thread id : %d.");
2021 formatter % boost::this_thread::get_id();
2022 putLogDebug(600059, formatter.str(), __FILE__, __LINE__);
2024 /*------DEBUG LOG END------*/
2026 //endpoint is matched
2029 //find the rs_endpoint in rs_list
2032 rs_list_itr = rs_list_begin();
2035 while ( rs_list_itr != rs_list_end())
2038 if ( rs_list_itr->tcp_endpoint == rs_endpoint )
2044 rs_list_itr = rs_list_next( rs_list_itr );
2049 //endpoint is matched in the list
2052 //data state is HTTP_START
2053 if (session_data_ptr->data_state == HTTP_START)
2056 status = CLIENT_RECV;
2058 //data state is not HTTP_START
2062 status = REALSERVER_CONNECT;
2065 //endpoint is not matched in the list
2068 //if reschedule is on then try multi times connect
2069 if (reschedule == 1)
2072 rs_endpoint = init_endpoint;
2074 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2075 /*-------- DEBUG LOG --------*/
2076 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2078 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2079 "handle_realserver_select() : call schedule_tcp : "
2080 "rs_endpoint = [%s]:%d. thread id : %d.");
2081 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2082 putLogDebug(600060, formatter.str(), __FILE__, __LINE__ );
2084 /*------DEBUG LOG END------*/
2086 //get the endpoint by schedule successfully
2087 if (init_endpoint != rs_endpoint)
2089 time_t init_time = 0;
2091 //write data to session table
2092 ip_data_processor->write_session_data(session_data_ptr->ip_hash, rs_endpoint, init_time);
2093 /*-------- DEBUG LOG --------*/
2094 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2096 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2097 "protocol_module_ip::handle_realserver_select() : "
2098 "write_session_data() end. thread id : %d.");
2099 formatter % boost::this_thread::get_id();
2100 putLogDebug(600061, formatter.str(), __FILE__, __LINE__);
2102 /*------DEBUG LOG END------*/
2104 //data state is HTTP_START
2105 if (session_data_ptr->data_state == HTTP_START)
2108 status = CLIENT_RECV;
2110 //data state is not HTTP_START
2114 status = REALSERVER_CONNECT;
2117 //get the endpoint by schedule unsuccessfully
2121 status = CLIENT_DISCONNECT;
2128 status = CLIENT_DISCONNECT;
2132 //endpoint is not matched
2136 rs_endpoint = init_endpoint;
2138 //call schedule_module's schedule function, get realserver endpoint
2139 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2141 /*-------- DEBUG LOG --------*/
2142 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2144 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2145 "handle_realserver_select() : call schedule_tcp : "
2146 "rs_endpoint = [%s]:%d. thread id : %d.");
2147 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2148 putLogDebug(600062, formatter.str(), __FILE__, __LINE__ );
2150 /*------DEBUG LOG END------*/
2152 //get the endpoint by schedule successfully
2153 if (init_endpoint != rs_endpoint)
2155 time_t init_time = 0;
2157 //write data to session table
2158 ip_data_processor->write_session_data(session_data_ptr->ip_hash, rs_endpoint, init_time);
2159 /*-------- DEBUG LOG --------*/
2160 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2162 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2163 "protocol_module_ip::handle_realserver_select() : "
2164 "write_session_data() end. thread id : %d.");
2165 formatter % boost::this_thread::get_id();
2166 putLogDebug(600063, formatter.str(), __FILE__, __LINE__);
2168 /*------DEBUG LOG END------*/
2170 //data state is HTTP_START
2171 if (session_data_ptr->data_state == HTTP_START)
2174 status = CLIENT_RECV;
2176 //data state is not HTTP_START
2180 status = REALSERVER_CONNECT;
2183 //get the endpoint by schedule unsuccessfully
2187 status = CLIENT_DISCONNECT;
2191 //realserver connect failed count is less than the max failed count
2192 else if (session_data_ptr->realserver_connect_failed_count < this->realserver_connect_failed_max_count)
2194 //if reschedule is on then try multi times connect
2195 if (reschedule == 1)
2198 rs_endpoint = init_endpoint;
2200 //call schedule_module's schedule function, get realserver endpoint
2201 schedule_tcp(thread_id, rs_list_begin, rs_list_end, rs_list_next, rs_endpoint);
2203 /*-------- DEBUG LOG --------*/
2204 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2206 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2207 "handle_realserver_select() : call schedule_tcp : "
2208 "rs_endpoint = [%s]:%d. thread id : %d.");
2209 formatter % rs_endpoint.address().to_string() % rs_endpoint.port() % boost::this_thread::get_id();
2210 putLogDebug(600064, formatter.str(), __FILE__, __LINE__ );
2212 /*------DEBUG LOG END------*/
2214 //get the endpoint by schedule successfully
2215 if (init_endpoint != rs_endpoint)
2217 time_t init_time = 0;
2219 //write data to session table
2220 ip_data_processor->write_session_data(session_data_ptr->ip_hash, rs_endpoint, init_time);
2221 /*-------- DEBUG LOG --------*/
2222 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2224 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2225 "protocol_module_ip::handle_realserver_select() : "
2226 "write_session_data() end. thread id : %d.");
2227 formatter % boost::this_thread::get_id();
2228 putLogDebug(600065, formatter.str(), __FILE__, __LINE__);
2230 /*------DEBUG LOG END------*/
2232 //data state is HTTP_START
2233 if (session_data_ptr->data_state == HTTP_START)
2236 status = CLIENT_RECV;
2238 //data state is not HTTP_START
2242 status = REALSERVER_CONNECT;
2245 //get the endpoint by schedule successfully
2249 status = CLIENT_DISCONNECT;
2256 status = CLIENT_DISCONNECT;
2259 //realserver connect failed count is more than 3
2263 status = CLIENT_DISCONNECT;
2267 session_data_ptr->last_status = status;
2271 /*-------- DEBUG LOG --------*/
2272 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2274 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2275 "handle_realserver_select() : catch exception e = %d. thread id : %d.");
2276 formatter % e % boost::this_thread::get_id();
2277 putLogDebug(600066, formatter.str(), __FILE__, __LINE__ );
2279 /*------DEBUG LOG END------*/
2282 catch (const std::exception& ex)
2284 std::cerr << "protocol_module_ip::handle_realserver_select() : exception : error = " << ex.what() << "." << std::endl;
2285 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2286 "handle_realserver_select() : exception : error = %s. thread id : %d.");
2287 formatter % ex.what() % boost::this_thread::get_id();
2288 putLogError(600044, formatter.str(), __FILE__, __LINE__ );
2293 std::cerr << "protocol_module_ip::handle_realserver_select() : Unknown exception." << std::endl;
2294 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2295 "protocol_module_ip::handle_realserver_select() : "
2296 "Unknown exception. thread id : %d.");
2297 formatter % boost::this_thread::get_id();
2298 putLogError(600045, formatter.str(), __FILE__, __LINE__ );
2302 /*-------- DEBUG LOG --------*/
2303 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2305 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2306 "handle_realserver_select(const boost::thread::id thread_id, "
2307 "boost::asio::ip::tcp::endpoint & rs_endpoint)"
2308 " : return_value = %d. thread id : %d.");
2309 formatter % status % boost::this_thread::get_id();
2310 putLogDebug(600067, formatter.str(), __FILE__, __LINE__ );
2312 /*------DEBUG LOG END------*/
2316 //! called from after realserver select
2317 //! @param[in] upstream thread id
2318 //! @param[out] realserver UDP endpoint
2319 //! @param[out] sendbuffer reference
2320 //! @param[out] send data length
2321 //! @return session use EVENT mode.
2322 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_select(
2323 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,
2324 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2326 /*-------- DEBUG LOG --------*/
2327 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2329 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2330 "handle_realserver_select(const boost::thread::id thread_id, "
2331 "boost::asio::ip::udp::endpoint& rs_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2332 "size_t& datalen) : "
2333 "return_value = %d. thread id : %d.");
2334 formatter % STOP % boost::this_thread::get_id();
2335 putLogDebug(600068, formatter.str(), __FILE__, __LINE__ );
2337 /*------DEBUG LOG END------*/
2340 //! called from after realserver connect
2341 //! @param[in] upstream thread id
2342 //! @param[out] sendbuffer reference
2343 //! @param[out] send data length
2344 //! @return session use EVENT mode.
2345 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_connect(
2346 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
2348 /*-------- DEBUG LOG --------*/
2349 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2351 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2352 "handle_realserver_connect(const boost::thread::id thread_id, "
2353 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
2355 formatter % thread_id;
2356 putLogDebug(600069, formatter.str(), __FILE__, __LINE__ );
2358 /*------DEBUG LOG END------*/
2360 EVENT_TAG status = FINALIZE;
2361 size_t send_possible_size = 0;
2362 size_t x_forwarded_for_insert_pos = 0;
2363 thread_data_ptr session_data_ptr;
2364 session_thread_data_map_it session_thread_it;
2365 std::pair<char*, size_t> buffer_element;
2366 std::string x_forwarded_for_context;
2371 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2374 session_thread_it = session_thread_data_map.find(thread_id);
2375 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2377 boost::format formatter("Invalid thread id. thread id : %d.");
2378 formatter % boost::this_thread::get_id();
2379 putLogError(600046, formatter.str(), __FILE__, __LINE__ );
2383 session_data_ptr = session_thread_it->second;
2386 send_possible_size = std::min(session_data_ptr->current_message_rest_size,
2387 session_data_ptr->data_length
2390 //buffer sequence is empty
2391 if (session_data_ptr->buffer_sequence.empty())
2393 //data state is HTTP_HEADER
2394 if (session_data_ptr->data_state == HTTP_HEADER)
2396 //forwarded_for flag is on
2397 if (forwarded_for == FORWARDED_FOR_ON)
2399 //search X-Forwarded-For header
2400 create_x_forwarded_for(session_data_ptr->client_endpoint.address().to_string(),
2401 session_data_ptr->data_buffer + session_data_ptr->data_offset,
2402 session_data_ptr->data_length,
2403 x_forwarded_for_insert_pos,
2404 x_forwarded_for_context);
2406 //put buffer data to buffer_sequence
2407 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
2408 buffer_element.second = x_forwarded_for_insert_pos;
2409 session_data_ptr->buffer_sequence.push_back(buffer_element);
2411 session_data_ptr->forwarded_for_buffer.assign(0);
2413 /*-------- DEBUG LOG --------*/
2414 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2416 std::string datadump;
2417 dump_memory(x_forwarded_for_context.c_str(),
2418 x_forwarded_for_context.size(), datadump);
2419 boost::format formatter(
2420 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2421 "handle_realserver_connect() : before memcpy (data dump) : "
2422 "data begin = 0, data_size = %d, data = %s");
2423 formatter % x_forwarded_for_context.size() % datadump;
2424 putLogDebug(600070, formatter.str(), __FILE__, __LINE__ );
2426 /*------DEBUG LOG END------*/
2428 memcpy(session_data_ptr->forwarded_for_buffer.data(),
2429 x_forwarded_for_context.c_str(),
2430 x_forwarded_for_context.size());
2432 /*-------- DEBUG LOG --------*/
2433 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2435 std::string datadump;
2436 dump_memory(x_forwarded_for_context.c_str(),
2437 x_forwarded_for_context.size(), datadump);
2438 boost::format formatter(
2439 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2440 "handle_realserver_connect() : after memcpy (data dump) : "
2441 "data begin = 0, data_size = %d, data = %s");
2442 formatter % x_forwarded_for_context.size() % datadump;
2443 putLogDebug(600071, formatter.str(), __FILE__, __LINE__ );
2445 /*------DEBUG LOG END------*/
2447 //set buffer's position
2448 buffer_element.first = session_data_ptr->forwarded_for_buffer.data();
2449 buffer_element.second = x_forwarded_for_context.size();
2451 //set data to buffer_sequence
2452 session_data_ptr->buffer_sequence.push_back(buffer_element);
2454 //set buffer's position
2455 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset + x_forwarded_for_insert_pos;
2456 buffer_element.second = send_possible_size - x_forwarded_for_insert_pos;
2458 //set data to buffer_sequence
2459 session_data_ptr->buffer_sequence.push_back(buffer_element);
2461 //forwarded_for flag is off
2464 //set buffer's position
2465 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
2466 buffer_element.second = send_possible_size;
2468 //set data to buffer_sequence
2469 session_data_ptr->buffer_sequence.push_back(buffer_element);
2471 session_data_ptr->data_state = HTTP_BODY;
2473 //data state is not HTTP_HEADER
2477 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
2478 buffer_element.second = send_possible_size;
2480 //set data to buffer_sequence
2481 session_data_ptr->buffer_sequence.push_back(buffer_element);
2486 //put buffer_sequence data into sendbuffer
2487 put_data_into_sendbuffer(session_data_ptr, sendbuffer, datalen);
2489 session_data_ptr->realserver_connect_failed_count = 0;
2491 status = REALSERVER_SEND;
2494 session_data_ptr->last_status = status;
2498 /*-------- DEBUG LOG --------*/
2499 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2501 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2502 "handle_realserver_connect() : catch exception e = %d. thread id : %d.");
2503 formatter % e % boost::this_thread::get_id();
2504 putLogDebug(600072, formatter.str(), __FILE__, __LINE__ );
2506 /*------DEBUG LOG END------*/
2511 catch (std::exception& ex)
2513 std::cerr << "protocol_module_ip::handle_realserver_connect() : exception : error = " << ex.what() << "." << std::endl;
2514 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2515 "handle_realserver_connect() : exception : error = %s. thread id : %d.");
2516 formatter % ex.what() % boost::this_thread::get_id();
2517 putLogError(600047, formatter.str(), __FILE__, __LINE__ );
2524 std::cerr << "protocol_module_ip::handle_realserver_connect() : Unknown exception." << std::endl;
2525 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2526 "handle_realserver_connect() : Unknown exception. thread id : %d.");
2527 formatter % boost::this_thread::get_id();
2528 putLogError(600048, formatter.str(), __FILE__, __LINE__ );
2534 /*-------- DEBUG LOG --------*/
2535 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2537 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2538 "handle_realserver_connect(const boost::thread::id thread_id, "
2539 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
2540 "size_t& datalen) : return_value = %d. thread id : %d.");
2541 formatter % status % boost::this_thread::get_id();
2542 putLogDebug(600073, formatter.str(), __FILE__, __LINE__ );
2544 /*------DEBUG LOG END------*/
2549 //! called from after realserver connection fail
2550 //! @param[in] upstream thread id
2551 //! @param[in] fail realserver endpoint reference
2552 //! @return session use EVENT mode.
2553 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_connection_fail(
2554 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
2556 /*-------- DEBUG LOG --------*/
2557 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2559 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2560 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2561 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
2562 "thread_id = %d, rs_endpoint = [%s]:%d.");
2563 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2564 putLogDebug(600074, formatter.str(), __FILE__, __LINE__ );
2566 /*------DEBUG LOG END------*/
2568 EVENT_TAG status = FINALIZE;
2569 thread_data_ptr session_data_ptr;
2570 session_thread_data_map_it session_thread_it;
2574 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2576 session_thread_it = session_thread_data_map.find(thread_id);
2577 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2579 boost::format formatter("Invalid thread id. thread id : %d.");
2580 formatter % boost::this_thread::get_id();
2581 putLogError(600049, formatter.str(), __FILE__, __LINE__ );
2585 session_data_ptr = session_thread_it->second;
2587 if (reschedule == 1)
2589 session_data_ptr->realserver_connect_failed_count++;
2592 status = REALSERVER_SELECT;
2597 session_data_ptr->end_flag = END_FLAG_ON;
2599 /*-------- DEBUG LOG --------*/
2600 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2602 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2603 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2604 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : END_FLAG_ON. "
2605 "thread_id = %d, rs_endpoint = [%s]:%d.");
2606 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
2607 putLogDebug(600075, formatter.str(), __FILE__, __LINE__ );
2609 /*------DEBUG LOG END------*/
2612 status = CLIENT_DISCONNECT;
2617 session_data_ptr->last_status = status;
2621 /*-------- DEBUG LOG --------*/
2622 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2624 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2625 "handle_realserver_connection_fail() : catch exception e = %d. thread id : %d.");
2626 formatter % e % boost::this_thread::get_id();
2627 putLogDebug(600076, formatter.str(), __FILE__, __LINE__ );
2629 /*------DEBUG LOG END------*/
2634 catch (const std::exception& ex)
2636 std::cerr << "protocol_module_ip::handle_realserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
2637 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2638 "handle_realserver_connection_fail() : exception : error = %s. thread id : %d.");
2639 formatter % ex.what() % boost::this_thread::get_id();
2640 putLogError(600050, formatter.str(), __FILE__, __LINE__ );
2647 std::cerr << "protocol_module_ip::handle_realserver_connection_fail() : Unknown exception." << std::endl;
2648 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2649 "protocol_module_ip::handle_realserver_connection_fail() : "
2650 "Unknown exception. thread id : %d.");
2651 formatter % boost::this_thread::get_id();
2652 putLogError(600051, formatter.str(), __FILE__, __LINE__ );
2658 /*-------- DEBUG LOG --------*/
2659 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2661 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2662 "handle_realserver_connection_fail(const boost::thread::id thread_id, "
2663 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
2664 formatter % status % boost::this_thread::get_id();
2665 putLogDebug(600077, formatter.str(), __FILE__, __LINE__ );
2667 /*------DEBUG LOG END------*/
2671 //! called from after realserver send.
2672 //! @param[in] upstream thread id
2673 //! @return session use EVENT mode.
2674 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_send(
2675 const boost::thread::id thread_id)
2677 /*-------- DEBUG LOG --------*/
2678 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2680 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2681 "handle_realserver_send(const boost::thread::id thread_id) : thread_id = %d.");
2682 formatter % thread_id;
2683 putLogDebug(600078, formatter.str(), __FILE__, __LINE__ );
2685 /*------DEBUG LOG END------*/
2687 EVENT_TAG status = FINALIZE;
2688 size_t http_header_all_offset = 0;
2689 size_t http_header_all_len = 0;
2690 size_t http_header_content_length_offset = 0;
2691 size_t http_header_content_length_len = 0;
2692 const size_t CR_LF_LEN = 2;
2693 const size_t CR_LF_CR_LF_LEN = 4;
2694 int content_length_value = 0;
2696 std::string content_length;
2698 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
2701 bool find_ret = false;
2702 http_utility::CHECK_RESULT_TAG check_ret;
2704 thread_data_ptr session_data_ptr;
2705 session_thread_data_map_it session_thread_it;
2710 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
2713 session_thread_it = session_thread_data_map.find(thread_id);
2714 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
2716 boost::format formatter("Invalid thread id. thread id : %d.");
2717 formatter % boost::this_thread::get_id();
2718 putLogError(600052, formatter.str(), __FILE__, __LINE__ );
2722 session_data_ptr = session_thread_it->second;
2725 //current_message_rest_size > 0
2726 if (session_data_ptr->current_message_rest_size > 0)
2729 if (session_data_ptr->data_length > 0)
2732 status = REALSERVER_CONNECT;
2738 session_data_ptr->data_offset = 0;
2741 status = CLIENT_RECV;
2744 //current_message_rest_size is 0
2748 if (session_data_ptr->data_length > 0)
2750 //data state is HTTP_BODY
2751 if (session_data_ptr->data_state == HTTP_BODY)
2753 //search whole http header, get whole http header's offset and length
2754 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
2755 session_data_ptr->data_length,
2756 http_header_all_offset,
2760 /*-------- DEBUG LOG --------*/
2761 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2763 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2764 "handle_realserver_send() : call find_http_header_all : "
2765 "return_value = %d. thread id : %d.");
2766 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
2767 putLogDebug(600079, formatter.str(), __FILE__, __LINE__ );
2769 /*------DEBUG LOG END------*/
2771 //search http header result is NG
2774 //set data state HTTP_START
2775 session_data_ptr->data_state = HTTP_START;
2778 status = CLIENT_RECV;
2780 //search http header result is OK
2783 //check http method and version
2784 check_ret = http_utility::check_http_method_and_version(session_data_ptr->data_buffer + session_data_ptr->data_offset,
2785 session_data_ptr->data_length);
2787 /*-------- DEBUG LOG --------*/
2788 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2790 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2791 "handle_realserver_send() : call check_http_method_and_version : "
2792 "return_value = %d. thread id : %d.");
2793 formatter % check_ret % boost::this_thread::get_id();
2794 putLogDebug(600080, formatter.str(), __FILE__, __LINE__ );
2796 /*------DEBUG LOG END------*/
2798 //check method and version result is NG
2799 if (check_ret == http_utility::CHECK_NG)
2801 //set current message rest size
2802 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
2804 //set data state UNKNOWN
2805 session_data_ptr->data_state = UNKNOWN;
2807 //check method and version result is OK
2810 //search Content_Length header
2811 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
2812 session_data_ptr->data_length,
2813 http_header_content_length_offset,
2814 http_header_content_length_len);
2816 /*-------- DEBUG LOG --------*/
2817 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2819 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2820 "handle_realserver_send() : call find_http_header_content_length : "
2821 "return_value = %d. thread id : %d.");
2822 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
2823 putLogDebug(600081, formatter.str(), __FILE__, __LINE__ );
2825 /*------DEBUG LOG END------*/
2827 //search Content_Length result is OK
2830 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
2831 http_header_content_length_len );
2832 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
2834 //"content-length: ddd\r\n"
2837 content_length = content_length.substr(
2838 regex_ret.position(1),
2839 regex_ret.length(1));
2841 //set content length value
2842 content_length_value = boost::lexical_cast<int>(content_length);
2845 //http_header context is "\r\n\r\n" only
2846 if (http_header_all_len == 0)
2848 //set current message rest size
2849 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_LEN;
2853 //set current message rest size
2854 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_CR_LF_LEN;
2857 //search Content_Length result is OK
2860 //http_header context is "\r\n\r\n" only
2861 if (http_header_all_len == 0)
2863 //set current message rest size
2864 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_LEN;
2868 //set current message rest size
2869 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_CR_LF_LEN;
2874 //set data state HTTP_HEADER
2875 session_data_ptr->data_state = HTTP_HEADER;
2879 status = REALSERVER_CONNECT;
2882 //data state is UNKNOWN
2883 else if (session_data_ptr->data_state == UNKNOWN)
2886 status = REALSERVER_CONNECT;
2893 //data state is HTTP_BODY
2894 if (session_data_ptr->data_state == HTTP_BODY)
2896 //set data state HTTP_START
2897 session_data_ptr->data_state = HTTP_START;
2901 session_data_ptr->data_offset = 0;
2904 status = CLIENT_RECV;
2908 session_data_ptr->last_status = status;
2912 /*-------- DEBUG LOG --------*/
2913 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2915 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2916 "handle_realserver_send() : catch exception e = %d. thread id : %d.");
2917 formatter % e % boost::this_thread::get_id();
2918 putLogDebug(600082, formatter.str(), __FILE__, __LINE__ );
2920 /*------DEBUG LOG END------*/
2925 catch (const boost::bad_lexical_cast& )
2927 std::cerr << "protocol_module_ip::handle_realserver_send() : exception : " << "Content_Length field's value is invalid." << std::endl;
2928 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_send() : "
2929 "Content_Length field's value is invalid. thread id : %d.");
2930 formatter % boost::this_thread::get_id();
2931 putLogError(600053, formatter.str(), __FILE__, __LINE__ );
2936 catch (const std::exception& ex)
2938 std::cerr << "protocol_module_ip::handle_realserver_send() : exception : error = " << ex.what() << "." << std::endl; //set data state HTTP_HEADER
2939 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2940 "handle_realserver_send() : exception : error = %s. thread id : %d.");
2941 formatter % ex.what() % boost::this_thread::get_id();
2942 putLogError(600054, formatter.str(), __FILE__, __LINE__ );
2949 std::cerr << "protocol_module_ip::handle_realserver_send() : Unknown exception." << std::endl;
2950 boost::format formatter("function : protocol_module_base::EVENT_TAG "
2951 "protocol_module_ip::handle_realserver_send() : "
2952 "Unknown exception. thread id : %d.");
2953 formatter % boost::this_thread::get_id();
2954 putLogError(600055, formatter.str(), __FILE__, __LINE__ );
2960 /*-------- DEBUG LOG --------*/
2961 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2963 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2964 "handle_realserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
2965 formatter % status % boost::this_thread::get_id();
2966 putLogDebug(600083, formatter.str(), __FILE__, __LINE__ );
2968 /*------DEBUG LOG END------*/
2973 //! called from after sorryserver select
2974 //! @param[in] upstream thread id
2975 //! @param[in] sorryserver endpiont reference
2976 //! @return session use EVENT mode.
2977 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_select(
2978 const boost::thread::id thread_id, boost::asio::ip::tcp::endpoint& sorry_endpoint)
2980 /*-------- DEBUG LOG --------*/
2981 if (unlikely(LOG_LV_DEBUG == getloglevel()))
2983 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
2984 "handle_sorryserver_select(const boost::thread::id thread_id, "
2985 "boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
2986 "thread_id = %d, sorry_endpoint = [%s]:%d.");
2987 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
2988 putLogDebug(600084, formatter.str(), __FILE__, __LINE__ );
2990 /*------DEBUG LOG END------*/
2992 EVENT_TAG status = FINALIZE;
2993 boost::asio::ip::tcp::endpoint tmp_endpoint;
2994 thread_data_ptr session_data_ptr;
2995 session_thread_data_map_it session_thread_it;
2996 session_thread_data_map_it session_thread_it_end;
3001 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3003 session_thread_it = session_thread_data_map.find(thread_id);
3004 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3006 boost::format formatter("Invalid thread id. thread id : %d.");
3007 formatter % boost::this_thread::get_id();
3008 putLogError(600056, formatter.str(), __FILE__, __LINE__ );
3012 session_data_ptr = session_thread_it->second;
3015 //data state is HTTP_START
3016 if (session_data_ptr->data_state == HTTP_START)
3019 status = CLIENT_RECV;
3021 //data state is not HTTP_START
3025 status = SORRYSERVER_CONNECT;
3029 session_data_ptr->last_status = status;
3033 /*-------- DEBUG LOG --------*/
3034 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3036 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3037 "handle_sorryserver_select() : catch exception e = %d. thread id : %d.");
3038 formatter % e % boost::this_thread::get_id();
3039 putLogDebug(600085, formatter.str(), __FILE__, __LINE__ );
3041 /*------DEBUG LOG END------*/
3046 catch (const std::exception& ex)
3048 std::cerr << "protocol_module_ip::handle_sorryserver_select() : exception : error = " << ex.what() << "." << std::endl;
3049 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3050 "handle_sorryserver_select() : exception : error = %s. thread id : %d.");
3051 formatter % ex.what() % boost::this_thread::get_id();
3052 putLogError(600057, formatter.str(), __FILE__, __LINE__ );
3059 std::cerr << "protocol_module_ip::handle_sorryserver_select() : Unknown exception." << std::endl;
3060 boost::format formatter("function : protocol_module_base::EVENT_TAG "
3061 "protocol_module_ip::handle_sorryserver_select() : "
3062 "Unknown exception. thread id : %d.");
3063 formatter % boost::this_thread::get_id();
3064 putLogError(600058, formatter.str(), __FILE__, __LINE__ );
3070 /*-------- DEBUG LOG --------*/
3071 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3073 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3074 "handle_sorryserver_select(const boost::thread::id thread_id, "
3075 "boost::asio::ip::tcp::endpoint & sorry_endpoint)"
3076 " : return_value = %d. thread id : %d.");
3077 formatter % status % boost::this_thread::get_id();
3078 putLogDebug(600086, formatter.str(), __FILE__, __LINE__ );
3080 /*------DEBUG LOG END------*/
3085 //! called from after sorryserver connect
3086 //! @param[in] upstream thread id
3087 //! @param[out] send buffer reference.
3088 //! @param[out] send length
3089 //! @return session use EVENT mode.
3090 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_connect(
3091 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
3093 /*-------- DEBUG LOG --------*/
3094 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3096 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3097 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3098 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
3100 formatter % thread_id;
3101 putLogDebug(600087, formatter.str(), __FILE__, __LINE__ );
3103 /*------DEBUG LOG END------*/
3105 EVENT_TAG status = FINALIZE;
3106 size_t send_possible_size = 0;
3107 size_t uri_offset = 0;
3109 size_t x_forwarded_for_insert_pos = 0;
3110 thread_data_ptr session_data_ptr;
3111 session_thread_data_map_it session_thread_it;
3112 std::pair<char*, size_t> buffer_element;
3113 std::string x_forwarded_for_context;
3118 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3121 session_thread_it = session_thread_data_map.find(thread_id);
3122 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3124 boost::format formatter("Invalid thread id. thread id : %d.");
3125 formatter % boost::this_thread::get_id();
3126 putLogError(600059, formatter.str(), __FILE__, __LINE__ );
3130 session_data_ptr = session_thread_it->second;
3132 //set send possible data size
3133 send_possible_size = std::min(session_data_ptr->current_message_rest_size,
3134 session_data_ptr->data_length
3137 if (session_data_ptr->buffer_sequence.empty())
3139 //data state is HTTP_HEADER
3140 if (session_data_ptr->data_state == HTTP_HEADER)
3143 http_utility::find_uri(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3144 session_data_ptr->data_length, uri_offset, uri_len);
3146 //set buffer's position
3147 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
3148 buffer_element.second = uri_offset;
3150 //put buffer data to buffer_sequence
3151 session_data_ptr->buffer_sequence.push_back(buffer_element);
3153 //set buffer's position
3154 buffer_element.first = sorry_uri.data();
3155 buffer_element.second = strlen(sorry_uri.data());
3157 //put buffer data to buffer_sequence
3158 session_data_ptr->buffer_sequence.push_back(buffer_element);
3160 //forwarded_for flag is on
3161 if (forwarded_for == FORWARDED_FOR_ON)
3163 create_x_forwarded_for(session_data_ptr->client_endpoint.address().to_string(),
3164 session_data_ptr->data_buffer + session_data_ptr->data_offset,
3165 session_data_ptr->data_length,
3166 x_forwarded_for_insert_pos,
3167 x_forwarded_for_context);
3169 //set buffer's position
3170 buffer_element.first = session_data_ptr->data_buffer
3171 + session_data_ptr->data_offset
3174 buffer_element.second = x_forwarded_for_insert_pos - uri_offset - uri_len;
3176 //put buffer data to buffer_sequence
3177 session_data_ptr->buffer_sequence.push_back(buffer_element);
3179 session_data_ptr->forwarded_for_buffer.assign(0);
3181 /*-------- DEBUG LOG --------*/
3182 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3184 std::string datadump;
3185 dump_memory(x_forwarded_for_context.c_str(),
3186 x_forwarded_for_context.size(), datadump);
3187 boost::format formatter(
3188 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3189 "handle_sorryserver_connect() : before memcpy (data dump) : "
3190 "data begin = 0, data_size = %d, data = %s");
3191 formatter % x_forwarded_for_context.size() % datadump;
3192 putLogDebug(600088, formatter.str(), __FILE__, __LINE__ );
3194 /*------DEBUG LOG END------*/
3196 memcpy(session_data_ptr->forwarded_for_buffer.data(),
3197 x_forwarded_for_context.c_str(),
3198 x_forwarded_for_context.size());
3200 /*-------- DEBUG LOG --------*/
3201 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3203 std::string datadump;
3204 dump_memory(x_forwarded_for_context.c_str(),
3205 x_forwarded_for_context.size(), datadump);
3206 boost::format formatter(
3207 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3208 "handle_sorryserver_connect() : after memcpy (data dump) : "
3209 "data begin = 0, data_size = %d, data = %s");
3210 formatter % x_forwarded_for_context.size() % datadump;
3211 putLogDebug(600089, formatter.str(), __FILE__, __LINE__ );
3213 /*------DEBUG LOG END------*/
3215 //set buffer's position
3216 buffer_element.first = session_data_ptr->forwarded_for_buffer.data();
3217 buffer_element.second = x_forwarded_for_context.size();
3218 //put buffer data to buffer_sequence
3219 session_data_ptr->buffer_sequence.push_back(buffer_element);
3221 //set buffer's position
3222 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset + x_forwarded_for_insert_pos;
3223 buffer_element.second = send_possible_size - x_forwarded_for_insert_pos;
3224 //put buffer data to buffer_sequence
3225 session_data_ptr->buffer_sequence.push_back(buffer_element);
3227 //forwarded_for flag is on
3230 //set buffer's position
3231 buffer_element.first = session_data_ptr->data_buffer
3232 + session_data_ptr->data_offset
3235 buffer_element.second = send_possible_size - uri_offset - uri_len;
3236 //put buffer data to buffer_sequence
3237 session_data_ptr->buffer_sequence.push_back(buffer_element);
3240 //set data state HTTP_BODY
3241 session_data_ptr->data_state = HTTP_BODY;
3243 //data state is not HTTP_HEADER
3246 //set buffer's position
3247 buffer_element.first = session_data_ptr->data_buffer + session_data_ptr->data_offset;
3248 buffer_element.second = send_possible_size;
3249 //put buffer data to buffer_sequence
3250 session_data_ptr->buffer_sequence.push_back(buffer_element);
3254 //put buffer_sequence data into sendbuffer
3255 put_data_into_sendbuffer(session_data_ptr, sendbuffer, datalen);
3258 status = SORRYSERVER_SEND;
3261 session_data_ptr->last_status = status;
3266 /*-------- DEBUG LOG --------*/
3267 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3269 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3270 "handle_sorryserver_connect() : catch exception e = %d. thread id : %d.");
3271 formatter % e % boost::this_thread::get_id();
3272 putLogDebug(600090, formatter.str(), __FILE__, __LINE__ );
3274 /*------DEBUG LOG END------*/
3279 catch (const std::exception& ex)
3281 std::cerr << "protocol_module_ip::handle_sorryserver_connect() : exception : error = " << ex.what() << "." << std::endl;
3282 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3283 "handle_sorryserver_connect() : exception : error = %s. thread id : %d.");
3284 formatter % ex.what() % boost::this_thread::get_id();
3285 putLogError(600060, formatter.str(), __FILE__, __LINE__ );
3292 std::cerr << "protocol_module_ip::handle_sorryserver_connect() : Unknown exception." << std::endl;
3293 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3294 "handle_sorryserver_connect() : Unknown exception. thread id : %d.");
3295 formatter % boost::this_thread::get_id();
3296 putLogError(600061, formatter.str(), __FILE__, __LINE__ );
3302 /*-------- DEBUG LOG --------*/
3303 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3305 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3306 "handle_sorryserver_connect(const boost::thread::id thread_id, "
3307 "boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
3308 "size_t& datalen) : return_value = %d. thread id : %d.");
3309 formatter % status % boost::this_thread::get_id();
3310 putLogDebug(600091, formatter.str(), __FILE__, __LINE__ );
3312 /*------DEBUG LOG END------*/
3316 //! called from after sorryserver connection fail
3317 //! @param[in] upstream thread id
3318 //! @param[in] sorryserver endpoint reference.
3319 //! @return session use EVENT mode.
3320 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_connection_fail(
3321 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
3323 /*-------- DEBUG LOG --------*/
3324 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3326 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3327 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
3328 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
3329 "thread_id = %d, sorry_endpoint = [%s]:%d.");
3330 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
3331 putLogDebug(600092, formatter.str(), __FILE__, __LINE__ );
3333 /*------DEBUG LOG END------*/
3335 EVENT_TAG status = FINALIZE;
3336 thread_data_ptr session_data_ptr;
3337 session_thread_data_map_it session_thread_it;
3341 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3343 session_thread_it = session_thread_data_map.find(thread_id);
3344 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3346 boost::format formatter("Invalid thread id. thread id : %d.");
3347 formatter % boost::this_thread::get_id();
3348 putLogError(600062, formatter.str(), __FILE__, __LINE__ );
3352 session_data_ptr = session_thread_it->second;
3355 status = CLIENT_DISCONNECT;
3358 session_data_ptr->last_status = status;
3362 /*-------- DEBUG LOG --------*/
3363 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3365 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3366 "handle_sorryserver_connection_fail() : catch exception e = %d. thread id : %d.");
3367 formatter % e % boost::this_thread::get_id();
3368 putLogDebug(600093, formatter.str(), __FILE__, __LINE__ );
3370 /*------DEBUG LOG END------*/
3375 catch (const std::exception& ex)
3377 std::cerr << "protocol_module_ip::handle_sorryserver_connection_fail() : exception : error = " << ex.what() << "." << std::endl;
3378 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3379 "handle_sorryserver_connection_fail() : exception : error = %s. thread id : %d.");
3380 formatter % ex.what() % boost::this_thread::get_id();
3381 putLogError(600063, formatter.str(), __FILE__, __LINE__ );
3388 std::cerr << "protocol_module_ip::handle_sorryserver_connection_fail() : Unknown exception." << std::endl;
3389 boost::format formatter("function : protocol_module_base::EVENT_TAG "
3390 "protocol_module_ip::handle_sorryserver_connection_fail() : "
3391 "Unknown exception. thread id : %d.");
3392 formatter % boost::this_thread::get_id();
3393 putLogError(600064, formatter.str(), __FILE__, __LINE__ );
3399 /*-------- DEBUG LOG --------*/
3400 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3402 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3403 "handle_sorryserver_connection_fail(const boost::thread::id thread_id, "
3404 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : return_value = %d. thread id : %d.");
3405 formatter % status % boost::this_thread::get_id();
3406 putLogDebug(600094, formatter.str(), __FILE__, __LINE__ );
3408 /*------DEBUG LOG END------*/
3413 //! called from after sorryserver send
3414 //! @param[in] upstream thread id
3415 //! @return session use EVENT mode.
3416 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_send(
3417 const boost::thread::id thread_id)
3419 /*-------- DEBUG LOG --------*/
3420 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3422 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3423 "handle_sorryserver_send(const boost::thread::id thread_id) : thread_id = %d.");
3424 formatter % thread_id;
3425 putLogDebug(600095, formatter.str(), __FILE__, __LINE__ );
3427 /*------DEBUG LOG END------*/
3429 EVENT_TAG status = FINALIZE;
3430 size_t http_header_all_offset = 0;
3431 size_t http_header_all_len = 0;
3432 size_t http_header_content_length_offset = 0;
3433 size_t http_header_content_length_len = 0;
3434 const size_t CR_LF_LEN = 2;
3435 const size_t CR_LF_CR_LF_LEN = 4;
3436 int content_length_value = 0;
3438 std::string content_length;
3440 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
3443 bool find_ret = false;
3444 http_utility::CHECK_RESULT_TAG check_ret;
3446 thread_data_ptr session_data_ptr;
3447 session_thread_data_map_it session_thread_it;
3452 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3455 session_thread_it = session_thread_data_map.find(thread_id);
3456 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3458 boost::format formatter("Invalid thread id. thread id : %d.");
3459 formatter % boost::this_thread::get_id();
3460 putLogError(600065, formatter.str(), __FILE__, __LINE__ );
3464 session_data_ptr = session_thread_it->second;
3467 //current_message_rest_size > 0
3468 if (session_data_ptr->current_message_rest_size > 0)
3471 if (session_data_ptr->data_length > 0)
3474 status = SORRYSERVER_CONNECT;
3480 session_data_ptr->data_offset = 0;
3483 status = CLIENT_RECV;
3486 //current_message_rest_size is 0
3490 if (session_data_ptr->data_length> 0)
3492 //data state is HTTP_BODY
3493 if (session_data_ptr->data_state == HTTP_BODY)
3495 //search whole http header, get whole http header's offset and length
3496 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3497 session_data_ptr->data_length,
3498 http_header_all_offset,
3502 /*-------- DEBUG LOG --------*/
3503 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3505 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3506 "handle_sorryserver_send() : call find_http_header_all : "
3507 "return_value = %d. thread id : %d.");
3508 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3509 putLogDebug(600096, formatter.str(), __FILE__, __LINE__ );
3511 /*------DEBUG LOG END------*/
3513 //search http header result is NG
3516 //set data state HTTP_START
3517 session_data_ptr->data_state = HTTP_START;
3520 status = CLIENT_RECV;
3522 //check method and version result is OK
3525 //search Content_Length header
3526 check_ret = http_utility::check_http_method_and_version(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3527 session_data_ptr->data_length);
3529 /*-------- DEBUG LOG --------*/
3530 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3532 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3533 "handle_sorryserver_send() : call check_http_method_and_version : "
3534 "return_value = %d. thread id : %d.");
3535 formatter % check_ret % boost::this_thread::get_id();
3536 putLogDebug(600097, formatter.str(), __FILE__, __LINE__ );
3538 /*------DEBUG LOG END------*/
3540 //check method and version result is NG
3541 if (check_ret == http_utility::CHECK_NG)
3543 //set current message rest size
3544 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3546 //set data state UNKNOWN
3547 session_data_ptr->data_state = UNKNOWN;
3549 //check method and version result is OK
3552 //search Content_Length header
3553 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
3554 session_data_ptr->data_length,
3555 http_header_content_length_offset,
3556 http_header_content_length_len);
3558 /*-------- DEBUG LOG --------*/
3559 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3561 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3562 "handle_sorryserver_send() : call find_http_header_content_length : "
3563 "return_value = %d. thread id : %d.");
3564 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3565 putLogDebug(600098, formatter.str(), __FILE__, __LINE__ );
3567 /*------DEBUG LOG END------*/
3569 //search Content_Length result is OK
3572 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
3573 http_header_content_length_len );
3574 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
3576 //"content-length: ddd\r\n"
3579 content_length = content_length.substr(
3580 regex_ret.position(1),
3581 regex_ret.length(1));
3583 //set content length value
3584 content_length_value = boost::lexical_cast<int>(content_length);
3587 //http_header context is "\r\n\r\n" only
3588 if (http_header_all_len == 0)
3590 //set current message rest size
3591 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_LEN;
3595 //set current message rest size
3596 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_CR_LF_LEN;
3599 //search Content_Length result is OK
3602 //http_header context is "\r\n\r\n" only
3603 if (http_header_all_len == 0)
3605 //set current message rest size
3606 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_LEN;
3610 //set current message rest size
3611 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_CR_LF_LEN;
3616 //set data state HTTP_HEADER
3617 session_data_ptr->data_state = HTTP_HEADER;
3621 status = SORRYSERVER_CONNECT;
3624 //data state is UNKNOWN
3625 else if (session_data_ptr->data_state == UNKNOWN)
3628 status = SORRYSERVER_CONNECT;
3635 //data state is HTTP_BODY
3636 if (session_data_ptr->data_state == HTTP_BODY)
3638 //set data state HTTP_START
3639 session_data_ptr->data_state = HTTP_START;
3643 session_data_ptr->data_offset = 0;
3646 status = CLIENT_RECV;
3651 session_data_ptr->last_status = status;
3655 /*-------- DEBUG LOG --------*/
3656 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3658 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3659 "handle_sorryserver_send() : catch exception e = %d. thread id : %d.");
3660 formatter % e % boost::this_thread::get_id();
3661 putLogDebug(600099, formatter.str(), __FILE__, __LINE__ );
3663 /*------DEBUG LOG END------*/
3668 catch (const boost::bad_lexical_cast& )
3670 std::cerr << "protocol_module_ip::handle_sorryserver_send() : exception : " << "Content_Length field's value is invalid." << std::endl;
3671 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_send() : "
3672 "Content_Length field's value is invalid. thread id : %d.");
3673 formatter % boost::this_thread::get_id();
3674 putLogError(600066, formatter.str(), __FILE__, __LINE__ );
3679 catch (const std::exception& ex)
3681 std::cerr << "protocol_module_ip::handle_sorryserver_send() : exception : error = " << ex.what() << "." << std::endl;
3682 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3683 "handle_sorryserver_send() : exception : error = %s. thread id : %d.");
3684 formatter % ex.what() % boost::this_thread::get_id();
3685 putLogError(600067, formatter.str(), __FILE__, __LINE__ );
3692 std::cerr << "protocol_module_ip::handle_sorryserver_send() : Unknown exception." << std::endl;
3693 boost::format formatter("function : protocol_module_base::EVENT_TAG "
3694 "protocol_module_ip::handle_sorryserver_send() : "
3695 "Unknown exception. thread id : %d.");
3696 formatter % boost::this_thread::get_id();
3697 putLogError(600068, formatter.str(), __FILE__, __LINE__ );
3703 /*-------- DEBUG LOG --------*/
3704 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3706 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3707 "handle_sorryserver_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
3708 formatter % status % boost::this_thread::get_id();
3709 putLogDebug(600100, formatter.str(), __FILE__, __LINE__ );
3711 /*------DEBUG LOG END------*/
3716 //! called from after realserver recive.for UDP
3717 //! @param[in] downstream thread id
3718 //! @param[in] realserver UDP endpoint reference
3719 //! @param[in] recive from realserver buffer reference
3720 //! @param[in] recv data length
3721 //! @return session use EVENT mode.
3722 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_recv(
3723 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,
3724 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
3726 /*-------- DEBUG LOG --------*/
3727 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3729 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3730 "handle_realserver_recv(const boost::thread::id thread_id, "
3731 "const boost::asio::ip::udp::endpoint& rs_endpoint, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3732 "const size_t& recvlen) : "
3733 "return_value = %d. thread id : %d.");
3734 formatter % STOP % boost::this_thread::get_id();
3735 putLogDebug(600101, formatter.str(), __FILE__, __LINE__ );
3737 /*------DEBUG LOG END------*/
3741 //! called from after realserver recvive for TCP/IP
3742 //! @param[in] downstream thread id
3743 //! @param[in] realserver TCP/IP endpoint reference
3744 //! @param[in] realserver recive buffer reference.
3745 //! @param[in] recv data length
3746 //! @return session use EVENT mode.
3747 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_recv(
3748 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& rs_endpoint, const boost::array<char,
3749 MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
3751 /*-------- DEBUG LOG --------*/
3752 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3754 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
3756 dump_memory(recvbuffer.data(), buffer_size, buffer);
3757 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3758 "handle_realserver_recv(const boost::thread::id thread_id, "
3759 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
3760 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3761 "const size_t recvlen) : thread_id = %d, rs_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
3762 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port()
3764 putLogDebug(600102, formatter.str(), __FILE__, __LINE__ );
3766 /*------DEBUG LOG END------*/
3768 EVENT_TAG status = FINALIZE;
3770 bool find_ret = false;
3771 size_t http_header_offset = 0;
3772 size_t http_header_len = 0;
3773 size_t http_header_content_length_offset = 0;
3774 size_t http_header_content_length_len = 0;
3775 int content_length_value = 0;
3776 const size_t CR_LF_LEN = 2; //length of "\r\n"
3777 const size_t CR_LF_CR_LF_LEN = 4; //length of "\r\n\r\n"
3779 session_thread_data_map_it session_thread_it;
3780 thread_data_ptr session_data_ptr;
3781 http_utility::CHECK_RESULT_TAG check_ret;
3783 std::string content_length;
3785 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
3787 if (unlikely(recvlen > recvbuffer.size()))
3789 std::cerr << "protocol_module_ip::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
3790 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
3791 formatter % boost::this_thread::get_id();
3792 putLogError(600069, formatter.str(), __FILE__, __LINE__ );
3794 /*-------- DEBUG LOG --------*/
3795 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3797 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3798 "handle_realserver_recv(const boost::thread::id thread_id, "
3799 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
3800 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3801 "const size_t recvlen) : return_value = %d. thread id : %d.");
3802 formatter % FINALIZE % boost::this_thread::get_id();
3803 putLogDebug(600103, formatter.str(), __FILE__, __LINE__ );
3805 /*------DEBUG LOG END------*/
3813 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
3815 session_thread_it = session_thread_data_map.find(thread_id);
3816 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
3818 boost::format formatter("Invalid thread id. thread id : %d.");
3819 formatter % boost::this_thread::get_id();
3820 putLogError(600070, formatter.str(), __FILE__, __LINE__ );
3824 session_data_ptr = session_thread_it->second;
3827 //set switch flag off
3828 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
3830 /*-------- DEBUG LOG --------*/
3831 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3833 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3834 "handle_realserver_recv(const boost::thread::id thread_id, "
3835 "const boost::asio::ip::tcp::endpoint& rs_endpoint, "
3836 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
3837 "const size_t recvlen) : SWITCH_FLAG_OFF. "
3838 "thread_id = %d, rs_endpoint = [%s]:%d.");
3839 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
3840 putLogDebug(600104, formatter.str(), __FILE__, __LINE__ );
3842 /*------DEBUG LOG END------*/
3844 //copy data from recvbuffer
3845 if (!get_data_from_recvbuffer(session_data_ptr, recvbuffer, recvlen))
3848 std::cerr << "protocol_module_ip::handle_realserver_recv() : Data size bigger than buffer size." << std::endl;
3849 boost::format formatter("Data size bigger than buffer size. thread id : % id.");
3850 formatter % boost::this_thread::get_id();
3851 putLogError(600071, formatter.str(), __FILE__, __LINE__);
3856 //data state is HTTP_START
3857 if (session_data_ptr->data_state == HTTP_START)
3859 //search http header
3860 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
3861 session_data_ptr->data_length,
3866 /*-------- DEBUG LOG --------*/
3867 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3869 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3870 "handle_realserver_recv() : call find_http_header_all : "
3871 "return_value = %d. thread id : %d.");
3872 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3873 putLogDebug(600105, formatter.str(), __FILE__, __LINE__ );
3875 /*------DEBUG LOG END------*/
3877 //search http header result is NG
3880 //data size bigger than max buffer size
3881 if (session_data_ptr->data_length >= MAX_IP_MODULE_BUFFER_SIZE - recvbuffer.size())
3883 //set data state UNKNOWN
3884 session_data_ptr->data_state = UNKNOWN;
3885 //set current message rest size
3886 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3889 //search http header result is OK
3892 //check http version and status code
3893 check_ret = http_utility::check_http_version_and_status_code(session_data_ptr->data_buffer,
3894 session_data_ptr->data_length);
3896 /*-------- DEBUG LOG --------*/
3897 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3899 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3900 "handle_realserver_recv() : call check_http_version_and_status_code : "
3901 "return_value = %d. thread id : %d.");
3902 formatter % check_ret % boost::this_thread::get_id();
3903 putLogDebug(600106, formatter.str(), __FILE__, __LINE__ );
3905 /*------DEBUG LOG END------*/
3907 //check http version and status code result is NG
3908 if (check_ret == http_utility::CHECK_NG)
3910 //set data state UNKNOWN
3911 session_data_ptr->data_state = UNKNOWN;
3912 //set current message rest size
3913 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3915 //check http version and status code result is OK
3918 //search Content_Length header
3919 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
3920 session_data_ptr->data_length,
3921 http_header_content_length_offset,
3922 http_header_content_length_len);
3924 /*-------- DEBUG LOG --------*/
3925 if (unlikely(LOG_LV_DEBUG == getloglevel()))
3927 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
3928 "handle_realserver_recv() : call find_http_header_content_length : "
3929 "return_value = %d. thread id : %d.");
3930 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
3931 putLogDebug(600107, formatter.str(), __FILE__, __LINE__ );
3933 /*------DEBUG LOG END------*/
3935 //search Content_Length result is OK
3938 //set content length string
3939 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
3940 http_header_content_length_len );
3941 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
3943 //"content-length: ddd\r\n"
3946 content_length = content_length.substr(
3947 regex_ret.position(1),
3948 regex_ret.length(1));
3950 //set content length value
3951 content_length_value = boost::lexical_cast<int>(content_length);
3954 //http_header context is "\r\n\r\n" only
3955 if (http_header_len == 0)
3957 //set current message rest size
3958 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_LEN;
3962 //set current message rest size
3963 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_CR_LF_LEN;
3966 //search Content_Length result is NG
3969 //http_header context is "\r\n\r\n" only
3970 if (http_header_len == 0)
3972 //set current message rest size
3973 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_LEN;
3977 //set current message rest size
3978 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_CR_LF_LEN;
3983 //set data state HTTP_HEADER
3984 session_data_ptr->data_state = HTTP_HEADER;
3988 //data state is UNKNOWN
3989 else if (session_data_ptr->data_state == UNKNOWN)
3991 //set current message rest size
3992 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
3999 //data state is HTTP_START
4000 if (session_data_ptr->data_state == HTTP_START)
4003 status = REALSERVER_RECV;
4005 //data state is not HTTP_START
4009 status = CLIENT_CONNECTION_CHECK;
4014 session_data_ptr->last_status = status;
4018 /*-------- DEBUG LOG --------*/
4019 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4021 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4022 "handle_realserver_recv() : catch exception e = %d. thread id : %d.");
4023 formatter % e % boost::this_thread::get_id();
4024 putLogDebug(600108, formatter.str(), __FILE__, __LINE__ );
4026 /*------DEBUG LOG END------*/
4031 catch (const boost::bad_lexical_cast& )
4033 std::cerr << "protocol_module_ip::handle_realserver_recv() : exception : " << "Content_Length field's value is invalid." << std::endl;
4034 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_recv() : "
4035 "Content_Length field's value is invalid. thread id : %d.");
4036 formatter % boost::this_thread::get_id();
4037 putLogError(600072, formatter.str(), __FILE__, __LINE__ );
4042 catch (const std::exception& ex)
4044 std::cerr << "protocol_module_ip::handle_realserver_recv() : exception : error = " << ex.what() << "." << std::endl;
4045 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4046 "handle_realserver_recv() : exception : error = %s. thread id : %d.");
4047 formatter % ex.what() % boost::this_thread::get_id();
4048 putLogError(600073, formatter.str(), __FILE__, __LINE__ );
4055 std::cerr << "protocol_module_ip::handle_realserver_recv() : Unknown exception." << std::endl;
4056 boost::format formatter("function : protocol_module_base::EVENT_TAG "
4057 "protocol_module_ip::handle_realserver_recv() : "
4058 "Unknown exception. thread id : %d.");
4059 formatter % boost::this_thread::get_id();
4060 putLogError(600074, 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_realserver_recv(const boost::thread::id thread_id, "
4071 "const boost::asio::ip::tcp::endpoint& rs_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(600109, formatter.str(), __FILE__, __LINE__ );
4077 /*------DEBUG LOG END------*/
4084 //! called from after sorryserver recive
4085 //! @param[in] downstream thread id
4086 //! @param[in] sorryserver endpoint reference
4087 //! @param[in] recive from realserver buffer reference.
4088 //! @param[in] recv data length
4089 //! @return session use EVENT mode
4090 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_recv(
4091 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint& sorry_endpoint, const boost::array<
4092 char, MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
4094 /*-------- DEBUG LOG --------*/
4095 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4097 size_t buffer_size = recvbuffer.size() < recvlen ? recvbuffer.size() : recvlen;
4099 dump_memory(recvbuffer.data(), buffer_size, buffer);
4100 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4101 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4102 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4103 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4104 "const size_t recvlen) : thread_id = %d, sorry_endpoint = [%s]:%d, recvbuffer = %s, recvlen = %d.");
4105 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port()
4107 putLogDebug(600110, formatter.str(), __FILE__, __LINE__ );
4109 /*------DEBUG LOG END------*/
4111 EVENT_TAG status = FINALIZE;
4112 bool find_ret = false;
4113 size_t http_header_offset = 0;
4114 size_t http_header_len = 0;
4115 size_t http_header_content_length_offset = 0;
4116 size_t http_header_content_length_len = 0;
4117 int content_length_value = 0;
4118 const size_t CR_LF_LEN = 2; //length of "\r\n"
4119 const size_t CR_LF_CR_LF_LEN = 4; //length of "\r\n\r\n"
4121 session_thread_data_map_it session_thread_it;
4122 thread_data_ptr session_data_ptr;
4123 http_utility::CHECK_RESULT_TAG check_ret;
4124 std::string content_length;
4126 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
4128 if (unlikely(recvlen > recvbuffer.size()))
4130 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
4131 boost::format formatter("Data size bigger than buffer size. thread id : %d.");
4132 formatter % boost::this_thread::get_id();
4133 putLogError(600075, formatter.str(), __FILE__, __LINE__ );
4135 /*-------- DEBUG LOG --------*/
4136 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4138 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4139 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4140 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4141 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4142 "const size_t recvlen) : return_value = %d. thread id : %d.");
4143 formatter % FINALIZE % boost::this_thread::get_id();
4144 putLogDebug(600111, formatter.str(), __FILE__, __LINE__ );
4146 /*------DEBUG LOG END------*/
4154 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
4156 session_thread_it = session_thread_data_map.find(thread_id);
4157 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4159 boost::format formatter("Invalid thread id. thread id : %d.");
4160 formatter % boost::this_thread::get_id();
4161 putLogError(600076, formatter.str(), __FILE__, __LINE__ );
4165 session_data_ptr = session_thread_it->second;
4168 //set switch flag off
4169 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
4171 /*-------- DEBUG LOG --------*/
4172 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4174 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4175 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4176 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4177 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4178 "const size_t recvlen) : SWITCH_FLAG_OFF. "
4179 "thread_id = %d, rs_endpoint = [%s]:%d.");
4180 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
4181 putLogDebug(600112, formatter.str(), __FILE__, __LINE__ );
4183 /*------DEBUG LOG END------*/
4185 //copy data from recvbuffer
4186 if (!get_data_from_recvbuffer(session_data_ptr, recvbuffer, recvlen))
4189 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : Data size bigger than buffer size." << std::endl;
4190 boost::format formatter("Data size bigger than buffer size. thread id : % id.");
4191 formatter % boost::this_thread::get_id();
4192 putLogError(600077, formatter.str(), __FILE__, __LINE__);
4198 //data state is HTTP_START
4199 if (session_data_ptr->data_state == HTTP_START)
4201 //search http header
4202 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
4203 session_data_ptr->data_length,
4208 /*-------- DEBUG LOG --------*/
4209 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4211 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4212 "handle_sorryserver_recv() : call find_http_header_all : "
4213 "return_value = %d. thread id : %d.");
4214 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4215 putLogDebug(600113, formatter.str(), __FILE__, __LINE__ );
4217 /*------DEBUG LOG END------*/
4219 //search http header result is NG
4222 //data size bigger than max buffer size
4223 if (session_data_ptr->data_length >= MAX_IP_MODULE_BUFFER_SIZE - recvbuffer.size())
4225 //set data state UNKNOWN
4226 session_data_ptr->data_state = UNKNOWN;
4227 //set current message rest size
4228 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4231 //search http header result is OK
4234 //check http version and status code
4235 check_ret = http_utility::check_http_version_and_status_code(session_data_ptr->data_buffer,
4236 session_data_ptr->data_length);
4238 /*-------- DEBUG LOG --------*/
4239 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4241 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4242 "handle_sorryserver_recv() : call check_http_version_and_status_code : "
4243 "return_value = %d. thread id : %d.");
4244 formatter % check_ret % boost::this_thread::get_id();
4245 putLogDebug(600114, formatter.str(), __FILE__, __LINE__ );
4247 /*------DEBUG LOG END------*/
4249 //check http version and status code result is NG
4250 if (check_ret == http_utility::CHECK_NG)
4252 //set data state UNKNOWN
4253 session_data_ptr->data_state = UNKNOWN;
4254 //set current message rest size
4255 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4257 //check http version and status code result is OK
4260 //search Content_Length header
4261 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
4262 session_data_ptr->data_length,
4263 http_header_content_length_offset,
4264 http_header_content_length_len);
4266 /*-------- DEBUG LOG --------*/
4267 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4269 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4270 "handle_sorryserver_recv() : call find_http_header_content_length : "
4271 "return_value = %d. thread id : %d.");
4272 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4273 putLogDebug(600115, formatter.str(), __FILE__, __LINE__ );
4275 /*------DEBUG LOG END------*/
4277 //search Content_Length result is OK
4280 ////set content length string
4281 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
4282 http_header_content_length_len );
4283 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
4285 //"content-length: ddd\r\n"
4288 content_length = content_length.substr(
4289 regex_ret.position(1),
4290 regex_ret.length(1));
4292 //set content length value
4293 content_length_value = boost::lexical_cast<int>(content_length);
4296 //http_header context is "\r\n\r\n" only
4297 if (http_header_len == 0)
4299 //set current message rest size
4300 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_LEN;
4304 //set current message rest size
4305 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + content_length_value + CR_LF_CR_LF_LEN;
4308 //search Content_Length result is NG
4311 //http_header context is "\r\n\r\n" only
4312 if (http_header_len == 0)
4314 //set current message rest size
4315 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_LEN;
4319 //set current message rest size
4320 session_data_ptr->current_message_rest_size = http_header_offset + http_header_len + CR_LF_CR_LF_LEN;
4325 //set data state HTTP_HEADER
4326 session_data_ptr->data_state = HTTP_HEADER;
4331 //data state is UNKNOWN
4332 else if (session_data_ptr->data_state == UNKNOWN)
4334 //set current message rest size
4335 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4342 //data state is HTTP_START
4343 if (session_data_ptr->data_state == HTTP_START)
4346 status = SORRYSERVER_RECV;
4348 //data state is not HTTP_START
4352 status = CLIENT_CONNECTION_CHECK;
4357 session_data_ptr->last_status = status;
4361 /*-------- DEBUG LOG --------*/
4362 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4364 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4365 "handle_sorryserver_recv() : catch exception e = %d. thread id : %d.");
4366 formatter % e % boost::this_thread::get_id();
4367 putLogDebug(600116, formatter.str(), __FILE__, __LINE__ );
4369 /*------DEBUG LOG END------*/
4374 catch (const boost::bad_lexical_cast& )
4376 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : exception : " << "Content_Length field's value is invalid." << std::endl;
4377 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_recv() : "
4378 "Content_Length field's value is invalid. thread id : %d.");
4379 formatter % boost::this_thread::get_id();
4380 putLogError(600078, formatter.str(), __FILE__, __LINE__ );
4385 catch (const std::exception& ex)
4387 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : exception : error = " << ex.what() << "." << std::endl;
4388 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4389 "handle_sorryserver_recv() : exception : error = %s. thread id : %d.");
4390 formatter % ex.what() % boost::this_thread::get_id();
4391 putLogError(600079, formatter.str(), __FILE__, __LINE__ );
4398 std::cerr << "protocol_module_ip::handle_sorryserver_recv() : Unknown exception." << std::endl;
4399 boost::format formatter("function : protocol_module_base::EVENT_TAG "
4400 "protocol_module_ip::handle_sorryserver_recv() : "
4401 "Unknown exception. thread id : %d.");
4402 formatter % boost::this_thread::get_id();
4403 putLogError(600080, formatter.str(), __FILE__, __LINE__ );
4409 /*-------- DEBUG LOG --------*/
4410 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4412 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4413 "handle_sorryserver_recv(const boost::thread::id thread_id, "
4414 "const boost::asio::ip::tcp::endpoint& sorry_endpoint, "
4415 "const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
4416 "const size_t recvlen) : return_value = %d. thread id : %d.");
4417 formatter % FINALIZE % boost::this_thread::get_id();
4418 putLogDebug(600117, formatter.str(), __FILE__, __LINE__ );
4420 /*------DEBUG LOG END------*/
4426 //! called from UPSTEEARM thread. make module original message.
4427 //! @param[in] downstream thread id.
4428 //! @return session use EVENT mode
4429 protocol_module_base::EVENT_TAG protocol_module_ip::handle_response_send_inform(
4430 const boost::thread::id thread_id)
4432 /*-------- DEBUG LOG --------*/
4433 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4435 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4436 "handle_response_send_inform(const boost::thread::id thread_id) : "
4437 "return_value = %d. thread id : %d.");
4438 formatter % STOP % boost::this_thread::get_id();
4439 putLogDebug(600118, formatter.str(), __FILE__, __LINE__ );
4441 /*------DEBUG LOG END------*/
4446 //! called from after client connection check. use TCP/IP only. create client send message.
4447 //! @param[in] downstream thread id
4448 //! @param[out] send budffer reference
4449 //! @param[out] send data length
4450 //! @return session use EVENT mode
4451 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_connection_check(
4452 const boost::thread::id thread_id, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
4454 /*-------- DEBUG LOG --------*/
4455 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4457 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4458 "handle_client_connection_check(const boost::thread::id thread_id, "
4459 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : "
4461 formatter % thread_id;
4462 putLogDebug(600119, formatter.str(), __FILE__, __LINE__ );
4464 /*------DEBUG LOG END------*/
4466 EVENT_TAG status = FINALIZE;
4467 thread_data_ptr session_data_ptr;
4468 size_t send_possible_size = 0;
4473 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
4475 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
4476 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4478 boost::format formatter("Invalid thread id. thread id : %d.");
4479 formatter % boost::this_thread::get_id();
4480 putLogError(600081, formatter.str(), __FILE__, __LINE__ );
4484 session_data_ptr = session_thread_it->second;
4487 //data state is HTTP_HEADER
4488 if (session_data_ptr->data_state == HTTP_HEADER)
4490 //set data HTTP_BODY
4491 session_data_ptr->data_state = HTTP_BODY;
4494 //set send possible data size
4495 send_possible_size = std::min(std::min(sendbuffer.size(), session_data_ptr->current_message_rest_size),
4496 session_data_ptr->data_length
4498 //set send data size
4499 datalen = send_possible_size;
4501 /*-------- DEBUG LOG --------*/
4502 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4504 std::string datadump;
4505 dump_memory(session_data_ptr->data_buffer + session_data_ptr->data_offset, send_possible_size, datadump);
4507 boost::format formatter(
4508 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4509 "handle_client_connection_check() : before memcpy (data dump) : "
4510 "data begin = %d, data_size = %d, data = %s");
4511 formatter % session_data_ptr->data_offset % send_possible_size % datadump;
4512 putLogDebug(600120, formatter.str(), __FILE__, __LINE__ );
4514 /*------DEBUG LOG END------*/
4516 //copy send possible data to sendbuffer
4517 memcpy(sendbuffer.data(), session_data_ptr->data_buffer + session_data_ptr->data_offset,
4518 send_possible_size);
4520 /*-------- DEBUG LOG --------*/
4521 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4523 std::string datadump;
4524 dump_memory(sendbuffer.data(), send_possible_size, datadump);
4526 boost::format formatter(
4527 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4528 "handle_client_connection_check() : after memcpy (data dump) : "
4529 "data begin = 0, data_size = %d, data = %s");
4530 formatter % send_possible_size % datadump;
4531 putLogDebug(600121, formatter.str(), __FILE__, __LINE__ );
4533 /*------DEBUG LOG END------*/
4535 //set current message rest size
4536 session_data_ptr->current_message_rest_size -= send_possible_size;
4538 //set buffer's position
4539 session_data_ptr->data_offset += send_possible_size;
4540 session_data_ptr->data_length -= send_possible_size;
4542 //current message rest size is 0
4543 if (session_data_ptr->current_message_rest_size == 0)
4545 boost::mutex::scoped_lock lock(session_data_mutex);
4548 boost::asio::ip::tcp::endpoint init_endpoint;
4550 //write session data to session table
4551 ip_data_processor->write_session_data(session_data_ptr->ip_hash,
4558 status = CLIENT_SEND;
4561 session_data_ptr->last_status = status;
4565 /*-------- DEBUG LOG --------*/
4566 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4568 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4569 "handle_client_connection_check() : catch exception e = %d. thread id : %d.");
4570 formatter % e % boost::this_thread::get_id();
4571 putLogDebug(600122, formatter.str(), __FILE__, __LINE__ );
4573 /*------DEBUG LOG END------*/
4578 catch (const std::exception& ex)
4580 std::cerr << "protocol_module_ip::handle_client_connection_check() : exception : error = " << ex.what() << "." << std::endl;
4581 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4582 "handle_client_connection_check() : exception : error = %s. thread id : %d.");
4583 formatter % ex.what() % boost::this_thread::get_id();
4584 putLogError(600082, formatter.str(), __FILE__, __LINE__ );
4591 std::cerr << "protocol_module_ip::handle_client_connection_check() : Unknown exception." << std::endl;
4592 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4593 "handle_client_connection_check() : Unknown exception. thread id : %d.");
4594 formatter % boost::this_thread::get_id();
4595 putLogError(600083, formatter.str(), __FILE__, __LINE__ );
4601 /*-------- DEBUG LOG --------*/
4602 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4604 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4605 "handle_client_connection_check(const boost::thread::id thread_id, "
4606 "boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen) : return_value = %d. thread id : %d.");
4607 formatter % status % boost::this_thread::get_id();
4608 putLogDebug(600123, formatter.str(), __FILE__, __LINE__ );
4610 /*------DEBUG LOG END------*/
4615 //! called from after client select. use UDP only
4616 //! @param[in] downstream thread id
4617 //! @param[in] client udp endpoint
4618 //! @param[out] send buffer reference
4619 //! @param[out] send data length
4620 //! @return session use EVENT mode
4621 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_select(
4622 const boost::thread::id thread_id, boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,
4623 MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
4625 /*-------- DEBUG LOG --------*/
4626 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4628 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4629 "handle_client_select(const boost::thread::id thread_id, "
4630 "boost::asio::ip::udp::endpoint& cl_endpoint, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
4631 "const size_t& datalen) : "
4632 "return_value = %d. thread id : %d.");
4633 formatter % STOP % boost::this_thread::get_id();
4634 putLogDebug(600124, formatter.str(), __FILE__, __LINE__ );
4636 /*------DEBUG LOG END------*/
4640 //! called from after client send
4641 //! @param[in] downstream thread id
4642 //! @return session use EVENT mode
4643 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_send(
4644 const boost::thread::id thread_id)
4646 /*-------- DEBUG LOG --------*/
4647 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4649 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4650 "handle_client_send(const boost::thread::id thread_id) : thread_id = %d.");
4651 formatter % thread_id;
4652 putLogDebug(600125, formatter.str(), __FILE__, __LINE__ );
4654 /*------DEBUG LOG END------*/
4656 EVENT_TAG status = FINALIZE;
4657 size_t http_header_all_offset = 0;
4658 size_t http_header_all_len = 0;
4659 size_t http_header_content_length_offset= 0;
4660 size_t http_header_content_length_len = 0;
4661 const size_t CR_LF_LEN = 2;
4662 const size_t CR_LF_CR_LF_LEN = 4;
4663 int content_length_value = 0;
4665 std::string content_length;
4667 cregex content_length_regex = icase("Content-Length") >> ":" >> *~_d >> (s1 = +_d) >> *~_d;
4670 bool find_ret = false;
4671 http_utility::CHECK_RESULT_TAG check_ret;
4673 thread_data_ptr session_data_ptr;
4674 session_thread_data_map_it session_thread_it;
4679 boost::mutex::scoped_lock slock(session_thread_data_map_mutex);
4682 session_thread_it = session_thread_data_map.find(thread_id);
4683 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
4685 boost::format formatter("Invalid thread id. thread id : %d.");
4686 formatter % boost::this_thread::get_id();
4687 putLogError(600084, formatter.str(), __FILE__, __LINE__ );
4691 session_data_ptr = session_thread_it->second;
4694 //current_message_rest_size > 0
4695 if (session_data_ptr->current_message_rest_size > 0)
4698 if (session_data_ptr->data_length > 0)
4701 status = CLIENT_CONNECTION_CHECK;
4707 session_data_ptr->data_offset = 0;
4710 status = REALSERVER_RECV;
4713 //current_message_rest_size is 0
4717 if (session_data_ptr->data_length > 0)
4719 //data state is HTTP_BODY
4720 if (session_data_ptr->data_state == HTTP_BODY)
4722 //search whole http header, get whole http header's offset and length
4723 find_ret = http_utility::find_http_header_all(session_data_ptr->data_buffer + session_data_ptr->data_offset,
4724 session_data_ptr->data_length,
4725 http_header_all_offset,
4729 /*-------- DEBUG LOG --------*/
4730 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4732 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4733 "handle_client_send() : call find_http_header_all : "
4734 "return_value = %d. thread id : %d.");
4735 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4736 putLogDebug(600126, formatter.str(), __FILE__, __LINE__ );
4738 /*------DEBUG LOG END------*/
4740 //search http header result is NG
4743 //set data state HTTP_START
4744 session_data_ptr->data_state = HTTP_START;
4747 status = REALSERVER_RECV;
4749 //search http header result is OK
4752 //check http version and status code
4753 check_ret = http_utility::check_http_version_and_status_code(session_data_ptr->data_buffer + session_data_ptr->data_offset,
4754 session_data_ptr->data_length);
4756 /*-------- DEBUG LOG --------*/
4757 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4759 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4760 "handle_client_send() : call check_http_version_and_status_code : "
4761 "return_value = %d. thread id : %d.");
4762 formatter % check_ret % boost::this_thread::get_id();
4763 putLogDebug(600127, formatter.str(), __FILE__, __LINE__ );
4765 /*------DEBUG LOG END------*/
4767 //check version and status code result is NG
4768 if (check_ret == http_utility::CHECK_NG)
4770 //set current message rest size
4771 session_data_ptr->current_message_rest_size = session_data_ptr->data_length;
4773 //set data state UNKNOWN
4774 session_data_ptr->data_state = UNKNOWN;
4776 //check version and status code result is OK
4779 //search Content_Length header
4780 find_ret = http_utility::find_http_header_content_length(session_data_ptr->data_buffer+session_data_ptr->data_offset,
4781 session_data_ptr->data_length,
4782 http_header_content_length_offset,
4783 http_header_content_length_len);
4785 /*-------- DEBUG LOG --------*/
4786 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4788 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4789 "handle_client_send() : call find_http_header_content_length : "
4790 "return_value = %d. thread id : %d.");
4791 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
4792 putLogDebug(600128, formatter.str(), __FILE__, __LINE__ );
4794 /*------DEBUG LOG END------*/
4796 //search Content_Length result is OK
4799 content_length.assign(session_data_ptr->data_buffer+session_data_ptr->data_offset + http_header_content_length_offset,
4800 http_header_content_length_len );
4801 find_ret = regex_search(content_length.c_str(), regex_ret, content_length_regex);
4803 //"content-length: ddd\r\n"
4806 content_length = content_length.substr(
4807 regex_ret.position(1),
4808 regex_ret.length(1));
4810 //set content length value
4811 content_length_value = boost::lexical_cast<int>(content_length);
4814 //http_header context is "\r\n\r\n" only
4815 if (http_header_all_len == 0)
4817 //set current message rest size
4818 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_LEN;
4822 //set current message rest size
4823 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + content_length_value + CR_LF_CR_LF_LEN;
4826 //search Content_Length result is OK
4829 //http_header context is "\r\n\r\n" only
4830 if (http_header_all_len == 0)
4832 //set current message rest size
4833 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_LEN;
4837 //set current message rest size
4838 session_data_ptr->current_message_rest_size = http_header_all_offset + http_header_all_len + CR_LF_CR_LF_LEN;
4843 //set data state HTTP_HEADER
4844 session_data_ptr->data_state = HTTP_HEADER;
4848 status = CLIENT_CONNECTION_CHECK;
4851 //data state is UNKNOWN
4852 else if (session_data_ptr->data_state == UNKNOWN)
4855 status = CLIENT_CONNECTION_CHECK;
4861 //data state is HTTP_BODY
4862 if (session_data_ptr->data_state == HTTP_BODY)
4864 //set data state HTTP_START
4865 session_data_ptr->data_state = HTTP_START;
4869 session_data_ptr->data_offset = 0;
4872 status = REALSERVER_RECV;
4876 //switch flag is on and status is REALSERVER_RECV
4877 if (session_data_ptr->switch_flag == SWITCH_FLAG_ON
4878 && status == REALSERVER_RECV)
4881 status = CLIENT_DISCONNECT;
4883 //sorry flag is on and and status is REALSERVER_RECV
4884 else if (session_data_ptr->sorry_flag == SORRY_FLAG_ON
4885 && status == REALSERVER_RECV)
4888 status = SORRYSERVER_RECV;
4896 session_data_ptr->last_status = status;
4900 /*-------- DEBUG LOG --------*/
4901 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4903 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4904 "handle_client_send() : catch exception e = %d. thread id : %d.");
4905 formatter % e % boost::this_thread::get_id();
4906 putLogDebug(600129, formatter.str(), __FILE__, __LINE__ );
4908 /*------DEBUG LOG END------*/
4913 catch (const boost::bad_lexical_cast& )
4915 std::cerr << "protocol_module_ip::handle_client_send() : exception : " << "Content_Length field's value is invalid." << std::endl;
4916 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_send() : "
4917 "Content_Length field's value is invalid. thread id : %d.");
4918 formatter % boost::this_thread::get_id();
4919 putLogError(600085, formatter.str(), __FILE__, __LINE__ );
4924 catch (const std::exception& ex)
4926 std::cerr << "protocol_module_ip::handle_client_send() : exception : error = " << ex.what() << "." << std::endl;
4927 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4928 "handle_client_send() : exception : error = %s. thread id : %d.");
4929 formatter % ex.what() % boost::this_thread::get_id();
4930 putLogError(600086, formatter.str(), __FILE__, __LINE__ );
4937 std::cerr << "protocol_module_ip::handle_client_send() : Unknown exception." << std::endl;
4938 boost::format formatter("function : protocol_module_base::EVENT_TAG "
4939 "protocol_module_ip::handle_client_send() : "
4940 "Unknown exception. thread id : %d.");
4941 formatter % boost::this_thread::get_id();
4942 putLogError(600087, formatter.str(), __FILE__, __LINE__ );
4948 /*-------- DEBUG LOG --------*/
4949 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4951 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4952 "handle_client_send(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4953 formatter % status % boost::this_thread::get_id();
4954 putLogDebug(600130, formatter.str(), __FILE__, __LINE__ );
4956 /*------DEBUG LOG END------*/
4961 //! call from client disconnect event. use upstream thread and downstream thread.
4962 //! @param[in] upstream and downstream thread id( check! one thread one event! )
4963 //! @return session use EVENT mode
4964 protocol_module_base::EVENT_TAG protocol_module_ip::handle_client_disconnect(
4965 const boost::thread::id thread_id)
4967 /*-------- DEBUG LOG --------*/
4968 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4970 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4971 "handle_client_disconnect(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
4972 formatter % FINALIZE % boost::this_thread::get_id();
4973 putLogDebug(600131, formatter.str(), __FILE__, __LINE__ );
4975 /*------DEBUG LOG END------*/
4979 //! call from sorry mode event. use upstream thread and downstream thread
4980 //! @param[in] upstream and downstream thread id( check! one thread one event and first time call pattern )
4981 //! @return session use EVENT mode
4982 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorry_enable(
4983 const boost::thread::id thread_id)
4985 /*-------- DEBUG LOG --------*/
4986 if (unlikely(LOG_LV_DEBUG == getloglevel()))
4988 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
4989 "handle_sorry_enable(const boost::thread::id thread_id) : thread_id = %d.");
4990 formatter % boost::this_thread::get_id();
4991 putLogDebug(600132, formatter.str(), __FILE__, __LINE__ );
4993 /*------DEBUG LOG END------*/
4995 EVENT_TAG status = FINALIZE;
4996 thread_data_ptr session_data_ptr;
5001 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
5003 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
5004 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5006 boost::format formatter("Invalid thread id. thread id : %d.");
5007 formatter % boost::this_thread::get_id();
5008 putLogError(600088, formatter.str(), __FILE__, __LINE__ );
5012 session_data_ptr = session_thread_it->second;
5017 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
5019 //accept_end_flag is off
5020 if (session_data_ptr->accept_end_flag == ACCEPT_END_FLAG_OFF)
5025 //accept_end_flag is on
5029 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5031 //data state is HTTP_START or HTTP_HEADER
5032 if (session_data_ptr->data_state == HTTP_START
5033 || session_data_ptr->data_state ==HTTP_HEADER)
5035 //set switch flag on
5036 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5038 /*-------- DEBUG LOG --------*/
5039 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5041 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5042 "handle_sorry_enable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5043 formatter % boost::this_thread::get_id();
5044 putLogDebug(600133, formatter.str(), __FILE__, __LINE__ );
5046 /*------DEBUG LOG END------*/
5049 status = SORRYSERVER_DISCONNECT;
5051 //data state is HTTP_BODY or UNKNOWN
5055 status = session_data_ptr->last_status;
5061 //data state is HTTP_START or HTTP_HEADER
5062 if (session_data_ptr->data_state == HTTP_START
5063 || session_data_ptr->data_state ==HTTP_HEADER)
5065 //set switch flag on
5066 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5068 /*-------- DEBUG LOG --------*/
5069 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5071 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5072 "handle_sorry_enable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5073 formatter % boost::this_thread::get_id();
5074 putLogDebug(600134, formatter.str(), __FILE__, __LINE__ );
5076 /*------DEBUG LOG END------*/
5078 //data state is HTTP_BODY or UNKNOWN
5082 session_data_ptr->end_flag = END_FLAG_ON;
5084 /*-------- DEBUG LOG --------*/
5085 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5087 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5088 "handle_sorry_enable(const boost::thread::id thread_id) : END_FLAG_ON. thread id : %d.");
5089 formatter % boost::this_thread::get_id();
5090 putLogDebug(600135, formatter.str(), __FILE__, __LINE__ );
5092 /*------DEBUG LOG END------*/
5096 status = REALSERVER_DISCONNECT;
5104 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5107 status = session_data_ptr->last_status;
5112 //data state is HTTP_START and data size is 0
5113 if (session_data_ptr->data_state == HTTP_START
5114 && session_data_ptr->data_length == 0)
5117 status = SORRYSERVER_RECV;
5119 //data state is HTTP_START and data size > 0
5120 else if (session_data_ptr->data_state == HTTP_START
5121 && session_data_ptr->data_length > 0)
5124 status = REALSERVER_DISCONNECT;
5126 //data state is HTTP_HEADER or HTTP_BODY
5127 else if (session_data_ptr->data_state == HTTP_HEADER
5128 || session_data_ptr->data_state == HTTP_BODY)
5130 //set switch flag on
5131 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5133 /*-------- DEBUG LOG --------*/
5134 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5136 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5137 "handle_sorry_enable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5138 formatter % boost::this_thread::get_id();
5139 putLogDebug(600136, formatter.str(), __FILE__, __LINE__ );
5141 /*------DEBUG LOG END------*/
5144 status = session_data_ptr->last_status;
5150 status = REALSERVER_DISCONNECT;
5156 session_data_ptr->sorry_flag = SORRY_FLAG_ON;
5158 /*-------- DEBUG LOG --------*/
5159 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5161 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5162 "handle_sorry_enable(const boost::thread::id thread_id) : SORRY_FLAG_ON. thread id : %d.");
5163 formatter % boost::this_thread::get_id();
5164 putLogDebug(600137, formatter.str(), __FILE__, __LINE__ );
5166 /*------DEBUG LOG END------*/
5169 session_data_ptr->last_status = status;
5174 /*-------- DEBUG LOG --------*/
5175 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5177 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5178 "handle_sorry_enable() : catch exception e = %d. thread id : %d.");
5179 formatter % e % boost::this_thread::get_id();
5180 putLogDebug(600138, formatter.str(), __FILE__, __LINE__ );
5182 /*------DEBUG LOG END------*/
5187 catch (std::exception& ex)
5189 std::cerr << "protocol_module_ip::handle_sorry_enable() : exception : error = " << ex.what() << "." << std::endl;
5190 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5191 "handle_sorry_enable() : exception : error = %s. thread id : %d.");
5192 formatter % ex.what() % boost::this_thread::get_id();
5193 putLogError(600089, formatter.str(), __FILE__, __LINE__ );
5200 std::cerr << "protocol_module_ip::handle_sorry_enable() : Unknown exception." << std::endl;
5201 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5202 "protocol_module_ip::handle_sorry_enable() : "
5203 "Unknown exception. thread id : %d.");
5204 formatter % boost::this_thread::get_id();
5205 putLogError(600090, formatter.str(), __FILE__, __LINE__ );
5211 /*-------- DEBUG LOG --------*/
5212 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5214 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5215 "handle_sorry_enable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
5216 formatter % status % boost::this_thread::get_id();
5217 putLogDebug(600139, formatter.str(), __FILE__, __LINE__ );
5219 /*------DEBUG LOG END------*/
5224 //! call from sorry mode disable. use upstream thread and downstream thread.
5225 //! @param[in] upstream and downstream thread id( check! one thread one event )
5226 //! @return session use EVENT mode
5227 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorry_disable(
5228 const boost::thread::id thread_id)
5230 /*-------- DEBUG LOG --------*/
5231 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5233 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5234 "handle_sorry_disable(const boost::thread::id thread_id) : thread_id = %d.");
5235 formatter % boost::this_thread::get_id();
5236 putLogDebug(600140, formatter.str(), __FILE__, __LINE__ );
5238 /*------DEBUG LOG END------*/
5240 EVENT_TAG status = FINALIZE;
5241 thread_data_ptr session_data_ptr;
5246 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
5248 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
5249 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5251 boost::format formatter("Invalid thread id. thread id : %d.");
5252 formatter % boost::this_thread::get_id();
5253 putLogError(600091, formatter.str(), __FILE__, __LINE__ );
5257 session_data_ptr = session_thread_it->second;
5261 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
5263 //accept_end_flag is off
5264 if (session_data_ptr->accept_end_flag == ACCEPT_END_FLAG_OFF)
5269 //accept_end_flag is on
5273 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5275 ///data state is HTTP_START or HTTP_HEADER
5276 if (session_data_ptr->data_state == HTTP_START
5277 || session_data_ptr->data_state ==HTTP_HEADER)
5279 //set switch flag on
5280 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5282 /*-------- DEBUG LOG --------*/
5283 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5285 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5286 "handle_sorry_disable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5287 formatter % boost::this_thread::get_id();
5288 putLogDebug(600141, formatter.str(), __FILE__, __LINE__ );
5290 /*------DEBUG LOG END------*/
5293 //data state is HTTP_BODY or UNKNOWN
5297 session_data_ptr->end_flag = END_FLAG_ON;
5299 /*-------- DEBUG LOG --------*/
5300 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5302 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5303 "handle_sorry_disable(const boost::thread::id thread_id) : END_FLAG_ON. thread id : %d.");
5304 formatter % boost::this_thread::get_id();
5305 putLogDebug(600142, formatter.str(), __FILE__, __LINE__ );
5307 /*------DEBUG LOG END------*/
5311 status = SORRYSERVER_DISCONNECT;
5317 //data state is HTTP_START or HTTP_HEADER
5318 if (session_data_ptr->data_state == HTTP_START
5319 || session_data_ptr->data_state ==HTTP_HEADER)
5321 //set switch flag on
5322 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5324 /*-------- DEBUG LOG --------*/
5325 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5327 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5328 "handle_sorry_disable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5329 formatter % boost::this_thread::get_id();
5330 putLogDebug(600143, formatter.str(), __FILE__, __LINE__ );
5332 /*------DEBUG LOG END------*/
5335 status = REALSERVER_DISCONNECT;
5337 //data state is HTTP_BODY or UNKNOWN
5341 status = session_data_ptr->last_status;
5350 if (session_data_ptr->sorry_flag == SORRY_FLAG_OFF)
5353 status = session_data_ptr->last_status;
5358 //data state is HTTP_START and data size is 0
5359 if (session_data_ptr->data_state == HTTP_START
5360 && session_data_ptr->data_length == 0)
5363 status = REALSERVER_RECV;
5365 //data state is HTTP_START and data size > 0
5366 else if (session_data_ptr->data_state == HTTP_START
5367 && session_data_ptr->data_length > 0)
5370 status = SORRYSERVER_DISCONNECT;
5372 //data state is HTTP_HEADER or HTTP_BODY
5373 else if (session_data_ptr->data_state == HTTP_HEADER
5374 || session_data_ptr->data_state == HTTP_BODY)
5376 //set switch flag on
5377 session_data_ptr->switch_flag = SWITCH_FLAG_ON;
5379 /*-------- DEBUG LOG --------*/
5380 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5382 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5383 "handle_sorry_disable(const boost::thread::id thread_id) : SWITCH_FLAG_ON. thread id : %d.");
5384 formatter % boost::this_thread::get_id();
5385 putLogDebug(600144, formatter.str(), __FILE__, __LINE__ );
5387 /*------DEBUG LOG END------*/
5390 status = session_data_ptr->last_status;
5396 status = SORRYSERVER_DISCONNECT;
5401 //set sorry flag off
5402 session_data_ptr->sorry_flag = SORRY_FLAG_OFF;
5404 /*-------- DEBUG LOG --------*/
5405 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5407 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5408 "handle_sorry_disable(const boost::thread::id thread_id) : SORRY_FLAG_OFF. thread id : %d.");
5409 formatter % boost::this_thread::get_id();
5410 putLogDebug(600145, formatter.str(), __FILE__, __LINE__ );
5412 /*------DEBUG LOG END------*/
5415 session_data_ptr->last_status = status;
5419 /*-------- DEBUG LOG --------*/
5420 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5422 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5423 "handle_sorry_disable() : catch exception e = %d. thread id : %d.");
5424 formatter % e % boost::this_thread::get_id();
5425 putLogDebug(600146, formatter.str(), __FILE__, __LINE__ );
5427 /*------DEBUG LOG END------*/
5432 catch (std::exception& ex)
5434 std::cerr << "protocol_module_ip::handle_sorry_disable() : exception : error = " << ex.what() << "." << std::endl;
5435 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5436 "handle_sorry_disable() : exception : error = %s. thread id : %d.");
5437 formatter % ex.what() % boost::this_thread::get_id();
5438 putLogError(600092, formatter.str(), __FILE__, __LINE__ );
5445 std::cerr << "protocol_module_ip::handle_sorry_disable() : Unknown exception." << std::endl;
5446 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5447 "protocol_module_ip::handle_sorry_disable() : "
5448 "Unknown exception. thread id : %d.");
5449 formatter % boost::this_thread::get_id();
5450 putLogError(600093, formatter.str(), __FILE__, __LINE__ );
5456 /*-------- DEBUG LOG --------*/
5457 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5459 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5460 "handle_sorry_disable(const boost::thread::id thread_id) : return_value = %d. thread id : %d.");
5461 formatter % status % boost::this_thread::get_id();
5462 putLogDebug(600147, formatter.str(), __FILE__, __LINE__ );
5464 /*------DEBUG LOG END------*/
5469 //! call from realserver disconnect. use upstream thread and downstream thread
5470 //! @param[in] upstream and downstream thread id( check! one thread one event )
5471 //! @param[in] disconnected realserver endpoint.
5472 //! @return session use EVENT mode
5473 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_disconnect(
5474 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint)
5476 /*-------- DEBUG LOG --------*/
5477 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5479 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5480 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & rs_endpoint) : "
5481 "thread_id = %d, rs_endpoint = [%s]:%d.");
5482 formatter % thread_id % rs_endpoint.address().to_string() % rs_endpoint.port();
5483 putLogDebug(600148, formatter.str(), __FILE__, __LINE__ );
5485 /*------DEBUG LOG END------*/
5487 EVENT_TAG status = FINALIZE;
5488 thread_data_ptr session_data_ptr;
5493 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
5495 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
5496 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5498 boost::format formatter("Invalid thread id. thread id : %d.");
5499 formatter % boost::this_thread::get_id();
5500 putLogError(600094, formatter.str(), __FILE__, __LINE__ );
5504 session_data_ptr = session_thread_it->second;
5509 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
5512 if (session_data_ptr->end_flag == END_FLAG_ON)
5515 status = CLIENT_RECV;
5521 if (session_data_ptr->switch_flag == SWITCH_FLAG_ON)
5524 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5527 status = SORRYSERVER_SELECT;
5533 status = CLIENT_RECV;
5536 //set switch flag off
5537 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
5539 /*-------- DEBUG LOG --------*/
5540 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5542 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5543 "handle_realserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint &" "rs_endpoint) : SWITCH_FLAG_OFF. thread id : %d.");
5544 formatter % boost::this_thread::get_id();
5545 putLogDebug(600149, formatter.str(), __FILE__, __LINE__ );
5547 /*------DEBUG LOG END------*/
5549 //switch flag is off
5553 status = CLIENT_RECV;
5561 status = CLIENT_DISCONNECT;
5565 session_data_ptr->last_status = status;
5569 /*-------- DEBUG LOG --------*/
5570 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5572 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5573 "handle_realserver_disconnect() : catch exception e = %d. thread id : %d.");
5574 formatter % e % boost::this_thread::get_id();
5575 putLogDebug(600150, formatter.str(), __FILE__, __LINE__ );
5577 /*------DEBUG LOG END------*/
5582 catch (std::exception& ex)
5584 std::cerr << "protocol_module_ip::handle_realserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
5585 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5586 "handle_realserver_disconnect() : exception : error = %s. thread id : %d.");
5587 formatter % ex.what() % boost::this_thread::get_id();
5588 putLogError(600095, formatter.str(), __FILE__, __LINE__ );
5595 std::cerr << "protocol_module_ip::handle_realserver_disconnect() : Unknown exception." << std::endl;
5596 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5597 "protocol_module_ip::handle_realserver_disconnect() : "
5598 "Unknown exception. thread id : %d.");
5599 formatter % boost::this_thread::get_id();
5600 putLogError(600096, formatter.str(), __FILE__, __LINE__ );
5606 /*-------- DEBUG LOG --------*/
5607 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5609 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5610 "handle_realserver_disconnect(const boost::thread::id thread_id, "
5611 "const boost::asio::ip::tcp::endpoint & rs_endpoint) : return_value = %d. thread id : %d.");
5612 formatter % status % boost::this_thread::get_id();
5613 putLogDebug(600151, formatter.str(), __FILE__, __LINE__ );
5615 /*------DEBUG LOG END------*/
5620 //! call from sorry server disconnect. use upstraem thread and downstream thread
5621 //! @param[in] upstream and downstream thread id( check! one thread one event )
5622 //! @param[in] disconnect sorryserver endpoint
5623 //! @return session use EVENT mode
5624 //! @return session use EVENT mode
5625 protocol_module_base::EVENT_TAG protocol_module_ip::handle_sorryserver_disconnect(
5626 const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint)
5629 /*-------- DEBUG LOG --------*/
5630 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5632 boost::format formatter("in_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5633 "handle_sorryserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint & sorry_endpoint) : "
5634 "thread_id = %d, sorry_endpoint = [%s]:%d.");
5635 formatter % thread_id % sorry_endpoint.address().to_string() % sorry_endpoint.port();
5636 putLogDebug(600152, formatter.str(), __FILE__, __LINE__ );
5638 /*------DEBUG LOG END------*/
5640 EVENT_TAG status = FINALIZE;
5641 thread_data_ptr session_data_ptr;
5646 boost::mutex::scoped_lock sclock(session_thread_data_map_mutex);
5648 session_thread_data_map_it session_thread_it = session_thread_data_map.find(thread_id);
5649 if (unlikely(session_thread_it == session_thread_data_map.end() || session_thread_it->second == NULL))
5651 boost::format formatter("Invalid thread id. thread id : %d.");
5652 formatter % boost::this_thread::get_id();
5653 putLogError(600097, formatter.str(), __FILE__, __LINE__ );
5657 session_data_ptr = session_thread_it->second;
5661 if (session_data_ptr->thread_division == THREAD_DIVISION_UP_STREAM)
5664 if (session_data_ptr->end_flag == END_FLAG_ON)
5667 status = CLIENT_RECV;
5673 if (session_data_ptr->switch_flag == SWITCH_FLAG_ON)
5676 if (session_data_ptr->sorry_flag == SORRY_FLAG_ON)
5679 status = SORRYSERVER_SELECT;
5685 status = CLIENT_RECV;
5688 //set switch flag off
5689 session_data_ptr->switch_flag = SWITCH_FLAG_OFF;
5691 /*-------- DEBUG LOG --------*/
5692 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5694 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5695 "handle_sorryserver_disconnect(const boost::thread::id thread_id, const boost::asio::ip::tcp::endpoint &" "sorry_endpoint) : SWITCH_FLAG_OFF. thread id : %d.");
5696 formatter % boost::this_thread::get_id();
5697 putLogDebug(600153, formatter.str(), __FILE__, __LINE__ );
5699 /*------DEBUG LOG END------*/
5702 //switch flag is off
5706 status = CLIENT_RECV;
5714 status = CLIENT_DISCONNECT;
5718 session_data_ptr->last_status = status;
5723 /*-------- DEBUG LOG --------*/
5724 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5726 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5727 "handle_sorryserver_disconnect() : catch exception e = %d. thread id : %d.");
5728 formatter % e % boost::this_thread::get_id();
5729 putLogDebug(600154, formatter.str(), __FILE__, __LINE__ );
5731 /*------DEBUG LOG END------*/
5737 catch (std::exception& ex)
5739 std::cerr << "protocol_module_ip::handle_sorryserver_disconnect() : exception : error = " << ex.what() << "." << std::endl;
5740 boost::format formatter("function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5741 "handle_sorryserver_disconnect() : exception : error = %s. thread id : %d.");
5742 formatter % ex.what() % boost::this_thread::get_id();
5743 putLogError(600098, formatter.str(), __FILE__, __LINE__ );
5750 std::cerr << "protocol_module_ip::handle_sorryserver_disconnect() : Unknown exception." << std::endl;
5751 boost::format formatter("function : protocol_module_base::EVENT_TAG "
5752 "protocol_module_ip::handle_sorryserver_disconnect() : "
5753 "Unknown exception. thread id : %d.");
5754 formatter % boost::this_thread::get_id();
5755 putLogError(600099, formatter.str(), __FILE__, __LINE__ );
5761 /*-------- DEBUG LOG --------*/
5762 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5764 boost::format formatter("out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5765 "handle_sorryserver_disconnect(const boost::thread::id thread_id, "
5766 "const boost::asio::ip::tcp::endpoint & sorry_endpoint) : return_value = %d. thread id : %d.");
5767 formatter % status % boost::this_thread::get_id();
5768 putLogDebug(600155, formatter.str(), __FILE__, __LINE__ );
5770 /*------DEBUG LOG END------*/
5775 //! call from realserver disconnect. use upstream thread and downstream thread.
5776 //! @param[in] upstream and downstream thread id( check! one thread one event )
5777 //! @param[in] disconnect realserver endpoint
5778 //! @return session use EVENT mode.
5779 protocol_module_base::EVENT_TAG protocol_module_ip::handle_realserver_close(
5780 const boost::thread::id thread_id, const boost::asio::ip::udp::endpoint & rs_endpoint)
5782 /*-------- DEBUG LOG --------*/
5783 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5785 boost::format formatter("in/out_function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5786 "handle_realserver_close(const boost::thread::id thread_id, "
5787 "boost::asio::ip::udp::endpoint& rs_endpoint) : "
5788 "return_value = %d. thread id : %d.");
5789 formatter % STOP % boost::this_thread::get_id();
5790 putLogDebug(600156, formatter.str(), __FILE__, __LINE__ );
5792 /*------DEBUG LOG END------*/
5798 bool protocol_module_ip::get_data_from_recvbuffer(
5799 thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, const size_t recvlen)
5801 /*-------- DEBUG LOG --------*/
5802 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5804 boost::format formatter("in_function : bool protocol_module_ip::get_data_from_recvbuffer("
5805 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5806 "const size_t& recvlen) : thread_id = %d.");
5807 formatter % boost::this_thread::get_id();
5808 putLogDebug(600157, formatter.str(), __FILE__, __LINE__);
5810 /*------DEBUG LOG END------*/
5812 char* tmpbuffer = NULL;
5814 //pointer volidate check
5815 if (unlikely(data_ptr == NULL || data_ptr->data_buffer == NULL))
5817 boost::format formatter("Invalid pointer. thread id : %d.");
5818 formatter % boost::this_thread::get_id();
5819 putLogError(600100, formatter.str(), __FILE__, __LINE__ );
5821 /*-------- DEBUG LOG --------*/
5822 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5824 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5825 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5826 "const size_t& recvlen) : return_value = false. thread id : %d.");
5827 formatter % boost::this_thread::get_id();
5828 putLogDebug(600158, formatter.str(), __FILE__, __LINE__ );
5830 /*------DEBUG LOG END------*/
5836 //the new data can append to buffer directly
5837 if (data_ptr->data_buffer_size - data_ptr->data_length - data_ptr->data_offset >= recvlen)
5840 /*-------- DEBUG LOG --------*/
5841 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5843 std::string datadump;
5844 dump_memory(recvbuffer.data(), recvlen, datadump);
5845 boost::format formatter(
5846 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5847 "get_data_from_recvbuffer() : before memcpy (data dump) : "
5848 "data begin = 0, data_size = %d, data = %s");
5849 formatter % recvlen % datadump;
5850 putLogDebug(600159, formatter.str(), __FILE__, __LINE__ );
5852 /*------DEBUG LOG END------*/
5854 memcpy(data_ptr->data_buffer + data_ptr->data_offset + data_ptr->data_length, recvbuffer.data(), recvlen);
5856 /*-------- DEBUG LOG --------*/
5857 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5859 std::string datadump;
5860 dump_memory(data_ptr->data_buffer + data_ptr->data_offset + data_ptr->data_length, recvlen, datadump);
5861 boost::format formatter(
5862 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5863 "get_data_from_recvbuffer() : after memcpy (data dump) : "
5864 "data begin = 0, data_size = %d, data = %s");
5865 formatter % recvlen % datadump;
5866 putLogDebug(600160, formatter.str(), __FILE__, __LINE__ );
5868 /*------DEBUG LOG END------*/
5870 data_ptr->data_length += recvlen;
5872 /*-------- DEBUG LOG --------*/
5873 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5875 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5876 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5877 "const size_t& recvlen) : return_value = true. thread id : %d.");
5878 formatter % boost::this_thread::get_id();
5879 putLogDebug(600161, formatter.str(), __FILE__, __LINE__ );
5881 /*------DEBUG LOG END------*/
5886 //the new data can append to buffer through moving orignal data
5887 if (data_ptr->data_buffer_size - data_ptr->data_length >= recvlen)
5889 memmove(data_ptr->data_buffer, data_ptr->data_buffer + data_ptr->data_offset, data_ptr->data_length);
5890 /*-------- DEBUG LOG --------*/
5891 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5893 std::string datadump;
5894 dump_memory(recvbuffer.data(), recvlen, datadump);
5895 boost::format formatter(
5896 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5897 "get_data_from_recvbuffer() : before memcpy (data dump) : "
5898 "data begin = 0, data_size = %d, data = %s");
5899 formatter % recvlen % datadump;
5900 putLogDebug(600162, formatter.str(), __FILE__, __LINE__ );
5902 /*------DEBUG LOG END------*/
5904 memcpy(data_ptr->data_buffer + data_ptr->data_length, recvbuffer.data(), recvlen);
5906 /*-------- DEBUG LOG --------*/
5907 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5909 std::string datadump;
5910 dump_memory(data_ptr->data_buffer + data_ptr->data_length, recvlen, datadump);
5911 boost::format formatter(
5912 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
5913 "get_data_from_recvbuffer() : after memcpy (data dump) : "
5914 "data begin = 0, data_size = %d, data = %s");
5915 formatter % recvlen % datadump;
5916 putLogDebug(600163, formatter.str(), __FILE__, __LINE__ );
5918 /*------DEBUG LOG END------*/
5920 data_ptr->data_offset = 0;
5921 data_ptr->data_length += recvlen;
5923 /*-------- DEBUG LOG --------*/
5924 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5926 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5927 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5928 "const size_t& recvlen) : return_value = true. thread id : %d.");
5929 formatter % boost::this_thread::get_id();
5930 putLogDebug(600164, formatter.str(), __FILE__, __LINE__ );
5932 /*------DEBUG LOG END------*/
5938 //not allowed to realloc new buffer who's size is larger than the max size
5939 if (data_ptr->data_buffer_size >= MAX_IP_MODULE_BUFFER_SIZE
5940 || data_ptr->data_buffer_size + recvlen >= MAX_IP_MODULE_BUFFER_SIZE)
5942 boost::format formatter("Buffer size is bigger than Max size. thread id : %d.");
5943 formatter % boost::this_thread::get_id();
5944 putLogError(600101, formatter.str(), __FILE__, __LINE__ );
5946 /*-------- DEBUG LOG --------*/
5947 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5949 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5950 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5951 "const size_t& recvlen) : return_value = false. thread id : %d.");
5952 formatter % boost::this_thread::get_id();
5953 putLogDebug(600165, formatter.str(), __FILE__, __LINE__ );
5955 /*------DEBUG LOG END------*/
5963 /*-------- DEBUG LOG --------*/
5964 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5966 boost::format formatter("new : address = &(%d), size = %lu.");
5967 formatter % static_cast<void*>(tmpbuffer) % MAX_IP_MODULE_BUFFER_SIZE;
5968 putLogDebug(600166, formatter.str(), __FILE__, __LINE__);
5970 /*------DEBUG LOG END------*/
5972 //alloc a new buffer who's size is max
5973 tmpbuffer = new char[MAX_IP_MODULE_BUFFER_SIZE];
5975 catch (const std::bad_alloc&) //memory alloc fail
5977 std::cerr << "protocol_module_ip::get_data_from_recvbuffer() : exception : Could not allocate memory." << std::endl;
5978 boost::format formatter("Could not allocate memory. thread id : %d.");
5979 formatter % boost::this_thread::get_id();
5980 putLogError(600102, formatter.str(), __FILE__, __LINE__);
5982 /*-------- DEBUG LOG --------*/
5983 if (unlikely(LOG_LV_DEBUG == getloglevel()))
5985 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
5986 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
5987 "const size_t& recvlen) : return_value = false. thread id : %d.");
5988 formatter % boost::this_thread::get_id();
5989 putLogDebug(600167, formatter.str(), __FILE__, __LINE__ );
5991 /*------DEBUG LOG END------*/
5996 memset(tmpbuffer, 0, MAX_IP_MODULE_BUFFER_SIZE);
5998 /*-------- DEBUG LOG --------*/
5999 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6001 std::string datadump;
6002 dump_memory(data_ptr->data_buffer+data_ptr->data_offset, data_ptr->data_length, datadump);
6003 boost::format formatter(
6004 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6005 "get_data_from_recvbuffer() : before memcpy (data dump) : "
6006 "data begin = 0, data_size = %d, data = %s");
6007 formatter % data_ptr->data_length % datadump;
6008 putLogDebug(600168, formatter.str(), __FILE__, __LINE__ );
6010 /*------DEBUG LOG END------*/
6012 //copy old data to new buffer
6013 memcpy(tmpbuffer, data_ptr->data_buffer+data_ptr->data_offset, data_ptr->data_length);
6015 /*-------- DEBUG LOG --------*/
6016 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6018 std::string datadump;
6019 dump_memory(tmpbuffer, data_ptr->data_length, datadump);
6020 boost::format formatter(
6021 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6022 "get_data_from_recvbuffer() : after memcpy (data dump) : "
6023 "data begin = 0, data_size = %d, data = %s");
6024 formatter % data_ptr->data_length % datadump;
6025 putLogDebug(600169, formatter.str(), __FILE__, __LINE__ );
6027 /*------DEBUG LOG END------*/
6029 /*-------- DEBUG LOG --------*/
6030 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6032 boost::format formatter("delete : address = &(%d).");
6033 formatter % static_cast<void*>(data_ptr->data_buffer);
6034 putLogDebug(600170, formatter.str(), __FILE__, __LINE__);
6036 /*------DEBUG LOG END------*/
6038 //release old memory
6039 delete [] data_ptr->data_buffer;
6040 data_ptr->data_buffer = tmpbuffer;
6041 data_ptr->data_offset = 0;
6043 /*-------- DEBUG LOG --------*/
6044 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6046 std::string datadump;
6047 dump_memory(recvbuffer.data(), recvlen, datadump);
6048 boost::format formatter(
6049 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6050 "get_data_from_recvbuffer() : before memcpy (data dump) : "
6051 "data begin = 0, data_size = %d, data = %s");
6052 formatter % recvlen % datadump;
6053 putLogDebug(600171, formatter.str(), __FILE__, __LINE__ );
6055 /*------DEBUG LOG END------*/
6058 memcpy(data_ptr->data_buffer+data_ptr->data_length, recvbuffer.data(), recvlen);
6060 /*-------- DEBUG LOG --------*/
6061 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6063 std::string datadump;
6064 dump_memory(data_ptr->data_buffer+data_ptr->data_length, recvlen, datadump);
6065 boost::format formatter(
6066 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6067 "get_data_from_recvbuffer() : after memcpy (data dump) : "
6068 "data begin = 0, data_size = %d, data = %s");
6069 formatter % recvlen % datadump;
6070 putLogDebug(600172, formatter.str(), __FILE__, __LINE__ );
6072 /*------DEBUG LOG END------*/
6074 data_ptr->data_length += recvlen;
6075 data_ptr->data_buffer_size = MAX_IP_MODULE_BUFFER_SIZE ;
6077 /*-------- DEBUG LOG --------*/
6078 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6080 boost::format formatter("out_function : bool protocol_module_ip::get_data_from_recvbuffer("
6081 "thread_data_ptr data_ptr, const boost::array<char,MAX_BUFFER_SIZE>& recvbuffer, "
6082 "const size_t& recvlen) : return_value = true. thread id : %d.");
6083 formatter % boost::this_thread::get_id();
6084 putLogDebug(600173, formatter.str(), __FILE__, __LINE__ );
6086 /*------DEBUG LOG END------*/
6095 bool protocol_module_ip::put_data_into_sendbuffer(
6096 thread_data_ptr data_ptr, boost::array<char, MAX_BUFFER_SIZE>& sendbuffer, size_t& datalen)
6098 /*-------- DEBUG LOG --------*/
6099 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6101 boost::format formatter("in_function : bool protocol_module_ip::put_data_to_sendbuffer("
6102 "thread_data_ptr data_ptr, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6103 "size_t& datalen) : thread_id = %d.");
6104 formatter % boost::this_thread::get_id();
6105 putLogDebug(600174, formatter.str(), __FILE__, __LINE__);
6107 /*------DEBUG LOG END------*/
6109 size_t sendbuffer_rest_size = 0;
6110 size_t new_offset = 0;
6112 if (unlikely(data_ptr == NULL || data_ptr->data_buffer == NULL || data_ptr->buffer_sequence.empty()))
6114 boost::format formatter("Invalid pointer. thread id : %d.");
6115 formatter % boost::this_thread::get_id();
6116 putLogError(600103, formatter.str(), __FILE__, __LINE__ );
6118 /*-------- DEBUG LOG --------*/
6119 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6121 boost::format formatter("out_function : bool protocol_module_ip::put_data_to_sendbuffer("
6122 "thread_data_ptr data_ptr, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6123 "size_t& datalen) : return_value = false. thread_id = %d.");
6124 formatter % boost::this_thread::get_id();
6125 putLogDebug(600175, formatter.str(), __FILE__, __LINE__);
6127 /*------DEBUG LOG END------*/
6132 sendbuffer_rest_size = sendbuffer.size();
6135 //buffer_sequence loop
6136 //copy data to send buffer until send buffer is full
6137 while (data_ptr->buffer_sequence.size() > 0)
6139 std::pair<char*, size_t> buffer_element = data_ptr->buffer_sequence.front();
6140 //sendbuffer rest size id bigger than copy possible size
6141 if (buffer_element.second <= sendbuffer_rest_size)
6143 /*-------- DEBUG LOG --------*/
6144 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6146 std::string datadump;
6147 dump_memory(buffer_element.first, buffer_element.second, datadump);
6148 boost::format formatter(
6149 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6150 "put_data_to_sendbuffer() : before memcpy (data dump) : "
6151 "data begin = 0, data_size = %d, data = %s");
6152 formatter % buffer_element.second % datadump;
6153 putLogDebug(600176, formatter.str(), __FILE__, __LINE__ );
6155 /*------DEBUG LOG END------*/
6157 //copy data to send buffer
6158 memcpy(sendbuffer.c_array() + datalen, buffer_element.first, buffer_element.second);
6160 /*-------- DEBUG LOG --------*/
6161 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6163 std::string datadump;
6164 dump_memory(sendbuffer.c_array() + datalen, buffer_element.second, datadump);
6165 boost::format formatter(
6166 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6167 "put_data_to_sendbuffer() : after memcpy (data dump) : "
6168 "data begin = 0, data_size = %d, data = %s");
6169 formatter % buffer_element.second % datadump;
6170 putLogDebug(600177, formatter.str(), __FILE__, __LINE__ );
6172 /*------DEBUG LOG END------*/
6174 datalen += buffer_element.second;
6175 sendbuffer_rest_size -= buffer_element.second;
6177 //it is the last item of the sequence
6178 if (data_ptr->buffer_sequence.size() == 1)
6181 new_offset = buffer_element.first + buffer_element.second - data_ptr->data_buffer;
6182 data_ptr->current_message_rest_size -= (new_offset - data_ptr->data_offset);
6183 data_ptr->data_length -= (new_offset - data_ptr->data_offset);
6184 data_ptr->data_offset = new_offset;
6189 data_ptr->buffer_sequence.pop_front();
6191 //sendbuffer rest size is too small
6194 /*-------- DEBUG LOG --------*/
6195 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6197 std::string datadump;
6198 dump_memory(buffer_element.first, sendbuffer_rest_size, datadump);
6199 boost::format formatter(
6200 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6201 "put_data_to_sendbuffer() : before memcpy (data dump) : "
6202 "data begin = 0, data_size = %d, data = %s");
6203 formatter % sendbuffer_rest_size % datadump;
6204 putLogDebug(600178, formatter.str(), __FILE__, __LINE__ );
6206 /*------DEBUG LOG END------*/
6208 //copy data to send buffer
6209 memcpy(sendbuffer.c_array() + datalen, buffer_element.first, sendbuffer_rest_size);
6211 /*-------- DEBUG LOG --------*/
6212 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6214 std::string datadump;
6215 dump_memory(sendbuffer.c_array() + datalen, sendbuffer_rest_size, datadump);
6216 boost::format formatter(
6217 "function : protocol_module_base::EVENT_TAG protocol_module_ip::"
6218 "put_data_to_sendbuffer() : after memcpy (data dump) : "
6219 "data begin = 0, data_size = %d, data = %s");
6220 formatter % sendbuffer_rest_size % datadump;
6221 putLogDebug(600179, formatter.str(), __FILE__, __LINE__ );
6223 /*------DEBUG LOG END------*/
6225 datalen += sendbuffer_rest_size;
6228 buffer_element.first += sendbuffer_rest_size;
6229 buffer_element.second -= sendbuffer_rest_size;
6230 sendbuffer_rest_size = 0;
6235 /*-------- DEBUG LOG --------*/
6236 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6238 boost::format formatter("out_function : bool protocol_module_ip::put_data_to_sendbuffer("
6239 "thread_data_ptr data_ptr, boost::array<char,MAX_BUFFER_SIZE>& sendbuffer, "
6240 "size_t& datalen) : return_value = true. thread_id = %d.");
6241 formatter % boost::this_thread::get_id();
6242 putLogDebug(600180, formatter.str(), __FILE__, __LINE__);
6244 /*------DEBUG LOG END------*/
6252 //! call from put_data_to_buffer_with_x_forwarded_for(). get x_forwarded_for header's offset and length
6253 //! if the buffer isn't include x_forwarded_for header, create a new one
6254 //! @param[in] buffer
6255 //! @param[in] buffer_len
6256 //! @param[out] x_forwarded_for_insert_pos
6257 //! @param[out] x_forwarded_for_context
6258 //! @return true:create a new x_forwarded_for header
6259 //! false: edit old one
6260 bool protocol_module_ip::create_x_forwarded_for(const std::string& client_endpoint,
6262 const size_t buffer_len,
6263 size_t& x_forwarded_for_insert_pos,
6264 std::string& x_forwarded_for_context)
6266 /*-------- DEBUG LOG --------*/
6267 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6269 boost::format formatter("in_function : bool protocol_module_ip::create_x_forwarded_for("
6270 "const std::string& client_endpoint, const char* buffer, const size_t buffer_len, "
6271 "size_t& x_forwarded_for_insert_pos, std::string& x_forwarded_for_context) : thread_id = %d.");
6272 formatter % boost::this_thread::get_id();
6273 putLogDebug(600181, formatter.str(), __FILE__, __LINE__);
6275 /*------DEBUG LOG END------*/
6277 bool find_ret = false;
6278 size_t x_forwarded_for_offset = 0;
6279 size_t x_forwarded_for_len = 0;
6280 size_t http_header_all_offset = 0;
6281 size_t http_header_all_len = 0;
6282 const char* X_FORWARDED_FOR = "X-Forwarded-For";
6284 //search "X-Forwared-For" header
6285 find_ret = http_utility::find_http_header_x_forwarded_for(buffer, buffer_len,
6286 x_forwarded_for_offset, x_forwarded_for_len);
6288 /*-------- DEBUG LOG --------*/
6289 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6291 boost::format formatter("function : bool protocol_module_ip::create_x_forwarded_for() : "
6292 "call find_http_header_x_forwarded_for : "
6293 "return_value = %d. thread id : %d.");
6294 formatter % static_cast<int>(find_ret) % boost::this_thread::get_id();
6295 putLogDebug(600182, formatter.str(), __FILE__, __LINE__ );
6297 /*------DEBUG LOG END------*/
6299 //search "X-Forwared-For" result is OK
6302 //create "X-Forwared-For" string
6303 x_forwarded_for_insert_pos = x_forwarded_for_offset + x_forwarded_for_len;
6304 x_forwarded_for_context = ", ";
6305 x_forwarded_for_context += client_endpoint;
6307 /*-------- DEBUG LOG --------*/
6308 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6310 boost::format formatter("out_function : bool protocol_module_ip::create_x_forwarded_for("
6311 "const std::string& client_endpoint, const char* buffer, const size_t buffer_len, "
6312 "size_t& x_forwarded_for_insert_pos, std::string& x_forwarded_for_context) : return_value = false. thread_id = %d.");
6313 formatter % boost::this_thread::get_id();
6314 putLogDebug(600183, formatter.str(), __FILE__, __LINE__);
6316 /*------DEBUG LOG END------*/
6322 //because state is HTTP_HEADER, find_http_header_all must be return true
6323 http_utility::find_http_header_all(buffer, buffer_len, http_header_all_offset, http_header_all_len);
6325 /*-------- DEBUG LOG --------*/
6326 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6328 boost::format formatter("function : bool protocol_module_ip::create_x_forwarded_for() : "
6329 "call find_http_header_all : "
6330 "return_value = true. thread id : %d.");
6331 formatter % boost::this_thread::get_id();
6332 putLogDebug(600184, formatter.str(), __FILE__, __LINE__ );
6334 /*------DEBUG LOG END------*/
6336 //create "X-Forwared-For" string
6337 x_forwarded_for_insert_pos = http_header_all_offset;
6338 x_forwarded_for_context = X_FORWARDED_FOR;
6339 x_forwarded_for_context += ": ";
6340 x_forwarded_for_context += client_endpoint;
6341 x_forwarded_for_context += "\r\n";
6343 /*-------- DEBUG LOG --------*/
6344 if (unlikely(LOG_LV_DEBUG == getloglevel()))
6346 boost::format formatter("out_function : bool protocol_module_ip::create_x_forwarded_for("
6347 "const std::string& client_endpoint, const char* buffer, const size_t buffer_len, "
6348 "size_t& x_forwarded_for_insert_pos, std::string& x_forwarded_for_context) : return_value = true. thread_id = %d.");
6349 formatter % boost::this_thread::get_id();
6350 putLogDebug(600185, formatter.str(), __FILE__, __LINE__);
6352 /*------DEBUG LOG END------*/
6361 extern "C" l7vs::protocol_module_base*
6364 return dynamic_cast<l7vs::protocol_module_base*>(new l7vs::protocol_module_ip());
6368 destroy_module( l7vs::protocol_module_base* in )