From 49dd734c241be1531bf11bb5d1b3f4a658b35031 Mon Sep 17 00:00:00 2001 From: Carlos Cruz Date: Thu, 14 Dec 2017 17:52:26 +0100 Subject: [PATCH 1/2] doc: time_mode param used for cdrs too --- src/modules/acc/doc/acc_admin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/acc/doc/acc_admin.xml b/src/modules/acc/doc/acc_admin.xml index 1e174705ec5..e9efa8f5eaf 100644 --- a/src/modules/acc/doc/acc_admin.xml +++ b/src/modules/acc/doc/acc_admin.xml @@ -1306,12 +1306,12 @@ modparam("acc", "cdrs_table", "acc_cdrs") 3 - save formatted time according - to time_format parameter, using the output of localtime(). + to time_format parameter, using the output of localtime(). Used for cdr entries too. 4 - save formatted time according - to time_format parameter, using the output of gmtime(). + to time_format parameter, using the output of gmtime(). Used for cdr entries too. From 63f747a9adcba51562b7ec6848d1f6454374bfa4 Mon Sep 17 00:00:00 2001 From: Carlos Cruz Date: Thu, 14 Dec 2017 16:33:04 +0100 Subject: [PATCH 2/2] acc: use acc.time_mode to save cdrs in gmtime - reuse acc.time_mode modparam for cdr entries, storing start_time and end_time in gmtime if time_mode is 4. GH #1358 --- src/modules/acc/acc_cdr.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/acc/acc_cdr.c b/src/modules/acc/acc_cdr.c index 21c917ccdcb..f29f139e2d2 100644 --- a/src/modules/acc/acc_cdr.c +++ b/src/modules/acc/acc_cdr.c @@ -64,6 +64,7 @@ #define TIME_STR_BUFFER_SIZE 20 #define TIME_BUFFER_LENGTH 256 +#define TIME_STRING_FORMAT "%Y-%m-%d %H:%M:%S" struct dlg_binds dlgb; struct acc_extra* cdr_extra = NULL; @@ -141,6 +142,8 @@ static int db_write_cdr( struct dlg_cell* dialog, long long_val; double double_val; char * end; + struct tm *t; + char cdr_time_format_buf[MAX_CDR_CORE][TIME_STR_BUFFER_SIZE]; if(acc_cdrs_table.len<=0) return 0; @@ -182,13 +185,24 @@ static int db_write_cdr( struct dlg_cell* dialog, VAL_STR(db_cdr_vals+i) = cdr_value_array[i]; break; case TYPE_DATE: - VAL_TYPE(db_cdr_vals+i)=DB1_DATETIME; VAL_NULL(db_cdr_vals+i)=0; if(string2time(&cdr_value_array[i], &timeval_val) < 0) { LM_ERR("failed to convert string to timeval.\n"); goto error; } - VAL_TIME(db_cdr_vals+i) = timeval_val.tv_sec; + if (acc_time_mode==4) { + VAL_TYPE(db_cdr_vals+i)=DB1_STRING; + t = gmtime(&timeval_val.tv_sec); + /* Convert time_t structure to format accepted by the database */ + if (strftime(cdr_time_format_buf[i], TIME_STR_BUFFER_SIZE, TIME_STRING_FORMAT, t) <= 0) { + cdr_time_format_buf[i][0] = '\0'; + } + + VAL_STRING(db_cdr_vals+i) = cdr_time_format_buf[i]; + } else { + VAL_TYPE(db_cdr_vals+i)=DB1_DATETIME; + VAL_TIME(db_cdr_vals+i) = timeval_val.tv_sec; + } break; case TYPE_DOUBLE: VAL_TYPE(db_cdr_vals+i)=DB1_DOUBLE;