]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Amend dcursor remove callback specification
authorNick Porter <nick@portercomputing.co.uk>
Tue, 24 Jan 2023 11:24:01 +0000 (11:24 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 9 Feb 2023 17:00:06 +0000 (11:00 -0600)
Allowing the callback to do the actual list removal.

This overcomes issues with tmpl_dcursor operations where the dcursor
refers to the top level list whilst the entries need to be removed from
a child list.

src/lib/util/dcursor.h

index b686ce01a25a2d1b8091a30b304385fc0557b610..3c11121a925e9f92977117299bf7ec6ce5bb1a2d 100644 (file)
@@ -67,7 +67,8 @@ typedef int (*fr_dcursor_insert_t)(fr_dlist_head_t *list, void *to_insert, void
  * @param[in] to_delete        The item being removed from the cursor.
  * @param[in] uctx     passed to #fr_dcursor_init.
  * @return
- *     - 0 on success.
+ *     - 0 on success if the caller should do the list removal.
+ *     - 1 on success if the callback has done the list removal.
  *     - -1 on failure.
  */
 typedef int (*fr_dcursor_remove_t)(fr_dlist_head_t *list, void *to_delete, void *uctx);
@@ -450,6 +451,7 @@ static inline int fr_dcursor_insert(fr_dcursor_t *cursor, void *v)
 static inline void *fr_dcursor_remove(fr_dcursor_t *cursor)
 {
        void *v;
+       int i = 0;
 
        if (!fr_cond_assert_msg(!cursor->is_const, "attempting to modify const list")) return NULL;
 
@@ -458,10 +460,15 @@ static inline void *fr_dcursor_remove(fr_dcursor_t *cursor)
        v = cursor->current;
        VALIDATE(v);
 
-       if (cursor->remove && (cursor->remove(cursor->dlist, v, cursor->mod_uctx) < 0)) return NULL;
+       if (cursor->remove) {
+               i = cursor->remove(cursor->dlist, v, cursor->mod_uctx);
+               if (i < 0) return NULL;
+       }
 
        dcursor_current_set(cursor, dcursor_next(cursor, cursor->iter, v));
 
+       if (i > 0) return v;
+
        fr_dlist_remove(cursor->dlist, v);
 
        return v;