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)
This commit is contained in:
Eduardo Arias 2024-08-19 11:26:56 -07:00
parent 7023c0a8b4
commit 2f5dac5c4c
96 changed files with 131 additions and 237 deletions

View File

@ -32,15 +32,47 @@ namespace actions {
class Action {
public:
/**
*
* Define the action kind regarding to the execution time.
*
*
*/
enum class Kind {
/**
*
* Action that are executed while loading the configuration. For instance
* the rule ID or the rule phase.
*
*/
ConfigurationKind,
/**
*
* Those are actions that demands to be executed before call the operator.
* For instance the tranformations.
*
*
*/
RunTimeBeforeMatchAttemptKind,
/**
*
* Actions that are executed after the execution of the operator, only if
* the operator returned Match (or True). For instance the disruptive
* actions.
*
*/
RunTimeOnlyIfMatchKind,
};
explicit Action(const std::string& _action)
: m_isNone(false),
temporaryAction(false),
action_kind(2),
action_kind(Kind::RunTimeOnlyIfMatchKind),
m_name(nullptr),
m_parser_payload("") {
set_name_and_payload(_action);
}
explicit Action(const std::string& _action, int kind)
explicit Action(const std::string& _action, Kind kind)
: m_isNone(false),
temporaryAction(false),
action_kind(kind),
@ -100,41 +132,9 @@ class Action {
bool m_isNone;
bool temporaryAction;
int action_kind;
Kind action_kind;
std::shared_ptr<std::string> m_name;
std::string m_parser_payload;
/**
*
* Define the action kind regarding to the execution time.
*
*
*/
enum Kind {
/**
*
* Action that are executed while loading the configuration. For instance
* the rule ID or the rule phase.
*
*/
ConfigurationKind,
/**
*
* Those are actions that demands to be executed before call the operator.
* For instance the tranformations.
*
*
*/
RunTimeBeforeMatchAttemptKind,
/**
*
* Actions that are executed after the execution of the operator, only if
* the operator returned Match (or True). For instance the disruptive
* actions.
*
*/
RunTimeOnlyIfMatchKind,
};
};

View File

@ -30,7 +30,7 @@ namespace actions {
class Accuracy : public Action {
public:
explicit Accuracy(const std::string &action)
: Action(action, ConfigurationKind),
: Action(action, Kind::ConfigurationKind),
m_accuracy(0) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -33,7 +33,7 @@ namespace actions {
class AuditLog : public Action {
public:
explicit AuditLog(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) override;

View File

@ -29,7 +29,7 @@ namespace actions {
class Capture : public Action {
public:
explicit Capture(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
};

View File

@ -33,7 +33,7 @@ namespace actions {
class Chain : public Action {
public:
explicit Chain(const std::string &action)
: Action(action, ConfigurationKind) { }
: Action(action, Kind::ConfigurationKind) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
};

View File

@ -34,7 +34,7 @@ namespace ctl {
class AuditEngine : public Action {
public:
explicit AuditEngine(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_auditEngine(audit_log::AuditLog::AuditLogStatus::NotSetLogStatus) { }
bool init(std::string *error) override;

View File

@ -29,7 +29,7 @@ namespace ctl {
class AuditLogParts : public Action {
public:
explicit AuditLogParts(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
mPartsAction(0),
mParts("") { }

View File

@ -30,7 +30,7 @@ namespace ctl {
class RequestBodyAccess : public Action {
public:
explicit RequestBodyAccess(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_request_body_access(false) { }
bool init(std::string *error) override;

View File

@ -29,7 +29,7 @@ namespace ctl {
class RequestBodyProcessorJSON : public Action {
public:
explicit RequestBodyProcessorJSON(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
};

View File

@ -29,7 +29,7 @@ namespace ctl {
class RequestBodyProcessorURLENCODED : public Action {
public:
explicit RequestBodyProcessorURLENCODED(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
};

View File

@ -29,7 +29,7 @@ namespace ctl {
class RequestBodyProcessorXML : public Action {
public:
explicit RequestBodyProcessorXML(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
};

View File

@ -31,7 +31,7 @@ namespace ctl {
class RuleEngine : public Action {
public:
explicit RuleEngine(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_ruleEngine(RulesSetProperties::PropertyNotSetRuleEngine) { }
bool init(std::string *error) override;

View File

@ -30,7 +30,7 @@ namespace ctl {
class RuleRemoveById : public Action {
public:
explicit RuleRemoveById(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool init(std::string *error) override;
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -30,7 +30,7 @@ namespace ctl {
class RuleRemoveByTag : public Action {
public:
explicit RuleRemoveByTag(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_tag("") { }
bool init(std::string *error) override;

View File

@ -30,7 +30,7 @@ namespace ctl {
class RuleRemoveTargetById : public Action {
public:
explicit RuleRemoveTargetById(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_id(0),
m_target("") { }

View File

@ -30,7 +30,7 @@ namespace ctl {
class RuleRemoveTargetByTag : public Action {
public:
explicit RuleRemoveTargetByTag(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool init(std::string *error) override;
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -33,8 +33,8 @@ namespace data {
class Status : public Action {
public:
explicit Status(const std::string &action) : Action(action, 2),
m_status(0) { }
explicit Status(const std::string &action)
: Action(action), m_status(0) { }
bool init(std::string *error) override;
bool evaluate(RuleWithActions *rule, Transaction *transaction,

View File

@ -54,7 +54,7 @@ enum AllowType : int {
class Allow : public Action {
public:
explicit Allow(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_allowType(NoneAllowType) { }

View File

@ -37,12 +37,12 @@ namespace disruptive {
class Redirect : public Action {
public:
explicit Redirect(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_status(0),
m_string(nullptr) { }
explicit Redirect(std::unique_ptr<RunTimeString> z)
: Action("redirert", RunTimeOnlyIfMatchKind),
: Action("redirert"),
m_status(0),
m_string(std::move(z)) { }

View File

@ -36,7 +36,7 @@ class ExpireVar : public Action {
explicit ExpireVar(const std::string &action) : Action(action) { }
explicit ExpireVar(std::unique_ptr<RunTimeString> z)
: Action("expirevar", RunTimeOnlyIfMatchKind),
: Action("expirevar"),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -35,7 +35,7 @@ class InitCol : public Action {
explicit InitCol(const std::string &action) : Action(action) { }
InitCol(const std::string &action, std::unique_ptr<RunTimeString> z)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -31,7 +31,7 @@ namespace actions {
class Log : public Action {
public:
explicit Log(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) override;

View File

@ -33,10 +33,10 @@ namespace actions {
class LogData : public Action {
public:
explicit LogData(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
explicit LogData(std::unique_ptr<RunTimeString> z)
: Action("logdata", RunTimeOnlyIfMatchKind),
: Action("logdata"),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction,

View File

@ -30,7 +30,7 @@ namespace actions {
class Maturity : public Action {
public:
explicit Maturity(const std::string &action)
: Action(action, ConfigurationKind),
: Action(action, Kind::ConfigurationKind),
m_maturity(0) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -34,10 +34,10 @@ namespace actions {
class Msg : public Action {
public:
explicit Msg(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
explicit Msg(std::unique_ptr<RunTimeString> z)
: Action("msg", RunTimeOnlyIfMatchKind),
: Action("msg"),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction,

View File

@ -33,7 +33,7 @@ namespace actions {
class MultiMatch : public Action {
public:
explicit MultiMatch(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
};

View File

@ -33,7 +33,7 @@ namespace actions {
class NoAuditLog : public Action {
public:
explicit NoAuditLog(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) override;

View File

@ -31,7 +31,7 @@ namespace actions {
class NoLog : public Action {
public:
explicit NoLog(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind) { }
: Action(action) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) override;

View File

@ -32,7 +32,7 @@ namespace actions {
class Phase : public Action {
public:
explicit Phase(const std::string &action) : Action(action, ConfigurationKind),
explicit Phase(const std::string &action) : Action(action, Kind::ConfigurationKind),
m_phase(0),
m_secRulesPhase(0) { }

View File

@ -29,7 +29,7 @@ namespace actions {
class Rev : public Action {
public:
explicit Rev(const std::string &action) : Action(action, ConfigurationKind) { }
explicit Rev(const std::string &action) : Action(action, Kind::ConfigurationKind) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
bool init(std::string *error) override;

View File

@ -33,7 +33,7 @@ namespace actions {
class RuleId : public Action {
public:
explicit RuleId(const std::string &action)
: Action(action, ConfigurationKind),
: Action(action, Kind::ConfigurationKind),
m_ruleId(0) { }
bool init(std::string *error) override;

View File

@ -36,7 +36,7 @@ class SetENV : public Action {
: Action(_action) { }
explicit SetENV(std::unique_ptr<RunTimeString> z)
: Action("setenv", RunTimeOnlyIfMatchKind),
: Action("setenv"),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -36,7 +36,7 @@ class SetRSC : public Action {
: Action(_action) { }
explicit SetRSC(std::unique_ptr<RunTimeString> z)
: Action("setsrc", RunTimeOnlyIfMatchKind),
: Action("setsrc"),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -36,7 +36,7 @@ class SetSID : public Action {
: Action(_action) { }
explicit SetSID(std::unique_ptr<RunTimeString> z)
: Action("setsid", RunTimeOnlyIfMatchKind),
: Action("setsid"),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -36,7 +36,7 @@ class SetUID : public Action {
: Action(_action) { }
explicit SetUID(std::unique_ptr<RunTimeString> z)
: Action("setuid", RunTimeOnlyIfMatchKind),
: Action("setuid"),
m_string(std::move(z)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -30,7 +30,7 @@ namespace actions {
class Skip : public Action {
public:
explicit Skip(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_skip_next(0) { }
bool init(std::string *error) override;

View File

@ -31,7 +31,7 @@ namespace actions {
class SkipAfter : public Action {
public:
explicit SkipAfter(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
: Action(action),
m_skipName(std::make_shared<std::string>(m_parser_payload)) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -33,7 +33,7 @@ namespace actions {
class Tag : public Action {
public:
explicit Tag(std::unique_ptr<RunTimeString> z)
: Action("tag", RunTimeOnlyIfMatchKind),
: Action("tag"),
m_string(std::move(z)) { }
std::string getName(Transaction *transaction);

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class Base64Decode : public Transformation {
public:
explicit Base64Decode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class Base64DecodeExt : public Transformation {
public:
explicit Base64DecodeExt(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class Base64Encode : public Transformation {
public:
explicit Base64Encode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class CmdLine : public Transformation {
public:
explicit CmdLine(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -19,11 +19,6 @@
namespace modsecurity::actions::transformations {
CompressWhitespace::CompressWhitespace(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool CompressWhitespace::transform(std::string &value, const Transaction *trans) const {
bool inWhiteSpace = false;

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class CompressWhitespace : public Transformation {
public:
explicit CompressWhitespace(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class CssDecode : public Transformation {
public:
explicit CssDecode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -20,12 +20,6 @@
namespace modsecurity::actions::transformations {
EscapeSeqDecode::EscapeSeqDecode(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
static inline int ansi_c_sequences_decode_inplace(std::string &value) {
auto d = reinterpret_cast<unsigned char *>(value.data());
const unsigned char* input = d;

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class EscapeSeqDecode : public Transformation {
public:
explicit EscapeSeqDecode(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class HexDecode : public Transformation {
public:
explicit HexDecode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -20,10 +20,6 @@
namespace modsecurity::actions::transformations {
HexEncode::HexEncode(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool HexEncode::transform(std::string &value, const Transaction *trans) const {
if (value.empty()) return false;

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class HexEncode : public Transformation {
public:
explicit HexEncode(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class HtmlEntityDecode : public Transformation {
public:
explicit HtmlEntityDecode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class JsDecode : public Transformation {
public:
explicit JsDecode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -19,11 +19,6 @@
namespace modsecurity::actions::transformations {
Length::Length(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool Length::transform(std::string &value, const Transaction *trans) const {
value = std::to_string(value.size());
return true;

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class Length : public Transformation {
public:
explicit Length(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,10 +22,6 @@
namespace modsecurity::actions::transformations {
LowerCase::LowerCase(const std::string &a)
: Transformation(a) {
}
bool LowerCase::transform(std::string &value, const Transaction *trans) const {
return convert(value, [](auto c) {
return std::tolower(c); });

View File

@ -24,7 +24,7 @@ namespace modsecurity::actions::transformations {
class LowerCase : public Transformation {
public:
explicit LowerCase(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class Md5 : public Transformation {
public:
explicit Md5(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -19,11 +19,6 @@
namespace modsecurity::actions::transformations {
NormalisePath::NormalisePath(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool NormalisePath::transform(std::string &value, const Transaction *trans) const {
return normalize_path_inplace(value, false);
}

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class NormalisePath : public Transformation {
public:
explicit NormalisePath(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class NormalisePathWin : public Transformation {
public:
explicit NormalisePathWin(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class ParityEven7bit : public Transformation {
public:
explicit ParityEven7bit(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class ParityOdd7bit : public Transformation {
public:
explicit ParityOdd7bit(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class ParityZero7bit : public Transformation {
public:
explicit ParityZero7bit(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class RemoveComments : public Transformation {
public:
explicit RemoveComments(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -18,10 +18,6 @@
namespace modsecurity::actions::transformations {
RemoveCommentsChar::RemoveCommentsChar(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool RemoveCommentsChar::transform(std::string &value, const Transaction *trans) const {
char *d = value.data();

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class RemoveCommentsChar : public Transformation {
public:
explicit RemoveCommentsChar(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -24,8 +24,7 @@ namespace modsecurity::actions::transformations {
class RemoveNulls : public Transformation {
public:
explicit RemoveNulls(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;

View File

@ -20,11 +20,6 @@
namespace modsecurity::actions::transformations {
RemoveWhitespace::RemoveWhitespace(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool RemoveWhitespace::transform(std::string &value, const Transaction *trans) const {
const char nonBreakingSpaces = 0xa0;
const char nonBreakingSpaces2 = 0xc2;

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class RemoveWhitespace : public Transformation {
public:
explicit RemoveWhitespace(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -59,12 +59,6 @@ static inline bool inplace(std::string &value) {
}
ReplaceComments::ReplaceComments(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool ReplaceComments::transform(std::string &value, const Transaction *trans) const {
return inplace(value);
}

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class ReplaceComments : public Transformation {
public:
explicit ReplaceComments(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -18,10 +18,6 @@
namespace modsecurity::actions::transformations {
ReplaceNulls::ReplaceNulls(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool ReplaceNulls::transform(std::string &value, const Transaction *trans) const {
bool changed = false;

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class ReplaceNulls : public Transformation {
public:
explicit ReplaceNulls(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -20,14 +20,11 @@
namespace modsecurity::actions::transformations {
Sha1::Sha1(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool Sha1::transform(std::string &value, const Transaction *trans) const {
value = Utils::Sha1::digest(value);
return true;
}
} // namespace modsecurity::actions::transformations

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class Sha1 : public Transformation {
public:
explicit Sha1(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class SqlHexDecode : public Transformation {
public:
explicit SqlHexDecode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -23,10 +23,7 @@ namespace modsecurity::actions::transformations {
class Transformation : public Action {
public:
explicit Transformation(const std::string& _action)
: Action(_action, RunTimeBeforeMatchAttemptKind) { }
explicit Transformation(const std::string& _action, int kind)
: Action(_action, kind) { }
: Action(_action, Kind::RunTimeBeforeMatchAttemptKind) { }
static Transformation* instantiate(std::string a);

View File

@ -55,12 +55,6 @@ bool Trim::trim(std::string &s) {
}
Trim::Trim(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool Trim::transform(std::string &value, const Transaction *trans) const {
return trim(value);
}

View File

@ -22,12 +22,10 @@ namespace modsecurity::actions::transformations {
class Trim : public Transformation {
public:
explicit Trim(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
protected:
static bool ltrim(std::string &s);
static bool rtrim(std::string &s);
static bool trim(std::string &s);

View File

@ -14,19 +14,14 @@
*/
#include "trim_left.h"
#include "trim.h"
namespace modsecurity::actions::transformations {
TrimLeft::TrimLeft(const std::string &action)
: Trim(action) {
this->action_kind = 1;
}
bool TrimLeft::transform(std::string &value, const Transaction *trans) const {
return ltrim(value);
return Trim::ltrim(value);
}

View File

@ -17,13 +17,12 @@
#define SRC_ACTIONS_TRANSFORMATIONS_TRIM_LEFT_H_
#include "transformation.h"
#include "trim.h"
namespace modsecurity::actions::transformations {
class TrimLeft : public Trim {
class TrimLeft : public Transformation {
public:
explicit TrimLeft(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -14,18 +14,14 @@
*/
#include "trim_right.h"
#include "trim.h"
namespace modsecurity::actions::transformations {
TrimRight::TrimRight(const std::string &action)
: Trim(action) {
this->action_kind = 1;
}
bool TrimRight::transform(std::string &value, const Transaction *trans) const {
return rtrim(value);
return Trim::rtrim(value);
}

View File

@ -17,13 +17,12 @@
#define SRC_ACTIONS_TRANSFORMATIONS_TRIM_RIGHT_H_
#include "transformation.h"
#include "trim.h"
namespace modsecurity::actions::transformations {
class TrimRight : public Trim {
class TrimRight : public Transformation {
public:
explicit TrimRight(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -24,10 +24,6 @@
namespace modsecurity::actions::transformations {
UpperCase::UpperCase(const std::string &a)
: Transformation(a) {
}
bool UpperCase::transform(std::string &value, const Transaction *trans) const {
return LowerCase::convert(value, [](auto c)
{ return std::toupper(c); });

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class UpperCase : public Transformation {
public:
explicit UpperCase(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -21,11 +21,6 @@
namespace modsecurity::actions::transformations {
UrlDecode::UrlDecode(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
bool UrlDecode::transform(std::string &value, const Transaction *trans) const {
int invalid_count;
return utils::urldecode_nonstrict_inplace(value, invalid_count);

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class UrlDecode : public Transformation {
public:
explicit UrlDecode(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class UrlDecodeUni : public Transformation {
public:
explicit UrlDecodeUni(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -20,12 +20,6 @@
namespace modsecurity::actions::transformations {
UrlEncode::UrlEncode(const std::string &action)
: Transformation(action) {
this->action_kind = 1;
}
static inline bool url_enc(std::string &value) {
const auto len = value.size() * 3 + 1;
std::string ret(len, {});

View File

@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
class UrlEncode : public Transformation {
public:
explicit UrlEncode(const std::string &action);
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations {
class Utf8ToUnicode : public Transformation {
public:
explicit Utf8ToUnicode(const std::string &action)
: Transformation(action) { }
using Transformation::Transformation;
bool transform(std::string &value, const Transaction *trans) const override;
};

View File

@ -29,7 +29,7 @@ namespace actions {
class Ver : public Action {
public:
explicit Ver(const std::string &action) : Action(action, ConfigurationKind) { }
explicit Ver(const std::string &action) : Action(action, Kind::ConfigurationKind) { }
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;

View File

@ -2424,8 +2424,8 @@ namespace yy {
definedPhase = phase->m_phase;
secRuleDefinedPhase = phase->m_secRulesPhase;
delete phase;
} else if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind ||
a->action_kind == actions::Action::RunTimeBeforeMatchAttemptKind) {
} else if (a->action_kind == actions::Action::Kind::RunTimeOnlyIfMatchKind ||
a->action_kind == actions::Action::Kind::RunTimeBeforeMatchAttemptKind) {
actions::transformations::None *none = dynamic_cast<actions::transformations::None *>(a);
if (none != NULL) {
driver.error(yystack_[2].location, "The transformation none is not suitable to be part of the SecDefaultActions");

View File

@ -1199,8 +1199,8 @@ expression:
definedPhase = phase->m_phase;
secRuleDefinedPhase = phase->m_secRulesPhase;
delete phase;
} else if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind ||
a->action_kind == actions::Action::RunTimeBeforeMatchAttemptKind) {
} else if (a->action_kind == actions::Action::Kind::RunTimeOnlyIfMatchKind ||
a->action_kind == actions::Action::Kind::RunTimeBeforeMatchAttemptKind) {
actions::transformations::None *none = dynamic_cast<actions::transformations::None *>(a);
if (none != NULL) {
driver.error(@0, "The transformation none is not suitable to be part of the SecDefaultActions");

View File

@ -89,11 +89,11 @@ RuleWithActions::RuleWithActions(
if (actions) {
for (Action *a : *actions) {
switch (a->action_kind) {
case Action::ConfigurationKind:
case Action::Kind::ConfigurationKind:
a->evaluate(this, NULL);
delete a;
break;
case Action::RunTimeOnlyIfMatchKind:
case Action::Kind::RunTimeOnlyIfMatchKind:
if (dynamic_cast<actions::Capture *>(a)) {
m_containsCaptureAction = true;
delete a;
@ -247,7 +247,7 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans,
bool disruptiveAlreadyExecuted = false;
for (const auto &a : trans->m_rules->m_defaultActions[getPhase()]) { // cppcheck-suppress ctunullpointer
if (a.get()->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
if (a.get()->action_kind != actions::Action::Kind::RunTimeOnlyIfMatchKind) {
continue;
}
if (!a.get()->isDisruptive()) {
@ -374,7 +374,7 @@ void RuleWithActions::executeTransformations(
if (none == 0) {
for (auto &a : trans->m_rules->m_defaultActions[getPhase()]) {
if (a->action_kind \
!= actions::Action::RunTimeBeforeMatchAttemptKind) {
!= actions::Action::Kind::RunTimeBeforeMatchAttemptKind) {
continue;
}

View File

@ -36,15 +36,15 @@ bool RulesExceptions::loadUpdateActionById(double id,
std::string *error) {
for (auto &a : *actions) {
if (a->action_kind == actions::Action::ConfigurationKind) {
if (a->action_kind == actions::Action::Kind::ConfigurationKind) {
std::cout << "General failure, action: " << a->m_name;
std::cout << " has not expected to be used with UpdateActionByID.";
std::cout << std::endl;
} else if (a->action_kind
== actions::Action::RunTimeBeforeMatchAttemptKind) {
== actions::Action::Kind::RunTimeBeforeMatchAttemptKind) {
m_action_pre_update_target_by_id.emplace(std::pair<double,
std::unique_ptr<actions::Action>>(id , std::move(a)));
} else if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind) {
} else if (a->action_kind == actions::Action::Kind::RunTimeOnlyIfMatchKind) {
m_action_pos_update_target_by_id.emplace(std::pair<double,
std::unique_ptr<actions::Action>>(id , std::move(a)));
} else {