Optionally store CDR's in GM time (bug #3500, with mods)
authorMark Spencer <markster@digium.com>
Fri, 4 Feb 2005 05:52:45 +0000 (05:52 +0000)
committerMark Spencer <markster@digium.com>
Fri, 4 Feb 2005 05:52:45 +0000 (05:52 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4962 65c4cc65-6c06-0410-ace0-fbb531ad65f3

cdr/cdr_odbc.c
configs/cdr_odbc.conf.sample

index f9f0ce7..7aefd93 100755 (executable)
@@ -39,6 +39,7 @@ static char *config = "cdr_odbc.conf";
 static char *dsn = NULL, *username = NULL, *password = NULL, *table = NULL;
 static int dsn_alloc = 0, username_alloc = 0, password_alloc = 0, table_alloc = 0;
 static int loguniqueid = 0;
 static char *dsn = NULL, *username = NULL, *password = NULL, *table = NULL;
 static int dsn_alloc = 0, username_alloc = 0, password_alloc = 0, table_alloc = 0;
 static int loguniqueid = 0;
+static int usegmtime = 0;
 static int dispositionstring = 0;
 static int connected = 0;
 
 static int dispositionstring = 0;
 static int connected = 0;
 
@@ -53,7 +54,7 @@ static SQLHSTMT       ODBC_stmt;                      /* global ODBC Statement Handle */
 
 static int odbc_log(struct ast_cdr *cdr)
 {
 
 static int odbc_log(struct ast_cdr *cdr)
 {
-       long int ODBC_err;
+       SQLINTEGER ODBC_err;
        short int ODBC_mlen;
        int ODBC_res;
        char ODBC_msg[200], ODBC_stat[10];
        short int ODBC_mlen;
        int ODBC_res;
        char ODBC_msg[200], ODBC_stat[10];
@@ -61,7 +62,10 @@ static int odbc_log(struct ast_cdr *cdr)
        int res = 0;
        struct tm tm;
 
        int res = 0;
        struct tm tm;
 
-       localtime_r(&cdr->start.tv_sec,&tm);
+       if (usegmtime) 
+               gmtime_r(&cdr->start.tv_sec,&tm);
+       else
+               localtime_r(&cdr->start.tv_sec,&tm);
 
        ast_mutex_lock(&odbc_lock);
        strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 
        ast_mutex_lock(&odbc_lock);
        strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
@@ -215,6 +219,7 @@ static int odbc_unload_module(void)
                table_alloc = 0;
        }
        loguniqueid = 0;
                table_alloc = 0;
        }
        loguniqueid = 0;
+       usegmtime = 0;
        dispositionstring = 0;
 
        ast_cdr_unregister(name);
        dispositionstring = 0;
 
        ast_cdr_unregister(name);
@@ -305,15 +310,28 @@ static int odbc_load_module(void)
        if (tmp) {
                loguniqueid = ast_true(tmp);
                if (loguniqueid) {
        if (tmp) {
                loguniqueid = ast_true(tmp);
                if (loguniqueid) {
-                       ast_log(LOG_NOTICE,"cdr_odbc: Logging uniqueid\n");
+                       ast_log(LOG_DEBUG,"cdr_odbc: Logging uniqueid\n");
                } else {
                } else {
-                       ast_log(LOG_ERROR,"cdr_odbc: Not logging uniqueid\n");
+                       ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
                }
        } else {
                }
        } else {
-               ast_log(LOG_WARNING,"cdr_odbc: Not logging uniqueid\n");
+               ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
                loguniqueid = 0;
        }
 
                loguniqueid = 0;
        }
 
+       tmp = ast_variable_retrieve(cfg,"global","usegmtime");
+       if (tmp) {
+               usegmtime = ast_true(tmp);
+               if (usegmtime) {
+                       ast_log(LOG_DEBUG,"cdr_odbc: Logging in GMT\n");
+               } else {
+                       ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
+               }
+       } else {
+               ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
+               usegmtime = 0;
+       }
+
        tmp = ast_variable_retrieve(cfg,"global","table");
        if (tmp) {
                table = malloc(strlen(tmp) + 1);
        tmp = ast_variable_retrieve(cfg,"global","table");
        if (tmp) {
                table = malloc(strlen(tmp) + 1);
@@ -357,7 +375,7 @@ out:
 
 static int odbc_do_query(void)
 {
 
 static int odbc_do_query(void)
 {
-       long int ODBC_err;
+       SQLINTEGER ODBC_err;
        int ODBC_res;
        short int ODBC_mlen;
        char ODBC_msg[200], ODBC_stat[10];
        int ODBC_res;
        short int ODBC_mlen;
        char ODBC_msg[200], ODBC_stat[10];
@@ -381,7 +399,7 @@ static int odbc_do_query(void)
 
 static int odbc_init(void)
 {
 
 static int odbc_init(void)
 {
-       long int ODBC_err;
+       SQLINTEGER ODBC_err;
        short int ODBC_mlen;
        int ODBC_res;
        char ODBC_msg[200], ODBC_stat[10];
        short int ODBC_mlen;
        int ODBC_res;
        char ODBC_msg[200], ODBC_stat[10];
index 8e10be6..6245e37 100755 (executable)
@@ -9,3 +9,4 @@
 ;loguniqueid=yes
 ;dispositionstring=yes
 ;table=cdr             ;"cdr" is default table name
 ;loguniqueid=yes
 ;dispositionstring=yes
 ;table=cdr             ;"cdr" is default table name
+;usegmtime=no             ; set to "yes" to log in GMT