From: Alan T. DeKok Date: Mon, 18 Dec 2023 22:28:33 +0000 (-0500) Subject: move regex comparisons to calc.c code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b68a3e0b9463e64b75615c36a670e401998a9f5d;p=thirdparty%2Ffreeradius-server.git move regex comparisons to calc.c code --- diff --git a/src/lib/server/pairmove.c b/src/lib/server/pairmove.c index ba1e5ca0129..9675ac5eaf6 100644 --- a/src/lib/server/pairmove.c +++ b/src/lib/server/pairmove.c @@ -482,24 +482,6 @@ int radius_legacy_map_cmp(request_t *request, map_t const *map) return -1; } - /* - * The RHS is a compiled regex, which we don't yet - * support. So just re-parse it at run time for - * programmer laziness. - */ - if ((map->op == T_OP_REG_EQ) || (map->op == T_OP_REG_NE)) { - if (box->type != FR_TYPE_STRING) { - fr_strerror_const("Invalid type for regular expression"); - return -1; - } - - rcode = fr_regex_cmp_op(map->op, &vp->data, box); - TALLOC_FREE(to_free); - if (rcode < 0) return rcode; - - return (rcode == 1); - } - /* * Let the calculation code do upcasting as necessary. */ diff --git a/src/lib/util/calc.c b/src/lib/util/calc.c index bfd8be60a5f..948d617c862 100644 --- a/src/lib/util/calc.c +++ b/src/lib/util/calc.c @@ -26,6 +26,7 @@ RCSID("$Id$") #include +#include #include #include "calc.h" @@ -1934,6 +1935,20 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint op = T_OP_NE; break; + case T_OP_REG_EQ: + case T_OP_REG_NE: + if (b->type != FR_TYPE_STRING) { + fr_strerror_const("Invalid type for regular expression"); + return -1; + } + + rcode = fr_regex_cmp_op(op, a, b); + if (rcode < 0) return rcode; + + fr_value_box_init(dst, FR_TYPE_BOOL, NULL, false); /* @todo - enum */ + dst->vb_bool = (rcode != 0); + return 0; + default: break; }