2727#include " src/parser/driver.h"
2828#include " src/utils/https_client.h"
2929#include " modsecurity/transaction.h"
30+ #include " modsecurity/rule_unconditional.h"
31+ #include " modsecurity/rule_with_operator.h"
32+
3033
3134void print_help () {
3235 std::cout << " Use ./optimization /path/to/files.something" << std::endl;
@@ -77,53 +80,42 @@ int main(int argc, char **argv) {
7780 std::cout << " rules)" << std::endl;
7881
7982 std::unordered_map<std::string, int > operators;
80- std::unordered_map<std::string, int > variables;
81- std::unordered_map<std::string, int > op2var;
8283
8384 for (int i = 0 ; i < rules->size (); i++) {
8485 auto z = rules->at (i);
85- // std::string key;
86+ std::string key;
8687 if (z == NULL ) {
8788 continue ;
8889 }
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 " ;
9293 if (operators.count (op) > 0 ) {
9394 operators[op] = 1 + operators[op];
9495 } else {
9596 operators[op] = 1 ;
9697 }
9798 key = op;
9899 }
99- #endif
100100
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 ());
103103
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];
116107 } else {
117- op2var[key ] = 1;
108+ operators[op ] = 1 ;
118109 }
110+ key = op;
119111 }
120- #endif
121- }
122112
123- if (operators.empty () && variables.empty () && op2var.empty ()) {
113+ }
114+ if (operators.empty ()) {
124115 std::cout << " ~ no SecRule found ~ " << std::endl;
125116 continue ;
126117 }
118+
127119 std::cout << " Operators" << std::endl;
128120 for (auto &z : operators) {
129121 auto &s = z.second ;
@@ -132,21 +124,6 @@ int main(int argc, char **argv) {
132124 std::cout << std::endl;
133125 }
134126
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-
150127 total += rules->size ();
151128 }
152129 std::cout << std::endl;
0 commit comments