res_config_pgsql: normalize database connection option with cel and cdr by supporting new options name

pull/1059/head
Abdelkader Boudih 4 months ago committed by asterisk-org-access-app[bot]
parent f72b8aa064
commit a24853ecdf

@ -1,25 +1,25 @@
; ;
; Sample configuration for res_config_pgsql ; Sample configuration for res_config_pgsql
; ;
; The value of dbhost may be either a hostname or an IP address. ; The value of hostname may be either a hostname or an IP address.
; If dbhost is commented out or the string "localhost", a connection ; If hostname is commented out or the string "localhost", a connection
; to the local host is assumed and dbsock is used instead of TCP/IP ; to the local host is assumed and dbsock is used instead of TCP/IP
; to connect to the server. ; to connect to the server.
; ;
[general] [general]
dbhost=127.0.0.1 ;hostname=localhost
dbport=5432 ;port=5432
dbname=asterisk ;dbname=asterisk
dbuser=asterisk ;user=postgres
dbpass=password ;password=password
;dbappname=asterisk ; Postgres application_name support (optional). Whitespace not allowed. ;appname=asterisk ; Postgres application_name support (optional). Whitespace not allowed.
;
; dbsock is specified as the directory where the socket file may be found. The ; socket is specified as the directory where the socket file may be found. The
; actual socket is constructed as a combination of dbsock and dbport. For ; actual socket is constructed as a combination of socket and port. For
; example, the values of '/tmp' and '5432', respectively, will specify a socket ; example, the values of '/tmp' and '5432', respectively, will specify a socket
; file of '/tmp/.s.PGSQL.5432'. ; file of '/tmp/.s.PGSQL.5432'.
; ;
;dbsock=/tmp ;socket=/tmp
; ;
; requirements - At startup, each realtime family will make requirements ; requirements - At startup, each realtime family will make requirements
; on the backend. There are several strategies for handling requirements: ; on the backend. There are several strategies for handling requirements:

@ -1459,61 +1459,80 @@ static int parse_config(int is_reload)
pgsqlConn = NULL; pgsqlConn = NULL;
} }
if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) { /* Check new 'user' option first, then fall back to legacy 'dbuser' */
ast_log(LOG_WARNING, s = ast_variable_retrieve(config, "general", "user");
"PostgreSQL RealTime: No database user found, using 'asterisk' as default.\n"); if (!s) {
s = ast_variable_retrieve(config, "general", "dbuser");
}
if (!s) {
ast_log(LOG_WARNING, "PostgreSQL RealTime: No database user found, using 'asterisk' as default.\n");
strcpy(dbuser, "asterisk"); strcpy(dbuser, "asterisk");
} else { } else {
ast_copy_string(dbuser, s, sizeof(dbuser)); ast_copy_string(dbuser, s, sizeof(dbuser));
} }
if (!(s = ast_variable_retrieve(config, "general", "dbpass"))) { /* Check new 'password' option first, then fall back to legacy 'dbpass' */
ast_log(LOG_WARNING, s = ast_variable_retrieve(config, "general", "password");
"PostgreSQL RealTime: No database password found, using 'asterisk' as default.\n"); if (!s) {
s = ast_variable_retrieve(config, "general", "dbpass");
}
if (!s) {
ast_log(LOG_WARNING, "PostgreSQL RealTime: No database password found, using 'asterisk' as default.\n");
strcpy(dbpass, "asterisk"); strcpy(dbpass, "asterisk");
} else { } else {
ast_copy_string(dbpass, s, sizeof(dbpass)); ast_copy_string(dbpass, s, sizeof(dbpass));
} }
if (!(s = ast_variable_retrieve(config, "general", "dbhost"))) { /* Check new 'hostname' option first, then fall back to legacy 'dbhost' */
ast_log(LOG_WARNING, s = ast_variable_retrieve(config, "general", "hostname");
"PostgreSQL RealTime: No database host found, using localhost via socket.\n"); if (!s) {
s = ast_variable_retrieve(config, "general", "dbhost");
}
if (!s) {
ast_log(LOG_WARNING, "PostgreSQL RealTime: No database host found, using localhost via socket.\n");
dbhost[0] = '\0'; dbhost[0] = '\0';
} else { } else {
ast_copy_string(dbhost, s, sizeof(dbhost)); ast_copy_string(dbhost, s, sizeof(dbhost));
} }
if (!(s = ast_variable_retrieve(config, "general", "dbname"))) { /* Check new 'port' option first, then fall back to legacy 'dbport' */
ast_log(LOG_WARNING, s = ast_variable_retrieve(config, "general", "port");
"PostgreSQL RealTime: No database name found, using 'asterisk' as default.\n"); if (!s) {
strcpy(dbname, "asterisk"); s = ast_variable_retrieve(config, "general", "dbport");
} else {
ast_copy_string(dbname, s, sizeof(dbname));
} }
if (!s) {
if (!(s = ast_variable_retrieve(config, "general", "dbport"))) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No database port found, using 5432 as default.\n");
ast_log(LOG_WARNING,
"PostgreSQL RealTime: No database port found, using 5432 as default.\n");
dbport = 5432; dbport = 5432;
} else { } else {
dbport = atoi(s); dbport = atoi(s);
} }
if (!(s = ast_variable_retrieve(config, "general", "dbappname"))) { /* Check new 'appname' option first, then fall back to legacy 'dbappname' */
s = ast_variable_retrieve(config, "general", "appname");
if (!s) {
s = ast_variable_retrieve(config, "general", "dbappname");
}
if (!s) {
dbappname[0] = '\0'; dbappname[0] = '\0';
} else { } else {
ast_copy_string(dbappname, s, sizeof(dbappname)); ast_copy_string(dbappname, s, sizeof(dbappname));
} }
/* Handle socket configuration if no host is specified */
if (!ast_strlen_zero(dbhost)) { if (!ast_strlen_zero(dbhost)) {
/* No socket needed */ /* No socket needed */
} else if (!(s = ast_variable_retrieve(config, "general", "dbsock"))) { } else {
ast_log(LOG_WARNING, s = ast_variable_retrieve(config, "general", "socket");
"PostgreSQL RealTime: No database socket found, using '/tmp/.s.PGSQL.%d' as default.\n", dbport); if (!s) {
s = ast_variable_retrieve(config, "general", "dbsock");
}
if (!s) {
ast_log(LOG_WARNING, "PostgreSQL RealTime: No database socket found, using '/tmp/.s.PGSQL.%d' as default.\n", dbport);
strcpy(dbsock, "/tmp"); strcpy(dbsock, "/tmp");
} else { } else {
ast_copy_string(dbsock, s, sizeof(dbsock)); ast_copy_string(dbsock, s, sizeof(dbsock));
} }
}
if (!(s = ast_variable_retrieve(config, "general", "requirements"))) { if (!(s = ast_variable_retrieve(config, "general", "requirements"))) {
ast_log(LOG_WARNING, ast_log(LOG_WARNING,

Loading…
Cancel
Save