This commit is contained in:
Amin Ben Romdhane 2025-04-04 10:26:07 +02:00
parent d5775d03fe
commit 500215fd59
2 changed files with 28 additions and 4 deletions

View file

@ -215,6 +215,7 @@ typedef struct dmnode {
DMOBJ *obj; DMOBJ *obj;
struct dmnode *parent; struct dmnode *parent;
struct uci_section *idb_s; struct uci_section *idb_s;
json_object *idb_json;
char *current_object; char *current_object;
void *prev_data; void *prev_data;
char *prev_instance; char *prev_instance;

View file

@ -1999,7 +1999,17 @@ static struct uci_section *get_uci_instance_db_section(const char *object, const
static int mobj_get_instances_db(DMOBJECT_ARGS) static int mobj_get_instances_db(DMOBJECT_ARGS)
{ {
//BBF_ERR("#### OBJ: node->current_object=%s && node->is_instanceobj=%d && node->obj->obj=%s ####", node->current_object, node->is_instanceobj, node->obj->obj); BBF_ERR("#### OBJ: node->current_object=%s && node->is_instanceobj=%d && node->obj->obj=%s &&& node->parent=%p && node->parent->current_object=%s &&& node->parent->idb_json=%p &&& node->idb_json=%p && instance=%s ####",
node->current_object, node->is_instanceobj,
node->obj->obj, node->parent, node->parent->current_object, node->parent->idb_json, node->idb_json, instance);
if (node->parent->idb_json == NULL) node->parent->idb_json = json_object_new_object();
if (node->idb_json == NULL) node->idb_json = json_object_new_object();
json_object_object_add(node->parent->idb_json, (node->is_instanceobj == 1) ? instance : node->obj->obj, node->idb_json);
if (node->is_instanceobj == 0 && node->obj->browseinstobj != NULL) { if (node->is_instanceobj == 0 && node->obj->browseinstobj != NULL) {
node->idb_s = get_uci_instance_db_section(node->current_object, "idb_parent"); node->idb_s = get_uci_instance_db_section(node->current_object, "idb_parent");
@ -2025,28 +2035,32 @@ static int mparam_get_instances_db(DMPARAM_ARGS)
if (node->is_instanceobj == 0) if (node->is_instanceobj == 0)
return 0; return 0;
BBF_ERR("LEAF: node->current_object=%s && leaf->parameter=%s && node->is_instanceobj=%d && node->obj->obj=%s && node->idb_json=%p",
node->current_object, leaf->parameter, node->is_instanceobj, node->obj->obj, node->idb_json);
char full_param[MAX_DM_PATH] = {0}; char full_param[MAX_DM_PATH] = {0};
char *value = dmstrdup(""); char *value = dmstrdup("");
snprintf(full_param, sizeof(full_param), "%s%s", node->current_object, leaf->parameter); snprintf(full_param, sizeof(full_param), "%s%s", node->current_object, leaf->parameter);
//BBF_ERR("LEAF: node->current_object=%s && leaf->parameter=%s && node->is_instanceobj=%d && node->obj->obj=%s", node->current_object, leaf->parameter, node->is_instanceobj, node->obj->obj);
(leaf->getvalue)(full_param, dmctx, data, instance, &value); (leaf->getvalue)(full_param, dmctx, data, instance, &value);
if (leaf->dm_flags & DM_FLAG_UNIQUE) { if (leaf->dm_flags & DM_FLAG_UNIQUE) {
if (node->idb_json) json_object_object_add(node->idb_json, leaf->parameter, json_object_new_string(value));
dmuci_set_value_by_section_bbfdm(node->idb_s, leaf->parameter, value); dmuci_set_value_by_section_bbfdm(node->idb_s, leaf->parameter, value);
} }
return 0; return 0;
} }
#define JSON_FILE "/etc/bbfdm/data.json"
int dm_entry_instances_db(struct dmctx *ctx) int dm_entry_instances_db(struct dmctx *ctx)
{ {
DMOBJ *root = ctx->dm_entryobj; DMOBJ *root = ctx->dm_entryobj;
DMNODE node = {.current_object = ""}; DMNODE node = {.current_object = ""};
int err = 0; int err = 0;
BBF_ERR("root->obj=%s && node->current_object=%s", root->obj, node.current_object);
ctx->inparam_isparam = 0; ctx->inparam_isparam = 0;
ctx->findparam = 1; ctx->findparam = 1;
ctx->stop = 0; ctx->stop = 0;
@ -2057,5 +2071,14 @@ int dm_entry_instances_db(struct dmctx *ctx)
err = dm_browse(ctx, &node, root, NULL, NULL); err = dm_browse(ctx, &node, root, NULL, NULL);
BBF_ERR("++++++++++++++++++++++++ END ++++++++++++++++++++++++++++");
BBF_ERR("&&& node.idb_json=%p &&&", node.idb_json);
FILE *fp = fopen(JSON_FILE, "w");
if (fp) {
fprintf(fp, "%s", json_object_to_json_string_ext(node.idb_json, JSON_C_TO_STRING_PRETTY));
fclose(fp);
}
return (ctx->findparam == 0) ? err : 0; return (ctx->findparam == 0) ? err : 0;
} }