From: Bert Hubert Date: Fri, 11 Jan 2013 09:23:54 +0000 (+0000) Subject: move our small regex helper out of the pipe backend, we'll need it for the selective... X-Git-Tag: auth-3.2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3ee84c3f2fb9832b05616885d0d70ceabf0a5fdc;p=thirdparty%2Fpdns.git move our small regex helper out of the pipe backend, we'll need it for the selective logging git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3040 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/modules/pipebackend/pipebackend.hh b/modules/pipebackend/pipebackend.hh index c93c0b8774..94712c870b 100644 --- a/modules/pipebackend/pipebackend.hh +++ b/modules/pipebackend/pipebackend.hh @@ -9,34 +9,10 @@ #include #include #include -#include #include #include "pdns/namespaces.hh" - -/** very small regex wrapper */ -class Regex -{ -public: - /** constructor that accepts the expression to regex */ - Regex(const string &expr) - { - if(regcomp(&d_preg, expr.c_str(), REG_ICASE|REG_NOSUB|REG_EXTENDED)) - throw AhuException("Regular expression did not compile"); - } - ~Regex() - { - regfree(&d_preg); - } - /** call this to find out if 'line' matches your expression */ - bool match(const string &line) - { - return regexec(&d_preg,line.c_str(),0,0,0)==0; - } - -private: - regex_t d_preg; -}; +#include "pdns/misc.hh" /** The CoWrapper class wraps around a coprocess and restarts it if needed. diff --git a/pdns/misc.cc b/pdns/misc.cc index 4739b6d969..1032adaca9 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -778,3 +778,8 @@ bool stringfgets(FILE* fp, std::string& line) return true; } +Regex::Regex(const string &expr) +{ + if(regcomp(&d_preg, expr.c_str(), REG_ICASE|REG_NOSUB|REG_EXTENDED)) + throw AhuException("Regular expression did not compile"); +} diff --git a/pdns/misc.hh b/pdns/misc.hh index 01993779b0..b5cf0a978d 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -449,4 +450,25 @@ replacing_insert(Index& i,const typename Index::value_type& x) return res; } +/** very small regex wrapper */ +class Regex +{ +public: + /** constructor that accepts the expression to regex */ + Regex(const string &expr); + + ~Regex() + { + regfree(&d_preg); + } + /** call this to find out if 'line' matches your expression */ + bool match(const string &line) + { + return regexec(&d_preg,line.c_str(),0,0,0)==0; + } + +private: + regex_t d_preg; +}; + #endif