[svn-commits] seanbright: branch seanbright/cdr-tds-conversion r124797 - /team/seanbright/c...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jun 23 19:47:11 CDT 2008


Author: seanbright
Date: Mon Jun 23 19:47:11 2008
New Revision: 124797

URL: http://svn.digium.com/view/asterisk?view=rev&rev=124797
Log:
Clean up message and error reporting, reorganize module unload, remove an unused variable, and don't forget to free up the config when we're done with it.

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=124797&r1=124796&r2=124797
==============================================================================
--- team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c (original)
+++ team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c Mon Jun 23 19:47:11 2008
@@ -333,9 +333,15 @@
 
 static int tds_unload_module(void)
 {
-	mssql_disconnect();
+	if (settings) {
+		ast_mutex_lock(&settings->lock);
+		mssql_disconnect();
+		ast_mutex_unlock(&settings->lock);
+	}
+
+	cdr_tds_config_destroy();
 	ast_cdr_unregister(name);
-	cdr_tds_config_destroy();
+
 	dbexit();
 
 	return 0;
@@ -343,20 +349,25 @@
 
 static int tds_error_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
 {
-	ast_log(LOG_ERROR, "%s / %s\n", dberrstr, oserrstr);
+	ast_log(LOG_ERROR, "%s (%d)\n", dberrstr, dberr);
+
+	if (oserr != DBNOERR) {
+		ast_log(LOG_ERROR, "%s (%d)\n", oserrstr, oserr);
+	}
+
 	return INT_CANCEL;
 }
 
 static int tds_message_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
 {
-	ast_log(LOG_NOTICE, "Error: %s\n", msgtext);
+	ast_log(LOG_NOTICE, "Msg %d, Level %d, State %d, Line %d\n%s\n", msgno, severity, msgstate, line, msgtext);
+
 	return 0;
 }
 
 static int tds_load_module(int reload)
 {
 	struct ast_config *cfg;
-	struct ast_variable *var;
 	const char *ptr = NULL;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
@@ -367,13 +378,14 @@
 	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
 		return 0;
 
-	var = ast_variable_browse(cfg, "global");
-	if (!var) /* nothing configured */ {
+	if (!ast_variable_browse(cfg, "global")) {
+		/* nothing configured */
 		ast_config_destroy(cfg);
 		return 0;
 	}
 
 	if (reload) {
+		/* This will clear out all of our existing settings */
 		ast_string_field_init(settings, 0);
 	} else {
 		if (dbinit() == FAIL) {
@@ -408,6 +420,7 @@
 		ast_log(LOG_ERROR, "Failed to connect: Database server hostname not specified.\n");
 		ast_mutex_unlock(&settings->lock);
 		cdr_tds_config_destroy();
+		ast_config_destroy(cfg);
 		return 0;
 	}
 
@@ -418,6 +431,7 @@
 		ast_log(LOG_ERROR, "Failed to connect: Database dbname not specified.\n");
 		ast_mutex_unlock(&settings->lock);
 		cdr_tds_config_destroy();
+		ast_config_destroy(cfg);
 		return 0;
 	}
 
@@ -428,6 +442,7 @@
 		ast_log(LOG_ERROR, "Failed to connect: Database dbuser not specified.\n");
 		ast_mutex_unlock(&settings->lock);
 		cdr_tds_config_destroy();
+		ast_config_destroy(cfg);
 		return 0;
 	}
 
@@ -438,6 +453,7 @@
 		ast_log(LOG_ERROR, "Failed to connect: Database password not specified.\n");
 		ast_mutex_unlock(&settings->lock);
 		cdr_tds_config_destroy();
+		ast_config_destroy(cfg);
 		return 0;
 	}
 




More information about the svn-commits mailing list