summaryrefslogtreecommitdiffhomepage
path: root/handler.c
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2014-02-17 12:12:22 +0000
committerFelix Fietkau <nbd@openwrt.org>2014-02-17 15:10:11 +0100
commitd5d6da8b108c61172ee72e65b86827a850d1be1d (patch)
tree0c58e0344ad50df16544044bafad29a30b04773b /handler.c
parent8663e9de716248bf72832aee70090f574b3ff5d2 (diff)
make netifd_handler_parse_config honour the luci validation passed from the backend scripts
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'handler.c')
-rw-r--r--handler.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/handler.c b/handler.c
index c5e47ad..f81a7c5 100644
--- a/handler.c
+++ b/handler.c
@@ -139,6 +139,7 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj
{
struct blobmsg_policy *attrs;
char *str_buf, *str_cur;
+ char const **validate;
int str_len = 0;
int i;
@@ -147,7 +148,12 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj
if (!attrs)
return NULL;
+ validate = calloc(1, sizeof(char*) * config->n_params);
+ if (!validate)
+ goto error;
+
config->params = attrs;
+ config->validate = validate;
for (i = 0; i < config->n_params; i++) {
json_object *cur, *name, *type;
@@ -178,15 +184,25 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj
str_cur = str_buf;
for (i = 0; i < config->n_params; i++) {
const char *name = attrs[i].name;
+ char *delim;
attrs[i].name = str_cur;
str_cur += sprintf(str_cur, "%s", name) + 1;
+ delim = strchr(attrs[i].name, ':');
+ if (delim) {
+ *delim = '\0';
+ validate[i] = ++delim;
+ } else {
+ validate[i] = NULL;
+ }
}
return str_buf;
error:
free(attrs);
+ if (validate)
+ free(validate);
config->n_params = 0;
return NULL;
}