diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h index 8cee399cb5..66788c88d4 100644 --- a/contrib/epee/include/net/http_client.h +++ b/contrib/epee/include/net/http_client.h @@ -40,7 +40,6 @@ #include "http_client_base.h" #include "string_tools.h" #include "string_tools_lexical.h" -#include "reg_exp_definer.h" #include "abstract_http_client.h" #include "http_base.h" #include "http_auth.h" @@ -696,7 +695,7 @@ namespace net_utils inline bool set_reply_content_encoder() { - STATIC_REGEXP_EXPR_1(rexp_match_gzip, "^.*?((gzip)|(deflate))", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_gzip("^.*?((gzip)|(deflate))", boost::regex::icase | boost::regex::normal); boost::smatch result; // 12 3 if(boost::regex_search( m_response_info.m_header_info.m_content_encoding, result, rexp_match_gzip, boost::match_default) && result[0].matched) { @@ -788,7 +787,7 @@ namespace net_utils inline bool is_connection_close_field(const std::string& str) { - STATIC_REGEXP_EXPR_1(rexp_match_close, "^\\s*close", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_close("^\\s*close", boost::regex::icase | boost::regex::normal); boost::smatch result; if(boost::regex_search( str, result, rexp_match_close, boost::match_default) && result[0].matched) return true; @@ -799,7 +798,7 @@ namespace net_utils bool is_multipart_body(const http_header_info& head_info, OUT std::string& boundary) { //Check whether this is multi part - if yes, capture boundary immediately - STATIC_REGEXP_EXPR_1(rexp_match_multipart_type, "^\\s*multipart/([\\w\\-]+); boundary=((\"(.*?)\")|(\\\\\"(.*?)\\\\\")|([^\\s;]*))", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_multipart_type("^\\s*multipart/([\\w\\-]+); boundary=((\"(.*?)\")|(\\\\\"(.*?)\\\\\")|([^\\s;]*))", boost::regex::icase | boost::regex::normal); boost::smatch result; if(boost::regex_search(head_info.m_content_type, result, rexp_match_multipart_type, boost::match_default) && result[0].matched) { diff --git a/contrib/epee/include/net/http_protocol_handler.inl b/contrib/epee/include/net/http_protocol_handler.inl index 6647d1f15c..f682c8bda3 100644 --- a/contrib/epee/include/net/http_protocol_handler.inl +++ b/contrib/epee/include/net/http_protocol_handler.inl @@ -28,7 +28,6 @@ #include #include #include "http_protocol_handler.h" -#include "reg_exp_definer.h" #include "string_tools.h" #include "file_io_utils.h" #include "net_parse_helpers.h" @@ -59,7 +58,7 @@ namespace net_utils inline bool match_boundary(const std::string& content_type, std::string& boundary) { - STATIC_REGEXP_EXPR_1(rexp_match_boundary, "boundary=(.*?)(($)|([;\\s,]))", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_boundary("boundary=(.*?)(($)|([;\\s,]))", boost::regex::icase | boost::regex::normal); // 1 boost::smatch result; if(boost::regex_search(content_type, result, rexp_match_boundary, boost::match_default) && result[0].matched) @@ -74,7 +73,7 @@ namespace net_utils inline bool parse_header(std::string::const_iterator it_begin, std::string::const_iterator it_end, multipart_entry& entry) { - STATIC_REGEXP_EXPR_1(rexp_mach_field, + static const boost::regex rexp_mach_field( "\n?((Content-Disposition)|(Content-Type)" // 12 3 "|([\\w-]+?)) ?: ?((.*?)(\r?\n))[^\t ]", @@ -399,7 +398,7 @@ namespace net_utils template bool simple_http_connection_handler::handle_invoke_query_line() { - STATIC_REGEXP_EXPR_1(rexp_match_command_line, "^(((OPTIONS)|(GET)|(HEAD)|(POST)|(PUT)|(DELETE)|(TRACE)) (\\S+) HTTP/(\\d+)\\.(\\d+))\r?\n", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_command_line("^(((OPTIONS)|(GET)|(HEAD)|(POST)|(PUT)|(DELETE)|(TRACE)) (\\S+) HTTP/(\\d+)\\.(\\d+))\r?\n", boost::regex::icase | boost::regex::normal); // 123 4 5 6 7 8 9 10 11 12 //size_t match_len = 0; boost::smatch result; @@ -546,7 +545,7 @@ namespace net_utils template bool simple_http_connection_handler::parse_cached_header(http_header_info& body_info, const std::string& m_cache_to_process, size_t pos) { - STATIC_REGEXP_EXPR_1(rexp_mach_field, + static const boost::regex rexp_mach_field( "\n?((Connection)|(Referer)|(Content-Length)|(Content-Type)|(Transfer-Encoding)|(Content-Encoding)|(Host)|(Cookie)|(User-Agent)|(Origin)" // 12 3 4 5 6 7 8 9 10 11 "|([\\w-]+?)) ?: ?((.*?)(\r?\n))[^\t ]", @@ -601,7 +600,7 @@ namespace net_utils template bool simple_http_connection_handler::get_len_from_content_lenght(const std::string& str, size_t& OUT len) { - STATIC_REGEXP_EXPR_1(rexp_mach_field, "\\d+", boost::regex::normal); + static const boost::regex rexp_mach_field("\\d+", boost::regex::normal); std::string res; boost::smatch result; if(!(boost::regex_search( str, result, rexp_mach_field, boost::match_default) && result[0].matched)) diff --git a/contrib/epee/include/reg_exp_definer.h b/contrib/epee/include/reg_exp_definer.h deleted file mode 100644 index d1b800a328..0000000000 --- a/contrib/epee/include/reg_exp_definer.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// * Neither the name of the Andrey N. Sabelnikov nor the -// names of its contributors may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY -// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - - -#ifndef _REG_EXP_DEFINER_H_ -#define _REG_EXP_DEFINER_H_ - -#include -#include -#include "syncobj.h" - -namespace epee -{ - class global_regexp_critical_section - { - private: - mutable critical_section regexp_lock; - public: - global_regexp_critical_section(){} - critical_section& get_lock()const {return regexp_lock;} - }; - - const static global_regexp_critical_section gregexplock; - -#define STATIC_REGEXP_EXPR_1(var_name, xpr_text, reg_exp_flags) \ - static std::atomic regexp_initialized_1(false);\ - volatile uint32_t local_is_initialized_1 = regexp_initialized_1;\ - if(!local_is_initialized_1)\ - gregexplock.get_lock().lock();\ - static const boost::regex var_name(xpr_text , reg_exp_flags);\ - if(!local_is_initialized_1)\ -{\ - regexp_initialized_1 = true;\ - gregexplock.get_lock().unlock();\ -} - -#define STATIC_REGEXP_EXPR_2(var_name, xpr_text, reg_exp_flags) \ - static std::atomic regexp_initialized_2(false);\ - volatile uint32_t local_is_initialized_2 = regexp_initialized_2;\ - if(!local_is_initialized_2)\ - gregexplock.get_lock().lock().lock();\ - static const boost::regex var_name(xpr_text , reg_exp_flags);\ - if(!local_is_initialized_2)\ -{\ - regexp_initialized_2 = true;\ - gregexplock.get_lock().lock().unlock();\ -} - -#define STATIC_REGEXP_EXPR_3(var_name, xpr_text, reg_exp_flags) \ - static std::atomic regexp_initialized_3(false);\ - volatile uint32_t local_is_initialized_3 = regexp_initialized_3;\ - if(!local_is_initialized_3)\ - gregexplock.get_lock().lock().lock();\ - static const boost::regex var_name(xpr_text , reg_exp_flags);\ - if(!local_is_initialized_3)\ -{\ - regexp_initialized_3 = true;\ - gregexplock.get_lock().lock().unlock();\ -} -} - -#endif //_REG_EXP_DEFINER_H_ diff --git a/contrib/epee/src/net_parse_helpers.cpp b/contrib/epee/src/net_parse_helpers.cpp index 2697bdac4f..187f155581 100644 --- a/contrib/epee/src/net_parse_helpers.cpp +++ b/contrib/epee/src/net_parse_helpers.cpp @@ -27,8 +27,8 @@ #include "net/net_parse_helpers.h" #include "net/http_base.h" #include "misc_log_ex.h" -#include "reg_exp_definer.h" #include +#include #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net" @@ -98,7 +98,7 @@ namespace net_utils ///iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash= content.m_query_params.clear(); - STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_uri("^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal); boost::smatch result; if(!(boost::regex_search(uri, result, rexp_match_uri, boost::match_default) && result[0].matched)) @@ -128,7 +128,7 @@ namespace net_utils bool parse_url_ipv6(const std::string url_str, http::url_content& content) { - STATIC_REGEXP_EXPR_1(rexp_match_uri, "^(([^:]*?)://)?(\\[(.*)\\](:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_uri("^(([^:]*?)://)?(\\[(.*)\\](:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal); // 12 3 4 5 6 7 content.port = 0; @@ -169,9 +169,7 @@ namespace net_utils if (parse_url_ipv6(url_str, content)) return true; - ///iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash= - //STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal); - STATIC_REGEXP_EXPR_1(rexp_match_uri, "^(([^:]*?)://)?(([^/:]*)(:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal); + static const boost::regex rexp_match_uri("^(([^:]*?)://)?(([^/:]*)(:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal); // 12 34 5 6 7 content.port = 0; boost::smatch result;