Skip to content

Commit 8e62341

Browse files
committed
Moving regex from utils to its own namespace
1 parent 145f2f3 commit 8e62341

File tree

22 files changed

+146
-70
lines changed

22 files changed

+146
-70
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
@@ -239,13 +239,17 @@ UTILS = \
239239
utils/md5.cc \
240240
utils/msc_tree.cc \
241241
utils/random.cc \
242-
utils/regex.cc \
243242
utils/sha1.cc \
244243
utils/string.cc \
245244
utils/system.cc \
246245
utils/shared_files.cc
247246

248247

248+
REGEX = \
249+
regex/regex.cc \
250+
regex/backend/pcre.cc
251+
252+
249253
COLLECTION = \
250254
collection/collections.cc \
251255
collection/backend/in_memory-per_process.cc \
@@ -287,6 +291,7 @@ libmodsecurity_la_SOURCES = \
287291
${COLLECTION} \
288292
${OPERATORS} \
289293
${UTILS} \
294+
${REGEX} \
290295
${VARIABLES}
291296

292297

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 {
@@ -124,10 +124,10 @@ std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(
124124
}
125125

126126

127-
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
127+
void AnchoredSetVariable::resolveRegularExpression(regex::Regex *r,
128128
std::vector<const VariableValue *> *l) {
129129
for (const auto& x : *this) {
130-
int ret = Utils::regex_search(x.first, *r);
130+
int ret = regex::regex_search(x.first, *r);
131131
if (ret <= 0) {
132132
continue;
133133
}
@@ -136,11 +136,11 @@ void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
136136
}
137137

138138

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

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 \
@@ -279,8 +279,8 @@ bool AuditLog::isRelevant(int status) {
279279
return true;
280280
}
281281

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

286286

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
@@ -538,7 +538,7 @@ void LMDB::resolveRegularExpression(const std::string& var,
538538
MDB_cursor *cursor;
539539
size_t pos;
540540

541-
Utils::Regex r(var);
541+
regex::Regex r = regex::Regex(var);
542542

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

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

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

@@ -219,18 +219,18 @@ void ModSecurity::serverLog(void *data, std::shared_ptr<RuleMessage> rm) {
219219
int ModSecurity::processContentOffset(const char *content, size_t len,
220220
const char *matchString, std::string *json, const char **err) {
221221
#ifdef WITH_YAJL
222-
Utils::Regex variables("v([0-9]+),([0-9]+)");
223-
Utils::Regex operators("o([0-9]+),([0-9]+)");
224-
Utils::Regex transformations("t:(?:(?!t:).)+");
222+
regex::Regex variables("v([0-9]+),([0-9]+)");
223+
regex::Regex operators("o([0-9]+),([0-9]+)");
224+
regex::Regex transformations("t:(?:(?!t:).)+");
225225
yajl_gen g;
226226
std::string varValue;
227227
std::string opValue;
228228
const unsigned char *buf;
229229
size_t jsonSize;
230230

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

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

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

src/operators/verify_cpf.h

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

2323
#include "src/operators/operator.h"
24-
#include "src/utils/regex.h"
24+
#include "src/regex/regex.h"
2525

2626

2727
namespace modsecurity {
28-
using Utils::SMatch;
29-
using Utils::regex_search;
30-
using Utils::Regex;
28+
using regex::SMatch;
29+
using regex::regex_search;
30+
using regex::Regex;
3131

3232
namespace operators {
3333

src/operators/verify_ssn.h

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

2323
#include "src/operators/operator.h"
24-
#include "src/utils/regex.h"
24+
#include "src/regex/regex.h"
2525

2626

2727
namespace modsecurity {
28-
using Utils::SMatch;
29-
using Utils::regex_search;
30-
using Utils::Regex;
28+
using regex::SMatch;
29+
using regex::regex_search;
30+
using regex::Regex;
3131

3232
namespace operators {
3333

src/regex/backend/pcre.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address security@modsecurity.org.
13+
*
14+
*/
15+
16+
#include <pcre.h>
17+
18+
#include <iostream>
19+
#include <fstream>
20+
#include <string>
21+
#include <list>
22+
23+
#ifndef SRC_REGEX_BACKEND_PCRE_H_
24+
#define SRC_REGEX_BACKEND_PCRE_H_
25+
26+
namespace modsecurity {
27+
namespace regex {
28+
29+
30+
31+
} // namespace regex
32+
} // namespace modsecurity
33+
34+
35+
#endif // SRC_REGEX_BACKEND_PCRE_H_

src/regex/backend/pcre.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address security@modsecurity.org.
13+
*
14+
*/
15+
16+
#include <pcre.h>
17+
18+
#include <iostream>
19+
#include <fstream>
20+
#include <string>
21+
#include <list>
22+
23+
#ifndef SRC_REGEX_BACKEND_PCRE_H_
24+
#define SRC_REGEX_BACKEND_PCRE_H_
25+
26+
namespace modsecurity {
27+
namespace regex {
28+
29+
30+
31+
} // namespace regex
32+
} // namespace modsecurity
33+
34+
35+
#endif // SRC_REGEX_BACKEND_PCRE_H_

src/utils/regex.cc renamed to src/regex/regex.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515

16-
#include "src/utils/regex.h"
16+
#include "src/regex/regex.h"
1717

1818
#include <pcre.h>
1919
#include <sys/socket.h>
@@ -35,7 +35,7 @@
3535
#endif
3636

3737
namespace modsecurity {
38-
namespace Utils {
38+
namespace regex {
3939

4040

4141
Regex::Regex(const std::string& pattern_)
@@ -119,5 +119,5 @@ int Regex::search(const std::string& s) const {
119119
s.size(), 0, 0, ovector, OVECCOUNT) > 0;
120120
}
121121

122-
} // namespace Utils
122+
} // namespace regex
123123
} // namespace modsecurity

src/regex/regex.cc.orig

Whitespace-only changes.

src/utils/regex.h renamed to src/regex/regex.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
#include <string>
2121
#include <list>
2222

23-
#ifndef SRC_UTILS_REGEX_H_
24-
#define SRC_UTILS_REGEX_H_
23+
#ifndef SRC_REGEX_REGEX_H_
24+
#define SRC_REGEX_REGEX_H_
2525

2626

2727
namespace modsecurity {
28-
namespace Utils {
28+
namespace regex {
29+
2930

3031
#define OVECCOUNT 30
3132

@@ -78,7 +79,7 @@ static inline int regex_search(const std::string& s, const Regex& regex) {
7879
}
7980

8081

81-
} // namespace Utils
82+
} // namespace regex
8283
} // namespace modsecurity
8384

84-
#endif // SRC_UTILS_REGEX_H_
85+
#endif // SRC_REGEX_REGEX_H_

src/regex/regex.h.orig

Whitespace-only changes.

0 commit comments

Comments
 (0)