return 0;
}
-static int cond_compare_attrs(request_t *request, fr_value_box_t *lhs, map_t const *map)
+static bool cond_compare_attrs(request_t *request, fr_value_box_t *lhs, map_t const *map)
{
int rcode;
fr_pair_t *vp;
}
tmpl_pair_cursor_clear(&cc);
- return rcode;
+ return (rcode == 1);
}
-static int cond_compare_virtual(request_t *request, map_t const *map)
+static bool cond_compare_virtual(request_t *request, map_t const *map)
{
int rcode;
fr_pair_t *virt, *vp;
}
tmpl_pair_cursor_clear(&cc);
- return rcode;
+ return (rcode == 1);
}
/** Evaluate a map
* @param[in] async_lhs the asynchronously evaluated value box, for XLAT and EXEC
* @param[in] async_rhs the asynchronously evaluated value box, for XLAT and EXEC
* @return
- * - -1 on failure.
- * - 0 for "no match".
- * - 1 for "match".
+ * - false for no match (including "not found")
+ * - true for match
*/
-static int cond_eval_map(request_t *request, fr_cond_t const *c,
+static bool cond_eval_map(request_t *request, fr_cond_t const *c,
fr_value_box_t *async_lhs, fr_value_box_t *async_rhs)
{
int rcode = 0;
*/
if (cond_realize_tmpl(request, &lhs, &lhs_free, map->lhs, map->rhs, async_lhs) < 0) {
fr_strerror_const("Failed evaluating left side of condition");
- return -1;
+ return false;
}
/*
*/
if (cond_realize_tmpl(request, &rhs, &rhs_free, map->rhs, map->lhs, async_rhs) < 0) {
fr_strerror_const("Failed evaluating right side of condition");
- return -1;
+ return false;
}
/*
if (slen <= 0) {
REMARKER(rhs->vb_strvalue, -slen, "%s", fr_strerror());
EVAL_DEBUG("FAIL %d", __LINE__);
- return -1;
+ return false;
}
preg = preg_free;
}
if (map->op == T_OP_REG_EQ) {
fr_strerror_const("Virtual attributes cannot be used with regular expressions");
- return -1;
+ return false;
}
/*
*/
if (!rhs) {
fr_strerror_const("Invalid comparison for virtual attribute");
- return -1;
+ return false;
}
MEM(vp = fr_pair_afrom_da(request->request_ctx, tmpl_da(map->lhs)));
* request data, in which case we don't free it.
*/
if (preg) talloc_free(preg_free);
- return rcode;
+ return (rcode == 1);
}
* @param[in] modreturn the previous module return code
* @param[in] c the condition to evaluate
* @return
- * - -1 on failure.
- * - -2 on attribute not found.
- * - 0 for "no match".
- * - 1 for "match".
+ * - false for "no match", including "not found"
+ * - true for "match"
*/
-int cond_eval(request_t *request, rlm_rcode_t modreturn, fr_cond_t const *c)
+bool cond_eval(request_t *request, rlm_rcode_t modreturn, fr_cond_t const *c)
{
int rcode = -1;
break;
default:
EVAL_DEBUG("FAIL %d", __LINE__);
- return -1;
+ return false;
}
/*
- * Errors cause failures.
+ * Errors are "no match".
*/
- if (rcode < 0) return rcode;
+ if (rcode < 0) return false;
if (c->negate) rcode = !rcode;
while (!c->next) {
return_to_parent:
c = c->parent;
- if (!c) return rcode;
+ if (!c) goto done;
}
/*
}
}
+done:
if (rcode < 0) {
EVAL_DEBUG("FAIL %d", __LINE__);
}
- return rcode;
+ return (rcode == 1);
}
/** Asynchronous evaluation of conditions.
/** Evaluate a map as if it is a condition.
*
*/
-int fr_cond_eval_map(request_t *request, map_t const *map)
+bool fr_cond_eval_map(request_t *request, map_t const *map)
{
fr_cond_t cond;
static unlang_action_t unlang_if(rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame)
{
- int condition;
unlang_group_t *g = unlang_generic_to_group(frame->instruction);
unlang_cond_t *gext = unlang_group_to_cond(g);
fr_assert(gext->cond != NULL);
- condition = cond_eval(request, *p_result, gext->cond);
- if (condition < 0) {
- switch (condition) {
- case -2:
- REDEBUG("Condition evaluation failed because a referenced attribute "
- "was not found in the request");
- break;
- default:
- case -1:
- REDEBUG("Condition evaluation failed because the value of an operand "
- "could not be determined - %s", fr_strerror());
- break;
- }
- condition = 0;
- }
-
/*
* Didn't pass. Remember that.
*/
- if (!condition) {
+ if (!cond_eval(request, *p_result, gext->cond)) {
RDEBUG2("...");
return UNLANG_ACTION_EXECUTE_NEXT;
}