Adds support to the @eq operator

This commit is contained in:
Felipe Zimmerle 2015-08-10 13:37:39 -03:00
parent 2f1bcf6cb9
commit f62e17c67c
2 changed files with 28 additions and 15 deletions

View File

@ -22,21 +22,32 @@
namespace ModSecurity {
namespace operators {
bool Eq::evaluate(Assay *assay) {
/**
* @todo Implement the operator Eq.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#eq
*/
return true;
bool Eq::evaluate(Assay *assay, const std::string &input) {
int p = 0;
int i = 0;
bool eq = false;
try {
p = std::stoi(param);
} catch (...) {
p = 0;
}
try {
i = std::stoi(input);
} catch (...) {
i = 0;
}
eq = p == i;
if (negation) {
return !eq;
}
return eq;
}
Eq::Eq(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -27,8 +27,10 @@ namespace operators {
class Eq : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Eq(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
Eq(std::string op, std::string param, bool negation)
: Operator(op, param, negation) { }
bool evaluate(Assay *assay, const std::string &input) override;
};
} // namespace operators