From fbef1df1dba01447d6e28002a0d2885bf4192f34 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 27 Sep 2014 14:26:49 +0100 Subject: [PATCH] Provide dict_read_string_array Signed-off-by: Ian Jackson --- conffile.c | 25 +++++++++++++++++++++++++ secnet.h | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/conffile.c b/conffile.c index 24d7e25..0bd4e33 100644 --- a/conffile.c +++ b/conffile.c @@ -691,6 +691,31 @@ string_t dict_read_string(dict_t *dict, cstring_t key, bool_t required, return r; } +const char **dict_read_string_array(dict_t *dict, cstring_t key, + bool_t required, cstring_t desc, + struct cloc loc, const char *const *def) +{ + list_t *l; + const char **ra, **rap; + + l=dict_lookup(dict,key); + if (!l) { + if (!required) return (const char**)def; + cfgfatal(loc,desc,"required string list \"%s\" not found\n",key); + } + + int32_t ll=list_length(l); + ra=safe_malloc_ary(sizeof(*ra), ll+1, "dict_read_string_array"); + for (rap=ra; l; l=l->next,rap++) { + item_t *it=l->item; + if (it->type!=t_string) + cfgfatal(it->loc,desc,"\"%s\" entry must be a string\n",key); + *rap=it->data.string; + } + *rap=0; + return ra; +} + uint32_t dict_read_number(dict_t *dict, cstring_t key, bool_t required, cstring_t desc, struct cloc loc, uint32_t def) { diff --git a/secnet.h b/secnet.h index e70db53..8a60ee3 100644 --- a/secnet.h +++ b/secnet.h @@ -138,6 +138,14 @@ extern uint32_t dict_read_number(dict_t *dict, cstring_t key, bool_t required, /* return value can safely be assigned to int32_t */ extern bool_t dict_read_bool(dict_t *dict, cstring_t key, bool_t required, cstring_t desc, struct cloc loc, bool_t def); +const char **dict_read_string_array(dict_t *dict, cstring_t key, + bool_t required, cstring_t desc, + struct cloc loc, const char *const *def); + /* Return value is a NULL-terminated array obtained from malloc; + * Individual string values are still owned by config file machinery + * and must not be modified or freed. Returns NULL if key not + * found. */ + struct flagstr { cstring_t name; uint32_t value; -- 2.30.2