Skip to content

Commit

Permalink
Saves `MATCHED_VAR' and related before execute the actions
Browse files Browse the repository at this point in the history
Actions should have access to the MATCHED_VAR.
  • Loading branch information
Felipe Zimmerle committed Feb 18, 2016
1 parent 778db25 commit 47a62b9
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/rule.cc
Expand Up @@ -400,6 +400,14 @@ bool Rule::evaluate(Transaction *trasn) {
" variable `" + v->m_key + "' (Value: `" + value + "' )";
#ifndef NO_LOGS
trasn->debug(4, "Rule returned 1.");
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR",
value);
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR_NAME",
v->m_key);
trasn->m_collections.store("MATCHED_VARS:"
+ v->m_key, value);
trasn->m_collections.store("MATCHED_VARS_NAMES:"
+ v->m_key, v->m_key);
#endif

for (Action *a :
Expand All @@ -419,24 +427,7 @@ bool Rule::evaluate(Transaction *trasn) {
#ifndef NO_LOGS
trasn->debug(4, "Executing chained rule.");
#endif
if (trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR",
value) == false) {
trasn->m_collections.store("MATCHED_VAR", value);
}
if (trasn->m_collections.storeOrUpdateFirst(
"MATCHED_VAR_NAME", v->m_key) == false) {
trasn->m_collections.store("MATCHED_VAR_NAME",
v->m_key);
}
trasn->m_collections.store("MATCHED_VARS:"
+ v->m_key, value);
trasn->m_collections.store("MATCHED_VARS_NAMES:"
+ v->m_key, v->m_key);
chainResult = this->chainedRule->evaluate(trasn);
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR", "");
trasn->m_collections.del("MATCHED_VARS:" + v->m_key);
trasn->m_collections.del("MATCHED_VARS_NAMES:" + v->m_key);
trasn->m_collections.del("MATCHED_VARS_NAME");
}
if ((this->chained && chainResult == true) || !this->chained) {
for (Action *a :
Expand Down Expand Up @@ -509,6 +500,11 @@ bool Rule::evaluate(Transaction *trasn) {
} else {
#ifndef NO_LOGS
trasn->debug(4, "Rule returned 0.");
trasn->m_collections.storeOrUpdateFirst("MATCHED_VAR", "");
trasn->m_collections.del("MATCHED_VARS:" + v->m_key);
trasn->m_collections.del("MATCHED_VARS_NAMES:" + v->m_key);
trasn->m_collections.del("MATCHED_VARS_NAME");

#endif
}
}
Expand Down

0 comments on commit 47a62b9

Please sign in to comment.