Skip to content

Commit

Permalink
Renames collection::Variable to VariableValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Zimmerle committed Feb 20, 2018
1 parent de7c5c8 commit eeec7ef
Show file tree
Hide file tree
Showing 137 changed files with 304 additions and 361 deletions.
10 changes: 5 additions & 5 deletions headers/modsecurity/anchored_set_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <memory>
#endif

#include "modsecurity/collection/variable.h"
#include "modsecurity/variable_value.h"

#ifndef HEADERS_MODSECURITY_ANCHORED_SET_VARIABLE_H_
#define HEADERS_MODSECURITY_ANCHORED_SET_VARIABLE_H_
Expand Down Expand Up @@ -66,7 +66,7 @@ struct MyHash{


class AnchoredSetVariable : public std::unordered_multimap<std::string,
collection::Variable *, MyHash, MyEqual> {
VariableValue *, MyHash, MyEqual> {
public:
AnchoredSetVariable(Transaction *t, std::string name);
~AnchoredSetVariable();
Expand All @@ -81,13 +81,13 @@ class AnchoredSetVariable : public std::unordered_multimap<std::string,

void setCopy(std::string key, std::string value, size_t offset);

void resolve(std::vector<const collection::Variable *> *l);
void resolve(std::vector<const VariableValue *> *l);

void resolve(const std::string &key,
std::vector<const collection::Variable *> *l);
std::vector<const VariableValue *> *l);

void resolveRegularExpression(Utils::Regex *r,
std::vector<const collection::Variable *> *l);
std::vector<const VariableValue *> *l);

std::unique_ptr<std::string> resolveFirst(const std::string &key);

Expand Down
6 changes: 3 additions & 3 deletions headers/modsecurity/anchored_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <memory>
#endif

#include "modsecurity/collection/variable.h"
#include "modsecurity/variable_value.h"

#ifndef HEADERS_MODSECURITY_ANCHORED_VARIABLE_H_
#define HEADERS_MODSECURITY_ANCHORED_VARIABLE_H_
Expand All @@ -53,7 +53,7 @@ class AnchoredVariable {
void append(const std::string &a, size_t offset,
bool spaceSeparator, int size);

void evaluate(std::vector<const collection::Variable *> *l);
void evaluate(std::vector<const VariableValue *> *l);
std::string * evaluate();
std::unique_ptr<std::string> resolveFirst();

Expand All @@ -63,7 +63,7 @@ class AnchoredVariable {
std::string m_value;

private:
collection::Variable *m_var;
VariableValue *m_var;
};

} // namespace modsecurity
Expand Down
21 changes: 11 additions & 10 deletions headers/modsecurity/collection/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#endif


#include "modsecurity/collection/variable.h"
#include "modsecurity/variable_value.h"


#ifndef HEADERS_MODSECURITY_COLLECTION_COLLECTION_H_
#define HEADERS_MODSECURITY_COLLECTION_COLLECTION_H_
Expand Down Expand Up @@ -56,11 +57,11 @@ class Collection {
const std::string& var) = 0;

virtual void resolveSingleMatch(const std::string& var,
std::vector<const Variable *> *l) = 0;
std::vector<const VariableValue *> *l) = 0;
virtual void resolveMultiMatches(const std::string& var,
std::vector<const Variable *> *l) = 0;
std::vector<const VariableValue *> *l) = 0;
virtual void resolveRegularExpression(const std::string& var,
std::vector<const Variable *> *l) = 0;
std::vector<const VariableValue *> *l) = 0;


/* store */
Expand Down Expand Up @@ -140,47 +141,47 @@ class Collection {

/* resolveSingleMatch */
virtual void resolveSingleMatch(const std::string& var,
std::string compartment, std::vector<const Variable *> *l) {
std::string compartment, std::vector<const VariableValue *> *l) {
std::string nkey = compartment + "::" + var;
resolveSingleMatch(nkey, l);
}


virtual void resolveSingleMatch(const std::string& var,
std::string compartment, std::string compartment2,
std::vector<const Variable *> *l) {
std::vector<const VariableValue *> *l) {
std::string nkey = compartment + "::" + compartment2 + "::" + var;
resolveSingleMatch(nkey, l);
}


/* resolveMultiMatches */
virtual void resolveMultiMatches(const std::string& var,
std::string compartment, std::vector<const Variable *> *l) {
std::string compartment, std::vector<const VariableValue *> *l) {
std::string nkey = compartment + "::" + var;
resolveMultiMatches(nkey, l);
}


virtual void resolveMultiMatches(const std::string& var,
std::string compartment, std::string compartment2,
std::vector<const Variable *> *l) {
std::vector<const VariableValue *> *l) {
std::string nkey = compartment + "::" + compartment2 + "::" + var;
resolveMultiMatches(nkey, l);
}


/* resolveRegularExpression */
virtual void resolveRegularExpression(const std::string& var,
std::string compartment, std::vector<const Variable *> *l) {
std::string compartment, std::vector<const VariableValue *> *l) {
std::string nkey = compartment + "::" + var;
resolveRegularExpression(nkey, l);
}


virtual void resolveRegularExpression(const std::string& var,
std::string compartment, std::string compartment2,
std::vector<const Variable *> *l) {
std::vector<const VariableValue *> *l) {
std::string nkey = compartment + "::" + compartment2 + "::" + var;
resolveRegularExpression(nkey, l);
}
Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/collection/collections.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#endif

#include "modsecurity/collection/collection.h"
#include "modsecurity/collection/variable.h"
#include "modsecurity/variable_value.h"

#ifndef HEADERS_MODSECURITY_COLLECTION_COLLECTIONS_H_
#define HEADERS_MODSECURITY_COLLECTION_COLLECTIONS_H_
Expand Down
4 changes: 2 additions & 2 deletions headers/modsecurity/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define HEADERS_MODSECURITY_RULE_H_

#include "modsecurity/transaction.h"
#include "modsecurity/collection/variable.h"
#include "modsecurity/variable_value.h"


#ifdef __cplusplus
Expand Down Expand Up @@ -55,7 +55,7 @@ class Rule {
virtual bool evaluate(Transaction *transaction,
std::shared_ptr<RuleMessage> rm);
bool evaluateActions(Transaction *transaction);
std::vector<std::unique_ptr<collection::Variable>>
std::vector<std::unique_ptr<VariableValue>>
getFinalVars(Transaction *trasn);
void executeActionsAfterFullMatch(Transaction *trasn,
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
Expand Down
6 changes: 3 additions & 3 deletions headers/modsecurity/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ typedef struct Transaction_t Transaction;
typedef struct Rules_t Rules;
#endif

#include "modsecurity/anchored_set_variable.h"
#include "modsecurity/anchored_variable.h"
#include "anchored_set_variable.h"
#include "anchored_variable.h"
#include "modsecurity/intervention.h"
#include "modsecurity/collection/collections.h"
#include "modsecurity/collection/variable.h"
#include "modsecurity/variable_value.h"
#include "modsecurity/collection/collection.h"
#include "modsecurity/variable_origin.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,54 @@

#include "modsecurity/variable_origin.h"

#ifndef HEADERS_MODSECURITY_COLLECTION_VARIABLE_H_
#define HEADERS_MODSECURITY_COLLECTION_VARIABLE_H_
#ifndef HEADERS_MODSECURITY_VARIABLE_H_
#define HEADERS_MODSECURITY_VARIABLE_H_

#ifndef __cplusplus
typedef struct Variable_t Variable;
typedef struct Variable_t VariableValue;
#endif

#ifdef __cplusplus
namespace modsecurity {
namespace collection {

class Collection;
class Variable {
class VariableValue {
public:
explicit Variable(const std::string *key) :
explicit VariableValue(const std::string *key) :
m_key(""),
m_value("") {
m_key.assign(*key);
m_keyWithCollection = std::make_shared<std::string>(*key);
}

Variable(const std::string *key, const std::string *value) :
VariableValue(const std::string *key, const std::string *value) :
m_key(""),
m_value("") {
m_key.assign(*key);
m_value.assign(*value);
m_keyWithCollection = std::make_shared<std::string>(*key);
}

Variable() :
VariableValue() :
m_key(""),
m_value("") {
m_keyWithCollection = std::make_shared<std::string>(m_key);
}

Variable(const std::string *a, const std::string *b, const std::string *c) :
VariableValue(const std::string *a, const std::string *b, const std::string *c) :
m_key(*a + ":" + *b),
m_value(*c) {
m_keyWithCollection = std::make_shared<std::string>(*a + ":" + *b);
}

Variable(std::shared_ptr<std::string> fullName) :
VariableValue(std::shared_ptr<std::string> fullName) :
m_key(""),
m_value("") {
m_keyWithCollection = fullName;
m_key.assign(*fullName.get());
}

Variable(std::shared_ptr<std::string> fullName, const std::string *value) :
VariableValue(std::shared_ptr<std::string> fullName, const std::string *value) :
m_key(""),
m_value("") {
m_value.assign(*value);
Expand All @@ -81,7 +80,7 @@ class Variable {
}


explicit Variable(const Variable *o) :
explicit VariableValue(const VariableValue *o) :
m_key(""),
m_value("") {
m_key.assign(o->m_key);
Expand All @@ -104,8 +103,7 @@ class Variable {
std::list<std::unique_ptr<VariableOrigin>> m_orign;
};

} // namespace collection
} // namespace modsecurity
#endif

#endif // HEADERS_MODSECURITY_COLLECTION_VARIABLE_H_
#endif // HEADERS_MODSECURITY_VARIABLE_H_
7 changes: 4 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ pkginclude_HEADERS = \
../headers/modsecurity/rules_exceptions.h \
../headers/modsecurity/rules_properties.h \
../headers/modsecurity/transaction.h \
../headers/modsecurity/variable_origin.h
../headers/modsecurity/variable_origin.h \
../headers/modsecurity/variable_value.h



libmodsecurity_includesub_collection_HEADERS = \
../headers/modsecurity/collection/collection.h \
../headers/modsecurity/collection/collections.h \
../headers/modsecurity/collection/variable.h
../headers/modsecurity/collection/collections.h



libmodsecurity_includesub_actions_HEADERS = \
Expand Down
4 changes: 2 additions & 2 deletions src/actions/set_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool SetVar::evaluate(Rule *rule, Transaction *t) {
}

std::string m_variableNameExpanded;
std::vector<const collection::Variable *> l;
std::vector<const VariableValue *> l;

auto *v = m_variable.get();
Variables::Tx_DynamicElement *tx = dynamic_cast<Variables::Tx_DynamicElement *> (v);
Expand Down Expand Up @@ -106,7 +106,7 @@ bool SetVar::evaluate(Rule *rule, Transaction *t) {
}

try {
std::vector<const collection::Variable *> l;
std::vector<const VariableValue *> l;
m_variable->evaluate(t, rule, &l);
if (l.size() == 0) {
value = 0;
Expand Down
21 changes: 10 additions & 11 deletions src/anchored_set_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
*
*/

#include "modsecurity/anchored_set_variable.h"

#include <ctime>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "modsecurity/anchored_set_variable.h"
#include "modsecurity/modsecurity.h"
#include "modsecurity/transaction.h"
#include "src/utils/regex.h"
Expand All @@ -42,7 +41,7 @@ AnchoredSetVariable::~AnchoredSetVariable() {

void AnchoredSetVariable::unset() {
for (const auto& x : *this) {
collection::Variable *var = x.second;
VariableValue *var = x.second;
delete var;
}
clear();
Expand All @@ -53,7 +52,7 @@ void AnchoredSetVariable::set(const std::string &key,
const std::string &value, size_t offset, size_t len) {
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
std::string *v = new std::string(value);
collection::Variable *var = new collection::Variable(std::make_shared<std::string>(m_name + ":" + key), v);
VariableValue *var = new VariableValue(std::make_shared<std::string>(m_name + ":" + key), v);
delete v;

origin->m_offset = offset;
Expand All @@ -68,7 +67,7 @@ void AnchoredSetVariable::set(const std::string &key,
const std::string &value, size_t offset) {
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
std::string *v = new std::string(value);
collection::Variable *var = new collection::Variable(std::make_shared<std::string>(m_name + ":" + key), v);
VariableValue *var = new VariableValue(std::make_shared<std::string>(m_name + ":" + key), v);
delete v;

origin->m_offset = offset;
Expand All @@ -80,18 +79,18 @@ void AnchoredSetVariable::set(const std::string &key,


void AnchoredSetVariable::resolve(
std::vector<const collection::Variable *> *l) {
std::vector<const VariableValue *> *l) {
for (const auto& x : *this) {
l->insert(l->begin(), new collection::Variable(x.second));
l->insert(l->begin(), new VariableValue(x.second));
}
}


void AnchoredSetVariable::resolve(const std::string &key,
std::vector<const collection::Variable *> *l) {
std::vector<const VariableValue *> *l) {
auto range = this->equal_range(key);
for (auto it = range.first; it != range.second; ++it) {
l->push_back(new collection::Variable(it->second));
l->push_back(new VariableValue(it->second));
}
}

Expand All @@ -109,13 +108,13 @@ std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(


void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
std::vector<const collection::Variable *> *l) {
std::vector<const VariableValue *> *l) {
for (const auto& x : *this) {
int ret = Utils::regex_search(x.first, *r);
if (ret <= 0) {
continue;
}
l->insert(l->begin(), new collection::Variable(x.second));
l->insert(l->begin(), new VariableValue(x.second));
}
}

Expand Down
Loading

0 comments on commit eeec7ef

Please sign in to comment.