From 9a7506f9e9e7df46d2b26533426a7c5c37bce96e Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Tue, 11 Aug 2015 13:50:37 -0300 Subject: [PATCH] Adds support to the beginsWith operator --- src/operators/begins_with.cc | 26 +++++++++++++------------- src/operators/begins_with.h | 6 ++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/operators/begins_with.cc b/src/operators/begins_with.cc index 3a0f8fa4..41c52d7a 100644 --- a/src/operators/begins_with.cc +++ b/src/operators/begins_with.cc @@ -23,22 +23,22 @@ namespace ModSecurity { namespace operators { +bool BeginsWith::evaluate(Assay *assay, const std::string &str) { + bool ret = false; -bool BeginsWith::evaluate(Assay *assay) { - /** - * @todo Implement the operator BeginsWith. - * Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#beginswith - */ - return true; + if (str.size() < param.size()) { + ret = false; + } else if (!str.compare(0, param.size(), param)) { + ret = true; + } + + if (negation) { + return !ret; + } + + return ret; } -BeginsWith::BeginsWith(std::string op, std::string param, - bool negation) - : Operator() { - this->op = op; - this->param = param; -} - } // namespace operators } // namespace ModSecurity diff --git a/src/operators/begins_with.h b/src/operators/begins_with.h index 37a97983..a69aecf5 100644 --- a/src/operators/begins_with.h +++ b/src/operators/begins_with.h @@ -27,8 +27,10 @@ namespace operators { class BeginsWith : public Operator { public: /** @ingroup ModSecurity_Operator */ - BeginsWith(std::string o, std::string p, bool i); - bool evaluate(Assay *assay); + BeginsWith(std::string op, std::string param, bool negation) + : Operator(op, param, negation) { } + + bool evaluate(Assay *assay, const std::string &str) override; }; } // namespace operators