static bool is_bool(const char *);
static const char *extract_value(const char *key);
static const char *get_nth_value(int idx, const char *key);
+static bool is_type(const char *s, enum cfg_flags);
/* Adds 'file_name' to the set of files or directories that are read by
* cfg_read(). Returns 0 on success, otherwise a positive errno value if
return retval;
}
+bool
+cfg_is_valid(enum cfg_flags flags, const char *key_, ...)
+{
+ char *key, **first, **last, **p;
+ size_t n;
+ bool retval;
+
+ FORMAT_KEY(key_, key);
+ first = find_key_le(key);
+ last = find_key_ge(key);
+ n = last - first;
+ retval = ((!(flags & CFG_REQUIRED) || n)
+ && (!(flags & CFG_MULTIPLE) || n <= 1));
+ for (p = first; retval && p < last; p++) {
+ retval = is_type(strchr(*p, '=') + 1, flags);
+ }
+ free(key);
+ return retval;
+}
+
/* Returns true if the configuration includes at least one key whose name
* begins with 'section' followed by a dot. */
bool
return idx < q - p ? extract_value(p[idx]) : NULL;
}
-#if 0
static bool
is_type(const char *s, enum cfg_flags flags)
{
|| (flags & CFG_IP && inet_aton(s, &addr))
|| (flags & CFG_MAC && parse_mac(s, mac)));
}
-#endif
void cfg_register(const char *key_spec, enum cfg_flags);
bool cfg_has(const char *key, ...) PRINTF_FORMAT(1, 2);
+bool cfg_is_valid(enum cfg_flags, const char *key, ...) PRINTF_FORMAT(2, 3);
bool cfg_has_section(const char *key, ...) PRINTF_FORMAT(1, 2);
int cfg_count(const char *key, ...) PRINTF_FORMAT(1, 2);