Changeset - 8b14d92f10a6
[Not reviewed]
0 1 0
HanzZ - 13 years ago 2012-04-08 14:17:32
hanzz.k@gmail.com
Don't crash when there are duplicated options and print error message instead
1 file changed with 5 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/config.cpp
Show inline comments
 
@@ -172,37 +172,42 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 

	
 
	BOOST_FOREACH(option &opt, parsed.options) {
 
		if (opt.unregistered) {
 
			m_unregistered[opt.string_key] = opt.value[0];
 
		}
 
		else if (opt.value[0].find("$jid") != std::string::npos) {
 
			boost::replace_all(opt.value[0], "$jid", jid);
 
		}
 
	}
 

	
 
	store(parsed, m_variables);
 
	notify(m_variables);
 

	
 
	onConfigReloaded();
 

	
 
	return true;
 
}
 

	
 
bool Config::load(std::istream &ifs) {
 
	options_description opts("Transport options");
 
	return load(ifs, opts);
 
}
 

	
 
bool Config::load(const std::string &configfile, const std::string &jid) {
 
	try {
 
		options_description opts("Transport options");
 
		return load(configfile, opts, jid);
 
	} catch ( const boost::program_options::multiple_occurrences& e ) {
 
		std::cerr << configfile << " parsing error: " << e.what() << " from option: " << e.get_option_name() << std::endl;
 
		return false;
 
	}
 
}
 

	
 
bool Config::reload() {
 
	if (m_file.empty()) {
 
		return false;
 
	}
 

	
 
	return load(m_file);
 
}
 

	
 
}
0 comments (0 inline, 0 general)