Changeset - fd4946efe48c
[Not reviewed]
0 5 0
HanzZ - 13 years ago 2013-02-11 21:24:19
hanzz.k@gmail.com
Libcommuni: Do not enable JID escaping for IRC
5 files changed with 28 insertions and 4 deletions:
0 comments (0 inline, 0 general)
backends/libcommuni/ircnetworkplugin.cpp
Show inline comments
 
@@ -44,30 +44,31 @@ void IRCNetworkPlugin::tryNextServer() {
 
	}
 
}
 

	
 
void IRCNetworkPlugin::readData() {
 
	size_t availableBytes = m_socket->bytesAvailable();
 
	if (availableBytes == 0)
 
		return;
 

	
 
	if (m_firstPing) {
 
		m_firstPing = false;
 
		// Users can join the network without registering if we allow
 
		// one user to connect multiple IRC networks.
 
		NetworkPlugin::PluginConfig cfg;
 
		if (m_servers.empty()) {
 
			NetworkPlugin::PluginConfig cfg;
 
			cfg.setNeedRegistration(false);
 
			cfg.setSupportMUC(true);
 
			sendConfig(cfg);
 
		}
 
		cfg.setSupportMUC(true);
 
		cfg.disableJIDEscaping();
 
		sendConfig(cfg);
 
	}
 

	
 
	std::string d = std::string(m_socket->readAll().data(), availableBytes);
 
	handleDataRead(d);
 
}
 

	
 
void IRCNetworkPlugin::sendData(const std::string &string) {
 
	m_socket->write(string.c_str(), string.size());
 
}
 

	
 
MyIrcSession *IRCNetworkPlugin::createSession(const std::string &user, const std::string &hostname, const std::string &nickname, const std::string &password, const std::string &suffix) {
 
	MyIrcSession *session = new MyIrcSession(user, this, suffix);
include/transport/networkplugin.h
Show inline comments
 
@@ -30,38 +30,41 @@ namespace Transport {
 

	
 
/// Represents Spectrum2 legacy network plugin.
 

	
 
/// This class is base class for all C++ legacy network plugins. It provides a way to connect 
 
/// Spectrum2 NetworkPluginServer and allows to use high-level API for legacy network plugins
 
/// development.
 
class NetworkPlugin {
 
	public:
 
		enum ExitCode { StorageBackendNeeded = -2 };
 

	
 
		class PluginConfig {
 
			public:
 
				PluginConfig() : m_needPassword(true), m_needRegistration(false), m_supportMUC(false), m_rawXML(false) {}
 
				PluginConfig() : m_needPassword(true), m_needRegistration(false), m_supportMUC(false), m_rawXML(false),
 
				m_disableJIDEscaping(false) {}
 
				virtual ~PluginConfig() {}
 

	
 
				void setNeedRegistration(bool needRegistration = false) { m_needRegistration = needRegistration; }
 
				void setNeedPassword(bool needPassword = true) { m_needPassword = needPassword; }
 
				void setSupportMUC(bool supportMUC = true) { m_supportMUC = supportMUC; }
 
				void setExtraFields(const std::vector<std::string> &fields) { m_extraFields = fields; }
 
				void setRawXML(bool rawXML = false) { m_rawXML = rawXML; }
 
				void disableJIDEscaping() { m_disableJIDEscaping = true; }
 

	
 
			private:
 
				bool m_needPassword;
 
				bool m_needRegistration;
 
				bool m_supportMUC;
 
				bool m_rawXML;
 
				bool m_disableJIDEscaping;
 
				std::vector<std::string> m_extraFields;
 

	
 
				friend class NetworkPlugin;
 
		};
 

	
 
		/// Creates new NetworkPlugin and connects the Spectrum2 NetworkPluginServer.
 
		/// \param loop Event loop.
 
		/// \param host Host where Spectrum2 NetworkPluginServer runs.
 
		/// \param port Port.
 
		NetworkPlugin();
 

	
 
		/// Destructor.
plugin/cpp/networkplugin.cpp
Show inline comments
 
@@ -65,24 +65,26 @@ NetworkPlugin::~NetworkPlugin() {
 
void NetworkPlugin::sendConfig(const PluginConfig &cfg) {
 
	std::string data = "[registration]\n";
 
	data += std::string("needPassword=") + (cfg.m_needPassword ? "1" : "0") + "\n";
 
	data += std::string("needRegistration=") + (cfg.m_needRegistration ? "1" : "0") + "\n";
 

	
 
	for (std::vector<std::string>::const_iterator it = cfg.m_extraFields.begin(); it != cfg.m_extraFields.end(); it++) {
 
		data += std::string("extraField=") + (*it) + "\n";
 
	}
 

	
 
	data += "[features]\n";
 
	data += std::string("muc=") + (cfg.m_supportMUC ? "1" : "0") + "\n";
 
	data += std::string("rawxml=") + (cfg.m_rawXML ? "1" : "0") + "\n";
 
	data += std::string("disable_jid_escaping=") + (cfg.m_disableJIDEscaping ? "1" : "0") + "\n";
 
	
 

	
 
	pbnetwork::BackendConfig m;
 
	m.set_config(data);
 

	
 
	std::string message;
 
	m.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_BACKEND_CONFIG);
 

	
 
	send(message);
 
}
 

	
src/config.cpp
Show inline comments
 
@@ -307,33 +307,40 @@ std::string Config::getCommandLineArgs() const {
 
	return commandLineArgs.str();
 
}
 

	
 
void Config::updateBackendConfig(const std::string &backendConfig) {
 
	options_description opts("Backend options");
 
	opts.add_options()
 
		("registration.needPassword", value<bool>()->default_value(true), "")
 
		("registration.needRegistration", value<bool>()->default_value(false), "")
 
		("registration.extraField", value<std::vector<std::string> >()->multitoken(), "")
 
		("features.receipts", value<bool>()->default_value(false), "")
 
		("features.muc", value<bool>()->default_value(false), "")
 
		("features.rawxml", value<bool>()->default_value(false), "")
 
		("features.disable_jid_escaping", value<bool>()->default_value(false), "")
 
	;
 

	
 
	std::stringstream ifs(backendConfig);
 
	parsed_options parsed = parse_config_file(ifs, opts, true);
 

	
 
	store(parsed, m_backendConfig);
 
	notify(m_backendConfig);
 

	
 
	onBackendConfigUpdated();
 

	
 
	if (CONFIG_BOOL_DEFAULTED(this, "features.disable_jid_escaping", false)) {
 
		Variables::iterator it(m_variables.find("service.jid_escaping"));
 
		boost::program_options::variable_value& vx(it->second);
 
		vx.value() = false;
 
	}
 
}
 

	
 
Config *Config::createFromArgs(int argc, char **argv, std::string &error, std::string &host, int &port) {
 
	std::string jid;
 
	std::ostringstream os;
 
	std::string configFile;
 
	boost::program_options::variables_map vm;
 
	boost::program_options::options_description desc("Usage: spectrum <config_file.cfg>\nAllowed options");
 
	desc.add_options()
 
		("help", "help")
 
		("host,h", boost::program_options::value<std::string>(&host)->default_value(""), "Host to connect to")
 
		("port,p", boost::program_options::value<int>(&port)->default_value(10000), "Port to connect to")
src/tests/config.cpp
Show inline comments
 
@@ -17,24 +17,25 @@
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
#include "transport/util.h"
 

	
 
using namespace Transport;
 

	
 
class ConfigTest : public CPPUNIT_NS :: TestFixture{
 
	CPPUNIT_TEST_SUITE(ConfigTest);
 
	CPPUNIT_TEST(setStringTwice);
 
	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) {
 

	
 
@@ -48,24 +49,34 @@ class ConfigTest : public CPPUNIT_NS :: TestFixture{
 
		CPPUNIT_ASSERT_EQUAL(std::string("localhost"), CONFIG_STRING(&cfg, "service.jids"));
 
	}
 

	
 
	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");
 
		cfg.load(ifs);
 
		CPPUNIT_ASSERT_EQUAL(true, CONFIG_BOOL(&cfg, "service.jid_escaping"));
 

	
 
		cfg.updateBackendConfig("[features]\ndisable_jid_escaping=1\n");
 
		CPPUNIT_ASSERT_EQUAL(false, CONFIG_BOOL(&cfg, "service.jid_escaping"));
 
	}
 

	
 
	void unregisteredList() {
 
		Config cfg;
 
		std::istringstream ifs("service.irc_server = irc.freenode.org\nservice.irc_server=localhost\n");
 
		cfg.load(ifs);
 
		CPPUNIT_ASSERT_EQUAL(2, (int) CONFIG_LIST(&cfg, "service.irc_server").size());
 
	}
 

	
 
	void unregisteredString() {
 
		Config cfg;
 
		std::istringstream ifs("service.irc_server = irc.freenode.org");
 
		cfg.load(ifs);
 
		CPPUNIT_ASSERT_EQUAL(std::string("irc.freenode.org"), CONFIG_STRING(&cfg, "service.irc_server"));
0 comments (0 inline, 0 general)