nterface-ip: remove superfluous iface check in interface_ip_set_enabled()
[project/netifd.git] / handler.c
index c5e47ad..8608a97 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -34,6 +34,9 @@ netifd_dir_push(int fd)
 static void
 netifd_dir_pop(int prev_fd)
 {
 static void
 netifd_dir_pop(int prev_fd)
 {
+       if (prev_fd < 0)
+               return;
+
        if (fchdir(prev_fd)) {}
        close(prev_fd);
 }
        if (fchdir(prev_fd)) {}
        close(prev_fd);
 }
@@ -105,7 +108,7 @@ netifd_parse_script_handler(const char *name, script_dump_cb cb)
                        tok = json_tokener_new();
 
                obj = json_tokener_parse_ex(tok, start, len);
                        tok = json_tokener_new();
 
                obj = json_tokener_parse_ex(tok, start, len);
-               if (!is_error(obj)) {
+               if (obj) {
                        netifd_init_script_handler(name, obj, cb);
                        json_object_put(obj);
                        json_tokener_free(tok);
                        netifd_init_script_handler(name, obj, cb);
                        json_object_put(obj);
                        json_tokener_free(tok);
@@ -128,10 +131,16 @@ void netifd_init_script_handlers(int dir_fd, script_dump_cb cb)
        int i, prev_fd;
 
        prev_fd = netifd_dir_push(dir_fd);
        int i, prev_fd;
 
        prev_fd = netifd_dir_push(dir_fd);
-       glob("./*.sh", 0, NULL, &g);
+       if (glob("./*.sh", 0, NULL, &g)) {
+               netifd_dir_pop(prev_fd);
+               return;
+       }
+
        for (i = 0; i < g.gl_pathc; i++)
                netifd_parse_script_handler(g.gl_pathv[i], cb);
        netifd_dir_pop(prev_fd);
        for (i = 0; i < g.gl_pathc; i++)
                netifd_parse_script_handler(g.gl_pathv[i], cb);
        netifd_dir_pop(prev_fd);
+
+       globfree(&g);
 }
 
 char *
 }
 
 char *
@@ -139,6 +148,7 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj
 {
        struct blobmsg_policy *attrs;
        char *str_buf, *str_cur;
 {
        struct blobmsg_policy *attrs;
        char *str_buf, *str_cur;
+       char const **validate;
        int str_len = 0;
        int i;
 
        int str_len = 0;
        int i;
 
@@ -147,7 +157,12 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj
        if (!attrs)
                return NULL;
 
        if (!attrs)
                return NULL;
 
+       validate = calloc(1, sizeof(char*) * config->n_params);
+       if (!validate)
+               goto error;
+
        config->params = attrs;
        config->params = attrs;
+       config->validate = validate;
        for (i = 0; i < config->n_params; i++) {
                json_object *cur, *name, *type;
 
        for (i = 0; i < config->n_params; i++) {
                json_object *cur, *name, *type;
 
@@ -178,15 +193,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;
        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;
 
                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);
        }
 
        return str_buf;
 
 error:
        free(attrs);
+       if (validate)
+               free(validate);
        config->n_params = 0;
        return NULL;
 }
        config->n_params = 0;
        return NULL;
 }