Skip to content

Commit 8274be0

Browse files
committed
Refactoring: Having RuleMarker in a separated file
1 parent bdedfd2 commit 8274be0

File tree

4 files changed

+80
-37
lines changed

4 files changed

+80
-37
lines changed

headers/modsecurity/rule.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "modsecurity/modsecurity.h"
3030
#include "modsecurity/variable_value.h"
3131

32-
3332
#ifdef __cplusplus
3433

3534
namespace modsecurity {
@@ -103,42 +102,6 @@ class Rule {
103102
};
104103

105104

106-
class RuleMarker : public Rule {
107-
public:
108-
RuleMarker(
109-
const std::string &name,
110-
std::unique_ptr<std::string> fileName,
111-
int lineNumber)
112-
: Rule(std::move(fileName), lineNumber),
113-
m_name(std::make_shared<std::string>(name)) { }
114-
115-
116-
virtual bool evaluate(Transaction *transaction,
117-
std::shared_ptr<RuleMessage> rm) override {
118-
119-
if (transaction->isInsideAMarker()) {
120-
if (*transaction->getCurrentMarker() == *m_name) {
121-
transaction->removeMarker();
122-
// FIXME: Move this to .cc
123-
// ms_dbg_a(transaction, 4, "Out of a SecMarker " + *m_name);
124-
}
125-
}
126-
127-
return true;
128-
};
129-
130-
131-
std::shared_ptr<std::string> getName() const {
132-
return m_name;
133-
}
134-
135-
bool isMarker() override { return true; }
136-
137-
private:
138-
std::shared_ptr<std::string> m_name;
139-
};
140-
141-
142105
class RuleWithActions : public Rule {
143106
public:
144107
RuleWithActions(

headers/modsecurity/rule_marker.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
#ifdef __cplusplus
17+
#include <stack>
18+
#include <vector>
19+
#include <string>
20+
#include <list>
21+
#include <memory>
22+
#include <utility>
23+
#endif
24+
25+
#ifndef HEADERS_MODSECURITY_RULE_MARKER_H_
26+
#define HEADERS_MODSECURITY_RULE_MARKER_H_
27+
28+
#include "modsecurity/transaction.h"
29+
#include "modsecurity/modsecurity.h"
30+
#include "modsecurity/variable_value.h"
31+
#include "modsecurity/rule.h"
32+
33+
#ifdef __cplusplus
34+
35+
namespace modsecurity {
36+
37+
38+
class RuleMarker : public Rule {
39+
public:
40+
RuleMarker(
41+
const std::string &name,
42+
std::unique_ptr<std::string> fileName,
43+
int lineNumber)
44+
: Rule(std::move(fileName), lineNumber),
45+
m_name(std::make_shared<std::string>(name)) { }
46+
47+
48+
virtual bool evaluate(Transaction *transaction,
49+
std::shared_ptr<RuleMessage> rm) override {
50+
51+
if (transaction->isInsideAMarker()) {
52+
if (*transaction->getCurrentMarker() == *m_name) {
53+
transaction->removeMarker();
54+
// FIXME: Move this to .cc
55+
// ms_dbg_a(transaction, 4, "Out of a SecMarker " + *m_name);
56+
}
57+
}
58+
59+
return true;
60+
};
61+
62+
63+
std::shared_ptr<std::string> getName() {
64+
return m_name;
65+
}
66+
67+
bool isMarker() override { return true; }
68+
69+
private:
70+
std::shared_ptr<std::string> m_name;
71+
};
72+
73+
74+
} // namespace modsecurity
75+
76+
#endif
77+
78+
#endif // HEADERS_MODSECURITY_RULE_MARKER_H_

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pkginclude_HEADERS = \
4242
../headers/modsecurity/intervention.h \
4343
../headers/modsecurity/modsecurity.h \
4444
../headers/modsecurity/rule.h \
45+
../headers/modsecurity/rule_marker.h \
4546
../headers/modsecurity/rules.h \
4647
../headers/modsecurity/rule_message.h \
4748
../headers/modsecurity/rules_set.h \

src/parser/driver.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "modsecurity/rules_set_properties.h"
1919
#include "src/parser/seclang-parser.hh"
2020
#include "modsecurity/audit_log.h"
21+
#include "modsecurity/rule_marker.h"
2122

2223
using modsecurity::audit_log::AuditLog;
2324
using modsecurity::RuleWithOperator;

0 commit comments

Comments
 (0)