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
 
@@ -57,13 +57,13 @@ void SchannelServerContext::connect()
 
	// If a user name is specified, then attempt to find a client
 
	// certificate. Otherwise, just create a NULL credential.
 
	if (!m_cert_name.empty())
 
	{
 
		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() );
 
				indicateError();
 
				return;
 
			}
include/transport/config.h
Show inline comments
 
@@ -32,12 +32,15 @@
 
#define CONFIG_STRING(PTR, KEY) (*PTR)[KEY].as<std::string>()
 
#define CONFIG_INT(PTR, KEY) (*PTR)[KEY].as<int>()
 
#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).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 {
 

	
 
/// Represents variable:value pairs.
 
typedef boost::program_options::variables_map Variables;
 

	
 
@@ -46,12 +49,15 @@ typedef boost::program_options::variables_map Variables;
 
/// It's used to load config file and allows others parts of libtransport to be configured
 
/// properly. Config files are text files which use "ini" format. Variables are divided into multiple
 
/// sections. Every class is configurable with some variables which change its behavior. Check particular
 
/// 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) {}
 

	
 
		/// Destructor
 
		virtual ~Config() {}
 

	
 
@@ -88,12 +94,16 @@ class Config {
 
			if (m_variables.find(key) != m_variables.end()) {
 
				return m_variables[key];
 
			}
 
			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; }
 

	
 
		/// This signal is emitted when config is loaded/reloaded.
 
		boost::signal<void ()> onConfigReloaded;
 
	
src/config.cpp
Show inline comments
 
@@ -28,12 +28,13 @@
 
#define PATH_MAX MAX_PATH
 
#endif
 
#endif
 

	
 
#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
 

	
 
using namespace boost::program_options;
 

	
 
@@ -246,7 +247,35 @@ bool Config::reload() {
 
		return false;
 
	}
 

	
 
	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)