Changeset - 68527d73e2b8
[Not reviewed]
0 5 0
Jan Kaluza - 10 years ago 2016-02-24 17:06:10
jkaluza@redhat.com
Libtransport: Allow unregistered boolean variables in Config
5 files changed with 24 insertions and 4 deletions:
0 comments (0 inline, 0 general)
libtransport/Config.cpp
Show inline comments
 
@@ -210,25 +210,33 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
	}
 
	if (!found_database) {
 
		std::vector<std::string> value;
 
		value.push_back("/var/lib/spectrum2/$jid/database.sql");
 
		parsed.options.push_back(boost::program_options::basic_option<char>("database.database", value));
 
	}
 

	
 
	std::list<std::string> has_key;
 
	BOOST_FOREACH(option &opt, parsed.options) {
 
		if (opt.unregistered) {
 
			if (std::find(has_key.begin(), has_key.end(), opt.string_key) == has_key.end()) {
 
				has_key.push_back(opt.string_key);
 
				m_unregistered[opt.string_key] = variable_value(opt.value[0], false);
 
				if (opt.value[0] == "true" || opt.value[0] == "1") {
 
					m_unregistered[opt.string_key] = variable_value(true, false);
 
				}
 
				else if (opt.value[0] == "true" || opt.value[0] == "1") {
 
					m_unregistered[opt.string_key] = variable_value(false, false);
 
				}
 
				else {
 
					m_unregistered[opt.string_key] = variable_value(opt.value[0], false);
 
				}
 
			}
 
			else {
 
				std::list<std::string> list;
 
				try {
 
					list = m_unregistered[opt.string_key].as<std::list<std::string> >();
 
				}
 
				catch(...) {
 
					list.push_back(m_unregistered[opt.string_key].as<std::string>());
 
				}
 
				
 
				list.push_back(opt.value[0]);
 
				m_unregistered[opt.string_key] = variable_value(list, false);
spectrum/src/frontends/xmpp/adhocmanager.cpp
Show inline comments
 
@@ -64,24 +64,27 @@ void AdHocManager::stop() {
 
		for (CommandsMap::iterator ct = it->second.begin(); ct != it->second.end(); ct++) {
 
			delete ct->second;
 
		}
 
	}
 

	
 
	m_sessions.clear();
 
}
 

	
 
void AdHocManager::handleUserCreated(User *user) {
 
	for (std::map<std::string, AdHocCommandFactory *>::const_iterator it = m_factories.begin(); it != m_factories.end(); it++) {
 
		for (std::map<std::string, std::string>::const_iterator it2 = it->second->getUserSettings().begin(); it2 != it->second->getUserSettings().end(); it2++) {
 
			std::string value = CONFIG_STRING_DEFAULTED(m_component->getConfig(), it->second->getNode() + "." + it2->first, it2->second);
 
			if (it2->second == "true" || it2->second == "1" || it2->second == "false" || it2->second == "0") {
 
				value = CONFIG_BOOL_DEFAULTED(m_component->getConfig(), it->second->getNode() + "." + it2->first, it2->second == "true" || it2->second == "1") ? "1" : "0";
 
			}
 
			if (m_storageBackend) {
 
				int type = (int) TYPE_BOOLEAN;
 
				m_storageBackend->getUserSetting(user->getUserInfo().id, it2->first, type, value);
 
			}
 
			user->addUserSetting(it2->first, value);
 
		}
 
	}
 
}
 

	
 
void AdHocManager::addAdHocCommand(AdHocCommandFactory *factory) {
 
	if (m_factories.find(factory->getNode()) != m_factories.end()) {
 
		LOG4CXX_ERROR(logger, "Command with node " << factory->getNode() << " is already registered. Ignoring this attempt.");
spectrum/src/frontends/xmpp/settingsadhoccommand.cpp
Show inline comments
 
@@ -58,29 +58,29 @@ boost::shared_ptr<Swift::Command> SettingsAdHocCommand::getForm() {
 
	}
 

	
 
	boost::shared_ptr<Swift::Command> response(new Swift::Command("settings", m_id, Swift::Command::Executing));
 
	boost::shared_ptr<Swift::Form> form(new Swift::Form());
 

	
 
	std::string value;
 
	int type = (int) TYPE_BOOLEAN;
 

	
 
	value = "1";
 
	m_storageBackend->getUserSetting(user.id, "enable_transport", type, value);
 
	FormUtils::addBooleanField(form, "enable_transport", value, "Enable transport");
 

	
 
	value = CONFIG_STRING_DEFAULTED(m_component->getConfig(), "settings.send_headlines", "0");
 
	value = CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "settings.send_headlines", false) ? "1" : "0";
 
	m_storageBackend->getUserSetting(user.id, "send_headlines", type, value);
 
	FormUtils::addBooleanField(form, "send_headlines", value, "Allow sending messages as headlines");
 

	
 
	value = CONFIG_STRING_DEFAULTED(m_component->getConfig(), "settings.stay_connected", "0");
 
	value = CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "settings.stay_connected", false) ? "1" : "0";
 
	m_storageBackend->getUserSetting(user.id, "stay_connected", type, value);
 
	FormUtils::addBooleanField(form, "stay_connected", value, "Stay connected to legacy network when offline on XMPP");
 

	
 
	response->setForm(form);
 
	return response;
 
}
 

	
 
void SettingsAdHocCommand::updateUserSetting(Swift::Form::ref form, UserInfo &user, const std::string &name) {
 
	std::string value = FormUtils::fieldValue(form, name, "");
 
	if (value.empty()) {
 
		return;
 
	}
tests/libtransport/config.cpp
Show inline comments
 
@@ -7,48 +7,57 @@
 
#include <Swiften/Network/DummyConnectionServer.h>
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 

	
 
using namespace Transport;
 

	
 
class ConfigTest : public CPPUNIT_NS :: TestFixture{
 
	CPPUNIT_TEST_SUITE(ConfigTest);
 
	CPPUNIT_TEST(setStringTwice);
 
	CPPUNIT_TEST(setUnknownBool);
 
	CPPUNIT_TEST(updateBackendConfig);
 
	CPPUNIT_TEST(updateBackendConfigJIDEscaping);
 
	CPPUNIT_TEST(unregisteredList);
 
	CPPUNIT_TEST(unregisteredString);
 
	CPPUNIT_TEST(unregisteredListAsString);
 
	CPPUNIT_TEST(unregisteredStringAsList);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
		void setUp (void) {
 
		}
 

	
 
		void tearDown (void) {
 

	
 
		}
 

	
 
	void setStringTwice() {
 
		char *argv[3] = {"binary", "--service.jids=localhost", NULL};
 
		Config cfg(2, argv);
 
		std::istringstream ifs("service.jids = irc.freenode.org\n");
 
		cfg.load(ifs);
 
		CPPUNIT_ASSERT_EQUAL(std::string("localhost"), CONFIG_STRING(&cfg, "service.jids"));
 
	}
 

	
 
	void setUnknownBool() {
 
		char *argv[3] = {"binary", "--service.jids=localhost", NULL};
 
		Config cfg(2, argv);
 
		std::istringstream ifs("service.irc_send_pass = 1\n");
 
		cfg.load(ifs);
 
		CPPUNIT_ASSERT_EQUAL(true, CONFIG_BOOL_DEFAULTED(&cfg, "service.irc_send_pass", false));
 
	}
 

	
 
	void updateBackendConfig() {
 
		Config cfg;
 
		CPPUNIT_ASSERT(!cfg.hasKey("registration.needPassword"));
 

	
 
		cfg.updateBackendConfig("[registration]\nneedPassword=0\n");
 
		CPPUNIT_ASSERT(cfg.hasKey("registration.needPassword"));
 
		CPPUNIT_ASSERT_EQUAL(false, CONFIG_BOOL(&cfg, "registration.needPassword"));
 
	}
 

	
 
	void updateBackendConfigJIDEscaping() {
 
		Config cfg;
 
		std::istringstream ifs("service.jids = irc.freenode.org\n");
tests/tests_output/localhost/vcard/client.dat
Show inline comments
 
@@ -11,18 +11,18 @@ return {
 
			[1] = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAAAAAAKSURBVHicY2AAAAACAAEAAAAASUVORA==";
 
			["attr"] = {
 
				["xmlns"] = "vcard-temp";
 
			};
 
			["name"] = "BINVAL";
 
		};
 
		["name"] = "PHOTO";
 
		["attr"] = {
 
			["xmlns"] = "vcard-temp";
 
		};
 
	};
 
	["attr"] = {
 
		["prodid"] = "-//HandGen//NONSGML vGen v1.0//EN";
 
		["version"] = "2.0";
 
		["prodid"] = "-//HandGen//NONSGML vGen v1.0//EN";
 
		["xmlns"] = "vcard-temp";
 
	};
 
	["name"] = "vCard";
 
};
0 comments (0 inline, 0 general)