Changeset - 1c04886a3686
[Not reviewed]
0 6 0
Vitaly Takmazov - 10 years ago 2016-01-21 13:58:35
vitalyster@gmail.com
win32 build fixes
6 files changed with 21 insertions and 11 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -85,399 +85,398 @@ 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)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread-mt signals)
 
	if (NOT Boost_FOUND)
 
		set(Boost_FIND_QUIETLY OFF)
 
		find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
	endif()
 
endif(WIN32)
 

	
 
message( STATUS "Found Boost: ${Boost_VERSION}, ${Boost_LIBRARIES}, ${Boost_INCLUDE_DIR}")
 

	
 
if (${Boost_VERSION} GREATER 104999)
 
	message( STATUS "Using BOOST_FILESYSTEM_VERSION=3")
 
	add_definitions(-DBOOST_FILESYSTEM_VERSION=3)
 
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
 
if(ENABLE_MYSQL)
 
	set(mysql_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(mysql)
 
endif()
 

	
 
# FIND PQXX
 
if(ENABLE_PQXX)
 
	set(pqxx_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(pqxx)
 
endif()
 

	
 
###### Plugins ######
 

	
 
# FIND LIBPURPLE
 
if(ENABLE_PURPLE)
 
	set(purple_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(purple)
 

	
 
	if (WIN32)
 
		if (PURPLE_NOT_RUNTIME)
 
			add_definitions(-DPURPLE_RUNTIME=0)
 
		else(PURPLE_NOT_RUNTIME)
 
			add_definitions(-DPURPLE_RUNTIME=1)
 
		endif(PURPLE_NOT_RUNTIME)
 
	else()
 
		add_definitions(-DPURPLE_RUNTIME=0)
 
	endif()
 

	
 
	# FIND LIBEVENT
 
	set(event_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(event)
 
endif()
 

	
 
# FIND GLIB
 
if(ENABLE_SKYPE OR ENABLE_PURPLE)
 
#	if (GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
 
#		set(GLIB2_FOUND TRUE)
 
#	else()
 
		set(glib_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
		find_package(glib)
 
#	endif()
 
endif()
 

	
 
# FIND LIBXML2
 
# set(libxml2_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
# find_package(libxml2)
 

	
 
# FIND PROTOBUF
 
set(Protobuf_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(Protobuf REQUIRED)
 

	
 
if (NOT PROTOBUF_FOUND AND PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY)
 
	set(PROTOBUF_FOUND 1)
 
	set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIR})
 
	if (PROTOBUF_PROTOC_EXECUTABLE)
 
	else()
 
		set(PROTOBUF_PROTOC_EXECUTABLE protoc)
 
	endif()
 
	message(STATUS "Using protobuf: ${PROTOBUF_INCLUDE_DIRS} ${PROTOBUF_LIBRARY}")
 
endif()
 

	
 
if (WIN32)
 
	add_definitions(-DSWIFTEN_STATIC=1)
 
	ADD_DEFINITIONS(-D_UNICODE)
 
	ADD_DEFINITIONS(-DUNICODE)
 
endif()
 

	
 

	
 
if (CMAKE_COMPILER_IS_GNUCXX)
 
set(openssl_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(openssl)
 
endif()
 

	
 
if(ENABLE_IRC)
 
	set(Communi_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(Communi)
 

	
 
	INCLUDE(FindQt4)
 
	FIND_PACKAGE(Qt4 COMPONENTS QtCore QtNetwork)
 
	# ADD_DEFINITIONS(${SWIFTEN_CFLAGS})
 
	ADD_DEFINITIONS(-DSUPPORT_LEGACY_CAPS)
 
	# ADD_DEFINITIONS(-DBOOST_FILESYSTEM_VERSION=2)
 
endif()
 

	
 
set(event_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(event)
 

	
 
if (NOT WIN32 AND ENABLE_SKYPE)
 
set(dbus_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(dbus)
 
endif()
 

	
 

	
 
####### Miscallanous ######
 

	
 
if(ENABLE_DOCS)
 
	find_package(Doxygen)
 
endif()
 

	
 
# if(ENABLE_LOG)
 
	if(LOG4CXX_INCLUDE_DIR AND LOG4CXX_LIBRARY)
 
		set(LOG4CXX_LIBRARIES ${LOG4CXX_LIBRARY})
 
		set(LOG4CXX_FOUND 1)
 
		message(STATUS "Using log4cxx: ${CPPUNIT_INCLUDE_DIR} ${LOG4CXX_INCLUDE_DIR}")
 
	else()
 
		set(log4cxx_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
		find_package(log4cxx)
 
	endif()
 
# endif()
 

	
 
# FIND CPPUNIT
 
if(ENABLE_TESTS)
 
	set(cppunit_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(cppunit)
 

	
 
	if(NOT CPPUNIT_FOUND AND CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY)
 
		set(CCPUNIT_LIBRARIES ${CPPUNIT_LIBRARY})
 
		set(CPPUNIT_FOUND 1)
 
		message(STATUS "Using cppunit: ${CPPUNIT_INCLUDE_DIR} ${CPPUNIT_LIBRARIES}")
 
	endif()
 
endif()
 

	
 
message("  Supported features")
 
message("-----------------------")
 

	
 
if (SPECTRUM_VERSION)
 
	ADD_DEFINITIONS(-DSPECTRUM_VERSION="${SPECTRUM_VERSION}")
 
else (SPECTRUM_VERSION)
 
	if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
 
		if (NOT GIT_EXECUTABLE)
 
		set (GIT_EXECUTABLE git)
 
		endif()
 
		execute_process(COMMAND ${GIT_EXECUTABLE} "--git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git" rev-parse --short HEAD
 
						OUTPUT_VARIABLE GIT_REVISION
 
						OUTPUT_STRIP_TRAILING_WHITESPACE
 
		)
 
		set(SPECTRUM_VERSION 2.0.0-git-${GIT_REVISION})
 
		ADD_DEFINITIONS(-DSPECTRUM_VERSION="${SPECTRUM_VERSION}")
 
	else (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
 
		set(SPECTRUM_VERSION 2.0.0)
 
		ADD_DEFINITIONS(-DSPECTRUM_VERSION="${SPECTRUM_VERSION}")
 
	endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
 
endif (SPECTRUM_VERSION)
 

	
 
message("Version           : " ${SPECTRUM_VERSION})
 

	
 
if (SQLITE3_FOUND)
 
	ADD_DEFINITIONS(-DWITH_SQLITE)
 
	include_directories(${SQLITE3_INCLUDE_DIR})
 
	message("SQLite3           : yes")
 
else (SQLITE3_FOUND)
 
if (WIN32)
 
		ADD_DEFINITIONS(-DWITH_SQLITE)
 
	include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/sqlite3")
 
	message("SQLite3           : bundled")
 
	else()
 
else (WIN32)
 
	include_directories(${SQLITE3_INCLUDE_DIR})
 
	message("SQLite3           : yes")
 
endif (WIN32)
 
else (SQLITE3_FOUND)
 
	set(SQLITE3_LIBRARIES "")
 
	if(ENABLE_SQLITE3)
 
		message("SQLite3           : no (install sqlite3)")
 
	else(ENABLE_SQLITE3)
 
		message("SQLite3           : no (user disabled)")
 
	endif()
 
	endif()
 
endif (SQLITE3_FOUND)
 

	
 
if (MYSQL_FOUND)
 
	ADD_DEFINITIONS(-DWITH_MYSQL)
 
	include_directories(${MYSQL_INCLUDE_DIR})
 
	message("MySQL             : yes")
 
else (MYSQL_FOUND)
 
	set(MYSQL_LIBRARIES "")
 
	if(ENABLE_MYSQL)
 
		message("MySQL             : no (install mysql-devel)")
 
	else(ENABLE_MYSQL)
 
		message("MySQL             : no (user disabled)")
 
	endif()
 
endif (MYSQL_FOUND)
 

	
 
if (PQXX_FOUND)
 
	ADD_DEFINITIONS(-DWITH_PQXX)
 
	include_directories(${PQXX_INCLUDE_DIR})
 
	message("PostgreSQL        : yes")
 
else (PQXX_FOUND)
 
	set(PQXX_LIBRARY "")
 
	set(PQ_LIBRARY "")
 
	if(ENABLE_PQXX)
 
		message("PostgreSQL        : no (install libpqxx-devel)")
 
	else(ENABLE_PQXX)
 
		message("PostgreSQL        : no (user disabled)")
 
	endif()
 
endif (PQXX_FOUND)
 

	
 
if (PROTOBUF_FOUND)
 
	ADD_DEFINITIONS(-DWITH_PROTOBUF)
 
	include_directories(${PROTOBUF_INCLUDE_DIRS})
 
	message("Network plugins   : yes")
 

	
 
	if(PURPLE_FOUND)
 
		message("Libpurple plugin  : yes")
 
		include_directories(${PURPLE_INCLUDE_DIR})
 
		include_directories(${GLIB2_INCLUDE_DIR})
 
	else()
 
		if(ENABLE_PURPLE)
 
			message("Libpurple plugin  : no (install libpurple)")
 
		else(ENABLE_PURPLE)
 
			message("Libpurple plugin  : no (user disabled)")
 
		endif()
 
	endif()
 

	
 
	if (HAVE_EVENT)
 
		ADD_DEFINITIONS(-DWITH_LIBEVENT)
 
		include_directories(${EVENT_INCLUDE_DIRS})
 
		message("  libev eventloop : yes")
 
	else()
 
		if(ENABLE_PURPLE)
 
			message("  libev eventloop : no (install libev-devel)")
 
		endif()
 
	endif()
 

	
 
	if(IRC_FOUND)
 
		ADD_DEFINITIONS(-DIRC_SHARED)
 
		message("IRC plugin        : yes")
 
		include_directories(${QT_QTNETWORK_INCLUDE_DIR})
 
		include_directories(${IRC_INCLUDE_DIR})
 
		include(${QT_USE_FILE})
 
	else()
 
		if(ENABLE_IRC)
 
			message("IRC plugin        : no (install libCommuni and libprotobuf-dev)")
 
		else(ENABLE_IRC)
 
			message("IRC plugin        : no (user disabled)")
 
		endif()
 
	endif()
 
	if(ENABLE_TWITTER)
 
		message("Twitter plugin    : yes")
 
	else(ENABLE_TWITTER)
 
		message("Twitter plugin    : no (user disabled)")
 
	endif()
 
	if (NOT WIN32)
 
		if(ENABLE_FROTZ)
 
			message("Frotz plugin      : yes")
 
		else()
 
			message("Frotz plugin      : no (user disabled)")
 
		endif()
 
		if(ENABLE_SMSTOOLS3)
 
			message("SMSTools3 plugin  : yes")
 
		else()
 
			message("SMSTools3 plugin  : no (user disabled)")
 
		endif()
 
		if(${LIBDBUSGLIB_FOUND})
 
			message("Skype plugin      : yes")
 
			include_directories(${LIBDBUSGLIB_INCLUDE_DIRS})
 
		else()
 
			if(ENABLE_SKYPE)
 
				message("Skype plugin      : no (install dbus-glib-devel)")
 
			else(ENABLE_SKYPE)
 
				message("Skype plugin      : no (user disabled)")
 
			endif()
 
		endif()
 
	else()
 
		message("Frotz plugin      : no (does not run on Win32)")
 
		message("SMSTools3 plugin  : no (does not run on Win32)")
 
		message("Skype plugin      : no (does not run on Win32)")
 
	endif()
 

	
 
	if(ENABLE_SWIFTEN)
 
		message("Swiften plugin    : yes")
 
	else()
 
		message("Swiften plugin    : no (user disabled)")
 
	endif()
 
else()
 
	message("Network plugins   : no (install libprotobuf-dev)")
 
	message("Libpurple plugin  : no (install libpurple and libprotobuf-dev)")
 
	message("IRC plugin        : no (install libircclient-qt and libprotobuf-dev)")
 
	message("Frotz plugin      : no (install libprotobuf-dev)")
 
	message("SMSTools3 plugin  : no (install libprotobuf-dev)")
 
	message("Swiften plugin    : no (install libprotobuf-dev)")
 
    message("Twitter plugin    : no (install libprotobuf-dev)")
 
endif()
 

	
 
if (LOG4CXX_FOUND)
 
	message("Log4cxx           : yes")
 
	include_directories(${LOG4CXX_INCLUDE_DIR})
 
	ADD_DEFINITIONS(-DWITH_LOG4CXX)
 
else()
 
	set(LOG4CXX_LIBRARIES "")
 
	if (WIN32)
 
		message("Log4cxx           : no (install log4cxx-devel)")
 
	else()
 
		message(FATAL_ERROR "Log4cxx           : no (install log4cxx-devel)")
 
	endif()
 
endif()
 

	
 
if (WIN32)
 
	ADD_DEFINITIONS(-DLOG4CXX_STATIC)
 
	ADD_DEFINITIONS(-D_WIN32_WINNT=0x501)
 
	ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN)
 
	ADD_DEFINITIONS(-DBOOST_USE_WINDOWS_H)
 
	ADD_DEFINITIONS(-DBOOST_THREAD_USE_LIB)
 
endif()
 

	
 
# We cannot use boost:signals2, because Swiften does not use them,
 
# for now, just ignore the deprecation warning.
 
ADD_DEFINITIONS(-DBOOST_SIGNALS_NO_DEPRECATION_WARNING)
 

	
 
if(CMAKE_BUILD_TYPE MATCHES Debug)
 
	if (CMAKE_COMPILER_IS_GNUCXX)
 
		ADD_DEFINITIONS(-O0)
 
		ADD_DEFINITIONS(-ggdb)
 
	endif()
 
	ADD_DEFINITIONS(-DDEBUG)
 
	message("Debug             : yes")
 
else(CMAKE_BUILD_TYPE MATCHES Debug)
 
	message("Debug             : no (run \"cmake . -DCMAKE_BUILD_TYPE=Debug\")")
 
endif(CMAKE_BUILD_TYPE MATCHES Debug)
 

	
 

	
 
SET(TRANSPORT_VERSION 2.0)
 
SET(PROJECT_VERSION 2.0)
 
include_directories(include)
 

	
 

	
 
include_directories(${EVENT_INCLUDE_DIRS})
 
include_directories(${SWIFTEN_INCLUDE_DIR})
 
include_directories(${Boost_INCLUDE_DIRS})
 

	
 
if (CMAKE_COMPILER_IS_GNUCXX)
 
include_directories(${OPENSSL_INCLUDE_DIR})
 
endif()
 

	
 
ADD_SUBDIRECTORY(libtransport)
 
ADD_SUBDIRECTORY(plugin)
 
ADD_SUBDIRECTORY(include)
 
ADD_SUBDIRECTORY(spectrum)
 
ADD_SUBDIRECTORY(backends)
 
ADD_SUBDIRECTORY(tests)
 
if (NOT WIN32)
 
	ADD_SUBDIRECTORY(spectrum_manager)
 
#	ADD_SUBDIRECTORY(spectrum2_send_message)
 
endif()
 

	
 
if (CPPUNIT_FOUND)
 
	message("tests             : yes")
 
	include_directories(${CPPUNIT_INCLUDE_DIR})
 
else()
 
	if(ENABLE_TESTS)
 
		message("tests             : no (install CPPUnit)")
 
	else(ENABLE_TESTS)
 
		message("tests             : no (user disabled)")
 
	endif()
 
endif()
 

	
 
if(DOXYGEN_FOUND)
 
	message("Docs              : yes")
 
	ADD_SUBDIRECTORY(docs)
 
else(DOXYGEN_FOUND)
backends/twitter/libtwitcurl/twitcurl.h
Show inline comments
 
#ifndef _TWITCURL_H_
 
#define _TWITCURL_H_
 

	
 
#include <string>
 
#include <sstream>
 
#include <cstring>
 
#include <vector>
 
#include <algorithm>
 
#include "oauthlib.h"
 
#include "curl/curl.h"
 

	
 
/* Few common types used by twitCurl */
 
namespace twitCurlTypes
 
{
 
    typedef enum _eTwitCurlApiFormatType
 
    {
 
        eTwitCurlApiFormatJson = 0,
 
        eTwitCurlApiFormatXml,
 
        eTwitCurlApiFormatMax
 
    } eTwitCurlApiFormatType;
 

	
 
    typedef enum _eTwitCurlProtocolType
 
    {
 
        eTwitCurlProtocolHttps = 0,
 
        eTwitCurlProtocolHttp,
 
        eTwitCurlProtocolMax
 
    } eTwitCurlProtocolType;
 
};
 

	
 
/* twitCurl class */
 
class twitCurl
 
{
 
public:
 
    twitCurl();
 
    ~twitCurl();
 

	
 
    /* Twitter OAuth authorization methods */
 
    oAuth& getOAuth();
 
    bool oAuthRequestToken( std::string& authorizeUrl /* out */ );
 
    bool oAuthAccessToken();
 
    bool oAuthHandlePIN( const std::string& authorizeUrl /* in */ );
 

	
 
    /* Twitter login APIs, set once and forget */
 
    std::string& getTwitterUsername();
 
    std::string& getTwitterPassword();
 
    void setTwitterUsername( std::string& userName /* in */ );
 
    void setTwitterPassword( std::string& passWord /* in */ );
 

	
 
    /* Twitter search APIs */
 
    bool search( std::string& searchQuery /* in */, std::string resultCount = "" /* in */ );
 

	
 
    /* Twitter status APIs */
 
    bool statusUpdate( std::string& newStatus /* in */, std::string inReplyToStatusId = "" /* in */ );
 
    bool statusShowById( std::string& statusId /* in */ );
 
    bool statusDestroyById( std::string& statusId /* in */ );
 
    bool retweetById( std::string& statusId /* in */ );
 

	
 
    /* Twitter timeline APIs */
 
    bool timelineHomeGet( std::string sinceId = ""  /* in */ );
 
    bool timelinePublicGet();
 
    bool timelineFriendsGet();
 
    bool timelineUserGet( bool trimUser /* in */, bool includeRetweets /* in */,
 
                          unsigned int tweetCount /* in */,
 
                          std::string userInfo = "" /* in */,
 
                          bool isUserId = false /* in */ );
 
    bool featuredUsersGet();
 
    bool mentionsGet( std::string sinceId = "" /* in */ );
 

	
 
    /* Twitter user APIs */
 
    bool userLookup( std::vector<std::string> &userInfo /* in */,  bool isUserId = false /* in */ );
 
    bool userGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool friendsGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
 
    bool followersGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
 

	
 
    /* Twitter direct message APIs */
 
    bool directMessageGet( std::string sinceId = "" /* in */ );
 
    bool directMessageSend( std::string& userInfo /* in */, std::string& dMsg /* in */, bool isUserId = false /* in */ );
 
    bool directMessageGetSent();
 
    bool directMessageDestroyById( std::string& dMsgId /* in */ );
 

	
 
    /* Twitter friendships APIs */
 
    bool friendshipCreate( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool friendshipDestroy( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool friendshipShow( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 

	
 
    /* Twitter social graphs APIs */
 
    bool friendsIdsGet( std::string& nextCursor /* in */,
 
                        std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool followersIdsGet( std::string& nextCursor /* in */,
 
                          std::string& userInfo /* in */, bool isUserId = false /* in */ );
 

	
 
    /* Twitter account APIs */
 
    bool accountRateLimitGet();
 
    bool accountVerifyCredGet();
 

	
 
    /* Twitter favorites APIs */
 
    bool favoriteGet();
 
    bool favoriteCreate( std::string& statusId /* in */ );
 
    bool favoriteDestroy( std::string& statusId /* in */ );
 

	
 
    /* Twitter block APIs */
 
    bool blockCreate( std::string& userInfo /* in */ );
 
    bool blockDestroy( std::string& userInfo /* in */ );
 
    bool blockListGet( std::string& nextCursor /* in */,
 
                        bool includeEntities /* in */, bool skipStatus /* in */ );
 
    bool blockIdsGet( std::string& nextCursor /* in */, bool stringifyIds /* in */ );
 

	
 
    /* Twitter search APIs */
 
    bool savedSearchGet();
 
    bool savedSearchCreate( std::string& query /* in */ );
 
    bool savedSearchShow( std::string& searchId /* in */ );
 
    bool savedSearchDestroy( std::string& searchId /* in */ );
 

	
 
    /* Twitter trends APIs (JSON) */
 
    bool trendsGet();
 
    bool trendsDailyGet();
 
    bool trendsWeeklyGet();
 
    bool trendsCurrentGet();
 
    bool trendsAvailableGet();
 

	
 
    /* cURL APIs */
 
    bool isCurlInit();
 
    void getLastWebResponse( std::string& outWebResp /* out */ );
 
    void getLastCurlError( std::string& outErrResp /* out */);
 

	
 
    /* Internal cURL related methods */
 
    int saveLastWebResponse( char*& data, size_t size );
 

	
 
    /* cURL proxy APIs */
 
    std::string& getProxyServerIp();
 
    std::string& getProxyServerPort();
 
    std::string& getProxyUserName();
 
    std::string& getProxyPassword();
 
    void setProxyServerIp( std::string& proxyServerIp /* in */ );
 
    void setProxyServerPort( std::string& proxyServerPort /* in */ );
 
    void setProxyUserName( std::string& proxyUserName /* in */ );
 
    void setProxyPassword( std::string& proxyPassword /* in */ );
 
    
 
    /* Clones this object */
 
    twitCurl* clone();
 

	
 
private:
 
    /* cURL data */
 
    CURL* m_curlHandle;
 
    char* m_errorBuffer;
 
    std::string m_callbackData;
 

	
 
    /* cURL flags */
 
    bool m_curlProxyParamsSet;
 
    bool m_curlLoginParamsSet;
 
    bool m_curlCallbackParamsSet;
 

	
 
    /* cURL proxy data */
 
    std::string m_proxyServerIp;
 
    std::string m_proxyServerPort;
 
    std::string m_proxyUserName;
 
    std::string m_proxyPassword;
 

	
 
    /* Twitter data */
 
    std::string m_twitterUsername;
 
    std::string m_twitterPassword;
 

	
 
    /* Twitter API type */
 
    twitCurlTypes::eTwitCurlApiFormatType m_eApiFormatType;
 
    twitCurlTypes::eTwitCurlProtocolType m_eProtocolType;
 

	
 
    /* OAuth data */
 
    oAuth m_oAuth;
 

	
 
    /* Private methods */
 
    void clearCurlCallbackBuffers();
 
    void prepareCurlProxy();
 
    void prepareCurlCallback();
 
    void prepareCurlUserPass();
 
    void prepareStandardParams();
 
    bool performGet( const std::string& getUrl );
 
    bool performGetInternal( const std::string& getUrl,
 
                             const std::string& oAuthHttpHeader );
 
    bool performDelete( const std::string& deleteUrl );
 
    bool performPost( const std::string& postUrl, std::string dataStr = "" );
 

	
 
    /* Internal cURL related methods */
 
    static int curlCallback( char* data, size_t size, size_t nmemb, twitCurl* pTwitCurlObj );
 
};
 

	
 

	
 
/* Private functions */
 
void utilMakeCurlParams( std::string& outStr, std::string& inParam1, std::string& inParam2 );
 
void utilMakeUrlForUser( std::string& outUrl, const std::string& baseUrl, std::string& userInfo, bool isUserId );
 

	
 
#endif // _TWITCURL_H_
cmake_modules/SwiftenConfig.cmake
Show inline comments
 
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} --version
 
			OUTPUT_VARIABLE SWIFTEN_VERSION)
 
		string(REGEX MATCH "([0-9])" SWIFTEN_VERSION "${SWIFTEN_VERSION}")
 
		message(STATUS "Swiften version ${SWIFTEN_VERSION}")
 
		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}")
 
		set(SWIFTEN_LIBRARY "")
 
		if (APPLE)
 
			string(REGEX MATCHALL "-framework [A-Za-z]+" APPLE_FRAMEWORKS "${SWIFTEN_LIB}")
 
			foreach(framework ${APPLE_FRAMEWORKS})
 
				list(APPEND SWIFTEN_LIBRARY ${framework} )
 
			endforeach(framework)
 
			string(REGEX REPLACE "-framework [A-Za-z]+" "" SWIFTEN_LIB "${SWIFTEN_LIB}")
 
		endif(APPLE)
 
		string(REGEX REPLACE " " ";" SWIFTEN_LIB "${SWIFTEN_LIB}")
 
		foreach(f ${SWIFTEN_LIB})
 
			STRING(SUBSTRING ${f} 0 2 f_out)
 
			STRING(COMPARE EQUAL ${f_out} "/L" IS_PATH)
 
			if(${IS_PATH})
 
				string(REGEX REPLACE "/LIBPATH:" ""  f_replaced "${f}")
 
				message("Added link directory: ${f_replaced}")
 
				link_directories(${f_replaced})
 
			else()
 
				list(APPEND SWIFTEN_LIBRARY ${f})
 
			endif()
 
		endforeach(f) 
 
		set( SWIFTEN_FOUND 1 )
 
	else()
 
		message( STATUS "Could NOT find swiften-config" )
 
	endif()
 

	
 
	if (SWIFTEN_FOUND)
 
		set( SWIFTEN_INCLUDE_DIR ${SWIFTEN_INCLUDE_DIR} )
 
		message( STATUS "Found libSwiften: ${SWIFTEN_LIBRARY}, ${SWIFTEN_INCLUDE_DIR}")
 
	endif()
 

	
 
else( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR )
 
    message( STATUS "Could NOT find libSwiften" )
 
endif( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR )
libtransport/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp *.h)
 
FILE(GLOB_RECURSE SWIFTEN_SRC ../include/Swiften/*.cpp)
 

	
 
# Build without openssl on msvc
 
if (NOT MSVC)
 
if (APPLE)
 
	string(REGEX REPLACE "[^;]+;?/Schannel/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}")
 
	string(REGEX REPLACE "[^;]+;?/OpenSSL/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}")
 
else()
 
	string(REGEX REPLACE "[^;]+;?/Schannel/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}")
 
	string(REGEX REPLACE "[^;]+;?/SecureTransport/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 
 
endif()
 
else()
 
	string(REGEX REPLACE "[^;]+;?/OpenSSL/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") 
 
	string(REGEX REPLACE "[^;]+;?/SecureTransport/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}")
 
endif()
 

	
 
if (SWIFTEN_VERSION GREATER 2)
 
	list(REMOVE_ITEM SWIFTEN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../include/Swiften/Network/DummyConnectionServer.h")
 
	list(REMOVE_ITEM SWIFTEN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../include/Swiften/Network/DummyConnectionServerFactory.h")
 
	list(REMOVE_ITEM SWIFTEN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../include/Swiften/Network/DummyConnectionServer.cpp")
 
	list(REMOVE_ITEM SWIFTEN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../include/Swiften/Network/DummyConnectionServerFactory.cpp")
 
endif()
 
FILE(GLOB HEADERS ../include/transport/*.h)
 
include_directories(../spectrum/src/frontends/xmpp/)
 

	
 
if (NOT WIN32)
 
include_directories(${POPT_INCLUDE_DIR})
 
endif()
 

	
 
# SOURCE_GROUP(headers FILES ${HEADERS})
 

	
 

	
 
if (PROTOBUF_FOUND)
 
	if (NOT WIN32)
 
		ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC})
 
	else()
 
		ADD_LIBRARY(transport STATIC ${HEADERS} ${SRC} ${SWIFTEN_SRC})
 
	endif()
 
#	SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/../include/transport/protocol.pb.cc PROPERTIES GENERATED 1)
 
	ADD_DEPENDENCIES(transport pb) 
 
else(PROTOBUF_FOUND)
 
	ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC})
 
endif(PROTOBUF_FOUND)
 

	
 
# if (CMAKE_COMPILER_IS_GNUCXX)
 
	if (NOT WIN32)
 
		ADD_DEFINITIONS(-fPIC)
 
	endif()
 
# endif()
 

	
 
find_package(CURL)
 

	
 
if (WIN32)
 
	include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/sqlite3")
 
	TARGET_LINK_LIBRARIES(transport transport-plugin sqlite3 ${PQXX_LIBRARY} ${CURL_LIBRARIES ${PQ_LIBRARY} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES} ${PROTOBUF_LIBRARY} psapi.lib)
 
	TARGET_LINK_LIBRARIES(transport transport-plugin sqlite3 ${PQXX_LIBRARY} ${CURL_LIBRARIES} ${PQ_LIBRARY} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES} ${PROTOBUF_LIBRARY} psapi.lib)
 
else()
 
	TARGET_LINK_LIBRARIES(transport transport-plugin ${PQXX_LIBRARY} ${CURL_LIBRARIES} ${PQ_LIBRARY} ${SQLITE3_LIBRARIES} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES} ${POPT_LIBRARY} ${PROTOBUF_LIBRARY})
 
endif()
 

	
 
SET_TARGET_PROPERTIES(transport PROPERTIES
 
      VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION}
 
)
 
if (APPLE)
 
	TARGET_LINK_LIBRARIES(transport ${APPLE_FRAMEWORKS})
 
endif()
 

	
 
INSTALL(TARGETS transport LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries)
 

	
 
#CONFIGURE_FILE(transport.pc.in "${CMAKE_CURRENT_BINARY_DIR}/transport.pc")
 
#INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/transport.pc" DESTINATION lib/pkgconfig)
libtransport/FileTransferManager.cpp
Show inline comments
 
/**
 
 * libtransport -- C++ library for easy XMPP Transports development
 
 *
 
 * Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/FileTransferManager.h"
 
#include "transport/Transport.h"
 
#include "transport/UserManager.h"
 
#include "transport/User.h"
 
#include "transport/Buddy.h"
 
#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_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;
 
 	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) {
 
// // 		m_filetransfers.push_back(ft);
 
// // 		ft->onStateChange.connect(boost::bind(&User::handleFTStateChanged, this, _1, Buddy::JIDToLegacyName(from), info.getName(), info.getSize(), id));
 
// // 		transfer.ft->start();
 
// // 	}
 
// 	return transfer;
 
 	return transfer;
 
}
 

	
 
}
spectrum/src/frontends/xmpp/XMPPFrontend.cpp
Show inline comments
 
@@ -158,242 +158,242 @@ void XMPPFrontend::init(Component *transport, Swift::EventLoop *loop, Swift::Net
 
		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, 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(&XMPPFrontend::handleCapsChanged, this, _1));
 

	
 
	m_stanzaChannel->onPresenceReceived.connect(bind(&XMPPFrontend::handleGeneralPresence, this, _1));
 
	m_stanzaChannel->onMessageReceived.connect(bind(&XMPPFrontend::handleMessage, this, _1));
 

	
 
	m_discoItemsResponder = new DiscoItemsResponder(transport);
 
	m_discoItemsResponder->start();
 
}
 

	
 
XMPPFrontend::~XMPPFrontend() {
 
	delete m_entityCapsManager;
 
	delete m_capsManager;
 
	delete m_capsMemoryStorage;
 
	if (m_component)
 
		delete m_component;
 
	if (m_server) {
 
		m_server->stop();
 
		delete m_server;
 
	}
 
}
 

	
 
void XMPPFrontend::handleGeneralPresence(Swift::Presence::ref presence) {
 
	onPresenceReceived(presence);
 
}
 

	
 
void XMPPFrontend::handleMessage(boost::shared_ptr<Swift::Message> message) {
 
	onMessageReceived(message);
 
}
 

	
 

	
 
void XMPPFrontend::clearRoomList() {
 
	m_discoItemsResponder->clearRooms();
 
}
 

	
 
void XMPPFrontend::addRoomToRoomList(const std::string &handle, const std::string &name) {
 
	m_discoItemsResponder->addRoom(handle, name);
 
}
 

	
 
void XMPPFrontend::sendPresence(Swift::Presence::ref presence) {
 
	if (!presence->getFrom().getNode().empty()) {
 
		presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::CapsInfo(m_discoItemsResponder->getBuddyCapsInfo())));
 
	}
 

	
 
	m_stanzaChannel->sendPresence(presence);
 
}
 

	
 
void XMPPFrontend::sendVCard(Swift::VCard::ref vcard, Swift::JID to) {
 
	boost::shared_ptr<Swift::GenericRequest<Swift::VCard> > request(new Swift::GenericRequest<Swift::VCard>(Swift::IQ::Result, to, vcard, m_iqRouter));
 
	request->send();
 
}
 

	
 
void XMPPFrontend::sendRosterRequest(Swift::RosterPayload::ref payload, Swift::JID to) {
 
	Swift::SetRosterRequest::ref request = Swift::SetRosterRequest::create(payload, to, m_iqRouter);
 
	request->send();
 
}
 

	
 
void XMPPFrontend::sendMessage(boost::shared_ptr<Swift::Message> message) {
 
	m_stanzaChannel->sendMessage(message);
 
}
 

	
 
void XMPPFrontend::sendIQ(boost::shared_ptr<Swift::IQ> iq) {
 
	m_iqRouter->sendIQ(iq);
 
}
 

	
 
boost::shared_ptr<Swift::DiscoInfo> XMPPFrontend::sendCapabilitiesRequest(Swift::JID to) {
 
	Swift::DiscoInfo::ref caps = m_entityCapsManager->getCaps(to);
 
	if (caps != Swift::DiscoInfo::ref()) {
 
		onCapabilitiesReceived(to, caps);
 
		return caps;
 
	}
 
#ifdef SUPPORT_LEGACY_CAPS
 
	else {
 
		GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(to, m_iqRouter);
 
		discoInfoRequest->onResponse.connect(boost::bind(&XMPPFrontend::handleDiscoInfoResponse, this, _1, _2, to));
 
		discoInfoRequest->send();
 
	}
 
#endif
 

	
 
	return Swift::DiscoInfo::ref();
 
}
 

	
 
void XMPPFrontend::reconnectUser(const std::string &user) {
 
	if (inServerMode()) {
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, "Sending probe presence to " << user);
 
	Swift::Presence::ref response = Swift::Presence::create();
 
	try {
 
		response->setTo(user);
 
	}
 
	catch (...) { return; }
 
	
 
	response->setFrom(m_component->getJID());
 
	response->setType(Swift::Presence::Probe);
 

	
 
	m_stanzaChannel->sendPresence(response);
 
}
 

	
 
RosterManager *XMPPFrontend::createRosterManager(User *user, Component *component) {
 
	return new XMPPRosterManager(user, component);
 
}
 

	
 
User *XMPPFrontend::createUser(const Swift::JID &jid, UserInfo &userInfo, Component *component, UserManager *userManager) {
 
	return new XMPPUser(jid, userInfo, component, userManager);
 
}
 

	
 
UserManager *XMPPFrontend::createUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend) {
 
	return new XMPPUserManager(component, userRegistry, storageBackend);
 
}
 

	
 
bool XMPPFrontend::handleIQ(boost::shared_ptr<Swift::IQ> iq) {
 
	if (!m_rawXML) {
 
		return false;
 
	}
 

	
 
	if (iq->getPayload<Swift::RosterPayload>() != NULL) { return false; }
 
	if (iq->getPayload<Swift::InBandRegistrationPayload>() != NULL) { return false; }
 
	if (iq->getPayload<Swift::StatsPayload>() != NULL) { return false; }
 

	
 
	if (iq->getTo().getNode().empty()) {
 
		return false;
 
	}
 

	
 
	m_transport->onRawIQReceived(iq);
 
	return true;
 
}
 

	
 
void XMPPFrontend::handleBackendConfigChanged() {
 
	if (!m_rawXML && CONFIG_BOOL_DEFAULTED(m_config, "features.rawxml", false)) {
 
		m_rawXML = true;
 
		m_iqRouter->addHandler(this);
 
	}
 
}
 

	
 
Swift::StanzaChannel *XMPPFrontend::getStanzaChannel() {
 
	return m_stanzaChannel;
 
}
 

	
 
void XMPPFrontend::connectToServer() {
 
	if (m_component && !m_component->isAvailable()) {
 
		LOG4CXX_INFO(logger, "Connecting XMPP server " << CONFIG_STRING(m_config, "service.server") << " port " << CONFIG_INT(m_config, "service.port"));
 
		if (CONFIG_INT(m_config, "service.port") == 5222) {
 
			LOG4CXX_WARN(logger, "Port 5222 is usually used for client connections, not for component connections! Are you sure you are using right port?");
 
		}
 
		m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port"));
 
	}
 
	else if (m_server) {
 
		LOG4CXX_INFO(logger, "Starting XMPPFrontend in server mode on port " << CONFIG_INT(m_config, "service.port"));
 
		m_server->start();
 

	
 
		//Type casting to BoostConnectionServer since onStopped signal is not defined in ConnectionServer
 
		//Ideally, onStopped must be defined in ConnectionServer
 
		if (boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())) {
 
			boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())->onStopped.connect(boost::bind(&XMPPFrontend::handleServerStopped, this, _1));
 
		}
 
		
 
		// We're connected right here, because we're in server mode...
 
		handleConnected();
 
	}
 
}
 

	
 
void XMPPFrontend::disconnectFromServer() {
 
	if (m_component) {
 
		// TODO: Call this once swiften will fix assert(!session_);
 
// 		m_component->disconnect();
 
	}
 
	else if (m_server) {
 
		LOG4CXX_INFO(logger, "Stopping component in server mode on port " << CONFIG_INT(m_config, "service.port"));
 
		m_server->stop();
 
	}
 
}
 

	
 
void XMPPFrontend::handleConnected() {
 
	m_transport->handleConnected();
 
}
 

	
 
void XMPPFrontend::handleServerStopped(boost::optional<Swift::BoostConnectionServer::Error> e) {
 
	if(e != NULL ) {
 
	if(e) {
 
		if(*e == Swift::BoostConnectionServer::Conflict) {
 
			LOG4CXX_INFO(logger, "Port "<< CONFIG_INT(m_config, "service.port") << " already in use! Stopping server..");
 
			if (CONFIG_INT(m_config, "service.port") == 5347) {
 
				LOG4CXX_INFO(logger, "Port 5347 is usually used for components. You are using server_mode=1. Are you sure you don't want to use server_mode=0 and run spectrum as component?");
 
			}
 
		}
 
		if(*e == Swift::BoostConnectionServer::UnknownError)
 
			LOG4CXX_INFO(logger, "Unknown error occured! Stopping server..");
 
		exit(1);
 
	}
 
}
 

	
 

	
 
void XMPPFrontend::handleConnectionError(const ComponentError &error) {
 
	std::string str = "Unknown error";
 
	switch (error.getType()) {
 
		case ComponentError::UnknownError: str = "Unknown error"; break;
 
		case ComponentError::ConnectionError: str = "Connection error"; break;
 
		case ComponentError::ConnectionReadError: str = "Connection read error"; break;
 
		case ComponentError::ConnectionWriteError: str = "Connection write error"; break;
 
		case ComponentError::XMLError: str = "XML Error"; break;
 
		case ComponentError::AuthenticationFailedError: str = "Authentication failed error"; break;
 
		case ComponentError::UnexpectedElementError: str = "Unexpected element error"; break;
 
	}
 

	
 
	m_transport->handleConnectionError(str);
 
}
 

	
 
void XMPPFrontend::handleDataRead(const Swift::SafeByteArray &data) {
 
	std::string d = safeByteArrayToString(data);
 
	m_transport->handleDataRead(d);
 
}
 

	
 
void XMPPFrontend::handleDataWritten(const Swift::SafeByteArray &data) {
 
	std::string d = safeByteArrayToString(data);
 
	m_transport->handleDataWritten(d);
 
}
 

	
 
void XMPPFrontend::handleDiscoInfoResponse(boost::shared_ptr<Swift::DiscoInfo> info, Swift::ErrorPayload::ref error, const Swift::JID& jid) {
 
#ifdef SUPPORT_LEGACY_CAPS
 
	onCapabilitiesReceived(jid, info);
 
#endif
 
}
 

	
 
void XMPPFrontend::handleCapsChanged(const Swift::JID& jid) {
 
	onCapabilitiesReceived(jid, m_entityCapsManager->getCaps(jid));
 
}
 

	
 
}
0 comments (0 inline, 0 general)