27
27
#include " src/parser/driver.h"
28
28
#include " src/utils/https_client.h"
29
29
#include " modsecurity/transaction.h"
30
+ #include " modsecurity/rule_unconditional.h"
31
+ #include " modsecurity/rule_with_operator.h"
32
+
30
33
31
34
void print_help () {
32
35
std::cout << " Use ./optimization /path/to/files.something" << std::endl;
@@ -77,53 +80,42 @@ int main(int argc, char **argv) {
77
80
std::cout << " rules)" << std::endl;
78
81
79
82
std::unordered_map<std::string, int > operators;
80
- std::unordered_map<std::string, int > variables;
81
- std::unordered_map<std::string, int > op2var;
82
83
83
84
for (int i = 0 ; i < rules->size (); i++) {
84
85
auto z = rules->at (i);
85
- // std::string key;
86
+ std::string key;
86
87
if (z == NULL ) {
87
88
continue ;
88
89
}
89
- # if 0
90
- if (z->isUnconditional() == false ) {
91
- std::string op = z->getOperatorName() ;
90
+
91
+ if (dynamic_cast <modsecurity::RuleUnconditional *>(z. get ()) != nullptr ) {
92
+ std::string op = " Unconditional " ;
92
93
if (operators.count (op) > 0 ) {
93
94
operators[op] = 1 + operators[op];
94
95
} else {
95
96
operators[op] = 1 ;
96
97
}
97
98
key = op;
98
99
}
99
- #endif
100
100
101
- # if 0
102
- FIXME: This test may not be useful anymore. Disabling it for now.
101
+ if ( dynamic_cast <modsecurity::RuleWithOperator *>(z. get ()) != nullptr ) {
102
+ auto *rwo = dynamic_cast <modsecurity::RuleWithOperator *>(z. get ());
103
103
104
- if (z->m_variables != NULL) {
105
- std::string var = std::string("") + z->m_variables;
106
- if (variables.count(var) > 0) {
107
- variables[var] = 1 + variables[var];
108
- } else {
109
- variables[var] = 1;
110
- }
111
- key = key + var;
112
- }
113
- if (z->m_variables != NULL && z->m_op != NULL) {
114
- if (op2var.count(key) > 0) {
115
- op2var[key] = 1 + op2var[key];
104
+ std::string op = rwo->getOperatorName ();
105
+ if (operators.count (op) > 0 ) {
106
+ operators[op] = 1 + operators[op];
116
107
} else {
117
- op2var[key ] = 1;
108
+ operators[op ] = 1 ;
118
109
}
110
+ key = op;
119
111
}
120
- #endif
121
- }
122
112
123
- if (operators.empty () && variables.empty () && op2var.empty ()) {
113
+ }
114
+ if (operators.empty ()) {
124
115
std::cout << " ~ no SecRule found ~ " << std::endl;
125
116
continue ;
126
117
}
118
+
127
119
std::cout << " Operators" << std::endl;
128
120
for (auto &z : operators) {
129
121
auto &s = z.second ;
@@ -132,21 +124,6 @@ int main(int argc, char **argv) {
132
124
std::cout << std::endl;
133
125
}
134
126
135
- std::cout << " Variables" << std::endl;
136
- for (auto &z : variables) {
137
- auto &s = z.second ;
138
- std::cout << " " << std::left << std::setw (20 ) << z.first ;
139
- std::cout << std::right << std::setw (4 ) << s;
140
- std::cout << std::endl;
141
- }
142
- std::cout << " Operators applied to variables" << std::endl;
143
- for (auto &z : op2var) {
144
- auto &s = z.second ;
145
- std::cout << " " << std::left << std::setw (40 ) << z.first ;
146
- std::cout << std::right << std::setw (4 ) << s;
147
- std::cout << std::endl;
148
- }
149
-
150
127
total += rules->size ();
151
128
}
152
129
std::cout << std::endl;
0 commit comments