summaryrefslogtreecommitdiffstats
path: root/libdm/libdm-config.c
diff options
context:
space:
mode:
authorPetr Rockai <prockai@redhat.com>2011-08-31 15:19:19 +0000
committerPetr Rockai <prockai@redhat.com>2011-08-31 15:19:19 +0000
commit97a4b5165e172e91a38e48790c769e29360fe768 (patch)
tree5a8b78ec9b9e35c47f9ae9d701180b47e9774315 /libdm/libdm-config.c
parentc0de52fd2dc7acff53f811fb2b460f9047d8a4eb (diff)
downloadlvm2-97a4b5165e172e91a38e48790c769e29360fe768.tar.gz
lvm2-97a4b5165e172e91a38e48790c769e29360fe768.tar.xz
lvm2-97a4b5165e172e91a38e48790c769e29360fe768.zip
Replace const usage of dm_config_find_node with more appropriate value-lookup
functionality. A number of bugs (copied and pasted all over the code) should disappear: - most string lookup based on dm_config_find_node would segfault when encountering a non-zero integer (the intention there was to print an error message instead) - check for required sections in metadata would have been satisfied by values as well (i.e. not sections) - encountering a section in place of expected flag value would have segfaulted (due to assumed but unchecked cn->v != NULL)
Diffstat (limited to 'libdm/libdm-config.c')
-rw-r--r--libdm/libdm-config.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index d6a3fe69..d9e41df5 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -973,7 +973,7 @@ static int _find_config_bool(const void *start, _node_lookup_fn find,
* node-based lookup
**/
-struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn,
+struct dm_config_node *dm_config_find_node(struct dm_config_node *cn,
const char *path)
{
return _find_config_node(cn, path);
@@ -1038,11 +1038,11 @@ int dm_config_tree_find_bool(const struct dm_config_tree *cft, const char *path,
int dm_config_get_uint32(const struct dm_config_node *cn, const char *path,
- uint32_t *result)
+ uint32_t *result)
{
const struct dm_config_node *n;
- n = dm_config_find_node(cn, path);
+ n = _find_config_node(cn, path);
if (!n || !n->v || n->v->type != DM_CFG_INT)
return 0;
@@ -1056,7 +1056,7 @@ int dm_config_get_uint64(const struct dm_config_node *cn, const char *path,
{
const struct dm_config_node *n;
- n = dm_config_find_node(cn, path);
+ n = _find_config_node(cn, path);
if (!n || !n->v || n->v->type != DM_CFG_INT)
return 0;
@@ -1070,7 +1070,7 @@ int dm_config_get_str(const struct dm_config_node *cn, const char *path,
{
const struct dm_config_node *n;
- n = dm_config_find_node(cn, path);
+ n = _find_config_node(cn, path);
if (!n || !n->v || n->v->type != DM_CFG_STRING)
return 0;
@@ -1079,6 +1079,39 @@ int dm_config_get_str(const struct dm_config_node *cn, const char *path,
return 1;
}
+int dm_config_get_list(const struct dm_config_node *cn, const char *path,
+ const struct dm_config_value **result)
+{
+ const struct dm_config_node *n;
+
+ n = _find_config_node(cn, path);
+ /* TODO when we represent single-item lists consistently, add a check
+ * for n->v->next != NULL */
+ if (!n || !n->v)
+ return 0;
+
+ *result = n->v;
+ return 1;
+}
+
+int dm_config_get_section(const struct dm_config_node *cn, const char *path,
+ const struct dm_config_node **result)
+{
+ const struct dm_config_node *n;
+
+ n = _find_config_node(cn, path);
+ if (!n || n->v)
+ return 0;
+
+ *result = n;
+ return 1;
+}
+
+int dm_config_has_node(const struct dm_config_node *cn, const char *path)
+{
+ return _find_config_node(cn, path) ? 1 : 0;
+}
+
/*
* Convert a token type to the char it represents.
*/