*
* ODBC CDR Backend
*
+ * Copyright (C) 2003-2005, Digium, Inc.
+ *
* Brian K. West <brian@bkw.org>
*
* This program is free software, distributed under the terms of
- * the GNU General Public License.
- *
- * Copyright (c) 2003 Digium, Inc.
- *
+ * the GNU General Public License
*/
#include <sys/types.h>
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;
+static int dsn_alloc = 0, username_alloc = 0, password_alloc = 0;
+static int loguniqueid = 0;
static int connected = 0;
AST_MUTEX_DEFINE_STATIC(odbc_lock);
ast_mutex_lock(&odbc_lock);
strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
memset(sqlcmd,0,2048);
- if ((loguniqueid != NULL) && (ast_true(loguniqueid))) {
+ if (loguniqueid) {
snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO cdr "
"(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,"
"lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) "
}
if (!connected) {
- res = odbc_init();
+ res = odbc_init();
if (res < 0) {
connected = 0;
ast_mutex_unlock(&odbc_lock);
return 0;
}
-
}
ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, ODBC_con, &ODBC_stmt);
SQLBindParameter(ODBC_stmt, 13, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->amaflags, 0, NULL);
SQLBindParameter(ODBC_stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->accountcode), 0, cdr->accountcode, 0, NULL);
- if ((loguniqueid != NULL) && (ast_true(loguniqueid))) {
+ if (loguniqueid) {
SQLBindParameter(ODBC_stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->uniqueid), 0, cdr->uniqueid, 0, NULL);
SQLBindParameter(ODBC_stmt, 16, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL);
}
password = NULL;
password_alloc = 0;
}
- if (loguniqueid && loguniqueid_alloc) {
- if (option_verbose > 10)
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free loguniqueid\n");
- free(loguniqueid);
- loguniqueid = NULL;
- loguniqueid_alloc = 0;
- }
+ loguniqueid = 0;
+
ast_cdr_unregister(name);
ast_mutex_unlock(&odbc_lock);
return 0;
strncpy(dsn, tmp, strlen(tmp));
} else {
ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
- return -1;
+ res = -1;
+ goto out;
}
} else {
ast_log(LOG_WARNING,"cdr_odbc: dsn not specified. Assuming asteriskdb\n");
strncpy(username, tmp, strlen(tmp));
} else {
ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
- return -1;
+ res = -1;
+ goto out;
}
} else {
ast_log(LOG_WARNING,"cdr_odbc: username not specified. Assuming root\n");
strncpy(password, tmp, strlen(tmp));
} else {
ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
- return -1;
+ res = -1;
+ goto out;
}
} else {
ast_log(LOG_WARNING,"cdr_odbc: database password not specified. Assuming blank\n");
tmp = ast_variable_retrieve(cfg,"global","loguniqueid");
if (tmp) {
- loguniqueid = malloc(strlen(tmp) + 1);
- if (loguniqueid != NULL) {
- strcpy(loguniqueid,tmp);
- loguniqueid_alloc = 1;
+ loguniqueid = ast_true(tmp);
+ if (loguniqueid) {
ast_log(LOG_NOTICE,"cdr_odbc: Logging uniqueid\n");
} else {
ast_log(LOG_ERROR,"cdr_odbc: Not logging uniqueid\n");
- loguniqueid_alloc = 1;
- loguniqueid = NULL;
}
} else {
ast_log(LOG_WARNING,"cdr_odbc: Not logging uniqueid\n");
- loguniqueid = NULL;
+ loguniqueid = 0;
}
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");
+ if (option_verbose > 2) {
+ ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: dsn is %s\n",dsn);
+ ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: username is %s\n",username);
+ ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: password is [secret]\n");
}
res = odbc_init();
if (res < 0) {
ast_log(LOG_ERROR, "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
- ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
+ if (option_verbose > 2) {
+ ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
+ }
}
res = ast_cdr_register(name, desc, odbc_log);
if (res) {