[asterisk-commits] murf: branch 1.4 r143964 - /branches/1.4/cdr/cdr_odbc.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 23 09:22:10 CDT 2008


Author: murf
Date: Tue Sep 23 09:22:10 2008
New Revision: 143964

URL: http://svn.digium.com/view/asterisk?view=rev&rev=143964
Log:
In at least one machine, we noted that the timestr
was not getting set in the STMT; it was coming out,
usually, as binary garbage to an mssql server.
These changes fixed the problem. The only thing
I can venture forth as a guess, is that the pointer
is being stored in the interface, not a copy of the
string. Because we ripped the build process into a 
subroutine, the timestr became a temp. stack variable,
and between the time the STMT got built and the
time it was executed on the server, the string being
pointed to was damaged. At any rate, even if this
theory is false, and some mechanism was at fault,
this fix worked reliably where it didn't before.

Why this bug didn't bite last week, I have no idea.
This change basically defines the timestr buffer
in the calling function, extending the life of the
buffer to cover both the STMT's building and
processing to the server.


Modified:
    branches/1.4/cdr/cdr_odbc.c

Modified: branches/1.4/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/cdr/cdr_odbc.c?view=diff&rev=143964&r1=143963&r2=143964
==============================================================================
--- branches/1.4/cdr/cdr_odbc.c (original)
+++ branches/1.4/cdr/cdr_odbc.c Tue Sep 23 09:22:10 2008
@@ -90,10 +90,10 @@
 	connected = 0;
 }
 
-static void build_query(struct ast_cdr *cdr)
+static void build_query(struct ast_cdr *cdr, char *timestr, int timesize)
 {
 	int ODBC_res;
-	char sqlcmd[2048] = "", timestr[128];
+	char sqlcmd[2048] = "";
 	int res = 0;
 	struct tm tm;
 
@@ -102,7 +102,7 @@
 	else
 		ast_localtime(&cdr->start.tv_sec, &tm, NULL);
 
-	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+	strftime(timestr, timesize, DATE_FORMAT, &tm);
 	memset(sqlcmd,0,2048);
 	if (loguniqueid) {
 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
@@ -150,7 +150,7 @@
 		return;
 	}
 
-	SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(timestr), 0, &timestr, 0, NULL);
+	SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, timesize, 0, timestr, 0, NULL);
 	SQLBindParameter(ODBC_stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->clid), 0, cdr->clid, 0, NULL);
 	SQLBindParameter(ODBC_stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->src), 0, cdr->src, 0, NULL);
 	SQLBindParameter(ODBC_stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dst), 0, cdr->dst, 0, NULL);
@@ -177,15 +177,14 @@
 static int odbc_log(struct ast_cdr *cdr)
 {
 	int res = 0;
+	char timestr[150];
 
 	ast_mutex_lock(&odbc_lock);
-	build_query(cdr);
+	build_query(cdr, timestr, sizeof(timestr));
 
 	if (connected) {
 		res = odbc_do_query();
 		if (res < 0) {
-			if (option_verbose > 10)		
-				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
 			if (option_verbose > 10)
 				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
 			odbc_disconnect();
@@ -198,7 +197,7 @@
 				if (option_verbose > 10)
 					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
 				SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
-				build_query(cdr); /* what a waste. If we have to reconnect, we have to build a new query */
+				build_query(cdr, timestr, sizeof(timestr)); /* what a waste. If we have to reconnect, we have to build a new query */
 				res = odbc_do_query();
 				if (res < 0) {
 					if (option_verbose > 10)




More information about the asterisk-commits mailing list