Skip to content
Snippets Groups Projects
Commit ad2636c6 authored by Suvendhu Hansa's avatar Suvendhu Hansa :speech_balloon:
Browse files

Fix empty params in transfer complete event

parent 1561b71a
No related branches found
No related tags found
1 merge request!16Fix empty params in transfer complete event
Pipeline #216182 failed
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "common.h" #include "common.h"
static void send_transfer_complete_event(struct ubus_context *ubus_ctx, const char *command, const char *obj_path, const char *transfer_url, static void send_transfer_complete_event(struct ubus_context *ubus_ctx, const char *command, const char *obj_path, const char *transfer_url,
char *fault_string, time_t start_t, time_t complete_t,const char *commandKey, const char *transfer_type) char *fault_string, time_t start_t, time_t complete_t,const char *commandKey, const char *transfer_type, const char *reqstr)
{ {
char start_time[32] = {0}; char start_time[32] = {0};
char complete_time[32] = {0}; char complete_time[32] = {0};
...@@ -31,12 +31,8 @@ static void send_transfer_complete_event(struct ubus_context *ubus_ctx, const ch ...@@ -31,12 +31,8 @@ static void send_transfer_complete_event(struct ubus_context *ubus_ctx, const ch
void *arr = blobmsg_open_array(&bb, "input"); void *arr = blobmsg_open_array(&bb, "input");
fill_blob_param(&bb, "Command", command, DMT_TYPE[DMT_STRING], 0); fill_blob_param(&bb, "Command", command, DMT_TYPE[DMT_STRING], 0);
if(commandKey) fill_blob_param(&bb, "CommandKey", commandKey ? commandKey : "", DMT_TYPE[DMT_STRING], 0);
fill_blob_param(&bb, "CommandKey", commandKey, DMT_TYPE[DMT_STRING], 0); fill_blob_param(&bb, "Requestor", reqstr ? reqstr : "", DMT_TYPE[DMT_STRING], 0);
else
fill_blob_param(&bb, "CommandKey", "", DMT_TYPE[DMT_STRING], 0);
fill_blob_param(&bb, "Requestor", "", DMT_TYPE[DMT_STRING], 0);
fill_blob_param(&bb, "TransferType", transfer_type, DMT_TYPE[DMT_STRING], 0); fill_blob_param(&bb, "TransferType", transfer_type, DMT_TYPE[DMT_STRING], 0);
fill_blob_param(&bb, "Affected", obj_path, DMT_TYPE[DMT_STRING], 0); fill_blob_param(&bb, "Affected", obj_path, DMT_TYPE[DMT_STRING], 0);
fill_blob_param(&bb, "TransferURL", transfer_url, DMT_TYPE[DMT_STRING], 0); fill_blob_param(&bb, "TransferURL", transfer_url, DMT_TYPE[DMT_STRING], 0);
...@@ -70,7 +66,7 @@ static bool get_response_code_status(const char *url, int response_code) ...@@ -70,7 +66,7 @@ static bool get_response_code_status(const char *url, int response_code)
} }
static int bbf_upload_log(struct ubus_context *ubus_ctx, const char *url, const char *username, const char *password, static int bbf_upload_log(struct ubus_context *ubus_ctx, const char *url, const char *username, const char *password,
char *config_name, const char *command, const char *obj_path, int type) char *config_name, const char *command, const char *obj_path, int type, const char *cmdkey, const char *reqstr)
{ {
int res = 0; int res = 0;
char fault_msg[128] = {0}; char fault_msg[128] = {0};
...@@ -86,10 +82,8 @@ static int bbf_upload_log(struct ubus_context *ubus_ctx, const char *url, const ...@@ -86,10 +82,8 @@ static int bbf_upload_log(struct ubus_context *ubus_ctx, const char *url, const
res = -1; res = -1;
} }
if (type == BBFDM_USP) { // Send the transfer complete event
// Send the transfer complete event send_transfer_complete_event(ubus_ctx, command, obj_path, url, fault_msg, start_time, complete_time, cmdkey, "Upload", reqstr);
send_transfer_complete_event(ubus_ctx, command, obj_path, url, fault_msg, start_time, complete_time, NULL, "Upload");
}
return res; return res;
} }
...@@ -306,17 +300,26 @@ static int archive_log_file(char *arch_file, char *file_path) ...@@ -306,17 +300,26 @@ static int archive_log_file(char *arch_file, char *file_path)
static int operate_DeviceInfoVendorLogFile_Upload(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) static int operate_DeviceInfoVendorLogFile_Upload(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{ {
char upload_path[256] = {0}; char upload_path[256] = {0};
char upload_command[32] = {0}; char upload_command[270] = {0};
char log_tar_file[256] = {0}; char log_tar_file[256] = {0};
char *vlf_file_path = NULL; char *vlf_file_path = NULL;
char *cmdkey = NULL, *reqstr = NULL;
int res; int res;
DM_STRNCPY(log_tar_file, "/tmp/vendor_log-XXXXXX.tar", sizeof(log_tar_file)); DM_STRNCPY(log_tar_file, "/tmp/vendor_log-XXXXXX.tar", sizeof(log_tar_file));
char *ret = DM_STRRCHR(refparam, '.');
if (!ret)
return USP_FAULT_INVALID_ARGUMENT;
if ((ret - refparam + 2) < sizeof(upload_path)) {
snprintf(upload_path, ret - refparam + 2, "%s", refparam);
}
if (ctx->dm_type == BBFDM_USP) { if (ctx->dm_type == BBFDM_USP) {
char *ret = DM_STRRCHR(refparam, '.'); DM_STRNCPY(upload_command, refparam, sizeof(upload_command));
strncpy(upload_path, refparam, ret - refparam +1); cmdkey = dmjson_get_value((json_object *)value, 1, "__BBF_CommandKey");
DM_STRNCPY(upload_command, ret+1, sizeof(upload_command)); reqstr = dmjson_get_value((json_object *)value, 1, "__BBF_Requestor");
} }
char *user = dmjson_get_value((json_object *)value, 1, "Username"); char *user = dmjson_get_value((json_object *)value, 1, "Username");
...@@ -343,7 +346,7 @@ static int operate_DeviceInfoVendorLogFile_Upload(char *refparam, struct dmctx * ...@@ -343,7 +346,7 @@ static int operate_DeviceInfoVendorLogFile_Upload(char *refparam, struct dmctx *
} }
if (res == 0) { if (res == 0) {
res = bbf_upload_log(ctx->ubus_ctx, url, user, pass, log_tar_file, upload_command, upload_path, ctx->dm_type); res = bbf_upload_log(ctx->ubus_ctx, url, user, pass, log_tar_file, upload_command, upload_path, ctx->dm_type, cmdkey, reqstr);
} }
if (file_exists(log_tar_file)) if (file_exists(log_tar_file))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment