summaryrefslogtreecommitdiff
path: root/cdr/cdr_sqlite.c
diff options
context:
space:
mode:
authorSean Bright <sean@malleable.com>2008-09-03 13:48:12 +0000
committerSean Bright <sean@malleable.com>2008-09-03 13:48:12 +0000
commita8a0ecb509ce6537554e0546c3f36830a15ab90f (patch)
tree6bd33073c10b4c9d3ed04e796027034ebdd84e0a /cdr/cdr_sqlite.c
parent4e105063a8f636c9795e106856a2570b106b3b87 (diff)
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: https://origsvn.digium.com/svn/asterisk/trunk@140821 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'cdr/cdr_sqlite.c')
-rw-r--r--cdr/cdr_sqlite.c20
1 files 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,