return prev;
}
+/** Return the next child of the CONF_ITEM
+ *
+ * @param[in] ci to return children from.
+ * @param[in] curr child to start searching from.
+ * @return
+ * - The next #CONF_ITEM that's a child of cs.
+ * - NULL if no more #CONF_ITEM.
+ */
+CONF_ITEM *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *curr)
+{
+ if (!ci) return NULL;
+
+ return fr_dlist_next(&ci->children, curr);
+}
+
/** Return the next child of cs
*
* @param[in] ci to return children from.
- * @param[in] prev child to start searching from.
+ * @param[in] curr child to start searching from.
* @return
* - The next #CONF_ITEM that's a child of cs.
* - NULL if no more #CONF_ITEM.
*/
-CONF_ITEM *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *prev)
+CONF_ITEM *_cf_item_prev(CONF_ITEM const *ci, CONF_ITEM const *curr)
{
if (!ci) return NULL;
- return fr_dlist_next(&ci->children, prev);
+ return fr_dlist_prev(&ci->children, curr);
}
/** Initialize a CONF_ITEM, so we don't have repeated code
#define cf_item_remove(_parent, _child) _cf_item_remove(CF_TO_ITEM(_parent), CF_TO_ITEM(_child))
CONF_ITEM *_cf_item_remove(CONF_ITEM *parent, CONF_ITEM *child);
-#define cf_item_next(_ci, _prev) _cf_item_next(CF_TO_ITEM(_ci), _prev)
-CONF_ITEM *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *prev);
+#define cf_item_next(_ci, _curr) _cf_item_next(CF_TO_ITEM(_ci), _curr)
+CONF_ITEM *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *curr);
+
+#define cf_item_prev(_ci, _curr) _cf_item_prev(CF_TO_ITEM(_ci), _curr)
+CONF_ITEM *_cf_item_prev(CONF_ITEM const *ci, CONF_ITEM const *prev);
#define cf_root(_cf) _cf_root(CF_TO_ITEM(_cf))
CONF_SECTION *_cf_root(CONF_ITEM const *ci);
if (!static_cs) {
static_cs = cf_section_alloc(modules, NULL, "static", NULL);
cf_section_foreach(modules, mod_cs) {
- CONF_SECTION *prev;
+ CONF_ITEM *prev;
/*
* Skip over the dynamic section
* the dynamic section into the static
* section for backwards compatibility.
*/
- prev = cf_item_to_section(cf_item_remove(modules, mod_cs));
+ prev = cf_item_remove(modules, mod_cs);
cf_item_add(static_cs, mod_cs);
- mod_cs = prev;
+
+ /*
+ * Find the previous item that's a section
+ */
+ while (prev && !cf_item_is_section(prev)) prev = cf_item_prev(modules, prev);
+
+ /*
+ * Resume iterating from that item
+ */
+ mod_cs = cf_item_to_section(prev);
}
cf_item_add(modules, static_cs);
}