Driver class is extending the Rules class instead of duplicate elements

This commit is contained in:
Felipe Zimmerle 2015-07-23 00:08:57 -03:00
parent dc0b13ad74
commit d3eb0fd913
6 changed files with 25 additions and 55 deletions

View File

@ -32,8 +32,6 @@ typedef struct Assay_t Assay;
#include "modsecurity/modsecurity.h"
#include "modsecurity/assay.h"
#include "modsecurity/debug_log.h"
#ifdef __cplusplus
class Driver;
@ -144,7 +142,7 @@ class Rules {
int requestBodyLimitAction;
int responseBodyLimitAction;
std::string parserError;
std::ostringstream parserError;
AuditLog *audit_log;

View File

@ -109,7 +109,6 @@ bool AuditLog::init() {
if (m_type == ParallelAuditLogType) {
m_writer = new AuditLogWriterParallel(this);
}
if (m_type == SerialAuditLogType) {
m_writer = new AuditLogWriterSerial(this);
}

View File

@ -16,14 +16,14 @@
#include "parser/driver.h"
#include "parser/seclang-parser.hh"
#include "src/audit_log.h"
Driver::Driver()
: trace_scanning(false),
trace_parsing(false),
requestBodyLimit(0),
responseBodyLimit(0),
audit_log(new ModSecurity::AuditLog()) {
}
trace_parsing(false) {
audit_log = new ModSecurity::AuditLog();
}
Driver::~Driver() {
@ -74,7 +74,7 @@ int Driver::parse(const std::string &f) {
int res = parser.parse();
if (this->audit_log->init() == false) {
if (audit_log->init() == false) {
return false;
}

View File

@ -26,11 +26,13 @@
#include "modsecurity/modsecurity.h"
#include "src/rule.h"
#include "modsecurity/rules.h"
#include "src/audit_log.h"
#include "parser/seclang-parser.hh"
using ModSecurity::Rule;
using ModSecurity::Rules;
# define YY_DECL \
yy::seclang_parser::symbol_type yylex(Driver& driver)
@ -45,7 +47,7 @@ typedef struct Driver_t Driver;
#endif
class Driver {
class Driver : public Rules {
/**
* @todo Place driver and parser under the correct namespace.
*
@ -79,28 +81,8 @@ class Driver {
// Error handling.
void error(const yy::location& l, const std::string& m);
void parser_error(const yy::location& l, const std::string& m);
void error(const yy::location& l, const std::string& m, const std::string& c);
std::vector<Rule *> rules[7]; // Number of Phases.
ModSecurity::Rules::RuleEngine secRuleEngine;
int sec_audit_type;
bool sec_audit_engine;
bool sec_request_body_access;
bool sec_response_body_access;
int requestBodyLimit;
int responseBodyLimit;
int requestBodyLimitAction;
int responseBodyLimitAction;
std::string debug_log_path;
std::list<std::string> components;
std::ostringstream parserError;
std::ostringstream syntaxError;
ModSecurity::AuditLog *audit_log;
int debug_level;
void error(const yy::location& l, const std::string& m,
const std::string& c);
};
#endif // SRC_PARSER_DRIVER_H_

View File

@ -16,6 +16,7 @@ class Driver;
#include "operators/operator.h"
#include "rule.h"
#include "utils/geo_lookup.h"
#include "audit_log.h"
#include "variables/duration.h"
#include "variables/env.h"

View File

@ -101,7 +101,7 @@ int Rules::loadFromUri(char *uri) {
Rules::~Rules() {
audit_log->refCountDecreaseAndCheck();
// audit_log->refCountDecreaseAndCheck();
}
@ -124,7 +124,7 @@ int Rules::load(const char *plain_rules) {
Driver *driver = new Driver();
if (driver->parse("/tmp/modsec_ugly_hack.txt")) {
ret = false;
parserError = driver->parserError.str();
parserError << driver->parserError.rdbuf();
}
this->merge(driver);
delete driver;
@ -134,7 +134,7 @@ int Rules::load(const char *plain_rules) {
std::string Rules::getParserError() {
return this->parserError;
return this->parserError.str();
}
@ -216,26 +216,16 @@ int Rules::merge(Rules *from) {
this->requestBodyLimitAction = from->requestBodyLimitAction;
this->responseBodyLimitAction = from->responseBodyLimitAction;
this->debug_log = from->debug_log;
if (m_custom_debug_log) {
this->debug_log = m_custom_debug_log->new_instance();
} else {
this->debug_log = new DebugLog();
}
/*
if (from->debug_log->isConfigured())
{
if (this->debug_log_path.compare(from->debug_log_path) != 0)
{
this->debug_log = new DebugLog();
this->debug_log->setDebugLevel(from->debug_level);
this->debug_log->setOutputFile(this->debug_log_path);
}
if (this->debug_level != from->debug_level)
{
this->debug_log->setDebugLevel(this->debug_log);
}
}
else
{
}
*/
this->audit_log = from->audit_log;
this->debug_log->setDebugLevel(this->debug_level);
this->debug_log->setOutputFile(this->debug_log_path);
return 0;
}