diff --git a/Makefile.am b/Makefile.am index e9906c7..9468741 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,6 @@ bin_PROGRAMS = icwmpd icwmpd_SOURCES = \ ./common.c \ - ./cwmp_time.c \ ./log.c \ ./cwmp_uci.c \ ./config.c \ diff --git a/common.c b/common.c index 6fc899c..d787d35 100755 --- a/common.c +++ b/common.c @@ -724,6 +724,26 @@ int get_connection_interface() return CWMP_OK; } +char *get_time(time_t t_time) +{ + static char local_time[32] = {0}; + struct tm *t_tm; + + t_tm = localtime(&t_time); + if (t_tm == NULL) + return NULL; + + if (strftime(local_time, sizeof(local_time), "%FT%T%z", t_tm) == 0) + return NULL; + + local_time[25] = local_time[24]; + local_time[24] = local_time[23]; + local_time[22] = ':'; + local_time[26] = '\0'; + + return local_time; +} + bool is_obj_excluded(char *object_name) { unsigned int i = 0; diff --git a/cwmp_du_state.c b/cwmp_du_state.c index e2ce415..d810cc9 100644 --- a/cwmp_du_state.c +++ b/cwmp_du_state.c @@ -16,7 +16,6 @@ #include "ubus.h" #include "log.h" #include "datamodel_interface.h" -#include "cwmp_time.h" #include "backupSession.h" #include "event.h" @@ -202,7 +201,7 @@ static int cwmp_launch_du_install(char *url, char *uuid, char *user, char *pass, int error = FAULT_CPE_NO_FAULT; char *fault_code; - (*pchange_du_state_complete)->start_time = strdup(mix_get_time()); + (*pchange_du_state_complete)->start_time = strdup(get_time(time(NULL))); cwmp_du_install(url, uuid, user, pass, env_name, env_id, &fault_code); if (fault_code != NULL) { @@ -225,7 +224,7 @@ static int cwmp_launch_du_update(char *uuid, char *url, char *user, char *pass, int error = FAULT_CPE_NO_FAULT; char *fault_code; - (*pchange_du_state_complete)->start_time = strdup(mix_get_time()); + (*pchange_du_state_complete)->start_time = strdup(get_time(time(NULL))); cwmp_du_update(url, uuid, user, pass, env_name, env_id, &fault_code); if (fault_code != NULL) { @@ -248,7 +247,7 @@ static int cwmp_launch_du_uninstall(char *package_name, char *env_name, int env_ int error = FAULT_CPE_NO_FAULT; char *fault_code; - (*pchange_du_state_complete)->start_time = strdup(mix_get_time()); + (*pchange_du_state_complete)->start_time = strdup(get_time(time(NULL))); cwmp_du_uninstall(package_name, env_name, env_id, &fault_code); @@ -326,7 +325,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v) res->uuid = strdup(p->uuid); res->version = strdup(p->version); res->current_state = strdup("Failed"); - res->start_time = strdup(mix_get_time()); + res->start_time = strdup(get_time(time(NULL))); res->complete_time = strdup(res->start_time); res->fault = error; } @@ -378,7 +377,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v) res->resolved = 0; } - res->complete_time = strdup(mix_get_time()); + res->complete_time = strdup(get_time(time(NULL))); res->fault = error; break; @@ -411,7 +410,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v) get_du_version(du_ref, &package_version); res->version = strdup(package_version ? package_version : ""); res->du_ref = strdup(du_ref ? du_ref : ""); - res->complete_time = strdup(mix_get_time()); + res->complete_time = strdup(get_time(time(NULL))); res->fault = error; FREE(du_ref); break; @@ -441,7 +440,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v) res->du_ref = strdup(du_ref ? du_ref : ""); res->uuid = strdup(p->uuid); res->version = strdup(package_version); - res->complete_time = strdup(mix_get_time()); + res->complete_time = strdup(get_time(time(NULL))); res->fault = error; FREE(du_ref); FREE(package_name); diff --git a/cwmp_time.c b/cwmp_time.c deleted file mode 100644 index 33e30a1..0000000 --- a/cwmp_time.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Copyright (C) 2011 Luka Perkov - */ - -#include - -char local_time[32] = { 0 }; - -char *mix_get_time_of(time_t t_time) -{ - struct tm *t_tm; - - t_tm = localtime(&t_time); - if (t_tm == NULL) - return NULL; - - if (strftime(local_time, sizeof(local_time), "%FT%T%z", t_tm) == 0) - return NULL; - - local_time[25] = local_time[24]; - local_time[24] = local_time[23]; - local_time[22] = ':'; - local_time[26] = '\0'; - - return local_time; -} - -char *mix_get_time(void) -{ - time_t t_time; - t_time = time(NULL); - mix_get_time_of(t_time); - return local_time; -} diff --git a/download.c b/download.c index d6fccb9..c670ed9 100644 --- a/download.c +++ b/download.c @@ -16,7 +16,6 @@ #include "ubus.h" #include "cwmp_uci.h" #include "backupSession.h" -#include "cwmp_time.h" #include "log.h" #include "event.h" @@ -175,7 +174,7 @@ int cwmp_launch_download(struct download *pdownload, char *download_file_name, e char *download_startTime; struct transfer_complete *p; - download_startTime = mix_get_time(); + download_startTime = get_time(time(NULL)); ltype == TYPE_DOWNLOAD ? bkp_session_delete_download(pdownload) : bkp_session_delete_schedule_download(pdownload); bkp_session_save(); @@ -246,7 +245,7 @@ end_download: p->command_key = pdownload->command_key ? strdup(pdownload->command_key) : strdup(""); p->start_time = strdup(download_startTime); - p->complete_time = strdup(mix_get_time()); + p->complete_time = strdup(get_time(time(NULL))); p->type = ltype; if (error != FAULT_CPE_NO_FAULT) { p->fault_code = error; @@ -348,7 +347,7 @@ struct transfer_complete *set_download_error_transfer_complete(struct cwmp *cwmp ptransfer_complete = calloc(1, sizeof(struct transfer_complete)); if (ptransfer_complete != NULL) { ptransfer_complete->command_key = strdup(pdownload->command_key); - ptransfer_complete->start_time = strdup(mix_get_time()); + ptransfer_complete->start_time = strdup(get_time(time(NULL))); ptransfer_complete->complete_time = strdup(ptransfer_complete->start_time); ptransfer_complete->fault_code = ltype == TYPE_DOWNLOAD ? FAULT_CPE_DOWNLOAD_FAILURE : FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW; ptransfer_complete->type = ltype; @@ -701,7 +700,7 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v) } ptransfer_complete->command_key = strdup(apply_download->command_key); ptransfer_complete->start_time = strdup(apply_download->start_time); - ptransfer_complete->complete_time = strdup(mix_get_time()); + ptransfer_complete->complete_time = strdup(get_time(time(NULL))); ptransfer_complete->fault_code = error; ptransfer_complete->type = TYPE_SCHEDULE_DOWNLOAD; bkp_session_insert_transfer_complete(ptransfer_complete); diff --git a/inc/common.h b/inc/common.h index db62468..5529c6f 100644 --- a/inc/common.h +++ b/inc/common.h @@ -494,6 +494,7 @@ void clean_custom_inform_parameters(); char *string_to_hex(const unsigned char *str, size_t size); int copy_file(char *source_file, char *target_file); int get_connection_interface(); +char *get_time(time_t t_time); bool is_obj_excluded(char *object_name); #ifndef FREE diff --git a/inc/cwmp_time.h b/inc/cwmp_time.h deleted file mode 100644 index afc43ac..0000000 --- a/inc/cwmp_time.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Copyright (C) 2013-2020 iopsys Software Solutions AB - * Author Omar Kallel - * - */ - -#ifndef CWMP_TIME_H_ -#define CWMP_TIME_H_ - -char *mix_get_time(void); -char *mix_get_time_of(time_t t_time); - -#endif /* SRC_INC_CWMP_TIME_H_ */ diff --git a/rpc_soap.c b/rpc_soap.c index 9a4f4d2..7b9a710 100755 --- a/rpc_soap.c +++ b/rpc_soap.c @@ -18,7 +18,6 @@ #include "cwmp_du_state.h" #include "log.h" #include "event.h" -#include "cwmp_time.h" #include "datamodel_interface.h" #include "messages.h" #include "event.h" @@ -307,7 +306,7 @@ int cwmp_rpc_acs_prepare_message_inform(struct cwmp *cwmp, struct session *sessi if (!b) goto error; - b = mxmlNewOpaque(b, mix_get_time()); + b = mxmlNewOpaque(b, get_time(time(NULL))); if (!b) goto error; @@ -603,7 +602,7 @@ int cwmp_rpc_acs_prepare_transfer_complete(struct cwmp *cwmp, struct session *se if (!n) goto error; - n = mxmlNewOpaque(n, mix_get_time()); + n = mxmlNewOpaque(n, get_time(time(NULL))); if (!n) goto error; diff --git a/test/cmocka/icwmp_backup_session_unit_test.c b/test/cmocka/icwmp_backup_session_unit_test.c index 241e9c6..6d57ac0 100644 --- a/test/cmocka/icwmp_backup_session_unit_test.c +++ b/test/cmocka/icwmp_backup_session_unit_test.c @@ -19,7 +19,6 @@ #include "backupSession.h" #include "xml.h" #include "config.h" -#include "cwmp_time.h" #include "event.h" static struct cwmp cwmp_main_test = { 0 }; @@ -220,8 +219,8 @@ static void cwmp_backup_session_unit_test(void **state) struct transfer_complete *p; p = icwmp_calloc(1, sizeof(struct transfer_complete)); p->command_key = icwmp_strdup("transfer_complete_key"); - p->start_time = icwmp_strdup(mix_get_time()); - p->complete_time = icwmp_strdup(mix_get_time()); + p->start_time = icwmp_strdup(get_time(time(NULL))); + p->complete_time = icwmp_strdup(get_time(time(NULL))); p->old_software_version = icwmp_strdup("iopsys_img_old"); p->type = TYPE_DOWNLOAD; p->fault_code = FAULT_CPE_NO_FAULT; diff --git a/test/cmocka/icwmp_cli_unit_test.c b/test/cmocka/icwmp_cli_unit_test.c index e15e7d1..3e8713b 100644 --- a/test/cmocka/icwmp_cli_unit_test.c +++ b/test/cmocka/icwmp_cli_unit_test.c @@ -21,7 +21,6 @@ #include "backupSession.h" #include "xml.h" #include "config.h" -#include "cwmp_time.h" #include "event.h" #include "cwmp_uci.h" #include "cwmp_cli.h" diff --git a/ubus.c b/ubus.c index c549088..c414178 100755 --- a/ubus.c +++ b/ubus.c @@ -26,7 +26,6 @@ #include "cwmp_du_state.h" #include "netlink.h" #include "event.h" -#include "cwmp_time.h" static struct ubus_context *ctx = NULL; @@ -163,20 +162,20 @@ static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj c = blobmsg_open_table(&blob_status, "cwmp"); blobmsg_add_string(&blob_status, "status", "up"); - blobmsg_add_string(&blob_status, "start_time", mix_get_time_of(cwmp_main.start_time)); + blobmsg_add_string(&blob_status, "start_time", get_time(cwmp_main.start_time)); blobmsg_add_string(&blob_status, "acs_url", cwmp_main.conf.acsurl); blobmsg_close_table(&blob_status, c); c = blobmsg_open_table(&blob_status, "last_session"); blobmsg_add_string(&blob_status, "status", cwmp_main.session_status.last_start_time ? arr_session_status[cwmp_main.session_status.last_status] : "N/A"); - blobmsg_add_string(&blob_status, "start_time", cwmp_main.session_status.last_start_time ? mix_get_time_of(cwmp_main.session_status.last_start_time) : "N/A"); - blobmsg_add_string(&blob_status, "end_time", cwmp_main.session_status.last_end_time ? mix_get_time_of(cwmp_main.session_status.last_end_time) : "N/A"); + blobmsg_add_string(&blob_status, "start_time", cwmp_main.session_status.last_start_time ? get_time(cwmp_main.session_status.last_start_time) : "N/A"); + blobmsg_add_string(&blob_status, "end_time", cwmp_main.session_status.last_end_time ? get_time(cwmp_main.session_status.last_end_time) : "N/A"); blobmsg_close_table(&blob_status, c); c = blobmsg_open_table(&blob_status, "next_session"); blobmsg_add_string(&blob_status, "status", arr_session_status[SESSION_WAITING]); ntime = get_session_status_next_time(); - blobmsg_add_string(&blob_status, "start_time", ntime ? mix_get_time_of(ntime) : "N/A"); + blobmsg_add_string(&blob_status, "start_time", ntime ? get_time(ntime) : "N/A"); blobmsg_add_string(&blob_status, "end_time", "N/A"); blobmsg_close_table(&blob_status, c); diff --git a/upload.c b/upload.c index 84d2f47..8c7153d 100644 --- a/upload.c +++ b/upload.c @@ -14,7 +14,6 @@ #include "upload.h" #include "download.h" -#include "cwmp_time.h" #include "datamodel_interface.h" #include "log.h" #include "backupSession.h" @@ -115,7 +114,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans char *upload_startTime; struct transfer_complete *p; char *name = NULL; - upload_startTime = mix_get_time(); + upload_startTime = get_time(time(NULL)); char file_path[128] = {'\0'}; bkp_session_delete_upload(pupload); bkp_session_save(); @@ -172,7 +171,7 @@ end_upload: p->command_key = pupload->command_key ? strdup(pupload->command_key) : strdup(""); p->start_time = strdup(upload_startTime); - p->complete_time = strdup(mix_get_time()); + p->complete_time = strdup(get_time(time(NULL))); p->type = TYPE_UPLOAD; if (error != FAULT_CPE_NO_FAULT) { p->fault_code = error; @@ -213,7 +212,7 @@ void *thread_cwmp_rpc_cpe_upload(void *v) error = FAULT_CPE_DOWNLOAD_FAILURE; ptransfer_complete->command_key = strdup(pupload->command_key); - ptransfer_complete->start_time = strdup(mix_get_time()); + ptransfer_complete->start_time = strdup(get_time(time(NULL))); ptransfer_complete->complete_time = strdup(ptransfer_complete->start_time); ptransfer_complete->fault_code = error; ptransfer_complete->type = TYPE_UPLOAD;