mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Optimize dm_parent uci mapping
This commit is contained in:
parent
b2239623ac
commit
fcfe8d9043
3 changed files with 59 additions and 8 deletions
|
|
@ -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);
|
||||
|
|
@ -1431,11 +1438,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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue