chiark / gitweb /
Provide dict_read_string_array
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Sep 2014 13:26:49 +0000 (14:26 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Sep 2014 15:00:43 +0000 (16:00 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
conffile.c
secnet.h

index 24d7e25b154e1ec30eaf8b48ce14b9179007b713..0bd4e33bb3d3f9e5ee4c709e3ca701485ab75377 100644 (file)
@@ -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)
 {
index e70db53a625175efe74d9dac31e6aae691c0a1a7..8a60ee30546ed4382c191f872e2f9cc04f32dc90 100644 (file)
--- 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;