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

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
@@ -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

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