summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2018-01-11 14:37:49 +0200
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2018-05-03 18:56:58 +0300
commit1e315f6cb505c706e319ba53643573872356d835 (patch)
tree721e0a202907e17a2a37bf0fb522131772c615a2
parent5b1946ebc196f5a1dfb620f719cabb5c276d7170 (diff)
cdr_mysql: check early for missing configs
ASTERISK-27572 Change-Id: Id5126f525fb255574bbf44878059a8d1890843fc
-rw-r--r--addons/cdr_mysql.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c
index bd31664c8..766c1fc0a 100644
--- a/addons/cdr_mysql.c
+++ b/addons/cdr_mysql.c
@@ -185,7 +185,7 @@ static int mysql_log(struct ast_cdr *cdr)
ast_mutex_lock(&mysql_lock);
db_reconnect:
- if ((!connected) && (hostname || dbsock) && dbuser && password && dbname && dbtable ) {
+ if (!connected) {
/* Attempt to connect */
mysql_init(&mysql);
/* Add option to quickly timeout the connection */
@@ -581,6 +581,37 @@ static int my_connect_db(struct ast_config *cfg)
return AST_MODULE_LOAD_SUCCESS;
}
+static const char * my_global_var(ast_config *cfg, const char *var_name)
+{
+ return ast_variable_retrieve(cfg, "global", variable);
+}
+
+
+const char[] required_global_cfgs[] = {
+ "dbuser", "dbpassword", "dbname", "dbtable"
+};
+
+static int is_valid_cfg(ast_config *cfg)
+{
+ int i;
+
+ if (! (my_global_var(cfg, "hostname") || my_global_var(cfg, "dbsock"))) {
+ ast_log(LOG_ERROR, "Either 'hostname' or 'dbsock' must be set\n");
+ return 0;
+ }
+
+ for (i = 0; i < sizeof(required_global_cfgs); i++) {
+ if (!my_global_var(cfg, required_global_cfgs[i])) {
+ ast_log(LOG_ERROR, "'%s' must be set\n",
+ required_global_cfgs[i]);
+ return 0;
+ }
+
+ }
+
+ return 1;
+}
+
static int my_load_module(int reload)
{
int res;
@@ -605,6 +636,10 @@ static int my_load_module(int reload)
return AST_MODULE_LOAD_DECLINE;
}
+ if (!is_valid_cfg(cfg)) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
if (reload) {
AST_RWLIST_WRLOCK(&columns);
my_unload_module(1);