[asterisk-commits] seanbright: branch seanbright/cdr-tds-conversion r126113 - /team/seanbright/c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 27 17:48:45 CDT 2008


Author: seanbright
Date: Fri Jun 27 17:48:44 2008
New Revision: 126113

URL: http://svn.digium.com/view/asterisk?view=rev&rev=126113
Log:
Try to make the locking more granular in the logging function, fix a date
time problem I just introduced, and introduce a small formatting change
that surely violates the coding guidelines.

Modified:
    team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c

Modified: team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c?view=diff&rev=126113&r1=126112&r2=126113
==============================================================================
--- team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c (original)
+++ team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c Fri Jun 27 17:48:44 2008
@@ -110,30 +110,30 @@
 	char start[80], answer[80], end[80];
 	char *accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid;
 	RETCODE erc;
+	int res = -1;
+
+	accountcode = anti_injection(cdr->accountcode, 20);
+	src         = anti_injection(cdr->src, 80);
+	dst         = anti_injection(cdr->dst, 80);
+	dcontext    = anti_injection(cdr->dcontext, 80);
+	clid        = anti_injection(cdr->clid, 80);
+	channel     = anti_injection(cdr->channel, 80);
+	dstchannel  = anti_injection(cdr->dstchannel, 80);
+	lastapp     = anti_injection(cdr->lastapp, 80);
+	lastdata    = anti_injection(cdr->lastdata, 80);
+	uniqueid    = anti_injection(cdr->uniqueid, 32);
+
+	get_date(start, sizeof(start), cdr->start);
+	get_date(answer, sizeof(answer), cdr->answer);
+	get_date(end, sizeof(end), cdr->end);
 
 	ast_mutex_lock(&tds_lock);
-
-	accountcode = anti_injection(cdr->accountcode, 20);
-	src = anti_injection(cdr->src, 80);
-	dst = anti_injection(cdr->dst, 80);
-	dcontext = anti_injection(cdr->dcontext, 80);
-	clid = anti_injection(cdr->clid, 80);
-	channel = anti_injection(cdr->channel, 80);
-	dstchannel = anti_injection(cdr->dstchannel, 80);
-	lastapp = anti_injection(cdr->lastapp, 80);
-	lastdata = anti_injection(cdr->lastdata, 80);
-	uniqueid = anti_injection(cdr->uniqueid, 32);
-
-	get_date(start, 80, cdr->start);
-	get_date(answer, 80, cdr->answer);
-	get_date(end, 80, cdr->end);
 
 	/* Ensure that we are connected */
 	if (!settings->connected) {
 		if (mssql_connect()) {
 			/* Connect failed */
-			ast_mutex_unlock(&tds_lock);
-			return -1;
+			goto done;
 		}
 	}
 
@@ -198,6 +198,29 @@
 		uniqueid
 	);
 
+	if (erc == FAIL) {
+		ast_log(LOG_ERROR, "Failed to build query\n");
+		goto done;
+	}
+
+	erc = dbsqlexec(settings->dbproc);
+
+	if (erc == FAIL) {
+		ast_log(LOG_ERROR, "Failed to send query\n");
+		goto done;
+	}
+
+	/* Consume any results we might get back (this is more of a sanity check than
+	 * anything else, since an INSERT shouldn't return results). */
+	while ((erc = dbresults(settings->dbproc)) != NO_MORE_RESULTS) {
+		while (dbnextrow(settings->dbproc) != NO_MORE_ROWS);
+	}
+
+	res = 0;
+
+done:
+	ast_mutex_unlock(&tds_lock);
+
 	ast_free(accountcode);
 	ast_free(src);
 	ast_free(dst);
@@ -209,28 +232,6 @@
 	ast_free(lastdata);
 	ast_free(uniqueid);
 
-	if (erc == FAIL) {
-		ast_log(LOG_ERROR, "Failed to build query\n");
-		ast_mutex_unlock(&tds_lock);
-		return -1;
-	}
-
-	erc = dbsqlexec(settings->dbproc);
-
-	if (erc == FAIL) {
-		ast_log(LOG_ERROR, "Failed to send query\n");
-		ast_mutex_unlock(&tds_lock);
-		return -1;
-	}
-
-	/* Consume any results we might get back (this is more of a sanity check than
-	 * anything else, since an INSERT shouldn't return results). */
-	while ((erc = dbresults(settings->dbproc)) != NO_MORE_RESULTS) {
-		while (dbnextrow(settings->dbproc) != NO_MORE_ROWS);
-	}
-
-	ast_mutex_unlock(&tds_lock);
-
 	return 0;
 }
 
@@ -274,7 +275,7 @@
 	if (!ast_tvzero(tv)) {
 		struct ast_tm tm;
 		ast_localtime(&tv, &tm, NULL);
-		ast_strftime(dateField, len, DATE_FORMAT, &tm);
+		ast_strftime(dateField, len, "'" DATE_FORMAT "'", &tm);
 	} else {
 		ast_copy_string(dateField, "null", len);
 	}




More information about the asterisk-commits mailing list