Fix get name

This commit is contained in:
Amin Ben Romdhane 2025-02-17 16:14:44 +01:00
parent 74e427f807
commit e0d1cbd6e0
5 changed files with 41 additions and 14 deletions

View file

@ -28,6 +28,8 @@
#include "libbbfdm-api/version-2/bbfdm_api.h"
#define ROOT_NODE "Device."
extern struct dm_permession_s DMREAD;
extern struct dm_permession_s DMWRITE;
extern struct dm_permession_s DMSYNC;

View file

@ -187,6 +187,17 @@ static int plugin_leaf_onlyobj_match(DMOBJECT_ARGS)
static int plugin_obj_nextlevel_match(DMOBJECT_ARGS)
{
if (strcmp(dmctx->in_param, "Device") ==0 && strcmp(dmctx->in_value, "core") !=0)
return FAULT_9005;
if (node->obj && node->obj->obj && strncmp(node->obj->obj, ROOT_NODE, strlen(ROOT_NODE)) == 0) {
unsigned int parent_path_dot_num = count_occurrences(node->obj->obj, '.');
unsigned int in_path_dot_num = count_occurrences(dmctx->in_param, '.');
if (parent_path_dot_num >= in_path_dot_num)
return FAULT_9005;
}
if (node->matched > 1)
return FAULT_9005;
@ -1070,6 +1081,12 @@ static int mobj_get_name(DMOBJECT_ARGS)
char *refparam = node->current_object;
char *perm = permission->val;
if (strcmp(node->current_object, ROOT_NODE) == 0 && strcmp(dmctx->in_value, "core") != 0)
return 0;
if (node->obj && node->obj->obj && strncmp(node->obj->obj, ROOT_NODE, strlen(ROOT_NODE)) == 0)
return 0;
if (permission->get_permission != NULL)
perm = permission->get_permission(refparam, dmctx, data, instance);
@ -1151,6 +1168,12 @@ static int mobj_get_name_in_obj(DMOBJECT_ARGS)
if (!node->matched)
return FAULT_9005;
if (strcmp(node->current_object, ROOT_NODE) == 0 && strcmp(dmctx->in_value, "core") != 0)
return 0;
if (node->obj && node->obj->obj && strncmp(node->obj->obj, ROOT_NODE, strlen(ROOT_NODE)) == 0)
return 0;
if (dmctx->iswildcard) {
if (dmctx->nextlevel && dm_strcmp_wildcard(node->current_object, dmctx->in_param) == 0)
return 0;
@ -1365,14 +1388,8 @@ int dm_entry_get_instances(struct dmctx *ctx)
ctx->inparam_isparam = 0;
ctx->findparam = 0;
ctx->stop = 0;
if (ctx->iswildcard) {
ctx->checkobj = (ctx->nextlevel) ? plugin_obj_wildcard_nextlevel_match : plugin_obj_wildcard_match;
ctx->checkleaf = (ctx->nextlevel) ? plugin_leaf_wildcard_nextlevel_match : plugin_leaf_wildcard_match;
} else {
ctx->checkobj = (ctx->nextlevel) ? plugin_obj_nextlevel_match : plugin_obj_match;
ctx->checkleaf = (ctx->nextlevel) ? plugin_leaf_nextlevel_match : plugin_leaf_match;
}
ctx->checkobj = (ctx->iswildcard) ? plugin_obj_wildcard_match : plugin_obj_match;
ctx->checkleaf = (ctx->iswildcard) ? plugin_leaf_wildcard_match : plugin_leaf_match;
ctx->method_obj = mobj_get_instances_in_obj;
ctx->method_param = mparam_get_instances_in_obj;

View file

@ -262,9 +262,16 @@ static int bbfdm_schema_handler(struct ubus_context *ctx, struct ubus_object *ob
struct blob_attr *tb[__DM_SCHEMA_MAX];
LIST_HEAD(paths_list);
bbfdm_data_t data;
struct bbfdm_context *u;
memset(&data, 0, sizeof(bbfdm_data_t));
u = container_of(ctx, struct bbfdm_context, ubus_ctx);
if (u == NULL) {
BBF_ERR("Failed to get the bbfdm context");
return UBUS_STATUS_UNKNOWN_ERROR;
}
if (blobmsg_parse(dm_schema_policy, __DM_SCHEMA_MAX, tb, blob_data(msg), blob_len(msg))) {
BBF_ERR("Failed to parse blob");
return UBUS_STATUS_UNKNOWN_ERROR;
@ -292,10 +299,14 @@ static int bbfdm_schema_handler(struct ubus_context *ctx, struct ubus_object *ob
data.bbf_ctx.isinfo = true;
bbfdm_get(&data, BBF_SCHEMA);
#else
if (dm_type == BBFDM_CWMP)
if (dm_type == BBFDM_CWMP) {
char *service_name = strdup(u->config.service_name);
data.bbf_ctx.in_value = (dm_type == BBFDM_CWMP) ? service_name : NULL;
bbfdm_get(&data, BBF_GET_NAME);
else
FREE(service_name);
} else {
bbfdm_get(&data, BBF_SCHEMA);
}
#endif
free_path_list(&paths_list);
@ -304,7 +315,6 @@ static int bbfdm_schema_handler(struct ubus_context *ctx, struct ubus_object *ob
static const struct blobmsg_policy dm_instances_policy[] = {
[DM_INSTANCES_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
[DM_INSTANCES_FIRST_LEVEL] = { .name = "first_level", .type = BLOBMSG_TYPE_BOOL },
[DM_INSTANCES_OPTIONAL] = { .name = "optional", .type = BLOBMSG_TYPE_TABLE },
};
@ -331,7 +341,6 @@ static int bbfdm_instances_handler(struct ubus_context *ctx, struct ubus_object
data.ctx = ctx;
data.req = req;
data.bbf_ctx.nextlevel = (tb[DM_INSTANCES_FIRST_LEVEL]) ? blobmsg_get_bool(tb[DM_INSTANCES_FIRST_LEVEL]) : false;
data.plist = &paths_list;
fill_optional_data(&data, tb[DM_INSTANCES_OPTIONAL]);

View file

@ -20,7 +20,7 @@
#define STRINGIFY(x) #x
#define TO_STR(x) STRINGIFY(x)
#define ROOT_NODE "Device."
//#define ROOT_NODE "Device."
#define BBF_EVENT_NAME "event"
#define MAX_DM_KEY_LEN 256

View file

@ -9,7 +9,6 @@ enum {
enum {
DM_INSTANCES_PATH,
DM_INSTANCES_FIRST_LEVEL,
DM_INSTANCES_OPTIONAL,
__DM_INSTANCES_MAX
};