Adds support for the server log integration

This commit is contained in:
Felipe Zimmerle
2015-09-17 09:01:52 -03:00
parent 5228b685bf
commit d0c215d78b
7 changed files with 48 additions and 11 deletions

View File

@@ -81,7 +81,7 @@ namespace ModSecurity {
* @endcode
*
*/
Assay::Assay(ModSecurity *ms, Rules *rules)
Assay::Assay(ModSecurity *ms, Rules *rules, void *logCbData)
: m_clientIpAddress(""),
m_serverIpAddress(""),
m_clientPort(0),
@@ -105,6 +105,7 @@ Assay::Assay(ModSecurity *ms, Rules *rules)
m_responseHeadersNames(NULL),
m_marker(""),
start(cpu_seconds()),
m_logCbData(logCbData),
m_ms(ms) {
id = std::to_string(this->timeStamp) + \
std::to_string(generate_assay_unique_id());
@@ -1428,10 +1429,12 @@ std::list<std::pair<std::string, std::string>>
return l;
}
void Assay::serverLog(const std::string& msg) {
std::cerr << "Server log is not ready : " << msg << std::endl;
m_ms->serverLog(m_logCbData, msg);
}
std::string* Assay::resolve_variable_first(const std::string& var) {
auto range = m_variables_strings.equal_range(var);
@@ -1500,8 +1503,8 @@ void Assay::setCollection(const std::string& collectionName,
*
*/
extern "C" Assay *msc_new_assay(ModSecurity *ms,
Rules *rules) {
return new Assay(ms, rules);
Rules *rules, void *logCbData) {
return new Assay(ms, rules, logCbData);
}

View File

@@ -44,7 +44,8 @@ namespace ModSecurity {
* @endcode
*/
ModSecurity::ModSecurity()
: m_connector("") {
: m_connector(""),
m_logCb(NULL) {
UniqueId::uniqueId();
srand(time(NULL));
#ifdef MSC_WITH_CURL
@@ -138,6 +139,23 @@ const std::string& ModSecurity::getConnectorInformation() {
}
void ModSecurity::serverLog(void *data, const std::string& msg) {
if (m_logCb == NULL) {
std::cout << "Server log callback is not set -- " << msg << std::endl;
} else {
m_logCb(data, msg.c_str());
}
}
void ModSecurity::setServerLogCb(LogCb cb) {
m_logCb = (LogCb) cb;
}
extern "C" void msc_set_log_cb(ModSecurity *msc, LogCb cb) {
msc->setServerLogCb(cb);
}
/**
* @name msc_set_connector_info
* @brief Set information about the connector that is using the library.