]> pilppa.com Git - libplp.git/commitdiff
Removed unrequired code
authorMika Laitio <lamikr@pilppa.org>
Mon, 11 Apr 2011 15:02:57 +0000 (18:02 +0300)
committerMika Laitio <lamikr@pilppa.org>
Mon, 11 Apr 2011 15:02:57 +0000 (18:02 +0300)
uci_lookup_option for section was not needed when saving config-data.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/config.c
src_test/test_config2.c

index df77e3b236b3660b7658a2945e82c92786365d2a..4e51b43ca78db17ddc946968775567b2b6df2adf 100644 (file)
@@ -50,18 +50,15 @@ bool set_config_value(const char *conf_dir_name,
        struct uci_package      *pkg;
        struct uci_section      *sct;
        struct uci_section      *tmp_sct;
-       struct uci_option       *opt;
        int                     err_flg;
        char                    *fname;
        int                     b_count;
-       bool                    save;
        struct uci_element      *elem;
        struct uci_ptr          ptr;
        FILE                    *fp;
        bool                    ret_val;
 
        ret_val = false;
-       save    = false;
        if ((conf_dir_name != NULL) &&
            (conf_file_name != NULL) &&
            (section_type != NULL) &&
@@ -109,45 +106,39 @@ bool set_config_value(const char *conf_dir_name,
                                                }
                                        }
                                        if (err_flg == 0) {
-                                               opt     = uci_lookup_option(ctx, sct, key);
-                                               if (opt != NULL) {
-                                                       memset(&ptr, 0, sizeof(ptr));
-                                                       ptr.package     = pkg->e.name;
-                                                       ptr.section     = sct->e.name;
-                                                       ptr.option      = key;
+                                               memset(&ptr, 0, sizeof(ptr));
+                                               ptr.package     = pkg->e.name;
+                                               ptr.section     = sct->e.name;
+                                               ptr.option      = key;
 
-                                                       if (uci_lookup_ptr(ctx, &ptr, NULL, false) == UCI_OK) {
-                                                               ptr.value       = value;
-                                                               uci_set(ctx, &ptr);
-                                                               save    = true;
-                                                       }
+                                               if (uci_lookup_ptr(ctx, &ptr, NULL, false) == UCI_OK) {
+                                                       ptr.value       = value;
+                                                       uci_set(ctx, &ptr);
+                                                       uci_save(ctx, pkg);
+                                                       ret_val         = true;
+                                                       log_debug("Created configuration section %s to configuration file: %s\n", section_name, fname);
                                                }
                                                else {
-                                                       opt     = uci_alloc_option(sct, key, value);
-                                                       save    = true;
-                                               }
-                                               if (save == true) {
-                                                       uci_save(ctx, pkg);
+                                                       log_error("Could not write to configuration file: %s\n. Could not look-up pointer for package %s section %s.\n", fname, pkg->e.name, sct->e.name);
                                                }
                                                uci_free_context(ctx);
-                                               ret_val = true;
                                        }
                                        else {
-                                               log_error("Could not write to configuration file: %s\n. Could not create section %s.", fname, section_name);
+                                               log_error("Could not write to configuration file: %s. Could not create section %s.\n", fname, section_name);
                                        }
                                }
                                else {
-                                       log_error("Could not write to configuration file: %s\n. File does not exist or is not writable.", fname);
+                                       log_error("Could not write to configuration file: %s. File does not exist or is not writable\n.", fname);
                                }
                        }
                        free(fname);
                }
                else {
-                       log_error("Could not change config value, out of memory");
+                       log_error("Could not change config value, out of memory\n");
                }
        }
        else {
-               log_error("Could not change config value, invalid parameters");
+               log_error("Could not change config value, invalid parameters\n");
        }
        return ret_val;
 }
index 32e1d931a467592e3e71afba11444f6de8f104c8..dfd0987c840d6bcf606ff11cee031c17933fb4d7 100644 (file)
@@ -84,18 +84,15 @@ bool set_config_value2(const char *conf_dir_name,
        struct uci_package      *pkg;
        struct uci_section      *sct;
        struct uci_section      *tmp_sct;
-       struct uci_option       *opt;
        int                     err_flg;
        char                    *fname;
        int                     b_count;
-       bool                    save;
        struct uci_element      *elem;
        struct uci_ptr          ptr;
        FILE                    *fp;
        bool                    ret_val;
 
        ret_val = false;
-       save    = false;
        if ((conf_dir_name != NULL) &&
            (conf_file_name != NULL) &&
            (section_type != NULL) &&
@@ -128,7 +125,6 @@ bool set_config_value2(const char *conf_dir_name,
                                                }
                                        }
                                        if (sct == NULL) {
-                                               log_debug("Creating configuration section %s to configuration file: %s\n", section_name, fname);
                                                //err_flg       = uci_add_named_section(ctx, pkg, section_type, section_name, &sct);
                                                //err_flg       = uci_add_section(ctx, pkg, section_name, &sct);
                                                err_flg = uci_create_named_section(ctx, conf_file_name, section_type, section_name);
@@ -143,45 +139,39 @@ bool set_config_value2(const char *conf_dir_name,
                                                }
                                        }
                                        if (err_flg == 0) {
-                                               opt     = uci_lookup_option(ctx, sct, key);
-                                               if (opt != NULL) {
-                                                       memset(&ptr, 0, sizeof(ptr));
-                                                       ptr.package     = pkg->e.name;
-                                                       ptr.section     = sct->e.name;
-                                                       ptr.option      = key;
-
-                                                       if (uci_lookup_ptr(ctx, &ptr, NULL, false) == UCI_OK) {
-                                                               ptr.value       = value;
-                                                               uci_set(ctx, &ptr);
-                                                               save    = true;
-                                                       }
+                                               memset(&ptr, 0, sizeof(ptr));
+                                               ptr.package     = pkg->e.name;
+                                               ptr.section     = sct->e.name;
+                                               ptr.option      = key;
+
+                                               if (uci_lookup_ptr(ctx, &ptr, NULL, false) == UCI_OK) {
+                                                       ptr.value       = value;
+                                                       uci_set(ctx, &ptr);
+                                                       uci_save(ctx, pkg);
+                                                       ret_val = true;
+                                                       log_debug("Created configuration section %s to configuration file: %s\n", section_name, fname);
                                                }
                                                else {
-                                                       opt     = uci_alloc_option(sct, key, value);
-                                                       save    = true;
-                                               }
-                                               if (save == true) {
-                                                       uci_save(ctx, pkg);
+                                                       log_error("Could not write to configuration file: %s\n. Could not look-up pointer for package %s section %s.\n", fname, pkg->e.name, sct->e.name);
                                                }
                                                uci_free_context(ctx);
-                                               ret_val = true;
                                        }
                                        else {
-                                               log_error("Could not write to configuration file: %s\n. Could not create section %s.", fname, section_name);
+                                               log_error("Could not write to configuration file: %s\n. Could not create section %s.\n", fname, section_name);
                                        }
                                }
                                else {
-                                       log_error("Could not write to configuration file: %s\n. File does not exist or is not writable.", fname);
+                                       log_error("Could not write to configuration file: %s. File does not exist or is not writable.\n", fname);
                                }
                        }
                        free(fname);
                }
                else {
-                       log_error("Could not change config value, out of memory");
+                       log_error("Could not change config value, out of memory\n");
                }
        }
        else {
-               log_error("Could not change config value, invalid parameters");
+               log_error("Could not change config value, invalid parameters\n");
        }
        return ret_val;
 }