[Asterisk-code-review] cdr adaptive odbc: Prevent not logger when is load before th... (asterisk[master])

Rodrigo Ramirez Norambuena asteriskteam at digium.com
Mon Mar 7 13:11:43 CST 2016


Rodrigo Ramirez Norambuena has uploaded a new change for review.

  https://gerrit.asterisk.org/2363

Change subject: cdr_adaptive_odbc: Prevent not logger when is load before than database.
......................................................................

cdr_adaptive_odbc: Prevent not logger when is load before than database.

When cdr_adaptive_odbc is loaded  before than the database the module is
not configure the fields then not logger the cdr.

This patch prevent this case. Is set a flag to check if connection is ok
otherwise try the reload the module before a log.

Also fix little format code.

ASTERISK-25834 #close

Change-Id: If3569e29d26357055f440abf70f790cd12e874bf
---
M cdr/cdr_adaptive_odbc.c
1 file changed, 26 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/63/2363/1

diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c
index 0da8c01..97e7b0f 100644
--- a/cdr/cdr_adaptive_odbc.c
+++ b/cdr/cdr_adaptive_odbc.c
@@ -90,6 +90,8 @@
 
 static AST_RWLIST_HEAD_STATIC(odbc_tables, tables);
 
+static int connected = 0;
+
 static int load_config(void)
 {
 	struct ast_config *cfg;
@@ -117,8 +119,9 @@
 
 	for (catg = ast_category_browse(cfg, NULL); catg; catg = ast_category_browse(cfg, catg)) {
 		var = ast_variable_browse(cfg, catg);
-		if (!var)
+		if (!var) {
 			continue;
+		}
 
 		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "connection"))) {
 			ast_log(LOG_WARNING, "No connection parameter found in '%s'.  Skipping.\n", catg);
@@ -298,6 +301,7 @@
 			/* Insert column info into column list */
 			AST_LIST_INSERT_TAIL(&(tableptr->columns), entry, list);
 			res = 0;
+			connected = 1;
 		}
 
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
@@ -322,6 +326,20 @@
 		}
 		ast_free(table);
 	}
+	return 0;
+}
+
+
+static int reload_config(void)
+{
+	if (AST_RWLIST_WRLOCK(&odbc_tables)) {
+		ast_log(LOG_ERROR, "Unable to lock column list.  Reload failed.\n");
+		return -1;
+	}
+
+	free_config();
+	load_config();
+	AST_RWLIST_UNLOCK(&odbc_tables);
 	return 0;
 }
 
@@ -396,6 +414,12 @@
 		if (sql2)
 			ast_free(sql2);
 		return -1;
+	}
+
+	// check was a connection on load by flag connection
+	if (!connected) {
+		ast_log(LOG_WARNING, "The initial connection is load is not work. Reload module...\n");
+		reload_config();
 	}
 
 	if (AST_RWLIST_RDLOCK(&odbc_tables)) {
@@ -814,15 +838,7 @@
 
 static int reload(void)
 {
-	if (AST_RWLIST_WRLOCK(&odbc_tables)) {
-		ast_log(LOG_ERROR, "Unable to lock column list.  Reload failed.\n");
-		return -1;
-	}
-
-	free_config();
-	load_config();
-	AST_RWLIST_UNLOCK(&odbc_tables);
-	return 0;
+	return reload_config();
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Adaptive ODBC CDR backend",
@@ -832,4 +848,3 @@
 	.reload = reload,
 	.load_pri = AST_MODPRI_CDR_DRIVER,
 );
-

-- 
To view, visit https://gerrit.asterisk.org/2363
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If3569e29d26357055f440abf70f790cd12e874bf
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Rodrigo Ramirez Norambuena <a at rodrigoramirez.com>



More information about the asterisk-code-review mailing list