mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75706 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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));
|
||||
|
@@ -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 "
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user