mirror of
https://github.com/monero-project/monero.git
synced 2025-08-09 01:52:30 -04:00
epee: remove reg_exp_definer.h
Locking to initialize static block variables isn't necessary since C++11: https://en.cppreference.com/w/cpp/language/storage_duration#Static_block_variables
This commit is contained in:
parent
977dedce2c
commit
18376ca57d
4 changed files with 12 additions and 101 deletions
|
@ -40,7 +40,6 @@
|
||||||
#include "http_client_base.h"
|
#include "http_client_base.h"
|
||||||
#include "string_tools.h"
|
#include "string_tools.h"
|
||||||
#include "string_tools_lexical.h"
|
#include "string_tools_lexical.h"
|
||||||
#include "reg_exp_definer.h"
|
|
||||||
#include "abstract_http_client.h"
|
#include "abstract_http_client.h"
|
||||||
#include "http_base.h"
|
#include "http_base.h"
|
||||||
#include "http_auth.h"
|
#include "http_auth.h"
|
||||||
|
@ -696,7 +695,7 @@ namespace net_utils
|
||||||
inline
|
inline
|
||||||
bool set_reply_content_encoder()
|
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
|
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)
|
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
|
inline
|
||||||
bool is_connection_close_field(const std::string& str)
|
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;
|
boost::smatch result;
|
||||||
if(boost::regex_search( str, result, rexp_match_close, boost::match_default) && result[0].matched)
|
if(boost::regex_search( str, result, rexp_match_close, boost::match_default) && result[0].matched)
|
||||||
return true;
|
return true;
|
||||||
|
@ -799,7 +798,7 @@ namespace net_utils
|
||||||
bool is_multipart_body(const http_header_info& head_info, OUT std::string& boundary)
|
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
|
//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;
|
boost::smatch result;
|
||||||
if(boost::regex_search(head_info.m_content_type, result, rexp_match_multipart_type, boost::match_default) && result[0].matched)
|
if(boost::regex_search(head_info.m_content_type, result, rexp_match_multipart_type, boost::match_default) && result[0].matched)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include "http_protocol_handler.h"
|
#include "http_protocol_handler.h"
|
||||||
#include "reg_exp_definer.h"
|
|
||||||
#include "string_tools.h"
|
#include "string_tools.h"
|
||||||
#include "file_io_utils.h"
|
#include "file_io_utils.h"
|
||||||
#include "net_parse_helpers.h"
|
#include "net_parse_helpers.h"
|
||||||
|
@ -59,7 +58,7 @@ namespace net_utils
|
||||||
inline
|
inline
|
||||||
bool match_boundary(const std::string& content_type, std::string& boundary)
|
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
|
// 1
|
||||||
boost::smatch result;
|
boost::smatch result;
|
||||||
if(boost::regex_search(content_type, result, rexp_match_boundary, boost::match_default) && result[0].matched)
|
if(boost::regex_search(content_type, result, rexp_match_boundary, boost::match_default) && result[0].matched)
|
||||||
|
@ -74,7 +73,7 @@ namespace net_utils
|
||||||
inline
|
inline
|
||||||
bool parse_header(std::string::const_iterator it_begin, std::string::const_iterator it_end, multipart_entry& entry)
|
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)"
|
"\n?((Content-Disposition)|(Content-Type)"
|
||||||
// 12 3
|
// 12 3
|
||||||
"|([\\w-]+?)) ?: ?((.*?)(\r?\n))[^\t ]",
|
"|([\\w-]+?)) ?: ?((.*?)(\r?\n))[^\t ]",
|
||||||
|
@ -399,7 +398,7 @@ namespace net_utils
|
||||||
template<class t_connection_context>
|
template<class t_connection_context>
|
||||||
bool simple_http_connection_handler<t_connection_context>::handle_invoke_query_line()
|
bool simple_http_connection_handler<t_connection_context>::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
|
// 123 4 5 6 7 8 9 10 11 12
|
||||||
//size_t match_len = 0;
|
//size_t match_len = 0;
|
||||||
boost::smatch result;
|
boost::smatch result;
|
||||||
|
@ -546,7 +545,7 @@ namespace net_utils
|
||||||
template<class t_connection_context>
|
template<class t_connection_context>
|
||||||
bool simple_http_connection_handler<t_connection_context>::parse_cached_header(http_header_info& body_info, const std::string& m_cache_to_process, size_t pos)
|
bool simple_http_connection_handler<t_connection_context>::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)"
|
"\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
|
// 12 3 4 5 6 7 8 9 10 11
|
||||||
"|([\\w-]+?)) ?: ?((.*?)(\r?\n))[^\t ]",
|
"|([\\w-]+?)) ?: ?((.*?)(\r?\n))[^\t ]",
|
||||||
|
@ -601,7 +600,7 @@ namespace net_utils
|
||||||
template<class t_connection_context>
|
template<class t_connection_context>
|
||||||
bool simple_http_connection_handler<t_connection_context>::get_len_from_content_lenght(const std::string& str, size_t& OUT len)
|
bool simple_http_connection_handler<t_connection_context>::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;
|
std::string res;
|
||||||
boost::smatch result;
|
boost::smatch result;
|
||||||
if(!(boost::regex_search( str, result, rexp_mach_field, boost::match_default) && result[0].matched))
|
if(!(boost::regex_search( str, result, rexp_mach_field, boost::match_default) && result[0].matched))
|
||||||
|
|
|
@ -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 <atomic>
|
|
||||||
#include <boost/regex.hpp>
|
|
||||||
#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<bool> 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<bool> 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<bool> 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_
|
|
|
@ -27,8 +27,8 @@
|
||||||
#include "net/net_parse_helpers.h"
|
#include "net/net_parse_helpers.h"
|
||||||
#include "net/http_base.h"
|
#include "net/http_base.h"
|
||||||
#include "misc_log_ex.h"
|
#include "misc_log_ex.h"
|
||||||
#include "reg_exp_definer.h"
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||||
#define MONERO_DEFAULT_LOG_CATEGORY "net"
|
#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=
|
///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();
|
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;
|
boost::smatch result;
|
||||||
if(!(boost::regex_search(uri, result, rexp_match_uri, boost::match_default) && result[0].matched))
|
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)
|
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
|
// 12 3 4 5 6 7
|
||||||
|
|
||||||
content.port = 0;
|
content.port = 0;
|
||||||
|
@ -169,9 +169,7 @@ namespace net_utils
|
||||||
|
|
||||||
if (parse_url_ipv6(url_str, content)) return true;
|
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 const boost::regex rexp_match_uri("^(([^:]*?)://)?(([^/:]*)(:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal);
|
||||||
//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);
|
|
||||||
// 12 34 5 6 7
|
// 12 34 5 6 7
|
||||||
content.port = 0;
|
content.port = 0;
|
||||||
boost::smatch result;
|
boost::smatch result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue