From 57fc3b50841eccdc93e8e7b126ee1ff0df512d2a Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 18 Jan 2019 18:05:31 -0300 Subject: [PATCH] Renames SMatch to RegexMatch --- src/modsecurity.cc | 6 +++--- src/operators/rx.cc | 4 ++-- src/operators/rx.h | 2 +- src/operators/verify_cpf.cc | 2 +- src/operators/verify_cpf.h | 2 +- src/operators/verify_ssn.cc | 2 +- src/operators/verify_ssn.h | 2 +- src/regex/regex.cc | 10 +++++----- src/regex/regex.h | 12 ++++++------ test/regression/regression.cc | 4 ++-- test/unit/unit_test.cc | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/modsecurity.cc b/src/modsecurity.cc index 8b316b8a..04a21acf 100644 --- a/src/modsecurity.cc +++ b/src/modsecurity.cc @@ -228,9 +228,9 @@ int ModSecurity::processContentOffset(const char *content, size_t len, const unsigned char *buf; size_t jsonSize; - std::list vars = variables.searchAll(matchString); - std::list ops = operators.searchAll(matchString); - std::list trans = transformations.searchAll(matchString); + std::list vars = variables.searchAll(matchString); + std::list ops = operators.searchAll(matchString); + std::list trans = transformations.searchAll(matchString); g = yajl_gen_alloc(NULL); if (g == NULL) { diff --git a/src/operators/rx.cc b/src/operators/rx.cc index 43f6444b..1ba4e078 100644 --- a/src/operators/rx.cc +++ b/src/operators/rx.cc @@ -38,7 +38,7 @@ bool Rx::init(const std::string &arg, std::string *error) { bool Rx::evaluate(Transaction *transaction, Rule *rule, const std::string& input, std::shared_ptr ruleMessage) { - std::list matches; + std::list matches; Regex *re; if (m_param.empty() && !m_string->m_containsMacro) { @@ -56,7 +56,7 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule, if (rule && rule->m_containsCaptureAction && transaction) { int i = 0; matches.reverse(); - for (const SMatch& a : matches) { + for (const RegexMatch& a : matches) { transaction->m_collections.m_tx_collection->storeOrUpdateFirst( std::to_string(i), a.str()); ms_dbg_a(transaction, 7, "Added regex subexpression TX." + diff --git a/src/operators/rx.h b/src/operators/rx.h index 5da9bfe2..27c0a762 100644 --- a/src/operators/rx.h +++ b/src/operators/rx.h @@ -26,7 +26,7 @@ namespace modsecurity { -using regex::SMatch; +using regex::RegexMatch; using regex::regex_search; using regex::Regex; diff --git a/src/operators/verify_cpf.cc b/src/operators/verify_cpf.cc index ac4874bf..1e00bba4 100644 --- a/src/operators/verify_cpf.cc +++ b/src/operators/verify_cpf.cc @@ -119,7 +119,7 @@ bool VerifyCPF::verify(const char *cpfnumber, int len) { bool VerifyCPF::evaluate(Transaction *t, Rule *rule, const std::string& input, std::shared_ptr ruleMessage) { - std::list matches; + std::list matches; bool is_cpf = false; int i; diff --git a/src/operators/verify_cpf.h b/src/operators/verify_cpf.h index 318625fd..ba11a15c 100644 --- a/src/operators/verify_cpf.h +++ b/src/operators/verify_cpf.h @@ -25,7 +25,7 @@ namespace modsecurity { -using regex::SMatch; +using regex::RegexMatch; using regex::regex_search; using regex::Regex; diff --git a/src/operators/verify_ssn.cc b/src/operators/verify_ssn.cc index deb97e6f..5704ffe7 100644 --- a/src/operators/verify_ssn.cc +++ b/src/operators/verify_ssn.cc @@ -110,7 +110,7 @@ invalid: bool VerifySSN::evaluate(Transaction *t, Rule *rule, const std::string& input, std::shared_ptr ruleMessage) { - std::list matches; + std::list matches; bool is_ssn = false; int i; diff --git a/src/operators/verify_ssn.h b/src/operators/verify_ssn.h index 1386805b..39ffaead 100644 --- a/src/operators/verify_ssn.h +++ b/src/operators/verify_ssn.h @@ -25,7 +25,7 @@ namespace modsecurity { -using regex::SMatch; +using regex::RegexMatch; using regex::regex_search; using regex::Regex; diff --git a/src/regex/regex.cc b/src/regex/regex.cc index 36de0c6d..403f230e 100644 --- a/src/regex/regex.cc +++ b/src/regex/regex.cc @@ -66,12 +66,12 @@ Regex::~Regex() { } -std::list Regex::searchAll(const std::string& s) const { +std::list Regex::searchAll(const std::string& s) const { const char *subject = s.c_str(); const std::string tmpString = std::string(s.c_str(), s.size()); int ovector[OVECCOUNT]; int rc, i, offset = 0; - std::list retList; + std::list retList; do { rc = pcre_exec(m_pc, m_pce, subject, @@ -87,7 +87,7 @@ std::list Regex::searchAll(const std::string& s) const { } std::string match = std::string(tmpString, start, len); offset = start + len; - retList.push_front(SMatch(match, start)); + retList.push_front(RegexMatch(match, start)); if (len == 0) { rc = 0; @@ -99,13 +99,13 @@ std::list Regex::searchAll(const std::string& s) const { return retList; } -int Regex::search(const std::string& s, SMatch *match) const { +int Regex::search(const std::string& s, RegexMatch *match) const { int ovector[OVECCOUNT]; int ret = pcre_exec(m_pc, m_pce, s.c_str(), s.size(), 0, 0, ovector, OVECCOUNT) > 0; if (ret > 0) { - *match = SMatch( + *match = RegexMatch( std::string(s, ovector[ret-1], ovector[ret] - ovector[ret-1]), 0); } diff --git a/src/regex/regex.h b/src/regex/regex.h index 1accf473..6687d35e 100644 --- a/src/regex/regex.h +++ b/src/regex/regex.h @@ -30,13 +30,13 @@ namespace regex { #define OVECCOUNT 30 -class SMatch { +class RegexMatch { public: - SMatch() : + RegexMatch() : m_match(), m_offset(0) { } - SMatch(const std::string &match, size_t offset) : + RegexMatch(const std::string &match, size_t offset) : m_match(match), m_offset(offset) { } @@ -58,8 +58,8 @@ class Regex { Regex(const Regex&) = delete; Regex& operator=(const Regex&) = delete; - std::list searchAll(const std::string& s) const; - int search(const std::string &s, SMatch *m) const; + std::list searchAll(const std::string& s) const; + int search(const std::string &s, RegexMatch *m) const; int search(const std::string &s) const; const std::string pattern; @@ -69,7 +69,7 @@ class Regex { }; -static inline int regex_search(const std::string& s, SMatch *match, const Regex& regex) { +static inline int regex_search(const std::string& s, RegexMatch *match, const Regex& regex) { return regex.search(s, match); } diff --git a/test/regression/regression.cc b/test/regression/regression.cc index 6f6498ee..f245565f 100644 --- a/test/regression/regression.cc +++ b/test/regression/regression.cc @@ -40,7 +40,7 @@ using modsecurity_test::RegressionTest; using modsecurity_test::RegressionTestResult; using modsecurity::regex::regex_search; -using modsecurity::regex::SMatch; +using modsecurity::regex::RegexMatch; using modsecurity::regex::Regex; std::string default_test_path = "test-cases/regression"; @@ -207,7 +207,7 @@ void perform_unit_test(ModSecurityTest *test, } Regex re(t->parser_error); - SMatch match; + RegexMatch match; std::string s = modsec_rules->getParserError(); if (regex_search(s, &match, re)) { diff --git a/test/unit/unit_test.cc b/test/unit/unit_test.cc index b0beb4e4..ca856f44 100644 --- a/test/unit/unit_test.cc +++ b/test/unit/unit_test.cc @@ -60,7 +60,7 @@ void replaceAll(std::string *s, const std::string &search, void json2bin(std::string *str) { modsecurity::regex::Regex re("\\\\x([a-z0-9A-Z]{2})"); modsecurity::regex::Regex re2("\\\\u([a-z0-9A-Z]{4})"); - modsecurity::regex::SMatch match; + modsecurity::regex::RegexMatch match; while (modsecurity::regex::regex_search(*str, &match, re)) { unsigned int p;