summaryrefslogtreecommitdiff
path: root/cdr
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2010-12-31 09:29:10 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2010-12-31 09:29:10 +0000
commit96b7a9950c4d6abc68b4285f35594cb499884693 (patch)
treec1d4fa8fe418fc3ff2a68ae36f207ceafa9ea63c /cdr
parent793b68b082edd03554bd5f61825689a399a2b61c (diff)
Support negative filters.
(closes issue #17979) Reported by: tilghman Patches: 20100911__for_blitzrage.diff.txt uploaded by tilghman (license 14) Tested by: lmadsen git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@300045 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'cdr')
-rw-r--r--cdr/cdr_adaptive_odbc.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c
index f0b0e99bf..db19896f2 100644
--- a/cdr/cdr_adaptive_odbc.c
+++ b/cdr/cdr_adaptive_odbc.c
@@ -65,6 +65,7 @@ struct columns {
SQLSMALLINT nullable;
SQLINTEGER octetlen;
AST_LIST_ENTRY(columns) list;
+ unsigned int negatefiltervalue:1;
};
struct tables {
@@ -163,9 +164,16 @@ static int load_config(void)
/* 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 @@ static int load_config(void)
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 @@ static int odbc_log(struct ast_cdr *cdr)
* 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;
}