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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 23 22:23:29 CDT 2008


Author: seanbright
Date: Mon Jun 23 22:23:29 2008
New Revision: 124834

URL: http://svn.digium.com/view/asterisk?view=rev&rev=124834
Log:
A little bit of reorganization and consolidation.

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=124834&r1=124833&r2=124834
==============================================================================
--- team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c (original)
+++ team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c Mon Jun 23 22:23:29 2008
@@ -102,7 +102,7 @@
 static int mssql_connect(void);
 static int mssql_disconnect(void);
 
-static void cdr_tds_config_destroy(void);
+static void tds_config_free(void);
 
 static int tds_log(struct ast_cdr *cdr)
 {
@@ -331,13 +331,15 @@
 	return 0;
 }
 
-static void cdr_tds_config_destroy(void)
-{
-	if (settings) {
-		ast_mutex_destroy(&settings->lock);
-		ast_string_field_free_memory(settings);
-		ast_free(settings);
-	}
+static void tds_config_free(void)
+{
+	if (!settings) {
+		return;
+	}
+
+	ast_mutex_destroy(&settings->lock);
+	ast_string_field_free_memory(settings);
+	ast_free(settings);
 }
 
 static int tds_unload_module(void)
@@ -348,7 +350,7 @@
 		ast_mutex_unlock(&settings->lock);
 	}
 
-	cdr_tds_config_destroy();
+	tds_config_free();
 	ast_cdr_unregister(name);
 
 	dbexit();
@@ -414,6 +416,7 @@
 				settings = NULL;
 			}
 			ast_config_destroy(cfg);
+			dbexit();
 			return 0;
 		}
 
@@ -427,10 +430,7 @@
 		ast_string_field_set(settings, hostname, ptr);
 	} else {
 		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;
+		goto failed;
 	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "dbname");
@@ -438,10 +438,7 @@
 		ast_string_field_set(settings, database, ptr);
 	} else {
 		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;
+		goto failed;
 	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "user");
@@ -449,10 +446,7 @@
 		ast_string_field_set(settings, username, ptr);
 	} else {
 		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;
+		goto failed;
 	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "password");
@@ -460,10 +454,7 @@
 		ast_string_field_set(settings, password, ptr);
 	} else {
 		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;
+		goto failed;
 	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "charset");
@@ -493,7 +484,7 @@
 	mssql_disconnect();
 
 	if (mssql_connect()) {
-		/* We failed to connect (mssql_connect) takes care of logging it. */
+		/* We failed to connect (mssql_connect takes care of logging it) */
 		ast_mutex_unlock(&settings->lock);
 		return 0;
 	}
@@ -501,6 +492,16 @@
 	ast_mutex_unlock(&settings->lock);
 
 	return 1;
+
+failed:
+	ast_mutex_unlock(&settings->lock);
+	tds_config_free();
+	ast_config_destroy(cfg);
+	if (!reload) {
+		dbexit();
+	}
+
+	return 0;
 }
 
 static int reload(void)




More information about the asterisk-commits mailing list