diff --git a/src/operators/eq.cc b/src/operators/eq.cc index 83bc99b7..0d28ef8c 100644 --- a/src/operators/eq.cc +++ b/src/operators/eq.cc @@ -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 diff --git a/src/operators/eq.h b/src/operators/eq.h index 0d77a44a..bb5f74a5 100644 --- a/src/operators/eq.h +++ b/src/operators/eq.h @@ -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