[asterisk-commits] seanbright: branch seanbright/issue13290 r137345 - /team/seanbright/issue1329...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 12 18:32:26 CDT 2008


Author: seanbright
Date: Tue Aug 12 18:32:25 2008
New Revision: 137345

URL: http://svn.digium.com/view/asterisk?view=rev&rev=137345
Log:
It compiles, that's a start.

Modified:
    team/seanbright/issue13290/cdr/cdr_tds.c

Modified: team/seanbright/issue13290/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/issue13290/cdr/cdr_tds.c?view=diff&rev=137345&r1=137344&r2=137345
==============================================================================
--- team/seanbright/issue13290/cdr/cdr_tds.c (original)
+++ team/seanbright/issue13290/cdr/cdr_tds.c Tue Aug 12 18:32:25 2008
@@ -48,7 +48,8 @@
 	[billsec] [int] NULL ,
 	[disposition] [varchar] (20) NULL ,
 	[amaflags] [varchar] (16) NULL ,
-	[uniqueid] [varchar] (32) NULL
+	[uniqueid] [varchar] (32) NULL ,
+	[userfield] [varchar] (256) NULL
 ) ON [PRIMARY]
 
 \endverbatim
@@ -93,8 +94,8 @@
 
 static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *charset = NULL, *language = NULL;
 static char *table = NULL;
-
 static int connected = 0;
+static int has_userfield = 0;
 
 AST_MUTEX_DEFINE_STATIC(tds_lock);
 
@@ -111,7 +112,7 @@
 static int tds_log(struct ast_cdr *cdr)
 {
 	char sqlcmd[2048], start[80], answer[80], end[80];
-	char *accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid;
+	char *accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid, *userfield = NULL;
 	int res = 0;
 	int retried = 0;
 #ifdef FREETDS_PRE_0_62
@@ -133,71 +134,144 @@
 	lastdata = anti_injection(cdr->lastdata, 80);
 	uniqueid = anti_injection(cdr->uniqueid, 32);
 
+	if (has_userfield) {
+		userfield = anti_injection(cdr->userfield, AST_MAX_USER_FIELD);
+	}
+
 	get_date(start, cdr->start);
 	get_date(answer, cdr->answer);
 	get_date(end, cdr->end);
 
-	sprintf(
-		sqlcmd,
-		"INSERT INTO %s "
-		"("
-			"accountcode, "
-			"src, "
-			"dst, "
-			"dcontext, "
-			"clid, "
-			"channel, "
-			"dstchannel, "
-			"lastapp, "
-			"lastdata, "
-			"start, "
-			"answer, "
-			"[end], "
-			"duration, "
-			"billsec, "
-			"disposition, "
-			"amaflags, "
-			"uniqueid"
-		") "
-		"VALUES "
-		"("
-			"'%s', "	/* accountcode */
-			"'%s', "	/* src */
-			"'%s', "	/* dst */
-			"'%s', "	/* dcontext */
-			"'%s', "	/* clid */
-			"'%s', "	/* channel */
-			"'%s', "	/* dstchannel */
-			"'%s', "	/* lastapp */
-			"'%s', "	/* lastdata */
-			"%s, "		/* start */
-			"%s, "		/* answer */
-			"%s, "		/* end */
-			"%ld, "		/* duration */
-			"%ld, "		/* billsec */
-			"'%s', "	/* disposition */
-			"'%s', "	/* amaflags */
-			"'%s'"		/* uniqueid */
-		")",
-		table,
-		accountcode,
-		src,
-		dst,
-		dcontext,
-		clid,
-		channel,
-		dstchannel,
-		lastapp,
-		lastdata,
-		start,
-		answer,
-		end,
-		cdr->duration,
-		cdr->billsec,
-		ast_cdr_disp2str(cdr->disposition),
-		ast_cdr_flags2str(cdr->amaflags),
-		uniqueid
-	);
+	if (has_userfield) {
+		snprintf(
+			sqlcmd,
+			sizeof(sqlcmd),
+			"INSERT INTO %s "
+			"("
+				"accountcode, "
+				"src, "
+				"dst, "
+				"dcontext, "
+				"clid, "
+				"channel, "
+				"dstchannel, "
+				"lastapp, "
+				"lastdata, "
+				"start, "
+				"answer, "
+				"[end], "
+				"duration, "
+				"billsec, "
+				"disposition, "
+				"amaflags, "
+				"uniqueid, "
+				"userfield"
+			") "
+			"VALUES "
+			"("
+				"'%s', "	/* accountcode */
+				"'%s', "	/* src */
+				"'%s', "	/* dst */
+				"'%s', "	/* dcontext */
+				"'%s', "	/* clid */
+				"'%s', "	/* channel */
+				"'%s', "	/* dstchannel */
+				"'%s', "	/* lastapp */
+				"'%s', "	/* lastdata */
+				"%s, "		/* start */
+				"%s, "		/* answer */
+				"%s, "		/* end */
+				"%ld, "		/* duration */
+				"%ld, "		/* billsec */
+				"'%s', "	/* disposition */
+				"'%s', "	/* amaflags */
+				"'%s', "	/* uniqueid */
+				"'%s'"		/* userfield */
+			")",
+			table,
+			accountcode,
+			src,
+			dst,
+			dcontext,
+			clid,
+			channel,
+			dstchannel,
+			lastapp,
+			lastdata,
+			start,
+			answer,
+			end,
+			cdr->duration,
+			cdr->billsec,
+			ast_cdr_disp2str(cdr->disposition),
+			ast_cdr_flags2str(cdr->amaflags),
+			uniqueid,
+			userfield
+			);
+	} else {
+		snprintf(
+			sqlcmd,
+			sizeof(sqlcmd),
+			"INSERT INTO %s "
+			"("
+				"accountcode, "
+				"src, "
+				"dst, "
+				"dcontext, "
+				"clid, "
+				"channel, "
+				"dstchannel, "
+				"lastapp, "
+				"lastdata, "
+				"start, "
+				"answer, "
+				"[end], "
+				"duration, "
+				"billsec, "
+				"disposition, "
+				"amaflags, "
+				"uniqueid"
+			") "
+			"VALUES "
+			"("
+				"'%s', "	/* accountcode */
+				"'%s', "	/* src */
+				"'%s', "	/* dst */
+				"'%s', "	/* dcontext */
+				"'%s', "	/* clid */
+				"'%s', "	/* channel */
+				"'%s', "	/* dstchannel */
+				"'%s', "	/* lastapp */
+				"'%s', "	/* lastdata */
+				"%s, "		/* start */
+				"%s, "		/* answer */
+				"%s, "		/* end */
+				"%ld, "		/* duration */
+				"%ld, "		/* billsec */
+				"'%s', "	/* disposition */
+				"'%s', "	/* amaflags */
+				"'%s'"		/* uniqueid */
+			")",
+			table,
+			accountcode,
+			src,
+			dst,
+			dcontext,
+			clid,
+			channel,
+			dstchannel,
+			lastapp,
+			lastdata,
+			start,
+			answer,
+			end,
+			cdr->duration,
+			cdr->billsec,
+			ast_cdr_disp2str(cdr->disposition),
+			ast_cdr_flags2str(cdr->amaflags),
+			uniqueid
+			);
+	}
 
 	do {
 		if (!connected) {
@@ -231,6 +305,9 @@
 	free(lastapp);
 	free(lastdata);
 	free(uniqueid);
+	if (userfield) {
+		free(userfield);
+	}
 
 	ast_mutex_unlock(&tds_lock);
 
@@ -388,7 +465,7 @@
 #endif
 	connection = NULL;
 
-	sprintf(query, "USE %s", dbname);
+	snprintf(query, sizeof(query), "USE %s", dbname);
 #ifdef FREETDS_PRE_0_62
 	if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
 #else
@@ -397,6 +474,29 @@
 	{
 		ast_log(LOG_ERROR, "Could not change database (%s)\n", dbname);
 		goto connect_fail;
+	}
+
+	snprintf(query, sizeof(query), "SELECT 1 FROM %s", table);
+#ifdef FREETDS_PRE_0_62
+	if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
+#else
+	if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds) != TDS_SUCCEED))
+#endif
+	{
+		ast_log(LOG_ERROR, "Could not find table '%s' in database '%s'\n", table, dbname);
+		goto connect_fail;
+	}
+
+	has_userfield = 1;
+	snprintf(query, sizeof(query), "SELECT userfield FROM %s WHERE 1 == 0", table);
+#ifdef FREETDS_PRE_0_62
+	if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
+#else
+	if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds) != TDS_SUCCEED))
+#endif
+	{
+		ast_log(LOG_NOTICE, "Unable to find 'userfield' column in table '%s'\n", table);
+		has_userfield = 0;
 	}
 
 	connected = 1;




More information about the asterisk-commits mailing list