Skip to content

Commit

Permalink
Refactoring: Renames RuleBase to Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmerle committed Mar 31, 2020
1 parent 59d4268 commit bdedfd2
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions headers/modsecurity/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ using Tags = std::vector<actions::Tag *>;
using SetVars = std::vector<actions::SetVar *>;
using MatchActions = std::vector<actions::Action *>;

class RuleBase {
class Rule {
public:
RuleBase(std::unique_ptr<std::string> fileName, int lineNumber)
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
: m_fileName(std::move(fileName)),
m_lineNumber(lineNumber),
m_phase(modsecurity::Phases::RequestHeadersPhase) {
Expand Down Expand Up @@ -103,13 +103,13 @@ class RuleBase {
};


class RuleMarker : public RuleBase {
class RuleMarker : public Rule {
public:
RuleMarker(
const std::string &name,
std::unique_ptr<std::string> fileName,
int lineNumber)
: RuleBase(std::move(fileName), lineNumber),
: Rule(std::move(fileName), lineNumber),
m_name(std::make_shared<std::string>(name)) { }


Expand Down Expand Up @@ -139,7 +139,7 @@ class RuleMarker : public RuleBase {
};


class RuleWithActions : public RuleBase {
class RuleWithActions : public Rule {
public:
RuleWithActions(
Actions *a,
Expand Down
10 changes: 5 additions & 5 deletions headers/modsecurity/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class Rules {
return j;
}

bool insert(std::shared_ptr<RuleBase> rule) {
bool insert(std::shared_ptr<Rule> rule) {
return insert(rule, nullptr, nullptr);
}

bool insert(std::shared_ptr<RuleBase> rule, const std::vector<int64_t> *ids, std::ostringstream *err) {
bool insert(std::shared_ptr<Rule> rule, const std::vector<int64_t> *ids, std::ostringstream *err) {
RuleWithOperator *r = dynamic_cast<RuleWithOperator *>(rule.get());
if (r && ids != nullptr && std::binary_search(ids->begin(), ids->end(), r->m_ruleId)) {
if (err != nullptr) {
Expand All @@ -79,10 +79,10 @@ class Rules {
}

size_t size() const { return m_rules.size(); }
std::shared_ptr<RuleBase> operator[](int index) const { return m_rules[index]; }
std::shared_ptr<RuleBase> at(int index) const { return m_rules[index]; }
std::shared_ptr<Rule> operator[](int index) const { return m_rules[index]; }
std::shared_ptr<Rule> at(int index) const { return m_rules[index]; }

std::vector<std::shared_ptr<RuleBase> > m_rules;
std::vector<std::shared_ptr<Rule> > m_rules;
};


Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/rules_set_phases.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Driver;
class RulesSetPhases {
public:

bool insert(std::shared_ptr<RuleBase> rule);
bool insert(std::shared_ptr<Rule> rule);

int append(RulesSetPhases *from, std::ostringstream *err);
void dump() const;
Expand Down
2 changes: 1 addition & 1 deletion src/rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ RuleWithActions::RuleWithActions(
Transformations *transformations,
std::unique_ptr<std::string> fileName,
int lineNumber)
: RuleBase(std::move(fileName), lineNumber),
: Rule(std::move(fileName), lineNumber),
m_rev(""),
m_ver(""),
m_accuracy(0),
Expand Down
4 changes: 2 additions & 2 deletions src/rules_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int RulesSet::evaluate(int phase, Transaction *t) {
for (int i = 0; i < rules->size(); i++) {
// FIXME: This is not meant to be here. At the end of this refactoring,
// the shared pointer won't be used.
std::shared_ptr<RuleBase> rule = rules->at(i);
std::shared_ptr<Rule> rule = rules->at(i);
if (t->isInsideAMarker() && !rule->isMarker()) {
ms_dbg_a(t, 9, "Skipped rule id '" + rule->getReference() \
+ "' due to a SecMarker: " + *t->getCurrentMarker());
Expand All @@ -152,7 +152,7 @@ int RulesSet::evaluate(int phase, Transaction *t) {
ms_dbg_a(t, 9, "Skipped rule id '" + rule->getReference() \
+ "' as request trough the utilization of an `allow' action.");
} else {
RuleBase *base = rule.get();
Rule *base = rule.get();
RuleWithOperator *ruleWithOperator = dynamic_cast<RuleWithOperator *>(base);
if (m_exceptions.contains(ruleWithOperator->m_ruleId)) {
ms_dbg_a(t, 9, "Skipped rule id '" + rule->getReference() \
Expand Down
2 changes: 1 addition & 1 deletion src/rules_set_phases.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace modsecurity {


bool RulesSetPhases::insert(std::shared_ptr<RuleBase> rule) {
bool RulesSetPhases::insert(std::shared_ptr<Rule> rule) {
if (rule->getPhase() >= modsecurity::Phases::NUMBER_OF_PHASES) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/run_time_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::string RunTimeString::evaluate(Transaction *t) {
}


std::string RunTimeString::evaluate(Transaction *t, RuleBase *r) {
std::string RunTimeString::evaluate(Transaction *t, Rule *r) {
std::string s;
for (auto &z : m_elements) {
if (z->m_string.size() > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/run_time_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RunTimeString {
void appendText(const std::string &text);
void appendVar(std::unique_ptr<modsecurity::variables::Variable> var);
std::string evaluate(Transaction *t);
std::string evaluate(Transaction *t, RuleBase *r);
std::string evaluate(Transaction *t, Rule *r);
std::string evaluate() {
return evaluate(NULL);
}
Expand Down

0 comments on commit bdedfd2

Please sign in to comment.