mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2026-01-16 08:27:10 +03:00
Having a better organization for Variables::
This commit is contained in:
@@ -30,10 +30,7 @@ namespace Variables {
|
||||
|
||||
Variable::Variable(std::string name)
|
||||
: m_name(name),
|
||||
m_collectionName(""),
|
||||
m_isExclusion(false),
|
||||
m_isCount(false),
|
||||
m_regex("") {
|
||||
m_collectionName("") {
|
||||
size_t a = m_name.find(":");
|
||||
if (a == std::string::npos) {
|
||||
a = m_name.find(".");
|
||||
@@ -51,36 +48,50 @@ Variable::Variable(std::string 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) {
|
||||
std::unique_ptr<KeyExclusion> r;
|
||||
VariableModificatorExclusion *ve = \
|
||||
dynamic_cast<VariableModificatorExclusion *>(v);
|
||||
VariableRegex *vr;
|
||||
|
||||
std::string Variable::to_s(
|
||||
std::vector<Variable *> *variables) {
|
||||
std::string ret;
|
||||
std::string except("");
|
||||
for (int i = 0; i < variables->size() ; i++) {
|
||||
VariableModificatorExclusion *e =
|
||||
dynamic_cast<VariableModificatorExclusion *>(variables->at(i));
|
||||
if (e != NULL) {
|
||||
if (except.empty()) {
|
||||
except = except + *variables->at(i)->m_fullName.get();
|
||||
} else {
|
||||
except = except + "|" + *variables->at(i)->m_fullName.get();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!ve) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
ret = ret + *variables->at(i)->m_fullName.get();
|
||||
vr = dynamic_cast<VariableRegex *>(ve->m_base.get());
|
||||
|
||||
if (vr == NULL) {
|
||||
r.reset(new KeyExclusionString(v->m_name));
|
||||
} else {
|
||||
r.reset(new KeyExclusionRegex(vr->m_regex));
|
||||
}
|
||||
|
||||
m_keyExclusion.push_back(std::move(r));
|
||||
}
|
||||
|
||||
|
||||
std::string operator+(std::string a, Variable *v) {
|
||||
return *v->m_fullName.get();
|
||||
}
|
||||
|
||||
|
||||
std::string operator+(std::string a, Variables *v) {
|
||||
std::string test;
|
||||
for (auto &b : *v) {
|
||||
if (test.empty()) {
|
||||
test = std::string("") + b;
|
||||
} else {
|
||||
ret = ret + "|" + *variables->at(i)->m_fullName.get();
|
||||
test = test + "|" + b;
|
||||
}
|
||||
}
|
||||
|
||||
if (except.empty() == false) {
|
||||
ret = ret + ", except for: " + except;
|
||||
}
|
||||
return ret;
|
||||
return a + test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user