[asterisk-commits] tilghman: trunk r142536 - in /trunk: cdr/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 11 16:45:08 CDT 2008


Author: tilghman
Date: Thu Sep 11 16:45:07 2008
New Revision: 142536

URL: http://svn.digium.com/view/asterisk?view=rev&rev=142536
Log:
Add usegmtime, as per the recent -users list discussion, and also add my
explanation to the file, since that additional text helps people understand
the concept.

Modified:
    trunk/cdr/cdr_adaptive_odbc.c
    trunk/configs/cdr_adaptive_odbc.conf.sample

Modified: trunk/cdr/cdr_adaptive_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_adaptive_odbc.c?view=diff&rev=142536&r1=142535&r2=142536
==============================================================================
--- trunk/cdr/cdr_adaptive_odbc.c (original)
+++ trunk/cdr/cdr_adaptive_odbc.c Thu Sep 11 16:45:07 2008
@@ -69,6 +69,7 @@
 struct tables {
 	char *connection;
 	char *table;
+	unsigned int usegmtime:1;
 	AST_LIST_HEAD_NOLOCK(odbc_columns, columns) columns;
 	AST_RWLIST_ENTRY(tables) list;
 };
@@ -86,7 +87,7 @@
 	char columnname[80];
 	char connection[40];
 	char table[40];
-	int lenconnection, lentable;
+	int lenconnection, lentable, usegmtime;
 	SQLLEN sqlptr;
 	int res = 0;
 	SQLHSTMT stmt = NULL;
@@ -109,6 +110,10 @@
 		}
 		ast_copy_string(connection, tmp, sizeof(connection));
 		lenconnection = strlen(connection);
+
+		if (!ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "usegmtime"))) {
+			usegmtime = ast_true(tmp);
+		}
 
 		/* When loading, we want to be sure we can connect. */
 		obj = ast_odbc_request_obj(connection, 1);
@@ -146,6 +151,7 @@
 			break;
 		}
 
+		tableptr->usegmtime = usegmtime;
 		tableptr->connection = (char *)tableptr + sizeof(*tableptr);
 		tableptr->table = (char *)tableptr + sizeof(*tableptr) + lenconnection + 1;
 		ast_copy_string(tableptr->connection, connection, lenconnection + 1);
@@ -354,11 +360,24 @@
 		}
 
 		AST_LIST_TRAVERSE(&(tableptr->columns), entry, list) {
+			int datefield = 0;
+			if (strcasecmp(entry->cdrname, "start") == 0) {
+				datefield = 1;
+			} else if (strcasecmp(entry->cdrname, "answer") == 0) {
+				datefield = 2;
+			} else if (strcasecmp(entry->cdrname, "end") == 0) {
+				datefield = 3;
+			}
+
 			/* Check if we have a similarly named variable */
-			ast_cdr_getvar(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0,
-				(strcasecmp(entry->cdrname, "start") == 0 ||
-				 strcasecmp(entry->cdrname, "answer") == 0 ||
-				 strcasecmp(entry->cdrname, "end") == 0) ? 0 : 1);
+			if (datefield && tableptr->usegmtime) {
+				struct timeval tv = (datefield == 1) ? cdr->start : (datefield == 2) ? cdr->answer : cdr->end;
+				struct ast_tm tm = { 0, };
+				ast_localtime(&tv, &tm, "UTC");
+				ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm);
+			} else {
+				ast_cdr_getvar(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0, datefield ? 0 : 1);
+			}
 
 			if (colptr) {
 				/* Check first if the column filters this entry.  Note that this

Modified: trunk/configs/cdr_adaptive_odbc.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/cdr_adaptive_odbc.conf.sample?view=diff&rev=142536&r1=142535&r2=142536
==============================================================================
--- trunk/configs/cdr_adaptive_odbc.conf.sample (original)
+++ trunk/configs/cdr_adaptive_odbc.conf.sample Thu Sep 11 16:45:07 2008
@@ -28,6 +28,7 @@
 ;[third]
 ;connection=sqlserver
 ;table=AsteriskCDR
+;usegmtime=yes ; defaults to no
 ;alias src => source
 ;alias channel => source_channel
 ;alias dst => dest
@@ -38,3 +39,19 @@
 ;filter src => 123
 
 
+; On Wednesday 10 September 2008 21:11:16 Tilghman Lesher wrote:
+;
+; I thought that the sample cdr_adaptive_odbc.conf was rather clear, but
+; apparently not.  The point of this module is to allow you log whatever you
+; like in terms of the CDR variables.  Do you want to log uniqueid?  Then simply
+; ensure that your table has that column.  If you don't want the column, ensure
+; that it does not exist in the table structure.  If you'd like to call uniqueid
+; something else in your table, simply provide an alias in the configuration
+; file that maps the standard CDR field name (uniqueid) to whatever column
+; name you like.  Perhaps you'd like some extra CDR values logged that aren't
+; in the standard repertoire of CDR variables (some that come to mind are
+; certain values used for LCR:  route, per_minute_cost, and per_minute_price).
+; Simply set those CDR variables in your dialplan, i.e. Set(CDR(route)=27),
+; ensure that a corresponding column exists in your table, and cdr_adaptive_odbc
+; will do the rest.
+




More information about the asterisk-commits mailing list