From 3a3b00b8e4243bd3eb1e51209a0ce608e4f03f32 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Tue, 6 Aug 2024 14:08:27 +0000 Subject: [PATCH] Remove support for deleting all instances since cwmp and usp protocols do not require it --- libbbfdm-api/dmapi.h | 2 +- libbbfdm-api/dmbbf.c | 5 ++- libbbfdm-api/plugin/json_plugin.c | 53 ++++++++---------------------- test/cmocka/functional_test_bbfd.c | 32 +++--------------- test/cmocka/unit_test_bbfd.c | 6 ++-- tools/convert_dm_json_to_c.py | 9 +---- 6 files changed, 24 insertions(+), 83 deletions(-) diff --git a/libbbfdm-api/dmapi.h b/libbbfdm-api/dmapi.h index a4cc38a4..c65dd4f7 100644 --- a/libbbfdm-api/dmapi.h +++ b/libbbfdm-api/dmapi.h @@ -239,7 +239,7 @@ enum event_action_enum { EVENT_CHECK }; -enum del_action_enum { +enum del_action_enum { // To be removed later!!!!!!!!!!!! DEL_INST, DEL_ALL }; diff --git a/libbbfdm-api/dmbbf.c b/libbbfdm-api/dmbbf.c index edd480aa..9eeab80c 100644 --- a/libbbfdm-api/dmbbf.c +++ b/libbbfdm-api/dmbbf.c @@ -2289,7 +2289,6 @@ static int delete_object_obj(DMOBJECT_ARGS) } else { char *refparam = node->current_object; char *perm = permission->val; - unsigned char del_action = DEL_INST; if (DM_STRCMP(refparam, dmctx->in_param) != 0) return FAULT_9005; @@ -2303,9 +2302,9 @@ static int delete_object_obj(DMOBJECT_ARGS) return FAULT_9005; if (!node->is_instanceobj) - del_action = DEL_ALL; + return FAULT_9005; - return (delobj)(refparam, dmctx, data, instance, del_action); + return (delobj)(refparam, dmctx, data, instance, DEL_INST); } return 0; diff --git a/libbbfdm-api/plugin/json_plugin.c b/libbbfdm-api/plugin/json_plugin.c index 9b9b4370..cf186923 100644 --- a/libbbfdm-api/plugin/json_plugin.c +++ b/libbbfdm-api/plugin/json_plugin.c @@ -634,49 +634,22 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta if (file && section_type && dmmap_file) { struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL; - switch (del_action) { - case DEL_INST: - uci_package_foreach_sections_safe(json_object_get_string(file), stmp, s) { - char *dm_parent = NULL; + uci_package_foreach_sections_safe(json_object_get_string(file), stmp, s) { + char *dm_parent = NULL; - dmuci_get_value_by_section_string(s, "dm_parent", &dm_parent); - if (DM_STRLEN(dm_parent) && strcmp(section_name(((struct dm_data *)data)->config_section), dm_parent) == 0) { - if (dmuci_delete_by_section(s, NULL, NULL)) - return -1; - } - } - - get_dmmap_section_of_config_section(json_object_get_string(dmmap_file), json_object_get_string(section_type), section_name(((struct dm_data *)data)->config_section), &dmmap_section); - if (dmuci_delete_by_section(dmmap_section, NULL, NULL)) + dmuci_get_value_by_section_string(s, "dm_parent", &dm_parent); + if (DM_STRLEN(dm_parent) && strcmp(section_name(((struct dm_data *)data)->config_section), dm_parent) == 0) { + if (dmuci_delete_by_section(s, NULL, NULL)) return -1; - - if (dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL)) - return -1; - - break; - case DEL_ALL: - uci_foreach_sections_safe(json_object_get_string(file), json_object_get_string(section_type), stmp, s) { - struct uci_section *ss = NULL, *sstmp = NULL; - - uci_package_foreach_sections_safe(json_object_get_string(file), sstmp, ss) { - char *dm_parent = NULL; - - dmuci_get_value_by_section_string(ss, "dm_parent", &dm_parent); - if (DM_STRLEN(dm_parent) && strcmp(section_name(s), dm_parent) == 0) { - if (dmuci_delete_by_section(ss, NULL, NULL)) - return -1; - } - } - - get_dmmap_section_of_config_section(json_object_get_string(dmmap_file), json_object_get_string(section_type), section_name(s), &dmmap_section); - if (dmuci_delete_by_section(dmmap_section, NULL, NULL)) - return -1; - - if (dmuci_delete_by_section(s, NULL, NULL)) - return -1; - } - break; + } } + + get_dmmap_section_of_config_section(json_object_get_string(dmmap_file), json_object_get_string(section_type), section_name(((struct dm_data *)data)->config_section), &dmmap_section); + if (dmuci_delete_by_section(dmmap_section, NULL, NULL)) + return -1; + + if (dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL)) + return -1; } } diff --git a/test/cmocka/functional_test_bbfd.c b/test/cmocka/functional_test_bbfd.c index 8e85c035..b30a5f8c 100644 --- a/test/cmocka/functional_test_bbfd.c +++ b/test/cmocka/functional_test_bbfd.c @@ -1068,15 +1068,9 @@ static void test_api_bbfdm_add_del_standard_object(void **state) fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); - // delete all object ==> expected "0" error + // delete all object ==> expected "9005" error ctx->in_param = "Device.Users.User."; fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.Users.User.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); } @@ -1111,15 +1105,9 @@ static void test_api_bbfdm_add_del_json_object(void **state) fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); - // delete all object ==> expected "0" error + // delete all object ==> expected "9005" error ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); } @@ -1154,15 +1142,9 @@ static void test_api_bbfdm_add_del_json_v1_object(void **state) fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); - // delete all object ==> expected "0" error + // delete all object ==> expected "9005" error ctx->in_param = "Device.UCI_TEST_V1.OWSD."; fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); // add object ==> expected "9005" error @@ -1213,15 +1195,9 @@ static void test_api_bbfdm_add_del_library_object(void **state) fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); - // delete all object ==> expected "0" error + // delete all object ==> expected "9005" error ctx->in_param = "Device.WiFi.SSID."; fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.WiFi.SSID.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); assert_int_equal(fault, FAULT_9005); } diff --git a/test/cmocka/unit_test_bbfd.c b/test/cmocka/unit_test_bbfd.c index 41b9a72e..17d0ea8b 100644 --- a/test/cmocka/unit_test_bbfd.c +++ b/test/cmocka/unit_test_bbfd.c @@ -345,7 +345,7 @@ static void test_api_bbfdm_delete_object_all_instances(void **state) ctx->in_param = "Device.Users.User."; fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); + assert_int_equal(fault, FAULT_9005); } static void test_api_bbfdm_delete_wrong_object(void **state) @@ -568,7 +568,7 @@ static void test_api_bbfdm_json_delete_object(void **state) ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); + assert_int_equal(fault, FAULT_9005); } static void test_api_bbfdm_library_get_value(void **state) @@ -624,7 +624,7 @@ static void test_api_bbfdm_library_delete_object(void **state) ctx->in_param = "Device.WiFi.SSID."; fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); + assert_int_equal(fault, FAULT_9005); } int main(void) diff --git a/tools/convert_dm_json_to_c.py b/tools/convert_dm_json_to_c.py index 4d3046fb..0d00750b 100755 --- a/tools/convert_dm_json_to_c.py +++ b/tools/convert_dm_json_to_c.py @@ -382,14 +382,7 @@ def cprintAddDelObj(faddobj, fdelobj): print("", file=fp) print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)" % fdelobj, file=fp) print("{", file=fp) - print(" switch (del_action) {", file=fp) - print(" case DEL_INST:", file=fp) - print(" //TODO", file=fp) - print(" break;", file=fp) - print(" case DEL_ALL:", file=fp) - print(" //TODO", file=fp) - print(" break;", file=fp) - print(" }", file=fp) + print(" //TODO", file=fp) print(" return 0;", file=fp) print("}", file=fp) print("", file=fp)