Skip to content

Commit 2f5dac5

Browse files
committed
Simplified initialization of Transformation's action_kind
- Some of the Transformation classes would initialize their Action's action_kind using the default (using Transformation constructor without an action_kind parameter). - Others, however, would use that constructor and initialize action_kind manually in their constructor, but setting the default value (RunTimeBeforeMatchAttemptKind = 1), which was redundant. - Removed unused Transformation constructor to specify action_kind. - Converted Action::Kind into an 'enum class' to require using the enum constants (instead of integer values, which are difficult to track in the codebase and change)
1 parent 7023c0a commit 2f5dac5

File tree

96 files changed

+131
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+131
-237
lines changed

headers/modsecurity/actions/action.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,47 @@ namespace actions {
3232

3333
class Action {
3434
public:
35+
/**
36+
*
37+
* Define the action kind regarding to the execution time.
38+
*
39+
*
40+
*/
41+
enum class Kind {
42+
/**
43+
*
44+
* Action that are executed while loading the configuration. For instance
45+
* the rule ID or the rule phase.
46+
*
47+
*/
48+
ConfigurationKind,
49+
/**
50+
*
51+
* Those are actions that demands to be executed before call the operator.
52+
* For instance the tranformations.
53+
*
54+
*
55+
*/
56+
RunTimeBeforeMatchAttemptKind,
57+
/**
58+
*
59+
* Actions that are executed after the execution of the operator, only if
60+
* the operator returned Match (or True). For instance the disruptive
61+
* actions.
62+
*
63+
*/
64+
RunTimeOnlyIfMatchKind,
65+
};
66+
3567
explicit Action(const std::string& _action)
3668
: m_isNone(false),
3769
temporaryAction(false),
38-
action_kind(2),
70+
action_kind(Kind::RunTimeOnlyIfMatchKind),
3971
m_name(nullptr),
4072
m_parser_payload("") {
4173
set_name_and_payload(_action);
4274
}
43-
explicit Action(const std::string& _action, int kind)
75+
explicit Action(const std::string& _action, Kind kind)
4476
: m_isNone(false),
4577
temporaryAction(false),
4678
action_kind(kind),
@@ -100,41 +132,9 @@ class Action {
100132

101133
bool m_isNone;
102134
bool temporaryAction;
103-
int action_kind;
135+
Kind action_kind;
104136
std::shared_ptr<std::string> m_name;
105137
std::string m_parser_payload;
106-
107-
/**
108-
*
109-
* Define the action kind regarding to the execution time.
110-
*
111-
*
112-
*/
113-
enum Kind {
114-
/**
115-
*
116-
* Action that are executed while loading the configuration. For instance
117-
* the rule ID or the rule phase.
118-
*
119-
*/
120-
ConfigurationKind,
121-
/**
122-
*
123-
* Those are actions that demands to be executed before call the operator.
124-
* For instance the tranformations.
125-
*
126-
*
127-
*/
128-
RunTimeBeforeMatchAttemptKind,
129-
/**
130-
*
131-
* Actions that are executed after the execution of the operator, only if
132-
* the operator returned Match (or True). For instance the disruptive
133-
* actions.
134-
*
135-
*/
136-
RunTimeOnlyIfMatchKind,
137-
};
138138
};
139139

140140

src/actions/accuracy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace actions {
3030
class Accuracy : public Action {
3131
public:
3232
explicit Accuracy(const std::string &action)
33-
: Action(action, ConfigurationKind),
33+
: Action(action, Kind::ConfigurationKind),
3434
m_accuracy(0) { }
3535

3636
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

src/actions/audit_log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace actions {
3333
class AuditLog : public Action {
3434
public:
3535
explicit AuditLog(const std::string &action)
36-
: Action(action, RunTimeOnlyIfMatchKind) { }
36+
: Action(action) { }
3737

3838
bool evaluate(RuleWithActions *rule, Transaction *transaction,
3939
std::shared_ptr<RuleMessage> rm) override;

src/actions/capture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace actions {
2929
class Capture : public Action {
3030
public:
3131
explicit Capture(const std::string &action)
32-
: Action(action, RunTimeOnlyIfMatchKind) { }
32+
: Action(action) { }
3333

3434
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
3535
};

src/actions/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace actions {
3333
class Chain : public Action {
3434
public:
3535
explicit Chain(const std::string &action)
36-
: Action(action, ConfigurationKind) { }
36+
: Action(action, Kind::ConfigurationKind) { }
3737

3838
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
3939
};

src/actions/ctl/audit_engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace ctl {
3434
class AuditEngine : public Action {
3535
public:
3636
explicit AuditEngine(const std::string &action)
37-
: Action(action, RunTimeOnlyIfMatchKind),
37+
: Action(action),
3838
m_auditEngine(audit_log::AuditLog::AuditLogStatus::NotSetLogStatus) { }
3939

4040
bool init(std::string *error) override;

src/actions/ctl/audit_log_parts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ctl {
2929
class AuditLogParts : public Action {
3030
public:
3131
explicit AuditLogParts(const std::string &action)
32-
: Action(action, RunTimeOnlyIfMatchKind),
32+
: Action(action),
3333
mPartsAction(0),
3434
mParts("") { }
3535

src/actions/ctl/request_body_access.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ctl {
3030
class RequestBodyAccess : public Action {
3131
public:
3232
explicit RequestBodyAccess(const std::string &action)
33-
: Action(action, RunTimeOnlyIfMatchKind),
33+
: Action(action),
3434
m_request_body_access(false) { }
3535

3636
bool init(std::string *error) override;

src/actions/ctl/request_body_processor_json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ctl {
2929
class RequestBodyProcessorJSON : public Action {
3030
public:
3131
explicit RequestBodyProcessorJSON(const std::string &action)
32-
: Action(action, RunTimeOnlyIfMatchKind) { }
32+
: Action(action) { }
3333

3434
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
3535
};

src/actions/ctl/request_body_processor_urlencoded.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ctl {
2929
class RequestBodyProcessorURLENCODED : public Action {
3030
public:
3131
explicit RequestBodyProcessorURLENCODED(const std::string &action)
32-
: Action(action, RunTimeOnlyIfMatchKind) { }
32+
: Action(action) { }
3333

3434
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
3535
};

0 commit comments

Comments
 (0)