[svn-commits] tilghman: trunk r559 - in /trunk: cdr/ configs/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 18 14:47:56 CDT 2008


Author: tilghman
Date: Tue Mar 18 14:47:56 2008
New Revision: 559

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=559
Log:
Create a compatibility mode, for people who want the old (incorrect) calldate behavior

Modified:
    trunk/cdr/cdr_addon_mysql.c
    trunk/configs/cdr_mysql.conf.sample

Modified: trunk/cdr/cdr_addon_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/cdr/cdr_addon_mysql.c?view=diff&rev=559&r1=558&r2=559
==============================================================================
--- trunk/cdr/cdr_addon_mysql.c (original)
+++ trunk/cdr/cdr_addon_mysql.c Tue Mar 18 14:47:56 2008
@@ -69,6 +69,7 @@
 static int records = 0;
 static int totalrecords = 0;
 static int timeout = 0;
+static int calldate_compat = 0;
 
 AST_MUTEX_DEFINE_STATIC(mysql_lock);
 
@@ -112,7 +113,7 @@
 		if (dbport)
 			snprintf(status, 255, "Connected to %s@%s, port %d", dbname->str, hostname->str, dbport);
 		else if (dbsock)
-			snprintf(status, 255, "Connected to %s on socket file %s", dbname->str, !ast_strlen_zero(dbsock->str) ? dbsock->str : "default");
+			snprintf(status, 255, "Connected to %s on socket file %s", dbname->str, S_OR(dbsock->str, "default"));
 		else
 			snprintf(status, 255, "Connected to %s@%s", dbname->str, hostname->str);
 
@@ -248,7 +249,29 @@
 					break;
 			}
 
-			cdrname = entry ? entry->cdrname : row[0];
+			if (entry) {
+				cdrname = entry->cdrname;
+			} else if (!strcmp(row[0], "calldate")) {
+				/*!\note
+				 * For some dumb reason, "calldate" used to be formulated using
+				 * the datetime the record was posted, rather than the start
+				 * time of the call.  If someone really wants the old compatible
+				 * behavior, it's provided here.
+				 */
+				if (calldate_compat) {
+					struct timeval tv = ast_tvnow();
+					struct ast_tm tm;
+					char timestr[128];
+					ast_localtime(&tv, &tm, NULL);
+					ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %T", &tm);
+					ast_cdr_setvar(cdr, "calldate", timestr, 0);
+					cdrname = "calldate";
+				} else {
+					cdrname = "start";
+				}
+			} else {
+				cdrname = row[0];
+			}
 
 			/* Construct SQL */
 			if (column_count++) {
@@ -411,6 +434,7 @@
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct column *entry;
 	char *temp;
+	struct ast_str *compat;
 #if MYSQL_VERSION_ID >= 50013
 	my_bool my_bool_true = 1;
 #endif
@@ -446,6 +470,12 @@
 
 	res |= my_load_config_number(cfg, "global", "port", &dbport, 0);
 	res |= my_load_config_number(cfg, "global", "timeout", &timeout, 0);
+	res |= my_load_config_string(cfg, "global", "compat", &compat, "no");
+	if (ast_true(compat->str)) {
+		calldate_compat = 1;
+	} else {
+		calldate_compat = 0;
+	}
 
 	if (res < 0)
 		return AST_MODULE_LOAD_FAILURE;
@@ -477,6 +507,7 @@
 	ast_debug(1, "Got user of %s\n", dbuser->str);
 	ast_debug(1, "Got dbname of %s\n", dbname->str);
 	ast_debug(1, "Got password of %s\n", password->str);
+	ast_debug(1, "%sunning in calldate compatibility mode\n", calldate_compat ? "R" : "Not r");
 
 	mysql_init(&mysql);
 

Modified: trunk/configs/cdr_mysql.conf.sample
URL: http://svn.digium.com/view/asterisk-addons/trunk/configs/cdr_mysql.conf.sample?view=diff&rev=559&r1=558&r2=559
==============================================================================
--- trunk/configs/cdr_mysql.conf.sample (original)
+++ trunk/configs/cdr_mysql.conf.sample Tue Mar 18 14:47:56 2008
@@ -18,6 +18,12 @@
 ;user=asteriskcdruser
 ;port=3306
 ;sock=/tmp/mysql.sock
+;
+; Older versions of cdr_mysql set the calldate field to whenever the
+; record was posted, rather than the start date of the call.  This flag
+; reverts to the old (incorrect) behavior.  Note that you'll also need
+; to comment out the "start=calldate" alias, below, to use this.
+;compat=no
 ;
 ; ssl connections (optional)
 ;ssl_ca=<path to CA cert>




More information about the svn-commits mailing list