Changeset - 47f86754eae6
[Not reviewed]
0 4 0
HanzZ - 13 years ago 2012-04-17 18:26:21
hanzz.k@gmail.com
Allow setting config file options also from command line
4 files changed with 12 insertions and 5 deletions:
0 comments (0 inline, 0 general)
include/transport/config.h
Show inline comments
 
@@ -47,13 +47,13 @@ typedef boost::program_options::variables_map Variables;
 
/// 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:
 
		/// Constructor.
 
		Config() {}
 
		Config(int argc = 0, char **argv = NULL) : m_argc(argc), m_argv(argv) {}
 

	
 
		/// Destructor
 
		virtual ~Config() {}
 

	
 
		/// Loads data from config file.
 
		
 
@@ -96,12 +96,14 @@ class Config {
 
		}
 

	
 
		/// This signal is emitted when config is loaded/reloaded.
 
		boost::signal<void ()> onConfigReloaded;
 
	
 
	private:
 
		int m_argc;
 
		char **m_argv;
 
		Variables m_variables;
 
		std::map<std::string, std::string> m_unregistered;
 
		std::string m_file;
 
};
 

	
 
}
spectrum/src/main.cpp
Show inline comments
 
@@ -111,13 +111,13 @@ static void daemonize(const char *cwd, const char *lock_file) {
 
}
 

	
 
#endif
 

	
 
int main(int argc, char **argv)
 
{
 
	Config config;
 
	Config config(argc, argv);
 

	
 
	boost::program_options::variables_map vm;
 
	bool no_daemon = false;
 
	std::string config_file;
 
	std::string jid;
 
	
spectrum/src/sample.cfg
Show inline comments
 
@@ -5,19 +5,19 @@ server = 127.0.0.1
 
port = 5222
 
server_mode = 1
 
backend_host=localhost
 
pidfile=./test.pid
 
# < this option doesn't work yet
 
#backend_port=10001
 
admin_jid=admin@localhost
 
#admin_jid=admin@localhost
 
admin_password=test
 
#cert=server.pfx #patch to PKCS#12 certificate
 
#cert_password=test #password to that certificate if any
 
users_per_backend=10
 
#backend=../..//backends/libpurple/spectrum2_libpurple_backend
 
backend=../../backends/template/template_backend.py
 
backend=../..//backends/libpurple/spectrum2_libpurple_backend
 
#backend=../../backends/template/template_backend.py
 
protocol=prpl-jabber
 
#protocol=prpl-msn
 
#protocol=any
 
#protocol=prpl-icq
 
working_dir=./
 

	
src/config.cpp
Show inline comments
 
@@ -184,12 +184,17 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		}
 
		else if (opt.value[0].find("$jid") != std::string::npos) {
 
			boost::replace_all(opt.value[0], "$jid", jid);
 
		}
 
	}
 

	
 
	// Load configs passed by command line
 
	if (m_argc != 0 && m_argv) {
 
		store(parse_command_line(m_argc, m_argv, opts), m_variables);
 
	}
 

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

	
 
	onConfigReloaded();
 

	
 
	return true;
0 comments (0 inline, 0 general)