]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
more cleanups to use only one cursor for the LHS
authorAlan T. DeKok <aland@freeradius.org>
Thu, 1 Sep 2022 13:50:15 +0000 (09:50 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 15 Sep 2022 18:41:09 +0000 (14:41 -0400)
src/lib/unlang/edit.c

index a331f47471ded32d86a8a81d3c51f6931bda4f97..b01ba1935ca4f8f135c41434b4a4fdbf1515041d 100644 (file)
@@ -638,18 +638,6 @@ static fr_pair_t *edit_list_pair_build(fr_pair_t *parent, fr_dcursor_t *cursor,
        fr_pair_t *vp;
        edit_map_t *current = uctx;
 
-       /*
-        *      We only build for `:=` and `=`.
-        */
-       switch (current->map->op) {
-       case T_OP_SET:
-       case T_OP_EQ:
-               break;
-
-       default:
-               return NULL;
-       }
-
        vp = fr_pair_afrom_da(parent, da);
        if (!vp) return NULL;
 
@@ -923,38 +911,47 @@ static int check_lhs_parented(request_t *request, unlang_frame_state_edit_t *sta
 static int check_lhs(request_t *request, unlang_frame_state_edit_t *state, edit_map_t *current)
 {
        map_t const *map = current->map;
+       tmpl_dcursor_build_t build = NULL;
+       int                     err;
+       fr_pair_t               *vp;
+       tmpl_dcursor_ctx_t      cc;
+       fr_dcursor_t            cursor;
 
-       if (tmpl_find_vp(&current->lhs.vp, request, current->lhs.vpt) < 0) {
-               int                     err;
-               fr_pair_t               *vp;
-               tmpl_dcursor_ctx_t      cc;
-               fr_dcursor_t            cursor;
+       if ((map->op == T_OP_SET) || (map->op == T_OP_EQ)) build = edit_list_pair_build;
 
-               /*
-                *      Use callback to build missing destination container.
-                */
-               fr_strerror_clear();
-               vp = tmpl_dcursor_build_init(&err, state, &cc, &cursor, request, current->lhs.vpt, edit_list_pair_build, current);
-               tmpl_dcursor_clear(&cc);
-               if (!vp) {
-                       RPDEBUG("Failed finding or creating %s - %d", current->lhs.vpt->name, err);
-                       return -1;
-               }
+       current->lhs.vp = NULL;
 
-       } else if (map->op == T_OP_EQ) {
-               /*
-                *      We're setting the value, but the attribute already exists.  This is a
-                *      NOOP, where we ignore this assignment.
-                */
-               return next_map(request, state, current);
+       /*
+        *      Use callback to build missing destination container.
+        */
+       fr_strerror_clear();
+       vp = tmpl_dcursor_build_init(&err, state, &cc, &cursor, request, current->lhs.vpt, build, current);
+       tmpl_dcursor_clear(&cc);
+       if (!vp) {
+               RPDEBUG("Failed finding or creating %s - %d", current->lhs.vpt->name, err);
+               return -1;
+       }
 
-       } else {
-               /*
-                *      Get the parent list of the attribute we're editing.
-                */
-               current->lhs.vp_parent = fr_pair_parent(current->lhs.vp);
+       /*
+        *      We just built it (= or :=).  Go do the RHS.
+        */
+       if (current->lhs.vp) {
+               return expand_rhs(request, state, current);
        }
 
+       /*
+        *      We found it, but the attribute already exists.  This
+        *      is a NOOP, where we ignore this assignment.
+        */
+       if (map->op == T_OP_EQ) {
+               return next_map(request, state, current);
+       }
+
+       /*
+        *      We found an existing attribute, with a modification operator.
+        */
+       current->lhs.vp = vp;
+       current->lhs.vp_parent = fr_pair_parent(current->lhs.vp);
        return expand_rhs(request, state, current);
 }