Skip to content

Commit ef7f65d

Browse files
author
Felipe Zimmerle
committed
Changes debuglogs schema to avoid unecessary str allocation
1 parent 23e0d35 commit ef7f65d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1098
-1372
lines changed

headers/modsecurity/debug_log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class DebugLog {
5050
const std::string& getDebugLogFile();
5151
virtual int getDebugLogLevel();
5252

53-
private:
5453
int m_debugLevel;
54+
private:
5555
std::string m_fileName;
5656
};
5757

headers/modsecurity/transaction.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ typedef struct Rules_t Rules;
4848
#include "modsecurity/collection/collection.h"
4949
#include "modsecurity/variable_origin.h"
5050

51+
#ifndef NO_LOGS
52+
#define ms_dbg(b, c) \
53+
do { \
54+
if (m_rules && m_rules->m_debugLog && m_rules->m_debugLog->m_debugLevel >= b) { \
55+
m_rules->debug(b, m_id, m_uri, c); \
56+
} \
57+
} while (0);
58+
#else
59+
#define ms_dbg(b, c) \
60+
do { } while (0);
61+
#endif
62+
63+
#ifndef NO_LOGS
64+
#define ms_dbg_a(t, b, c) \
65+
do { \
66+
if (t && t->m_rules && t->m_rules->m_debugLog && t->m_rules->m_debugLog->m_debugLevel >= b) { \
67+
t->debug(b, c); \
68+
} \
69+
} while (0);
70+
#else
71+
#define ms_dbg_a(t, b, c) \
72+
do { } while (0);
73+
#endif
74+
5175

5276
#define LOGFY_ADD(a, b) \
5377
yajl_gen_string(g, reinterpret_cast<const unsigned char*>(a), strlen(a)); \

src/actions/block.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ namespace actions {
3131

3232
bool Block::evaluate(Rule *rule, Transaction *transaction,
3333
std::shared_ptr<RuleMessage> rm) {
34-
#ifndef NO_LOGS
35-
transaction->debug(8, "Marking request as disruptive.");
36-
#endif
34+
ms_dbg_a(transaction, 8, "Marking request as disruptive.");
3735

3836
for (Action *a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
3937
if (a->isDisruptive() == false) {

src/actions/ctl/rule_engine.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020

2121
#include "modsecurity/rules_properties.h"
22+
#include "modsecurity/rules.h"
2223
#include "modsecurity/transaction.h"
2324

2425
namespace modsecurity {
@@ -50,9 +51,7 @@ bool RuleEngine::evaluate(Rule *rule, Transaction *transaction) {
5051
a << modsecurity::RulesProperties::ruleEngineStateString(m_ruleEngine);
5152
a << " as requested by a ctl:ruleEngine action";
5253

53-
#ifndef NO_LOGS
54-
transaction->debug(8, a.str());
55-
#endif
54+
ms_dbg_a(transaction, 8, a.str());
5655

5756
transaction->m_secRuleEngine = m_ruleEngine;
5857
return true;

src/actions/disruptive/allow.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "modsecurity/transaction.h"
2222
#include "modsecurity/rule.h"
23+
#include "modsecurity/rules.h"
2324
#include "src/utils/string.h"
2425
#include "modsecurity/modsecurity.h"
2526

@@ -49,11 +50,9 @@ bool Allow::init(std::string *error) {
4950

5051

5152
bool Allow::evaluate(Rule *rule, Transaction *transaction) {
52-
#ifndef NO_LOGS
53-
transaction->debug(4, "Dropping the evaluation of upcoming rules " \
53+
ms_dbg_a(transaction, 4, "Dropping the evaluation of upcoming rules " \
5454
"in favor of an `allow' action of type: " \
5555
+ allowTypeToName(m_allowType));
56-
#endif
5756

5857
transaction->m_allowType = m_allowType;
5958

src/actions/disruptive/deny.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ namespace disruptive {
3030

3131
bool Deny::evaluate(Rule *rule, Transaction *transaction,
3232
std::shared_ptr<RuleMessage> rm) {
33-
#ifndef NO_LOGS
34-
transaction->debug(8, "Running action deny");
35-
#endif
33+
ms_dbg_a(transaction, 8, "Running action deny");
3634

3735
if (transaction->m_it.status == 200) {
3836
transaction->m_it.status = 403;

src/actions/disruptive/deny.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "modsecurity/actions/action.h"
2020
#include "modsecurity/transaction.h"
21+
#include "modsecurity/rules.h"
2122
#include "modsecurity/rule_message.h"
2223

2324
#ifndef SRC_ACTIONS_DISRUPTIVE_DENY_H_

src/actions/disruptive/pass.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "modsecurity/transaction.h"
2323
#include "modsecurity/rule.h"
24+
#include "modsecurity/rules.h"
2425
#include "modsecurity/rule_message.h"
2526

2627
namespace modsecurity {
@@ -33,9 +34,7 @@ bool Pass::evaluate(Rule *rule, Transaction *transaction,
3334
intervention::free(&transaction->m_it);
3435
intervention::reset(&transaction->m_it);
3536

36-
#ifndef NO_LOGS
37-
transaction->debug(8, "Running action pass");
38-
#endif
37+
ms_dbg_a(transaction, 8, "Running action pass");
3938

4039
return true;
4140
}

src/actions/exec.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "modsecurity/actions/action.h"
2222
#include "modsecurity/transaction.h"
2323
#include "modsecurity/rule.h"
24+
#include "modsecurity/rules.h"
2425
#include "src/utils/system.h"
2526
#include "src/engine/lua.h"
2627

@@ -49,9 +50,7 @@ bool Exec::init(std::string *error) {
4950

5051

5152
bool Exec::evaluate(Rule *rule, Transaction *t) {
52-
#ifndef NO_LOGS
53-
t->debug(8, "Running script... " + m_script);
54-
#endif
53+
ms_dbg_a(t, 8, "Running script... " + m_script);
5554
m_lua.run(t);
5655
return true;
5756
}

src/actions/init_col.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ bool InitCol::evaluate(Rule *rule, Transaction *t) {
6767
return false;
6868
}
6969

70-
#ifndef NO_LOGS
71-
t->debug(5, "Collection `" + m_collection_key + "' initialized with " \
70+
ms_dbg_a(t, 5, "Collection `" + m_collection_key + "' initialized with " \
7271
"value: " + collectionName);
73-
#endif
7472

7573
return true;
7674
}

0 commit comments

Comments
 (0)