From: Ben Pfaff Date: Tue, 6 Jan 2009 00:01:32 +0000 (-0800) Subject: vswitchd: New function cfg_is_valid(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adf90e17cef41623a4e84218021cd1d3b79289ac;p=openvswitch vswitchd: New function cfg_is_valid(). --- diff --git a/vswitchd/cfg.c b/vswitchd/cfg.c index 757f214d..545e6e02 100644 --- a/vswitchd/cfg.c +++ b/vswitchd/cfg.c @@ -77,6 +77,7 @@ static bool is_int(const char *); 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 @@ -172,6 +173,26 @@ cfg_has(const char *key_, ...) 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 @@ -749,7 +770,6 @@ get_nth_value(int idx, const char *key) return idx < q - p ? extract_value(p[idx]) : NULL; } -#if 0 static bool is_type(const char *s, enum cfg_flags flags) { @@ -763,4 +783,3 @@ is_type(const char *s, enum cfg_flags flags) || (flags & CFG_IP && inet_aton(s, &addr)) || (flags & CFG_MAC && parse_mac(s, mac))); } -#endif diff --git a/vswitchd/cfg.h b/vswitchd/cfg.h index 1cee0560..d1111031 100644 --- a/vswitchd/cfg.h +++ b/vswitchd/cfg.h @@ -62,6 +62,7 @@ enum cfg_flags { 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);