Warming up to the remote collections support

Huge refactoring to have the code in shape to later support the
remote collections with different backends.
This commit is contained in:
Felipe Zimmerle
2016-05-03 13:49:16 -03:00
parent ff165a4035
commit 5643d2fa28
50 changed files with 125 additions and 688 deletions

View File

@@ -28,14 +28,14 @@ namespace modsecurity {
namespace Variables {
void Duration::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
std::string res;
double e = cpu_seconds() - transaction->m_creationTimeStamp;
res = std::to_string(e);
l->push_back(new transaction::Variable("DURATION", std::string(res)));
l->push_back(new collection::Variable("DURATION", std::string(res)));
}

View File

@@ -34,7 +34,7 @@ class Duration : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void Env::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
std::map<std::string, std::string> envs;
for (char **current = environ; *current; current++) {
std::string env = std::string(*current);
@@ -47,7 +47,7 @@ void Env::evaluateInternal(Transaction *transaction,
envs.insert(std::pair<std::string, std::string>("ENV:" + key, value));
if ("env:" + key == m_name) {
l->push_back(new transaction::Variable(m_name, value));
l->push_back(new collection::Variable(m_name, value));
return;
}
}
@@ -57,7 +57,7 @@ void Env::evaluateInternal(Transaction *transaction,
&& (x.first != m_name)) {
continue;
}
l->push_back(new transaction::Variable(x.first, x.second));
l->push_back(new collection::Variable(x.first, x.second));
}
}

View File

@@ -34,7 +34,7 @@ class Env : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};

View File

@@ -27,8 +27,8 @@ namespace modsecurity {
namespace Variables {
void HighestSeverity::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
l->push_back(new transaction::Variable("HIGHEST_SEVERITY",
std::vector<const collection::Variable *> *l) {
l->push_back(new collection::Variable("HIGHEST_SEVERITY",
std::to_string(transaction->m_highestSeverityAction)));
}

View File

@@ -34,7 +34,7 @@ class HighestSeverity : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};

View File

@@ -28,14 +28,14 @@ namespace modsecurity {
namespace Variables {
void ModsecBuild::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
std::ostringstream ss;
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MAJOR;
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MINOR;
ss << std::setw(2) << std::setfill('0') << MODSECURITY_PATCHLEVEL;
ss << std::setw(2) << std::setfill('0') << MODSECURITY_TAG_NUM;
l->push_back(new transaction::Variable("MODSEC_BUILD", ss.str()));
l->push_back(new collection::Variable("MODSEC_BUILD", ss.str()));
}

View File

@@ -34,7 +34,7 @@ class ModsecBuild : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void Time::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
@@ -46,7 +46,7 @@ void Time::evaluateInternal(Transaction *transaction,
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%H:%M:%S", &timeinfo);
l->push_back(new transaction::Variable("TIME", std::string(tstr)));
l->push_back(new collection::Variable("TIME", std::string(tstr)));
}

View File

@@ -35,7 +35,7 @@ class Time : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void TimeDay::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
time_t timer;
@@ -45,7 +45,7 @@ void TimeDay::evaluateInternal(Transaction *transaction,
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%d", &timeinfo);
l->push_back(new transaction::Variable("TIME_DAY", std::string(tstr)));
l->push_back(new collection::Variable("TIME_DAY", std::string(tstr)));
}

View File

@@ -34,7 +34,7 @@ class TimeDay : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,8 +34,8 @@ namespace modsecurity {
namespace Variables {
void TimeEpoch::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
l->push_back(new transaction::Variable("TIME_EPOCH",
std::vector<const collection::Variable *> *l) {
l->push_back(new collection::Variable("TIME_EPOCH",
std::to_string(std::time(nullptr))));
}

View File

@@ -34,7 +34,7 @@ class TimeEpoch : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void TimeHour::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
time_t timer;
@@ -45,7 +45,7 @@ void TimeHour::evaluateInternal(Transaction *transaction,
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%H", &timeinfo);
l->push_back(new transaction::Variable("TIME_HOUR", std::string(tstr)));
l->push_back(new collection::Variable("TIME_HOUR", std::string(tstr)));
}

View File

@@ -34,7 +34,7 @@ class TimeHour : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void TimeMin::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
time_t timer;
@@ -45,7 +45,7 @@ void TimeMin::evaluateInternal(Transaction *transaction,
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%M", &timeinfo);
l->push_back(new transaction::Variable("TIME_MIN", std::string(tstr)));
l->push_back(new collection::Variable("TIME_MIN", std::string(tstr)));
}

View File

@@ -34,7 +34,7 @@ class TimeMin : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void TimeMon::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
time_t timer;
@@ -47,7 +47,7 @@ void TimeMon::evaluateInternal(Transaction *transaction,
int a = atoi(tstr);
a--;
l->push_back(new transaction::Variable("TIME_MON", std::to_string(a)));
l->push_back(new collection::Variable("TIME_MON", std::to_string(a)));
}

View File

@@ -34,7 +34,7 @@ class TimeMon : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void TimeSec::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
time_t timer;
@@ -45,7 +45,7 @@ void TimeSec::evaluateInternal(Transaction *transaction,
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%S", &timeinfo);
l->push_back(new transaction::Variable("TIME_SEC", std::string(tstr)));
l->push_back(new collection::Variable("TIME_SEC", std::string(tstr)));
}

View File

@@ -34,7 +34,7 @@ class TimeSec : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void TimeWDay::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
time_t timer;
@@ -47,7 +47,7 @@ void TimeWDay::evaluateInternal(Transaction *transaction,
int a = atoi(tstr);
a--;
l->push_back(new transaction::Variable("TIME_WDAY", std::to_string(a)));
l->push_back(new collection::Variable("TIME_WDAY", std::to_string(a)));
}

View File

@@ -34,7 +34,7 @@ class TimeWDay : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -34,7 +34,7 @@ namespace modsecurity {
namespace Variables {
void TimeYear::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
char tstr[200];
struct tm timeinfo;
time_t timer;
@@ -45,7 +45,7 @@ void TimeYear::evaluateInternal(Transaction *transaction,
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%Y", &timeinfo);
l->push_back(new transaction::Variable("TIME_YEAR", std::string(tstr)));
l->push_back(new collection::Variable("TIME_YEAR", std::string(tstr)));
}

View File

@@ -34,7 +34,7 @@ class TimeYear : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -35,7 +35,7 @@ namespace Variables {
void Tx::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
if (m_type == SingleMatch) {
transaction->m_collections.resolveSingleMatch(m_name, "TX", l);
} else if (m_type == MultipleMatches) {

View File

@@ -35,7 +35,7 @@ class Tx : public Variable {
: Variable(_name) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
};
} // namespace Variables

View File

@@ -71,17 +71,17 @@ Variable::Variable(std::string name, VariableKind kind)
}
std::vector<const transaction::Variable *> *
std::vector<const collection::Variable *> *
Variable::evaluate(Transaction *transaction) {
std::vector<const transaction::Variable *> *l = NULL;
l = new std::vector<const transaction::Variable *>();
std::vector<const collection::Variable *> *l = NULL;
l = new std::vector<const collection::Variable *>();
evaluate(transaction, l);
return l;
}
void Variable::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
if (m_collectionName.empty() == false) {
if (m_kind == CollectionVarible && m_type == MultipleMatches) {
transaction->m_collections.resolveMultiMatches(m_name,
@@ -108,7 +108,7 @@ void Variable::evaluateInternal(Transaction *transaction,
void Variable::evaluate(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
evaluateInternal(transaction, l);
}

View File

@@ -66,14 +66,14 @@ class Variable {
static std::string to_s(std::vector<Variable *> *variables);
virtual std::vector<const transaction::Variable *>
virtual std::vector<const collection::Variable *>
*evaluate(Transaction *transaction);
virtual void evaluate(Transaction *transaction,
std::vector<const transaction::Variable *> *l);
std::vector<const collection::Variable *> *l);
virtual void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l);
std::vector<const collection::Variable *> *l);
std::string m_name;

View File

@@ -29,8 +29,8 @@ namespace Variables {
namespace Variations {
void Count::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const transaction::Variable *> *reslIn;
std::vector<const collection::Variable *> *l) {
std::vector<const collection::Variable *> *reslIn;
int count = 0;
reslIn = var->evaluate(transaction);
@@ -47,7 +47,7 @@ void Count::evaluateInternal(Transaction *transaction,
std::string res = std::to_string(count);
l->push_back(new transaction::Variable(std::string(var->m_name),
l->push_back(new collection::Variable(std::string(var->m_name),
std::string(res)));
}

View File

@@ -36,7 +36,7 @@ class Count : public Variable {
var(v) { }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
Variable *var;
};

View File

@@ -30,7 +30,7 @@ namespace Variations {
void Exclusion::evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) {
std::vector<const collection::Variable *> *l) {
transaction->m_collections.resolveMultiMatches(m_name, l);
}

View File

@@ -38,7 +38,7 @@ class Exclusion : public Variable {
{ m_isExclusion = true; }
void evaluateInternal(Transaction *transaction,
std::vector<const transaction::Variable *> *l) override;
std::vector<const collection::Variable *> *l) override;
Variable *var;
};