allow to use host database connection parameter

Add config option:
db_host (default empty) - name of host to connect to
This commit is contained in:
2022-04-28 06:12:44 +02:00
parent 98c1e8daad
commit c6c50a5d23
6 changed files with 51 additions and 16 deletions

View File

@@ -355,7 +355,7 @@ bool App::Init()
if( !config.db_conn_string.empty() )
postgresql_connector.set_conn_param(config.db_conn_string);
else
postgresql_connector.set_conn_param(config.db_hostaddr, config.db_port, config.db_database, config.db_user, config.db_pass);
postgresql_connector.set_conn_param(config.db_host, config.db_hostaddr, config.db_port, config.db_database, config.db_user, config.db_pass);
postgresql_connector.set_logger(log);
postgresql_connector.set_log_queries(config.log_db_query);
@@ -385,7 +385,7 @@ bool App::Init()
if( !config.db_conn_string.empty() )
db_conn.SetConnParam(config.db_conn_string);
else
db_conn.SetConnParam(config.db_hostaddr, config.db_port, config.db_database, config.db_user, config.db_pass);
db_conn.SetConnParam(config.db_host, config.db_hostaddr, config.db_port, config.db_database, config.db_user, config.db_pass);
db_conn.WaitForConnection();
db.LogQueries(config.log_db_query);

View File

@@ -181,6 +181,7 @@ void Config::AssignValues()
http_session_id_name = Text(L"http_session_id_name", L"session_id");
db_conn_string = Text(L"db_conn_string");
db_host = Text(L"db_host");
db_hostaddr = Text(L"db_hostaddr");
db_port = Text(L"db_port");
db_database = Text(L"db_database");

View File

@@ -204,12 +204,37 @@ public:
// the database connection string
// https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNSTRING
// default: empty (not used if empty)
// default: empty
// if empty then winix uses db_host and db_hostaddr
std::wstring db_conn_string;
// the database host ip address and port number
// default: empty which means winix connects to a Unix-domain socket
// the database host name used if db_conn_string is empty
// default: empty
std::wstring db_host;
// the database host ip address used if db_conn_string is empty
// default: empty
// if db_host is empty and db_hostaddr is empty then winix connects to a Unix-domain socket
// meaning of db_host and db_hostaddr parameters is the same as described in
// https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNSTRING
//
// from above documentation:
// Using hostaddr allows the application to avoid a host name look-up, which might be important
// in applications with time constraints. However, a host name is required for GSSAPI or SSPI
// authentication methods, as well as for verify-full SSL certificate verification.
// The following rules are used:
//
// - If host is specified without hostaddr, a host name lookup occurs.
//
// - If hostaddr is specified without host, the value for hostaddr gives the server network address.
// The connection attempt will fail if the authentication method requires a host name.
//
// - If both host and hostaddr are specified, the value for hostaddr gives the server network address.
// The value for host is ignored unless the authentication method requires it, in which case it will
// be used as the host name.
std::wstring db_hostaddr;
// the database port number
std::wstring db_port;
// the database name, user name and a password for the PostgreSQL database

View File

@@ -92,7 +92,7 @@ void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
if( !config->db_conn_string.empty() )
data.postgresql_connector.set_conn_param(config->db_conn_string);
else
data.postgresql_connector.set_conn_param(config->db_hostaddr, config->db_port, config->db_database, config->db_user, config->db_pass);
data.postgresql_connector.set_conn_param(config->db_host, config->db_hostaddr, config->db_port, config->db_database, config->db_user, config->db_pass);
data.postgresql_connector.set_logger(item.object->get_logger());
data.postgresql_connector.set_log_queries(config->log_db_query);