Skip to content

Commit a863799

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 d37d9f6 commit a863799

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

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

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

147147

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)