aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_config_pgsql.c
diff options
context:
space:
mode:
authormogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-08-31 21:00:20 +0000
committermogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-08-31 21:00:20 +0000
commit73925ee14a02afb50f6c0aea3cc4e54f99493440 (patch)
tree5eac7fd790352b502dbbc4fc21ae517fe7c388ad /res/res_config_pgsql.c
parent43c75db33e757e08cdec37b1713a0e275d9a039b (diff)
everything that loads a config that needs a config file to run
now reports AST_MODULE_LOAD_DECLINE when loading if config file is not there, also fixed an error in res_config_pgsql where it had a non static function when it should. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@41633 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_config_pgsql.c')
-rw-r--r--res/res_config_pgsql.c93
1 files changed, 48 insertions, 45 deletions
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index f004bfd13..d3d11446a 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -553,7 +553,8 @@ static struct ast_config_engine pgsql_engine = {
static int load_module(void)
{
- parse_config();
+ if(!parse_config())
+ return AST_MODULE_LOAD_DECLINE;
ast_mutex_lock(&pgsql_lock);
@@ -624,61 +625,63 @@ static int reload(void)
return 0;
}
-int parse_config(void)
+static int parse_config(void)
{
struct ast_config *config;
char *s;
config = ast_config_load(RES_CONFIG_PGSQL_CONF);
- if (config) {
- if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: No database user found, using 'asterisk' as default.\n");
- strcpy(dbuser, "asterisk");
- } else {
- ast_copy_string(dbuser, s, sizeof(dbuser));
- }
+ if (!config) {
+ ast_log(LOG_WARNING, "Unable to load config %s\n",RES_CONFIG_PGSQL_CONF);
+ return 0;
+ }
+ if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) {
+ ast_log(LOG_WARNING,
+ "Postgresql RealTime: No database user found, using 'asterisk' as default.\n");
+ strcpy(dbuser, "asterisk");
+ } else {
+ ast_copy_string(dbuser, s, sizeof(dbuser));
+ }
- if (!(s = ast_variable_retrieve(config, "general", "dbpass"))) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: No database password found, using 'asterisk' as default.\n");
- strcpy(dbpass, "asterisk");
- } else {
- ast_copy_string(dbpass, s, sizeof(dbpass));
- }
+ if (!(s = ast_variable_retrieve(config, "general", "dbpass"))) {
+ ast_log(LOG_WARNING,
+ "Postgresql RealTime: No database password found, using 'asterisk' as default.\n");
+ strcpy(dbpass, "asterisk");
+ } else {
+ ast_copy_string(dbpass, s, sizeof(dbpass));
+ }
- if (!(s = ast_variable_retrieve(config, "general", "dbhost"))) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: No database host found, using localhost via socket.\n");
- dbhost[0] = '\0';
- } else {
- ast_copy_string(dbhost, s, sizeof(dbhost));
- }
+ if (!(s = ast_variable_retrieve(config, "general", "dbhost"))) {
+ ast_log(LOG_WARNING,
+ "Postgresql RealTime: No database host found, using localhost via socket.\n");
+ dbhost[0] = '\0';
+ } else {
+ ast_copy_string(dbhost, s, sizeof(dbhost));
+ }
- if (!(s = ast_variable_retrieve(config, "general", "dbname"))) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: No database name found, using 'asterisk' as default.\n");
- strcpy(dbname, "asterisk");
- } else {
- ast_copy_string(dbname, s, sizeof(dbname));
- }
+ if (!(s = ast_variable_retrieve(config, "general", "dbname"))) {
+ ast_log(LOG_WARNING,
+ "Postgresql RealTime: No database name found, using 'asterisk' as default.\n");
+ strcpy(dbname, "asterisk");
+ } else {
+ ast_copy_string(dbname, s, sizeof(dbname));
+ }
- if (!(s = ast_variable_retrieve(config, "general", "dbport"))) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: No database port found, using 5432 as default.\n");
- dbport = 5432;
- } else {
- dbport = atoi(s);
- }
+ if (!(s = ast_variable_retrieve(config, "general", "dbport"))) {
+ ast_log(LOG_WARNING,
+ "Postgresql RealTime: No database port found, using 5432 as default.\n");
+ dbport = 5432;
+ } else {
+ dbport = atoi(s);
+ }
- if (dbhost && !(s = ast_variable_retrieve(config, "general", "dbsock"))) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: No database socket found, using '/tmp/pgsql.sock' as default.\n");
- strcpy(dbsock, "/tmp/pgsql.sock");
- } else {
- ast_copy_string(dbsock, s, sizeof(dbsock));
- }
+ if (dbhost && !(s = ast_variable_retrieve(config, "general", "dbsock"))) {
+ ast_log(LOG_WARNING,
+ "Postgresql RealTime: No database socket found, using '/tmp/pgsql.sock' as default.\n");
+ strcpy(dbsock, "/tmp/pgsql.sock");
+ } else {
+ ast_copy_string(dbsock, s, sizeof(dbsock));
}
ast_config_destroy(config);