Refactoring on {global,ip,resources,session,tx,user} collections

Now using the same name schema and interface for these "special"
collection.

Fix: #1754, #1778
This commit is contained in:
Felipe Zimmerle 2018-05-29 23:48:05 -03:00
parent 550e9d3f39
commit 892beb5360
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
7 changed files with 66 additions and 43 deletions

View File

@ -105,9 +105,10 @@ void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
l->insert(l->begin(), new VariableValue(&m_name, &i.first, &i.second)); l->insert(l->begin(), new VariableValue(&m_name, &i.first, &i.second));
} }
} else { } else {
auto range = this->equal_range(var); for (auto &a : *this) {
for (auto it = range.first; it != range.second; ++it) { if (a.first.compare(0, var.size(), var) == 0) {
l->insert(l->begin(), new VariableValue(&m_name, &var, &it->second)); l->insert(l->begin(), new VariableValue(&m_name, &var, &a.second));
}
} }
} }
} }
@ -116,7 +117,6 @@ void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
void InMemoryPerProcess::resolveRegularExpression(const std::string& var, void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
std::vector<const VariableValue *> *l) { std::vector<const VariableValue *> *l) {
//if (var.find(":") == std::string::npos) { //if (var.find(":") == std::string::npos) {
// return; // return;
//} //}

View File

@ -34,14 +34,15 @@ namespace Variables {
class Global_DictElement : public Variable { class Global_DictElement : public Variable {
public: public:
explicit Global_DictElement(std::string dictElement) explicit Global_DictElement(std::string dictElement)
: Variable("GLOBAL"), : Variable("GLOBAL:" + dictElement),
m_dictElement(dictElement) { } m_dictElement("GLOBAL:" + dictElement) { }
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_global_collection->resolveMultiMatches( t->m_collections.m_global_collection->resolveMultiMatches(
m_dictElement, t->m_collections.m_global_collection_key, l); m_name, t->m_collections.m_global_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
std::string m_dictElement; std::string m_dictElement;
@ -56,8 +57,9 @@ class Global_NoDictElement : public Variable {
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_global_collection->resolveMultiMatches(m_name, t->m_collections.m_global_collection->resolveMultiMatches("",
t->m_collections.m_global_collection_key, l); t->m_collections.m_global_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
}; };
@ -73,7 +75,9 @@ class Global_DictElementRegexp : public Variable {
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_global_collection->resolveRegularExpression( t->m_collections.m_global_collection->resolveRegularExpression(
m_dictElement, t->m_collections.m_global_collection_key, l); m_dictElement,
t->m_collections.m_global_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
Utils::Regex m_r; Utils::Regex m_r;
@ -92,19 +96,24 @@ class Global_DynamicElement : public Variable {
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
std::string string = m_string->evaluate(t); std::string string = m_string->evaluate(t);
t->m_collections.m_global_collection->resolveMultiMatches( t->m_collections.m_global_collection->resolveMultiMatches(
string, t->m_collections.m_global_collection_key, l); string,
t->m_collections.m_global_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
void del(Transaction *t, std::string k) { void del(Transaction *t, std::string k) {
t->m_collections.m_global_collection->del(k, t->m_collections.m_global_collection->del(k,
t->m_collections.m_global_collection_key); t->m_collections.m_global_collection_key,
t->m_rules->m_secWebAppId.m_value);
} }
void storeOrUpdateFirst(Transaction *t, std::string var, void storeOrUpdateFirst(Transaction *t, std::string var,
std::string value) { std::string value) {
t->m_collections.m_global_collection->storeOrUpdateFirst( t->m_collections.m_global_collection->storeOrUpdateFirst(
var, t->m_collections.m_global_collection_key, value); var, t->m_collections.m_global_collection_key,
t->m_rules->m_secWebAppId.m_value,
value);
} }
std::unique_ptr<RunTimeString> m_string; std::unique_ptr<RunTimeString> m_string;

View File

@ -40,9 +40,9 @@ class Ip_DictElement : public Variable {
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_ip_collection->resolveMultiMatches(m_dictElement, t->m_collections.m_ip_collection->resolveMultiMatches(
t->m_collections.m_ip_collection_key, l); m_name, t->m_collections.m_ip_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
std::string m_dictElement; std::string m_dictElement;
@ -57,8 +57,9 @@ class Ip_NoDictElement : public Variable {
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_ip_collection->resolveMultiMatches(m_name, t->m_collections.m_ip_collection->resolveMultiMatches("",
t->m_collections.m_ip_collection_key, l); t->m_collections.m_ip_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
}; };
@ -68,13 +69,14 @@ class Ip_DictElementRegexp : public Variable {
explicit Ip_DictElementRegexp(std::string dictElement) explicit Ip_DictElementRegexp(std::string dictElement)
: Variable("IP:regex(" + dictElement + ")"), : Variable("IP:regex(" + dictElement + ")"),
m_r(dictElement), m_r(dictElement),
m_dictElement("IP:" + dictElement) { } m_dictElement(dictElement) { }
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_ip_collection->resolveRegularExpression(m_dictElement, t->m_collections.m_ip_collection->resolveRegularExpression(m_dictElement,
t->m_collections.m_ip_collection_key, l); t->m_collections.m_ip_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
Utils::Regex m_r; Utils::Regex m_r;
@ -92,19 +94,24 @@ class Ip_DynamicElement : public Variable {
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
std::string string = m_string->evaluate(t); std::string string = m_string->evaluate(t);
t->m_collections.m_ip_collection->resolveMultiMatches("IP:" + string, t->m_collections.m_ip_collection->resolveMultiMatches(
t->m_collections.m_ip_collection_key, l); string,
t->m_collections.m_ip_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
void del(Transaction *t, std::string k) { void del(Transaction *t, std::string k) {
t->m_collections.m_ip_collection->del(k, t->m_collections.m_ip_collection->del(k,
t->m_collections.m_ip_collection_key); t->m_collections.m_ip_collection_key,
t->m_rules->m_secWebAppId.m_value);
} }
void storeOrUpdateFirst(Transaction *t, std::string var, void storeOrUpdateFirst(Transaction *t, std::string var,
std::string value) { std::string value) {
t->m_collections.m_ip_collection->storeOrUpdateFirst( t->m_collections.m_ip_collection->storeOrUpdateFirst(
var, t->m_collections.m_ip_collection_key, value); var, t->m_collections.m_ip_collection_key,
t->m_rules->m_secWebAppId.m_value,
value);
} }
std::unique_ptr<RunTimeString> m_string; std::unique_ptr<RunTimeString> m_string;

View File

@ -35,13 +35,13 @@ class Resource_DictElement : public Variable {
public: public:
explicit Resource_DictElement(std::string dictElement) explicit Resource_DictElement(std::string dictElement)
: Variable("RESOURCE:" + dictElement), : Variable("RESOURCE:" + dictElement),
m_dictElement(dictElement) { } m_dictElement("RESOURCE:" + dictElement) { }
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_resource_collection->resolveMultiMatches(m_dictElement, t->m_collections.m_resource_collection->resolveMultiMatches(
t->m_collections.m_resource_collection_key, m_name, t->m_collections.m_resource_collection_key,
t->m_rules->m_secWebAppId.m_value, l); t->m_rules->m_secWebAppId.m_value, l);
} }
@ -102,14 +102,14 @@ class Resource_DynamicElement : public Variable {
void del(Transaction *t, std::string k) { void del(Transaction *t, std::string k) {
t->m_collections.m_resource_collection->del(k, t->m_collections.m_resource_collection->del(k,
t->m_collections.m_resource_collection_key); t->m_collections.m_resource_collection_key,
t->m_rules->m_secWebAppId.m_value);
} }
void storeOrUpdateFirst(Transaction *t, std::string var, void storeOrUpdateFirst(Transaction *t, std::string var,
std::string value) { std::string value) {
t->m_collections.m_resource_collection->storeOrUpdateFirst( t->m_collections.m_resource_collection->storeOrUpdateFirst(
var, var, t->m_collections.m_resource_collection_key,
t->m_collections.m_resource_collection_key,
t->m_rules->m_secWebAppId.m_value, value); t->m_rules->m_secWebAppId.m_value, value);
} }

View File

@ -34,14 +34,14 @@ namespace Variables {
class Session_DictElement : public Variable { class Session_DictElement : public Variable {
public: public:
explicit Session_DictElement(std::string dictElement) explicit Session_DictElement(std::string dictElement)
: Variable("SESSION"), : Variable("SESSION:" + dictElement),
m_dictElement(dictElement) { } m_dictElement("SESSION:" + dictElement) { }
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_session_collection->resolveMultiMatches( t->m_collections.m_session_collection->resolveMultiMatches(
m_dictElement, t->m_collections.m_session_collection_key, m_name, t->m_collections.m_session_collection_key,
t->m_rules->m_secWebAppId.m_value, l); t->m_rules->m_secWebAppId.m_value, l);
} }
@ -57,7 +57,7 @@ class Session_NoDictElement : public Variable {
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_session_collection->resolveMultiMatches(m_name, t->m_collections.m_session_collection->resolveMultiMatches("",
t->m_collections.m_session_collection_key, t->m_collections.m_session_collection_key,
t->m_rules->m_secWebAppId.m_value, l); t->m_rules->m_secWebAppId.m_value, l);
} }
@ -96,18 +96,21 @@ class Session_DynamicElement : public Variable {
std::string string = m_string->evaluate(t); std::string string = m_string->evaluate(t);
t->m_collections.m_session_collection->resolveMultiMatches( t->m_collections.m_session_collection->resolveMultiMatches(
string, string,
t->m_collections.m_session_collection_key, l); t->m_collections.m_session_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
void del(Transaction *t, std::string k) { void del(Transaction *t, std::string k) {
t->m_collections.m_session_collection->del(k, t->m_collections.m_session_collection->del(k,
t->m_collections.m_session_collection_key); t->m_collections.m_session_collection_key,
t->m_collections.m_ip_collection_key);
} }
void storeOrUpdateFirst(Transaction *t, std::string var, void storeOrUpdateFirst(Transaction *t, std::string var,
std::string value) { std::string value) {
t->m_collections.m_session_collection->storeOrUpdateFirst( t->m_collections.m_session_collection->storeOrUpdateFirst(
var, t->m_collections.m_session_collection_key, var, t->m_collections.m_session_collection_key,
t->m_rules->m_secWebAppId.m_value,
value); value);
} }

View File

@ -35,13 +35,13 @@ class Tx_DictElement : public Variable {
public: public:
explicit Tx_DictElement(std::string dictElement) explicit Tx_DictElement(std::string dictElement)
: Variable("TX:" + dictElement), : Variable("TX:" + dictElement),
m_dictElement(dictElement) { } m_dictElement("TX:" + dictElement) { }
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_tx_collection->resolveMultiMatches( t->m_collections.m_tx_collection->resolveMultiMatches(
m_dictElement, l); m_name, l);
} }
std::string m_dictElement; std::string m_dictElement;

View File

@ -34,14 +34,14 @@ namespace Variables {
class User_DictElement : public Variable { class User_DictElement : public Variable {
public: public:
explicit User_DictElement(std::string dictElement) explicit User_DictElement(std::string dictElement)
: Variable("USER"), : Variable("USER:" + dictElement),
m_dictElement(dictElement) { } m_dictElement("USER:" + dictElement) { }
void evaluate(Transaction *t, void evaluate(Transaction *t,
Rule *rule, Rule *rule,
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
t->m_collections.m_user_collection->resolveMultiMatches( t->m_collections.m_user_collection->resolveMultiMatches(
m_dictElement, t->m_collections.m_user_collection_key, m_name, t->m_collections.m_user_collection_key,
t->m_rules->m_secWebAppId.m_value, l); t->m_rules->m_secWebAppId.m_value, l);
} }
@ -95,18 +95,22 @@ class User_DynamicElement : public Variable {
std::vector<const VariableValue *> *l) override { std::vector<const VariableValue *> *l) override {
std::string string = m_string->evaluate(t); std::string string = m_string->evaluate(t);
t->m_collections.m_user_collection->resolveMultiMatches( t->m_collections.m_user_collection->resolveMultiMatches(
string, t->m_collections.m_user_collection_key, l); string,
t->m_collections.m_user_collection_key,
t->m_rules->m_secWebAppId.m_value, l);
} }
void del(Transaction *t, std::string k) { void del(Transaction *t, std::string k) {
t->m_collections.m_user_collection->del(k, t->m_collections.m_user_collection->del(k,
t->m_collections.m_user_collection_key); t->m_collections.m_user_collection_key,
t->m_rules->m_secWebAppId.m_value);
} }
void storeOrUpdateFirst(Transaction *t, std::string var, void storeOrUpdateFirst(Transaction *t, std::string var,
std::string value) { std::string value) {
t->m_collections.m_user_collection->storeOrUpdateFirst( t->m_collections.m_user_collection->storeOrUpdateFirst(
var, t->m_collections.m_user_collection_key, var, t->m_collections.m_user_collection_key,
t->m_rules->m_secWebAppId.m_value,
value); value);
} }