File tree 8 files changed +53
-9
lines changed
8 files changed +53
-9
lines changed Original file line number Diff line number Diff line change 1
1
v3.x.y - YYYY-MMM-DD (to be released)
2
2
-------------------------------------
3
3
4
+ - More structured rules dump. Better supporting debugging.
5
+ [@zimmerle]
4
6
- Added the basics for supporting better error/warning handling while
5
7
loading configurations.
6
8
[@zimmerle]
Original file line number Diff line number Diff line change @@ -46,8 +46,8 @@ class Rule {
46
46
Rule (std::unique_ptr<std::string> fileName, int lineNumber)
47
47
: m_fileName(std::make_shared<std::string>(*fileName)),
48
48
m_lineNumber (lineNumber),
49
- m_phase(modsecurity::Phases::RequestHeadersPhase) {
50
- }
49
+ m_phase(modsecurity::Phases::RequestHeadersPhase)
50
+ { }
51
51
52
52
Rule (const Rule &other) :
53
53
m_fileName(other.m_fileName),
@@ -82,6 +82,18 @@ class Rule {
82
82
return " <<no file>>:" + std::to_string (m_lineNumber);
83
83
}
84
84
85
+ virtual void dump (std::stringstream &out) {
86
+ out << getOriginInTextFormat () << std::endl;
87
+ }
88
+
89
+ protected:
90
+ std::string getOriginInTextFormat () const {
91
+ std::stringstream ss;
92
+ ss << " # File name: " << *getFileName () << std::endl;
93
+ ss << " # Line number: " << getLineNumber ();
94
+ return ss.str ();
95
+ }
96
+
85
97
private:
86
98
std::shared_ptr<std::string> m_fileName;
87
99
int m_lineNumber;
Original file line number Diff line number Diff line change @@ -61,7 +61,12 @@ class Rules {
61
61
std::vector<std::shared_ptr<actions::Action> > m_defaultActions;
62
62
std::vector<std::shared_ptr<actions::transformations::Transformation> > m_defaultTransformations;
63
63
64
- void dump ();
64
+ virtual void dump () {
65
+ std::stringstream ss;
66
+ dump (ss);
67
+ std::cout << ss.str ();
68
+ };
69
+ virtual void dump (std::stringstream &out);
65
70
66
71
inline iterator begin () noexcept { return m_rules.begin (); }
67
72
inline const_iterator cbegin () const noexcept { return m_rules.cbegin (); }
Original file line number Diff line number Diff line change @@ -47,7 +47,12 @@ class RuleMarker : public Rule {
47
47
RuleMarker (const RuleMarker& r) :
48
48
Rule(r),
49
49
m_name(r.m_name)
50
- { }
50
+ { };
51
+
52
+ RuleMarker (RuleMarker &&r) :
53
+ Rule(r),
54
+ m_name(std::move(r.m_name))
55
+ { };
51
56
52
57
RuleMarker &operator =(const RuleMarker& r) {
53
58
Rule::operator = (r);
@@ -72,6 +77,11 @@ class RuleMarker : public Rule {
72
77
return m_name;
73
78
}
74
79
80
+ virtual void dump (std::stringstream &out) override {
81
+ Rule::dump (out);
82
+ out << " SecMarker \" " << *getName () << " \" " << std::endl;
83
+ }
84
+
75
85
private:
76
86
std::shared_ptr<std::string> m_name;
77
87
};
Original file line number Diff line number Diff line change @@ -442,6 +442,11 @@ class RuleWithActions : public Rule {
442
442
return dst;
443
443
}
444
444
445
+
446
+ virtual void dump (std::stringstream &out) override {
447
+ out << " RuleWithActions" << std::endl;
448
+ }
449
+
445
450
private:
446
451
RuleId m_ruleId;
447
452
Original file line number Diff line number Diff line change 30
30
#include " modsecurity/variable_value.h"
31
31
#include " modsecurity/rule.h"
32
32
#include " src/rule_with_actions.h"
33
+ #include " src/variables/variable.h"
34
+ #include " src/operators/operator.h"
33
35
34
36
#ifdef __cplusplus
35
37
@@ -73,6 +75,15 @@ class RuleWithOperator : public RuleWithActions {
73
75
return std::to_string (getId ());
74
76
}
75
77
78
+ virtual void dump (std::stringstream &out) override {
79
+ Rule::dump (out);
80
+ out << " # RuleWithOperator" << std::endl;
81
+ out << " SecRule " ;
82
+ out << m_variables->getVariableNames () << " " ;
83
+ out << " \" " << " @" << m_operator->m_op << " " << m_operator->m_param << " \" " ;
84
+ out << std::endl;
85
+ }
86
+
76
87
private:
77
88
std::shared_ptr<modsecurity::variables::Variables> m_variables;
78
89
std::shared_ptr<operators::Operator> m_operator;
Original file line number Diff line number Diff line change @@ -57,13 +57,11 @@ std::shared_ptr<Rule> Rules::at(int index) const {
57
57
}
58
58
59
59
60
- void Rules::dump () {
61
- for (int j = 0 ; j < m_rules.size (); j++) {
62
- std::cout << " Rule ID: " << m_rules.at (j)->getReference ();
63
- std::cout << " --" << m_rules.at (j) << std::endl;
60
+ void Rules::dump (std::stringstream &out) {
61
+ for (auto &r : m_rules) {
62
+ r->dump (out);
64
63
}
65
64
}
66
65
67
-
68
66
} // namespace modsecurity
69
67
Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ int main(int argc, char **argv) {
91
91
if (err.empty () == false ) {
92
92
std::cerr << " " << err << std::endl;
93
93
}
94
+ rules->dump ();
94
95
next:
95
96
args++;
96
97
}
You can’t perform that action at this time.
0 commit comments