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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 31 09:29:13 UTC 2010


Author: tilghman
Date: Fri Dec 31 03:29:10 2010
New Revision: 300045

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300045
Log:
Support negative filters.

(closes issue #17979)
 Reported by: tilghman
 Patches: 
       20100911__for_blitzrage.diff.txt uploaded by tilghman (license 14)
 Tested by: lmadsen

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

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=300045&r1=300044&r2=300045
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Fri Dec 31 03:29:10 2010
@@ -26,6 +26,11 @@
    gtalk.conf.
  * The 'logger reload' command now supports an optional argument, specifying an
    alternate configuration file to use.
+
+CDR
+---
+ * The filter option in cdr_adaptive_odbc now supports negating the argument,
+   thus allowing records which do NOT match the specified filter.
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 1.6.2 to Asterisk 1.8 ----------------

Modified: trunk/cdr/cdr_adaptive_odbc.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_adaptive_odbc.c?view=diff&rev=300045&r1=300044&r2=300045
==============================================================================
--- trunk/cdr/cdr_adaptive_odbc.c (original)
+++ trunk/cdr/cdr_adaptive_odbc.c Fri Dec 31 03:29:10 2010
@@ -65,6 +65,7 @@
 	SQLSMALLINT nullable;
 	SQLINTEGER octetlen;
 	AST_LIST_ENTRY(columns) list;
+	unsigned int negatefiltervalue:1;
 };
 
 struct tables {
@@ -163,9 +164,16 @@
 		/* Check for filters first */
 		for (var = ast_variable_browse(cfg, catg); var; var = var->next) {
 			if (strncmp(var->name, "filter", 6) == 0) {
+				int negate = 0;
 				char *cdrvar = ast_strdupa(var->name + 6);
 				cdrvar = ast_strip(cdrvar);
-				ast_verb(3, "Found filter %s for cdr variable %s in %s@%s\n", var->value, cdrvar, tableptr->table, tableptr->connection);
+				if (cdrvar[strlen(cdrvar) - 1] == '!') {
+					negate = 1;
+					cdrvar[strlen(cdrvar) - 1] = '\0';
+					ast_trim_blanks(cdrvar);
+				}
+
+				ast_verb(3, "Found filter %s'%s' for cdr variable %s in %s@%s\n", negate ? "!" : "", var->value, cdrvar, tableptr->table, tableptr->connection);
 
 				entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(cdrvar) + 1 + strlen(var->value) + 1);
 				if (!entry) {
@@ -180,6 +188,7 @@
 				entry->filtervalue = (char *)entry + sizeof(*entry) + strlen(cdrvar) + 1;
 				strcpy(entry->cdrname, cdrvar);
 				strcpy(entry->filtervalue, var->value);
+				entry->negatefiltervalue = negate;
 
 				AST_LIST_INSERT_TAIL(&(tableptr->columns), entry, list);
 			}
@@ -403,10 +412,11 @@
 				 * is very specifically NOT ast_strlen_zero(), because the filter
 				 * could legitimately specify that the field is blank, which is
 				 * different from the field being unspecified (NULL). */
-				if (entry->filtervalue && strcasecmp(colptr, entry->filtervalue) != 0) {
+				if ((entry->filtervalue && !entry->negatefiltervalue && strcasecmp(colptr, entry->filtervalue) != 0) ||
+					(entry->filtervalue && entry->negatefiltervalue && strcasecmp(colptr, entry->filtervalue) == 0)) {
 					ast_verb(4, "CDR column '%s' with value '%s' does not match filter of"
-						" '%s'.  Cancelling this CDR.\n",
-						entry->cdrname, colptr, entry->filtervalue);
+						" %s'%s'.  Cancelling this CDR.\n",
+						entry->cdrname, colptr, entry->negatefiltervalue ? "!" : "", entry->filtervalue);
 					goto early_release;
 				}
 

Modified: trunk/configs/cdr_adaptive_odbc.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/cdr_adaptive_odbc.conf.sample?view=diff&rev=300045&r1=300044&r2=300045
==============================================================================
--- trunk/configs/cdr_adaptive_odbc.conf.sample (original)
+++ trunk/configs/cdr_adaptive_odbc.conf.sample Fri Dec 31 03:29:10 2010
@@ -37,6 +37,8 @@
 ; Any filter specified MUST match exactly or the CDR will be discarded
 ;filter accountcode => somename
 ;filter src => 123
+; Negative filters are also now available
+;filter src != 456
 ;
 ; Additionally, we now support setting static values per column.  Reason
 ; for this is to allow different sections to specify different values for




More information about the svn-commits mailing list