Index: configs/cdr_mysql.conf.sample =================================================================== --- configs/cdr_mysql.conf.sample (revision 703) +++ configs/cdr_mysql.conf.sample (working copy) @@ -32,9 +32,11 @@ ; ; You may also configure the field names used in the CDR table. ; -[aliases] -start=calldate -callerid=clid +[columns] +;static = +;alias = +alias start=calldate +alias callerid=clid ;src=src ;dst=dst ;dcontext=dcontext Index: cdr/cdr_addon_mysql.c =================================================================== --- cdr/cdr_addon_mysql.c (revision 703) +++ cdr/cdr_addon_mysql.c (working copy) @@ -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") || @@ -525,46 +528,68 @@ 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 (!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]); - 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_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); - ast_log(LOG_NOTICE, "Found a DB column %s, type %s\n", entry->name, 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) {