Skip to content

Commit b8e31d1

Browse files
zimmerleWGH-
authored andcommitted
Moving regex from utils to its own namespace
1 parent e9dce44 commit b8e31d1

File tree

22 files changed

+152
-76
lines changed

22 files changed

+152
-76
lines changed

headers/modsecurity/anchored_set_variable.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
namespace modsecurity {
4040
class Transaction;
41-
namespace Utils {
41+
namespace regex {
4242
class Regex;
4343
}
4444
namespace variables {
@@ -91,10 +91,10 @@ class AnchoredSetVariable : public std::unordered_multimap<std::string,
9191
void resolve(const std::string &key,
9292
std::vector<const VariableValue *> *l);
9393

94-
void resolveRegularExpression(Utils::Regex *r,
94+
void resolveRegularExpression(regex::Regex *r,
9595
std::vector<const VariableValue *> *l);
9696

97-
void resolveRegularExpression(Utils::Regex *r,
97+
void resolveRegularExpression(regex::Regex *r,
9898
std::vector<const VariableValue *> *l,
9999
variables::KeyExclusions &ke);
100100

src/Makefile.am

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,17 @@ UTILS = \
247247
utils/md5.cc \
248248
utils/msc_tree.cc \
249249
utils/random.cc \
250-
utils/regex.cc \
251250
utils/sha1.cc \
252251
utils/string.cc \
253252
utils/system.cc \
254253
utils/shared_files.cc
255254

256255

256+
REGEX = \
257+
regex/regex.cc \
258+
regex/backend/pcre.cc
259+
260+
257261
COLLECTION = \
258262
collection/collections.cc \
259263
collection/backend/in_memory-per_process.cc \
@@ -299,6 +303,7 @@ libmodsecurity_la_SOURCES = \
299303
${COLLECTION} \
300304
${OPERATORS} \
301305
${UTILS} \
306+
${REGEX} \
302307
${VARIABLES}
303308

304309

src/anchored_set_variable.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "modsecurity/anchored_set_variable.h"
2323
#include "modsecurity/modsecurity.h"
2424
#include "modsecurity/transaction.h"
25-
#include "src/utils/regex.h"
25+
#include "src/regex/regex.h"
2626
#include "src/variables/variable.h"
2727

2828
namespace modsecurity {
@@ -123,10 +123,10 @@ std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(
123123
}
124124

125125

126-
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
126+
void AnchoredSetVariable::resolveRegularExpression(regex::Regex *r,
127127
std::vector<const VariableValue *> *l) {
128128
for (const auto& x : *this) {
129-
int ret = Utils::regex_search(x.first, *r);
129+
int ret = regex::regex_search(x.first, *r);
130130
if (ret <= 0) {
131131
continue;
132132
}
@@ -135,11 +135,11 @@ void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
135135
}
136136

137137

138-
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
138+
void AnchoredSetVariable::resolveRegularExpression(regex::Regex *r,
139139
std::vector<const VariableValue *> *l,
140140
variables::KeyExclusions &ke) {
141141
for (const auto& x : *this) {
142-
int ret = Utils::regex_search(x.first, *r);
142+
int ret = regex::regex_search(x.first, *r);
143143
if (ret <= 0) {
144144
continue;
145145
}

src/anchored_variable.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "../headers/modsecurity/anchored_variable.h"
2323
#include "modsecurity/modsecurity.h"
2424
#include "modsecurity/transaction.h"
25-
#include "src/utils/regex.h"
25+
#include "src/regex/regex.h"
2626

2727
namespace modsecurity {
2828

src/audit_log/audit_log.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "src/audit_log/writer/parallel.h"
2727
#include "src/audit_log/writer/serial.h"
2828
#include "src/audit_log/writer/writer.h"
29-
#include "src/utils/regex.h"
29+
#include "src/regex/regex.h"
3030

3131
#define PARTS_CONSTAINS(a, c) \
3232
if (new_parts.find(toupper(a)) != std::string::npos \
@@ -278,8 +278,8 @@ bool AuditLog::isRelevant(int status) {
278278
return true;
279279
}
280280

281-
return Utils::regex_search(sstatus,
282-
Utils::Regex(m_relevant)) != 0;
281+
return regex::regex_search(sstatus,
282+
regex::Regex(m_relevant)) != 0;
283283
}
284284

285285

src/collection/backend/in_memory-per_process.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <pthread.h>
2828

2929
#include "modsecurity/variable_value.h"
30-
#include "src/utils/regex.h"
30+
#include "src/regex/regex.h"
3131
#include "src/utils/string.h"
3232

3333

@@ -134,7 +134,7 @@ void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
134134
//std::string name = std::string(var, var.find(":") + 2,
135135
// var.size() - var.find(":") - 3);
136136
//size_t keySize = col.size();
137-
Utils::Regex r(var);
137+
regex::Regex r(var);
138138

139139
for (const auto& x : *this) {
140140
//if (x.first.size() <= keySize + 1) {
@@ -148,7 +148,7 @@ void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
148148
//}
149149
//std::string content = std::string(x.first, keySize + 1,
150150
// x.first.size() - keySize - 1);
151-
int ret = Utils::regex_search(x.first, r);
151+
int ret = regex::regex_search(x.first, r);
152152
if (ret <= 0) {
153153
continue;
154154
}

src/collection/backend/lmdb.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <memory>
2424

2525
#include "modsecurity/variable_value.h"
26-
#include "src/utils/regex.h"
26+
#include "src/regex/regex.h"
2727
#include "src/variables/variable.h"
2828

2929
#undef LMDB_STDOUT_COUT
@@ -537,7 +537,7 @@ void LMDB::resolveRegularExpression(const std::string& var,
537537
MDB_stat mst;
538538
MDB_cursor *cursor;
539539

540-
Utils::Regex r(var);
540+
regex::Regex r(var);
541541

542542
rc = mdb_txn_begin(m_env, NULL, 0, &txn);
543543
lmdb_debug(rc, "txn", "resolveRegularExpression");
@@ -559,7 +559,7 @@ void LMDB::resolveRegularExpression(const std::string& var,
559559

560560
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
561561
char *a = reinterpret_cast<char *>(key.mv_data);
562-
int ret = Utils::regex_search(a, r);
562+
int ret = regex::regex_search(a, r);
563563
if (ret <= 0) {
564564
continue;
565565
}

src/modsecurity.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "src/collection/backend/in_memory-per_process.h"
3939
#include "src/collection/backend/lmdb.h"
4040
#include "src/unique_id.h"
41-
#include "src/utils/regex.h"
41+
#include "src/regex/regex.h"
4242
#include "src/utils/geo_lookup.h"
4343
#include "src/actions/transformations/transformation.h"
4444

@@ -221,17 +221,17 @@ void ModSecurity::serverLog(void *data, std::shared_ptr<RuleMessage> rm) {
221221
int ModSecurity::processContentOffset(const char *content, size_t len,
222222
const char *matchString, std::string *json, const char **err) {
223223
#ifdef WITH_YAJL
224-
Utils::Regex variables("v([0-9]+),([0-9]+)");
225-
Utils::Regex operators("o([0-9]+),([0-9]+)");
226-
Utils::Regex transformations("t:(?:(?!t:).)+");
224+
regex::Regex variables("v([0-9]+),([0-9]+)");
225+
regex::Regex operators("o([0-9]+),([0-9]+)");
226+
regex::Regex transformations("t:(?:(?!t:).)+");
227227
yajl_gen g;
228228
std::string varValue;
229229
const unsigned char *buf;
230230
size_t jsonSize;
231231

232-
std::list<Utils::SMatch> vars = variables.searchAll(matchString);
233-
std::list<Utils::SMatch> ops = operators.searchAll(matchString);
234-
std::list<Utils::SMatch> trans = transformations.searchAll(matchString);
232+
std::list<regex::SMatch> vars = variables.searchAll(matchString);
233+
std::list<regex::SMatch> ops = operators.searchAll(matchString);
234+
std::list<regex::SMatch> trans = transformations.searchAll(matchString);
235235

236236
g = yajl_gen_alloc(NULL);
237237
if (g == NULL) {

src/operators/rx.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ bool Rx::evaluate(Transaction *transaction, RuleWithActions *rule,
5151
re = m_re;
5252
}
5353

54-
std::vector<Utils::SMatchCapture> captures;
54+
std::vector<regex::SMatchCapture> captures;
5555
re->searchOneMatch(input, captures);
5656

5757
if (rule && rule->hasCaptureAction() && transaction) {
58-
for (const Utils::SMatchCapture& capture : captures) {
58+
for (const regex::SMatchCapture& capture : captures) {
5959
const std::string capture_substring(input.substr(capture.m_offset,capture.m_length));
6060
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
6161
std::to_string(capture.m_group), capture_substring);

src/operators/rx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
#include <utility>
2323

2424
#include "src/operators/operator.h"
25-
#include "src/utils/regex.h"
25+
#include "src/regex/regex.h"
2626

2727

2828
namespace modsecurity {
29-
using Utils::SMatch;
30-
using Utils::regex_search;
31-
using Utils::Regex;
29+
using regex::SMatch;
30+
using regex::regex_search;
31+
using regex::Regex;
3232

3333
namespace operators {
3434

0 commit comments

Comments
 (0)