diff --git a/dmdynamicjson.c b/dmdynamicjson.c index a09efa88..39d435f1 100644 --- a/dmdynamicjson.c +++ b/dmdynamicjson.c @@ -523,7 +523,7 @@ static int add_obj(char *refparam, struct dmctx *ctx, void *data, char **instanc find_current_obj(refparam, object, sizeof(object)); snprintf(buf_instance, sizeof(buf_instance), "%s_instance", object); - snprintf(sec_name, sizeof(sec_name), "%s%s_%s", data ? section_name((struct uci_section *)data) : "", object, *instance); + snprintf(sec_name, sizeof(sec_name), "%s%s%s_%s", data ? section_name((struct uci_section *)data) : "", data ? "_" : "", object, *instance); for (int i = 0; buf_instance[i]; i++) buf_instance[i] = tolower(buf_instance[i]); @@ -591,6 +591,14 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta switch (del_action) { case DEL_INST: + uci_package_foreach_sections_safe(json_object_get_string(file), stmp, s) { + char *dm_parent = NULL; + + dmuci_get_value_by_section_string(s, "dm_parent", &dm_parent); + if (DM_STRLEN(dm_parent) && strcmp(section_name((struct uci_section *)data), dm_parent) == 0) + dmuci_delete_by_section(s, NULL, NULL); + } + get_dmmap_section_of_config_section(json_object_get_string(dmmap_file), json_object_get_string(section_type), section_name((struct uci_section *)data), &dmmap_section); dmuci_delete_by_section(dmmap_section, NULL, NULL); @@ -598,15 +606,14 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta break; case DEL_ALL: uci_foreach_sections_safe(json_object_get_string(file), json_object_get_string(section_type), stmp, s) { + struct uci_section *ss = NULL, *sstmp = NULL; - if (data) { + uci_package_foreach_sections_safe(json_object_get_string(file), sstmp, ss) { char *dm_parent = NULL; - dmuci_get_value_by_section_string(s, "dm_parent", &dm_parent); - if (data && DM_STRLEN(dm_parent)) { - if (strcmp(section_name((struct uci_section *)data), dm_parent) != 0) - continue; - } + dmuci_get_value_by_section_string(ss, "dm_parent", &dm_parent); + if (DM_STRLEN(dm_parent) && strcmp(section_name(s), dm_parent) == 0) + dmuci_delete_by_section(ss, NULL, NULL); } get_dmmap_section_of_config_section(json_object_get_string(dmmap_file), json_object_get_string(section_type), section_name(s), &dmmap_section); @@ -1427,11 +1434,23 @@ static void uci_v1_set_value(json_object *mapping_obj, int json_version, char *r static void set_value_from_mapping(json_object *param_obj, int json_version, char *refparam, struct dmctx *ctx, void *data, char *instance, char *value) { - struct json_object *mapping_arr = NULL, *mapping = NULL; + struct json_object *type_obj = NULL, *mapping_arr = NULL, *mapping = NULL; if (!param_obj) return; + json_object_object_get_ex(param_obj, "type", &type_obj); + if (!type_obj) + return; + + char *type = json_object_get_string(type_obj); + if (!type) + return; + + if (DM_LSTRCMP(type, "boolean") == 0) { + value = dmuci_string_to_boolean(value) ? "1" : "0"; + } + json_object_object_get_ex(param_obj, "mapping", &mapping_arr); if (mapping_arr && json_object_get_type(mapping_arr) == json_type_array) { diff --git a/libbbf_api/dmuci.c b/libbbf_api/dmuci.c index b8e262e1..9a022206 100644 --- a/libbbf_api/dmuci.c +++ b/libbbf_api/dmuci.c @@ -863,6 +863,26 @@ end: return s; } +struct uci_section *dmuci_walk_all_sections(char *package, struct uci_section *prev_section, int walk) +{ + struct uci_element *e = NULL; + struct uci_list *list_section; + struct uci_ptr ptr = {0}; + + if (walk == GET_FIRST_SECTION) { + if (dmuci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL) != UCI_OK) + return NULL; + + list_section = &(ptr.p)->sections; + e = list_to_element(list_section->next); + } else { + list_section = &prev_section->package->sections; + e = list_to_element(prev_section->e.list.next); + } + + return (&e->list != list_section) ? uci_to_section(e) : NULL; +} + /**** UCI GET db config *****/ int db_get_value_string(char *package, char *section, char *option, char **value) { diff --git a/libbbf_api/dmuci.h b/libbbf_api/dmuci.h index 12109671..8aa8729d 100644 --- a/libbbf_api/dmuci.h +++ b/libbbf_api/dmuci.h @@ -113,6 +113,17 @@ struct package_change section != NULL; \ section = dmuci_walk_section(package, stype, arg, NULL, CMP_FILTER_FUNC, func, section, GET_NEXT_SECTION)) +#define uci_package_foreach_sections(package, section) \ + for (section = dmuci_walk_all_sections(package, NULL, GET_FIRST_SECTION); \ + section != NULL; \ + section = dmuci_walk_all_sections(package, section, GET_NEXT_SECTION)) + +#define uci_package_foreach_sections_safe(package, _tmp, section) \ + for (section = dmuci_walk_all_sections(package, NULL, GET_FIRST_SECTION), \ + _tmp = (section) ? dmuci_walk_all_sections(package, section, GET_NEXT_SECTION) : NULL; \ + section != NULL; \ + section = _tmp, _tmp = (section) ? dmuci_walk_all_sections(package, section, GET_NEXT_SECTION) : NULL) + #define section_name(s) s ? (s)->e.name : "" #define section_type(s) s ? (s)->type : "" #define section_config(s) s ? (s)->package->e.name : "" @@ -349,6 +360,7 @@ int dmuci_add_list_value_by_section(struct uci_section *s, char *option, char *v int dmuci_del_list_value_by_section(struct uci_section *s, char *option, char *value); int dmuci_rename_section_by_section(struct uci_section *s, char *value); struct uci_section *dmuci_walk_section(char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk); +struct uci_section *dmuci_walk_all_sections(char *package, struct uci_section *prev_section, int walk); int dmuci_get_option_value_string_bbfdm(char *package, char *section, char *option, char **value); int dmuci_set_value_bbfdm(char *package, char *section, char *option, char *value); diff --git a/test/files/etc/config/bulkdata b/test/files/etc/config/bulkdata index f703a4c2..7697c166 100644 --- a/test/files/etc/config/bulkdata +++ b/test/files/etc/config/bulkdata @@ -8,22 +8,22 @@ config profile 'profile_1' option enable '0' option name '' option nbre_of_retained_failed_reports '0' - option protocol 'http' + option protocol 'HTTP' option encoding_type '' option reporting_interval '86400' option time_reference '0' option csv_encoding_field_separator ',' option csv_encoding_row_separator ' ' option csv_encoding_escape_character '"' - option csv_encoding_report_format 'column' - option csv_encoding_row_time_stamp 'unix' - option json_encoding_report_format 'objecthierarchy' - option json_encoding_report_time_stamp 'unix' + option csv_encoding_report_format 'ParameterPerColumn' + option csv_encoding_row_time_stamp 'Unix-Epoch' + option json_encoding_report_format 'ObjectHierarchy' + option json_encoding_report_time_stamp 'Unix-Epoch' option http_url '' option http_username '' option http_password '' - option http_compression 'none' - option http_method 'post' + option http_compression 'None' + option http_method 'POST' option http_use_date_header '1' option http_retry_enable '0' option http_retry_minimum_wait_interval '5' @@ -64,22 +64,22 @@ config profile 'profile_2' option enable '0' option name '' option nbre_of_retained_failed_reports '0' - option protocol 'http' + option protocol 'HTTP' option encoding_type '' option reporting_interval '86400' option time_reference '0' option csv_encoding_field_separator ',' option csv_encoding_row_separator ' ' option csv_encoding_escape_character '"' - option csv_encoding_report_format 'column' - option csv_encoding_row_time_stamp 'unix' - option json_encoding_report_format 'objecthierarchy' - option json_encoding_report_time_stamp 'unix' + option csv_encoding_report_format 'ParameterPerColumn' + option csv_encoding_row_time_stamp 'Unix-Epoch' + option json_encoding_report_format 'ObjectHierarchy' + option json_encoding_report_time_stamp 'Unix-Epoch' option http_url '' option http_username '' option http_password '' - option http_compression 'none' - option http_method 'post' + option http_compression 'None' + option http_method 'POST' option http_use_date_header '1' option http_retry_enable '0' option http_retry_minimum_wait_interval '5' diff --git a/tools/tools_input.json b/tools/tools_input.json index a503a711..d109fab5 100644 --- a/tools/tools_input.json +++ b/tools/tools_input.json @@ -16,7 +16,7 @@ "repo": "https://dev.iopsys.eu/iopsys/bulkdata.git", "proto": "git", "dm_files": [ - "bbf_plugin/datamodel.c" + "bbf_plugin/bulkdata.json" ] }, {