*
* @param[in] request the request_t
* @param[in] modreturn the previous module return code
- * @param[in] depth of the recursion (only used for debugging)
* @param[in] c the condition to evaluate
* @return
* - -1 on failure.
* - 0 for "no match".
* - 1 for "match".
*/
-int cond_eval(request_t *request, rlm_rcode_t modreturn, int depth, fr_cond_t const *c)
+int cond_eval(request_t *request, rlm_rcode_t modreturn, fr_cond_t const *c)
{
int rcode = -1;
+ int depth = 0;
+
#ifdef WITH_EVAL_DEBUG
char buffer[1024];
break;
case COND_TYPE_CHILD:
- rcode = cond_eval(request, modreturn, depth + 1, c->data.child);
- break;
+ depth++;
+ c = c->data.child;
+ continue;
case COND_TYPE_TRUE:
rcode = true;
return -1;
}
+ /*
+ * Errors cause failures.
+ */
if (rcode < 0) return rcode;
if (c->negate) rcode = !rcode;
if (c->next) {
switch (c->next->type) {
case COND_TYPE_AND:
- if (!rcode) return false;
+ if (!rcode) goto return_to_parent;
c = c->next; /* skip the && */
break;
case COND_TYPE_OR:
- if (rcode) return true;
+ if (rcode) goto return_to_parent;
c = c->next; /* skip the || */
break;
}
}
+ /*
+ * We've fallen off of the end of this evaluation
+ * string. Go back up to the parent, and then to
+ * the next sibling of the parent.
+ */
+ if (!c->next) {
+return_to_parent:
+ c = c->parent;
+ depth--;
+
+ if (!c) break; /* we have to do this, otherwise the next line will fail */
+ }
+
c = c->next;
}
int cond_eval_tmpl(request_t *request, int depth, tmpl_t const *vpt);
int cond_eval_map(request_t *request, int depth, fr_cond_t const *c);
-int cond_eval(request_t *request, rlm_rcode_t modreturn, int depth, fr_cond_t const *c);
+int cond_eval(request_t *request, rlm_rcode_t modreturn, fr_cond_t const *c);
#ifdef __cplusplus
}
* !(!FOO) --> FOO, etc.
*/
child->negate = (c->negate != child->negate);
+ child->parent = c->parent;
talloc_free(c);
c = child;
continue;
*/
if (!c->next && !c->negate) {
(void) talloc_steal(ctx, child);
+ child->parent = c->parent;
talloc_free(c);
c = child;
continue;
gext = unlang_group_to_cond(g);
fr_assert(gext->cond != NULL);
- condition = cond_eval(request, *p_result, 0, gext->cond);
+ condition = cond_eval(request, *p_result, gext->cond);
if (condition < 0) {
switch (condition) {
case -2: