[svn-commits] tilghman: branch tilghman/cdr_custom_odbc r61769 - in
/team/tilghman/cdr_cust...
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Mon Apr 23 16:10:41 MST 2007
Author: tilghman
Date: Mon Apr 23 18:10:40 2007
New Revision: 61769
URL: http://svn.digium.com/view/asterisk?view=rev&rev=61769
Log:
Change name, add aliases, optimize for memory allocations
Modified:
team/tilghman/cdr_custom_odbc/cdr/cdr_custom_odbc.c
team/tilghman/cdr_custom_odbc/configs/cdr_custom_odbc.conf.sample
Modified: team/tilghman/cdr_custom_odbc/cdr/cdr_custom_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/cdr_custom_odbc/cdr/cdr_custom_odbc.c?view=diff&rev=61769&r1=61768&r2=61769
==============================================================================
--- team/tilghman/cdr_custom_odbc/cdr/cdr_custom_odbc.c (original)
+++ team/tilghman/cdr_custom_odbc/cdr/cdr_custom_odbc.c Mon Apr 23 18:10:40 2007
@@ -3,7 +3,7 @@
*
* Copyright (C) 2007, Tilghman Lesher
*
- * Tilghman Lesher <cdr_custom_odbc__v1 at the-tilghman.com>
+ * Tilghman Lesher <cdr_adaptive_odbc__v1 at the-tilghman.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -18,9 +18,9 @@
/*! \file
*
- * \brief Custom ODBC CDR backend
+ * \brief Adaptive ODBC CDR backend
*
- * \author Tilghman Lesher <cdr_custom_odbc__v1 at the-tilghman.com>
+ * \author Tilghman Lesher <cdr_adaptive_odbc__v1 at the-tilghman.com>
* \ingroup cdr_drivers
*/
@@ -53,12 +53,15 @@
#include "asterisk/module.h"
#include "asterisk/logger.h"
-#define CONFIG "custom_odbc.conf"
-
-static char *name = "Custom ODBC";
+#define CONFIG "cdr_adaptive_odbc.conf"
+
+static char *name = "Adaptive ODBC";
+/* Optimization to reduce number of memory allocations */
+static int maxsize = 512, maxsize2 = 512;
struct columns {
char *name;
+ char *cdrname;
SQLSMALLINT type;
SQLINTEGER size;
SQLSMALLINT decimals;
@@ -95,7 +98,7 @@
cfg = ast_config_load(CONFIG);
if (!cfg) {
- ast_log(LOG_WARNING, "Unable to load " CONFIG ". No custom ODBC CDRs.\n");
+ ast_log(LOG_WARNING, "Unable to load " CONFIG ". No adaptive ODBC CDRs.\n");
return -1;
}
@@ -138,7 +141,7 @@
continue;
}
- tableptr = ast_calloc(1, sizeof(*tableptr) + lenconnection + 1 + lentable + 1);
+ tableptr = ast_calloc(sizeof(char), sizeof(*tableptr) + lenconnection + 1 + lentable + 1);
if (!tableptr) {
ast_log(LOG_ERROR, "Out of memory creating entry for table '%s' on connection '%s'\n", table, connection);
ast_odbc_release_obj(obj);
@@ -152,15 +155,36 @@
ast_copy_string(tableptr->table, table, lentable + 1);
while ((res = SQLFetch(stmt)) != SQL_NO_DATA && res != SQL_ERROR) {
+ char *cdrvar = "";
+
SQLGetData(stmt, 4, SQL_C_CHAR, columnname, sizeof(columnname), &sqlptr);
- entry = ast_calloc(1, sizeof(*entry) + strlen(columnname) + 1);
+
+ /* Is there an alias for this column? */
+
+ /* NOTE: This seems like a non-optimal parse method, but I'm going
+ * for user configuration readability, rather than fast parsing. We
+ * really don't parse this file all that often, anyway.
+ */
+ for (var = ast_variable_browse(cfg, catg); var; var = var->next) {
+ if (strcasecmp(var->value, columnname) == 0) {
+ cdrvar = ast_strip(ast_strdupa(var->name + 5));
+ break;
+ }
+ }
+ entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(columnname) + 1 + strlen(cdrvar) + 1);
if (!entry) {
ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s' on connection '%s'\n", columnname, table, connection);
res = -1;
break;
}
entry->name = (char *)entry + sizeof(*entry);
- strcpy((char *)entry + sizeof(*entry), columnname);
+ strcpy(entry->name, columnname);
+
+ if (!ast_strlen_zero(cdrvar)) {
+ entry->cdrname = entry->name + strlen(columnname) + 1;
+ strcpy(entry->cdrname, cdrvar);
+ } else /* Point to same place as the column name */
+ entry->cdrname = (char *)entry + sizeof(*entry);
SQLGetData(stmt, 5, SQL_C_SHORT, &entry->type, sizeof(entry->type), NULL);
SQLGetData(stmt, 7, SQL_C_LONG, &entry->size, sizeof(entry->size), NULL);
@@ -257,9 +281,9 @@
struct tables *tableptr;
struct columns *entry;
struct odbc_obj *obj;
+ int lensql, lensql2, sizesql = maxsize, sizesql2 = maxsize2, newsize;
/* Allocated, so we can realloc() */
- char *sql = ast_calloc(1, 512), *sql2 = ast_calloc(1, 512), *tmp;
- int lensql, lensql2, sizesql = 512, sizesql2 = 512, newsize;
+ char *sql = ast_calloc(sizeof(char), sizesql), *sql2 = ast_calloc(sizeof(char), sizesql2), *tmp;
char colbuf[1024], *colptr;
SQLHSTMT stmt = NULL;
SQLINTEGER rows = 0;
@@ -501,14 +525,20 @@
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
}
if (rows == 0) {
- ast_log(LOG_WARNING, "cdr_custom_odbc: Insert failed on '%s:%s'. CDR failed: %s\n", tableptr->connection, tableptr->table, sql);
+ ast_log(LOG_WARNING, "cdr_adaptive_odbc: Insert failed on '%s:%s'. CDR failed: %s\n", tableptr->connection, tableptr->table, sql);
}
ast_odbc_release_obj(obj);
} else {
- ast_log(LOG_WARNING, "cdr_custom_odbc: Unable to retrieve database handle for '%s:%s'. CDR failed: %s\n", tableptr->connection, tableptr->table, sql);
+ ast_log(LOG_WARNING, "cdr_adaptive_odbc: Unable to retrieve database handle for '%s:%s'. CDR failed: %s\n", tableptr->connection, tableptr->table, sql);
}
}
AST_RWLIST_UNLOCK(&odbc_tables);
+
+ /* Next time, just allocate buffers that are that big to start with. */
+ if (sizesql > maxsize)
+ maxsize = sizesql;
+ if (sizesql2 > maxsize2)
+ maxsize2 = sizesql2;
ast_free(sql);
ast_free(sql2);
@@ -556,7 +586,7 @@
return 0;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Custom ODBC CDR backend",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Adaptive ODBC CDR backend",
.load = load_module,
.unload = unload_module,
.reload = reload,
Modified: team/tilghman/cdr_custom_odbc/configs/cdr_custom_odbc.conf.sample
URL: http://svn.digium.com/view/asterisk/team/tilghman/cdr_custom_odbc/configs/cdr_custom_odbc.conf.sample?view=diff&rev=61769&r1=61768&r2=61769
==============================================================================
--- team/tilghman/cdr_custom_odbc/configs/cdr_custom_odbc.conf.sample (original)
+++ team/tilghman/cdr_custom_odbc/configs/cdr_custom_odbc.conf.sample Mon Apr 23 18:10:40 2007
@@ -7,7 +7,8 @@
; system is that beyond setting up the configuration file to tell you what
; tables to look at, there isn't anything more to do beyond creating the
; columns for the fields that you want, and populating the corresponding
-; CDR variables in the dialplan.
+; CDR variables in the dialplan. For the builtin variables only, you may
+; create aliases for the real column name.
;
; Please note that after adding columns to the database, it is necessary to
; reload this module to get the new column names and types read.
@@ -27,4 +28,9 @@
[third]
connection=sqlserver
table=AsteriskCDR
+alias src => source
+alias channel => source_channel
+alias dst => dest
+alias dstchannel => dest_channel
+
More information about the svn-commits
mailing list