Changeset - 0d99e8c85d38
[Not reviewed]
34 31 0
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
 
@@ -74,13 +74,12 @@ if(NOT SWIFTEN_FOUND)
 
	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)
 
@@ -112,12 +111,13 @@ 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")
backends/swiften/main.cpp
Show inline comments
 
@@ -4,12 +4,14 @@
 
#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"
 
@@ -84,14 +86,17 @@ class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
 
			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.");
 
		}
 
 
@@ -110,14 +115,17 @@ class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
 
			}
 
			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();
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
 
@@ -646,13 +646,17 @@ void TwitterPlugin::populateRoster(std::string &user, std::vector<User> &friends
 
			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(), 
 
@@ -818,13 +822,17 @@ void TwitterPlugin::createFriendResponse(std::string &user, User &frnd, std::str
 
	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)
backends/twitter/TwitterPlugin.h
Show inline comments
 
@@ -29,15 +29,20 @@
 
#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 + ")")
 
 
@@ -48,12 +53,15 @@ 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();
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
#define NOMINMAX
 
#include <algorithm>
 
#include <memory.h>
 
#include "twitcurlurls.h"
 
#include "twitcurl.h"
 
#include "urlencode.h"
 
 
/*++
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)
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
 
@@ -40,14 +40,16 @@ boost::shared_ptr<OutgoingFileTransfer> CombinedOutgoingFileTransferManager::cre
 
	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>();
 
	}
 
	
include/Swiften/FileTransfer/CombinedOutgoingFileTransferManager.h
Show inline comments
 
@@ -9,12 +9,15 @@
 
#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;
include/Swiften/FileTransfer/MyOutgoingSIFileTransfer.cpp
Show inline comments
 
@@ -37,73 +37,80 @@ 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
 
@@ -15,12 +15,14 @@
 
#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;
 
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
 
@@ -4,15 +4,13 @@
 
 * 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>
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
 
@@ -73,13 +73,13 @@ void ServerFromClientSession::handlePasswordInvalid(const std::string &error) {
 
		}
 
		
 
		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")) {
include/Swiften/Server/ServerFromClientSession.h
Show inline comments
 
@@ -13,12 +13,14 @@
 
#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;
 
@@ -57,13 +59,17 @@ namespace Swift {
 
			}
 
 
			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; 
include/Swiften/Server/ServerStanzaChannel.cpp
Show inline comments
 
@@ -60,14 +60,17 @@ void ServerStanzaChannel::handleDataRead(const SafeByteArray &data, const boost:
 
		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) {
include/Swiften/Server/ServerStanzaChannel.h
Show inline comments
 
@@ -12,26 +12,30 @@
 
#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;
include/transport/filetransfermanager.h
Show inline comments
 
@@ -16,22 +16,32 @@
 
 * 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;
 
@@ -56,13 +66,18 @@ class FileTransferManager {
 
		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
 
@@ -32,12 +32,14 @@
 
#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;
 
@@ -156,15 +158,17 @@ class NetworkPluginServer : Swift::XMPPParserClient {
 
		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;
include/transport/settingsadhoccommand.h
Show inline comments
 
@@ -22,12 +22,14 @@
 
 
#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;
include/transport/userregistration.h
Show inline comments
 
@@ -21,12 +21,14 @@
 
#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;
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
 
@@ -41,12 +41,15 @@ DiscoInfoResponder::DiscoInfoResponder(Swift::IQRouter *router, Config *config)
 
	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;
 
@@ -90,14 +93,17 @@ void DiscoInfoResponder::setBuddyFeatures(std::list<std::string> &f) {
 
 
	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;
src/discoinforesponder.h
Show inline comments
 
@@ -23,12 +23,19 @@
 
#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> {
 
@@ -57,9 +64,12 @@ class DiscoInfoResponder : public Swift::GetResponder<Swift::DiscoInfo> {
 
		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
 
@@ -32,44 +32,57 @@ 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();
src/networkpluginserver.cpp
Show inline comments
 
@@ -268,13 +268,17 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
 
	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));
 
@@ -831,14 +835,16 @@ void NetworkPluginServer::handleFTStartPayload(const std::string &data) {
 
	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
 
@@ -988,14 +994,17 @@ void NetworkPluginServer::handleRoomListPayload(const std::string &data) {
 
 
	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());
 
@@ -1874,18 +1883,20 @@ void NetworkPluginServer::handleFTRejected(User *user, const std::string &buddyN
 
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;
src/settingsadhoccommand.cpp
Show inline comments
 
@@ -31,63 +31,90 @@
 
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;
 
@@ -100,23 +127,31 @@ boost::shared_ptr<Swift::Command> SettingsAdHocCommand::handleResponse(boost::sh
 
	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;
 
}
src/transport.cpp
Show inline comments
 
@@ -123,13 +123,17 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
 
		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));
 
 
@@ -152,13 +156,17 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
 
		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));
 
src/user.cpp
Show inline comments
 
@@ -67,13 +67,17 @@ User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component, User
 
	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;
 
}
 
@@ -484,13 +488,17 @@ void User::handleDisconnected(const std::string &error, Swift::SpectrumErrorPayl
 
	// 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
 
@@ -563,13 +563,17 @@ void UserManager::connectUser(const Swift::JID &user) {
 
				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
src/userregistration.cpp
Show inline comments
 
@@ -30,12 +30,15 @@
 
#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");
 
@@ -242,67 +245,100 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
 
 
 
	// 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);
 
		}
 
	}
 
@@ -341,63 +377,120 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
 
	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;
 
			}
 
		}
0 comments (0 inline, 0 general)