From 8e1f28fdd6908a852dd0d11ea868fef965b89790 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 21 Aug 2008 10:00:09 +0000 Subject: Made postgres addr, username and password configurable. --- server/src/configuration.cc | 4 ++++ server/src/configuration.h | 4 ++++ server/src/configurationparser.cc | 19 +++++++++++++++++++ server/src/database.h | 6 +++--- server/src/server.cc | 2 +- 5 files changed, 31 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/src/configuration.cc b/server/src/configuration.cc index fc2da6a..33f3256 100644 --- a/server/src/configuration.cc +++ b/server/src/configuration.cc @@ -38,3 +38,7 @@ time_t Conf::pentominos_max_ttl = 60 * 60 * 24; std::string Conf::pentominos_addr = "localhost"; port_t Conf::pentominos_port = 11108; + +std::string Conf::database_addr = "localhost"; +std::string Conf::database_user = "pracro"; +std::string Conf::database_passwd = "pracro"; diff --git a/server/src/configuration.h b/server/src/configuration.h index eacac14..fde9bd1 100644 --- a/server/src/configuration.h +++ b/server/src/configuration.h @@ -47,6 +47,10 @@ namespace Conf { extern std::string pentominos_addr; extern port_t pentominos_port; + + extern std::string database_addr; + extern std::string database_user; + extern std::string database_passwd; }; #endif/*__ARTEFACT_CONFIGURATION_H__*/ diff --git a/server/src/configurationparser.cc b/server/src/configurationparser.cc index 3065907..6bab578 100644 --- a/server/src/configurationparser.cc +++ b/server/src/configurationparser.cc @@ -103,4 +103,23 @@ void ConfigurationParser::reload() Conf::pentominos_port = p; } catch( ... ) { } + + try { + std::string a = lookup("database_addr"); + Conf::database_addr = a; + } catch( ... ) { + } + + try { + std::string u = lookup("database_user"); + Conf::database_user = u; + } catch( ... ) { + } + + try { + std::string p = lookup("database_passwd"); + Conf::database_passwd = p; + } catch( ... ) { + } + } diff --git a/server/src/database.h b/server/src/database.h index c15aca5..332907f 100644 --- a/server/src/database.h +++ b/server/src/database.h @@ -50,9 +50,9 @@ typedef std::vector< std::string > Fieldnames; class Database { public: - Database(std::string hostname = "localhost", - std::string user = "pracro", - std::string password = "pracro"); + Database(std::string hostname, + std::string user, + std::string password); ~Database(); // Make a commit to the db diff --git a/server/src/server.cc b/server/src/server.cc index 75dc341..b98cc94 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -79,7 +79,7 @@ static std::string handleTransaction(Transaction &transaction) answer += "\n"; try { - Database db; + Database db(Conf::database_addr, Conf::database_user, Conf::database_passwd); // // Handle commits -- cgit v1.2.3