Skip to content

Commit f63bd1a

Browse files
committed
Moves Rule[WithActions|WithOperator] to their own files
1 parent 8274be0 commit f63bd1a

File tree

10 files changed

+1092
-897
lines changed

10 files changed

+1092
-897
lines changed

headers/modsecurity/actions/action.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "modsecurity/intervention.h"
2525
#include "modsecurity/rule.h"
26+
#include "modsecurity/rule_with_actions.h"
2627

2728
#ifndef HEADERS_MODSECURITY_ACTIONS_ACTION_H_
2829
#define HEADERS_MODSECURITY_ACTIONS_ACTION_H_
@@ -32,7 +33,6 @@
3233
namespace modsecurity {
3334
class Transaction;
3435
class RuleWithOperator;
35-
class RuleWithActions;
3636

3737
namespace actions {
3838

headers/modsecurity/rule.h

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -102,127 +102,6 @@ class Rule {
102102
};
103103

104104

105-
class RuleWithActions : public Rule {
106-
public:
107-
RuleWithActions(
108-
Actions *a,
109-
Transformations *t,
110-
std::unique_ptr<std::string> fileName,
111-
int lineNumber);
112-
113-
~RuleWithActions();
114-
115-
void executeAction(Transaction *trans,
116-
bool containsBlock,
117-
std::shared_ptr<RuleMessage> ruleMessage,
118-
actions::Action *a,
119-
bool context);
120-
121-
void executeTransformations(
122-
Transaction *trasn, const std::string &value, TransformationResults &ret);
123-
inline void executeTransformation(
124-
actions::transformations::Transformation *a,
125-
std::shared_ptr<std::string> *value,
126-
Transaction *trans,
127-
TransformationResults *ret,
128-
std::string *path,
129-
int *nth) const;
130-
131-
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
132-
bool *b, std::shared_ptr<RuleMessage> ruleMessage);
133-
void executeActionsAfterFullMatch(Transaction *trasn,
134-
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
135-
136-
std::vector<actions::Action *> getActionsByName(const std::string& name,
137-
Transaction *t);
138-
bool containsTag(const std::string& name, Transaction *t);
139-
bool containsMsg(const std::string& name, Transaction *t);
140-
141-
inline bool isChained() const { return m_isChained == true; }
142-
inline bool hasCaptureAction() const { return m_containsCaptureAction == true; }
143-
inline void setChained(bool b) { m_isChained = b; }
144-
inline bool hasDisruptiveAction() const { return m_disruptiveAction != NULL; }
145-
inline bool hasBlockAction() const { return m_containsStaticBlockAction == true; }
146-
inline bool hasMultimatch() const { return m_containsMultiMatchAction == true; }
147-
148-
inline bool hasLogData() const { return m_logData != NULL; }
149-
std::string logData(Transaction *t);
150-
inline bool hasMsg() const { return m_msg != NULL; }
151-
std::string msg(Transaction *t);
152-
inline bool hasSeverity() const { return m_severity != NULL; }
153-
int severity() const;
154-
155-
std::string m_rev;
156-
std::string m_ver;
157-
int m_accuracy;
158-
int m_maturity;
159-
160-
int64_t m_ruleId;
161-
162-
private:
163-
/* actions */
164-
actions::Action *m_disruptiveAction;
165-
actions::LogData *m_logData;
166-
actions::Msg *m_msg;
167-
actions::Severity *m_severity;
168-
MatchActions m_actionsRuntimePos;
169-
SetVars m_actionsSetVar;
170-
Tags m_actionsTag;
171-
172-
/* actions > transformations */
173-
Transformations m_transformations;
174-
175-
bool m_containsCaptureAction:1;
176-
bool m_containsMultiMatchAction:1;
177-
bool m_containsStaticBlockAction:1;
178-
bool m_isChained:1;
179-
};
180-
181-
182-
class RuleWithOperator : public RuleWithActions {
183-
public:
184-
RuleWithOperator(operators::Operator *op,
185-
variables::Variables *variables,
186-
std::vector<actions::Action *> *actions,
187-
Transformations *transformations,
188-
std::unique_ptr<std::string> fileName,
189-
int lineNumber);
190-
191-
virtual ~RuleWithOperator();
192-
193-
bool evaluate(Transaction *transaction,
194-
std::shared_ptr<RuleMessage> rm) override;
195-
196-
void getVariablesExceptions(Transaction *t,
197-
variables::Variables *exclusion, variables::Variables *addition);
198-
inline void getFinalVars(variables::Variables *vars,
199-
variables::Variables *eclusion, Transaction *trans);
200-
201-
bool executeOperatorAt(Transaction *trasn, const std::string &key,
202-
std::string value, std::shared_ptr<RuleMessage> rm);
203-
204-
static void updateMatchedVars(Transaction *trasn, const std::string &key,
205-
const std::string &value);
206-
static void cleanMatchedVars(Transaction *trasn);
207-
208-
inline bool isUnconditional() const { return m_operator == NULL; }
209-
210-
std::string getOperatorName() const;
211-
212-
virtual std::string getReference() override {
213-
return std::to_string(m_ruleId);
214-
}
215-
216-
std::unique_ptr<RuleWithOperator> m_chainedRuleChild;
217-
RuleWithOperator *m_chainedRuleParent;
218-
219-
private:
220-
modsecurity::variables::Variables *m_variables;
221-
operators::Operator *m_operator;
222-
223-
bool m_unconditional:1;
224-
};
225-
226105
} // namespace modsecurity
227106
#endif
228107

headers/modsecurity/rule_message.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "modsecurity/transaction.h"
2828
#include "modsecurity/rule.h"
29+
#include "modsecurity/rule_with_operator.h"
2930

3031

3132
#ifdef __cplusplus
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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_WITH_ACTIONS_H_
26+
#define HEADERS_MODSECURITY_RULE_WITH_ACTIONS_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 RuleWithActions : public Rule {
39+
public:
40+
RuleWithActions(
41+
Actions *a,
42+
Transformations *t,
43+
std::unique_ptr<std::string> fileName,
44+
int lineNumber);
45+
46+
~RuleWithActions();
47+
48+
void executeAction(Transaction *trans,
49+
bool containsBlock,
50+
std::shared_ptr<RuleMessage> ruleMessage,
51+
actions::Action *a,
52+
bool context);
53+
54+
55+
void executeTransformations(
56+
Transaction *trasn, const std::string &value, TransformationResults &ret);
57+
58+
inline void executeTransformation(
59+
actions::transformations::Transformation *a,
60+
std::shared_ptr<std::string> *value,
61+
Transaction *trans,
62+
TransformationResults *ret,
63+
std::string *path,
64+
int *nth) const;
65+
66+
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
67+
bool *b, std::shared_ptr<RuleMessage> ruleMessage);
68+
void executeActionsAfterFullMatch(Transaction *trasn,
69+
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
70+
71+
std::vector<actions::Action *> getActionsByName(const std::string& name,
72+
Transaction *t);
73+
bool containsTag(const std::string& name, Transaction *t);
74+
bool containsMsg(const std::string& name, Transaction *t);
75+
76+
inline bool isChained() const { return m_isChained == true; }
77+
inline bool hasCaptureAction() const { return m_containsCaptureAction == true; }
78+
inline void setChained(bool b) { m_isChained = b; }
79+
inline bool hasDisruptiveAction() const { return m_disruptiveAction != NULL; }
80+
inline bool hasBlockAction() const { return m_containsStaticBlockAction == true; }
81+
inline bool hasMultimatch() const { return m_containsMultiMatchAction == true; }
82+
83+
inline bool hasLogData() const { return m_logData != NULL; }
84+
std::string logData(Transaction *t);
85+
inline bool hasMsg() const { return m_msg != NULL; }
86+
std::string msg(Transaction *t);
87+
inline bool hasSeverity() const { return m_severity != NULL; }
88+
int severity() const;
89+
90+
std::string m_rev;
91+
std::string m_ver;
92+
int m_accuracy;
93+
int m_maturity;
94+
95+
96+
int64_t m_ruleId;
97+
98+
private:
99+
/* actions */
100+
actions::Action *m_disruptiveAction;
101+
actions::LogData *m_logData;
102+
actions::Msg *m_msg;
103+
actions::Severity *m_severity;
104+
MatchActions m_actionsRuntimePos;
105+
SetVars m_actionsSetVar;
106+
Tags m_actionsTag;
107+
108+
/* actions > transformations */
109+
Transformations m_transformations;
110+
111+
bool m_containsCaptureAction:1;
112+
bool m_containsMultiMatchAction:1;
113+
bool m_containsStaticBlockAction:1;
114+
bool m_isChained:1;
115+
};
116+
117+
} // namespace modsecurity
118+
#endif
119+
120+
121+
#endif // HEADERS_MODSECURITY_RULE_WITH_ACTIONS_H_
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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_WITH_OPERATOR_H_
26+
#define HEADERS_MODSECURITY_RULE_WITH_OPERATOR_H_
27+
28+
#include "modsecurity/transaction.h"
29+
#include "modsecurity/modsecurity.h"
30+
#include "modsecurity/variable_value.h"
31+
#include "modsecurity/rule.h"
32+
#include "modsecurity/rule_with_actions.h"
33+
34+
#ifdef __cplusplus
35+
36+
namespace modsecurity {
37+
38+
39+
class RuleWithOperator : public RuleWithActions {
40+
public:
41+
RuleWithOperator(operators::Operator *op,
42+
variables::Variables *variables,
43+
std::vector<actions::Action *> *actions,
44+
Transformations *transformations,
45+
std::unique_ptr<std::string> fileName,
46+
int lineNumber);
47+
48+
virtual ~RuleWithOperator();
49+
50+
bool evaluate(Transaction *transaction,
51+
std::shared_ptr<RuleMessage> rm) override;
52+
53+
void getVariablesExceptions(Transaction *t,
54+
variables::Variables *exclusion, variables::Variables *addition);
55+
inline void getFinalVars(variables::Variables *vars,
56+
variables::Variables *eclusion, Transaction *trans);
57+
58+
bool executeOperatorAt(Transaction *trasn, const std::string &key,
59+
std::string value, std::shared_ptr<RuleMessage> rm);
60+
61+
static void updateMatchedVars(Transaction *trasn, const std::string &key,
62+
const std::string &value);
63+
static void cleanMatchedVars(Transaction *trasn);
64+
65+
inline bool isUnconditional() const { return m_operator == NULL; }
66+
67+
std::string getOperatorName() const;
68+
69+
virtual std::string getReference() override {
70+
return std::to_string(m_ruleId);
71+
}
72+
73+
std::unique_ptr<RuleWithOperator> m_chainedRuleChild;
74+
RuleWithOperator *m_chainedRuleParent;
75+
76+
private:
77+
modsecurity::variables::Variables *m_variables;
78+
operators::Operator *m_operator;
79+
80+
81+
bool m_unconditional:1;
82+
};
83+
84+
85+
} // namespace modsecurity
86+
#endif
87+
88+
89+
#endif // HEADERS_MODSECURITY_RULE_WITH_OPERATOR_H_

headers/modsecurity/rules.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#endif
2828

2929
#include "modsecurity/rule.h"
30+
#include "modsecurity/rule_with_operator.h"
31+
#include "modsecurity/rule_with_actions.h"
3032

3133
#ifndef HEADERS_MODSECURITY_RULES_H_
3234
#define HEADERS_MODSECURITY_RULES_H_

src/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pkginclude_HEADERS = \
4343
../headers/modsecurity/modsecurity.h \
4444
../headers/modsecurity/rule.h \
4545
../headers/modsecurity/rule_marker.h \
46+
../headers/modsecurity/rule_with_actions.h \
47+
../headers/modsecurity/rule_with_operator.h \
4648
../headers/modsecurity/rules.h \
4749
../headers/modsecurity/rule_message.h \
4850
../headers/modsecurity/rules_set.h \
@@ -283,6 +285,8 @@ libmodsecurity_la_SOURCES = \
283285
debug_log/debug_log_writer.cc \
284286
run_time_string.cc \
285287
rule.cc \
288+
rule_with_actions.cc \
289+
rule_with_operator.cc \
286290
rule_message.cc \
287291
rule_script.cc \
288292
unique_id.cc \

0 commit comments

Comments
 (0)