Blocked revisions 94543 via svnmerge
[asterisk/asterisk.git] / cdr / cdr_sqlite.c
index bd232b4..601e5b2 100644 (file)
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <sqlite.h>
 
 #include "asterisk/channel.h"
 #include "asterisk/module.h"
-#include "asterisk/logger.h"
 #include "asterisk/utils.h"
+#include "asterisk/paths.h"
 
 #define LOG_UNIQUEID   0
 #define LOG_USERFIELD  0
@@ -96,24 +91,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;
-       localtime_r(&t, &tm);
-       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;
-       localtime_r(&t, &tm);
-       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;
-       localtime_r(&t, &tm);
-       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,
@@ -161,7 +152,7 @@ static int sqlite_log(struct ast_cdr *cdr)
        
        if (zErr) {
                ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr);
-               free(zErr);
+               ast_free(zErr);
        }
 
        ast_mutex_unlock(&sqlite_lock);
@@ -190,7 +181,7 @@ static int load_module(void)
        db = sqlite_open(fn, AST_FILE_MODE, &zErr);
        if (!db) {
                ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr);
-               free(zErr);
+               ast_free(zErr);
                return -1;
        }
 
@@ -200,7 +191,7 @@ static int load_module(void)
                res = sqlite_exec(db, sql_create_table, NULL, NULL, &zErr);
                if (res) {
                        ast_log(LOG_ERROR, "cdr_sqlite: Unable to create table 'cdr': %s\n", zErr);
-                       free(zErr);
+                       ast_free(zErr);
                        goto err;
                }