mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-09 23:34:38 +01:00
Compare commits
2 commits
b86d526324
...
72c3307651
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72c3307651 | ||
|
|
8f72146f0f |
3 changed files with 65 additions and 7 deletions
|
|
@ -728,7 +728,14 @@ struct uci_section *create_dmmap_obj(struct dmctx *dmctx, unsigned char instance
|
|||
|
||||
char *curr_instance = NULL;
|
||||
dmuci_get_value_by_section_string(s, "__instance__", &curr_instance);
|
||||
int curr_instance_int = (curr_instance && *curr_instance != '\0') ? DM_STRTOL(curr_instance) : 0;
|
||||
if (DM_STRLEN(curr_instance) == 0) {
|
||||
BBF_ERR("Found section without __instance__ in package: %s, section type: %s section name: %s. Deleting this entry",
|
||||
section_config(s), section_type(s), section_name(s));
|
||||
dmuci_delete_by_section(s, NULL, NULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
int curr_instance_int = DM_STRTOL(curr_instance);
|
||||
if (curr_instance_int > max_instance)
|
||||
max_instance = curr_instance_int;
|
||||
|
||||
|
|
@ -751,19 +758,20 @@ struct uci_section *create_dmmap_obj(struct dmctx *dmctx, unsigned char instance
|
|||
char s_name[64] = {0};
|
||||
int pos = 0;
|
||||
|
||||
dmuci_add_section_bbfdm(obj_file, obj_name, &dmmap_section);
|
||||
|
||||
for (int i = 0; i < instance_level; i++) {
|
||||
dmuci_set_value_by_section(dmmap_section, dmctx->obj_buf[i], dmctx->inst_buf[i]);
|
||||
pos += snprintf(&s_name[pos], sizeof(s_name) - pos, "%s_%s", dmctx->obj_buf[i], dmctx->inst_buf[i]);
|
||||
}
|
||||
|
||||
snprintf(&s_name[pos], sizeof(s_name) - pos, "%s_%s", obj_name, *instance);
|
||||
|
||||
dmuci_rename_section_by_section(dmmap_section, s_name);
|
||||
dmuci_add_named_section_bbfdm(obj_file, obj_name, s_name, &dmmap_section);
|
||||
|
||||
dmuci_set_value_by_section(dmmap_section, "__section_name__", config_sec_name);
|
||||
dmuci_set_value_by_section(dmmap_section, "__instance__", *instance);
|
||||
|
||||
for (int i = 0; i < instance_level; i++) {
|
||||
dmuci_set_value_by_section(dmmap_section, dmctx->obj_buf[i], dmctx->inst_buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
dmctx->obj_buf[instance_level] = obj_name;
|
||||
|
|
@ -797,14 +805,14 @@ char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node,
|
|||
switch(parent_node->browse_type) {
|
||||
case BROWSE_NORMAL:
|
||||
dmasprintf(&instance, "%d", inst_nbr);
|
||||
dmctx->obj_buf[parent_node->instance_level] = parent_node->obj->obj;
|
||||
dmctx->inst_buf[parent_node->instance_level] = instance ? instance : "";
|
||||
break;
|
||||
case BROWSE_FIND_MAX_INST:
|
||||
case BROWSE_NUM_OF_ENTRIES:
|
||||
break;
|
||||
}
|
||||
|
||||
dmctx->inst_buf[parent_node->instance_level] = instance ? instance : "";
|
||||
|
||||
return instance ? instance : "";
|
||||
}
|
||||
|
||||
|
|
@ -821,6 +829,14 @@ int generic_browse(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, ch
|
|||
char *config_sec_name = NULL;
|
||||
bool is_same_parent = true;
|
||||
|
||||
// skip instances which has no __instance__
|
||||
dmuci_get_value_by_section_string(curr_data.dmmap_section, "__instance__", &instance);
|
||||
if (DM_STRLEN(instance) == 0) {
|
||||
BBF_WARNING("Skipping object with no instance number in package: %s, section type: %s, section name: %s",
|
||||
section_config(curr_data.dmmap_section), section_type(curr_data.dmmap_section), section_name(curr_data.dmmap_section));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < parent_node->instance_level; i++) {
|
||||
char *curr_obj_inst = NULL;
|
||||
dmuci_get_value_by_section_string(curr_data.dmmap_section, dmctx->obj_buf[i], &curr_obj_inst);
|
||||
|
|
|
|||
|
|
@ -729,6 +729,7 @@ enum uci_oper_type {
|
|||
UCI_OP_DEL,
|
||||
UCI_OP_RENAME,
|
||||
UCI_OP_REORDER,
|
||||
UCI_OP_ADD_NAMED,
|
||||
__UCI_OP_MAX
|
||||
};
|
||||
|
||||
|
|
@ -761,6 +762,11 @@ static int __uci_perform_op(int operation, bbfdm_uci_op_data *op_data)
|
|||
if (uci_set(op_data->ucictx, &ptr) != UCI_OK)
|
||||
return -1;
|
||||
break;
|
||||
case UCI_OP_ADD_NAMED:
|
||||
if (uci_set(op_data->ucictx, &ptr) != UCI_OK || ptr.s == NULL)
|
||||
return -1;
|
||||
*op_data->s = ptr.s;
|
||||
break;
|
||||
case UCI_OP_ADD_LIST:
|
||||
if (uci_add_list(op_data->ucictx, &ptr) != UCI_OK)
|
||||
return -1;
|
||||
|
|
@ -850,6 +856,31 @@ int dmuci_add_section(const char *package, const char *stype, struct uci_section
|
|||
return __uci_perform_op(UCI_OP_ADD, &conf_data);
|
||||
}
|
||||
|
||||
int dmuci_add_named_section(const char *package, const char *stype, const char *name, struct uci_section **s)
|
||||
{
|
||||
char fname[128];
|
||||
bbfdm_uci_op_data conf_data = {0};
|
||||
|
||||
if (s == NULL)
|
||||
return -1;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/%s", uci_ctx->confdir, package);
|
||||
|
||||
if (create_empty_file(fname))
|
||||
return -1;
|
||||
|
||||
*s = NULL;
|
||||
|
||||
conf_data.s = s;
|
||||
conf_data.ucictx = uci_ctx;
|
||||
conf_data.dmctx = get_bbfdm_global_dmctx();
|
||||
conf_data.package = package;
|
||||
conf_data.section = name;
|
||||
conf_data.value = stype;
|
||||
|
||||
return __uci_perform_op(UCI_OP_ADD_NAMED, &conf_data);
|
||||
}
|
||||
|
||||
/**** UCI DELETE by section pointer *****/
|
||||
int dmuci_delete_by_section(struct uci_section *s, const char *option, const char *value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -219,6 +219,15 @@ int dmuci_add_section_##UCI_PATH(const char *package, const char *stype, struct
|
|||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
int dmuci_add_named_section_##UCI_PATH(const char *package, const char *stype, const char *name, struct uci_section **s)\
|
||||
{\
|
||||
struct uci_context *save_uci_ctx; \
|
||||
save_uci_ctx = uci_ctx; \
|
||||
uci_ctx = uci_ctx_##UCI_PATH; \
|
||||
int res = dmuci_add_named_section(package, stype, name, s); \
|
||||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
int dmuci_delete_##UCI_PATH(const char *package, const char *section, const char *option, const char *value) \
|
||||
{\
|
||||
struct uci_context *save_uci_ctx; \
|
||||
|
|
@ -312,6 +321,7 @@ int dmuci_set_value(const char *package, const char *section, const char *option
|
|||
int dmuci_add_list_value(const char *package, const char *section, const char *option, const char *value);
|
||||
int dmuci_del_list_value(const char *package, const char *section, const char *option, const char *value);
|
||||
int dmuci_add_section(const char *package, const char *stype, struct uci_section **s);
|
||||
int dmuci_add_named_section(const char *package, const char *stype, const char *name, struct uci_section **s);
|
||||
int dmuci_delete(const char *package, const char *section, const char *option, const char *value);
|
||||
int dmuci_rename_section(const char *package, const char *section, const char *value);
|
||||
int dmuci_get_value_by_section_string(struct uci_section *s, const char *option, char **value);
|
||||
|
|
@ -333,6 +343,7 @@ int dmuci_set_value_bbfdm(const char *package, const char *section, const char *
|
|||
int dmuci_set_value_by_section_bbfdm(struct uci_section *s, const char *option, const char *value);
|
||||
int dmuci_add_list_value_bbfdm(const char *package, const char *section, const char *option, const char *value);
|
||||
int dmuci_add_section_bbfdm(const char *package, const char *stype, struct uci_section **s);
|
||||
int dmuci_add_named_section_bbfdm(const char *package, const char *stype, const char *name, struct uci_section **s);
|
||||
int dmuci_delete_bbfdm(const char *package, const char *section, const char *option, const char *value);
|
||||
int dmuci_delete_by_section_unnamed_bbfdm(struct uci_section *s, const char *option, const char *value);
|
||||
int dmuci_delete_by_section_bbfdm(struct uci_section *s, const char *option, const char *value);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue