Skip to content

Commit 2ef14bf

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 a299c00 commit 2ef14bf

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

+35-35
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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
};

src/actions/ctl/request_body_processor_xml.h

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

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

src/actions/ctl/rule_engine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace ctl {
3131
class RuleEngine : public Action {
3232
public:
3333
explicit RuleEngine(const std::string &action)
34-
: Action(action, RunTimeOnlyIfMatchKind),
34+
: Action(action),
3535
m_ruleEngine(RulesSetProperties::PropertyNotSetRuleEngine) { }
3636

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

src/actions/ctl/rule_remove_by_id.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ctl {
3030
class RuleRemoveById : public Action {
3131
public:
3232
explicit RuleRemoveById(const std::string &action)
33-
: Action(action, RunTimeOnlyIfMatchKind) { }
33+
: Action(action) { }
3434

3535
bool init(std::string *error) override;
3636
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

src/actions/ctl/rule_remove_by_tag.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ctl {
3030
class RuleRemoveByTag : public Action {
3131
public:
3232
explicit RuleRemoveByTag(const std::string &action)
33-
: Action(action, RunTimeOnlyIfMatchKind),
33+
: Action(action),
3434
m_tag("") { }
3535

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

src/actions/ctl/rule_remove_target_by_id.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ctl {
3030
class RuleRemoveTargetById : public Action {
3131
public:
3232
explicit RuleRemoveTargetById(const std::string &action)
33-
: Action(action, RunTimeOnlyIfMatchKind),
33+
: Action(action),
3434
m_id(0),
3535
m_target("") { }
3636

src/actions/ctl/rule_remove_target_by_tag.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ctl {
3030
class RuleRemoveTargetByTag : public Action {
3131
public:
3232
explicit RuleRemoveTargetByTag(const std::string &action)
33-
: Action(action, RunTimeOnlyIfMatchKind) { }
33+
: Action(action) { }
3434

3535
bool init(std::string *error) override;
3636
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

src/actions/data/status.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace data {
3333

3434
class Status : public Action {
3535
public:
36-
explicit Status(const std::string &action) : Action(action, 2),
37-
m_status(0) { }
36+
explicit Status(const std::string &action)
37+
: Action(action), m_status(0) { }
3838

3939
bool init(std::string *error) override;
4040
bool evaluate(RuleWithActions *rule, Transaction *transaction,

src/actions/disruptive/allow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum AllowType : int {
5454
class Allow : public Action {
5555
public:
5656
explicit Allow(const std::string &action)
57-
: Action(action, RunTimeOnlyIfMatchKind),
57+
: Action(action),
5858
m_allowType(NoneAllowType) { }
5959

6060

src/actions/disruptive/redirect.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ namespace disruptive {
3737
class Redirect : public Action {
3838
public:
3939
explicit Redirect(const std::string &action)
40-
: Action(action, RunTimeOnlyIfMatchKind),
40+
: Action(action),
4141
m_status(0),
4242
m_string(nullptr) { }
4343

4444
explicit Redirect(std::unique_ptr<RunTimeString> z)
45-
: Action("redirert", RunTimeOnlyIfMatchKind),
45+
: Action("redirert"),
4646
m_status(0),
4747
m_string(std::move(z)) { }
4848

src/actions/expire_var.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ExpireVar : public Action {
3636
explicit ExpireVar(const std::string &action) : Action(action) { }
3737

3838
explicit ExpireVar(std::unique_ptr<RunTimeString> z)
39-
: Action("expirevar", RunTimeOnlyIfMatchKind),
39+
: Action("expirevar"),
4040
m_string(std::move(z)) { }
4141

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

src/actions/init_col.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class InitCol : public Action {
3535
explicit InitCol(const std::string &action) : Action(action) { }
3636

3737
InitCol(const std::string &action, std::unique_ptr<RunTimeString> z)
38-
: Action(action, RunTimeOnlyIfMatchKind),
38+
: Action(action),
3939
m_string(std::move(z)) { }
4040

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

src/actions/log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace actions {
3131
class Log : public Action {
3232
public:
3333
explicit Log(const std::string &action)
34-
: Action(action, RunTimeOnlyIfMatchKind) { }
34+
: Action(action) { }
3535

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

src/actions/log_data.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ namespace actions {
3333
class LogData : public Action {
3434
public:
3535
explicit LogData(const std::string &action)
36-
: Action(action, RunTimeOnlyIfMatchKind) { }
36+
: Action(action) { }
3737

3838
explicit LogData(std::unique_ptr<RunTimeString> z)
39-
: Action("logdata", RunTimeOnlyIfMatchKind),
39+
: Action("logdata"),
4040
m_string(std::move(z)) { }
4141

4242
bool evaluate(RuleWithActions *rule, Transaction *transaction,

src/actions/maturity.h

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

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

src/actions/msg.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ namespace actions {
3434
class Msg : public Action {
3535
public:
3636
explicit Msg(const std::string &action)
37-
: Action(action, RunTimeOnlyIfMatchKind) { }
37+
: Action(action) { }
3838

3939
explicit Msg(std::unique_ptr<RunTimeString> z)
40-
: Action("msg", RunTimeOnlyIfMatchKind),
40+
: Action("msg"),
4141
m_string(std::move(z)) { }
4242

4343
bool evaluate(RuleWithActions *rule, Transaction *transaction,

src/actions/multi_match.h

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

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

src/actions/no_audit_log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace actions {
3333
class NoAuditLog : public Action {
3434
public:
3535
explicit NoAuditLog(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/no_log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace actions {
3131
class NoLog : public Action {
3232
public:
3333
explicit NoLog(const std::string &action)
34-
: Action(action, RunTimeOnlyIfMatchKind) { }
34+
: Action(action) { }
3535

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

src/actions/phase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace actions {
3232

3333
class Phase : public Action {
3434
public:
35-
explicit Phase(const std::string &action) : Action(action, ConfigurationKind),
35+
explicit Phase(const std::string &action) : Action(action, Kind::ConfigurationKind),
3636
m_phase(0),
3737
m_secRulesPhase(0) { }
3838

src/actions/rev.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace actions {
2929

3030
class Rev : public Action {
3131
public:
32-
explicit Rev(const std::string &action) : Action(action, ConfigurationKind) { }
32+
explicit Rev(const std::string &action) : Action(action, Kind::ConfigurationKind) { }
3333

3434
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
3535
bool init(std::string *error) override;

src/actions/rule_id.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace actions {
3333
class RuleId : public Action {
3434
public:
3535
explicit RuleId(const std::string &action)
36-
: Action(action, ConfigurationKind),
36+
: Action(action, Kind::ConfigurationKind),
3737
m_ruleId(0) { }
3838

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

src/actions/set_env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SetENV : public Action {
3636
: Action(_action) { }
3737

3838
explicit SetENV(std::unique_ptr<RunTimeString> z)
39-
: Action("setenv", RunTimeOnlyIfMatchKind),
39+
: Action("setenv"),
4040
m_string(std::move(z)) { }
4141

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

src/actions/set_rsc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SetRSC : public Action {
3636
: Action(_action) { }
3737

3838
explicit SetRSC(std::unique_ptr<RunTimeString> z)
39-
: Action("setsrc", RunTimeOnlyIfMatchKind),
39+
: Action("setsrc"),
4040
m_string(std::move(z)) { }
4141

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

0 commit comments

Comments
 (0)