Skip to content

Commit

Permalink
acc: use acc.time_mode to save cdrs in gmtime
Browse files Browse the repository at this point in the history
acc.time_mode modparam allows saving acc transactions time field using
the output of gmtime() when it is set to 4.

This commit aims to reuse this modparam for cdr entries, storing start_time
and end_time in gmtime if time_mode is 4.

Fixes kamailio#1358
  • Loading branch information
cruzccl committed Dec 14, 2017
1 parent 28f107d commit 1d95b2e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/modules/acc/acc_cdr.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_STR;
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_STR(db_cdr_vals+i) = (str){cdr_time_format_buf[i], TIME_STR_BUFFER_SIZE-1};
} 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;
Expand Down

0 comments on commit 1d95b2e

Please sign in to comment.