mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-09 23:34:38 +01:00
Create dmmap file for each root object
This commit is contained in:
parent
8389f3d9bd
commit
d5775d03fe
4 changed files with 45 additions and 12 deletions
|
|
@ -222,7 +222,7 @@ int bbf_set_alias(struct dmctx *ctx, struct uci_section *s, const char *option_n
|
|||
return 0;
|
||||
}
|
||||
|
||||
int resolve_path(const char *base_path, const char *key_name, char *key_value, char *out, size_t out_len)
|
||||
int resolve_path(const char *config_name, const char *base_path, const char *key_name, char *key_value, char *out, size_t out_len)
|
||||
{
|
||||
struct uci_section *idb_s = NULL;
|
||||
struct uci_list *uci_list = NULL;
|
||||
|
|
@ -234,7 +234,7 @@ int resolve_path(const char *base_path, const char *key_name, char *key_value, c
|
|||
// No wildcard, directly search
|
||||
calculate_hash(base_path, hash_str, sizeof(hash_str));
|
||||
|
||||
idb_s = dmuci_get_section_bbfdm("instance_db", hash_str);
|
||||
idb_s = dmuci_get_section_bbfdm(config_name, hash_str);
|
||||
if (idb_s == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
@ -245,12 +245,12 @@ int resolve_path(const char *base_path, const char *key_name, char *key_value, c
|
|||
uci_foreach_element(uci_list, e) {
|
||||
char *value = NULL;
|
||||
|
||||
dmuci_get_option_value_string_bbfdm("instance_db", e->name, key_name, &value);
|
||||
dmuci_get_option_value_string_bbfdm(config_name, e->name, key_name, &value);
|
||||
|
||||
if (DM_STRLEN(value) && DM_STRCMP(value, key_value) == 0) {
|
||||
char *instance = NULL;
|
||||
|
||||
dmuci_get_option_value_string_bbfdm("instance_db", e->name, "instance", &instance);
|
||||
dmuci_get_option_value_string_bbfdm(config_name, e->name, "instance", &instance);
|
||||
|
||||
if (DM_STRLEN(instance)) {
|
||||
snprintf(out, out_len, "%s%s", base_path, instance);
|
||||
|
|
@ -267,11 +267,11 @@ int resolve_path(const char *base_path, const char *key_name, char *key_value, c
|
|||
char temp_path[256] = {0};
|
||||
|
||||
DM_STRNCPY(temp_path, base_path, star_pos - base_path + 1);
|
||||
BBF_ERR("## temp_path=%s ##", temp_path);
|
||||
BBF_DEBUG("## temp_path=%s ##", temp_path);
|
||||
|
||||
calculate_hash(temp_path, hash_str, sizeof(hash_str));
|
||||
|
||||
idb_s = dmuci_get_section_bbfdm("instance_db", hash_str);
|
||||
idb_s = dmuci_get_section_bbfdm(config_name, hash_str);
|
||||
if (idb_s == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
@ -283,14 +283,14 @@ int resolve_path(const char *base_path, const char *key_name, char *key_value, c
|
|||
char *instance = NULL;
|
||||
|
||||
// No wildcard, directly search
|
||||
dmuci_get_option_value_string_bbfdm("instance_db", e->name, "instance", &instance);
|
||||
dmuci_get_option_value_string_bbfdm(config_name, e->name, "instance", &instance);
|
||||
|
||||
if (DM_STRLEN(instance)) {
|
||||
char new_path[512] = {0};
|
||||
|
||||
snprintf(new_path, sizeof(new_path), "%s%s%s", temp_path, instance, star_pos + 1);
|
||||
|
||||
if (resolve_path(new_path, key_name, key_value, out, out_len) == 0)
|
||||
if (resolve_path(config_name, new_path, key_name, key_value, out, out_len) == 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -325,11 +325,18 @@ int bbfdm_get_references(struct dmctx *ctx, int match_action, const char *base_p
|
|||
size_t len = DM_STRLEN(out);
|
||||
|
||||
if (len > 0 && match_action == MATCH_FIRST) {
|
||||
BBF_ERR("Reference has already been resolved ('%s'). Skipping next possibility ('%s')", out, base_path);
|
||||
BBF_DEBUG("Reference has already been resolved ('%s'). Skipping next possibility ('%s')", out, base_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (resolve_path(base_path, key_name, key_value, ref_value, sizeof(ref_value)) != 0) {
|
||||
char root_obj[128] = {0};
|
||||
|
||||
if (find_config_name(base_path, root_obj, sizeof(root_obj)) == false) {
|
||||
BBF_ERR("Can't find config name");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (resolve_path(root_obj, base_path, key_name, key_value, ref_value, sizeof(ref_value)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1979,13 +1979,17 @@ int dm_entry_event(struct dmctx *dmctx)
|
|||
static struct uci_section *get_uci_instance_db_section(const char *object, const char *sec_name)
|
||||
{
|
||||
struct uci_section *idb_s = NULL;
|
||||
char root_obj[128] = {0};
|
||||
char hash_str[9] = {0};
|
||||
|
||||
if (find_config_name(object, root_obj, sizeof(root_obj)) == false)
|
||||
return NULL;
|
||||
|
||||
calculate_hash(object, hash_str, sizeof(hash_str));
|
||||
|
||||
idb_s = dmuci_get_section_bbfdm("instance_db", hash_str);
|
||||
idb_s = dmuci_get_section_bbfdm(root_obj, hash_str);
|
||||
if (idb_s == NULL) {
|
||||
dmuci_add_section_bbfdm("instance_db", sec_name, &idb_s);
|
||||
dmuci_add_section_bbfdm(root_obj, sec_name, &idb_s);
|
||||
dmuci_rename_section_by_section(idb_s, hash_str);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2215,3 +2215,24 @@ void calculate_hash(const char *input, char *output, size_t out_len)
|
|||
snprintf(output, out_len, "%08X", hash);
|
||||
}
|
||||
|
||||
bool find_config_name(const char *input, char *output, size_t output_size)
|
||||
{
|
||||
if (!input || !output || output_size == 0) // Invalid input
|
||||
return false;
|
||||
|
||||
const char *first_dot = strchr(input, '.');
|
||||
if (!first_dot) // No dot found, invalid format
|
||||
return false;
|
||||
|
||||
const char *second_arg = first_dot + 1; // Move past first dot
|
||||
const char *second_dot = strchr(second_arg, '.');
|
||||
|
||||
size_t len = second_dot ? (size_t)(second_dot - second_arg) : strlen(second_arg);
|
||||
|
||||
if (len >= output_size) // Output buffer too small
|
||||
return false;
|
||||
|
||||
DM_STRNCPY(output, second_arg, len + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,5 +240,6 @@ int get_proto_type(const char *proto);
|
|||
bool is_str_eq(const char *s1, const char *s2);
|
||||
|
||||
void calculate_hash(const char *input, char *output, size_t out_len);
|
||||
bool find_config_name(const char *input, char *output, size_t output_size);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue