[svn-commits] tilghman: trunk r704 - in /trunk: ./ cdr/ configs/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Dec 4 13:50:04 CST 2008
Author: tilghman
Date: Thu Dec 4 13:50:04 2008
New Revision: 704
URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=704
Log:
Permit static values in the MySQL backend, just like cdr_adaptive_odbc.
(closes issue #14009)
Reported by: markwilkinson
Patches:
cdr_mysql-2.patch uploaded by markwilkinson (license 532)
Modified:
trunk/UPGRADE.txt
trunk/cdr/cdr_addon_mysql.c
trunk/configs/cdr_mysql.conf.sample
Modified: trunk/UPGRADE.txt
URL: http://svn.digium.com/view/asterisk-addons/trunk/UPGRADE.txt?view=diff&rev=704&r1=703&r2=704
==============================================================================
--- trunk/UPGRADE.txt (original)
+++ trunk/UPGRADE.txt Thu Dec 4 13:50:04 2008
@@ -8,7 +8,7 @@
cdr_addon_mysql
===============
- Module has been completely revamped, with some options in the config file no
- longer used and an additional new section called [aliases]. Please read the
+ longer used and an additional new section called [columns]. Please read the
sample config to familiarize yourself with these changes.
- Module now permits arbitrary columns to be created and populated, just like
cdr_adaptive_odbc, simply by adding the column to the table and defining the
@@ -22,4 +22,6 @@
- Standard columns may also be excluded now, simply by dropping the column
name from the table, renaming the column, or aliasing the cdrname from a
nonexistent variable (e.g. foo => amaflags).
+ - Also, static values may be defined in the configuration file, for inserting
+ specific static values into the MySQL CDR table.
Modified: trunk/cdr/cdr_addon_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/cdr/cdr_addon_mysql.c?view=diff&rev=704&r1=703&r2=704
==============================================================================
--- trunk/cdr/cdr_addon_mysql.c (original)
+++ trunk/cdr/cdr_addon_mysql.c Thu Dec 4 13:50:04 2008
@@ -83,6 +83,7 @@
struct column {
char *name;
char *cdrname;
+ char *staticvalue;
char *type;
AST_LIST_ENTRY(column) list;
};
@@ -262,7 +263,9 @@
strcat(sql1, entry->name);
/* Need the type and value to determine if we want the raw value or not */
- if ((!strcmp(cdrname, "start") ||
+ if (entry->staticvalue) {
+ value = ast_strdupa(entry->staticvalue);
+ } else if ((!strcmp(cdrname, "start") ||
!strcmp(cdrname, "answer") ||
!strcmp(cdrname, "end") ||
!strcmp(cdrname, "disposition") ||
@@ -456,8 +459,9 @@
calldate_compat = 0;
}
- if (res < 0)
+ if (res < 0) {
return AST_MODULE_LOAD_FAILURE;
+ }
/* Check for any aliases */
AST_RWLIST_WRLOCK(&columns);
@@ -524,47 +528,69 @@
while ((row = mysql_fetch_row(result))) {
struct column *entry;
- int foundalias = 0;
+ char *cdrvar = "", *staticvalue = "";
ast_debug(1, "Got a field '%s' of type '%s'\n", row[0], row[1]);
- /* Check for an alias */
- for (var = ast_variable_browse(cfg, "aliases"); var; var = var->next) {
- if (strcasecmp(var->value, row[0])) {
- continue;
+ /* Check for an alias or a static value */
+ for (var = ast_variable_browse(cfg, "columns"); var; var = var->next) {
+ if (strncmp(var->name, "alias", 5) == 0 && strcasecmp(var->value, row[0]) == 0 ) {
+ char *alias = ast_strdupa(var->name + 5);
+ cdrvar = ast_strip(alias);
+ ast_verb(3, "Found alias %s for column %s\n", cdrvar, row[0]);
+ break;
+ } else if (strncmp(var->name, "static", 6) == 0 && strcasecmp(var->value, row[0]) == 0) {
+ char *item = ast_strdupa(var->name + 6);
+ item = ast_strip(item);
+ if (item[0] == '"' && item[strlen(item) - 1] == '"') {
+ /* Remove surrounding quotes */
+ item[strlen(item) - 1] = '\0';
+ item++;
+ }
+ staticvalue = item;
}
-
- if (!(entry = ast_calloc(1, sizeof(*entry) + strlen(var->name) + 1 + strlen(var->value) + 1 + strlen(row[1]) + 1))) {
- continue;
- }
-
+ }
+
+ entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(row[0]) + 1 + strlen(cdrvar) + 1 + strlen(staticvalue) + 1 + strlen(row[1]) + 1);
+ if (!entry) {
+ ast_log(LOG_ERROR, "Out of memory creating entry for column '%s'\n", row[0]);
+ res = -1;
+ break;
+ }
+
+ entry->name = (char *)entry + sizeof(*entry);
+ strcpy(entry->name, row[0]);
+
+ if (!ast_strlen_zero(cdrvar)) {
+ entry->cdrname = entry->name + strlen(row[0]) + 1;
+ strcpy(entry->cdrname, cdrvar);
+ } else { /* Point to same place as the column name */
entry->cdrname = (char *)entry + sizeof(*entry);
- entry->name = (char *)entry + sizeof(*entry) + strlen(var->name) + 1;
- entry->type = (char *)entry + sizeof(*entry) + strlen(var->name) + 1 + strlen(var->value) + 1;
- strcpy(entry->cdrname, var->name);
- strcpy(entry->name, var->value);
- strcpy(entry->type, row[1]);
-
- AST_LIST_INSERT_TAIL(&columns, entry, list);
- ast_log(LOG_NOTICE, "Found an alias from CDR variable %s to DB column %s, type %s\n", entry->cdrname, entry->name, entry->type);
- foundalias = 1;
- break;
- }
-
- if (!foundalias && (entry = ast_calloc(1, sizeof(*entry) + strlen(row[0]) + 1 + strlen(row[1]) + 1))) {
- entry->cdrname = (char *)entry + sizeof(*entry);
- entry->name = (char *)entry + sizeof(*entry);
- entry->type = (char *)entry + sizeof(*entry) + strlen(row[0]) + 1;
- strcpy(entry->name, row[0]);
- strcpy(entry->type, row[1]);
-
- AST_LIST_INSERT_TAIL(&columns, entry, list);
- ast_log(LOG_NOTICE, "Found a DB column %s, type %s\n", entry->name, entry->type);
- }
+ }
+
+ if (!ast_strlen_zero(staticvalue)) {
+ entry->staticvalue = entry->cdrname + strlen(entry->cdrname) + 1;
+ strcpy(entry->staticvalue, staticvalue);
+ ast_debug(1, "staticvalue length: %d\n", strlen(staticvalue) );
+ entry->type = entry->staticvalue + strlen(entry->staticvalue) + 1;
+ } else {
+ entry->type = entry->cdrname + strlen(entry->cdrname) + 1;
+ }
+ strcpy(entry->type, row[1]);
+
+ ast_debug(1, "Entry name '%s'\n", entry->name);
+ ast_debug(1, " cdrname '%s'\n", entry->cdrname);
+ ast_debug(1, " static '%s'\n", entry->staticvalue);
+ ast_debug(1, " type '%s'\n", entry->type);
+
+ AST_LIST_INSERT_TAIL(&columns, entry, list);
}
mysql_free_result(result);
}
AST_RWLIST_UNLOCK(&columns);
ast_config_destroy(cfg);
+ if (res < 0) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
res = ast_cdr_register(name, desc, mysql_log);
if (res) {
Modified: trunk/configs/cdr_mysql.conf.sample
URL: http://svn.digium.com/view/asterisk-addons/trunk/configs/cdr_mysql.conf.sample?view=diff&rev=704&r1=703&r2=704
==============================================================================
--- trunk/configs/cdr_mysql.conf.sample (original)
+++ trunk/configs/cdr_mysql.conf.sample Thu Dec 4 13:50:04 2008
@@ -32,20 +32,22 @@
;
; You may also configure the field names used in the CDR table.
;
-[aliases]
-start=calldate
-callerid=clid
-;src=src
-;dst=dst
-;dcontext=dcontext
-;channel=channel
-;dstchannel=dstchannel
-;lastapp=lastapp
-;lastdata=lastdata
-;duration=duration
-;billsec=billsec
-;disposition=disposition
-;amaflags=amaflags
-;accountcode=accountcode
-;userfield=userfield
-;uniqueid=uniqueid
+[columns]
+;static "<value>" => <column>
+;alias <cdrvar> => <column>
+alias start => calldate
+alias callerid => clid
+;alias src => src
+;alias dst => dst
+;alias dcontext => dcontext
+;alias channel => channel
+;alias dstchannel => dstchannel
+;alias lastapp => lastapp
+;alias lastdata => lastdata
+;alias duration => duration
+;alias billsec => billsec
+;alias disposition => disposition
+;alias amaflags => amaflags
+;alias accountcode => accountcode
+;alias userfield => userfield
+;alias uniqueid => uniqueid
More information about the svn-commits
mailing list