*/
static bool cf_template_merge(CONF_SECTION *cs, CONF_SECTION const *template)
{
- CONF_ITEM *ci = NULL;
-
if (!cs || !template) return true;
cs->template = NULL;
* current section. But only if the entries don't
* already exist in the current section.
*/
- while ((ci = fr_dlist_next(&template->item.children, ci))) {
+ cf_item_foreach(&template->item, ci) {
if (ci->type == CONF_ITEM_PAIR) {
CONF_PAIR *cp1, *cp2;
*/
int cf_section_pass2(CONF_SECTION *cs)
{
- CONF_ITEM *ci = NULL;
-
- while ((ci = fr_dlist_next(&cs->item.children, ci))) {
+ cf_item_foreach(&cs->item, ci) {
char const *value;
CONF_PAIR *cp;
char buffer[8192];
cp->value = talloc_typed_strdup(cp, value);
}
- ci = NULL;
- while ((ci = fr_dlist_next(&cs->item.children, ci))) {
+ cf_item_foreach(&cs->item, ci) {
if (ci->type != CONF_ITEM_SECTION) continue;
if (cf_section_pass2(cf_item_to_section(ci)) < 0) return -1;
int cf_section_write(FILE *fp, CONF_SECTION *cs, int depth)
{
- CONF_ITEM *ci = NULL;
-
if (!fp || !cs) return -1;
/*
* Loop over the children. Either recursing, or opening
* a new file.
*/
- while ((ci = fr_dlist_next(&cs->item.children, ci))) {
+ cf_item_foreach(&cs->item, ci) {
switch (ci->type) {
case CONF_ITEM_SECTION:
cf_section_write(fp, cf_item_to_section(ci), depth + 1);
static void cf_section_parse_warn(CONF_SECTION *cs)
{
- CONF_ITEM *ci = NULL;
-
- while ((ci = fr_dlist_next(&cs->item.children, ci))) {
+ cf_item_foreach(&cs->item, ci) {
/*
* Don't recurse on sections. We can only safely
* check conf pairs at the same level as the
* No ident1, iterate over the child list
*/
if (IS_WILDCARD(ident1)) {
- CONF_ITEM *ci = NULL;
-
- while ((ci = fr_dlist_next(&parent->children, ci))) {
+ cf_item_foreach(parent, ci) {
if (find->type != ci->type) continue;
- if (cf_ident2_cmp(find, ci) == 0) break;
+ if (cf_ident2_cmp(find, ci) == 0) return ci;
}
- return ci;
+ return NULL;
}
/*
{
CONF_SECTION *new, *subcs;
CONF_PAIR *cp;
- CONF_ITEM *ci = NULL;
new = cf_section_alloc(ctx, parent, name1, name2);
cf_filename_set(new, cs->item.filename);
cf_lineno_set(new, cs->item.lineno);
- while ((ci = fr_dlist_next(&cs->item.children, ci))) {
+ cf_item_foreach(&cs->item, ci) {
switch (ci->type) {
case CONF_ITEM_SECTION:
subcs = cf_item_to_section(ci);
*/
void _cf_debug(CONF_ITEM const *ci)
{
- CONF_ITEM const *child = NULL;
-
/*
* Print summary of the item
*/
*/
DEBUG("CHILDREN");
- while ((child = fr_dlist_next(&ci->children, child))) {
+ cf_item_foreach(ci, child) {
char const *in_ident1, *in_ident2;
in_ident1 = fr_rb_find(ci->ident1, child) == child? "in ident1 " : "";
#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);
+/** Iterate over the contents of a list
+ *
+ * @param[in] _ci to iterate over.
+ * @param[in] _iter Name of iteration variable.
+ * Will be declared in the scope of the loop.
+ */
+#define cf_item_foreach(_ci, _iter) \
+ for (CONF_ITEM *_iter = fr_dlist_head(&(_ci)->children); _iter; _iter = fr_dlist_next(&(_ci)->children, _iter))
+
#define cf_root(_cf) _cf_root(CF_TO_ITEM(_cf))
CONF_SECTION *_cf_root(CONF_ITEM const *ci);