Changeset - 17f3dabe1419
[Not reviewed]
0 5 0
Jan Kaluza - 10 years ago 2016-02-06 07:57:48
jkaluza@redhat.com
Libtransport: Fix and enable rawXML tests
5 files changed with 6 insertions and 9 deletions:
0 comments (0 inline, 0 general)
include/transport/Frontend.h
Show inline comments
 
@@ -75,36 +75,38 @@ class Frontend {
 
		virtual void sendRosterRequest(Swift::RosterPayload::ref, Swift::JID to) = 0;
 

	
 
		virtual void sendMessage(boost::shared_ptr<Swift::Message> message) = 0;
 

	
 
		virtual void sendIQ(boost::shared_ptr<Swift::IQ>) = 0;
 

	
 
		virtual boost::shared_ptr<Swift::DiscoInfo> sendCapabilitiesRequest(Swift::JID to) = 0;
 

	
 
		virtual void reconnectUser(const std::string &user) = 0;
 

	
 
		virtual RosterManager *createRosterManager(User *user, Component *component) = 0;
 

	
 
		virtual User *createUser(const Swift::JID &jid, UserInfo &userInfo, Component *component, UserManager *userManager) = 0;
 

	
 
		virtual UserManager *createUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend = NULL) = 0;
 

	
 
		virtual void clearRoomList() = 0;
 
		virtual void addRoomToRoomList(const std::string &handle, const std::string &name) = 0;
 

	
 
		virtual std::string setOAuth2Code(const std::string &code, const std::string &state) { return "OAuth2 code is not needed for this frontend."; }
 
		virtual std::string getOAuth2URL(const std::vector<std::string> &args) { return ""; }
 
		virtual std::string getRegistrationFields() { return "Jabber ID\n3rd-party network username\n3rd-party network password"; }
 
		virtual bool handleAdminMessage(Swift::Message::ref /*message*/) { return false; }
 

	
 
		virtual bool isRawXMLEnabled() { return false; }
 

	
 
		boost::signal<void (User *, const std::string &name, unsigned int id)> onVCardRequired;
 
		boost::signal<void (User *, boost::shared_ptr<Swift::VCard> vcard)> onVCardUpdated;
 
		boost::signal<void (Buddy *, const Swift::RosterItemPayload &item)> onBuddyUpdated;
 
		boost::signal<void (Buddy *)> onBuddyRemoved;
 
		boost::signal<void (Buddy *, const Swift::RosterItemPayload &item)> onBuddyAdded;
 
		boost::signal<void (Swift::Message::ref message)> onMessageReceived;
 
		boost::signal<void (bool /* isAvailable */)> onAvailableChanged;
 
		boost::signal<void (boost::shared_ptr<Swift::Presence>) > onPresenceReceived;
 
		boost::signal<void (const Swift::JID& jid, boost::shared_ptr<Swift::DiscoInfo> info)> onCapabilitiesReceived;
 
};
 

	
 
}
include/transport/Transport.h
Show inline comments
 
@@ -80,73 +80,68 @@ namespace Transport {
 
			Swift::JID &getJID() { return m_jid; }
 

	
 
			/// Returns Swift::NetworkFactories which can be used to create new connections.
 

	
 
			/// \return Swift::NetworkFactories which can be used to create new connections.
 
			Swift::NetworkFactories *getNetworkFactories() { return m_factories; }
 

	
 
			/// Returns Transport Factory used to create basic Transport components.
 

	
 
			/// \return Transport Factory used to create basic Transport components.
 
			Factory *getFactory() { return m_factory; }
 

	
 
			/// This signal is emitted when server disconnects the transport because of some error.
 

	
 
			/// \param error disconnection error
 
			boost::signal<void (const std::string &error)> onConnectionError;
 

	
 
			/// This signal is emitted when transport successfully connects the server.
 
			boost::signal<void ()> onConnected;
 

	
 
			/// This signal is emitted when XML stanza is sent to server.
 

	
 
			Config *getConfig() { return m_config; }
 

	
 
			bool isRawXMLEnabled() {
 
				return m_rawXML;
 
			}
 

	
 
			/// It's emitted only for presences addressed to transport itself
 
			/// (for example to="j2j.domain.tld") and for presences comming to
 
			/// MUC (for example to="#chat%irc.freenode.org@irc.domain.tld")
 
			/// \param presence Presence.
 
			boost::signal<void (Swift::Presence::ref presence)> onUserPresenceReceived;
 

	
 
			boost::signal<void (boost::shared_ptr<Swift::IQ>)> onRawIQReceived;
 
			
 
			void handlePresence(Swift::Presence::ref presence);
 
			void handleConnected();
 
			void handleConnectionError(const std::string &error);
 
			void handleDataRead(const std::string &data);
 
			void handleDataWritten(const std::string &data);
 

	
 
			Frontend *getFrontend() {
 
				return m_frontend;
 
			}
 

	
 
			PresenceOracle *getPresenceOracle();
 

	
 
		private:
 
			void handleDiscoInfoResponse(boost::shared_ptr<Swift::DiscoInfo> info, Swift::ErrorPayload::ref error, const Swift::JID& jid);
 
			void handleCapsChanged(const Swift::JID& jid);
 

	
 
			void handleBackendConfigChanged();
 

	
 
			Swift::NetworkFactories *m_factories;
 
			Swift::Timer::ref m_reconnectTimer;
 
			PresenceOracle *m_presenceOracle;
 
			
 
			Transport::UserRegistry *m_userRegistry;
 
			StorageBackend *m_storageBackend;
 
			int m_reconnectCount;
 
			Config* m_config;
 
			Swift::JID m_jid;
 
			Factory *m_factory;
 
			Swift::EventLoop *m_loop;
 
			bool m_rawXML;
 
			Frontend *m_frontend;
 

	
 
		friend class User;
 
		friend class UserRegistration;
 
		friend class NetworkPluginServer;
 
	};
 
}
libtransport/LocalBuddy.cpp
Show inline comments
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/LocalBuddy.h"
 
#include "transport/User.h"
 
#include "transport/RosterManager.h"
 
#include "transport/Transport.h"
 
#include "transport/Frontend.h"
 

	
 
namespace Transport {
 

	
 
LocalBuddy::LocalBuddy(RosterManager *rosterManager, long id, const std::string &name, const std::string &alias, const std::vector<std::string> &groups, BuddyFlag flags) : Buddy(rosterManager, id, flags) {
 
	m_status = Swift::StatusShow::None;
 
	m_alias = alias;
 
	m_name = name;
 
	m_groups = groups;
 
	try {
 
		generateJID();
 
	} catch (...) {
 
	}
 
}
 

	
 
LocalBuddy::~LocalBuddy() {
 
}
 

	
 
void LocalBuddy::setStatus(const Swift::StatusShow &status, const std::string &statusMessage) {
 
	bool changed = ((m_status.getType() != status.getType()) || (m_statusMessage != statusMessage));
 
	if (changed) {
 
		m_status = status;
 
		m_statusMessage = statusMessage;
 
		sendPresence();
 
	}
 
@@ -80,33 +81,33 @@ void LocalBuddy::setAlias(const std::string &alias) {
 
		getRosterManager()->doUpdateBuddy(this);
 
		getRosterManager()->storeBuddy(this);
 
	}
 
}
 

	
 
void LocalBuddy::setGroups(const std::vector<std::string> &groups) {
 
	bool changed = m_groups.size() != groups.size();
 
	if (!changed) {
 
		for (int i = 0; i != m_groups.size(); i++) {
 
			if (m_groups[i] != groups[i]) {
 
				changed = true;
 
				break;
 
			}
 
		}
 
	}
 

	
 
	m_groups = groups;
 
	if (changed) {
 
		getRosterManager()->doUpdateBuddy(this);
 
		getRosterManager()->storeBuddy(this);
 
	}
 
}
 

	
 
bool LocalBuddy::getStatus(Swift::StatusShow &status, std::string &statusMessage) {
 
	if (getRosterManager()->getUser()->getComponent()->isRawXMLEnabled()) {
 
	if (getRosterManager()->getUser()->getComponent()->getFrontend()->isRawXMLEnabled()) {
 
		return false;
 
	}
 
	status = m_status;
 
	statusMessage = m_statusMessage;
 
	return true;
 
}
 

	
 
}
libtransport/Transport.cpp
Show inline comments
 
@@ -22,49 +22,48 @@
 
#include "transport/Transport.h"
 
#include "transport/Logging.h"
 
#include "transport/Frontend.h"
 
#include "transport/PresenceOracle.h"
 
#include "transport/Config.h"
 

	
 
#include <boost/bind.hpp>
 
#include <boost/algorithm/string/predicate.hpp>
 

	
 
using namespace Swift;
 

	
 
namespace Transport {
 
	
 
DEFINE_LOGGER(logger, "Component");
 
DEFINE_LOGGER(logger_xml, "Component.RAW");
 

	
 
Component::Component(Frontend *frontend, Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry) {
 
	m_frontend = frontend;
 
	m_userRegistry = NULL;
 
	m_reconnectCount = 0;
 
	m_config = config;
 
	m_factory = factory;
 
	m_loop = loop;
 
	m_userRegistry = userRegistry;
 
	m_rawXML = false;
 
	m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid"));
 

	
 
	m_factories = factories;
 

	
 
	m_reconnectTimer = m_factories->getTimerFactory()->createTimer(3000);
 
	m_reconnectTimer->onTick.connect(boost::bind(&Component::start, this)); 
 

	
 
	m_presenceOracle = new Transport::PresenceOracle(frontend);
 
	m_presenceOracle->onPresenceChange.connect(boost::bind(&Component::handlePresence, this, _1));
 

	
 
	m_frontend->init(this, loop, factories, config, userRegistry);
 
}
 

	
 
Component::~Component() {
 
	delete m_presenceOracle;
 
}
 

	
 
Transport::PresenceOracle *Component::getPresenceOracle() {
 
	return m_presenceOracle;
 
}
 

	
 
bool Component::inServerMode() {
 
	 return CONFIG_BOOL_DEFAULTED(m_config, "service.server_mode", false);
 
}
tests/libtransport/networkpluginserver.cpp
Show inline comments
 
@@ -21,50 +21,50 @@ class Clock {
 
	public:
 
		double m_beginTime;
 
		double m_elapsedTime;
 

	
 
		void start() {
 
			m_beginTime = clock();
 
		}
 

	
 
		void end() {
 
			m_elapsedTime = double(clock() - m_beginTime) / CLOCKS_PER_SEC;
 
		}
 

	
 
		double elapsedTime() const {
 
			return m_elapsedTime;
 
		}
 
};
 

	
 
class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(NetworkPluginServerTest);
 
	CPPUNIT_TEST(handleBuddyChangedPayload);
 
	CPPUNIT_TEST(handleBuddyChangedPayloadNoEscaping);
 
	CPPUNIT_TEST(handleBuddyChangedPayloadUserContactInRoster);
 
	CPPUNIT_TEST(handleMessageHeadline);
 
	CPPUNIT_TEST(handleConvMessageAckPayload);
 
// 	CPPUNIT_TEST(handleRawXML);
 
// 	CPPUNIT_TEST(handleRawXMLSplit);
 
	CPPUNIT_TEST(handleRawXML);
 
	CPPUNIT_TEST(handleRawXMLSplit);
 

	
 
	CPPUNIT_TEST(benchmarkHandleBuddyChangedPayload);
 
	CPPUNIT_TEST(benchmarkSendUnavailablePresence);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
		NetworkPluginServer *serv;
 

	
 
		void setUp (void) {
 
			setMeUp();
 

	
 
			serv = new NetworkPluginServer(component, cfg, userManager, NULL);
 
			connectUser();
 
			received.clear();
 
		}
 

	
 
		void tearDown (void) {
 
			received.clear();
 
			disconnectUser();
 
			delete serv;
 
			tearMeDown();
 
		}
 

	
 
		void handleConvMessageAckPayload() {
0 comments (0 inline, 0 general)