Check if vhosts are configured before using them

This commit is contained in:
Jan Kaluza 2011-11-07 13:10:42 +01:00
parent 7cd4658101
commit bf55d8c7b5
2 changed files with 12 additions and 2 deletions

View file

@ -34,6 +34,7 @@
#define CONFIG_BOOL(PTR, KEY) (*PTR)[KEY].as<bool>()
#define CONFIG_LIST(PTR, KEY) (*PTR)[KEY].as<std::list<std::string> >()
#define CONFIG_VECTOR(PTR, KEY) (*PTR)[KEY].as<std::vector<std::string> >()
#define CONFIG_HAS_KEY(PTR, KEY) (*PTR).hasKey(KEY)
namespace Transport {
@ -75,6 +76,10 @@ class Config {
bool reload();
bool hasKey(const std::string &key) {
return m_variables.find(key) != m_variables.end();
}
/// Returns value of variable defined by key.
/// For variables in sections you can use "section.variable" key format.

View file

@ -151,7 +151,10 @@ static void start_all_instances(ManagerConfig *config) {
continue;
}
std::vector<std::string> vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost");
std::vector<std::string> vhosts;
if (CONFIG_HAS_KEY(&cfg, "vhosts.vhost"))
vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost");
vhosts.push_back(CONFIG_STRING(&cfg, "service.jid"));
BOOST_FOREACH(std::string &vhost, vhosts) {
@ -201,7 +204,9 @@ static void stop_all_instances(ManagerConfig *config) {
std::cerr << "Can't load config file " << itr->path().string() << ". Skipping...\n";
}
std::vector<std::string> vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost");
std::vector<std::string> vhosts;
if (CONFIG_HAS_KEY(&cfg, "vhosts.vhost"))
vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost");
vhosts.push_back(CONFIG_STRING(&cfg, "service.jid"));
BOOST_FOREACH(std::string &vhost, vhosts) {