diff --git a/bbfdmd/ubus/bbfdmd.c b/bbfdmd/ubus/bbfdmd.c index d7ce3ce5..7049cf56 100644 --- a/bbfdmd/ubus/bbfdmd.c +++ b/bbfdmd/ubus/bbfdmd.c @@ -294,6 +294,8 @@ static int bbfdm_handler_async(struct ubus_context *ctx, struct ubus_object *obj context->ubus_ctx = ctx; context->raw_format = raw_format; + INIT_LIST_HEAD(&context->uci_modified); + memset(&context->tmp_bb, 0, sizeof(struct blob_buf)); blob_buf_init(&context->tmp_bb, 0); diff --git a/bbfdmd/ubus/common.c b/bbfdmd/ubus/common.c index 7ee99179..a3c8858a 100644 --- a/bbfdmd/ubus/common.c +++ b/bbfdmd/ubus/common.c @@ -109,6 +109,21 @@ struct blob_attr *get_results_array(struct blob_attr *msg) return tb[0]; } +struct blob_attr *get_modified_uci_array(struct blob_attr *msg) +{ + struct blob_attr *tb[1] = {0}; + const struct blobmsg_policy p[1] = { + { "modified_uci", BLOBMSG_TYPE_ARRAY } + }; + + if (msg == NULL) + return NULL; + + blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg)); + + return tb[0]; +} + bool str_match(const char *string, const char *pattern, size_t nmatch, regmatch_t pmatch[]) { regex_t re; diff --git a/bbfdmd/ubus/common.h b/bbfdmd/ubus/common.h index 77cd07dd..47a961b2 100644 --- a/bbfdmd/ubus/common.h +++ b/bbfdmd/ubus/common.h @@ -39,6 +39,7 @@ unsigned int get_proto_type(const char *proto); void fill_optional_input(struct blob_attr *msg, unsigned int *proto, bool *raw_format); struct blob_attr *get_results_array(struct blob_attr *msg); +struct blob_attr *get_modified_uci_array(struct blob_attr *msg); bool str_match(const char *string, const char *pattern, size_t nmatch, regmatch_t pmatch[]); bool proto_match(unsigned int dm_type, const enum bbfdmd_type_enum type); diff --git a/bbfdmd/ubus/get.c b/bbfdmd/ubus/get.c index 12b66340..5cc78f3f 100644 --- a/bbfdmd/ubus/get.c +++ b/bbfdmd/ubus/get.c @@ -30,6 +30,17 @@ static void prepare_and_send_response(struct async_request_context *ctx) blobmsg_close_array(&ctx->tmp_bb, ctx->array); + struct list_uci_modified *list_node = NULL, *tmp = NULL; + void *array = blobmsg_open_array(&ctx->tmp_bb, "modified_uci"); + + list_for_each_entry_safe(list_node, tmp, &ctx->uci_modified, list) { + blobmsg_add_string(&ctx->tmp_bb, "", list_node->file_path); + list_del(&list_node->list); + BBFDM_FREE(list_node); + } + + blobmsg_close_array(&ctx->tmp_bb, array); + if (strcmp(ctx->ubus_method, "get") == 0 && ctx->raw_format == false) { // Pretty Format struct blob_buf bb_pretty = {0}; @@ -65,11 +76,41 @@ static void append_response_data(struct ubus_request_tracker *tracker, struct bl return; struct blob_attr *results = get_results_array(msg); - if (!results) - return; + if (results) { + blobmsg_for_each_attr(attr, results, remaining) { + blobmsg_add_blob(&tracker->ctx->tmp_bb, attr); + } + } - blobmsg_for_each_attr(attr, results, remaining) { - blobmsg_add_blob(&tracker->ctx->tmp_bb, attr); + struct blob_attr *modified_uci = get_modified_uci_array(msg); + if (modified_uci) { + bool exist = false; + struct list_uci_modified *list_node = NULL; + + attr = NULL; + remaining = 0; + + blobmsg_for_each_attr(attr, modified_uci, remaining) { + list_for_each_entry(list_node, &tracker->ctx->uci_modified, list) { + if (strcmp(list_node->file_path, blobmsg_get_string(attr)) == 0) { + exist = true; + break; + } + } + + if (exist == true) + continue; + + list_node = (struct list_uci_modified *)calloc(1, sizeof(struct list_uci_modified)); + if (list_node == NULL) { + BBFDM_INFO("Failed to allocate memory in get response handler for changed uci"); + continue; + } + + INIT_LIST_HEAD(&list_node->list); + list_add_tail(&list_node->list, &tracker->ctx->uci_modified); + snprintf(list_node->file_path, sizeof(list_node->file_path), "%s", blobmsg_get_string(attr)); + } } } diff --git a/bbfdmd/ubus/get.h b/bbfdmd/ubus/get.h index 53680980..3b234140 100644 --- a/bbfdmd/ubus/get.h +++ b/bbfdmd/ubus/get.h @@ -20,6 +20,7 @@ enum { }; struct async_request_context { + struct list_head uci_modified; struct ubus_context *ubus_ctx; struct ubus_request_data request_data; struct blob_buf tmp_bb; @@ -40,6 +41,11 @@ struct ubus_request_tracker { char request_name[128]; }; +struct list_uci_modified { + struct list_head list; + char file_path[2048]; +}; + void run_async_call(struct async_request_context *ctx, service_entry_t *service, struct blob_attr *msg); void send_response(struct async_request_context *ctx); diff --git a/libbbfdm-ubus/get.c b/libbbfdm-ubus/get.c index 4d8ff690..28b38cd7 100644 --- a/libbbfdm-ubus/get.c +++ b/libbbfdm-ubus/get.c @@ -42,6 +42,16 @@ void bbfdm_get(bbfdm_data_t *data, int method) blobmsg_close_array(&data->bbf_ctx.bb, array); + array = blobmsg_open_array(&data->bbf_ctx.bb, "modified_uci"); + if (data->bbf_ctx.modified_uci_head != NULL) { + struct dm_modified_uci *m; + list_for_each_entry(m, data->bbf_ctx.modified_uci_head, list) { + bb_add_string(&data->bbf_ctx.bb, "", m->uci_file); + } + } + + blobmsg_close_array(&data->bbf_ctx.bb, array); + if (!validate_msglen(data)) { BBF_ERR("IPC failed for path(%s)", data->bbf_ctx.in_param); } @@ -50,8 +60,10 @@ void bbfdm_get(bbfdm_data_t *data, int method) ubus_send_reply(data->ctx, data->req, data->bbf_ctx.bb.head); } - // Apply all bbfdm changes - dmuci_commit_bbfdm(); + // Apply all bbfdm dmmap changes + if (data->bbf_ctx.dm_type == BBFDM_BOTH) { + dmuci_commit_bbfdm(); + } bbf_cleanup(&data->bbf_ctx); } diff --git a/utilities/src/ubus/utils.c b/utilities/src/ubus/utils.c index b2398645..cd1b63f9 100644 --- a/utilities/src/ubus/utils.c +++ b/utilities/src/ubus/utils.c @@ -105,7 +105,7 @@ static void add_external_action_list(struct list_head *action_list, struct list_ bool arg_exist = false; list_for_each_entry(act_node, action_list, list) { - if (strcmp(app_node->action, DEFAULT_HANDLER_ACT) == 0) { + if (strcmp(act_node->action, DEFAULT_HANDLER_ACT) == 0) { node_exist = true; for (int i = 0; i < act_node->idx; i++) { if (strcmp(act_node->arg[i], config) == 0) {