From a2ac2601d3a83ee65418e342df3efc6f3d84127e Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Tue, 16 Nov 2021 17:19:12 +0100 Subject: [PATCH] Improve JSON mapping && Fix some issues in browse function --- README.md | 39 +- dmdynamicjson.c | 365 +++++++++++------- test/cmocka/functional_test_bbfd.c | 6 +- .../etc/bbfdm/json/X_IOPSYS_EU_WiFi.json | 4 - test/files/etc/bbfdm/json/index.json | 26 ++ test/files/tmp/dhcp.ipv6leases.data | 4 +- 6 files changed, 285 insertions(+), 159 deletions(-) diff --git a/README.md b/README.md index fb0d0f4a..1ab3434d 100644 --- a/README.md +++ b/README.md @@ -707,45 +707,42 @@ The application should bring its JSON file under **'/etc/bbfdm/json/'** path wit "version": "2.13", "protocols": [ "usp" - ], - "datatype": "string" + ] } }, "Status()": { "type": "command", "async": true, - "version" : "2.12", + "version": "2.12", "protocols": [ "usp" ], "input": { - "Option" : { - "type" : "string", - "read" : "true", - "write" : "true", - "protocol" : [ + "Option": { + "type": "string", + "read": "true", + "write": "true", + "protocols": [ "usp" - ], - "datatype" : "string" + ] } }, "output": { - "Result" : { - "type" : "string", - "read" : "true", - "write" : "false", - "protocol" : [ + "Result": { + "type": "string", + "read": "true", + "write": "false", + "protocols": [ "usp" - ], - "datatype" : "string" + ] } }, "mapping": [ { - "type" : "ubus", - "ubus" : { - "object" : "test", - "method" : "status" + "type": "ubus", + "ubus": { + "object": "test", + "method": "status" } } ] diff --git a/dmdynamicjson.c b/dmdynamicjson.c index 650ff478..d0ec3c67 100644 --- a/dmdynamicjson.c +++ b/dmdynamicjson.c @@ -218,6 +218,141 @@ static int get_index_of_available_entry(DMOBJ *jentryobj) return idx; } +static json_object *get_requested_json_obj(json_object *json_obj, char *instance, const char *key, char *arr_name, size_t arr_len) +{ + struct json_object *res = json_obj; + char *pch = NULL, *pchr = NULL; + char buf_args[256] = {0}; + + DM_STRNCPY(buf_args, key, sizeof(buf_args)); + + for (pch = strtok_r(buf_args, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { + + if (pchr && *pchr && (strchr(pch, '['))) { + char buf[32] = {0}; + unsigned idx_pos = 0; + + DM_STRNCPY(buf, pch, sizeof(buf)); + buf[strlen(buf) - 1] = 0; + char *p = strchr(buf, '['); + + if (strcmp(p+1, "@index") == 0 || strcmp(p+1, "@i-1") == 0) { + idx_pos = instance ? atoi(instance)-1 : 1; + } else { + idx_pos = atoi(p+1); + } + *p = 0; + + res = (idx_pos >= 0) ? dmjson_select_obj_in_array_idx(res, idx_pos, 1, buf) : res; + + } else if (pchr && *pchr) { + res = dmjson_get_obj(res, 1, pch); + } + + DM_STRNCPY(arr_name, pch, arr_len); + } + + return res; +} + +static int get_number_of_instances(char *refparam) +{ + char *pch = NULL, *pchr = NULL; + char buf_path[512] = {0}; + int nbr_inst = 0; + + DM_STRNCPY(buf_path, refparam, sizeof(buf_path)); + + for (pch = strtok_r(buf_path, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { + if (atoi(pch) != 0) + nbr_inst++; + } + + return nbr_inst; +} + +static void replace_indexes(struct dmctx *ctx, char *old_key, char *new_key, size_t key_len) +{ + char buf_key[256] = {0}; + unsigned char idx = 0; + unsigned pos = 0; + + DM_STRNCPY(buf_key, old_key, sizeof(buf_key)); + + for (int i = 0; buf_key[i] != '\0'; i++) { + if (strstr(&buf_key[i], "{i}") == &buf_key[i]) { + pos += snprintf(&new_key[pos], key_len - pos, "%s", ctx->inst_buf[idx] ? ctx->inst_buf[idx] : ""); + idx++; + i += 3; // increase i with length of "{i}" + } + + pos += snprintf(&new_key[pos], key_len - pos, "%c", buf_key[i]); + } +} + +static void resolve_all_symbols(struct dmctx *ctx, void *data, char *instance, char *value, int nbr_instances, int json_version, + const char *old_key, char *new_key, size_t key_len) +{ + char *pch = NULL, *pchr = NULL; + char buf_key[256] = {0}; + unsigned pos = 0; + + DM_STRNCPY(buf_key, old_key, sizeof(buf_key)); + + for (pch = strtok_r(buf_key, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { + + if (strcmp(pch, "@Name") == 0) + pos += snprintf(&new_key[pos], key_len - pos, "%s.", data ? section_name((struct uci_section *)data) : ""); + else if (strcmp(pch, "@Value") == 0) + pos += snprintf(&new_key[pos], key_len - pos, "%s.", value); + else if (strcmp(pch, (json_version == JSON_VERSION_1) ? "@index" : "@i-1") == 0) + pos += snprintf(&new_key[pos], key_len - pos, "%d.", instance ? atoi(instance)-1 : 1); + else if (strstr(pch, "@index-")) { + char *p = strchr(pch, '-'); + int idx_pos = atoi(p + 1); + + if (idx_pos != 0 && nbr_instances - idx_pos >= 0) + pos += snprintf(&new_key[pos], key_len - pos, "%s.", ctx->inst_buf[nbr_instances - idx_pos] ? ctx->inst_buf[nbr_instances - idx_pos] : ""); + } else + pos += snprintf(&new_key[pos], key_len - pos, "%s.", pch); + } + + if (pos) + new_key[pos - 1] = 0; + + if (strstr(new_key, "{i}")) + replace_indexes(ctx, new_key, new_key, key_len); +} + +static int fill_ubus_arguments(struct dmctx *ctx, void *data, char *instance, char *value, int nbr_instances, int json_version, + struct json_object *args_obj, struct ubus_arg u_args[]) +{ + int u_args_size = 0; + + json_object_object_foreach(args_obj, key, val) { + char buf_key[256] = {0}; + char buf_val[256] = {0}; + + resolve_all_symbols(ctx, data, instance, value, nbr_instances, json_version, key, buf_key, sizeof(buf_key)); + resolve_all_symbols(ctx, data, instance, value, nbr_instances, json_version, json_object_get_string(val), buf_val, sizeof(buf_val)); + + u_args[u_args_size].key = dm_dynamic_strdup(&json_memhead, buf_key); + u_args[u_args_size].val = dm_dynamic_strdup(&json_memhead, buf_val); + u_args[u_args_size].type = String; + u_args_size++; + } + + return u_args_size; +} + +static void free_ubus_arguments(struct ubus_arg u_args[], int u_args_size) +{ + for (int i = 0; i < u_args_size; i++) { + dmfree((char *)u_args[i].key); + dmfree((char *)u_args[i].val); + } +} + static int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct dm_json_obj *pobj = NULL; @@ -289,25 +424,39 @@ static int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, struct json_object *method = NULL; struct json_object *args_obj = NULL; struct json_object *key = NULL; - char *args1 = NULL; + struct ubus_arg u_args[16] = {0}; + char buf_object[256] = {0}; + char buf_method[256] = {0}; + int u_args_size = 0; + + int nbr_instances = get_number_of_instances(parent_node->current_object); json_object_object_get_ex((mapping_0 && json_version == JSON_VERSION_1) ? mapping_0 : mapping_obj, "ubus", &ubus_obj); json_object_object_get_ex(ubus_obj, "object", &object); json_object_object_get_ex(ubus_obj, "method", &method); json_object_object_get_ex(ubus_obj, "args", &args_obj); - json_object_object_foreach(args_obj, arg1, args2) { - args1 = arg1; - } json_object_object_get_ex(ubus_obj, "key", &key); - if (object && method && args1 && args2) - dmubus_call(json_object_get_string(object), json_object_get_string(method), UBUS_ARGS{{args1, json_object_get_string(args2), String}}, 1, &res); - else - dmubus_call(json_object_get_string(object), json_object_get_string(method), UBUS_ARGS{0}, 0, &res); + if (object) + resolve_all_symbols(dmctx, prev_data, prev_instance, "", nbr_instances, json_version, json_object_get_string(object), buf_object, sizeof(buf_object)); + + if (method) + resolve_all_symbols(dmctx, prev_data, prev_instance, "", nbr_instances, json_version, json_object_get_string(method), buf_method, sizeof(buf_method)); + + if (args_obj) + u_args_size = fill_ubus_arguments(dmctx, prev_data, prev_instance, "", nbr_instances, json_version, args_obj, u_args); + + dmubus_call(buf_object, buf_method, u_args, u_args_size, &res); + + free_ubus_arguments(u_args, u_args_size); + if (res && key) { + char arr_name[32] = {0}; int id = 0, i = 0; - dmjson_foreach_obj_in_array(res, arrobj, dyn_obj, i, 1, json_object_get_string(key)) { + json_object *arr_obj = get_requested_json_obj(res, prev_instance, json_object_get_string(key), arr_name, sizeof(arr_name)); + + dmjson_foreach_obj_in_array(arr_obj, arrobj, dyn_obj, i, 1, arr_name) { char *inst = handle_instance_without_section(dmctx, parent_node, ++id); if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dyn_obj, inst) == DM_STOP) break; @@ -439,37 +588,6 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -static char *get_param_ubus_value(json_object *json_obj, char *arguments) -{ - char *value = ""; - - char *opt = strchr(arguments, '.'); - if (opt) { - *opt = '\0'; - value = dmjson_get_value(json_obj, 2, arguments, opt + 1); - } else { - value = dmjson_get_value(json_obj, 1, arguments); - } - - return value; -} - -static void replace_indexes(struct dmctx *ctx, char *refparam, char *obj, size_t obj_size) -{ - unsigned pos = 0; - unsigned char idx = 0; - - for (int i = 0; refparam[i] != '\0'; i++) { - if (strstr(&refparam[i], "{i}") == &refparam[i]) { - pos += snprintf(&obj[pos], obj_size - pos, "%s", ctx->inst_buf[idx] ? ctx->inst_buf[idx] : ""); - idx++; - i += 3; // increase i with length of "{i}" - } - - pos += snprintf(&obj[pos], obj_size - pos, "%c", refparam[i]); - } -} - static char *uci_get_value(json_object *mapping_obj, int json_version, char *refparam, struct dmctx *ctx, void *data, char *instance) { struct json_object *obj = NULL; @@ -491,9 +609,9 @@ static char *uci_get_value(json_object *mapping_obj, int json_version, char *ref json_object_object_get_ex(option, "name", &option_name); json_object_object_get_ex(obj, "path", &path); - if (file && type && option_name && strstr(refparam, "NumberOfEntries") && json_version == JSON_VERSION_1) { + if (file && type && option_name && strstr(refparam, "NumberOfEntries")) { - if (strcmp(json_object_get_string(option_name), "@Count") != 0) + if (strcmp(json_object_get_string(option_name), "@Count") != 0 && json_version == JSON_VERSION_1) goto end; struct uci_section *s = NULL; @@ -533,55 +651,51 @@ static char *ubus_get_value(json_object *mapping_obj, int json_version, char *re struct json_object *key = NULL; struct json_object *args = NULL; struct json_object *res = NULL; - char arg2_1[128] = {0}, *opt = NULL; - char *args1 = NULL; + char buf_object[256] = {0}; + char buf_method[256] = {0}; + struct ubus_arg u_args[16] = {0}; + int u_args_size = 0; char *value = ""; + int nbr_instances = get_number_of_instances(refparam); + json_object_object_get_ex(mapping_obj, "ubus", &ubus_obj); json_object_object_get_ex(ubus_obj, "object", &object); json_object_object_get_ex(ubus_obj, "method", &method); json_object_object_get_ex(ubus_obj, "args", &args); - json_object_object_foreach(args, arg1, args2) { - args1 = arg1; - } json_object_object_get_ex(ubus_obj, "key", &key); - if ((opt = strstr(json_object_get_string(object), "@Name"))) { - *opt = '\0'; - snprintf(arg2_1, sizeof(arg2_1), "%s%s", json_object_get_string(object), section_name((struct uci_section *)data)); - } else if ((opt = strstr(json_object_get_string(object), (json_version == JSON_VERSION_1) ? "@index" : "@i-1"))) { - *opt = '\0'; - snprintf(arg2_1, sizeof(arg2_1), "%s%d", json_object_get_string(object), atoi(instance) - 1); - } else { - DM_STRNCPY(arg2_1, json_object_get_string(object), sizeof(arg2_1)); - } + if (object) + resolve_all_symbols(ctx, data, instance, "", nbr_instances, json_version, json_object_get_string(object), buf_object, sizeof(buf_object)); - if (args1 && args2 && method) { - if (data && (strcmp(json_object_get_string(args2), "@Name") == 0)) { - dmubus_call(arg2_1, json_object_get_string(method), UBUS_ARGS{{args1, section_name((struct uci_section *)data), String}}, 1, &res); - } else if (strstr(json_object_get_string(args2), "{i}")) { - char arg2_buf[512] = {0}; + if (method) + resolve_all_symbols(ctx, data, instance, "", nbr_instances, json_version, json_object_get_string(method), buf_method, sizeof(buf_method)); - replace_indexes(ctx, json_object_get_string(args2), arg2_buf, sizeof(arg2_buf)); - dmubus_call(arg2_1, json_object_get_string(method), UBUS_ARGS{{args1, arg2_buf, String}}, 1, &res); - } else { - dmubus_call(arg2_1, json_object_get_string(method), UBUS_ARGS{{args1, json_object_get_string(args2), String}}, 1, &res); - } - } else { - dmubus_call(arg2_1, json_object_get_string(method), UBUS_ARGS{0}, 0, &res); - } + if (args) + u_args_size = fill_ubus_arguments(ctx, data, instance, "", nbr_instances, json_version, args, u_args); - if (key && strstr(refparam, "NumberOfEntries") && json_version == JSON_VERSION_1) { + dmubus_call(buf_object, buf_method, u_args, u_args_size, &res); + + free_ubus_arguments(u_args, u_args_size); + + if (key && strstr(refparam, "NumberOfEntries")) { + json_object *arr_obj = NULL; char buf[64] = {0}; - char *str = NULL; + int nbre_entries = 0; DM_STRNCPY(buf, json_object_get_string(key), sizeof(buf)); - if ((str = strstr(buf, ".@Count")) == NULL || res == NULL) + + if (res == NULL) goto end; - json_object *arr_obj = NULL; - int nbre_entries = 0; - *str = 0; + if (json_version == JSON_VERSION_1) { + char *str = NULL; + + if ((str = strstr(buf, ".@Count")) == NULL) + goto end; + + *str = 0; + } json_object_object_get_ex(res, buf, &arr_obj); nbre_entries = (arr_obj) ? json_object_array_length(arr_obj) : 0; @@ -590,15 +704,18 @@ static char *ubus_get_value(json_object *mapping_obj, int json_version, char *re } if (key) { - char arg6_buf[128] = ""; + char key_buf[128] = {0}; + char key_name[32] = {0}; - DM_STRNCPY(arg6_buf, json_object_get_string(key), sizeof(arg6_buf)); - char *is_array = strstr(arg6_buf, (json_version == JSON_VERSION_1) ? "[@index]" : "[@i-1]"); - if (is_array) { + DM_STRNCPY(key_buf, json_object_get_string(key), sizeof(key_buf)); + char *is_array = strstr(key_buf, (json_version == JSON_VERSION_1) ? "[@index]" : "[@i-1]"); + if (data && is_array) { char *arguments = (json_version == JSON_VERSION_1) ? is_array + sizeof("[@index]") : is_array + sizeof("[@i-1]"); - value = get_param_ubus_value((json_object *)data, arguments); + json_object *json_obj = get_requested_json_obj((json_object *)data, instance, arguments, key_name, sizeof(key_name)); + value = dmjson_get_value(json_obj, 1, key_name); } else { - value = get_param_ubus_value(res, arg6_buf); + json_object *json_obj = get_requested_json_obj(res, instance, key_buf, key_name, sizeof(key_name)); + value = dmjson_get_value(json_obj, 1, key_name); } } @@ -644,11 +761,10 @@ static char *ubus_v1_get_value(json_object *mapping_obj, char *refparam, struct goto end; if (key) { - char key_buf[128] = ""; - - DM_STRNCPY(key_buf, json_object_get_string(key), sizeof(key_buf)); - value = get_param_ubus_value((json_object *)data, key_buf); + char key_name[128] = {32}; + json_object *json_obj = get_requested_json_obj((json_object *)data, instance, json_object_get_string(key), key_name, sizeof(key_name)); + value = dmjson_get_value(json_obj, 1, key_name); } end: @@ -711,33 +827,38 @@ static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -static int ubus_set_operate(json_object *mapping_obj, int json_version, struct dmctx *ctx, void *data, void *value, char *instance) +static int ubus_set_operate(json_object *mapping_obj, int json_version, char *refparam, struct dmctx *ctx, void *data, void *value, char *instance) { struct json_object *ubus_obj = NULL; struct json_object *object = NULL; struct json_object *method = NULL; struct json_object *res = NULL; - char obj_name[128] = {0}, *opt = NULL; + char buf_object[256] = {0}; + char buf_method[256] = {0}; + + int nbr_instances = get_number_of_instances(refparam); json_object_object_get_ex(mapping_obj, "ubus", &ubus_obj); json_object_object_get_ex(ubus_obj, "object", &object); json_object_object_get_ex(ubus_obj, "method", &method); - if ((opt = strstr(json_object_get_string(object), "@Name"))) { - *opt = '\0'; - snprintf(obj_name, sizeof(obj_name), "%s%s", json_object_get_string(object), section_name((struct uci_section *)data)); - } else if ((opt = strstr(json_object_get_string(object), (json_version == JSON_VERSION_1) ? "@index" : "@i-1"))) { - *opt = '\0'; - snprintf(obj_name, sizeof(obj_name), "%s%d", json_object_get_string(object), atoi(instance) - 1); - } else { - DM_STRNCPY(obj_name, json_object_get_string(object), sizeof(obj_name)); - } + if (object) + resolve_all_symbols(ctx, data, instance, "", nbr_instances, json_version, json_object_get_string(object), buf_object, sizeof(buf_object)); - dmubus_operate_blob_set(obj_name, json_object_get_string(method), value, &res); + if (method) + resolve_all_symbols(ctx, data, instance, "", nbr_instances, json_version, json_object_get_string(method), buf_method, sizeof(buf_method)); + + dmubus_operate_blob_set(buf_object, buf_method, value, &res); if (res) { json_object_object_foreach(res, key, val) { - add_list_parameter(ctx, dmstrdup(key), dmstrdup(json_object_to_json_string(val)), DMT_TYPE[DMT_STRING], NULL); + char buf_key[256] = {0}; + char buf_val[256] = {0}; + + resolve_all_symbols(ctx, data, instance, "", nbr_instances, json_version, key, buf_key, sizeof(buf_key)); + resolve_all_symbols(ctx, data, instance, "", nbr_instances, json_version, json_object_get_string(val), buf_val, sizeof(buf_val)); + + add_list_parameter(ctx, dmstrdup(buf_key), dmstrdup(buf_val), DMT_TYPE[DMT_STRING], NULL); } json_object_put(res); } @@ -797,7 +918,7 @@ static int setcommand_param(char *refparam, struct dmctx *ctx, void *data, char json_object_object_get_ex(map_obj, "type", &type); if (type && strcmp(json_object_get_string(type), "ubus") == 0) { - return ubus_set_operate(map_obj, json_version, ctx, data, value, instance); + return ubus_set_operate(map_obj, json_version, refparam, ctx, data, value, instance); } return CMD_FAIL; @@ -1066,46 +1187,30 @@ static void ubus_set_value(json_object *mapping_obj, int json_version, char *ref struct json_object *object = NULL; struct json_object *method = NULL; struct json_object *args = NULL; - char *args1 = NULL, *opt = NULL; - char obj_buf[128] = {0}; - char object_buf[256] = {0}; + char buf_object[256] = {0}; + char buf_method[256] = {0}; + struct ubus_arg u_args[16] = {0}; + int u_args_size = 0; + + int nbr_instances = get_number_of_instances(refparam); json_object_object_get_ex(mapping_obj, "ubus", &ubus_obj); json_object_object_get_ex(ubus_obj, "object", &object); json_object_object_get_ex(ubus_obj, "method", &method); json_object_object_get_ex(ubus_obj, "args", &args); - json_object_object_foreach(args, arg1, args2) { - args1 = arg1; - } - DM_STRNCPY(obj_buf, json_object_get_string(object), sizeof(obj_buf)); + if (object) + resolve_all_symbols(ctx, data, instance, value, json_version, nbr_instances, json_object_get_string(object), buf_object, sizeof(buf_object)); - if ((opt = strstr(obj_buf, "@Name"))) { - *opt = '\0'; - snprintf(object_buf, sizeof(object_buf), "%s%s", obj_buf, section_name((struct uci_section *)data)); - } else if ((opt = strstr(obj_buf, (json_version == JSON_VERSION_1) ? "@index" : "@i-1"))) { - *opt = '\0'; - snprintf(object_buf, sizeof(object_buf), "%s%d", obj_buf, atoi(instance) - 1); - } else { - DM_STRNCPY(object_buf, json_object_get_string(object), sizeof(object_buf)); - } + if (method) + resolve_all_symbols(ctx, data, instance, value, json_version, nbr_instances, json_object_get_string(method), buf_method, sizeof(buf_method)); - if (args1 && args2 && method) { - if (data && (strcmp(json_object_get_string(args2), "@Name") == 0)) { - dmubus_call_set(object_buf, json_object_get_string(method), UBUS_ARGS{{args1, section_name((struct uci_section *)data), String}}, 1); - } else if (strstr(json_object_get_string(args2), "{i}")) { - char arg2_buf[512] = {0}; + if (args) + u_args_size = fill_ubus_arguments(ctx, data, instance, value, nbr_instances, json_version, args, u_args); - replace_indexes(ctx, json_object_get_string(args2), arg2_buf, sizeof(arg2_buf)); - dmubus_call_set(object_buf, json_object_get_string(method), UBUS_ARGS{{args1, arg2_buf, String}}, 1); - } else if (strcmp(json_object_get_string(args2), "@Value") == 0) { - dmubus_call_set(object_buf, json_object_get_string(method), UBUS_ARGS{{args1, value, String}}, 1); - } else { - dmubus_call_set(object_buf, json_object_get_string(method), UBUS_ARGS{{args1, json_object_get_string(args2), String}}, 1); - } - } else { - dmubus_call_set(object_buf, json_object_get_string(method), UBUS_ARGS{0}, 0); - } + dmubus_call_set(buf_object, buf_method, u_args, u_args_size); + + free_ubus_arguments(u_args, u_args_size); } static void uci_v1_set_value(json_object *mapping_obj, int json_version, char *refparam, struct dmctx *ctx, void *data, char *instance, char *value) diff --git a/test/cmocka/functional_test_bbfd.c b/test/cmocka/functional_test_bbfd.c index b4f78132..fb0d69e2 100644 --- a/test/cmocka/functional_test_bbfd.c +++ b/test/cmocka/functional_test_bbfd.c @@ -1337,7 +1337,8 @@ static void test_api_bbfdm_valid_json_operate(void **state) assert_int_equal(fault, CMD_SUCCESS); list_for_each_entry(n, &ctx->list_parameter, list) { - assert_string_not_equal(n->data, "Success"); + assert_string_equal(n->name, "Result"); + assert_string_equal(n->data, "Success"); assert_string_equal(n->type, "xsd:string"); } } @@ -1394,7 +1395,8 @@ static void test_api_bbfdm_valid_json_v1_operate(void **state) assert_int_equal(fault, CMD_SUCCESS); list_for_each_entry(n, &ctx->list_parameter, list) { - assert_string_not_equal(n->data, "Success"); + assert_string_equal(n->name, "Result"); + assert_string_equal(n->data, "Success"); assert_string_equal(n->type, "xsd:string"); } } diff --git a/test/files/etc/bbfdm/json/X_IOPSYS_EU_WiFi.json b/test/files/etc/bbfdm/json/X_IOPSYS_EU_WiFi.json index df2af78a..894e1b1d 100644 --- a/test/files/etc/bbfdm/json/X_IOPSYS_EU_WiFi.json +++ b/test/files/etc/bbfdm/json/X_IOPSYS_EU_WiFi.json @@ -26,7 +26,6 @@ "cwmp", "usp" ], - "datatype": "int", "mapping": [ { "type" : "ubus", @@ -48,7 +47,6 @@ "cwmp", "usp" ], - "datatype": "string", "mapping": [ { "type" : "ubus", @@ -79,7 +77,6 @@ "cwmp", "usp" ], - "datatype": "unsignedInt", "mapping": [ { "type" : "ubus", @@ -101,7 +98,6 @@ "cwmp", "usp" ], - "datatype": "unsignedInt", "mapping": [ { "type" : "ubus", diff --git a/test/files/etc/bbfdm/json/index.json b/test/files/etc/bbfdm/json/index.json index 67610901..25a82a67 100644 --- a/test/files/etc/bbfdm/json/index.json +++ b/test/files/etc/bbfdm/json/index.json @@ -1,6 +1,7 @@ { "Device.PD2.{i}.": { "type": "object", + "version": "2.14", "protocols": [ "cwmp", "usp" @@ -16,8 +17,31 @@ "key": "devices" } }, + "MiniHubNumberOfEntries": { + "type": "int", + "version": "2.14", + "protocols": [ + "cwmp", + "usp" + ], + "read": true, + "write": false, + "datatype": "int", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "proxd", + "method": "list", + "args": {}, + "key": "devices" + } + } + ] + }, "Device.PD2.{i}.MiniHub.{i}.": { "type": "object", + "version": "2.14", "protocols": [ "cwmp", "usp" @@ -35,6 +59,7 @@ }, "Device.PD2.{i}.MiniHub.{i}.DeviceInfo.": { "type": "object", + "version": "2.14", "protocols": [ "cwmp", "usp" @@ -43,6 +68,7 @@ "array": false, "Description": { "type": "string", + "version": "2.14", "read": true, "write": false, "protocols": [ diff --git a/test/files/tmp/dhcp.ipv6leases.data b/test/files/tmp/dhcp.ipv6leases.data index 36027abe..c67436bb 100644 --- a/test/files/tmp/dhcp.ipv6leases.data +++ b/test/files/tmp/dhcp.ipv6leases.data @@ -20,7 +20,7 @@ ], "valid": 1284 }, - { + { "duid": "0004bc823a7bb321a63f328ef37740021102", "iaid": 1420466609, "hostname": "", @@ -31,7 +31,7 @@ ], "ipv6-addr": [ { - "2001:1ba8:1458:ce00::bf3", + "address": "2001:1ba8:1458:ce00::bf3", "preferred-lifetime": 17099, "valid-lifetime": 27899 }