SSL Proxy
Revisão | 12db482f92cc52c6e4e3f6527caf8c2c08271cd0 (tree) |
---|---|
Hora | 2009-10-02 17:11:52 |
Autor | Kohei TANUMA <tanuma@user...> |
Commiter | TATEISHI Katsuyuki |
Check packet edit flag before memcpy.
@@ -67,7 +67,7 @@ protected: | ||
67 | 67 | std::string _body; |
68 | 68 | std::string incomplete; |
69 | 69 | std::string raw_message; |
70 | - bool modified; | |
70 | + bool _modified; | |
71 | 71 | std::string convert_upper_camel_case(std::string) const; |
72 | 72 | |
73 | 73 | public: |
@@ -79,6 +79,7 @@ public: | ||
79 | 79 | void header( std::string, std::string ); |
80 | 80 | std::string body() const; |
81 | 81 | std::string body( std::string ); |
82 | + bool modified() const; | |
82 | 83 | |
83 | 84 | std::string as_string(); |
84 | 85 | void parse( std::string ); |
@@ -29,7 +29,7 @@ | ||
29 | 29 | */ |
30 | 30 | http_message::http_message() |
31 | 31 | : |
32 | - modified(false) | |
32 | + _modified(false) | |
33 | 33 | { |
34 | 34 | /*-------- DEBUG LOG --------*/ |
35 | 35 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -47,7 +47,7 @@ http_message::http_message() | ||
47 | 47 | */ |
48 | 48 | http_message::http_message(std::string header) |
49 | 49 | : |
50 | - modified(false) | |
50 | + _modified(false) | |
51 | 51 | { |
52 | 52 | /*-------- DEBUG LOG --------*/ |
53 | 53 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -128,18 +128,18 @@ void http_message::header(std::string field_name, std::string field_value) | ||
128 | 128 | if (field_value != "") { |
129 | 129 | if ( _header.get<field_map>().replace(it, field(name, field_value)) ) { |
130 | 130 | changed = true; |
131 | - this->modified = true; | |
131 | + this->_modified = true; | |
132 | 132 | } |
133 | 133 | } |
134 | 134 | else { |
135 | 135 | _header.get<field_map>().erase(it); |
136 | 136 | changed = true; |
137 | - this->modified = true; | |
137 | + this->_modified = true; | |
138 | 138 | } |
139 | 139 | } |
140 | 140 | if (!changed && field_value != "") { |
141 | 141 | _header.get<field_map>().insert( field(name, field_value) ); |
142 | - this->modified = true; | |
142 | + this->_modified = true; | |
143 | 143 | } |
144 | 144 | } |
145 | 145 | catch (...) { |
@@ -194,7 +194,7 @@ std::string http_message::body(std::string _body) | ||
194 | 194 | |
195 | 195 | std::string ret = this->_body; |
196 | 196 | this->_body = _body; |
197 | - this->modified = true; | |
197 | + this->_modified = true; | |
198 | 198 | |
199 | 199 | /*-------- DEBUG LOG --------*/ |
200 | 200 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -208,6 +208,26 @@ std::string http_message::body(std::string _body) | ||
208 | 208 | } |
209 | 209 | |
210 | 210 | /*! |
211 | + * Get modified flag function. | |
212 | + * | |
213 | + * @return modified flag | |
214 | + */ | |
215 | +bool http_message::modified() const | |
216 | +{ | |
217 | + /*-------- DEBUG LOG --------*/ | |
218 | + if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { | |
219 | + LOGGER_PUT_LOG_DEBUG(LOG_CAT_PACKET_EDIT_HTTP, 66, | |
220 | + "in_function : bool http_message::modified(void)"); | |
221 | + LOGGER_PUT_LOG_DEBUG(LOG_CAT_PACKET_EDIT_HTTP, 67, | |
222 | + "out_function : bool http_message::modified(void) : " | |
223 | + "return(%s)", this->_modified ? "true" : "false"); | |
224 | + } | |
225 | + /*------ DEBUG LOG END ------*/ | |
226 | + | |
227 | + return this->_modified; | |
228 | +} | |
229 | + | |
230 | +/*! | |
211 | 231 | * Get full HTTP message function. |
212 | 232 | * |
213 | 233 | * @return HTTP message |
@@ -221,7 +241,7 @@ std::string http_message::as_string() | ||
221 | 241 | } |
222 | 242 | /*------ DEBUG LOG END ------*/ |
223 | 243 | |
224 | - if (this->modified) | |
244 | + if (this->_modified) | |
225 | 245 | this->rebuild(); |
226 | 246 | |
227 | 247 | /*-------- DEBUG LOG --------*/ |
@@ -107,7 +107,7 @@ std::string http_request::method(std::string _method) | ||
107 | 107 | |
108 | 108 | std::string ret = this->_method; |
109 | 109 | this->_method = _method; |
110 | - this->modified = true; | |
110 | + this->_modified = true; | |
111 | 111 | |
112 | 112 | /*-------- DEBUG LOG --------*/ |
113 | 113 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -159,7 +159,7 @@ std::string http_request::request_uri(std::string _request_uri) | ||
159 | 159 | |
160 | 160 | std::string ret = this->_request_uri; |
161 | 161 | this->_request_uri = _request_uri; |
162 | - this->modified = true; | |
162 | + this->_modified = true; | |
163 | 163 | |
164 | 164 | /*-------- DEBUG LOG --------*/ |
165 | 165 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -211,7 +211,7 @@ std::string http_request::http_version(std::string _http_version) | ||
211 | 211 | |
212 | 212 | std::string ret = this->_http_version; |
213 | 213 | this->_http_version = _http_version; |
214 | - this->modified = true; | |
214 | + this->_modified = true; | |
215 | 215 | |
216 | 216 | /*-------- DEBUG LOG --------*/ |
217 | 217 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -265,7 +265,7 @@ std::string http_request::as_string() | ||
265 | 265 | } |
266 | 266 | /*------ DEBUG LOG END ------*/ |
267 | 267 | |
268 | - if (this->modified) | |
268 | + if (this->_modified) | |
269 | 269 | this->rebuild(); |
270 | 270 | |
271 | 271 | /*-------- DEBUG LOG --------*/ |
@@ -107,7 +107,7 @@ std::string http_response::http_version(std::string _http_version) | ||
107 | 107 | |
108 | 108 | std::string ret = this->_http_version; |
109 | 109 | this->_http_version = _http_version; |
110 | - this->modified = true; | |
110 | + this->_modified = true; | |
111 | 111 | |
112 | 112 | /*-------- DEBUG LOG --------*/ |
113 | 113 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -159,7 +159,7 @@ std::string http_response::status_code(std::string _status_code) | ||
159 | 159 | |
160 | 160 | std::string ret = this->_status_code; |
161 | 161 | this->_status_code = _status_code; |
162 | - this->modified = true; | |
162 | + this->_modified = true; | |
163 | 163 | |
164 | 164 | /*-------- DEBUG LOG --------*/ |
165 | 165 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -211,7 +211,7 @@ std::string http_response::reason_phrase(std::string _reason_phrase) | ||
211 | 211 | |
212 | 212 | std::string ret = this->_reason_phrase; |
213 | 213 | this->_reason_phrase = _reason_phrase; |
214 | - this->modified = true; | |
214 | + this->_modified = true; | |
215 | 215 | |
216 | 216 | /*-------- DEBUG LOG --------*/ |
217 | 217 | if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) { |
@@ -265,7 +265,7 @@ std::string http_response::as_string() | ||
265 | 265 | } |
266 | 266 | /*------ DEBUG LOG END ------*/ |
267 | 267 | |
268 | - if (this->modified) | |
268 | + if (this->_modified) | |
269 | 269 | this->rebuild(); |
270 | 270 | |
271 | 271 | /*-------- DEBUG LOG --------*/ |
@@ -138,16 +138,18 @@ void packet_editor::edit_client(char* client_msg, size_t& client_length) | ||
138 | 138 | * Insert other protocol editor. |
139 | 139 | */ |
140 | 140 | |
141 | - std::string edited = request.as_string(); | |
142 | - // New client message is too long (over buffer size) | |
143 | - if (edited.size() > MAX_BUFFER_SIZE) { | |
144 | - LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 1, "Edited message is too long. Drop message."); | |
145 | - } | |
146 | - else { | |
147 | - // Set new client message size. | |
148 | - client_length = edited.size(); | |
149 | - // Set new client message. | |
150 | - memcpy(client_msg, edited.c_str(), client_length); | |
141 | + if (request.modified()) { | |
142 | + std::string edited = request.as_string(); | |
143 | + // New client message is too long (over buffer size) | |
144 | + if (edited.size() > MAX_BUFFER_SIZE) { | |
145 | + LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 1, "Edited message is too long. Drop message."); | |
146 | + } | |
147 | + else { | |
148 | + // Set new client message size. | |
149 | + client_length = edited.size(); | |
150 | + // Set new client message. | |
151 | + memcpy(client_msg, edited.c_str(), client_length); | |
152 | + } | |
151 | 153 | } |
152 | 154 | |
153 | 155 | /*-------- DEBUG LOG --------*/ |
@@ -234,16 +236,18 @@ void packet_editor::edit_server(char* server_msg, size_t& server_length) | ||
234 | 236 | * Insert other protocol editor. |
235 | 237 | */ |
236 | 238 | |
237 | - std::string edited = response.as_string(); | |
238 | - // New server message is too long (over buffer size) | |
239 | - if (edited.size() > MAX_BUFFER_SIZE) { | |
240 | - LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 2, "Edited message is too long. Drop message."); | |
241 | - } | |
242 | - else { | |
243 | - // Set new server message size. | |
244 | - server_length = edited.size(); | |
245 | - // Set new server message. | |
246 | - memcpy(server_msg, edited.c_str(), server_length); | |
239 | + if (response.modified()) { | |
240 | + std::string edited = response.as_string(); | |
241 | + // New server message is too long (over buffer size) | |
242 | + if (edited.size() > MAX_BUFFER_SIZE) { | |
243 | + LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 2, "Edited message is too long. Drop message."); | |
244 | + } | |
245 | + else { | |
246 | + // Set new server message size. | |
247 | + server_length = edited.size(); | |
248 | + // Set new server message. | |
249 | + memcpy(server_msg, edited.c_str(), server_length); | |
250 | + } | |
247 | 251 | } |
248 | 252 | |
249 | 253 | /*-------- DEBUG LOG --------*/ |