Changeset - 0d99e8c85d38
[Not reviewed]
! ! !
Vitaly Takmazov - 10 years ago 2015-03-31 13:14:15
vitalyster@gmail.com
Initial swiften 3 support
65 files changed with 306 insertions and 1114 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -68,25 +68,24 @@ if(NOT SWIFTEN_FOUND)
 
	if (LIBXML_LIBRARY)
 
		set(SWIFTEN_LIBRARY ${SWIFTEN_LIBRARY} ${LIBXML_LIBRARY})
 
	endif()
 
	set(SWIFTEN_LIBRARY ${SWIFTEN_LIBRARY} "Dnsapi")
 
	set(SWIFTEN_LIBRARY ${SWIFTEN_LIBRARY} "Crypt32")
 
	set(SWIFTEN_LIBRARY ${SWIFTEN_LIBRARY} "Secur32")
 
	set(SWIFTEN_LIBRARY ${SWIFTEN_LIBRARY} "Iphlpapi")
 
	set(SWIFTEN_LIBRARY ${SWIFTEN_LIBRARY} "Winscard")
 
	message(STATUS "Using swiften: ${SWIFTEN_INCLUDE_DIR} ${SWIFTEN_LIBRARY}")
 
endif()
 
 
# FIND BOOST
 
set(Boost_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
if (WIN32)
 
	set(Boost_USE_STATIC_LIBS      ON)
 
	set(Boost_USE_MULTITHREADED      ON)
 
	set(Boost_USE_STATIC_RUNTIME    OFF)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
else(WIN32)
 
	LIST_CONTAINS(contains -lboost_program_options ${SWIFTEN_LIBRARY})
 
	if(contains)
 
		message(STATUS "Using non-multithreaded boost")
 
		set(Boost_USE_MULTITHREADED 0)
 
	endif(contains)
 
	set(Boost_FIND_QUIETLY ON)
 
@@ -106,24 +105,25 @@ endif()
 
 
# FIND POPT
 
if (NOT WIN32)
 
	set(popt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(popt REQUIRED)
 
endif()
 
 
###### Database ######
 
 
# FIND SQLITE3
 
if (ENABLE_SQLITE3)
 
	if (MSVC)
 
		set(SQLITE3_FOUND 1)
 
		ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/msvc-deps)
 
	else()
 
		if (WIN32)
 
			ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/msvc-deps/sqlite3)
 
		else()
 
			set(sqlite3_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
			find_package(sqlite3)
 
		endif()
 
	endif()
 
endif()
 
 
# FIND MYSQL
backends/swiften/main.cpp
Show inline comments
 
// Transport includes
 
#include "transport/config.h"
 
#include "transport/networkplugin.h"
 
#include "transport/logging.h"
 
 
#include "boost/date_time/posix_time/posix_time.hpp"
 
 
// Swiften
 
#include "Swiften/Swiften.h"
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
#ifndef WIN32
 
// for signal handler
 
#include "unistd.h"
 
#include "signal.h"
 
#include "sys/wait.h"
 
#include "sys/signal.h"
 
#endif
 
 
#ifndef __FreeBSD__
 
#ifndef __MACH__
 
// malloc_trim
 
@@ -78,52 +80,58 @@ class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
 
		
 
		Swift::FullPayloadSerializerCollection collection;
 
		Swift::XMPPParser *m_xmppParser;
 
		Swift::FullPayloadParserFactoryCollection m_collection2;
 
 
		SwiftenPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
			m_firstPing = true;
 
			m_factories = new Swift::BoostNetworkFactories(loop);
 
			m_conn = m_factories->getConnectionFactory()->createConnection();
 
			m_conn->onDataRead.connect(boost::bind(&SwiftenPlugin::_handleDataRead, this, _1));
 
			m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
 

	
 
#if HAVE_SWIFTEN_3
 
			serializer = new Swift::XMPPSerializer(&collection, Swift::ClientStreamType, false);
 
#else
 
			serializer = new Swift::XMPPSerializer(&collection, Swift::ClientStreamType);
 
#endif
 
			m_xmppParser = new Swift::XMPPParser(this, &m_collection2, m_factories->getXMLParserFactory());
 
			m_xmppParser->parse("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>");
 
 
			LOG4CXX_INFO(logger, "Starting the plugin.");
 
		}
 
 
		// NetworkPlugin uses this method to send the data to networkplugin server
 
		void sendData(const std::string &string) {
 
			m_conn->write(Swift::createSafeByteArray(string));
 
		}
 
 
		// This method has to call handleDataRead with all received data from network plugin server
 
		void _handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data) {
 
			if (m_firstPing) {
 
				m_firstPing = false;
 
				NetworkPlugin::PluginConfig cfg;
 
				cfg.setRawXML(true);
 
				sendConfig(cfg);
 
			}
 
			std::string d(data->begin(), data->end());
 
			handleDataRead(d);
 
		}
 
 
		void handleStreamStart(const Swift::ProtocolHeader&) {}
 

	
 
#if HAVE_SWIFTEN_3
 
		void handleElement(boost::shared_ptr<Swift::ToplevelElement> element) {
 
#else
 
		void handleElement(boost::shared_ptr<Swift::Element> element) {
 
#endif
 
			boost::shared_ptr<Swift::Stanza> stanza = boost::dynamic_pointer_cast<Swift::Stanza>(element);
 
			if (!stanza) {
 
				return;
 
			}
 
 
			std::string user = stanza->getFrom().toBare();
 
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (!client)
 
				return;
 
 
			stanza->setFrom(client->getJID());
backends/twitter/CMakeLists.txt
Show inline comments
 
include_directories (${libtransport_SOURCE_DIR}/backends/twitter/libtwitcurl) 
 
FILE(GLOB SRC *.cpp libtwitcurl/*.cpp Requests/*.cpp)
 
add_executable(spectrum2_twitter_backend ${SRC})
 

	
 
if (NOT WIN32)
 
target_link_libraries(spectrum2_twitter_backend curl transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
find_package(curl)
 

	
 
if(CURL_FOUND)
 
message(STATUS "Using curl ${CURL_VERSION_STRING}: ${CURL_INCLUDE_DIRS} ${CURL_LIBRARIES}")
 
include_directories (${CURL_INCLUDE_DIRS}) 
 
target_link_libraries(spectrum2_twitter_backend transport ${CURL_LIBRARIES} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
else()
 
include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/curl/include")
 
target_link_libraries(spectrum2_twitter_backend libcurl transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
message(FATAL_ERROR "curl not found")
 
endif()
 

	
 
INSTALL(TARGETS spectrum2_twitter_backend RUNTIME DESTINATION bin)
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -640,25 +640,29 @@ void TwitterPlugin::populateRoster(std::string &user, std::vector<User> &friends
 
{
 
	if(errMsg.getMessage().length() == 0) 
 
	{
 
		for(int i=0 ; i<friends.size() ; i++) {
 
			userdb[user].buddies.insert(friends[i].getScreenName());
 
			userdb[user].buddiesInfo[friends[i].getScreenName()] = friends[i];
 
			userdb[user].buddiesImgs[friends[i].getScreenName()] = friendAvatars[i];
 
			
 
			if(userdb[user].twitterMode == MULTIPLECONTACT) {
 
				std::string lastTweet = friends[i].getLastStatus().getTweet();
 
				//LOG4CXX_INFO(logger, user << " - " << SHA(friendAvatars[i]))
 
				handleBuddyChanged(user, friends[i].getScreenName(), friends[i].getUserName(), std::vector<std::string>(), 
 
#if HAVE_SWIFTEN_3
 
					pbnetwork::STATUS_ONLINE, lastTweet, Swift::byteArrayToString(cryptoProvider->getSHA1Hash(Swift::createByteArray(friendAvatars[i]))));
 
#else
 
								   pbnetwork::STATUS_ONLINE, lastTweet, SHA(friendAvatars[i]));
 
#endif
 
			}
 
			else if(userdb[user].twitterMode == CHATROOM)
 
				handleParticipantChanged(user, friends[i].getScreenName(), adminChatRoom, 0, pbnetwork::STATUS_ONLINE);
 
			
 
			/*handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
							   	friends[i].getScreenName() + " - " + friends[i].getLastStatus().getTweet(), 
 
								userdb[user].twitterMode == CHATROOM ? adminNickName : "");*/
 
		}
 
	} else {
 
		if (errMsg.isCurlError()) {
 
			handleDisconnected(user, 3, errMsg.getMessage());
 
			return;
 
@@ -812,25 +816,29 @@ void TwitterPlugin::createFriendResponse(std::string &user, User &frnd, std::str
 
		return;
 
	}
 
 
	handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
						std::string("You are now following ") + frnd.getScreenName(), userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 
	
 
	userdb[user].buddies.insert(frnd.getScreenName());
 
	userdb[user].buddiesInfo[frnd.getScreenName()] = frnd;
 
	userdb[user].buddiesImgs[frnd.getScreenName()] = img;
 
	
 
	LOG4CXX_INFO(logger, user << " - " << frnd.getScreenName() << ", " << frnd.getProfileImgURL())
 
	if(userdb[user].twitterMode == MULTIPLECONTACT) {
 
#if HAVE_SWIFTEN_3
 
		handleBuddyChanged(user, frnd.getScreenName(), frnd.getUserName(), std::vector<std::string>(), pbnetwork::STATUS_ONLINE, "", Swift::byteArrayToString(cryptoProvider->getSHA1Hash(Swift::createByteArray(img))));
 
#else
 
		handleBuddyChanged(user, frnd.getScreenName(), frnd.getUserName(), std::vector<std::string>(), pbnetwork::STATUS_ONLINE, "", SHA(img));
 
#endif
 
	} else if(userdb[user].twitterMode == CHATROOM) {
 
		handleParticipantChanged(user, frnd.getScreenName(), adminChatRoom, 0, pbnetwork::STATUS_ONLINE);
 
	}
 
}
 
 
void TwitterPlugin::deleteFriendResponse(std::string &user, User &frnd, Error &errMsg)
 
{
 
	if(errMsg.getMessage().length()) {
 
		if (errMsg.isCurlError()) {
 
			handleDisconnected(user, 3, errMsg.getMessage());
 
			return;
 
		}
backends/twitter/TwitterPlugin.h
Show inline comments
 
@@ -23,43 +23,51 @@
 
#include <boost/thread/mutex.hpp>
 
 
#include "twitcurl.h"
 
#include "TwitterResponseParser.h"
 
 
#include <iostream>
 
#include <sstream>
 
#include <map>
 
#include <vector>
 
#include <queue>
 
#include <set>
 
#include <cstdio>
 

	
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
#if HAVE_SWIFTEN_3
 
#include <Swiften/Crypto/CryptoProvider.h>
 
#include <Swiften/Crypto/PlatformCryptoProvider.h>
 
#else
 
#include "Swiften/StringCodecs/SHA1.h"
 

	
 
#endif
 
using namespace boost::filesystem;
 
using namespace boost::program_options;
 
using namespace Transport;
 
 
#define STR(x) (std::string("(") + x.from + ", " + x.to + ", " + x.message + ")")
 
 
class TwitterPlugin;
 
extern TwitterPlugin *np;
 
extern Swift::SimpleEventLoop *loop_; // Event Loop
 
 
 
class TwitterPlugin : public NetworkPlugin {
 
	public:
 
		Swift::BoostNetworkFactories *m_factories;
 
		Swift::BoostIOServiceThread m_boostIOServiceThread;
 
		boost::shared_ptr<Swift::Connection> m_conn;
 
#if HAVE_SWIFTEN_3
 
		boost::shared_ptr<Swift::CryptoProvider> cryptoProvider;
 
#endif
 
		Swift::Timer::ref tweet_timer;
 
		Swift::Timer::ref message_timer;
 
		StorageBackend *storagebackend;
 
 
		TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, StorageBackend *storagebackend, const std::string &host, int port);
 
		~TwitterPlugin();
 
 
		// Send data to NetworkPlugin server
 
		void sendData(const std::string &string);
 
 
		// Receive date from the NetworkPlugin server and invoke the appropirate payload handler (implement in the NetworkPlugin class)
 
		void _handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data);
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
#define NOMINMAX
 
#include <algorithm>
 
#include <memory.h>
 
#include "twitcurlurls.h"
 
#include "twitcurl.h"
 
#include "urlencode.h"
 
 
/*++
 
* @method: twitCurl::twitCurl
 
*
 
* @description: constructor
 
*
 
* @input: none
 
*
cmake_modules/SwiftenConfig.cmake
Show inline comments
 
FIND_LIBRARY(SWIFTEN_LIBRARY NAMES Swiften HINTS ../lib)
 
FIND_LIBRARY(SWIFTEN_LIBRARY NAMES Swiften Swiften3 HINTS ../lib)
 
FIND_PATH(SWIFTEN_INCLUDE_DIR NAMES "Swiften/Swiften.h" PATH_SUFFIXES libSwiften Swiften HINTS ../include)
 
 
if( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR )
 
	find_program(SWIFTEN_CONFIG_EXECUTABLE NAMES swiften-config DOC "swiften-config executable" HINTS ../bin)
 
	set( SWIFTEN_CFLAGS "" )
 
	if (SWIFTEN_CONFIG_EXECUTABLE)
 
		execute_process(
 
			COMMAND ${SWIFTEN_CONFIG_EXECUTABLE} --libs
 
			OUTPUT_VARIABLE SWIFTEN_LIB)
 
		string(REGEX REPLACE "[\r\n]"                  " " SWIFTEN_LIB ${SWIFTEN_LIB})
 
		string(REGEX REPLACE " +$"                     ""  SWIFTEN_LIB ${SWIFTEN_LIB})
 
		string(REGEX REPLACE " " ";" SWIFTEN_LIB ${SWIFTEN_LIB})
include/Swiften/Elements/PubSubItem.cpp
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubItem.h
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubPayload.cpp
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubPayload.h
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubPublishPayload.cpp
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubPublishPayload.h
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubSubscribePayload.cpp
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubSubscribePayload.h
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubSubscriptionPayload.cpp
Show inline comments
 
deleted file
include/Swiften/Elements/PubSubSubscriptionPayload.h
Show inline comments
 
deleted file
include/Swiften/FileTransfer/CombinedOutgoingFileTransferManager.cpp
Show inline comments
 
@@ -34,26 +34,28 @@ CombinedOutgoingFileTransferManager::~CombinedOutgoingFileTransferManager() {
 
boost::shared_ptr<OutgoingFileTransfer> CombinedOutgoingFileTransferManager::createOutgoingFileTransfer(const JID& from, const JID& receipient, boost::shared_ptr<ReadBytestream> readBytestream, const StreamInitiationFileInfo& fileInfo) {
 
	// check if receipient support Jingle FT
 
	boost::optional<JID> fullJID = highestPriorityJIDSupportingJingle(receipient);
 
	if (!fullJID.is_initialized()) {
 
		fullJID = highestPriorityJIDSupportingSI(receipient);
 
	}
 
	else {
 
		JingleSessionImpl::ref jingleSession = boost::make_shared<JingleSessionImpl>(from, receipient, idGenerator->generateID(), iqRouter);
 
 
		//jsManager->getSession(receipient, idGenerator->generateID());
 
		assert(jingleSession);
 
		jsManager->registerOutgoingSession(from, jingleSession);
 
#if !HAVE_SWIFTEN_3
 
		boost::shared_ptr<OutgoingJingleFileTransfer> jingleFT =  boost::shared_ptr<OutgoingJingleFileTransfer>(new OutgoingJingleFileTransfer(jingleSession, remoteFactory, localFactory, iqRouter, idGenerator, from, receipient, readBytestream, fileInfo, bytestreamRegistry, bytestreamProxy));
 
		return jingleFT;
 
#endif
 
	}
 
 
	if (!fullJID.is_initialized()) {
 
		return boost::shared_ptr<OutgoingFileTransfer>();
 
	}
 
	
 
	// otherwise try SI
 
	boost::shared_ptr<MyOutgoingSIFileTransfer> jingleFT =  boost::shared_ptr<MyOutgoingSIFileTransfer>(new MyOutgoingSIFileTransfer(idGenerator->generateID(), from, fullJID.get(), fileInfo.getName(), fileInfo.getSize(), fileInfo.getDescription(), readBytestream, iqRouter, bytestreamServer, bytestreamRegistry));
 
	// else fail
 
	
 
	return jingleFT;
 
}
include/Swiften/FileTransfer/CombinedOutgoingFileTransferManager.h
Show inline comments
 
@@ -3,24 +3,27 @@
 
 * Licensed under the simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 
 
#pragma once
 
 
#include <boost/shared_ptr.hpp>
 
#include <boost/optional.hpp>
 
 
#include <Swiften/JID/JID.h>
 
 
#include "transport/presenceoracle.h"
 
#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
namespace Swift {
 
 
class JingleSessionManager;
 
class IQRouter;
 
class EntityCapsProvider;
 
class RemoteJingleTransportCandidateSelectorFactory;
 
class LocalJingleTransportCandidateGeneratorFactory;
 
class OutgoingFileTransfer;
 
class JID;
 
class IDGenerator;
 
class ReadBytestream;
include/Swiften/FileTransfer/MyOutgoingSIFileTransfer.cpp
Show inline comments
 
@@ -31,81 +31,88 @@ void MyOutgoingSIFileTransfer::start() {
 
}
 
 
void MyOutgoingSIFileTransfer::stop() {
 
}
 
 
void MyOutgoingSIFileTransfer::cancel() {
 
	// TODO
 
// 	session->sendTerminate(JinglePayload::Reason::Cancel);
 
 
	if (ibbSession) {
 
		ibbSession->stop();
 
	}
 
#if !HAVE_SWIFTEN_3
 
	SOCKS5BytestreamServerSession *serverSession = registry->getConnectedSession(SOCKS5BytestreamRegistry::getHostname(id, from, to));
 
	if (serverSession) {
 
		serverSession->stop();
 
	}
 
 
	onStateChange(FileTransfer::State(FileTransfer::State::Canceled));
 
#endif
 
}
 
 
void MyOutgoingSIFileTransfer::handleStreamInitiationRequestResponse(StreamInitiation::ref response, ErrorPayload::ref error) {
 
	if (error) {
 
		finish(FileTransferError());
 
	}
 
	else {
 
		if (response->getRequestedMethod() == "http://jabber.org/protocol/bytestreams") {
 
#if !HAVE_SWIFTEN_3
 
			registry->addReadBytestream(SOCKS5BytestreamRegistry::getHostname(id, from, to), bytestream);
 
			socksServer->addReadBytestream(id, from, to, bytestream);
 
#endif
 
			Bytestreams::ref bytestreams(new Bytestreams());
 
			bytestreams->setStreamID(id);
 
			HostAddressPort addressPort = socksServer->getAddressPort();
 
			bytestreams->addStreamHost(Bytestreams::StreamHost(addressPort.getAddress().toString(), from, addressPort.getPort()));
 
			BytestreamsRequest::ref request = BytestreamsRequest::create(from, to, bytestreams, iqRouter);
 
			request->onResponse.connect(boost::bind(&MyOutgoingSIFileTransfer::handleBytestreamsRequestResponse, this, _1, _2));
 
			request->send();
 
		}
 
		else if (response->getRequestedMethod() == "http://jabber.org/protocol/ibb") {
 
			ibbSession = boost::shared_ptr<IBBSendSession>(new IBBSendSession(id, from, to, bytestream, iqRouter));
 
			ibbSession->onFinished.connect(boost::bind(&MyOutgoingSIFileTransfer::handleIBBSessionFinished, this, _1));
 
			ibbSession->start();
 

	
 
#if !HAVE_SWIFTEN_3
 
			onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
 
#endif
 
		}
 
	}
 
}
 
 
void MyOutgoingSIFileTransfer::handleBytestreamsRequestResponse(Bytestreams::ref, ErrorPayload::ref error) {
 
	if (error) {
 
		finish(FileTransferError());
 
		return;
 
	}
 

	
 
#if !HAVE_SWIFTEN_3
 
	SOCKS5BytestreamServerSession *serverSession = registry->getConnectedSession(SOCKS5BytestreamRegistry::getHostname(id, from, to));
 
// 	serverSession->onBytesSent.connect(boost::bind(boost::ref(onProcessedBytes), _1));
 
// 	serverSession->onFinished.connect(boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1));
 
	serverSession->startTransfer();
 
	onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
 
	>
 
#endif	
 
	//socksServer->onTransferFinished.connect();
 
}
 
 
void MyOutgoingSIFileTransfer::finish(boost::optional<FileTransferError> error) {
 
	if (ibbSession) {
 
		ibbSession->onFinished.disconnect(boost::bind(&MyOutgoingSIFileTransfer::handleIBBSessionFinished, this, _1));
 
		ibbSession.reset();
 
	}
 
#if !HAVE_SWIFTEN_3
 
	socksServer->removeReadBytestream(id, from, to);
 
	if(error) {
 
		onStateChange(FileTransfer::State(FileTransfer::State::Canceled));
 
	}
 
	else {
 
		onStateChange(FileTransfer::State(FileTransfer::State::Finished));
 
	}
 
#endif
 
	onFinished(error);
 
}
 
 
void MyOutgoingSIFileTransfer::handleIBBSessionFinished(boost::optional<FileTransferError> error) {
 
	finish(error);
 
}
 
 
}
include/Swiften/FileTransfer/MyOutgoingSIFileTransfer.h
Show inline comments
 
@@ -9,24 +9,26 @@
 
#include <boost/shared_ptr.hpp>
 
 
#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
 
#include <Swiften/FileTransfer/ReadBytestream.h>
 
#include <Swiften/Base/boost_bsignals.h>
 
#include <Swiften/FileTransfer/FileTransferError.h>
 
#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
 
#include <Swiften/JID/JID.h>
 
#include <Swiften/Elements/StreamInitiation.h>
 
#include <Swiften/Elements/Bytestreams.h>
 
#include <Swiften/Elements/ErrorPayload.h>
 
#include <Swiften/FileTransfer/IBBSendSession.h>
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
namespace Swift {
 
	class IQRouter;
 
	class SOCKS5BytestreamServer;
 
	class SOCKS5BytestreamRegistry;
 
 
	class MyOutgoingSIFileTransfer : public OutgoingFileTransfer {
 
		public:
 
			MyOutgoingSIFileTransfer(const std::string& id, const JID& from, const JID& to, const std::string& name, int size, const std::string& description, boost::shared_ptr<ReadBytestream> bytestream, IQRouter* iqRouter, SOCKS5BytestreamServer* socksServer, SOCKS5BytestreamRegistry* registry);
 
 
			virtual void start();
 
			virtual void stop();
include/Swiften/Network/DummyConnectionServer.cpp
Show inline comments
 
deleted file
include/Swiften/Network/DummyConnectionServer.h
Show inline comments
 
deleted file
include/Swiften/Network/DummyConnectionServerFactory.cpp
Show inline comments
 
deleted file
include/Swiften/Network/DummyConnectionServerFactory.h
Show inline comments
 
deleted file
include/Swiften/Network/DummyNetworkFactories.h
Show inline comments
 
/*
 
 * Copyright (c) 2010 Remko Tronçon
 
 * Licensed under the GNU General Public License v3.
 
 * See Documentation/Licenses/GPLv3.txt for more information.
 
 */
 
 
#pragma once
 
 
#include <Swiften/Version.h>
 
//#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
// Swiften 3 was not released yet and these changes are not in 3.0alpha
 
#define HAVE_SWIFTEN_3 0
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
#include <Swiften/Network/NetworkFactories.h>
 
#include <Swiften/Parser/PlatformXMLParserFactory.h>
 
#if HAVE_SWIFTEN_3
 
#include <Swiften/IDN/IDNConverter.h>
 
#include <Swiften/IDN/PlatformIDNConverter.h>
 
#endif
 
 
namespace Swift {
 
	class EventLoop;
 
 
	class DummyNetworkFactories : public NetworkFactories {
include/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubItemParser.h
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubPayloadParser.cpp
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubPayloadParser.h
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubPublishPayloadParser.cpp
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubPublishPayloadParser.h
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubSubscribePayloadParser.cpp
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubSubscribePayloadParser.h
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubSubscriptionPayloadParser.cpp
Show inline comments
 
deleted file
include/Swiften/Parser/PayloadParsers/PubSubSubscriptionPayloadParser.h
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubPayloadSerializer.cpp
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubPayloadSerializer.h
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubPublishPayloadSerializer.cpp
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubPublishPayloadSerializer.h
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubSubscribePayloadSerializer.cpp
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubSubscribePayloadSerializer.h
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionPayloadSerializer.cpp
Show inline comments
 
deleted file
include/Swiften/Serializer/PayloadSerializers/PubSubSubscriptionPayloadSerializer.h
Show inline comments
 
deleted file
include/Swiften/Server/ServerFromClientSession.cpp
Show inline comments
 
@@ -67,25 +67,25 @@ void ServerFromClientSession::handlePasswordValid() {
 
void ServerFromClientSession::handlePasswordInvalid(const std::string &error) {
 
	if (!isInitialized()) {
 
		getXMPPLayer()->writeElement(boost::shared_ptr<AuthFailure>(new AuthFailure));
 
		if (!error.empty()) {
 
			boost::shared_ptr<StreamError> msg(new StreamError(StreamError::UndefinedCondition, error));
 
			getXMPPLayer()->writeElement(msg);
 
		}
 
		
 
		finishSession(AuthenticationFailedError);
 
	}
 
}
 
 
void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) {
 
void ServerFromClientSession::handleElement(boost::shared_ptr<ToplevelElement> element) {
 
	if (isInitialized()) {
 
		onElementReceived(element);
 
	}
 
	else {
 
		if (AuthRequest* authRequest = dynamic_cast<AuthRequest*>(element.get())) {
 
			if (authRequest->getMechanism() == "PLAIN" || (allowSASLEXTERNAL && authRequest->getMechanism() == "EXTERNAL")) {
 
				if (authRequest->getMechanism() == "EXTERNAL") {
 
						getXMPPLayer()->writeElement(boost::shared_ptr<AuthSuccess>(new AuthSuccess()));
 
						authenticated_ = true;
 
						getXMPPLayer()->resetParser();
 
				}
 
				else {
include/Swiften/Server/ServerFromClientSession.h
Show inline comments
 
@@ -7,24 +7,26 @@
 
#pragma once
 
 
#include <boost/shared_ptr.hpp>
 
#include <Swiften/Base/boost_bsignals.h>
 
#include <boost/enable_shared_from_this.hpp>
 
 
#include <string>
 
#include <Swiften/Session/Session.h>
 
#include <Swiften/JID/JID.h>
 
#include <Swiften/Network/Connection.h>
 
#include <Swiften/Base/ByteArray.h>
 
#include <Swiften/TLS/CertificateWithKey.h>
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
namespace Swift {
 
	class ProtocolHeader;
 
	class Element;
 
	class Stanza;
 
	class PayloadParserFactoryCollection;
 
	class PayloadSerializerCollection;
 
	class StreamStack;
 
	class UserRegistry;
 
	class XMPPLayer;
 
	class ConnectionLayer;
 
	class Connection;
 
@@ -51,25 +53,29 @@ namespace Swift {
 
			}
 
 
			void addTLSEncryption(TLSServerContextFactory* tlsContextFactory, CertificateWithKey::ref cert);
 
 
			Swift::JID getBareJID() {
 
				return Swift::JID(user_, getLocalJID().getDomain());
 
			}
 
 
			void handlePasswordValid();
 
			void handlePasswordInvalid(const std::string &error = "");
 
 
		private:
 
#if HAVE_SWIFTEN_3
 
			void handleElement(boost::shared_ptr<ToplevelElement>);
 
#else		
 
			void handleElement(boost::shared_ptr<Element>);
 
#endif
 
			void handleStreamStart(const ProtocolHeader& header);
 
			void handleSessionFinished(const boost::optional<SessionError>&);
 
 
			void setInitialized();
 
			bool isInitialized() const { 
 
				return initialized; 
 
			}
 
 
			void handleTLSError() { }
 
			void handleTLSConnected() { tlsConnected = true; }
 
 
		private:
include/Swiften/Server/ServerStanzaChannel.cpp
Show inline comments
 
@@ -54,26 +54,29 @@ void ServerStanzaChannel::sendMessage(boost::shared_ptr<Message> message) {
 
void ServerStanzaChannel::sendPresence(boost::shared_ptr<Presence> presence) {
 
	send(presence);
 
}
 
 
void ServerStanzaChannel::handleDataRead(const SafeByteArray &data, const boost::shared_ptr<ServerFromClientSession> &session) {
 
	if (safeByteArrayToString(data).find("</stream:stream>") != std::string::npos) {
 
		Swift::Presence::ref presence = Swift::Presence::create();
 
		presence->setFrom(session->getRemoteJID());
 
		presence->setType(Swift::Presence::Unavailable);
 
		onPresenceReceived(presence);
 
	}
 
}
 

	
 
#if HAVE_SWIFTEN_3
 
void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr<ToplevelElement> element, bool last) {
 
#else
 
void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr<Element> element, bool last) {
 
#endif
 
	std::vector<boost::shared_ptr<ServerFromClientSession> > candidateSessions;
 
	for (std::list<boost::shared_ptr<ServerFromClientSession> >::const_iterator i = sessions[to.toBare().toString()].begin(); i != sessions[to.toBare().toString()].end(); ++i) {
 
		candidateSessions.push_back(*i);
 
	}
 
 
	for (std::vector<boost::shared_ptr<ServerFromClientSession> >::const_iterator i = candidateSessions.begin(); i != candidateSessions.end(); ++i) {
 
		removeSession(*i);
 
		if (element) {
 
			(*i)->sendElement(element);
 
		}
 
 
		if (last && (*i)->getRemoteJID().isValid()) {
include/Swiften/Server/ServerStanzaChannel.h
Show inline comments
 
@@ -6,38 +6,42 @@
 
 
#pragma once
 
 
#include <boost/shared_ptr.hpp>
 
 
#include "Swiften/Base/IDGenerator.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Client/StanzaChannel.h"
 
#include "Swiften/Elements/Message.h"
 
#include "Swiften/Elements/IQ.h"
 
#include "Swiften/Elements/Presence.h"
 
#include "Swiften/TLS/Certificate.h"
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
namespace Swift {
 
	class Error;
 
	class ServerStanzaChannel : public StanzaChannel {
 
		public:
 
			void addSession(boost::shared_ptr<ServerFromClientSession> session);
 
			void removeSession(boost::shared_ptr<ServerFromClientSession> session);
 
 
			void sendIQ(boost::shared_ptr<IQ> iq);
 
			void sendMessage(boost::shared_ptr<Message> message);
 
			void sendPresence(boost::shared_ptr<Presence> presence);
 

	
 
#if HAVE_SWIFTEN_3
 
			void finishSession(const JID& to, boost::shared_ptr<ToplevelElement> element, bool last = false);
 
#else
 
			void finishSession(const JID& to, boost::shared_ptr<Element> element, bool last = false);
 

	
 
#endif
 
			bool getStreamManagementEnabled() const {
 
				return false;
 
			}
 
	
 
			bool isAvailable() const {
 
				return true;
 
			}
 
			
 
			std::vector<Certificate::ref> getPeerCertificateChain() const {
 
				return std::vector<Certificate::ref>();
 
			}
 
include/transport/filetransfermanager.h
Show inline comments
 
@@ -10,34 +10,44 @@
 
 *
 
 * 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
 
 */
 
 
#pragma once
 

	
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
#include <Swiften/Elements/StreamInitiationFileInfo.h>
 
#if !HAVE_SWIFTEN_3
 
#include <Swiften/FileTransfer/ConnectivityManager.h>
 
#endif
 
#include <Swiften/FileTransfer/CombinedOutgoingFileTransferManager.h>
 
#include <Swiften/FileTransfer/IncomingFileTransferManager.h>
 
#if !HAVE_SWIFTEN_3
 
#include <Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGeneratorFactory.h>
 
#include <Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h>
 
#else
 
#include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h>
 
#include <Swiften/FileTransfer/SOCKS5BytestreamServerManager.h>
 
#endif
 
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
 
#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
 
#if !HAVE_SWIFTEN_3
 
#include <Swiften/FileTransfer/SOCKS5BytestreamProxy.h>
 
#endif
 
 
namespace Transport {
 
 
class UserManager;
 
class User;
 
class Component;
 
class Buddy;
 
 
class FileTransferManager {
 
	public:
 
		typedef struct Transfer {
 
			boost::shared_ptr<Swift::OutgoingFileTransfer> ft;
 
@@ -50,19 +60,24 @@ class FileTransferManager {
 
		virtual ~FileTransferManager();
 
		
 
		FileTransferManager::Transfer sendFile(User *user, Buddy *buddy, boost::shared_ptr<Swift::ReadBytestream> byteStream, const Swift::StreamInitiationFileInfo &info);
 
 
	private:
 
		Component *m_component;
 
		UserManager *m_userManager;
 
		Swift::CombinedOutgoingFileTransferManager* m_outgoingFTManager;
 
		Swift::RemoteJingleTransportCandidateSelectorFactory* m_remoteCandidateSelectorFactory;
 
		Swift::LocalJingleTransportCandidateGeneratorFactory* m_localCandidateGeneratorFactory;
 
		Swift::JingleSessionManager *m_jingleSessionManager;
 
		Swift::SOCKS5BytestreamRegistry* m_bytestreamRegistry;
 
#if HAVE_SWIFTEN_3
 
		Swift::SOCKS5BytestreamServerManager* m_proxyServerManager;
 
		Swift::SOCKS5BytestreamProxiesManager *m_proxyManager;
 
#else
 
		Swift::SOCKS5BytestreamServer* m_bytestreamServer;
 
		Swift::SOCKS5BytestreamProxy* m_bytestreamProxy;
 
		Swift::SOCKS5BytestreamServer *bytestreamServer;
 
		Swift::ConnectivityManager* m_connectivityManager;
 
#endif
 
};
 
 
}
include/transport/networkpluginserver.h
Show inline comments
 
@@ -26,24 +26,26 @@
 
#include "Swiften/Network/BoostConnectionServer.h"
 
#include "Swiften/Network/Connection.h"
 
#include "Swiften/Elements/ChatState.h"
 
#include "Swiften/Elements/RosterItemPayload.h"
 
#include "Swiften/Elements/VCard.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
 
#include "Swiften/Parser/XMPPParser.h"
 
#include "Swiften/Parser/XMPPParserClient.h"
 
#include "Swiften/Serializer/XMPPSerializer.h"
 
#include "storagebackend.h"
 
#include "transport/filetransfermanager.h"
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
namespace Transport {
 
 
class UserManager;
 
class User;
 
class Component;
 
class Buddy;
 
class LocalBuddy;
 
class Config;
 
class NetworkConversation;
 
class VCardResponder;
 
class RosterResponder;
 
@@ -150,27 +152,29 @@ class NetworkPluginServer : Swift::XMPPParserClient {
 
	private:
 
		void send(boost::shared_ptr<Swift::Connection> &, const std::string &data);
 
 
		void pingTimeout();
 
		void sendPing(Backend *c);
 
		Backend *getFreeClient(bool acceptUsers = true, bool longRun = false, bool check = false);
 
		void connectWaitingUsers();
 
		void loginDelayFinished();
 
		void handleRawIQReceived(boost::shared_ptr<Swift::IQ> iq);
 
		void handleRawPresenceReceived(boost::shared_ptr<Swift::Presence> presence);
 
 
		void handleStreamStart(const Swift::ProtocolHeader&) {}
 

	
 
#if HAVE_SWIFTEN_3
 
		void handleElement(boost::shared_ptr<Swift::ToplevelElement> element);
 
#else
 
		void handleElement(boost::shared_ptr<Swift::Element> element);
 

	
 
#endif
 
		void handleStreamEnd() {}
 
 
		UserManager *m_userManager;
 
		VCardResponder *m_vcardResponder;
 
		RosterResponder *m_rosterResponder;
 
		BlockResponder *m_blockResponder;
 
		Config *m_config;
 
		boost::shared_ptr<Swift::ConnectionServer> m_server;
 
		std::list<Backend *>  m_clients;
 
		std::vector<unsigned long> m_pids;
 
		Swift::Timer::ref m_pingTimer;
 
		Swift::Timer::ref m_collectTimer;
include/transport/settingsadhoccommand.h
Show inline comments
 
@@ -16,24 +16,26 @@
 
 * 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
 
 */
 
 
#pragma once
 
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include "transport/adhoccommand.h"
 
#include "transport/adhoccommandfactory.h"
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
 
namespace Transport {
 
 
class Component;
 
class UserManager;
 
class StorageBackend;
 
 
class SettingsAdHocCommand : public AdHocCommand {
 
	public:
 
		typedef enum { Init, WaitingForResponse } State;
 
include/transport/userregistration.h
Show inline comments
 
@@ -15,24 +15,26 @@
 
 *
 
 * 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
 
 */
 
 
#pragma once
 
 
#include "Swiften/Queries/Responder.h"
 
#include "Swiften/Elements/InBandRegistrationPayload.h"
 
#include "Swiften/Elements/RosterPayload.h"
 
#include <boost/signal.hpp>
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
 
namespace Transport {
 
 
struct UserInfo;
 
class Component;
 
class StorageBackend;
 
class UserManager;
 
class Config;
 
 
/// Allows users to register the transport using service discovery.
 
class UserRegistration : public Swift::Responder<Swift::InBandRegistrationPayload> {
 
	public:
msvc-deps/CMakeLists.txt
Show inline comments
 
ADD_SUBDIRECTORY(sqlite3)
 
ADD_SUBDIRECTORY(curl)
msvc-deps/curl
Show inline comments
 
Subproject commit 9ce2d7001939b795b45a8ce7700d1a3dcde0475d
 
Subproject commit f39b1c080129c01c8204d3a5a40aad038c7a57f3
src/discoinforesponder.cpp
Show inline comments
 
@@ -35,24 +35,27 @@ using namespace boost;
 
 
DEFINE_LOGGER(logger, "DiscoInfoResponder");
 
 
namespace Transport {
 
 
DiscoInfoResponder::DiscoInfoResponder(Swift::IQRouter *router, Config *config) : Swift::GetResponder<DiscoInfo>(router) {
 
	m_config = config;
 
	m_config->onBackendConfigUpdated.connect(boost::bind(&DiscoInfoResponder::updateFeatures, this));
 
	m_buddyInfo = NULL;
 
	m_transportInfo.addIdentity(DiscoInfo::Identity(CONFIG_STRING(m_config, "identity.name"),
 
													CONFIG_STRING(m_config, "identity.category"),
 
													CONFIG_STRING(m_config, "identity.type")));
 
#if HAVE_SWIFTEN_3
 
	crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
 
#endif
 
 
	updateFeatures();
 
}
 
 
DiscoInfoResponder::~DiscoInfoResponder() {
 
	delete m_buddyInfo;
 
}
 
 
void DiscoInfoResponder::updateFeatures() {
 
	std::list<std::string> features2;
 
	features2.push_back("jabber:iq:register");
 
	features2.push_back("jabber:iq:gateway");
 
@@ -84,26 +87,29 @@ void DiscoInfoResponder::setTransportFeatures(std::list<std::string> &features)
 
}
 
 
void DiscoInfoResponder::setBuddyFeatures(std::list<std::string> &f) {
 
	delete m_buddyInfo;
 
	m_buddyInfo = new Swift::DiscoInfo;
 
	m_buddyInfo->addIdentity(DiscoInfo::Identity(CONFIG_STRING(m_config, "identity.name"), "client", "pc"));
 
 
	for (std::list<std::string>::iterator it = f.begin(); it != f.end(); it++) {
 
		if (!m_buddyInfo->hasFeature(*it)) {
 
			m_buddyInfo->addFeature(*it);
 
		}
 
	}
 

	
 
#if HAVE_SWIFTEN_3
 
	CapsInfoGenerator caps("spectrum", crypto.get());
 
#else
 
	CapsInfoGenerator caps("spectrum");
 
#endif
 
	m_capsInfo = caps.generateCapsInfo(*m_buddyInfo);
 
	onBuddyCapsInfoChanged(m_capsInfo);
 
}
 
 
void DiscoInfoResponder::addRoom(const std::string &jid, const std::string &name) {
 
	std::string j = jid;
 
	boost::algorithm::to_lower(j);
 
	m_rooms[j] = name;
 
}
 
 
void DiscoInfoResponder::clearRooms() {
 
	m_rooms.clear();
src/discoinforesponder.h
Show inline comments
 
@@ -17,24 +17,31 @@
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 
 
#pragma once
 
 
#include <vector>
 
#include <list>
 
#include <boost/signal.hpp>
 
#include "Swiften/Queries/GetResponder.h"
 
#include "Swiften/Elements/DiscoInfo.h"
 
#include "Swiften/Elements/CapsInfo.h"
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  SWIFTEN_VERSION >= 0x030000
 
#if HAVE_SWIFTEN_3
 
#include <Swiften/Crypto/CryptoProvider.h>
 
#include <Swiften/Crypto/PlatformCryptoProvider.h>
 
#endif
 
 
 
namespace Transport {
 
 
class Config;
 
 
class DiscoInfoResponder : public Swift::GetResponder<Swift::DiscoInfo> {
 
	public:
 
		DiscoInfoResponder(Swift::IQRouter *router, Config *config);
 
		~DiscoInfoResponder();
 
 
		void setTransportFeatures(std::list<std::string> &features);
 
		void setBuddyFeatures(std::list<std::string> &features);
 
@@ -51,15 +58,18 @@ class DiscoInfoResponder : public Swift::GetResponder<Swift::DiscoInfo> {
 
		}
 
 
	private:
 
		virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::DiscoInfo> payload);
 
		void updateFeatures();
 
 
		Swift::DiscoInfo m_transportInfo;
 
		Swift::DiscoInfo *m_buddyInfo;
 
		Config *m_config;
 
		Swift::CapsInfo m_capsInfo;
 
		std::map<std::string, std::string> m_rooms;
 
		std::map<std::string, std::string> m_commands;
 
#if HAVE_SWIFTEN_3
 
		boost::shared_ptr<Swift::CryptoProvider> crypto;
 
#endif
 
};
 
 
}
src/filetransfermanager.cpp
Show inline comments
 
@@ -26,56 +26,69 @@
 
#include "transport/logging.h"
 
#include "Swiften/Network/ConnectionServerFactory.h"
 
 
namespace Transport {
 
 
DEFINE_LOGGER(logger, "FileTransferManager");
 
 
FileTransferManager::FileTransferManager(Component *component, UserManager *userManager) {
 
	m_component = component;
 
	m_userManager = userManager;
 
 
	m_jingleSessionManager = new Swift::JingleSessionManager(m_component->getIQRouter());
 
#if !HAVE_SWIFTEN_3
 
	m_connectivityManager = new Swift::ConnectivityManager(m_component->getNetworkFactories()->getNATTraverser());
 
#endif
 
	m_bytestreamRegistry = new Swift::SOCKS5BytestreamRegistry();
 
#if !HAVE_SWIFTEN_3
 
	m_bytestreamProxy = new Swift::SOCKS5BytestreamProxy(m_component->getNetworkFactories()->getConnectionFactory(), m_component->getNetworkFactories()->getTimerFactory());
 

	
 
	m_localCandidateGeneratorFactory = new Swift::DefaultLocalJingleTransportCandidateGeneratorFactory(m_connectivityManager, m_bytestreamRegistry, m_bytestreamProxy, "thishouldnotbeused");
 
	m_remoteCandidateSelectorFactory = new Swift::DefaultRemoteJingleTransportCandidateSelectorFactory(m_component->getNetworkFactories()->getConnectionFactory(), m_component->getNetworkFactories()->getTimerFactory());
 

	
 
#else
 
	m_proxyManager = new Swift::SOCKS5BytestreamProxiesManager(m_component->getNetworkFactories()->getConnectionFactory(), m_component->getNetworkFactories()->getTimerFactory(), m_component->getNetworkFactories()->getDomainNameResolver(), m_component->getIQRouter(), "bar.com");
 
#endif
 
	boost::shared_ptr<Swift::ConnectionServer> server = m_component->getNetworkFactories()->getConnectionServerFactory()->createConnectionServer(19645);
 
	server->start();
 
#if HAVE_SWIFTEN_3
 
	m_proxyServerManager = new Swift::SOCKS5BytestreamServerManager(m_bytestreamRegistry, m_component->getNetworkFactories()->getConnectionServerFactory(), m_component->getNetworkFactories()->getNetworkEnvironment(), m_component->getNetworkFactories()->getNATTraverser());
 
#else
 
	m_bytestreamServer = new Swift::SOCKS5BytestreamServer(server, m_bytestreamRegistry);
 
	m_bytestreamServer->start();
 

	
 
	m_outgoingFTManager = new Swift::CombinedOutgoingFileTransferManager(m_jingleSessionManager, m_component->getIQRouter(),
 
		m_userManager, m_remoteCandidateSelectorFactory,
 
		m_localCandidateGeneratorFactory, m_bytestreamRegistry,
 
		m_bytestreamProxy, m_component->getPresenceOracle(),
 
		m_bytestreamServer);
 
#endif
 
 
	
 
 
// WARNING: Swiften crashes when this is uncommented... But we probably need it for working Jingle FT
 
// 	m_connectivityManager->addListeningPort(19645);
 
}
 
 
FileTransferManager::~FileTransferManager() {
 
#if !HAVE_SWIFTEN_3
 
	m_bytestreamServer->stop();
 
	delete m_outgoingFTManager;
 
	delete m_remoteCandidateSelectorFactory;
 
	delete m_localCandidateGeneratorFactory;
 
#endif
 
	delete m_outgoingFTManager;
 
	delete m_jingleSessionManager;
 
	delete m_bytestreamRegistry;
 
#if !HAVE_SWIFTEN_3
 
	delete m_bytestreamServer;
 
	delete m_bytestreamProxy;
 
	delete m_connectivityManager;
 
#endif
 
}
 
 
FileTransferManager::Transfer FileTransferManager::sendFile(User *user, Buddy *buddy, boost::shared_ptr<Swift::ReadBytestream> byteStream, const Swift::StreamInitiationFileInfo &info) {
 
	FileTransferManager::Transfer transfer;
 
	transfer.from = buddy->getJID();
 
	transfer.to = user->getJID();
 
	transfer.readByteStream = byteStream;
 
 
	LOG4CXX_INFO(logger, "Starting FT from '" << transfer.from << "' to '" << transfer.to << "'")
 
 
	transfer.ft = m_outgoingFTManager->createOutgoingFileTransfer(transfer.from, transfer.to, transfer.readByteStream, info);
 
// 	if (transfer.ft) {
src/networkpluginserver.cpp
Show inline comments
 
@@ -262,25 +262,29 @@ static void handleBuddyPayload(LocalBuddy *buddy, const pbnetwork::Buddy &payloa
 
NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, UserManager *userManager, FileTransferManager *ftManager, DiscoItemsResponder *discoItemsResponder) {
 
	_server = this;
 
	m_ftManager = ftManager;
 
	m_userManager = userManager;
 
	m_config = config;
 
	m_component = component;
 
	m_isNextLongRun = false;
 
	m_adminInterface = NULL;
 
	m_startingBackend = false;
 
	m_lastLogin = 0;
 
	m_xmppParser = new Swift::XMPPParser(this, &m_collection, component->getNetworkFactories()->getXMLParserFactory());
 
	m_xmppParser->parse("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>");
 
#if HAVE_SWIFTEN_3
 
	m_serializer = new Swift::XMPPSerializer(&m_collection2, Swift::ClientStreamType, false);
 
#else
 
	m_serializer = new Swift::XMPPSerializer(&m_collection2, Swift::ClientStreamType);
 
#endif
 
	m_discoItemsResponder = discoItemsResponder;
 
	m_component->m_factory = new NetworkFactory(this);
 
	m_userManager->onUserCreated.connect(boost::bind(&NetworkPluginServer::handleUserCreated, this, _1));
 
	m_userManager->onUserDestroyed.connect(boost::bind(&NetworkPluginServer::handleUserDestroyed, this, _1));
 
 
	m_component->onRawIQReceived.connect(boost::bind(&NetworkPluginServer::handleRawIQReceived, this, _1));
 
 
	m_pingTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(20000);
 
	m_pingTimer->onTick.connect(boost::bind(&NetworkPluginServer::pingTimeout, this));
 
	m_pingTimer->start();
 
 
	m_loginTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(CONFIG_INT(config, "service.login_delay") * 1000);
 
@@ -825,26 +829,28 @@ void NetworkPluginServer::handleFTStartPayload(const std::string &data) {
 
	boost::shared_ptr<MemoryReadBytestream> bytestream(new MemoryReadBytestream(payload.size()));
 
	bytestream->onDataNeeded.connect(boost::bind(&NetworkPluginServer::handleFTDataNeeded, this, c, bytestream_id + 1));
 
 
	LOG4CXX_INFO(logger, "jid=" << buddy->getJID());
 
 
	FileTransferManager::Transfer transfer = m_ftManager->sendFile(user, buddy, bytestream, fileInfo);
 
	if (!transfer.ft) {
 
		handleFTRejected(user, payload.buddyname(), payload.filename(), payload.size());
 
		return;
 
	}
 
 
	m_filetransfers[++bytestream_id] = transfer;
 
#if !HAVE_SWIFTEN_3
 
	transfer.ft->onStateChange.connect(boost::bind(&NetworkPluginServer::handleFTStateChanged, this, _1, payload.username(), payload.buddyname(), payload.filename(), payload.size(), bytestream_id));
 
	transfer.ft->start();
 
#endif
 
}
 
 
void NetworkPluginServer::handleFTFinishPayload(const std::string &data) {
 
	pbnetwork::File payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 
 
	if (payload.has_ftid()) {
 
		if (m_filetransfers.find(payload.ftid()) != m_filetransfers.end()) {
 
			FileTransferManager::Transfer &transfer = m_filetransfers[payload.ftid()];
 
@@ -982,26 +988,29 @@ void NetworkPluginServer::handleBackendConfigPayload(const std::string &data) {
 
void NetworkPluginServer::handleRoomListPayload(const std::string &data) {
 
	pbnetwork::RoomList payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 
 
	m_discoItemsResponder->clearRooms();
 
	for (int i = 0; i < payload.room_size() && i < payload.name_size(); i++) {
 
		m_discoItemsResponder->addRoom(Swift::JID::getEscapedNode(payload.room(i)) + "@" + m_component->getJID().toString(), payload.name(i));
 
	}
 
}
 

	
 
#if HAVE_SWIFTEN_3
 
void NetworkPluginServer::handleElement(boost::shared_ptr<Swift::ToplevelElement> element) {
 
#else
 
void NetworkPluginServer::handleElement(boost::shared_ptr<Swift::Element> element) {
 
#endif
 
	boost::shared_ptr<Swift::Stanza> stanza = boost::dynamic_pointer_cast<Swift::Stanza>(element);
 
	if (!stanza) {
 
		return;
 
	}
 
 
	User *user = m_userManager->getUser(stanza->getTo().toBare());
 
	if (!user)
 
		return;
 
 
	Swift::JID originalJID = stanza->getFrom();
 
	NetworkConversation *conv = (NetworkConversation *) user->getConversationManager()->getConversation(originalJID.toBare());
 
 
@@ -1868,30 +1877,32 @@ void NetworkPluginServer::handleFTRejected(User *user, const std::string &buddyN
 
	if (!c) {
 
		return;
 
	}
 
	send(c->connection, message);
 
}
 
 
void NetworkPluginServer::handleFTStateChanged(Swift::FileTransfer::State state, const std::string &userName, const std::string &buddyName, const std::string &fileName, unsigned long size, unsigned long id) {
 
	User *user = m_userManager->getUser(userName);
 
	if (!user) {
 
		// TODO: FIXME We have to remove filetransfer when use disconnects
 
		return;
 
	}
 
#if !HAVE_SWIFTEN_3
 
	if (state.state == Swift::FileTransfer::State::Transferring) {
 
		handleFTAccepted(user, buddyName, fileName, size, id);
 
	}
 
	else if (state.state == Swift::FileTransfer::State::Canceled) {
 
		handleFTRejected(user, buddyName, fileName, size);
 
	}
 
#endif
 
}
 
 
void NetworkPluginServer::sendPing(Backend *c) {
 
 
	std::string message;
 
	pbnetwork::WrapperMessage wrap;
 
	wrap.set_type(pbnetwork::WrapperMessage_Type_TYPE_PING);
 
	wrap.SerializeToString(&message);
 
 
	if (c->connection) {
 
		LOG4CXX_INFO(logger, "PING to " << c << " (ID=" << c->id << ")");
 
		send(c->connection, message);
src/settingsadhoccommand.cpp
Show inline comments
 
@@ -25,104 +25,139 @@
 
#include "transport/factory.h"
 
#include "transport/user.h"
 
#include "transport/logging.h"
 
#include "transport/storagebackend.h"
 
 
 
namespace Transport {
 
 
DEFINE_LOGGER(logger, "SettingsAdHocCommand");
 
 
SettingsAdHocCommand::SettingsAdHocCommand(Component *component, UserManager *userManager, StorageBackend *storageBackend, const Swift::JID &initiator, const Swift::JID &to) : AdHocCommand(component, userManager, storageBackend, initiator, to) {
 
	m_state = Init;
 
#if HAVE_SWIFTEN_3
 
	Swift::FormField::ref field = boost::make_shared<Swift::FormField>(Swift::FormField::BooleanType, "1");
 
#else
 
	Swift::BooleanFormField::ref field;
 
 
	field = Swift::BooleanFormField::create(true);
 
#endif
 
	field->setName("enable_transport");
 
	field->setLabel("Enable transport");
 
	addFormField(field);
 

	
 
#if HAVE_SWIFTEN_3
 
	field = boost::make_shared<Swift::FormField>(Swift::FormField::BooleanType, CONFIG_STRING_DEFAULTED(component->getConfig(), "settings.send_headlines", "0"));
 
#else
 
	field = Swift::BooleanFormField::create(CONFIG_STRING_DEFAULTED(component->getConfig(), "settings.send_headlines", "0") == "1");
 
#endif
 
	field->setName("send_headlines");
 
	field->setLabel("Allow sending messages as headlines");
 
	addFormField(field);
 

	
 
#if HAVE_SWIFTEN_3
 
	field = boost::make_shared<Swift::FormField>(Swift::FormField::BooleanType, CONFIG_STRING_DEFAULTED(component->getConfig(), "settings.stay_connected", "0"));
 
#else
 
	field = Swift::BooleanFormField::create(CONFIG_STRING_DEFAULTED(component->getConfig(), "settings.stay_connected", "0") == "1");
 
#endif
 
	field->setName("stay_connected");
 
	field->setLabel("Stay connected to legacy network when offline on XMPP");
 
	addFormField(field);
 
}
 
 
SettingsAdHocCommand::~SettingsAdHocCommand() {
 
}
 
 
boost::shared_ptr<Swift::Command> SettingsAdHocCommand::getForm() {
 
	if (!m_storageBackend) {
 
		boost::shared_ptr<Swift::Command> response(new Swift::Command("settings", m_id, Swift::Command::Completed));
 
		boost::shared_ptr<Swift::Form> form(new Swift::Form());
 
#if HAVE_SWIFTEN_3
 
		form->addField(boost::make_shared<Swift::FormField>(Swift::FormField::FixedType, "This server does not support transport settings. There is no storage backend configured"));
 
#else
 
		form->addField(Swift::FixedFormField::create("This server does not support transport settings. There is no storage backend configured"));
 
#endif
 
		response->setForm(form);
 
		return response;
 
	}
 
 
	UserInfo user;
 
	if (m_storageBackend->getUser(m_initiator.toBare().toString(), user) == false) {
 
		boost::shared_ptr<Swift::Command> response(new Swift::Command("settings", m_id, Swift::Command::Completed));
 
		boost::shared_ptr<Swift::Form> form(new Swift::Form());
 
#if HAVE_SWIFTEN_3
 
		form->addField(boost::make_shared<Swift::FormField>(Swift::FormField::FixedType, "You are not registered."));
 
#else
 
		form->addField(Swift::FixedFormField::create("You are not registered."));
 
#endif
 
		response->setForm(form);
 
		return response;
 
	}
 
 
	boost::shared_ptr<Swift::Command> response(new Swift::Command("settings", m_id, Swift::Command::Executing));
 
	boost::shared_ptr<Swift::Form> form(new Swift::Form());
 
 
	BOOST_FOREACH(Swift::FormField::ref field, m_fields) {
 
		// FIXME: Support for more types than boolean
 
#if HAVE_SWIFTEN_3
 
		if (field->getType() == Swift::FormField::BooleanType) {
 
			std::string value = field->getBoolValue() ? "1" : "0";
 
			int type = (int) TYPE_BOOLEAN;
 
			m_storageBackend->getUserSetting(user.id, field->getName(), type, value);
 
			field->setBoolValue(value == "1");
 
		}
 
#else
 
		if (boost::dynamic_pointer_cast<Swift::BooleanFormField>(field)) {
 
			Swift::BooleanFormField::ref f(boost::dynamic_pointer_cast<Swift::BooleanFormField>(field));
 
			std::string value = f->getValue() ? "1" : "0";
 
			int type = (int)TYPE_BOOLEAN;
 
			m_storageBackend->getUserSetting(user.id, f->getName(), type, value);
 
			f->setValue(value == "1");
 
		}
 
#endif			
 
 
		form->addField(field);
 
	}
 
 
	response->setForm(form);
 
	return response;
 
}
 
 
boost::shared_ptr<Swift::Command> SettingsAdHocCommand::handleResponse(boost::shared_ptr<Swift::Command> payload) {
 
	UserInfo user;
 
	bool registered = m_storageBackend->getUser(m_initiator.toBare().toString(), user);
 
 
	if (registered && payload->getForm()) {
 
		BOOST_FOREACH(Swift::FormField::ref field, m_fields) {
 
			Swift::FormField::ref received = payload->getForm()->getField(field->getName());
 
			if (!received) {
 
				continue;
 
			}
 

	
 
#if HAVE_SWIFTEN_3
 
			if (received->getType() == Swift::FormField::BooleanType) {
 
				std::string value = received->getBoolValue() ? "1" : "0";
 
				m_storageBackend->updateUserSetting(user.id, received->getName(), value);
 
			} else if (received->getType() == Swift::FormField::TextSingleType) {
 
				m_storageBackend->updateUserSetting(user.id, received->getName(), received->getTextSingleValue());
 
			}
 
#else
 
			// FIXME: Support for more types than boolean
 
			if (boost::dynamic_pointer_cast<Swift::BooleanFormField>(received)) {
 
				Swift::BooleanFormField::ref f(boost::dynamic_pointer_cast<Swift::BooleanFormField>(received));
 
				std::string value = f->getValue() ? "1" : "0";
 
				m_storageBackend->updateUserSetting(user.id, f->getName(), value);
 
			}
 
			else if (boost::dynamic_pointer_cast<Swift::TextSingleFormField>(received)) {
 
				Swift::TextSingleFormField::ref f(boost::dynamic_pointer_cast<Swift::TextSingleFormField>(received));
 
				m_storageBackend->updateUserSetting(user.id, f->getName(), f->getValue());
 
			}
 
#endif
 
		}
 
	}
 
 
	boost::shared_ptr<Swift::Command> response(new Swift::Command("settings", m_id, Swift::Command::Completed));
 
	return response;
 
}
 
 
boost::shared_ptr<Swift::Command> SettingsAdHocCommand::handleRequest(boost::shared_ptr<Swift::Command> payload) {
 
	boost::shared_ptr<Swift::Command> response;
 
	if (payload->getAction() == Swift::Command::Cancel) {
 
		response = boost::shared_ptr<Swift::Command>(new Swift::Command("settings", m_id, Swift::Command::Canceled));
 
		return response;
src/transport.cpp
Show inline comments
 
@@ -117,25 +117,29 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
		m_server->addPayloadSerializer(new Swift::XHTMLIMSerializer());
 
		m_server->addPayloadSerializer(new Transport::BlockSerializer());
 
		m_server->addPayloadSerializer(new Swift::InvisibleSerializer());
 
		m_server->addPayloadSerializer(new Swift::StatsSerializer());
 
		m_server->addPayloadSerializer(new Swift::SpectrumErrorSerializer());
 
		m_server->addPayloadSerializer(new Swift::GatewayPayloadSerializer());
 
 
		m_server->onDataRead.connect(boost::bind(&Component::handleDataRead, this, _1));
 
		m_server->onDataWritten.connect(boost::bind(&Component::handleDataWritten, this, _1));
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, "Creating component in gateway mode");
 
#if HAVE_SWIFTEN_3
 
		m_component = new Swift::Component(m_jid, CONFIG_STRING(m_config, "service.password"), m_factories);
 
#else
 
		m_component = new Swift::Component(loop, m_factories, m_jid, CONFIG_STRING(m_config, "service.password"));
 
#endif
 
		m_component->setSoftwareVersion("Spectrum", SPECTRUM_VERSION);
 
		m_component->onConnected.connect(bind(&Component::handleConnected, this));
 
		m_component->onError.connect(boost::bind(&Component::handleConnectionError, this, _1));
 
		m_component->onDataRead.connect(boost::bind(&Component::handleDataRead, this, _1));
 
		m_component->onDataWritten.connect(boost::bind(&Component::handleDataWritten, this, _1));
 
 
		m_component->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private"));
 
		m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0"));
 
		m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im"));
 
		m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0"));
 
		m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0"));
 
		m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats"));
 
@@ -146,25 +150,29 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
		m_component->addPayloadSerializer(new Swift::XHTMLIMSerializer());
 
		m_component->addPayloadSerializer(new Transport::BlockSerializer());
 
		m_component->addPayloadSerializer(new Swift::InvisibleSerializer());
 
		m_component->addPayloadSerializer(new Swift::StatsSerializer());
 
		m_component->addPayloadSerializer(new Swift::SpectrumErrorSerializer());
 
		m_component->addPayloadSerializer(new Swift::GatewayPayloadSerializer());
 
 
		m_stanzaChannel = m_component->getStanzaChannel();
 
		m_iqRouter = m_component->getIQRouter();
 
	}
 
 
	m_capsMemoryStorage = new CapsMemoryStorage();
 
#if HAVE_SWIFTEN_3
 
	m_capsManager = new CapsManager(m_capsMemoryStorage, m_stanzaChannel, m_iqRouter, m_factories->getCryptoProvider());
 
#else
 
	m_capsManager = new CapsManager(m_capsMemoryStorage, m_stanzaChannel, m_iqRouter);
 
#endif
 
	m_entityCapsManager = new EntityCapsManager(m_capsManager, m_stanzaChannel);
 
 	m_entityCapsManager->onCapsChanged.connect(boost::bind(&Component::handleCapsChanged, this, _1));
 
	
 
	m_presenceOracle = new Transport::PresenceOracle(m_stanzaChannel);
 
	m_presenceOracle->onPresenceChange.connect(bind(&Component::handlePresence, this, _1));
 
 
 
 
// 
 
// 	m_registerHandler = new SpectrumRegisterHandler(m_component);
 
// 	m_registerHandler->start();
 
}
src/user.cpp
Show inline comments
 
@@ -61,25 +61,29 @@ User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component, User
 
	m_reconnectTimer = m_component->getNetworkFactories()->getTimerFactory()->createTimer(5000);
 
	m_reconnectTimer->onTick.connect(boost::bind(&User::onConnectingTimeout, this)); 
 
 
	m_rosterManager = new RosterManager(this, m_component);
 
	m_conversationManager = new ConversationManager(this, m_component);
 
	LOG4CXX_INFO(logger, m_jid.toString() << ": Created");
 
	updateLastActivity();
 
}
 
 
User::~User(){
 
	LOG4CXX_INFO(logger, m_jid.toString() << ": Destroying");
 
	if (m_component->inServerMode()) {
 
#if HAVE_SWIFTEN_3
 
		dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::ToplevelElement>());
 
#else
 
		dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>());
 
#endif
 
	}
 
 
	m_reconnectTimer->stop();
 
	delete m_rosterManager;
 
	delete m_conversationManager;
 
}
 
 
const Swift::JID &User::getJID() {
 
	return m_jid;
 
}
 
 
std::vector<Swift::JID> User::getJIDWithFeature(const std::string &feature) {
 
@@ -478,23 +482,27 @@ void User::handleDisconnected(const std::string &error, Swift::SpectrumErrorPayl
 
	msg->setFrom(m_component->getJID());
 
	msg->addPayload(boost::make_shared<Swift::SpectrumErrorPayload>(e));
 
	m_component->getStanzaChannel()->sendMessage(msg);
 
 
	// In server mode, server finishes the session and pass unavailable session to userManager if we're connected to legacy network,
 
	// so we can't removeUser() in server mode, because it would be removed twice.
 
	// Once in finishSession and once in m_userManager->removeUser.
 
	if (m_component->inServerMode()) {
 
		// Remove user later just to be sure there won't be double-free.
 
		// We can't be sure finishSession sends unavailable presence everytime, so check if user gets removed
 
		// in finishSession(...) call and if not, remove it here.
 
		std::string jid = m_jid.toBare().toString();
 
#if HAVE_SWIFTEN_3
 
		dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::ToplevelElement>(new Swift::StreamError(Swift::StreamError::UndefinedCondition, error)));
 
#else
 
		dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>(new Swift::StreamError(Swift::StreamError::UndefinedCondition, error)));
 
#endif
 
		if (m_userManager->getUser(jid) != NULL) {
 
			m_userManager->removeUser(this);
 
		}
 
	}
 
	else {
 
		m_userManager->removeUser(this);
 
	}
 
}
 
 
}
src/usermanager.cpp
Show inline comments
 
@@ -557,25 +557,29 @@ void UserManager::connectUser(const Swift::JID &user) {
 
			else {
 
				// Send message to currently logged in session
 
				boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
				msg->setBody("You have signed on from another location.");
 
				msg->setTo(user);
 
				msg->setFrom(m_component->getJID());
 
				m_component->getStanzaChannel()->sendMessage(msg);
 
 
				// Switch the session = accept new one, disconnect old one.
 
				// Unavailable presence from old session has to be ignored, otherwise it would disconnect the user from legacy network.
 
				m_userRegistry->onPasswordValid(user);
 
				m_component->onUserPresenceReceived.disconnect(bind(&UserManager::handlePresence, this, _1));
 
#if HAVE_SWIFTEN_3
 
				dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(user, boost::shared_ptr<Swift::ToplevelElement>(new Swift::StreamError()), true);
 
#else				
 
				dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(user, boost::shared_ptr<Swift::Element>(new Swift::StreamError()), true);
 
#endif
 
				m_component->onUserPresenceReceived.connect(bind(&UserManager::handlePresence, this, _1));
 
			}
 
		}
 
		else {
 
			// User is created, but not connected => he's loggin in or he just logged out, but hasn't been deleted yet.
 
			// Stop deletion process if there's any
 
			m_removeTimer->onTick.disconnect(boost::bind(&UserManager::handleRemoveTimeout, this, user.toBare().toString(), m_users[user.toBare().toString()], false));
 
 
			// Delete old User instance but create new one immediatelly
 
			m_removeTimer->onTick.connect(boost::bind(&UserManager::handleRemoveTimeout, this, user.toBare().toString(), m_users[user.toBare().toString()], true));
 
			m_removeTimer->start();
 
		}
src/userregistration.cpp
Show inline comments
 
@@ -24,24 +24,27 @@
 
#include "transport/transport.h"
 
#include "transport/rostermanager.h"
 
#include "transport/user.h"
 
#include "transport/logging.h"
 
#include "Swiften/Elements/ErrorPayload.h"
 
#include "Swiften/EventLoop/SimpleEventLoop.h"
 
#include "Swiften/Network/BoostNetworkFactories.h"
 
#include "Swiften/Client/Client.h"
 
#include <boost/shared_ptr.hpp>
 
#include <boost/thread.hpp>
 
#include <boost/date_time/posix_time/posix_time.hpp>
 
#include <boost/regex.hpp> 
 
#if HAVE_SWIFTEN_3
 
#include <Swiften/Elements/Form.h>
 
#endif
 
 
using namespace Swift;
 
 
namespace Transport {
 
 
DEFINE_LOGGER(logger, "UserRegistration");
 
 
UserRegistration::UserRegistration(Component *component, UserManager *userManager, StorageBackend *storageBackend) : Swift::Responder<Swift::InBandRegistrationPayload>(component->m_iqRouter) {
 
	m_component = component;
 
	m_config = m_component->m_config;
 
	m_storageBackend = storageBackend;
 
	m_userManager = userManager;
 
@@ -236,79 +239,112 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
 
	reg->setInstructions(instructions);
 
	reg->setRegistered(registered);
 
	reg->setUsername(res.uin);
 
	if (CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true)) {
 
		reg->setPassword("");
 
	}
 
 
 
	// form
 
	Form::ref form(new Form(Form::FormType));
 
	form->setTitle((("Registration")));
 
	form->setInstructions((instructions));
 

	
 
#if HAVE_SWIFTEN_3
 
	FormField::ref type = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:register");	
 
#else
 
	HiddenFormField::ref type = HiddenFormField::create();
 
	type->setName("FORM_TYPE");
 
	type->setValue("jabber:iq:register");
 
#endif
 
	type->setName("FORM_TYPE");
 
	form->addField(type);
 

	
 
#if HAVE_SWIFTEN_3
 
	FormField::ref username = boost::make_shared<FormField>(FormField::TextSingleType, res.uin);
 
#else
 
	TextSingleFormField::ref username = TextSingleFormField::create();
 
	username->setValue(res.uin);
 
#endif
 
	username->setName("username");
 
	username->setLabel((usernameField));
 
	username->setValue(res.uin);
 
	username->setRequired(true);
 
	form->addField(username);
 
 
	if (CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true)) {
 
#if HAVE_SWIFTEN_3
 
		FormField::ref password = boost::make_shared<FormField>(FormField::TextPrivateType);
 
#else
 
		TextPrivateFormField::ref password = TextPrivateFormField::create();
 
#endif
 
		password->setName("password");
 
		password->setLabel((("Password")));
 
		password->setRequired(true);
 
		form->addField(password);
 
	}
 

	
 
#if HAVE_SWIFTEN_3
 
	FormField::ref language = boost::make_shared<FormField>(FormField::ListSingleType);
 
#else
 
	ListSingleFormField::ref language = ListSingleFormField::create();
 
#endif
 
	language->setName("language");
 
	language->setLabel((("Language")));
 
	language->addOption(Swift::FormField::Option(CONFIG_STRING(m_config, "registration.language"), CONFIG_STRING(m_config, "registration.language")));
 
	if (registered)
 
#if HAVE_SWIFTEN_3
 
		language->addValue(res.language);
 
#else
 
		language->setValue(res.language);
 
#endif
 
	else
 
#if HAVE_SWIFTEN_3
 
		language->addValue(CONFIG_STRING(m_config, "registration.language"));
 
#else
 
		language->setValue(CONFIG_STRING(m_config, "registration.language"));
 
#endif
 
	form->addField(language);
 
 
//	TextSingleFormField::ref encoding = TextSingleFormField::create();
 
//	encoding->setName("encoding");
 
//	encoding->setLabel((("Encoding")));
 
//	if (registered)
 
//		encoding->setValue(res.encoding);
 
//	else
 
//		encoding->setValue(CONFIG_STRING(m_config, "registration.encoding"));
 
//	form->addField(encoding);
 
 
	if (registered) {
 
#if HAVE_SWIFTEN_3
 
		FormField::ref boolean = boost::make_shared<FormField>(FormField::BooleanType, "0");
 
#else
 
		BooleanFormField::ref boolean = BooleanFormField::create();
 
		boolean->setValue(0);
 
#endif
 
		boolean->setName("unregister");
 
		boolean->setLabel((("Remove your registration")));		
 
		boolean->setValue(0);
 
		form->addField(boolean);
 
	} else {
 
		if (CONFIG_BOOL(m_config,"registration.require_local_account")) {
 
			std::string localUsernameField = CONFIG_STRING(m_config, "registration.local_username_label");
 
#if HAVE_SWIFTEN_3
 
			FormField::ref local_username = boost::make_shared<FormField>(FormField::TextSingleType);
 
#else
 
			TextSingleFormField::ref local_username = TextSingleFormField::create();
 
#endif
 
			local_username->setName("local_username");
 
			local_username->setLabel((localUsernameField));
 
			local_username->setRequired(true);
 
			form->addField(local_username);
 
#if HAVE_SWIFTEN_3
 
			FormField::ref local_password = boost::make_shared<FormField>(FormField::TextPrivateType);
 
#else
 
			TextPrivateFormField::ref local_password = TextPrivateFormField::create();
 
#endif
 
			local_password->setName("local_password");
 
			local_password->setLabel((("Local Password")));
 
			local_password->setRequired(true);
 
			form->addField(local_password);
 
		}
 
	}
 
 
	reg->setForm(form);
 
 
	sendResponse(from, id, reg);
 
 
	return true;
 
@@ -335,75 +371,132 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
 
	UserInfo res;
 
	bool registered = m_storageBackend->getUser(barejid, res);
 
 
	std::string encoding;
 
	std::string language;
 
	std::string local_username("");
 
	std::string local_password("");
 
 
	Form::ref form = payload->getForm();
 
	if (form) {
 
		const std::vector<FormField::ref> fields = form->getFields();
 
		for (std::vector<FormField::ref>::const_iterator it = fields.begin(); it != fields.end(); it++) {
 
#if HAVE_SWIFTEN_3
 
			FormField::ref textSingle = *it;
 
			if (textSingle->getType() == FormField::TextSingleType) {
 
#else
 
			TextSingleFormField::ref textSingle = boost::dynamic_pointer_cast<TextSingleFormField>(*it);
 
			if (textSingle) {
 
#endif
 
				if (textSingle->getName() == "username") {
 
#if HAVE_SWIFTEN_3
 
					payload->setUsername(textSingle->getTextSingleValue());
 
#else
 
					payload->setUsername(textSingle->getValue());
 
#endif
 
				}
 
				else if (textSingle->getName() == "encoding") {
 
#if HAVE_SWIFTEN_3
 
					encoding = textSingle->getTextSingleValue();
 
#else
 
					encoding = textSingle->getValue();
 
#endif
 
				}
 
				// Pidgin sends it as textSingle, not sure why...
 
				else if (textSingle->getName() == "password") {
 
#if HAVE_SWIFTEN_3
 
					payload->setPassword(textSingle->getTextSingleValue());
 
#else
 
					payload->setPassword(textSingle->getValue());
 
#endif
 
				}
 
				else if (textSingle->getName() == "local_username") {
 
#if HAVE_SWIFTEN_3
 
					local_username = textSingle->getTextSingleValue();
 
#else
 
					local_username = textSingle->getValue();
 
#endif
 
				}
 
				// Pidgin sends it as textSingle, not sure why...
 
				else if (textSingle->getName() == "local_password") {
 
#if HAVE_SWIFTEN_3
 
					local_password = textSingle->getTextSingleValue();
 
#else
 
					local_password = textSingle->getValue();
 
#endif
 
				}
 
				// Pidgin sends it as textSingle, not sure why...
 
				else if (textSingle->getName() == "unregister") {
 
#if HAVE_SWIFTEN_3
 
					if (textSingle->getTextSingleValue() == "1" || textSingle->getTextSingleValue() == "true") {
 
#else
 
					if (textSingle->getValue() == "1" || textSingle->getValue() == "true") {
 
#endif
 
						payload->setRemove(true);
 
					}
 
				}
 
				continue;
 
			}
 

	
 
#if HAVE_SWIFTEN_3
 
			FormField::ref textPrivate = *it;
 
			if (textPrivate->getType() == FormField::TextPrivateType) {
 
#else
 
			TextPrivateFormField::ref textPrivate = boost::dynamic_pointer_cast<TextPrivateFormField>(*it);
 
			if (textPrivate) {
 
#endif
 
				if (textPrivate->getName() == "password") {
 
#if HAVE_SWIFTEN_3
 
					payload->setPassword(textPrivate->getTextPrivateValue());
 
#else
 
					payload->setPassword(textPrivate->getValue());
 
#endif
 
				}
 
				else if (textPrivate->getName() == "local_password") {
 
#if HAVE_SWIFTEN_3
 
					local_password = textPrivate->getTextPrivateValue();
 
#else
 
					local_password = textPrivate->getValue();
 
#endif
 
				}
 
				continue;
 
			}
 

	
 
#if HAVE_SWIFTEN_3
 
			FormField::ref listSingle = *it;
 
			if (listSingle->getType() == FormField::ListSingleType) {
 
#else
 
			ListSingleFormField::ref listSingle = boost::dynamic_pointer_cast<ListSingleFormField>(*it);
 
			if (listSingle) {
 
#endif
 
				if (listSingle->getName() == "language") {
 
#if HAVE_SWIFTEN_3
 
					language = listSingle->getValues()[0];
 
#else
 
					language = listSingle->getValue();
 
#endif
 
				}
 
				continue;
 
			}
 

	
 
#if HAVE_SWIFTEN_3
 
			FormField::ref boolean = *it;
 
			if (boolean->getType() == FormField::BooleanType) {
 
#else
 
			BooleanFormField::ref boolean = boost::dynamic_pointer_cast<BooleanFormField>(*it);
 
			if (boolean) {
 
#endif
 
				if (boolean->getName() == "unregister") {
 
#if HAVE_SWIFTEN_3
 
					if (boolean->getBoolValue()) {
 
#else
 
					if (boolean->getValue()) {
 
#endif
 
						payload->setRemove(true);
 
					}
 
				}
 
				continue;
 
			}
 
		}
 
	}
 
 
	if (payload->isRemove()) {
 
		unregisterUser(barejid);
 
		sendResponse(from, id, InBandRegistrationPayload::ref());
 
		return true;
0 comments (0 inline, 0 general)