Index: cdr/cdr_odbc.c =================================================================== RCS file: /usr/cvsroot/asterisk/cdr/cdr_odbc.c,v retrieving revision 1.15.2.1 diff -u -5 -r1.15.2.1 cdr_odbc.c --- cdr/cdr_odbc.c 5 Oct 2004 02:02:17 -0000 1.15.2.1 +++ cdr/cdr_odbc.c 31 Oct 2004 20:41:28 -0000 @@ -35,12 +35,12 @@ #define DATE_FORMAT "%Y-%m-%d %T" static char *desc = "ODBC CDR Backend"; static char *name = "ODBC"; static char *config = "cdr_odbc.conf"; -static char *dsn = NULL, *username = NULL, *password = NULL, *loguniqueid = NULL; -static int dsn_alloc = 0, username_alloc = 0, password_alloc = 0, loguniqueid_alloc = 0; +static char *dsn = NULL, *username = NULL, *password = NULL, *loguniqueid = NULL, *table = NULL; +static int dsn_alloc = 0, username_alloc = 0, password_alloc = 0, loguniqueid_alloc = 0, table_alloc = 0; static int connected = 0; AST_MUTEX_DEFINE_STATIC(odbc_lock); static int odbc_do_query(void); @@ -64,19 +64,19 @@ ast_mutex_lock(&odbc_lock); strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); memset(sqlcmd,0,2048); if ((loguniqueid != NULL) && (ast_true(loguniqueid))) { - snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO cdr " + snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s " "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp," "lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) " - "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table); } else { - snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO cdr " + snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s " "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata," "duration,billsec,disposition,amaflags,accountcode) " - "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table); } if (!connected) { res = odbc_init(); if (res < 0) { @@ -208,10 +208,17 @@ ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free loguniqueid\n"); free(loguniqueid); loguniqueid = NULL; loguniqueid_alloc = 0; } + if (table && table_alloc) { + if (option_verbose > 10) + ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free table\n"); + free(table); + table = NULL; + table_alloc = 0; + } ast_cdr_unregister(name); ast_mutex_unlock(&odbc_lock); return 0; } @@ -299,15 +306,32 @@ } else { ast_log(LOG_WARNING,"cdr_odbc: Not logging uniqueid\n"); loguniqueid = NULL; } + tmp = ast_variable_retrieve(cfg,"global","table"); + if (tmp) { + table = malloc(strlen(tmp) + 1); + if (table != NULL) { + memset(table, 0, strlen(tmp) + 1); + table_alloc = 1; + strncpy(table, tmp, strlen(tmp)); + } else { + ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n"); + return -1; + } + } else { + ast_log(LOG_WARNING,"cdr_odbc: table not specified. Assuming cdr\n"); + table = "cdr"; + } + ast_destroy(cfg); if (option_verbose > 3) { ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: dsn is %s\n",dsn); ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: username is %s\n",username); ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: password is [secret]\n"); + ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: table is %s\n",table); } res = odbc_init(); if (res < 0) { ast_log(LOG_ERROR, "cdr_odbc: Unable to connect to datasource: %s\n", dsn); @@ -417,11 +441,17 @@ return odbc_load_module(); } int usecount(void) { - return connected; + /* Simplistic use count */ + if (ast_mutex_trylock(&odbc_lock)) { + return 1; + } else { + ast_mutex_unlock(&odbc_lock); + return 0; + } } char *key() { return ASTERISK_GPL_KEY;