mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-01-27 17:37:17 +01:00
Revert "Revert "Do not commit in get operation""
This reverts merge request !1253
This commit is contained in:
parent
8201f79d12
commit
583fa5dfb9
7 changed files with 84 additions and 7 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,14 +76,44 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_request_timeout(struct uloop_timeout *timeout)
|
||||
{
|
||||
struct ubus_request_tracker *tracker = container_of(timeout, struct ubus_request_tracker, timeout);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// Apply all bbfdm dmmap changes
|
||||
if (data->bbf_ctx.dm_type == BBFDM_BOTH) {
|
||||
dmuci_commit_bbfdm();
|
||||
}
|
||||
|
||||
bbf_cleanup(&data->bbf_ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue