mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-16 17:41:52 +03:00
Cleanup on Action class
This commit is contained in:
@@ -39,35 +39,27 @@ namespace actions {
|
||||
|
||||
class Action {
|
||||
public:
|
||||
|
||||
explicit Action(const std::string& _action)
|
||||
: m_isNone(false),
|
||||
temporaryAction(false),
|
||||
action_kind(2),
|
||||
: m_actionKind(2),
|
||||
m_name(nullptr),
|
||||
m_parser_payload("") {
|
||||
set_name_and_payload(_action);
|
||||
}
|
||||
|
||||
Action(const std::string& _action, int kind)
|
||||
: m_isNone(false),
|
||||
temporaryAction(false),
|
||||
action_kind(kind),
|
||||
: m_actionKind(kind),
|
||||
m_name(nullptr),
|
||||
m_parser_payload("") {
|
||||
set_name_and_payload(_action);
|
||||
}
|
||||
|
||||
Action(const Action &a)
|
||||
: m_isNone(a.m_isNone),
|
||||
temporaryAction(a.temporaryAction),
|
||||
action_kind(a.action_kind),
|
||||
: m_actionKind(a.m_actionKind),
|
||||
m_name(a.m_name),
|
||||
m_parser_payload(a.m_parser_payload) { }
|
||||
|
||||
Action &operator=(const Action& a) {
|
||||
m_isNone = a.m_isNone;
|
||||
temporaryAction = a.temporaryAction;
|
||||
action_kind = a.action_kind;
|
||||
m_actionKind = a.m_actionKind;
|
||||
m_name = a.m_name;
|
||||
m_parser_payload = a.m_parser_payload;
|
||||
return *this;
|
||||
@@ -75,52 +67,24 @@ class Action {
|
||||
|
||||
virtual ~Action() { }
|
||||
|
||||
virtual bool init(std::string *error) { return true; }
|
||||
|
||||
virtual std::string execute(const std::string &exp,
|
||||
Transaction *transaction);
|
||||
virtual bool execute(RuleWithActions *rule, Transaction *transaction);
|
||||
|
||||
virtual bool execute(RuleWithActions *rule,
|
||||
Transaction *transaction);
|
||||
/**
|
||||
* This method is meant to be used by transformations — a particular
|
||||
* type of action.
|
||||
*
|
||||
*/
|
||||
virtual void execute(Transaction *t,
|
||||
ModSecStackString &in,
|
||||
ModSecStackString &out) {
|
||||
ModSecString &in,
|
||||
ModSecString &out) {
|
||||
};
|
||||
|
||||
virtual bool init(std::string *error) { return true; }
|
||||
virtual bool isDisruptive() { return false; }
|
||||
|
||||
|
||||
void set_name_and_payload(const std::string& data) {
|
||||
size_t pos = data.find(":");
|
||||
std::string t = "t:";
|
||||
|
||||
if (data.compare(0, t.length(), t) == 0) {
|
||||
pos = data.find(":", 2);
|
||||
}
|
||||
|
||||
if (pos == std::string::npos) {
|
||||
m_name = std::shared_ptr<std::string>(new std::string(data));
|
||||
return;
|
||||
}
|
||||
|
||||
m_name = std::shared_ptr<std::string>(new std::string(data, 0, pos));
|
||||
m_parser_payload = std::string(data, pos + 1, data.length());
|
||||
|
||||
if (m_parser_payload.at(0) == '\'' && m_parser_payload.size() > 2) {
|
||||
m_parser_payload.erase(0, 1);
|
||||
m_parser_payload.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
bool m_isNone;
|
||||
bool temporaryAction;
|
||||
int action_kind;
|
||||
std::shared_ptr<std::string> m_name;
|
||||
std::string m_parser_payload;
|
||||
|
||||
/**
|
||||
*
|
||||
* Define the action kind regarding to the execution time.
|
||||
@@ -152,7 +116,35 @@ class Action {
|
||||
*/
|
||||
RunTimeOnlyIfMatchKind,
|
||||
};
|
||||
};
|
||||
|
||||
int m_actionKind;
|
||||
std::shared_ptr<std::string> m_name;
|
||||
std::string m_parser_payload;
|
||||
|
||||
private:
|
||||
|
||||
void set_name_and_payload(const std::string& data) {
|
||||
size_t pos = data.find(":");
|
||||
std::string t = "t:";
|
||||
|
||||
if (data.compare(0, t.length(), t) == 0) {
|
||||
pos = data.find(":", 2);
|
||||
}
|
||||
|
||||
if (pos == std::string::npos) {
|
||||
m_name = std::shared_ptr<std::string>(new std::string(data));
|
||||
return;
|
||||
}
|
||||
|
||||
m_name = std::shared_ptr<std::string>(new std::string(data, 0, pos));
|
||||
m_parser_payload = std::string(data, pos + 1, data.length());
|
||||
|
||||
if (m_parser_payload.at(0) == '\'' && m_parser_payload.size() > 2) {
|
||||
m_parser_payload.erase(0, 1);
|
||||
m_parser_payload.pop_back();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace actions
|
||||
|
||||
Reference in New Issue
Block a user