various fixes regarding coding guidelines issues

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@28935 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Russell Bryant 19 years ago
parent bdc30b8d9d
commit f1a97c3b3f

@ -209,82 +209,60 @@ static int my_unload_module(void)
static int process_my_load_module(struct ast_config *cfg) static int process_my_load_module(struct ast_config *cfg)
{ {
int res;
struct ast_variable *var; struct ast_variable *var;
char *pgerror; char *pgerror;
char *tmp; char *tmp;
var = ast_variable_browse(cfg, "global"); if (!(var = ast_variable_browse(cfg, "global")))
if (!var) {
/* nothing configured */
return 0; return 0;
}
tmp = ast_variable_retrieve(cfg,"global","hostname"); if (!(tmp = ast_variable_retrieve(cfg,"global","hostname"))) {
if (tmp == NULL) {
ast_log(LOG_WARNING,"PostgreSQL server hostname not specified. Assuming unix socket connection\n"); ast_log(LOG_WARNING,"PostgreSQL server hostname not specified. Assuming unix socket connection\n");
tmp = ""; /* connect via UNIX-socket by default */ tmp = ""; /* connect via UNIX-socket by default */
} }
pghostname = strdup(tmp);
if (pghostname == NULL) { if (!(pghostname = ast_strdup(tmp)))
ast_log(LOG_ERROR,"Out of memory error.\n");
return -1; return -1;
}
tmp = ast_variable_retrieve(cfg,"global","dbname"); if (!(tmp = ast_variable_retrieve(cfg, "global", "dbname"))) {
if (tmp == NULL) {
ast_log(LOG_WARNING,"PostgreSQL database not specified. Assuming asterisk\n"); ast_log(LOG_WARNING,"PostgreSQL database not specified. Assuming asterisk\n");
tmp = "asteriskcdrdb"; tmp = "asteriskcdrdb";
} }
pgdbname = strdup(tmp);
if (pgdbname == NULL) { if (!(pgdbname = ast_strdup(tmp)))
ast_log(LOG_ERROR,"Out of memory error.\n");
return -1; return -1;
}
tmp = ast_variable_retrieve(cfg,"global","user"); if (!(tmp = ast_variable_retrieve(cfg, "global", "user"))) {
if (tmp == NULL) {
ast_log(LOG_WARNING,"PostgreSQL database user not specified. Assuming root\n"); ast_log(LOG_WARNING,"PostgreSQL database user not specified. Assuming root\n");
tmp = "root"; tmp = "root";
} }
pgdbuser = strdup(tmp);
if (pgdbuser == NULL) { if (!(pgdbuser = ast_strdup(tmp)))
ast_log(LOG_ERROR,"Out of memory error.\n");
return -1; return -1;
}
tmp = ast_variable_retrieve(cfg,"global","password"); if (!(tmp = ast_variable_retrieve(cfg, "global", "password"))) {
if (tmp == NULL) {
ast_log(LOG_WARNING,"PostgreSQL database password not specified. Assuming blank\n"); ast_log(LOG_WARNING,"PostgreSQL database password not specified. Assuming blank\n");
tmp = ""; tmp = "";
} }
pgpassword = strdup(tmp);
if (pgpassword == NULL) { if (!(pgpassword = ast_strdup(tmp)))
ast_log(LOG_ERROR,"Out of memory error.\n");
return -1; return -1;
}
tmp = ast_variable_retrieve(cfg,"global","port"); if (!(tmp = ast_variable_retrieve(cfg,"global","port"))) {
if (tmp == NULL) {
ast_log(LOG_WARNING,"PostgreSQL database port not specified. Using default 5432.\n"); ast_log(LOG_WARNING,"PostgreSQL database port not specified. Using default 5432.\n");
tmp = "5432"; tmp = "5432";
} }
pgdbport = strdup(tmp);
if (pgdbport == NULL) { if (!(pgdbport = ast_strdup(tmp)))
ast_log(LOG_ERROR,"Out of memory error.\n");
return -1; return -1;
}
tmp = ast_variable_retrieve(cfg,"global","table"); if (!(tmp = ast_variable_retrieve(cfg, "global", "table"))) {
if (tmp == NULL) {
ast_log(LOG_WARNING,"CDR table not specified. Assuming cdr\n"); ast_log(LOG_WARNING,"CDR table not specified. Assuming cdr\n");
tmp = "cdr"; tmp = "cdr";
} }
table = strdup(tmp);
if (table == NULL) { if (!(table = ast_strdup(tmp)))
ast_log(LOG_ERROR,"Out of memory error.\n");
return -1; return -1;
}
if (option_debug) { if (option_debug) {
if (ast_strlen_zero(pghostname)) if (ast_strlen_zero(pghostname))
@ -310,24 +288,22 @@ static int process_my_load_module(struct ast_config *cfg)
connected = 0; connected = 0;
} }
res = ast_cdr_register(name, desc, pgsql_log); return ast_cdr_register(name, desc, pgsql_log);
if (res) {
ast_log(LOG_ERROR, "Unable to register PGSQL CDR handling\n");
}
return res;
} }
static int my_load_module(void) static int my_load_module(void)
{ {
struct ast_config *cfg; struct ast_config *cfg;
int res; int res;
cfg = ast_config_load(config);
if (!cfg) { if (!(cfg = ast_config_load(config))) {
ast_log(LOG_WARNING, "Unable to load config for PostgreSQL CDR's: %s\n", config); ast_log(LOG_WARNING, "Unable to load config for PostgreSQL CDR's: %s\n", config);
return 0; return 0;
} }
res = process_my_load_module(cfg); res = process_my_load_module(cfg);
ast_config_destroy(cfg); ast_config_destroy(cfg);
return res; return res;
} }

Loading…
Cancel
Save