Module: sip-router
Branch: master
Commit: df4fbc220efd333fa638831167dd4fe5e69a89a2
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=df4fbc2…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Fri Oct 4 12:02:32 2013 +0200
acc: new parameter acc_time_format
- specify the format to print time as string for acc_time_mode=3 (using
localtime) and acc_time_mode=4 (using gmtime)
- default value is "%Y-%m-%d %H:%M:%S"
---
modules/acc/acc.c | 44 ++++++++++++++++++++++++++++++++++++++++----
modules/acc/acc_mod.c | 2 ++
2 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/modules/acc/acc.c b/modules/acc/acc.c
index 8a6f3cc..efaebc0 100644
--- a/modules/acc/acc.c
+++ b/modules/acc/acc.c
@@ -75,6 +75,7 @@
extern struct acc_extra *log_extra;
extern struct acc_extra *leg_info;
extern struct acc_enviroment acc_env;
+extern char *acc_time_format;
#ifdef RAD_ACC
extern struct acc_extra *rad_extra;
@@ -99,6 +100,9 @@ static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
+#define ACC_TIME_FORMAT_SIZE 128
+static char acc_time_format_buf[ACC_TIME_FORMAT_SIZE];
+
/********************************************
* acc CORE function
********************************************/
@@ -226,6 +230,7 @@ int acc_log_request( struct sip_msg *rq)
int n;
int m;
int i;
+ struct tm *t;
/* get default values */
m = core2strar( rq, val_arr, int_arr, type_arr);
@@ -279,19 +284,34 @@ int acc_log_request( struct sip_msg *rq)
if(acc_time_mode==1) {
LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%u%s",
- acc_env.text.len, acc_env.text.s,(unsigned long) acc_env.ts,
+ acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
acc_time_exten.s, (unsigned int)acc_env.tv.tv_usec,
log_msg);
} else if(acc_time_mode==2) {
LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%.3f%s",
- acc_env.text.len, acc_env.text.s,(unsigned long) acc_env.ts,
+ acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
acc_time_attr.s,
(((double)(acc_env.tv.tv_sec * 1000)
+ (acc_env.tv.tv_usec / 1000)) / 1000),
log_msg);
+ } else if(acc_time_mode==3 || acc_time_mode==4) {
+ if(acc_time_mode==3) {
+ t = localtime(&acc_env.ts);
+ } else {
+ t = gmtime(&acc_env.ts);
+ }
+ if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
+ acc_time_format, t)<0) {
+ acc_time_format_buf[0] = '\0';
+ }
+ LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%s%s",
+ acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
+ acc_time_attr.s,
+ acc_time_format_buf,
+ log_msg);
} else {
LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu%s",
- acc_env.text.len, acc_env.text.s,(unsigned long) acc_env.ts,
+ acc_env.text.len, acc_env.text.s,(unsigned long)acc_env.ts,
log_msg);
}
@@ -337,7 +357,8 @@ static void acc_db_init_keys(void)
db_keys[n++] = &acc_sipreason_col;
db_keys[n++] = &acc_time_col;
time_idx = n-1;
- if(acc_time_mode==1 || acc_time_mode==2) {
+ if(acc_time_mode==1 || acc_time_mode==2
+ || acc_time_mode==3 || acc_time_mode==4) {
db_keys[n++] = &acc_time_attr;
if(acc_time_mode==1) {
db_keys[n++] = &acc_time_exten;
@@ -363,6 +384,8 @@ static void acc_db_init_keys(void)
VAL_TYPE(db_vals+time_idx+2)=DB1_INT;
} else if(acc_time_mode==2) {
VAL_TYPE(db_vals+time_idx+1)=DB1_DOUBLE;
+ } else if(acc_time_mode==3 || acc_time_mode==4) {
+ VAL_TYPE(db_vals+time_idx+1)=DB1_STRING;
}
}
@@ -414,6 +437,7 @@ int acc_db_request( struct sip_msg *rq)
int m;
int n;
int i;
+ struct tm *t;
/* formated database columns */
m = core2strar( rq, val_arr, int_arr, type_arr );
@@ -432,6 +456,18 @@ int acc_db_request( struct sip_msg *rq)
VAL_DOUBLE(db_vals+(m++)) = ((double)(acc_env.tv.tv_sec * 1000)
+ (acc_env.tv.tv_usec / 1000)) / 1000;
i++;
+ } else if(acc_time_mode==3 || acc_time_mode==4) {
+ if(acc_time_mode==3) {
+ t = localtime(&acc_env.ts);
+ } else {
+ t = gmtime(&acc_env.ts);
+ }
+ if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
+ acc_time_format, t)<0) {
+ acc_time_format_buf[0] = '\0';
+ }
+ VAL_STRING(db_vals+(m++)) = acc_time_format_buf;
+ i++;
}
/* extra columns */
diff --git a/modules/acc/acc_mod.c b/modules/acc/acc_mod.c
index a36ecbe..2fb9258 100644
--- a/modules/acc/acc_mod.c
+++ b/modules/acc/acc_mod.c
@@ -109,6 +109,7 @@ unsigned short failed_filter[MAX_FAILED_FILTER_COUNT + 1];
static char* leg_info_str = 0; /*!< multi call-leg support */
struct acc_extra *leg_info = 0;
int acc_prepare_flag = -1; /*!< should the request be prepared for later acc */
+char *acc_time_format = "%Y-%m-%d %H:%M:%S";
/* ----- time mode variables ------- */
/*! \name AccTimeModeVariables Time Mode Variables */
@@ -309,6 +310,7 @@ static param_export_t params[] = {
{"time_attr", PARAM_STR, &acc_time_attr },
{"time_exten", PARAM_STR, &acc_time_exten },
{"cdrs_table", PARAM_STR, &acc_cdrs_table },
+ {"time_format", STR_PARAM, &acc_time_format },
{0,0,0}
};