Module: kamailio
Branch: master
Commit: 55e4ead882349d503e64de64dcb9321cc6ab8a20
URL:
https://github.com/kamailio/kamailio/commit/55e4ead882349d503e64de64dcb9321…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2017-12-16T09:46:21+01:00
Merge pull request #1368 from cruzccl/acc-cdrs-in-utc
acc: use acc.time_mode to save cdrs in gmtime
---
Modified: src/modules/acc/acc_cdr.c
Modified: src/modules/acc/doc/acc_admin.xml
---
Diff:
https://github.com/kamailio/kamailio/commit/55e4ead882349d503e64de64dcb9321…
Patch:
https://github.com/kamailio/kamailio/commit/55e4ead882349d503e64de64dcb9321…
---
diff --git a/src/modules/acc/acc_cdr.c b/src/modules/acc/acc_cdr.c
index 21c917ccdc..f29f139e2d 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;
diff --git a/src/modules/acc/doc/acc_admin.xml b/src/modules/acc/doc/acc_admin.xml
index 1e174705ec..e9efa8f5ea 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")
</listitem>
<listitem>
<para><emphasis>3</emphasis> - 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.
</para>
</listitem>
<listitem>
<para><emphasis>4</emphasis> - 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.
</para>
</listitem>
</itemizedlist>