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

@@ -32,11 +32,10 @@ pkginclude_HEADERS = \
libmodsecurity_includesub_HEADERS = \
../headers/modsecurity/transaction/collection.h \
../headers/modsecurity/transaction/collections.h \
../headers/modsecurity/transaction/variable.h \
../headers/modsecurity/transaction/variables.h
../headers/modsecurity/transaction/global_variables.h
../headers/modsecurity/collection/collection.h \
../headers/modsecurity/collection/collections.h \
../headers/modsecurity/collection/global_collection.h \
../headers/modsecurity/collection/variable.h
@@ -176,6 +175,9 @@ UTILS = \
libmodsecurity_la_SOURCES = \
collection/collection.cc \
collection/collections.cc \
collection/global_collections.cc \
parser/seclang-parser.yy \
parser/seclang-scanner.ll \
parser/driver.cc \
@@ -188,9 +190,6 @@ libmodsecurity_la_SOURCES = \
modsecurity.cc \
rules.cc \
utils.cc \
collections.cc \
variables.cc \
global_variables.cc \
debug_log.cc \
debug_log_writer.cc \
debug_log_writer_agent.cc \

View File

@@ -14,7 +14,7 @@
*/
#include "modsecurity/transaction/variables.h"
#include "modsecurity/collection/collection.h"
#ifdef __cplusplus
#include <string>
@@ -23,27 +23,27 @@
#include <list>
#endif
#include "modsecurity/transaction/variable.h"
#include "modsecurity/collection/variable.h"
#include "src/utils.h"
namespace modsecurity {
namespace transaction {
namespace collection {
Variables::Variables() {
Collection::Collection() {
this->reserve(1000);
}
Variables::~Variables() {
Collection::~Collection() {
this->clear();
}
void Variables::store(std::string key, std::string value) {
void Collection::store(std::string key, std::string value) {
this->emplace(key, value);
}
bool Variables::storeOrUpdateFirst(const std::string &key,
bool Collection::storeOrUpdateFirst(const std::string &key,
const std::string &value) {
if (updateFirst(key, value) == false) {
store(key, value);
@@ -52,7 +52,7 @@ bool Variables::storeOrUpdateFirst(const std::string &key,
}
bool Variables::updateFirst(const std::string &key, const std::string &value) {
bool Collection::updateFirst(const std::string &key, const std::string &value) {
auto range = this->equal_range(key);
for (auto it = range.first; it != range.second; ++it) {
@@ -63,30 +63,30 @@ bool Variables::updateFirst(const std::string &key, const std::string &value) {
}
void Variables::del(const std::string& key) {
void Collection::del(const std::string& key) {
this->erase(key);
}
void Variables::resolveSingleMatch(const std::string& var,
std::vector<const transaction::Variable *> *l) {
void Collection::resolveSingleMatch(const std::string& var,
std::vector<const Variable *> *l) {
auto range = this->equal_range(var);
for (auto it = range.first; it != range.second; ++it) {
l->push_back(new transaction::Variable(var, it->second));
l->push_back(new Variable(var, it->second));
}
}
void Variables::resolveMultiMatches(const std::string& var,
std::vector<const transaction::Variable *> *l) {
void Collection::resolveMultiMatches(const std::string& var,
std::vector<const Variable *> *l) {
size_t keySize = var.size();
l->reserve(15);
auto range = this->equal_range(var);
for (auto it = range.first; it != range.second; ++it) {
l->insert(l->begin(), new transaction::Variable(var, it->second));
l->insert(l->begin(), new Variable(var, it->second));
}
for (const auto& x : *this) {
@@ -99,18 +99,18 @@ void Variables::resolveMultiMatches(const std::string& var,
if (x.first.compare(0, keySize, var) != 0) {
continue;
}
l->insert(l->begin(), new transaction::Variable(x.first, x.second));
l->insert(l->begin(), new Variable(x.first, x.second));
}
}
void Variables::resolveRegularExpression(const std::string& var,
std::vector<const transaction::Variable *> *l) {
void Collection::resolveRegularExpression(const std::string& var,
std::vector<const Variable *> *l) {
/* Not ready */
}
std::string* Variables::resolveFirst(const std::string& var) {
std::string* Collection::resolveFirst(const std::string& var) {
auto range = equal_range(var);
for (auto it = range.first; it != range.second; ++it) {
@@ -121,5 +121,5 @@ std::string* Variables::resolveFirst(const std::string& var) {
}
} // namespace transaction
} // namespace collection
} // namespace modsecurity

View File

@@ -14,7 +14,7 @@
*/
#include "modsecurity/transaction/collections.h"
#include "modsecurity/collection/collections.h"
#ifdef __cplusplus
#include <string>
@@ -24,21 +24,22 @@
#include <vector>
#endif
#include "modsecurity/transaction/variable.h"
#include "modsecurity/collection/variable.h"
#include "modsecurity/collection/collection.h"
#include "src/utils.h"
namespace modsecurity {
namespace transaction {
namespace collection {
Collections::Collections(transaction::GlobalVariables *global,
transaction::GlobalVariables *ip)
Collections::Collections(GlobalCollection *global,
GlobalCollection *ip)
: m_global_collection_key(""),
m_ip_collection_key(""),
m_global_collection(global),
m_ip_collection(ip) {
/* Create collection TX */
this->emplace("TX", new Collection("TX", ""));
this->emplace("TX", new Collection());
}
@@ -49,12 +50,6 @@ Collections::~Collections() {
this->clear();
}
void Collections::init(const std::string& name, const std::string& key) {
this->emplace(name, new Collection(name, key));
}
void Collections::storeOrUpdateFirst(const std::string& collectionName,
const std::string& variableName,
const std::string& targetValue) {
@@ -73,7 +68,7 @@ void Collections::storeOrUpdateFirst(const std::string& collectionName,
}
try {
transaction::Variables *collection;
Collection *collection;
collection = this->at(collectionName);
collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, targetValue);
@@ -128,7 +123,6 @@ std::string* Collections::resolveFirst(const std::string& var) {
std::string* Collections::resolveFirst(const std::string& collectionName,
const std::string& var) {
if (tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) {
return m_ip_collection->resolveFirst(toupper(collectionName)
@@ -143,7 +137,7 @@ std::string* Collections::resolveFirst(const std::string& collectionName,
for (auto &a : *this) {
if (tolower(a.first) == tolower(collectionName)) {
transaction::Variables *t = a.second;
Collection *t = a.second;
auto range = t->equal_range(toupper(collectionName)
+ ":" + var);
for (auto it = range.first; it != range.second; ++it) {
@@ -157,7 +151,7 @@ std::string* Collections::resolveFirst(const std::string& collectionName,
void Collections::resolveSingleMatch(const std::string& var,
std::vector<const transaction::Variable *> *l) {
std::vector<const Variable *> *l) {
m_transient.resolveSingleMatch(var, l);
}
@@ -165,7 +159,7 @@ void Collections::resolveSingleMatch(const std::string& var,
void Collections::resolveSingleMatch(const std::string& var,
const std::string& collection,
std::vector<const transaction::Variable *> *l) {
std::vector<const Variable *> *l) {
if (tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) {
@@ -175,7 +169,8 @@ void Collections::resolveSingleMatch(const std::string& var,
if (tolower(collection) == "global"
&& !m_global_collection_key.empty()) {
m_global_collection->resolveSingleMatch(var, m_global_collection_key, l);
m_global_collection->resolveSingleMatch(var,
m_global_collection_key, l);
return;
}
@@ -185,7 +180,7 @@ void Collections::resolveSingleMatch(const std::string& var,
}
void Collections::resolveMultiMatches(const std::string& var,
std::vector<const transaction::Variable *> *l) {
std::vector<const Variable *> *l) {
m_transient.resolveMultiMatches(var, l);
}
@@ -193,7 +188,7 @@ void Collections::resolveMultiMatches(const std::string& var,
void Collections::resolveMultiMatches(const std::string& var,
const std::string& collection,
std::vector<const transaction::Variable *> *l) {
std::vector<const Variable *> *l) {
if (tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) {
m_ip_collection->resolveMultiMatches(var, m_ip_collection_key, l);
@@ -202,7 +197,8 @@ void Collections::resolveMultiMatches(const std::string& var,
if (tolower(collection) == "global"
&& !m_global_collection_key.empty()) {
m_global_collection->resolveMultiMatches(var, m_global_collection_key, l);
m_global_collection->resolveMultiMatches(var,
m_global_collection_key, l);
return;
}
@@ -212,14 +208,14 @@ void Collections::resolveMultiMatches(const std::string& var,
}
void Collections::resolveRegularExpression(const std::string& var,
std::vector<const transaction::Variable *> *l) {
std::vector<const Variable *> *l) {
m_transient.resolveRegularExpression(var, l);
}
void Collections::resolveRegularExpression(const std::string& var,
const std::string& collection,
std::vector<const transaction::Variable *> *l) {
std::vector<const Variable *> *l) {
if (tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) {
m_ip_collection->resolveRegularExpression(toupper(collection)
@@ -239,5 +235,5 @@ void Collections::resolveRegularExpression(const std::string& var,
} catch (...) { }
}
} // namespace transaction
} // namespace collection
} // namespace modsecurity

View File

@@ -1,126 +0,0 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "modsecurity/transaction/global_variables.h"
#ifdef __cplusplus
#include <string>
#include <iostream>
#include <unordered_map>
#include <list>
#endif
#include "modsecurity/transaction/variable.h"
#include "src/utils.h"
namespace modsecurity {
namespace transaction {
GlobalVariables::GlobalVariables() {
this->reserve(1000);
}
GlobalVariables::~GlobalVariables() {
this->clear();
}
void GlobalVariables::store(std::string key, std::string compartment, std::string value) {
this->emplace(new CollectionKey(key, compartment), value);
}
bool GlobalVariables::storeOrUpdateFirst(const std::string &key,
std::string compartment, const std::string &value) {
if (updateFirst(key, compartment, value) == false) {
store(key, compartment, value);
}
return true;
}
bool GlobalVariables::updateFirst(const std::string &key, std::string compartment, const std::string &value) {
auto range = this->equal_range(new CollectionKey(key, compartment));
for (auto it = range.first; it != range.second; ++it) {
it->second = value;
return true;
}
return false;
}
void GlobalVariables::del(const std::string& key, std::string compartment) {
this->erase(new CollectionKey(key, compartment));
}
void GlobalVariables::resolveSingleMatch(const std::string& var,
std::string compartment, std::vector<const transaction::Variable *> *l) {
auto range = this->equal_range(new CollectionKey(var, compartment));
for (auto it = range.first; it != range.second; ++it) {
l->push_back(new transaction::Variable(var, it->second));
}
}
void GlobalVariables::resolveMultiMatches(const std::string& var,
std::string compartment, std::vector<const transaction::Variable *> *l) {
size_t keySize = var.size();
l->reserve(15);
auto range = this->equal_range(new CollectionKey(var, compartment));
for (auto it = range.first; it != range.second; ++it) {
l->insert(l->begin(), new transaction::Variable(var, it->second));
}
for (const auto& x : *this) {
if (x.first->m_name.size() <= keySize + 1) {
continue;
}
if (x.first->m_name.at(keySize) != ':') {
continue;
}
if (x.first->m_name.compare(0, keySize, var) != 0) {
continue;
}
l->insert(l->begin(), new transaction::Variable(x.first->m_name, x.second));
}
}
void GlobalVariables::resolveRegularExpression(const std::string& var,
std::string compartment, std::vector<const transaction::Variable *> *l) {
/* Not ready */
}
std::string* GlobalVariables::resolveFirst(const std::string& var,
std::string compartment) {
auto range = equal_range(new CollectionKey(var, compartment));
for (auto it = range.first; it != range.second; ++it) {
return &it->second;
}
return NULL;
}
} // namespace transaction
} // namespace modsecurity

View File

@@ -20,6 +20,7 @@
#include <string>
#include "request_body_processor/multipart_blob.h"
#include "modsecurity/collection/collections.h"
namespace modsecurity {
namespace RequestBodyProcessor {
@@ -200,12 +201,14 @@ void Multipart::checkForCrlfLf(const std::string &data) {
}
bool Multipart::process(std::string data) {
collection::Collections *col;
std::list<std::string> blobs;
size_t start = data.find(m_boundary);
size_t endl = 1;
size_t lastValidBoundary = 0;
size_t firstValidBoundary = start;
double files_size = 0;
col = &m_transaction->m_collections;
if (start != 0) {
#ifndef NO_LOGS
@@ -267,14 +270,14 @@ bool Multipart::process(std::string data) {
filename = "no-file-name-" + std::to_string(i);
}
variables.emplace("FILES:" + name, filename);
variables.emplace("FILES_NAMES:" + name, name);
variables.emplace("FILES_SIZES:" + name,
col->storeOrUpdateFirst("FILES:" + name, filename);
col->storeOrUpdateFirst("FILES_NAMES:" + name, name);
col->storeOrUpdateFirst("FILES_SIZES:" + name,
std::to_string(m.content.size()));
#ifndef NO_LOGS
debug(5, "Multipart: Saving FILES_TMP_CONTENT:" + name + " variable.");
#endif
variables.emplace("FILES_TMP_CONTENT:" + name, m.content);
col->storeOrUpdateFirst("FILES_TMP_CONTENT:" + name, m.content);
files_size = files_size + m.content.size();
if (m.invalidQuote) {
#ifndef NO_LOGS
@@ -284,12 +287,12 @@ bool Multipart::process(std::string data) {
}
}
if (filename.empty() == false) {
variables.emplace("MULTIPART_FILENAME", filename);
col->storeOrUpdateFirst("MULTIPART_FILENAME", filename);
}
if (name.empty() == false) {
variables.emplace("MULTIPART_NAME", name);
col->storeOrUpdateFirst("MULTIPART_NAME", name);
}
variables.emplace("FILES_COMBINED_SIZE", std::to_string(files_size));
col->storeOrUpdateFirst("FILES_COMBINED_SIZE", std::to_string(files_size));
return true;
}

View File

@@ -35,8 +35,6 @@ class Multipart {
bool process(std::string data);
void checkForCrlfLf(const std::string &blob);
transaction::Variables variables;
bool crlf;
bool containsDataAfter;
bool containsDataBefore;

View File

@@ -305,7 +305,7 @@ bool Rule::evaluate(Transaction *trasn) {
for (int i = 0; i < variables->size(); i++) {
Variable *variable = variables->at(i);
if (variable->m_isExclusion) {
std::vector<const transaction::Variable *> z;
std::vector<const collection::Variable *> z;
variable->evaluateInternal(trasn, &z);
for (auto &y : z) {
exclusions.push_back(y->m_key);
@@ -321,7 +321,7 @@ bool Rule::evaluate(Transaction *trasn) {
continue;
}
std::vector<const transaction::Variable *> e;
std::vector<const collection::Variable *> e;
variable->evaluateInternal(trasn, &e);
for (auto &v : e) {

View File

@@ -112,9 +112,7 @@ Transaction::Transaction(ModSecurity *ms, Rules *rules, void *logCbData)
m_creationTimeStamp(cpu_seconds()),
m_logCbData(logCbData),
m_ms(ms),
m_collections(&ms->m_global_collection, &ms->m_ip_collection)
{
m_collections(&ms->m_global_collection, &ms->m_ip_collection) {
m_id = std::to_string(this->m_timeStamp) + \
std::to_string(generate_transaction_unique_id());
m_rules->incrementReferenceCount();
@@ -590,9 +588,6 @@ int Transaction::processRequestBody() {
if (m.init() == true) {
m.process(m_requestBody.str());
for (auto &a : m.variables) {
m_collections.store(a.first, a.second);
}
if (m.crlf && m.lf) {
m_collections.store("MULTIPART_CRLF_LF_LINES", "1");
} else {
@@ -734,7 +729,7 @@ int Transaction::processRequestBody() {
* computationally intensive.
*/
std::string fullRequest;
std::vector<const transaction::Variable *> l;
std::vector<const collection::Variable *> l;
m_collections.resolveMultiMatches("REQUEST_HEADERS", &l);
for (auto &a : l) {
fullRequest = fullRequest + \

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;
};