When setting final configuration nodes, set the whole tree as final.

Prevents benign log message of parent nodes of final values being
redefined (which ends up having no affect as the final nodes
are protected from being removed).
pull/683/head
Jason Ish 13 years ago committed by Victor Julien
parent 729540673e
commit ab7091927e

@ -53,12 +53,13 @@ static ConfNode *root_backup = NULL;
* nodes is usually part of application initialization. * nodes is usually part of application initialization.
* *
* \param name The name of the configuration node to get. * \param name The name of the configuration node to get.
* \param final Flag to set created nodes as final or not.
* *
* \retval The existing configuration node if it exists, or a newly * \retval The existing configuration node if it exists, or a newly
* created node for the provided name. On error, NULL will be returned. * created node for the provided name. On error, NULL will be returned.
*/ */
static ConfNode * static ConfNode *
ConfGetNodeOrCreate(char *name) ConfGetNodeOrCreate(char *name, int final)
{ {
ConfNode *parent = root; ConfNode *parent = root;
ConfNode *node = NULL; ConfNode *node = NULL;
@ -86,6 +87,7 @@ ConfGetNodeOrCreate(char *name)
} }
node->name = SCStrdup(key); node->name = SCStrdup(key);
node->parent = parent; node->parent = parent;
node->final = final;
TAILQ_INSERT_TAIL(&parent->head, node, next); TAILQ_INSERT_TAIL(&parent->head, node, next);
} }
key = next; key = next;
@ -220,7 +222,7 @@ ConfGetRootNode(void)
int int
ConfSet(char *name, char *val) ConfSet(char *name, char *val)
{ {
ConfNode *node = ConfGetNodeOrCreate(name); ConfNode *node = ConfGetNodeOrCreate(name, 0);
if (node == NULL || node->final) { if (node == NULL || node->final) {
return 0; return 0;
} }
@ -247,7 +249,7 @@ ConfSet(char *name, char *val)
int int
ConfSetFinal(char *name, char *val) ConfSetFinal(char *name, char *val)
{ {
ConfNode *node = ConfGetNodeOrCreate(name); ConfNode *node = ConfGetNodeOrCreate(name, 1);
if (node == NULL) { if (node == NULL) {
return 0; return 0;
} }
@ -1253,7 +1255,7 @@ ConfGetNodeOrCreateTest(void)
/* Get a node that should not exist, give it a value, re-get it /* Get a node that should not exist, give it a value, re-get it
* and make sure the second time it returns the existing node. */ * and make sure the second time it returns the existing node. */
node = ConfGetNodeOrCreate("node0"); node = ConfGetNodeOrCreate("node0", 0);
if (node == NULL) { if (node == NULL) {
fprintf(stderr, "returned null\n"); fprintf(stderr, "returned null\n");
goto end; goto end;
@ -1267,7 +1269,7 @@ ConfGetNodeOrCreateTest(void)
goto end; goto end;
} }
node->val = SCStrdup("node0"); node->val = SCStrdup("node0");
node = ConfGetNodeOrCreate("node0"); node = ConfGetNodeOrCreate("node0", 0);
if (node == NULL) { if (node == NULL) {
fprintf(stderr, "returned null\n"); fprintf(stderr, "returned null\n");
goto end; goto end;
@ -1282,7 +1284,7 @@ ConfGetNodeOrCreateTest(void)
} }
/* Do the same, but for something deeply nested. */ /* Do the same, but for something deeply nested. */
node = ConfGetNodeOrCreate("parent.child.grandchild"); node = ConfGetNodeOrCreate("parent.child.grandchild", 0);
if (node == NULL) { if (node == NULL) {
fprintf(stderr, "returned null\n"); fprintf(stderr, "returned null\n");
goto end; goto end;
@ -1296,7 +1298,7 @@ ConfGetNodeOrCreateTest(void)
goto end; goto end;
} }
node->val = SCStrdup("parent.child.grandchild"); node->val = SCStrdup("parent.child.grandchild");
node = ConfGetNodeOrCreate("parent.child.grandchild"); node = ConfGetNodeOrCreate("parent.child.grandchild", 0);
if (node == NULL) { if (node == NULL) {
fprintf(stderr, "returned null\n"); fprintf(stderr, "returned null\n");
goto end; goto end;
@ -1311,8 +1313,8 @@ ConfGetNodeOrCreateTest(void)
} }
/* Test that 2 child nodes have the same root. */ /* Test that 2 child nodes have the same root. */
ConfNode *child1 = ConfGetNodeOrCreate("parent.kids.child1"); ConfNode *child1 = ConfGetNodeOrCreate("parent.kids.child1", 0);
ConfNode *child2 = ConfGetNodeOrCreate("parent.kids.child2"); ConfNode *child2 = ConfGetNodeOrCreate("parent.kids.child2", 0);
if (child1 == NULL || child2 == NULL) { if (child1 == NULL || child2 == NULL) {
fprintf(stderr, "returned null\n"); fprintf(stderr, "returned null\n");
goto end; goto end;

Loading…
Cancel
Save