mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
Use common function to get time
This commit is contained in:
parent
673600fd3d
commit
a695e0d2cd
12 changed files with 43 additions and 87 deletions
|
|
@ -6,7 +6,6 @@ bin_PROGRAMS = icwmpd
|
|||
|
||||
icwmpd_SOURCES = \
|
||||
./common.c \
|
||||
./cwmp_time.c \
|
||||
./log.c \
|
||||
./cwmp_uci.c \
|
||||
./config.c \
|
||||
|
|
|
|||
20
common.c
20
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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
39
cwmp_time.c
39
cwmp_time.c
|
|
@ -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 <freecwmp@lukaperkov.net>
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <omar.kallel@pivasoftware.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#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_ */
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
9
ubus.c
9
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);
|
||||
|
||||
|
|
|
|||
7
upload.c
7
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue