Changeset - c2cdd3702f33
[Not reviewed]
0 3 0
Jan Kaluza - 13 years ago 2012-09-04 08:16:16
hanzz.k@gmail.com
Config::getSectionValues and Config::getCommandLineArgs
3 files changed with 40 insertions and 1 deletions:
0 comments (0 inline, 0 general)
include/Swiften/TLS/Schannel/SchannelServerContext.cpp
Show inline comments
 
@@ -60,7 +60,7 @@ void SchannelServerContext::connect()
 
	{
 
		if (m_my_cert_store == NULL)
 
		{
 
			m_my_cert_store = CertOpenSystemStore(0, m_cert_store_name.c_str());
 
			m_my_cert_store = CertOpenSystemStoreA(0, m_cert_store_name.c_str());
 
			if (!m_my_cert_store)
 
			{
 
/////			printf( "**** Error 0x%x returned by CertOpenSystemStore\n", GetLastError() );
include/transport/config.h
Show inline comments
 
@@ -35,6 +35,9 @@
 
#define CONFIG_LIST(PTR, KEY) (*PTR)[KEY].as<std::list<std::string> >()
 
#define CONFIG_VECTOR(PTR, KEY) ((*PTR).hasKey(KEY) ? (*PTR)[KEY].as<std::vector<std::string> >() : std::vector<std::string>())
 

	
 
#define CONFIG_STRING_DEFAULTED(PTR, KEY, DEF) ((*PTR).hasKey(KEY) ? (*PTR)[KEY].as<std::string>() : DEF)
 
#define CONFIG_BOOL_DEFAULTED(PTR, KEY, DEF) ((*PTR).hasKey(KEY) ? (*PTR)[KEY].as<bool>() : DEF)
 

	
 

	
 
namespace Transport {
 

	
 
@@ -49,6 +52,9 @@ typedef boost::program_options::variables_map Variables;
 
/// class documentation to get a list of all relevant variables for that class.
 
class Config {
 
	public:
 
		typedef std::map<std::string, boost::program_options::variable_value> SectionValuesCont;
 
		typedef std::map<std::string, boost::program_options::variable_value> UnregisteredCont;
 

	
 
		/// Constructor.
 
		Config(int argc = 0, char **argv = NULL) : m_argc(argc), m_argv(argv) {}
 

	
 
@@ -91,6 +97,10 @@ class Config {
 
			return m_unregistered[key];
 
		}
 

	
 
		SectionValuesCont getSectionValues(const std::string& sectionName);
 
 
 
		std::string getCommandLineArgs() const;
 

	
 
		/// Returns path to config file from which data were loaded.
 
		const std::string &getConfigFile() { return m_file; }
 

	
src/config.cpp
Show inline comments
 
@@ -31,6 +31,7 @@
 

	
 
#include "iostream"
 
#include "boost/version.hpp"
 
#include "boost/algorithm/string.hpp"
 

	
 
#define BOOST_MAJOR_VERSION BOOST_VERSION / 100000
 
#define BOOST_MINOR_VERSION BOOST_VERSION / 100 % 1000
 
@@ -249,4 +250,32 @@ bool Config::reload() {
 
	return load(m_file);
 
}
 

	
 
Config::SectionValuesCont Config::getSectionValues(const std::string& sectionName) {
 
	SectionValuesCont sectionValues;
 

	
 
	std::string sectionSearchString = sectionName + ".";
 
	BOOST_FOREACH (const Variables::value_type & varItem, m_variables) {
 
		if (boost::istarts_with(varItem.first, sectionSearchString))
 
			sectionValues[varItem.first] = varItem.second;
 
	}
 

	
 
	BOOST_FOREACH (const UnregisteredCont::value_type & varItem, m_unregistered) {
 
		if (boost::istarts_with(varItem.first, sectionSearchString))
 
			sectionValues[varItem.first] = varItem.second;
 
	}
 

	
 
	return sectionValues;
 
}
 

	
 
std::string Config::getCommandLineArgs() const {
 
	std::ostringstream commandLineArgs;
 

	
 
	// Return the command-line arguments that were passed to us originally (but remove the initial .exe part)
 
	for (int i = 1; i < m_argc; ++i) 	{
 
		commandLineArgs << "\"" << m_argv[i] << "\" ";
 
	}
 

	
 
	return commandLineArgs.str();
 
}
 

	
 
}
0 comments (0 inline, 0 general)