projects
/
project
/
ubox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
logread: ensure that the len < sizeof(struct blob_attr) check runs before trying...
[project/ubox.git]
/
validate
/
cli.c
diff --git
a/validate/cli.c
b/validate/cli.c
index
a2a82ed
..
07d2b2e
100644
(file)
--- a/
validate/cli.c
+++ b/
validate/cli.c
@@
-22,9
+22,9
@@
print_usage(char *argv)
static const char *
bool_to_num(const char *val)
{
static const char *
bool_to_num(const char *val)
{
- if (!strcmp(val, "0") || !strcmp(val, "off") || !strcmp(val, "false") || !strcmp(val, "disabled"))
+ if (!strcmp(val, "0") || !strcmp(val, "off") || !strcmp(val, "false") || !strcmp(val, "
no") || !strcmp(val, "
disabled"))
return "0";
return "0";
- if (!strcmp(val, "1") || !strcmp(val, "on") || !strcmp(val, "true") || !strcmp(val, "enabled"))
+ if (!strcmp(val, "1") || !strcmp(val, "on") || !strcmp(val, "true") || !strcmp(val, "
yes") || !strcmp(val, "
enabled"))
return "1";
return "";
return "1";
return "";
@@
-105,12
+105,12
@@
export_value(enum dt_type type, const char *name, const char *val)
printf("; ");
}
printf("; ");
}
-static
void
+static
int
validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
{
int i = 0;
bool empty = true, first = true;
validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
{
int i = 0;
bool empty = true, first = true;
- enum dt_type type;
+ enum dt_type type
= DT_INVALID
;
struct uci_element *e;
struct uci_option *opt = ptr->o;
struct uci_element *e;
struct uci_option *opt = ptr->o;
@@
-128,7
+128,7
@@
validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
if (empty)
{
export_value(DT_STRING, ptr->option, def);
if (empty)
{
export_value(DT_STRING, ptr->option, def);
- return;
+ return
0
;
}
uci_foreach_element(&opt->v.list, e)
}
uci_foreach_element(&opt->v.list, e)
@@
-159,7
+159,7
@@
validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
if (!opt->v.string || !*opt->v.string)
{
export_value(DT_STRING, ptr->option, def);
if (!opt->v.string || !*opt->v.string)
{
export_value(DT_STRING, ptr->option, def);
- return;
+ return
0
;
}
type = dt_parse(expr, opt->v.string);
}
type = dt_parse(expr, opt->v.string);
@@
-169,9
+169,10
@@
validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
ptr->package, ptr->section, ptr->option, opt->v.string,
expr, type ? "true" : "false");
}
ptr->package, ptr->section, ptr->option, opt->v.string,
expr, type ? "true" : "false");
}
+ return type ? 0 : -1;
}
}
-static
void
+static
int
validate_option(struct uci_context *ctx, char *package, char *section, char *option)
{
char *opt, *expr, *def;
validate_option(struct uci_context *ctx, char *package, char *section, char *option)
{
char *opt, *expr, *def;
@@
-180,7
+181,7
@@
validate_option(struct uci_context *ctx, char *package, char *section, char *opt
if (!parse_tuple(option, &opt, &expr, &def))
{
fprintf(stderr, "%s is not a valid option\n", option);
if (!parse_tuple(option, &opt, &expr, &def))
{
fprintf(stderr, "%s is not a valid option\n", option);
- return;
+ return
-1
;
}
ptr.package = package;
}
ptr.package = package;
@@
-192,10
+193,10
@@
validate_option(struct uci_context *ctx, char *package, char *section, char *opt
(ptr.last->type != UCI_TYPE_OPTION))
{
export_value(DT_STRING, opt, def);
(ptr.last->type != UCI_TYPE_OPTION))
{
export_value(DT_STRING, opt, def);
- return;
+ return
0
;
}
}
- validate_value(&ptr, expr, def);
+
return
validate_value(&ptr, expr, def);
}
int
}
int
@@
-206,7
+207,7
@@
main(int argc, char **argv)
char *opt, *expr, *def;
int len = argc - 4;
enum dt_type rv;
char *opt, *expr, *def;
int len = argc - 4;
enum dt_type rv;
- int i;
+ int i
, rc
;
if (argc == 3) {
rv = dt_parse(argv[1], argv[2]);
if (argc == 3) {
rv = dt_parse(argv[1], argv[2]);
@@
-243,8
+244,12
@@
main(int argc, char **argv)
if (uci_load(ctx, argv[1], &package))
return -1;
if (uci_load(ctx, argv[1], &package))
return -1;
- for (i = 0; i < len; i++)
- validate_option(ctx, argv[1], argv[3], argv[4 + i]);
+ rc = 0;
+ for (i = 0; i < len; i++) {
+ if (validate_option(ctx, argv[1], argv[3], argv[4 + i])) {
+ rc = -1;
+ }
+ }
- return
0
;
+ return
rc
;
}
}