From 706602fc520d237c45cf0b17c5b55a681c879263 Mon Sep 17 00:00:00 2001 From: seanbright Date: Wed, 3 Sep 2008 13:48:12 +0000 Subject: Move some duplicated code into a separate function. Also try to do some wacky stuff in the commit message, like: a newline \n a bell \a a tab \t a format specification %p That is all. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@140821 f38db490-d61c-443f-a65b-d21fe96a405b --- cdr/cdr_sqlite.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cdr/cdr_sqlite.c b/cdr/cdr_sqlite.c index 601e5b245..4a3c9406d 100644 --- a/cdr/cdr_sqlite.c +++ b/cdr/cdr_sqlite.c @@ -87,24 +87,26 @@ static char sql_create_table[] = "CREATE TABLE cdr (" #endif ");"; +static void format_date(char *buffer, size_t length, struct timeval *when) +{ + struct ast_tm tm; + + ast_localtime(when, &tm, NULL); + ast_strftime(buffer, length, DATE_FORMAT, &tm); +} + static int sqlite_log(struct ast_cdr *cdr) { int res = 0; char *zErr = 0; - struct ast_tm tm; char startstr[80], answerstr[80], endstr[80]; int count; ast_mutex_lock(&sqlite_lock); - ast_localtime(&cdr->start, &tm, NULL); - ast_strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm); - - ast_localtime(&cdr->answer, &tm, NULL); - ast_strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm); - - ast_localtime(&cdr->end, &tm, NULL); - ast_strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm); + format_date(startstr, sizeof(startstr), &cdr->start); + format_date(answerstr, sizeof(answerstr), &cdr->answer); + format_date(endstr, sizeof(endstr), &cdr->end); for(count=0; count<5; count++) { res = sqlite_exec_printf(db, -- cgit v1.2.3