mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Refactoring on variables::Variable
Using the references on key and collection as shared pointers
This commit is contained in:
parent
bac54787af
commit
6c79e716e7
@ -73,7 +73,7 @@ bool SetVar::execute(Transaction *t) const noexcept {
|
|||||||
} else if (user) {
|
} else if (user) {
|
||||||
m_variableNameExpanded = user->evaluateRunTimeString(t);
|
m_variableNameExpanded = user->evaluateRunTimeString(t);
|
||||||
} else {
|
} else {
|
||||||
m_variableNameExpanded = m_variable->m_name;
|
m_variableNameExpanded = *m_variable->getVariableKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_operation == setOperation) {
|
if (m_operation == setOperation) {
|
||||||
@ -126,7 +126,7 @@ bool SetVar::execute(Transaction *t) const noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_dbg_a(t, 8, "Saving variable: " + m_variable->m_collectionName \
|
ms_dbg_a(t, 8, "Saving variable: " + *m_variable->getVariableKeyWithCollection() \
|
||||||
+ ":" + m_variableNameExpanded + " with value: " + targetValue);
|
+ ":" + m_variableNameExpanded + " with value: " + targetValue);
|
||||||
|
|
||||||
if (tx) {
|
if (tx) {
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
--- src/rule_with_actions.h
|
|
||||||
+++ src/rule_with_actions.h
|
|
||||||
@@ -520,11 +528,10 @@ class RuleWithActions : public Rule {
|
|
||||||
for (auto &a : m_XmlNSs) {
|
|
||||||
dst.push_back(a.get());
|
|
||||||
}
|
|
||||||
-
|
|
||||||
+
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
-
|
|
||||||
virtual void dump(std::stringstream &out) const override {
|
|
||||||
out << "RuleWithActions" << std::endl;
|
|
||||||
}
|
|
@ -187,7 +187,7 @@ inline void RuleWithOperator::getFinalVars(variables::Variables *vars,
|
|||||||
trans->m_ruleRemoveTargetById.end(),
|
trans->m_ruleRemoveTargetById.end(),
|
||||||
[&, variable, this](std::pair<int, std::string> &m) -> bool {
|
[&, variable, this](std::pair<int, std::string> &m) -> bool {
|
||||||
return m.first == getId()
|
return m.first == getId()
|
||||||
&& m.second == *variable->m_fullName.get();
|
&& m.second == *variable->getVariableKeyWithCollection();
|
||||||
}) != trans->m_ruleRemoveTargetById.end()) {
|
}) != trans->m_ruleRemoveTargetById.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ inline void RuleWithOperator::getFinalVars(variables::Variables *vars,
|
|||||||
[&, variable, trans, this](
|
[&, variable, trans, this](
|
||||||
std::pair<std::string, std::string> &m) -> bool {
|
std::pair<std::string, std::string> &m) -> bool {
|
||||||
return containsTag(m.first, trans)
|
return containsTag(m.first, trans)
|
||||||
&& m.second == *variable->m_fullName.get();
|
&& m.second == *variable->getVariableKeyWithCollection();
|
||||||
}) != trans->m_ruleRemoveTargetByTag.end()) {
|
}) != trans->m_ruleRemoveTargetByTag.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,12 @@ void Env::evaluate(Transaction *transaction,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto& x : transaction->m_variableEnvs) {
|
for (auto& x : transaction->m_variableEnvs) {
|
||||||
if (x.first != m_name && m_name.length() > 0) {
|
if (x.first != *getVariableKey() && getVariableKey()->length() > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!m_keyExclusion.toOmit(x.first)) {
|
if (!m_keyExclusion.toOmit(x.first)) {
|
||||||
l->emplace_back(std::make_shared<VariableValue>(&m_collectionName, &x.first, &x.second));
|
l->emplace_back(std::make_shared<VariableValue>(getVariableKeyWithCollection().get(),
|
||||||
|
&x.first, &x.second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class Global_DictElement : public Variable {
|
|||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_global_collection->resolveMultiMatches(
|
t->m_collections.m_global_collection->resolveMultiMatches(
|
||||||
m_name, t->m_collections.m_global_collection_key,
|
*getVariableKey(), t->m_collections.m_global_collection_key,
|
||||||
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class Global_DynamicElement : public VariableWithRunTimeString {
|
|||||||
public:
|
public:
|
||||||
explicit Global_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
explicit Global_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
||||||
: VariableWithRunTimeString(
|
: VariableWithRunTimeString(
|
||||||
"GLOBAL:dynamic",
|
"GLOBAL",
|
||||||
std::move(dictElement)
|
std::move(dictElement)
|
||||||
)
|
)
|
||||||
{ };
|
{ };
|
||||||
|
@ -30,7 +30,7 @@ void HighestSeverity::evaluate(Transaction *transaction,
|
|||||||
std::vector<std::shared_ptr<const VariableValue>> *l) {
|
std::vector<std::shared_ptr<const VariableValue>> *l) {
|
||||||
transaction->m_variableHighestSeverityAction.assign(
|
transaction->m_variableHighestSeverityAction.assign(
|
||||||
std::to_string(transaction->m_highestSeverityAction));
|
std::to_string(transaction->m_highestSeverityAction));
|
||||||
l->push_back(std::make_shared<VariableValue>(m_fullName.get(), &transaction->m_variableHighestSeverityAction));
|
l->push_back(std::make_shared<VariableValue>(getVariableKeyWithCollection().get(), &transaction->m_variableHighestSeverityAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class Ip_DictElement : public Variable {
|
|||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_ip_collection->resolveMultiMatches(
|
t->m_collections.m_ip_collection->resolveMultiMatches(
|
||||||
m_name, t->m_collections.m_ip_collection_key,
|
*getVariableKey(), t->m_collections.m_ip_collection_key,
|
||||||
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ class Ip_DynamicElement : public VariableWithRunTimeString {
|
|||||||
public:
|
public:
|
||||||
explicit Ip_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
explicit Ip_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
||||||
: VariableWithRunTimeString(
|
: VariableWithRunTimeString(
|
||||||
"IP:dynamic",
|
"IP",
|
||||||
std::move(dictElement)
|
std::move(dictElement)
|
||||||
)
|
)
|
||||||
{ }
|
{ }
|
||||||
|
@ -42,7 +42,7 @@ class Resource_DictElement : public Variable {
|
|||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_resource_collection->resolveMultiMatches(
|
t->m_collections.m_resource_collection->resolveMultiMatches(
|
||||||
m_name, t->m_collections.m_resource_collection_key,
|
*getVariableKey(), t->m_collections.m_resource_collection_key,
|
||||||
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class Resource_NoDictElement : public Variable {
|
|||||||
|
|
||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_resource_collection->resolveMultiMatches(m_name,
|
t->m_collections.m_resource_collection->resolveMultiMatches(*getVariableKey(),
|
||||||
t->m_collections.m_resource_collection_key,
|
t->m_collections.m_resource_collection_key,
|
||||||
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ class Resource_NoDictElement : public Variable {
|
|||||||
class Resource_DictElementRegexp : public VariableRegex {
|
class Resource_DictElementRegexp : public VariableRegex {
|
||||||
public:
|
public:
|
||||||
explicit Resource_DictElementRegexp(const std::string &dictElement)
|
explicit Resource_DictElementRegexp(const std::string &dictElement)
|
||||||
: VariableRegex("RESOURCE:", dictElement),
|
: VariableRegex("RESOURCE", dictElement),
|
||||||
m_dictElement(dictElement) { }
|
m_dictElement(dictElement) { }
|
||||||
|
|
||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
@ -85,7 +85,7 @@ class Resource_DynamicElement : public VariableWithRunTimeString {
|
|||||||
public:
|
public:
|
||||||
explicit Resource_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
explicit Resource_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
||||||
: VariableWithRunTimeString(
|
: VariableWithRunTimeString(
|
||||||
"RESOURCE:dynamic",
|
"RESOURCE",
|
||||||
std::move(dictElement)
|
std::move(dictElement)
|
||||||
)
|
)
|
||||||
{ }
|
{ }
|
||||||
|
@ -41,7 +41,7 @@ class Session_DictElement : public Variable {
|
|||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_session_collection->resolveMultiMatches(
|
t->m_collections.m_session_collection->resolveMultiMatches(
|
||||||
m_name, t->m_collections.m_session_collection_key,
|
*getVariableKey(), t->m_collections.m_session_collection_key,
|
||||||
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class Session_DynamicElement : public VariableWithRunTimeString {
|
|||||||
public:
|
public:
|
||||||
explicit Session_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
explicit Session_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
||||||
: VariableWithRunTimeString(
|
: VariableWithRunTimeString(
|
||||||
"SESSION:dynamic",
|
"SESSION",
|
||||||
std::move(dictElement)
|
std::move(dictElement)
|
||||||
)
|
)
|
||||||
{ }
|
{ }
|
||||||
|
@ -42,7 +42,7 @@ class Tx_DictElement : public Variable {
|
|||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_tx_collection->resolveMultiMatches(
|
t->m_collections.m_tx_collection->resolveMultiMatches(
|
||||||
m_name, l, m_keyExclusion);
|
*getVariableKey(), l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m_dictElement;
|
std::string m_dictElement;
|
||||||
@ -82,7 +82,7 @@ class Tx_DynamicElement : public VariableWithRunTimeString {
|
|||||||
public:
|
public:
|
||||||
explicit Tx_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
explicit Tx_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
||||||
: VariableWithRunTimeString(
|
: VariableWithRunTimeString(
|
||||||
"TX:dynamic",
|
"TX",
|
||||||
std::move(dictElement)
|
std::move(dictElement)
|
||||||
)
|
)
|
||||||
{ }
|
{ }
|
||||||
|
@ -42,7 +42,7 @@ class User_DictElement : public Variable {
|
|||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_user_collection->resolveMultiMatches(
|
t->m_collections.m_user_collection->resolveMultiMatches(
|
||||||
m_name, t->m_collections.m_user_collection_key,
|
*getVariableKey(), t->m_collections.m_user_collection_key,
|
||||||
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class User_NoDictElement : public Variable {
|
|||||||
|
|
||||||
void evaluate(Transaction *t,
|
void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
t->m_collections.m_user_collection->resolveMultiMatches(m_name,
|
t->m_collections.m_user_collection->resolveMultiMatches(*getVariableKey(),
|
||||||
t->m_collections.m_user_collection_key,
|
t->m_collections.m_user_collection_key,
|
||||||
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
t->m_rules->m_secWebAppId.m_value, l, m_keyExclusion);
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ class User_DynamicElement : public VariableWithRunTimeString {
|
|||||||
public:
|
public:
|
||||||
explicit User_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
explicit User_DynamicElement(std::unique_ptr<RunTimeString> dictElement)
|
||||||
: VariableWithRunTimeString(
|
: VariableWithRunTimeString(
|
||||||
"USER:dynamic",
|
"USER",
|
||||||
std::move(dictElement)
|
std::move(dictElement)
|
||||||
)
|
)
|
||||||
{ }
|
{ }
|
||||||
|
@ -29,31 +29,25 @@ namespace variables {
|
|||||||
|
|
||||||
|
|
||||||
Variable::Variable(const std::string &name)
|
Variable::Variable(const std::string &name)
|
||||||
: m_name(name),
|
: m_keyWithCollection(new std::string("")),
|
||||||
m_collectionName("") {
|
m_keyExclusion(),
|
||||||
size_t a = m_name.find(":");
|
m_collectionName(new std::string("")),
|
||||||
|
m_key(new std::string("")) {
|
||||||
|
size_t a = name.find(":");
|
||||||
if (a == std::string::npos) {
|
if (a == std::string::npos) {
|
||||||
a = m_name.find(".");
|
a = name.find(".");
|
||||||
}
|
}
|
||||||
if (a != std::string::npos) {
|
if (a != std::string::npos) {
|
||||||
m_collectionName = utils::string::toupper(std::string(m_name, 0, a));
|
m_collectionName->assign(utils::string::toupper(std::string(name, 0, a)));
|
||||||
m_name = std::string(m_name, a + 1, m_name.size());
|
m_key->assign(std::string(name, a + 1, name.size()));
|
||||||
m_fullName = std::make_shared<std::string>(m_collectionName
|
m_keyWithCollection->assign(*m_collectionName.get() + ":" + std::string(name, a + 1, name.size()));
|
||||||
+ ":" + m_name);
|
|
||||||
} else {
|
} else {
|
||||||
m_fullName = std::make_shared<std::string>(m_name);
|
m_keyWithCollection->assign(name);
|
||||||
m_collectionName = m_name;
|
m_collectionName->assign(name);
|
||||||
m_name = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Variable::Variable(Variable *var) :
|
|
||||||
m_name(var->m_name),
|
|
||||||
m_collectionName(var->m_collectionName),
|
|
||||||
m_fullName(var->m_fullName) { }
|
|
||||||
|
|
||||||
|
|
||||||
void Variable::addsKeyExclusion(Variable *v) {
|
void Variable::addsKeyExclusion(Variable *v) {
|
||||||
std::unique_ptr<KeyExclusion> r;
|
std::unique_ptr<KeyExclusion> r;
|
||||||
VariableModificatorExclusion *ve = \
|
VariableModificatorExclusion *ve = \
|
||||||
@ -67,7 +61,7 @@ void Variable::addsKeyExclusion(Variable *v) {
|
|||||||
vr = dynamic_cast<VariableRegex *>(ve->m_base.get());
|
vr = dynamic_cast<VariableRegex *>(ve->m_base.get());
|
||||||
|
|
||||||
if (vr == NULL) {
|
if (vr == NULL) {
|
||||||
r.reset(new KeyExclusionString(v->m_name));
|
r.reset(new KeyExclusionString(*v->getVariableKey()));
|
||||||
} else {
|
} else {
|
||||||
r.reset(new KeyExclusionRegex(vr->m_regex));
|
r.reset(new KeyExclusionRegex(vr->m_regex));
|
||||||
}
|
}
|
||||||
@ -77,7 +71,7 @@ void Variable::addsKeyExclusion(Variable *v) {
|
|||||||
|
|
||||||
|
|
||||||
std::string operator+(const std::string &a, Variable *v) {
|
std::string operator+(const std::string &a, Variable *v) {
|
||||||
return a + *v->m_fullName.get();
|
return a + *v->getVariableKeyWithCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -554,26 +554,35 @@ class Variable : public VariableMonkeyResolution {
|
|||||||
public:
|
public:
|
||||||
explicit Variable(const std::string &name);
|
explicit Variable(const std::string &name);
|
||||||
|
|
||||||
explicit Variable(Variable *_name);
|
|
||||||
|
|
||||||
Variable(const Variable &v)
|
explicit Variable(Variable *var)
|
||||||
: m_name(v.m_name),
|
: m_keyWithCollection(var->m_keyWithCollection),
|
||||||
m_collectionName(v.m_collectionName),
|
m_keyExclusion(var->m_keyExclusion),
|
||||||
m_fullName(v.m_fullName),
|
m_collectionName(var->m_collectionName),
|
||||||
m_keyExclusion(v.m_keyExclusion)
|
m_key(var->m_key)
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
virtual ~Variable() { }
|
|
||||||
|
Variable(const Variable &v)
|
||||||
|
: m_keyWithCollection(v.m_keyWithCollection),
|
||||||
|
m_keyExclusion(v.m_keyExclusion),
|
||||||
|
m_collectionName(v.m_collectionName),
|
||||||
|
m_key(v.m_key)
|
||||||
|
{ };
|
||||||
|
|
||||||
|
|
||||||
|
virtual ~Variable()
|
||||||
|
{ };
|
||||||
|
|
||||||
|
|
||||||
virtual void evaluate(Transaction *t,
|
virtual void evaluate(Transaction *t,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) = 0;
|
std::vector<std::shared_ptr<const VariableValue>> *l) = 0;
|
||||||
|
|
||||||
|
|
||||||
bool inline belongsToCollection(Variable *var) {
|
bool inline belongsToCollection(Variable *var) const noexcept {
|
||||||
return m_collectionName.size() == var->m_collectionName.size()
|
return m_collectionName->size() == var->m_collectionName->size()
|
||||||
&& std::equal(m_collectionName.begin(), m_collectionName.end(),
|
&& std::equal(m_collectionName->begin(), m_collectionName->end(),
|
||||||
var->m_collectionName.begin(),
|
var->m_collectionName->begin(),
|
||||||
[](char aa, char bb) {
|
[](char aa, char bb) {
|
||||||
return toupper(aa) == bb;
|
return toupper(aa) == bb;
|
||||||
});
|
});
|
||||||
@ -583,22 +592,65 @@ class Variable : public VariableMonkeyResolution {
|
|||||||
void addsKeyExclusion(Variable *v);
|
void addsKeyExclusion(Variable *v);
|
||||||
|
|
||||||
|
|
||||||
bool operator==(const Variable& b) const {
|
bool operator==(const Variable& b) const noexcept {
|
||||||
return m_collectionName == b.m_collectionName &&
|
return *m_collectionName == *b.m_collectionName &&
|
||||||
m_name == b.m_name &&
|
*m_key == *b.m_key &&
|
||||||
*m_fullName == *b.m_fullName;
|
*m_keyWithCollection == *b.m_keyWithCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string& operator+=(const char * p) { return m_name; }
|
std::string& operator+=(const char *p) { return *m_key; }
|
||||||
|
|
||||||
|
|
||||||
std::string m_name;
|
/**
|
||||||
std::string m_collectionName;
|
*
|
||||||
std::shared_ptr<std::string> m_fullName;
|
* Returns the variable key, if any is specified.
|
||||||
|
*
|
||||||
|
* 'ENV:a' will return 'a'
|
||||||
|
* 'ENV' will return a blank std::shared_ptr.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
std::shared_ptr<std::string> getVariableKey() const noexcept {
|
||||||
|
return m_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Returns the Collection name.
|
||||||
|
*
|
||||||
|
* 'ENV:a' will return 'ENV'
|
||||||
|
* 'ENV' will return 'ENV'
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
std::shared_ptr<std::string> getVariableCollection() const noexcept {
|
||||||
|
return m_collectionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Returns the Collection with key name.
|
||||||
|
*
|
||||||
|
* 'ENV:a' will return 'ENV:a'
|
||||||
|
* 'ENV' will return 'ENV'
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
std::shared_ptr<std::string> getVariableKeyWithCollection() const noexcept {
|
||||||
|
return m_keyWithCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
KeyExclusions m_keyExclusion;
|
KeyExclusions m_keyExclusion;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<std::string> m_keyWithCollection;
|
||||||
|
std::shared_ptr<std::string> m_key;
|
||||||
|
std::shared_ptr<std::string> m_collectionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VariableDictElement : public Variable {
|
class VariableDictElement : public Variable {
|
||||||
public:
|
public:
|
||||||
VariableDictElement(const std::string &name, const std::string &dict_element)
|
VariableDictElement(const std::string &name, const std::string &dict_element)
|
||||||
@ -649,7 +701,7 @@ class Variables : public std::vector<Variable *> {
|
|||||||
if (r) {
|
if (r) {
|
||||||
return r->m_r.searchAll(v->getKey()).size() > 0;
|
return r->m_r.searchAll(v->getKey()).size() > 0;
|
||||||
}
|
}
|
||||||
return v->getKeyWithCollection() == *m->m_fullName.get();
|
return v->getKeyWithCollection() == *m->getVariableKeyWithCollection();
|
||||||
}) != end();
|
}) != end();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -658,9 +710,9 @@ class Variables : public std::vector<Variable *> {
|
|||||||
std::string names;
|
std::string names;
|
||||||
for (auto a : *this) {
|
for (auto a : *this) {
|
||||||
if (names.length() > 0) {
|
if (names.length() > 0) {
|
||||||
names = names + sep + *a->m_fullName;
|
names = names + sep + *a->getVariableKeyWithCollection();
|
||||||
} else {
|
} else {
|
||||||
names = *a->m_fullName;
|
names = *a->getVariableKeyWithCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
@ -699,7 +751,7 @@ class VariableModificatorCount : public Variable {
|
|||||||
auto count = reslIn.size();
|
auto count = reslIn.size();
|
||||||
|
|
||||||
std::string res(std::to_string(count));
|
std::string res(std::to_string(count));
|
||||||
l->push_back(std::make_shared<VariableValue>(m_fullName.get(), &res));
|
l->push_back(std::make_shared<VariableValue>(getVariableKeyWithCollection().get(), &res));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,9 +37,8 @@ class WebAppId : public Variable {
|
|||||||
|
|
||||||
void evaluate(Transaction *transaction,
|
void evaluate(Transaction *transaction,
|
||||||
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
std::vector<std::shared_ptr<const VariableValue>> *l) override {
|
||||||
const std::string name("WEBAPPID");
|
|
||||||
const std::string rname = transaction->m_rules->m_secWebAppId.m_value;
|
const std::string rname = transaction->m_rules->m_secWebAppId.m_value;
|
||||||
l->push_back(std::make_shared<VariableValue>(&m_name, &rname));
|
l->push_back(std::make_shared<VariableValue>(getVariableKeyWithCollection().get(), &rname));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ void XML_WithNSPath::evaluate(Transaction *t,
|
|||||||
int i;
|
int i;
|
||||||
//size_t pos;
|
//size_t pos;
|
||||||
|
|
||||||
param = m_name;
|
param = *getVariableKey();
|
||||||
/*
|
/*
|
||||||
pos = m_name.find_first_of(":");
|
pos = m_name.find_first_of(":");
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
@ -124,8 +124,8 @@ void XML_WithNSPath::evaluate(Transaction *t,
|
|||||||
xmlNodeGetContent(nodes->nodeTab[i]));
|
xmlNodeGetContent(nodes->nodeTab[i]));
|
||||||
if (content != NULL) {
|
if (content != NULL) {
|
||||||
std::string a(content);
|
std::string a(content);
|
||||||
if (!m_keyExclusion.toOmit(*m_fullName)) {
|
if (!m_keyExclusion.toOmit(*getVariableKeyWithCollection())) {
|
||||||
l->push_back(std::make_shared<VariableValue>(m_fullName.get(), &a));
|
l->push_back(std::make_shared<VariableValue>(getVariableKeyWithCollection().get(), &a));
|
||||||
}
|
}
|
||||||
xmlFree(content);
|
xmlFree(content);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class XML_WithoutNSPath : public RuleVariable, public Variable {
|
|||||||
: RuleVariable(),
|
: RuleVariable(),
|
||||||
Variable("XML"),
|
Variable("XML"),
|
||||||
m_plain("[XML document tree]"),
|
m_plain("[XML document tree]"),
|
||||||
m_var(std::make_shared<VariableValue>(&m_name, &m_plain))
|
m_var(std::make_shared<VariableValue>(getVariableKeyWithCollection().get(), &m_plain))
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
XML_WithoutNSPath(const XML_WithoutNSPath &r)
|
XML_WithoutNSPath(const XML_WithoutNSPath &r)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user