Changeset - 347ed2861846
[Not reviewed]
0 2 0
HanzZ - 14 years ago 2011-10-28 08:55:47
hanzz.k@gmail.com
Working variable
2 files changed with 31 insertions and 2 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -66,12 +66,26 @@ static void transportDataReceived(gpointer data, gint source, PurpleInputConditi
 

	
 
class SpectrumNetworkPlugin;
 

	
 
GKeyFile *keyfile;
 
SpectrumNetworkPlugin *np;
 

	
 
std::string replaceAll(
 
  std::string result,
 
  const std::string& replaceWhat,
 
  const std::string& replaceWithWhat)
 
{
 
  while(1)
 
  {
 
	const int pos = result.find(replaceWhat);
 
	if (pos==-1) break;
 
	result.replace(pos,replaceWhat.size(),replaceWithWhat);
 
  }
 
  return result;
 
}
 

	
 
static std::string KEYFILE_STRING(const std::string &cat, const std::string &key, const std::string &def = "") {
 
	gchar *str = g_key_file_get_string(keyfile, cat.c_str(), key.c_str(), 0);
 
	if (!str) {
 
		return def;
 
	}
 
	std::string ret(str);
 
@@ -80,12 +94,17 @@ static std::string KEYFILE_STRING(const std::string &cat, const std::string &key
 
	if (ret.find("#") != std::string::npos) {
 
		ret = ret.substr(0, ret.find("#"));
 
		while(*(ret.end() - 1) == ' ') {
 
			ret.erase(ret.end() - 1);
 
		}
 
	}
 

	
 
	if (ret.find("$jid") != std::string::npos) {
 
		std::string jid = KEYFILE_STRING("service", "jid");
 
		ret = replaceAll(ret, "$jid", jid);
 
	}
 
	return ret;
 
}
 

	
 
#define KEYFILE_BOOL(CAT, KEY) g_key_file_get_boolean(keyfile, CAT, KEY, 0)
 

	
 
static gboolean nodaemon = FALSE;
src/config.cpp
Show inline comments
 
@@ -57,14 +57,14 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		("service.password", value<std::string>()->default_value(""), "Password used to auth the server")
 
		("service.port", value<int>()->default_value(0), "Port the server is listening on")
 
		("service.user", value<std::string>()->default_value(""), "The name of user Spectrum runs as.")
 
		("service.group", value<std::string>()->default_value(""), "The name of group Spectrum runs as.")
 
		("service.backend", value<std::string>()->default_value("libpurple_backend"), "Backend")
 
		("service.protocol", value<std::string>()->default_value(""), "Protocol")
 
		("service.pidfile", value<std::string>()->default_value("/var/run/spectrum2/spectrum2.pid"), "Full path to pid file")
 
		("service.working_dir", value<std::string>()->default_value("/var/lib/spectrum2"), "Working dir")
 
		("service.pidfile", value<std::string>()->default_value("/var/run/spectrum2/$jid.pid"), "Full path to pid file")
 
		("service.working_dir", value<std::string>()->default_value("/var/lib/spectrum2/$jid"), "Working dir")
 
		("service.allowed_servers", value<std::string>()->default_value(""), "Only users from these servers can connect")
 
		("service.server_mode", value<bool>()->default_value(false), "True if Spectrum should behave as server")
 
		("service.users_per_backend", value<int>()->default_value(100), "Number of users per one legacy network backend")
 
		("service.backend_host", value<std::string>()->default_value("localhost"), "Host to bind backend server to")
 
		("service.backend_port", value<std::string>()->default_value("10000"), "Port to bind backend server to")
 
		("service.cert", value<std::string>()->default_value(""), "PKCS#12 Certificate.")
 
@@ -98,16 +98,26 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		("backend.avatars_directory", value<std::string>()->default_value(""), "Path to directory with avatars")
 
		("backend.no_vcard_fetch", value<bool>()->default_value(false), "True if VCards for buddies should not be fetched. Only avatars will be forwarded.")
 
	;
 

	
 
	parsed_options parsed = parse_config_file(ifs, opts, true);
 

	
 
	std::string jid = "";
 
	BOOST_FOREACH(option opt, parsed.options) {
 
		if (opt.string_key == "service.jid") {
 
			jid = opt.value[0];
 
		}
 
	}
 

	
 
	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();
0 comments (0 inline, 0 general)