From b5ca607e76d776a483c843f8f33846613390903d Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Thu, 23 Jul 2015 01:31:37 -0300 Subject: [PATCH] Places class Driver under the Parser namespace --- headers/modsecurity/rules.h | 6 ++++-- src/parser/driver.cc | 18 +++++++++++++----- src/parser/driver.h | 7 ++++++- src/parser/seclang-parser.yy | 6 +++++- src/parser/seclang-scanner.ll | 5 +++++ src/rules.cc | 2 ++ 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/headers/modsecurity/rules.h b/headers/modsecurity/rules.h index ba511832..5218a09f 100644 --- a/headers/modsecurity/rules.h +++ b/headers/modsecurity/rules.h @@ -34,11 +34,13 @@ typedef struct Assay_t Assay; #include "modsecurity/assay.h" #ifdef __cplusplus -class Driver; namespace ModSecurity { class Rule; class AuditLog; +namespace Parser { +class Driver; +} /** @ingroup ModSecurity_CPP_API */ class Rules { @@ -68,7 +70,7 @@ class Rules { int loadRemote(char *key, char *uri); int load(const char *rules); - int merge(Driver *driver); + int merge(Parser::Driver *driver); int merge(Rules *rules); int evaluate(int phase, Assay *assay); diff --git a/src/parser/driver.cc b/src/parser/driver.cc index 6ea3a442..82d098cc 100644 --- a/src/parser/driver.cc +++ b/src/parser/driver.cc @@ -18,11 +18,16 @@ #include "parser/seclang-parser.hh" #include "src/audit_log.h" +using ModSecurity::AuditLog; +using ModSecurity::Rule; + +namespace ModSecurity { +namespace Parser { Driver::Driver() : trace_scanning(false), trace_parsing(false) { - audit_log = new ModSecurity::AuditLog(); + audit_log = new AuditLog(); } @@ -30,8 +35,8 @@ Driver::~Driver() { } -int Driver::addSecRule(ModSecurity::Rule *rule) { - if (rule->phase >= ModSecurity::ModSecurity::Phases::NUMBER_OF_PHASES) { +int Driver::addSecRule(Rule *rule) { + if (rule->phase >= ModSecurity::Phases::NUMBER_OF_PHASES) { /** TODO: return an error message */ return -1; } @@ -43,13 +48,13 @@ int Driver::addSecRule(ModSecurity::Rule *rule) { return true; } - ModSecurity::Rule *lastRule = this->rules[rule->phase][size-1]; + Rule *lastRule = this->rules[rule->phase][size-1]; if (lastRule->chained && lastRule->chainedRule == NULL) { lastRule->chainedRule = rule; return true; } if (lastRule->chained && lastRule->chainedRule != NULL) { - ModSecurity::Rule *a = lastRule->chainedRule; + Rule *a = lastRule->chainedRule; while (a->chained && a->chainedRule != NULL) { a = a->chainedRule; } @@ -113,3 +118,6 @@ void Driver::parser_error(const yy::location& l, const std::string& m) { parserError << ". " << m << "." << std::endl; } + +} // namespace Parser +} // namespace ModSecurity diff --git a/src/parser/driver.h b/src/parser/driver.h index c2ffa851..872ef22e 100644 --- a/src/parser/driver.h +++ b/src/parser/driver.h @@ -36,10 +36,12 @@ using ModSecurity::Rules; # define YY_DECL \ - yy::seclang_parser::symbol_type yylex(Driver& driver) + yy::seclang_parser::symbol_type yylex(ModSecurity::Parser::Driver& driver) YY_DECL; +namespace ModSecurity { +namespace Parser { #ifdef __cplusplus class Driver; @@ -89,4 +91,7 @@ class Driver : public Rules { }; +} // namespace Parser +} // namespace ModSecurity + #endif // SRC_PARSER_DRIVER_H_ diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index 09955d21..9c46f54b 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -9,7 +9,11 @@ { # include +namespace ModSecurity { +namespace Parser { class Driver; +} +} #include "actions/action.h" #include "actions/transformations/transformation.h" @@ -55,7 +59,7 @@ using ModSecurity::Variables::Variable; } // The parsing context. -%param { Driver& driver } +%param { ModSecurity::Parser::Driver& driver } %locations %initial-action { diff --git a/src/parser/seclang-scanner.ll b/src/parser/seclang-scanner.ll index aac886cc..c7148005 100755 --- a/src/parser/seclang-scanner.ll +++ b/src/parser/seclang-scanner.ll @@ -6,6 +6,8 @@ # include "parser/driver.h" # include "seclang-parser.hh" +using ModSecurity::Parser::Driver; + // Work around an incompatibility in flex (at least versions // 2.5.31 through 2.5.33): it generates code that does // not conform to C89. See Debian bug 333231 @@ -185,6 +187,8 @@ FREE_TEXT_NEW_LINE [^\"|\n]+ %% +namespace ModSecurity { + void Driver::scan_begin () { yy_flex_debug = trace_scanning; if (buffer.empty() == false) { @@ -206,3 +210,4 @@ void Driver::scan_end () { } } +} diff --git a/src/rules.cc b/src/rules.cc index 426b1965..4b9ee159 100644 --- a/src/rules.cc +++ b/src/rules.cc @@ -26,6 +26,8 @@ #include "src/utils.h" #include "parser/driver.h" +using ModSecurity::Parser::Driver; + namespace ModSecurity {