Skip to content

Commit 47a62b9

Browse files
author
Felipe Zimmerle
committed
Saves `MATCHED_VAR' and related before execute the actions
Actions should have access to the MATCHED_VAR.
1 parent 778db25 commit 47a62b9

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/rule.cc

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ bool Rule::evaluate(Transaction *trasn) {
400400
" variable `" + v->m_key + "' (Value: `" + value + "' )";
401401
#ifndef NO_LOGS
402402
trasn->debug(4, "Rule returned 1.");
403+
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR",
404+
value);
405+
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR_NAME",
406+
v->m_key);
407+
trasn->m_collections.store("MATCHED_VARS:"
408+
+ v->m_key, value);
409+
trasn->m_collections.store("MATCHED_VARS_NAMES:"
410+
+ v->m_key, v->m_key);
403411
#endif
404412

405413
for (Action *a :
@@ -419,24 +427,7 @@ bool Rule::evaluate(Transaction *trasn) {
419427
#ifndef NO_LOGS
420428
trasn->debug(4, "Executing chained rule.");
421429
#endif
422-
if (trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR",
423-
value) == false) {
424-
trasn->m_collections.store("MATCHED_VAR", value);
425-
}
426-
if (trasn->m_collections.storeOrUpdateFirst(
427-
"MATCHED_VAR_NAME", v->m_key) == false) {
428-
trasn->m_collections.store("MATCHED_VAR_NAME",
429-
v->m_key);
430-
}
431-
trasn->m_collections.store("MATCHED_VARS:"
432-
+ v->m_key, value);
433-
trasn->m_collections.store("MATCHED_VARS_NAMES:"
434-
+ v->m_key, v->m_key);
435430
chainResult = this->chainedRule->evaluate(trasn);
436-
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR", "");
437-
trasn->m_collections.del("MATCHED_VARS:" + v->m_key);
438-
trasn->m_collections.del("MATCHED_VARS_NAMES:" + v->m_key);
439-
trasn->m_collections.del("MATCHED_VARS_NAME");
440431
}
441432
if ((this->chained && chainResult == true) || !this->chained) {
442433
for (Action *a :
@@ -509,6 +500,11 @@ bool Rule::evaluate(Transaction *trasn) {
509500
} else {
510501
#ifndef NO_LOGS
511502
trasn->debug(4, "Rule returned 0.");
503+
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR", "");
504+
trasn->m_collections.del("MATCHED_VARS:" + v->m_key);
505+
trasn->m_collections.del("MATCHED_VARS_NAMES:" + v->m_key);
506+
trasn->m_collections.del("MATCHED_VARS_NAME");
507+
512508
#endif
513509
}
514510
}

0 commit comments

Comments
 (0)