From 6cd4c0492aec84bc61d6936bad4051d6390f88dc Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Mon, 3 Aug 2015 14:24:17 -0300 Subject: [PATCH] Adds support to the Rx operator --- src/operators/rx.cc | 21 +++++++++------------ src/operators/rx.h | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/operators/rx.cc b/src/operators/rx.cc index f164f2e4..ae7375d3 100644 --- a/src/operators/rx.cc +++ b/src/operators/rx.cc @@ -22,20 +22,17 @@ namespace ModSecurity { namespace operators { -bool Rx::evaluate(Assay *assay) { - /** - * @todo Implement the operator Rx. - * Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#rx - */ - return true; + +bool Rx::evaluate(Assay *assay, const std::string& input) { + SMatch match; + + if (regex_search(input, &match, m_re) && match.size() >= 1) { + return true; + } + + return false; } -Rx::Rx(std::string op, std::string param, bool negation) - : Operator() { - this->op = op; - this->param = param; -} - } // namespace operators } // namespace ModSecurity diff --git a/src/operators/rx.h b/src/operators/rx.h index f1a33bc9..f10bf057 100644 --- a/src/operators/rx.h +++ b/src/operators/rx.h @@ -19,17 +19,30 @@ #include #include "operators/operator.h" +#include "utils/regex.h" #ifdef __cplusplus namespace ModSecurity { +using Utils::SMatch; +using Utils::regex_search; +using Utils::Regex; + namespace operators { + class Rx : public Operator { public: /** @ingroup ModSecurity_Operator */ - Rx(std::string o, std::string p, bool i); - bool evaluate(Assay *assay); + Rx(std::string op, std::string param, bool negation) + : Operator(op, param, negation), + m_re(param) { } + + bool evaluate(Assay *assay, const std::string &input); + private: + Regex m_re; }; + + } // namespace operators } // namespace ModSecurity