Skip to content

Commit 771cd8c

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 8500f8d commit 771cd8c

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
@@ -37,15 +37,47 @@ namespace actions {
3737

3838
class Action {
3939
public:
40+
/**
41+
*
42+
* Define the action kind regarding to the execution time.
43+
*
44+
*
45+
*/
46+
enum class Kind {
47+
/**
48+
*
49+
* Action that are executed while loading the configuration. For instance
50+
* the rule ID or the rule phase.
51+
*
52+
*/
53+
ConfigurationKind,
54+
/**
55+
*
56+
* Those are actions that demands to be executed before call the operator.
57+
* For instance the tranformations.
58+
*
59+
*
60+
*/
61+
RunTimeBeforeMatchAttemptKind,
62+
/**
63+
*
64+
* Actions that are executed after the execution of the operator, only if
65+
* the operator returned Match (or True). For instance the disruptive
66+
* actions.
67+
*
68+
*/
69+
RunTimeOnlyIfMatchKind,
70+
};
71+
4072
explicit Action(const std::string& _action)
4173
: m_isNone(false),
4274
temporaryAction(false),
43-
action_kind(2),
75+
action_kind(Kind::RunTimeOnlyIfMatchKind),
4476
m_name(nullptr),
4577
m_parser_payload("") {
4678
set_name_and_payload(_action);
4779
}
48-
explicit Action(const std::string& _action, int kind)
80+
explicit Action(const std::string& _action, Kind kind)
4981
: m_isNone(false),
5082
temporaryAction(false),
5183
action_kind(kind),
@@ -105,41 +137,9 @@ class Action {
105137

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

145145

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)