Skip to content

Commit 2408006

Browse files
committed
Introduces ActionWithExecution
1 parent dd5c23d commit 2408006

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+737
-604
lines changed

headers/modsecurity/actions/action.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ class Action {
6969
return true;
7070
}
7171

72-
73-
virtual bool execute(Transaction *transaction = nullptr) noexcept {
74-
return true;
75-
}
76-
77-
7872
const std::string *getName() const noexcept {
7973
return &m_name;
8074
}

src/actions/action_type_rule_metadata.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ class ActionTypeRuleMetaData : public virtual Action {
3737
: Action()
3838
{ };
3939

40-
bool execute(Transaction *t) noexcept override {
41-
return true;
42-
}
43-
4440
virtual void configure(RuleWithActions *rule) = 0;
4541
};
4642

src/actions/action_with_execution.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 - 2020 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address [email protected].
13+
*
14+
*/
15+
16+
17+
#include "modsecurity/actions/action.h"
18+
#include "src/rule_with_actions.h"
19+
20+
#ifndef SRC_ACTIONS_ACTION_WITH_EXECUTION_H_
21+
#define SRC_ACTIONS_ACTION_WITH_EXECUTION_H_
22+
23+
24+
namespace modsecurity {
25+
namespace actions {
26+
27+
28+
class ActionWithExecution : public virtual Action {
29+
public:
30+
ActionWithExecution()
31+
: Action()
32+
{ };
33+
34+
virtual bool execute(Transaction *t) const noexcept = 0;
35+
};
36+
37+
38+
} // namespace actions
39+
} // namespace modsecurity
40+
41+
#endif // SRC_ACTIONS_ACTION_WITH_EXECUTION_H_

src/actions/ctl/audit_log_parts.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool AuditLogParts::init(std::string *error) {
5555
}
5656

5757

58-
bool AuditLogParts::execute(Transaction *transaction) noexcept {
58+
bool AuditLogParts::execute(Transaction *transaction) const noexcept {
5959
ms_dbg_a(transaction, 7, "AuditLog parts before modification: " +
6060
std::to_string(transaction->m_auditLogParts) + ".");
6161

src/actions/ctl/audit_log_parts.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_AUDIT_LOG_PARTS_H_
@@ -29,7 +30,7 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class AuditLogParts : public Action {
33+
class AuditLogParts : public ActionWithExecution {
3334
public:
3435
explicit AuditLogParts(const std::string &action)
3536
: Action(action),
@@ -38,7 +39,7 @@ class AuditLogParts : public Action {
3839

3940
bool init(std::string *error) override;
4041

41-
bool execute(Transaction *transaction) noexcept override;
42+
bool execute(Transaction *transaction) const noexcept override;
4243

4344
protected:
4445
int m_partsToModify;

src/actions/ctl/request_body_access.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool RequestBodyAccess::init(std::string *error) {
4444
}
4545

4646

47-
bool RequestBodyAccess::execute(Transaction *transaction) noexcept {
47+
bool RequestBodyAccess::execute(Transaction *transaction) const noexcept {
4848
if (m_requestBodyAccess) {
4949
transaction->m_requestBodyAccess =
5050
RulesSetProperties::TrueConfigBoolean;

src/actions/ctl/request_body_access.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_REQUEST_BODY_ACCESS_H_
@@ -29,7 +30,7 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class RequestBodyAccess : public Action {
33+
class RequestBodyAccess : public ActionWithExecution {
3334
public:
3435
explicit RequestBodyAccess(const std::string &action)
3536
: Action(action),
@@ -38,7 +39,7 @@ class RequestBodyAccess : public Action {
3839

3940
bool init(std::string *error) override;
4041

41-
bool execute(Transaction *transaction) noexcept override;
42+
bool execute(Transaction *transaction) const noexcept override;
4243

4344
private:
4445
bool m_requestBodyAccess;

src/actions/ctl/request_body_processor_json.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace actions {
2626
namespace ctl {
2727

2828

29-
bool RequestBodyProcessorJSON::execute(Transaction *transaction) noexcept {
29+
bool RequestBodyProcessorJSON::execute(Transaction *transaction) const noexcept {
3030
transaction->m_requestBodyProcessor = Transaction::JSONRequestBody;
3131
transaction->m_variableReqbodyProcessor.set("JSON",
3232
transaction->m_variableOffset);

src/actions/ctl/request_body_processor_json.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_REQUEST_BODY_PROCESSOR_JSON_H_
@@ -29,13 +30,13 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class RequestBodyProcessorJSON : public Action {
33+
class RequestBodyProcessorJSON : public ActionWithExecution {
3334
public:
3435
explicit RequestBodyProcessorJSON(const std::string &action)
3536
: Action(action)
3637
{ }
3738

38-
bool execute(Transaction *transaction) noexcept override;
39+
bool execute(Transaction *transaction) const noexcept override;
3940
};
4041

4142

src/actions/ctl/request_body_processor_urlencoded.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace ctl {
2727

2828

2929
bool RequestBodyProcessorURLENCODED::execute(
30-
Transaction *transaction) noexcept {
30+
Transaction *transaction) const noexcept {
3131
transaction->m_requestBodyType = Transaction::WWWFormUrlEncoded;
3232
transaction->m_variableReqbodyProcessor.set("URLENCODED",
3333
transaction->m_variableOffset);

src/actions/ctl/request_body_processor_urlencoded.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_REQUEST_BODY_PROCESSOR_URLENCODED_H_
@@ -29,13 +30,13 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class RequestBodyProcessorURLENCODED : public Action {
33+
class RequestBodyProcessorURLENCODED : public ActionWithExecution {
3334
public:
3435
explicit RequestBodyProcessorURLENCODED(const std::string &action)
3536
: Action(action)
3637
{ }
3738

38-
bool execute(Transaction *transaction) noexcept override;
39+
bool execute(Transaction *transaction) const noexcept override;
3940
};
4041

4142

src/actions/ctl/request_body_processor_xml.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace actions {
2626
namespace ctl {
2727

2828

29-
bool RequestBodyProcessorXML::execute(Transaction *transaction) noexcept {
29+
bool RequestBodyProcessorXML::execute(Transaction *transaction) const noexcept {
3030
transaction->m_requestBodyProcessor = Transaction::XMLRequestBody;
3131
transaction->m_variableReqbodyProcessor.set("XML",
3232
transaction->m_variableOffset);

src/actions/ctl/request_body_processor_xml.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_REQUEST_BODY_PROCESSOR_XML_H_
@@ -29,13 +30,13 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class RequestBodyProcessorXML : public Action {
33+
class RequestBodyProcessorXML : public ActionWithExecution {
3334
public:
3435
explicit RequestBodyProcessorXML(const std::string &action)
3536
: Action(action)
3637
{ }
3738

38-
bool execute(Transaction *transaction) noexcept override;
39+
bool execute(Transaction *transaction) const noexcept override;
3940
};
4041

4142

src/actions/ctl/rule_engine.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool RuleEngine::init(std::string *error) {
4747
}
4848

4949

50-
bool RuleEngine::execute(Transaction *transaction) noexcept {
50+
bool RuleEngine::execute(Transaction *transaction) const noexcept {
5151
std::stringstream a;
5252
a << "Setting SecRuleEngine to ";
5353
a << modsecurity::RulesSetProperties::ruleEngineStateString(m_ruleEngine);

src/actions/ctl/rule_engine.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/rules_set_properties.h"
2020
#include "modsecurity/actions/action.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_RULE_ENGINE_H_
@@ -29,7 +30,7 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class RuleEngine : public Action {
33+
class RuleEngine : public ActionWithExecution {
3334
public:
3435
explicit RuleEngine(const std::string &action)
3536
: Action(action),
@@ -38,7 +39,7 @@ class RuleEngine : public Action {
3839

3940
bool init(std::string *error) override;
4041

41-
bool execute(Transaction *transaction) noexcept override;
42+
bool execute(Transaction *transaction) const noexcept override;
4243

4344
private:
4445
RulesSetProperties::RuleEngine m_ruleEngine;

src/actions/ctl/rule_remove_by_id.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool RuleRemoveById::init(std::string *error) {
8888
}
8989

9090

91-
bool RuleRemoveById::execute(Transaction *transaction) noexcept {
91+
bool RuleRemoveById::execute(Transaction *transaction) const noexcept {
9292
for (auto &i : m_ids) {
9393
transaction->m_ruleRemoveById.push_back(i);
9494
}

src/actions/ctl/rule_remove_by_id.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "modsecurity/actions/action.h"
2222
#include "modsecurity/transaction.h"
23+
#include "src/actions/action_with_execution.h"
2324

2425

2526
#ifndef SRC_ACTIONS_CTL_RULE_REMOVE_BY_ID_H_
@@ -31,15 +32,15 @@ namespace actions {
3132
namespace ctl {
3233

3334

34-
class RuleRemoveById : public Action {
35+
class RuleRemoveById : public ActionWithExecution {
3536
public:
3637
explicit RuleRemoveById(const std::string &action)
3738
: Action(action)
3839
{ }
3940

4041
bool init(std::string *error) override;
4142

42-
bool execute(Transaction *transaction) noexcept override;
43+
bool execute(Transaction *transaction) const noexcept override;
4344

4445
private:
4546
std::list<std::pair<int, int> > m_ranges;

src/actions/ctl/rule_remove_by_tag.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool RuleRemoveByTag::init(std::string *error) {
3434
}
3535

3636

37-
bool RuleRemoveByTag::execute(Transaction *transaction) noexcept {
37+
bool RuleRemoveByTag::execute(Transaction *transaction) const noexcept {
3838
transaction->m_ruleRemoveByTag.push_back(m_tag);
3939
return true;
4040
}

src/actions/ctl/rule_remove_by_tag.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_RULE_REMOVE_BY_TAG_H_
@@ -29,7 +30,7 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class RuleRemoveByTag : public Action {
33+
class RuleRemoveByTag : public ActionWithExecution {
3334
public:
3435
explicit RuleRemoveByTag(const std::string &action)
3536
: Action(action),
@@ -38,7 +39,7 @@ class RuleRemoveByTag : public Action {
3839

3940
bool init(std::string *error) override;
4041

41-
bool execute(Transaction *transaction) noexcept override;
42+
bool execute(Transaction *transaction) const noexcept override;
4243

4344
private:
4445
std::string m_tag;

src/actions/ctl/rule_remove_target_by_id.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool RuleRemoveTargetById::init(std::string *error) {
5353
}
5454

5555

56-
bool RuleRemoveTargetById::execute(Transaction *transaction) noexcept {
56+
bool RuleRemoveTargetById::execute(Transaction *transaction) const noexcept {
5757
transaction->m_ruleRemoveTargetById.push_back(
5858
std::make_pair(m_id, m_target));
5959
return true;

src/actions/ctl/rule_remove_target_by_id.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "src/actions/action_with_execution.h"
2122

2223

2324
#ifndef SRC_ACTIONS_CTL_RULE_REMOVE_TARGET_BY_ID_H_
@@ -29,7 +30,7 @@ namespace actions {
2930
namespace ctl {
3031

3132

32-
class RuleRemoveTargetById : public Action {
33+
class RuleRemoveTargetById : public ActionWithExecution {
3334
public:
3435
explicit RuleRemoveTargetById(const std::string &action)
3536
: Action(action),
@@ -39,7 +40,7 @@ class RuleRemoveTargetById : public Action {
3940

4041
bool init(std::string *error) override;
4142

42-
bool execute(Transaction *transaction) noexcept override;
43+
bool execute(Transaction *transaction) const noexcept override;
4344

4445
private:
4546
int m_id;

src/actions/ctl/rule_remove_target_by_tag.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool RuleRemoveTargetByTag::init(std::string *error) {
4646
}
4747

4848

49-
bool RuleRemoveTargetByTag::execute(Transaction *transaction) noexcept {
49+
bool RuleRemoveTargetByTag::execute(Transaction *transaction) const noexcept {
5050
transaction->m_ruleRemoveTargetByTag.push_back(
5151
std::make_pair(m_tag, m_target));
5252
return true;

0 commit comments

Comments
 (0)