[Asterisk-cvs] asterisk/cdr cdr_odbc.c,1.15.2.4,1.15.2.5

russell at lists.digium.com russell at lists.digium.com
Sun Jan 16 19:40:10 CST 2005


Update of /usr/cvsroot/asterisk/cdr
In directory mongoose.digium.com:/tmp/cvs-serv24092/cdr

Modified Files:
      Tag: v1-0
	cdr_odbc.c 
Log Message:
various fixes (bug #3340)


Index: cdr_odbc.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr/cdr_odbc.c,v
retrieving revision 1.15.2.4
retrieving revision 1.15.2.5
diff -u -d -r1.15.2.4 -r1.15.2.5
--- cdr_odbc.c	13 Jan 2005 04:08:15 -0000	1.15.2.4
+++ cdr_odbc.c	17 Jan 2005 01:43:33 -0000	1.15.2.5
@@ -3,13 +3,12 @@
  *
  * ODBC CDR Backend
  * 
+ * Copyright (C) 2003-2005, Digium, Inc.
+ *
  * Brian K. West <brian at 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>
@@ -37,8 +36,9 @@
 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);
@@ -65,7 +65,7 @@
 	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) "
@@ -78,13 +78,12 @@
 	}
 
 	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);
@@ -130,7 +129,7 @@
 	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);
 	}
@@ -204,13 +203,8 @@
 		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;
@@ -246,7 +240,8 @@
 			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");
@@ -262,7 +257,8 @@
 			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");
@@ -278,7 +274,8 @@
 			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");
@@ -287,32 +284,30 @@
 
 	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) {




More information about the svn-commits mailing list