aboutsummaryrefslogtreecommitdiffstats
path: root/cdr
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-18 19:47:20 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-18 19:47:20 +0000
commit74c2948c2299773fd3816af43e06e3bdf714ba3a (patch)
tree540f82bac3e6105b6fc34cd4b4613c1756a7512b /cdr
parentfd471b4a0cbb2abd7b4c8f30fee850cedefedaa1 (diff)
Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@75706 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rw-r--r--cdr/cdr_csv.c12
-rw-r--r--cdr/cdr_manager.c18
-rw-r--r--cdr/cdr_odbc.c9
-rw-r--r--cdr/cdr_pgsql.c6
-rw-r--r--cdr/cdr_radius.c26
-rw-r--r--cdr/cdr_sqlite.c18
-rw-r--r--cdr/cdr_tds.c8
7 files changed, 36 insertions, 61 deletions
diff --git a/cdr/cdr_csv.c b/cdr/cdr_csv.c
index f40f555a8..bfc509803 100644
--- a/cdr/cdr_csv.c
+++ b/cdr/cdr_csv.c
@@ -188,21 +188,15 @@ static int append_int(char *buf, int s, size_t bufsize)
static int append_date(char *buf, struct timeval tv, size_t bufsize)
{
char tmp[80] = "";
- struct tm tm;
- time_t t;
- t = tv.tv_sec;
+ struct ast_tm tm;
if (strlen(buf) > bufsize - 3)
return -1;
if (ast_tvzero(tv)) {
strncat(buf, ",", bufsize - strlen(buf) - 1);
return 0;
}
- if (usegmtime) {
- gmtime_r(&t,&tm);
- } else {
- ast_localtime(&t, &tm, NULL);
- }
- strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
+ ast_localtime(&tv, &tm, usegmtime ? "GMT" : NULL);
+ ast_strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
return append_string(buf, tmp, bufsize);
}
diff --git a/cdr/cdr_manager.c b/cdr/cdr_manager.c
index a245d92bf..5dc4da6fe 100644
--- a/cdr/cdr_manager.c
+++ b/cdr/cdr_manager.c
@@ -103,8 +103,7 @@ static int load_config(void)
static int manager_log(struct ast_cdr *cdr)
{
- time_t t;
- struct tm timeresult;
+ struct ast_tm timeresult;
char strStartTime[80] = "";
char strAnswerTime[80] = "";
char strEndTime[80] = "";
@@ -114,19 +113,16 @@ static int manager_log(struct ast_cdr *cdr)
if (!enablecdr)
return 0;
- t = cdr->start.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->start, &timeresult, NULL);
+ ast_strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
if (cdr->answer.tv_sec) {
- t = cdr->answer.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->answer, &timeresult, NULL);
+ ast_strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
}
- t = cdr->end.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->end, &timeresult, NULL);
+ ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
/* Custom fields handling */
memset(buf, 0 , sizeof(buf));
diff --git a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c
index d1aa1f2d1..680002784 100644
--- a/cdr/cdr_odbc.c
+++ b/cdr/cdr_odbc.c
@@ -95,15 +95,12 @@ static int odbc_log(struct ast_cdr *cdr)
int ODBC_res;
char sqlcmd[2048] = "", timestr[128];
int res = 0;
- struct tm tm;
+ struct ast_tm tm;
- if (usegmtime)
- gmtime_r(&cdr->start.tv_sec,&tm);
- else
- ast_localtime(&cdr->start.tv_sec, &tm, NULL);
+ ast_localtime(&cdr->start, &tm, usegmtime ? "GMT" : NULL);
ast_mutex_lock(&odbc_lock);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
memset(sqlcmd,0,2048);
if (loguniqueid) {
snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c
index 2379d7728..12d9778c2 100644
--- a/cdr/cdr_pgsql.c
+++ b/cdr/cdr_pgsql.c
@@ -71,15 +71,15 @@ static PGconn *conn = NULL;
static int pgsql_log(struct ast_cdr *cdr)
{
- struct tm tm;
+ struct ast_tm tm;
char sqlcmd[2048] = "", timestr[128];
char *pgerror;
PGresult *result;
ast_mutex_lock(&pgsql_lock);
- ast_localtime(&cdr->start.tv_sec, &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->start, &tm, NULL);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
diff --git a/cdr/cdr_radius.c b/cdr/cdr_radius.c
index c41d680dd..b344c0b26 100644
--- a/cdr/cdr_radius.c
+++ b/cdr/cdr_radius.c
@@ -98,7 +98,7 @@ static rc_handle *rh = NULL;
static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
{
int recordtype = PW_STATUS_STOP;
- struct tm tm;
+ struct ast_tm tm;
char timestr[128];
char *tmp;
@@ -143,29 +143,23 @@ static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
/* Start Time */
- if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
- gmtime_r(&(cdr->start.tv_sec), &tm);
- else
- ast_localtime(&(cdr->start.tv_sec), &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
+ ast_localtime(&cdr->start, &tm,
+ ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
if (!rc_avpair_add(rh, send, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE))
return -1;
/* Answer Time */
- if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
- gmtime_r(&(cdr->answer.tv_sec), &tm);
- else
- ast_localtime(&(cdr->answer.tv_sec), &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
+ ast_localtime(&cdr->answer, &tm,
+ ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
if (!rc_avpair_add(rh, send, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE))
return -1;
/* End Time */
- if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
- gmtime_r(&(cdr->end.tv_sec), &tm);
- else
- ast_localtime(&(cdr->end.tv_sec), &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
+ ast_localtime(&cdr->end, &tm,
+ ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
if (!rc_avpair_add(rh, send, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE))
return -1;
diff --git a/cdr/cdr_sqlite.c b/cdr/cdr_sqlite.c
index 52010ad93..2c526a60c 100644
--- a/cdr/cdr_sqlite.c
+++ b/cdr/cdr_sqlite.c
@@ -96,24 +96,20 @@ static int sqlite_log(struct ast_cdr *cdr)
{
int res = 0;
char *zErr = 0;
- struct tm tm;
- time_t t;
+ struct ast_tm tm;
char startstr[80], answerstr[80], endstr[80];
int count;
ast_mutex_lock(&sqlite_lock);
- t = cdr->start.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->start, &tm, NULL);
+ ast_strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
- t = cdr->answer.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->answer, &tm, NULL);
+ ast_strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm);
- t = cdr->end.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->end, &tm, NULL);
+ ast_strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
for(count=0; count<5; count++) {
res = sqlite_exec_printf(db,
diff --git a/cdr/cdr_tds.c b/cdr/cdr_tds.c
index 451bf1440..2707a4b89 100644
--- a/cdr/cdr_tds.c
+++ b/cdr/cdr_tds.c
@@ -278,16 +278,14 @@ static char *anti_injection(const char *str, int len)
static void get_date(char *dateField, struct timeval tv)
{
- struct tm tm;
- time_t t;
+ struct ast_tm tm;
char buf[80];
/* To make sure we have date variable if not insert null to SQL */
if (!ast_tvzero(tv))
{
- t = tv.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(buf, 80, DATE_FORMAT, &tm);
+ ast_localtime(&tv, &tm, NULL);
+ ast_strftime(buf, 80, DATE_FORMAT, &tm);
sprintf(dateField, "'%s'", buf);
}
else