on review, most of the calls to cf_section_add() were wrong.
the child section was already added to the parent section by
_cf_section_alloc(). There were many, many, calls to
cf_item_add() or cf_section_add() which resulted in the
section being added twice.
However, cf_pair_alloc() and cf_data_alloc() did not add the item
to the parent.
In the interest of less code and fewer errors, we've removed
cf_section_add() and cf_pair_add(). The calls to cf_item_add()
are now done only from the alloc functions.
We still have many calls to cf_data_add(), because that function
is in fact allocating *and* adding the CONF_DATA items.
cs = cf_section_alloc(ctx, NULL, "client", name);
cp = cf_pair_alloc(cs, "ipaddr", ip, T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
- cf_pair_add(cs, cp);
-
cp = cf_pair_alloc(cs, "secret", "supersecret", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING);
- cf_pair_add(cs, cp);
-
cp = cf_pair_alloc(cs, "nas_type", "test", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING);
- cf_pair_add(cs, cp);
-
cp = cf_pair_alloc(cs, "shortname", "test", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING);
- cf_pair_add(cs, cp);
-
cp = cf_pair_alloc(cs, "groups", "foo", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING);
- cf_pair_add(cs, cp);
-
cp = cf_pair_alloc(cs, "groups", "bar", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING);
- cf_pair_add(cs, cp);
-
cp = cf_pair_alloc(cs, "groups", "baz", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING);
- cf_pair_add(cs, cp);
client = client_afrom_cs(ctx, cs, NULL);
if (!client) {
cf_filename_set(subcs, ci->filename);
cf_lineno_set(subcs, ci->lineno);
- cf_item_add(outer_cs, &(subcs->item));
ptr = next + 1;
cf_filename_set(cp2, cp1->item.filename);
cf_lineno_set(cp2, cp1->item.lineno);
- cf_item_add(cs, &(cp2->item));
continue;
}
cf_filename_set(subcs2, subcs1->item.filename);
cf_lineno_set(subcs2, subcs1->item.lineno);
- cf_item_add(cs, &(subcs2->item));
continue;
}
cf_filename_set(cp, filename);
cf_lineno_set(cp, lineno);
cp->pass2 = pass2;
- cf_item_add(parent, &(cp->item));
cd = cf_data_find(CF_TO_ITEM(parent), CONF_PARSER, attr);
if (!cd) return 0;
p = strrchr(cp->value, FR_DIR_SEP);
if (p) *p = '\0';
- cf_item_add(cs, &(cp->item));
-
MEM(tree = rbtree_talloc_alloc(cs, cf_file_t, node, _inode_cmp, NULL, 0));
cf_data_add(cs, tree, "filename", false);
ret = func(value_ctx, entry, base, cf_pair_to_item(cp), rule);
if (ret < 0) {
talloc_free(array);
- talloc_free(dflt_cp);
return -1;
}
cp->parsed = true;
}
ret = func(ctx, out, base, cf_pair_to_item(cp), rule);
- if (ret < 0) {
- talloc_free(dflt_cp);
- return -1;
- }
+ if (ret < 0) return -1;
cp->parsed = true;
}
- /*
- * If we created a default cp and succeeded
- * in parsing the dflt value, add the new
- * cp to the enclosing section.
- */
- if (dflt_cp) {
- cf_item_add(cs, &(dflt_cp->item));
- return 1;
- }
-
return 0;
}
talloc_free(new);
return NULL;
}
- cf_section_add(new, subcs);
break;
case CONF_ITEM_PAIR:
talloc_free(new);
return NULL;
}
- cf_pair_add(new, cp);
break;
case CONF_ITEM_DATA: /* Skip data */
return new;
}
-/** Add a section as a child of another section
- *
- * @param[in] parent section we're adding to.
- * @param[in] cs we're adding.
- *
- * @hidecallergraph
- */
-void cf_section_add(CONF_SECTION *parent, CONF_SECTION *cs)
-{
- cf_item_add(parent, &(cs->item));
-}
/** Return the next child that's a #CONF_SECTION
*
if (!cp->value) goto error;
}
+ cf_item_add(parent, &(cp->item));
return cp;
}
return 0;
}
-/** Add a configuration pair to a section
- *
- * @param[in] parent section to add pair to.
- * @param[in] cp to add.
- */
-void cf_pair_add(CONF_SECTION *parent, CONF_PAIR *cp)
-{
- cf_item_add(parent, cf_pair_to_item(cp));
-}
/** Mark a pair as parsed
*
talloc_set_destructor(cd, _cd_free);
}
+ cf_item_add(parent, cd);
return cd;
}
cd->is_talloced = true;
cf_filename_set(cd, filename);
cf_lineno_set(cd, lineno);
- cf_item_add(ci, cd);
return cd;
}
cd->is_talloced = false;
cf_filename_set(cd, filename);
cf_lineno_set(cd, lineno);
- cf_item_add(ci, cd);
return cd;
}
char const *filename, int lineno);
CONF_SECTION *cf_section_dup(TALLOC_CTX *ctx, CONF_SECTION *parent, CONF_SECTION const *cs,
char const *name1, char const *name2, bool copy_meta);
-void cf_section_add(CONF_SECTION *parent, CONF_SECTION *cs);
/** @hidecallergraph */
CONF_SECTION *cf_section_next(CONF_SECTION const *cs, CONF_SECTION const *prev);
/** @hidecallergraph */
fr_token_t op, fr_token_t lhs_type, fr_token_t rhs_type);
CONF_PAIR *cf_pair_dup(CONF_SECTION *parent, CONF_PAIR *cp);
int cf_pair_replace(CONF_SECTION *cs, CONF_PAIR *cp, char const *value);
-void cf_pair_add(CONF_SECTION *parent, CONF_PAIR *cp);
void cf_pair_mark_parsed(CONF_PAIR *cp);
CONF_PAIR *cf_pair_next(CONF_SECTION const *cs, CONF_PAIR const *prev);
CONF_PAIR *cf_pair_find(CONF_SECTION const *cs, char const *name);
cc = cf_section_find(out, cf_section_name1(cs), cf_section_name2(cs));
if (!cc) {
cc = cf_section_alloc(out, out, cf_section_name1(cs), cf_section_name2(cs));
- cf_section_add(out, cc);
if (!cc) return -1;
}
}
RDEBUG2("%s = %s", cf_pair_attr(cp), cf_pair_value(cp));
- cf_pair_add(cs, cp);
}
REXDENT();
cp = cf_pair_alloc(cs, name, enabled ? "yes" : "no",
T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
if (!cp) return -1;
- cf_pair_add(cs, cp);
}
return 0;
cp = cf_pair_alloc(cs, name, version, T_OP_EQ, T_BARE_WORD, T_SINGLE_QUOTED_STRING);
if (!cp) return -1;
- cf_pair_add(cs, cp);
} else {
WARN("Replacing user version.%s (%s) with %s", name, cf_pair_value(old), version);
}
} else {
MEM(cp = cf_pair_alloc(cs, "name", config->name, T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING));
- cf_pair_add(cs, cp);
}
}
*/
if (!transport_cs) {
transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL);
- cf_section_add(listen_cs, transport_cs);
inst->io.app_io_conf = transport_cs;
}
*/
if (!transport_cs) {
transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL);
- cf_section_add(listen_cs, transport_cs);
inst->io.app_io_conf = transport_cs;
}
cs = cf_section_alloc(NULL, NULL, "client", "ldap");
cp = cf_pair_alloc(cs, "ipaddr", fr_inet_ntop(buffer, sizeof(buffer), &inst->dst_ipaddr),
T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
- cf_pair_add(cs, cp);
cp = cf_pair_alloc(cs, "secret", "fake", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
- cf_pair_add(cs, cp);
client = client_afrom_cs(inst, cs, NULL);
if (!client) {
ERROR("Failed creating server pair");
fr_exit_now(EXIT_FAILURE);
}
- cf_pair_add(conf->cs, cp);
/*
* Unescape sequences in the pool name
cp = cf_pair_find(pool_cs, "start");
if (!cp) {
cp = cf_pair_alloc(pool_cs, "start", "0", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
- cf_pair_add(pool_cs, cp);
}
cp = cf_pair_find(pool_cs, "spare");
if (!cp) {
cp = cf_pair_alloc(pool_cs, "spare", "0", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
- cf_pair_add(pool_cs, cp);
}
cp = cf_pair_find(pool_cs, "min");
if (!cp) {
cp = cf_pair_alloc(pool_cs, "min", "0", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
- cf_pair_add(pool_cs, cp);
}
if (driver_init(conf, conf->cs, &conf->driver) < 0) {