From 75c3538a9fbaf22e8df1a64eb363b4a8be6b9494 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane <amin.benromdhane@iopsys.eu> Date: Mon, 27 Mar 2023 17:03:16 +0200 Subject: [PATCH] Align with bbf changes --- src/Makefile | 2 +- src/add_delete.c | 2 +- src/common.c | 36 ++++++++++++++++++++++++++++++++++-- src/common.h | 2 +- src/events.c | 2 +- src/get.c | 12 ++++++------ src/get_helper.c | 17 +++++++++++++---- src/get_helper.h | 2 ++ src/operate.c | 2 +- src/pretty_print.c | 1 - src/set.c | 5 ++--- src/usp.c | 5 ++--- test/cmocka/Makefile | 2 +- 13 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/Makefile b/src/Makefile index f1bf9f9..c143efe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ PROG_CFLAGS = $(CFLAGS) \ -Wformat-signedness -fPIC PROG_LDFLAGS = $(LDFLAGS) -PROG_LDFLAGS += -luci -lubus -lubox -ljson-c -lblobmsg_json -lbbfdm +PROG_LDFLAGS += -luci -lubus -lubox -ljson-c -lblobmsg_json -lbbf_api -lbbf_dm ifeq ($(USE_MBEDTLS),yes) PROG_LDFLAGS += -lmbedcrypto -lmbedtls diff --git a/src/add_delete.c b/src/add_delete.c index 3004e29..2cc8370 100644 --- a/src/add_delete.c +++ b/src/add_delete.c @@ -23,7 +23,7 @@ #include "common.h" #include "add_delete.h" #include "get_helper.h" -#include <libbbfdm/dmbbfcommon.h> +#include <libbbf_api/dmentry.h> typedef int (*ADD_DEL_CB_T)(struct dmctx *bbf_ctx, struct blob_buf *bb, char *path, const char *pkey); diff --git a/src/common.c b/src/common.c index 56945dc..76cb233 100644 --- a/src/common.c +++ b/src/common.c @@ -21,7 +21,6 @@ */ #include "common.h" -#include <libbbfdm/dmbbfcommon.h> #include "ipc.h" #include "get_helper.h" @@ -145,7 +144,7 @@ bool get_uci_option_string(char *package, char *section, if (!uci_ctx) return false; - if (bbfdmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) { + if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) { *value = NULL; ret = false; } else if (ptr.o && ptr.o->v.string) { @@ -208,3 +207,36 @@ bool validate_msglen(struct blob_buf *bb) return true; } + +int get_dm_type(char *dm_type) +{ + if (dm_type == NULL) + return DMT_STRING; + + if (DM_STRCMP(dm_type, DMT_TYPE[DMT_STRING]) == 0) + return DMT_STRING; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_UNINT]) == 0) + return DMT_UNINT; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_INT]) == 0) + return DMT_INT; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_UNLONG]) == 0) + return DMT_UNLONG; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_LONG]) == 0) + return DMT_LONG; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_BOOL]) == 0) + return DMT_BOOL; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_TIME]) == 0) + return DMT_TIME; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_HEXBIN]) == 0) + return DMT_HEXBIN; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_BASE64]) == 0) + return DMT_BASE64; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_COMMAND]) == 0) + return DMT_COMMAND; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_EVENT]) == 0) + return DMT_EVENT; + else + return DMT_STRING; + + return DMT_STRING; +} diff --git a/src/common.h b/src/common.h index 93a8cc1..ce0d139 100644 --- a/src/common.h +++ b/src/common.h @@ -46,7 +46,7 @@ void print_info(const char *format, ...); void print_debug(const char *format, ...); bool get_boolean_string(char *value); bool validate_msglen(struct blob_buf *bb); - +int get_dm_type(char *dm_type); #define DEBUG(fmt, args...) \ print_debug("[%s:%d]"fmt, __func__, __LINE__, ##args) diff --git a/src/events.c b/src/events.c index 2f1c13d..1504201 100644 --- a/src/events.c +++ b/src/events.c @@ -23,7 +23,7 @@ #include "common.h" #include "events.h" #include "get_helper.h" -#include <libbbfdm/dmentry.h> +#include <libbbf_api/dmentry.h> #include <libubus.h> static struct event_map_list ev_map_list[] = { diff --git a/src/get.c b/src/get.c index c24b97e..992a4c9 100644 --- a/src/get.c +++ b/src/get.c @@ -25,7 +25,7 @@ #include "pretty_print.h" #include "ipc.h" #include <libubus.h> -#include <libbbfdm/dmbbfcommon.h> +#include <libbbf_api/dmentry.h> void init_dmmap(void) { @@ -38,7 +38,7 @@ void init_dmmap(void) get_resolved_paths(&bbf_ctx, ROOT_NODE, &resolved_list); // Commit dmmap - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); free_path_list(&resolved_list); bbf_cleanup(&bbf_ctx); @@ -130,7 +130,7 @@ void usp_get_value(usp_data_t *data) // Apply all bbfdm changes if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); @@ -177,7 +177,7 @@ void usp_validate_path(usp_data_t *data) // Apply all bbfdm changes if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); @@ -227,7 +227,7 @@ void usp_get_instance(usp_data_t *data) // Apply all bbfdm changes if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); @@ -278,7 +278,7 @@ void usp_get_name(usp_data_t *data) // Commit all bbfdm changes if transaction is not in progress if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); diff --git a/src/get_helper.c b/src/get_helper.c index d5600fa..f259cab 100644 --- a/src/get_helper.c +++ b/src/get_helper.c @@ -26,12 +26,21 @@ #include <time.h> #include <setjmp.h> -#include <libbbfdm/dmbbfcommon.h> - #include "get_helper.h" #include "common.h" #include "pretty_print.h" +#include <libbbf_api/dmentry.h> +#include <libbbf_dm/device.h> +#include <libbbf_dm/vendor.h> + +DMOBJ *DM_ROOT_OBJ = tEntry181Obj; +DM_MAP_VENDOR *DM_VENDOR_EXTENSION[2] = { + tVendorExtension, + tVendorExtensionOverwrite +}; +DM_MAP_VENDOR_EXCLUDE *DM_VENDOR_EXTENSION_EXCLUDE = tVendorExtensionExclude; + // uloop.h does not have versions, below line is to use // deprecated uloop_timeout_remaining for the time being #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -97,7 +106,7 @@ void bbf_configure_ubus(struct ubus_context *ctx) void bbf_init(struct dmctx *dm_ctx, int instance) { - dm_ctx_init(dm_ctx, instance); + dm_ctx_init(dm_ctx, DM_ROOT_OBJ, DM_VENDOR_EXTENSION, DM_VENDOR_EXTENSION_EXCLUDE, instance); } void bbf_cleanup(struct dmctx *dm_ctx) @@ -117,7 +126,7 @@ static void bbf_sub_init(struct dmctx *dm_ctx, char *path) instance = INSTANCE_MODE_ALIAS; } DEBUG("instance|%u|", instance); - dm_ctx_init_sub(dm_ctx, instance); + dm_ctx_init_sub(dm_ctx, DM_ROOT_OBJ, DM_VENDOR_EXTENSION, DM_VENDOR_EXTENSION_EXCLUDE, instance); } static void bbf_sub_cleanup(struct dmctx *dm_ctx) diff --git a/src/get_helper.h b/src/get_helper.h index 159adb2..e23970c 100644 --- a/src/get_helper.h +++ b/src/get_helper.h @@ -28,6 +28,8 @@ struct pathNode { char path[MAX_DM_PATH]; }; +extern DMOBJ *DM_ROOT_OBJ; + int resolve_path(struct dmctx *bbf_ctx, char *qPath, size_t pos, struct list_head *resolved_plist); diff --git a/src/operate.c b/src/operate.c index 59e5c68..ead8745 100644 --- a/src/operate.c +++ b/src/operate.c @@ -25,8 +25,8 @@ #include "get_helper.h" #include "pretty_print.h" #include "ipc.h" -#include <libbbfdm/dmbbfcommon.h> #include <libubus.h> +#include <libbbf_api/dmentry.h> static void usp_operate_cmd(usp_data_t *data, struct blob_buf *bb) { diff --git a/src/pretty_print.c b/src/pretty_print.c index 4aff473..3cb4fd2 100644 --- a/src/pretty_print.c +++ b/src/pretty_print.c @@ -23,7 +23,6 @@ #include "common.h" #include "get_helper.h" #include "pretty_print.h" -#include <libbbfdm/dmbbfcommon.h> // private function and structures diff --git a/src/set.c b/src/set.c index f5f12cf..80cb27e 100644 --- a/src/set.c +++ b/src/set.c @@ -23,8 +23,7 @@ #include "set.h" #include "get_helper.h" #include <libubus.h> -#include <libbbfdm/dmbbfcommon.h> - +#include <libbbf_api/dmentry.h> static const struct blobmsg_policy dm_setm_value_policy[] = { [DM_SET_V_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING }, @@ -78,7 +77,7 @@ int usp_set_value(usp_data_t *data) blobmsg_add_u8(&bb, "status", false); blobmsg_add_u32(&bb, "fault", (uint32_t)p->fault); blobmsg_close_table(&bb, table); - del_list_fault_param(p); + bbf_api_del_list_fault_param(p); } } } diff --git a/src/usp.c b/src/usp.c index a071dd2..e9e37ce 100644 --- a/src/usp.c +++ b/src/usp.c @@ -30,8 +30,7 @@ #include <libubox/uloop.h> #include <libubus.h> #include <sys/prctl.h> - -#include <libbbfdm/dmbbfcommon.h> +#include <libbbf_api/dmentry.h> #include "usp.h" #include "set.h" @@ -1594,7 +1593,7 @@ bool usp_cleanup(struct usp_context *u) free_ubus_obj_list(&u->obj_list); free_path_list(&u->instances); free_path_list(&u->old_instances); - bbf_dm_cleanup(); + bbf_dm_cleanup(DM_ROOT_OBJ); return true; } diff --git a/test/cmocka/Makefile b/test/cmocka/Makefile index 85d22c4..493c74e 100644 --- a/test/cmocka/Makefile +++ b/test/cmocka/Makefile @@ -2,7 +2,7 @@ CC = gcc USPD_LIB_DIR ?= $(shell dirname $(PWD)) USPD_LIB = -luspd -L$(USPD_LIB_DIR) CMOCKA_LIB = -l cmocka -LIBS = $(USPD_LIB) $(CMOCKA_LIB) -luci -pthread -lubus -lubox -ljson-c -lblobmsg_json -lbbfdm -lpthread +LIBS = $(USPD_LIB) $(CMOCKA_LIB) -luci -pthread -lubus -lubox -ljson-c -lblobmsg_json -lpthread CFLAGS = -g -Wall -I../../src LDFLAGS = $(LIBS) -Wl,-rpath=$(USPD_LIB_DIR) -I$(USPD_LIB_DIR) UNIT_TESTS = unit_test_uspd -- GitLab