Change fw3_parse_options() to indicate whether all options where parsed successfully
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 18 Nov 2013 12:36:45 +0000 (12:36 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 18 Nov 2013 12:36:45 +0000 (12:36 +0000)
options.c
options.h

index 6f96681561cbeec9b782da075dab1880a8568400..c212218f671be51c74929185f4fec9cd5c711a4c 100644 (file)
--- a/options.c
+++ b/options.c
@@ -853,7 +853,7 @@ fw3_parse_setmatch(void *ptr, const char *val, bool is_list)
 }
 
 
-void
+bool
 fw3_parse_options(void *s, const struct fw3_option *opts,
                   struct uci_section *section)
 {
@@ -863,6 +863,7 @@ fw3_parse_options(void *s, const struct fw3_option *opts,
        struct uci_option *o;
        const struct fw3_option *opt;
        struct list_head *dest;
+       bool valid = true;
 
        uci_foreach_element(&section->options, e)
        {
@@ -882,6 +883,7 @@ fw3_parse_options(void *s, const struct fw3_option *opts,
                                if (!opt->elem_size)
                                {
                                        warn_elem(e, "must not be a list");
+                                       valid = false;
                                }
                                else
                                {
@@ -895,6 +897,7 @@ fw3_parse_options(void *s, const struct fw3_option *opts,
                                                if (!opt->parse(dest, l->name, true))
                                                {
                                                        warn_elem(e, "has invalid value '%s'", l->name);
+                                                       valid = false;
                                                        continue;
                                                }
                                        }
@@ -910,7 +913,10 @@ fw3_parse_options(void *s, const struct fw3_option *opts,
                                if (!opt->elem_size)
                                {
                                        if (!opt->parse((char *)s + opt->offset, o->v.string, false))
+                                       {
                                                warn_elem(e, "has invalid value '%s'", o->v.string);
+                                               valid = false;
+                                       }
                                }
                                else
                                {
@@ -921,6 +927,7 @@ fw3_parse_options(void *s, const struct fw3_option *opts,
                                                if (!opt->parse(dest, p, true))
                                                {
                                                        warn_elem(e, "has invalid value '%s'", p);
+                                                       valid = false;
                                                        continue;
                                                }
                                        }
@@ -934,6 +941,8 @@ fw3_parse_options(void *s, const struct fw3_option *opts,
                if (!known)
                        warn_elem(e, "is unknown");
        }
+
+       return valid;
 }
 
 
index 88c98a0cedc915ca7c7be926bb004692786a631c..262a21b5385e22bf3a9eb2b5aadc47a5a5a0c2f2 100644 (file)
--- a/options.h
+++ b/options.h
@@ -514,7 +514,7 @@ bool fw3_parse_monthdays(void *ptr, const char *val, bool is_list);
 bool fw3_parse_mark(void *ptr, const char *val, bool is_list);
 bool fw3_parse_setmatch(void *ptr, const char *val, bool is_list);
 
-void fw3_parse_options(void *s, const struct fw3_option *opts,
+bool fw3_parse_options(void *s, const struct fw3_option *opts,
                        struct uci_section *section);
 
 const char * fw3_address_to_string(struct fw3_address *address,