From 1db5be3db8cf558c1e9da26f31848a91a6ee8451 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Mon, 17 Oct 2011 21:26:13 +0200 Subject: [PATCH 01/15] Working libpurple FT again --- backends/libpurple/main.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index b5e4d279..c7e3890b 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -1700,15 +1700,20 @@ static void spectrum_sigchld_handler(int sig) } static void transportDataReceived(gpointer data, gint source, PurpleInputCondition cond) { - char buffer[65535]; - char *ptr = buffer; - ssize_t n = read(source, ptr, sizeof(buffer)); - if (n <= 0) { - LOG4CXX_INFO(logger, "Diconnecting from spectrum2 server"); - exit(errno); + if (cond & PURPLE_INPUT_READ) { + char buffer[65535]; + char *ptr = buffer; + ssize_t n = read(source, ptr, sizeof(buffer)); + if (n <= 0) { + LOG4CXX_INFO(logger, "Diconnecting from spectrum2 server"); + exit(errno); + } + std::string d = std::string(buffer, n); + np->handleDataRead(d); + } + else { + np->readyForData(); } - std::string d = std::string(buffer, n); - np->handleDataRead(d); } int main(int argc, char **argv) { @@ -1821,6 +1826,7 @@ int main(int argc, char **argv) { fcntl(m_sock, F_SETFL, flags); purple_input_add(m_sock, PURPLE_INPUT_READ, &transportDataReceived, NULL); + purple_input_add(m_sock, PURPLE_INPUT_WRITE, &transportDataReceived, NULL); np = new SpectrumNetworkPlugin(host, port); bool libev = KEYFILE_STRING("service", "eventloop") == "libev"; From 7bc85a4c61e9277ab3c63bbed87a8424abd9d89c Mon Sep 17 00:00:00 2001 From: HanzZ Date: Mon, 17 Oct 2011 22:05:20 +0200 Subject: [PATCH 02/15] Working setDefaultAccountOptions --- backends/libpurple/main.cpp | 83 +++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index c7e3890b..c81e48ef 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -500,47 +500,48 @@ class SpectrumNetworkPlugin : public NetworkPlugin { } void setDefaultAccountOptions(PurpleAccount *account) { -// for (std::map::const_iterator it = config->getUnregistered().begin(); -// it != config->getUnregistered().end(); it++) { -// if ((*it).first.find("purple.") == 0) { -// std::string key = (*it).first.substr((*it).first.find(".") + 1); -// -// PurplePlugin *plugin = purple_find_prpl(purple_account_get_protocol_id(account)); -// PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); -// bool found = false; -// for (GList *l = prpl_info->protocol_options; l != NULL; l = l->next) { -// PurpleAccountOption *option = (PurpleAccountOption *) l->data; -// PurplePrefType type = purple_account_option_get_type(option); -// std::string key2(purple_account_option_get_setting(option)); -// std::cout << key << " " << key2 << " " << (*it).second << "\n"; -// if (key != key2) -// continue; -// -// found = true; -// switch (type) { -// case PURPLE_PREF_BOOLEAN: -// purple_account_set_bool(account, key.c_str(), fromString((*it).second)); -// break; -// -// case PURPLE_PREF_INT: -// purple_account_set_int(account, key.c_str(), fromString((*it).second)); -// break; -// -// case PURPLE_PREF_STRING: -// case PURPLE_PREF_STRING_LIST: -// purple_account_set_string(account, key.c_str(), (*it).second.c_str()); -// break; -// default: -// continue; -// } -// break; -// } -// -// if (!found) { -// purple_account_set_string(account, key.c_str(), (*it).second.c_str()); -// } -// } -// } + int i; + gchar **keys = g_key_file_get_keys (keyfile, "purple", NULL, NULL); + while (keys[i] != NULL) { + std::string key = keys[i]; + + PurplePlugin *plugin = purple_find_prpl(purple_account_get_protocol_id(account)); + PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); + bool found = false; + for (GList *l = prpl_info->protocol_options; l != NULL; l = l->next) { + PurpleAccountOption *option = (PurpleAccountOption *) l->data; + PurplePrefType type = purple_account_option_get_type(option); + std::string key2(purple_account_option_get_setting(option)); + if (key != key2) { + continue; + } + + found = true; + switch (type) { + case PURPLE_PREF_BOOLEAN: + purple_account_set_bool(account, key.c_str(), fromString(KEYFILE_STRING("purple", key))); + break; + + case PURPLE_PREF_INT: + purple_account_set_int(account, key.c_str(), fromString(KEYFILE_STRING("purple", key))); + break; + + case PURPLE_PREF_STRING: + case PURPLE_PREF_STRING_LIST: + purple_account_set_string(account, key.c_str(), KEYFILE_STRING("purple", key).c_str()); + break; + default: + continue; + } + break; + } + + if (!found) { + purple_account_set_string(account, key.c_str(), KEYFILE_STRING("purple", key).c_str()); + } + i++; + } + g_strfreev (keys); } void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) { From 53353b28b8509c11309581c5b0a315bf78fe18b7 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 18 Oct 2011 12:46:13 +0200 Subject: [PATCH 03/15] Added missing CMakeList.txt --- plugin/CMakeLists.txt | 1 + plugin/src/CMakeLists.txt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 plugin/CMakeLists.txt create mode 100644 plugin/src/CMakeLists.txt diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt new file mode 100644 index 00000000..4b7537b5 --- /dev/null +++ b/plugin/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(src) diff --git a/plugin/src/CMakeLists.txt b/plugin/src/CMakeLists.txt new file mode 100644 index 00000000..5995ea8f --- /dev/null +++ b/plugin/src/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 2.6) +FILE(GLOB SRC *.cpp *.h) +FILE(GLOB HEADERS ../include/transport/*.h) + +ADD_LIBRARY(transport-plugin SHARED ${HEADERS} ${SRC} ${PROTOBUF_SRC} ${PROTOBUF_HDRS} ../../src/memoryusage.cpp ../../include/transport/protocol.pb.cc) +ADD_DEPENDENCIES(transport-plugin pb) +ADD_DEFINITIONS(-fPIC) + +TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES}) + +SET_TARGET_PROPERTIES(transport-plugin PROPERTIES + VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION} +) + +INSTALL(TARGETS transport-plugin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT libraries) + +#CONFIGURE_FILE(transport.pc.in "${CMAKE_CURRENT_BINARY_DIR}/transport.pc") +#INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/transport.pc" DESTINATION lib/pkgconfig) From c1cbd2d1616a8522004086afd82fb568f5481956 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Tue, 18 Oct 2011 10:53:06 +0200 Subject: [PATCH 04/15] Fixed compilation problems + support for latest swiften --- include/Swiften/Network/DummyNetworkFactories.h | 8 ++++++++ include/transport/CMakeLists.txt | 13 +++++++------ src/CMakeLists.txt | 7 +++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/Swiften/Network/DummyNetworkFactories.h b/include/Swiften/Network/DummyNetworkFactories.h index 0ba99113..8942be4b 100644 --- a/include/Swiften/Network/DummyNetworkFactories.h +++ b/include/Swiften/Network/DummyNetworkFactories.h @@ -40,6 +40,14 @@ namespace Swift { return 0; } + Swift::TLSContextFactory* getTLSContextFactory() const { + return 0; + } + + Swift::ProxyProvider* getProxyProvider() const { + return 0; + } + private: TimerFactory* timerFactory; ConnectionFactory* connectionFactory; diff --git a/include/transport/CMakeLists.txt b/include/transport/CMakeLists.txt index 17737c9f..2868190d 100644 --- a/include/transport/CMakeLists.txt +++ b/include/transport/CMakeLists.txt @@ -1,10 +1,11 @@ if (PROTOBUF_FOUND) - add_custom_target(pb - ${PROTOBUF_PROTOC_EXECUTABLE} - --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/protocol.proto - COMMENT "Running C++ protocol buffer compiler on protocol.proto" - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/protocol.proto - VERBATIM ) + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/protocol.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/protocol.pb.h + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/protocol.proto + COMMENT "Running C++ protocol buffer compiler on protocol.proto" + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/protocol.proto + ) + ADD_CUSTOM_TARGET(pb DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/protocol.pb.cc) endif() FILE(GLOB HEADERS *.h protocol.h) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4040e2f9..291844f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,12 +17,11 @@ include_directories(${POPT_INCLUDE_DIR}) - if (PROTOBUF_FOUND) - ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC} ../include/transport/protocol.pb.cc) - ADD_DEPENDENCIES(transport pb) + ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC} ../include/transport/protocol.pb.cc) + ADD_DEPENDENCIES(transport pb) else() - ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC}) + ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC}) endif() ADD_DEFINITIONS(-fPIC) From 7f06cbad05fa85eb0c5a69f5e659effca82847fd Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 18 Oct 2011 18:24:22 +0200 Subject: [PATCH 05/15] Mark protocol.pb.cc as generated --- plugin/src/CMakeLists.txt | 3 ++- src/CMakeLists.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin/src/CMakeLists.txt b/plugin/src/CMakeLists.txt index 5995ea8f..f432ff6c 100644 --- a/plugin/src/CMakeLists.txt +++ b/plugin/src/CMakeLists.txt @@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 2.6) FILE(GLOB SRC *.cpp *.h) FILE(GLOB HEADERS ../include/transport/*.h) -ADD_LIBRARY(transport-plugin SHARED ${HEADERS} ${SRC} ${PROTOBUF_SRC} ${PROTOBUF_HDRS} ../../src/memoryusage.cpp ../../include/transport/protocol.pb.cc) +ADD_LIBRARY(transport-plugin SHARED ${HEADERS} ${SRC} ${PROTOBUF_SRC} ${PROTOBUF_HDRS} ../../src/memoryusage.cpp ${CMAKE_CURRENT_BINARY_DIR}/../../include/transport/protocol.pb.cc) ADD_DEPENDENCIES(transport-plugin pb) +SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/../../include/transport/protocol.pb.cc PROPERTIES GENERATED 1) ADD_DEFINITIONS(-fPIC) TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 291844f3..f3a9304d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,8 @@ include_directories(${POPT_INCLUDE_DIR}) if (PROTOBUF_FOUND) - ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC} ../include/transport/protocol.pb.cc) + ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC} ${CMAKE_CURRENT_BINARY_DIR}/../include/transport/protocol.pb.cc) + SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/../include/transport/protocol.pb.cc PROPERTIES GENERATED 1) ADD_DEPENDENCIES(transport pb) else() ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC}) From 912ef389e890283c02a3f98a5bf86fc4342e51cb Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 18 Oct 2011 18:26:15 +0200 Subject: [PATCH 06/15] initialize variables --- backends/libpurple/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index c81e48ef..2ae0d73e 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -500,7 +500,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin { } void setDefaultAccountOptions(PurpleAccount *account) { - int i; + int i = 0; gchar **keys = g_key_file_get_keys (keyfile, "purple", NULL, NULL); while (keys[i] != NULL) { std::string key = keys[i]; @@ -1017,7 +1017,7 @@ static void buddyListNewNode(PurpleBlistNode *node) { PurpleAccount *account = purple_buddy_get_account(buddy); // Status - pbnetwork::StatusType status; + pbnetwork::StatusType status = pbnetwork::STATUS_NONE; std::string message; getStatus(buddy, status, message); From 0fa08124e61618acc0d3c4cc6e9050fa1eed1832 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 18 Oct 2011 19:25:53 +0200 Subject: [PATCH 07/15] link spectrum2 against boost/swiften --- backends/frotz/main.cpp | 14 ++++++++++++++ spectrum/src/CMakeLists.txt | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backends/frotz/main.cpp b/backends/frotz/main.cpp index c54466f9..cf9737f4 100644 --- a/backends/frotz/main.cpp +++ b/backends/frotz/main.cpp @@ -146,8 +146,22 @@ static void start_dfrotz(dfrotz &p, const std::string &game) { class FrotzNetworkPlugin : public NetworkPlugin { public: + Swift::BoostNetworkFactories *m_factories; + Swift::BoostIOServiceThread m_boostIOServiceThread; + boost::shared_ptr m_conn; + FrotzNetworkPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() { this->config = config; + m_factories = new Swift::BoostNetworkFactories(loop); + m_conn = m_factories->getConnectionFactory()->createConnection(); + m_conn->onDataRead.connect(boost::bind(&FrotzNetworkPlugin::_handleDataRead, this, _1)); +// m_conn->onConnectFinished.connect(boost::bind(&FrotzNetworkPlugin::_handleConnected, this, _1)); +// m_conn->onDisconnected.connect(boost::bind(&FrotzNetworkPlugin::handleDisconnected, this)); + } + + void _handleDataRead(boost::shared_ptr data) { + std::string d = Swift::safeByteArrayToString(*data); + handleDataRead(d); } void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) { diff --git a/spectrum/src/CMakeLists.txt b/spectrum/src/CMakeLists.txt index c2b3d0ad..5a78327f 100644 --- a/spectrum/src/CMakeLists.txt +++ b/spectrum/src/CMakeLists.txt @@ -6,7 +6,7 @@ ADD_EXECUTABLE(spectrum2 ${SRC}) ADD_DEPENDENCIES(spectrum2 spectrum2_libpurple_backend) ADD_DEPENDENCIES(spectrum2 spectrum2_libircclient-qt_backend) -target_link_libraries(spectrum2 transport) +target_link_libraries(spectrum2 transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) INSTALL(TARGETS spectrum2 RUNTIME DESTINATION bin) From 93b2e86e9ce5e824a2fad025108e8c3be553df16 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 18 Oct 2011 20:10:09 +0200 Subject: [PATCH 08/15] Working dfrotz backend --- backends/frotz/CMakeLists.txt | 2 +- backends/frotz/main.cpp | 10 ++++++++-- backends/libpurple/main.cpp | 2 +- plugin/src/networkplugin.cpp | 2 -- spectrum/src/sample.cfg | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backends/frotz/CMakeLists.txt b/backends/frotz/CMakeLists.txt index ed843bbb..7ce14f86 100644 --- a/backends/frotz/CMakeLists.txt +++ b/backends/frotz/CMakeLists.txt @@ -6,7 +6,7 @@ FILE(GLOB SRC *.c *.cpp) ADD_EXECUTABLE(spectrum2_frotz_backend ${SRC}) -target_link_libraries(spectrum2_frotz_backend transport pthread transport-plugin) +target_link_libraries(spectrum2_frotz_backend transport pthread transport-plugin ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) INSTALL(TARGETS spectrum2_frotz_backend RUNTIME DESTINATION bin) diff --git a/backends/frotz/main.cpp b/backends/frotz/main.cpp index cf9737f4..b1e433a4 100644 --- a/backends/frotz/main.cpp +++ b/backends/frotz/main.cpp @@ -155,12 +155,17 @@ class FrotzNetworkPlugin : public NetworkPlugin { m_factories = new Swift::BoostNetworkFactories(loop); m_conn = m_factories->getConnectionFactory()->createConnection(); m_conn->onDataRead.connect(boost::bind(&FrotzNetworkPlugin::_handleDataRead, this, _1)); + m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port)); // m_conn->onConnectFinished.connect(boost::bind(&FrotzNetworkPlugin::_handleConnected, this, _1)); // m_conn->onDisconnected.connect(boost::bind(&FrotzNetworkPlugin::handleDisconnected, this)); } + void sendData(const std::string &string) { + m_conn->write(Swift::createSafeByteArray(string)); + } + void _handleDataRead(boost::shared_ptr data) { - std::string d = Swift::safeByteArrayToString(*data); + std::string d(data->begin(), data->end()); handleDataRead(d); } @@ -234,7 +239,8 @@ class FrotzNetworkPlugin : public NetworkPlugin { return games; } - void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &/*xhtml*/) { + void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "") { + std::cout << "aaa\n"; if (message.find("start") == 0) { std::string game = message.substr(6); std::vector lst = getGames(); diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index 2ae0d73e..916294b1 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -502,7 +502,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin { void setDefaultAccountOptions(PurpleAccount *account) { int i = 0; gchar **keys = g_key_file_get_keys (keyfile, "purple", NULL, NULL); - while (keys[i] != NULL) { + while (keys && keys[i] != NULL) { std::string key = keys[i]; PurplePlugin *plugin = purple_find_prpl(purple_account_get_protocol_id(account)); diff --git a/plugin/src/networkplugin.cpp b/plugin/src/networkplugin.cpp index 1064eb8b..9b08d72d 100644 --- a/plugin/src/networkplugin.cpp +++ b/plugin/src/networkplugin.cpp @@ -487,7 +487,6 @@ void NetworkPlugin::handleDataRead(std::string &data) { handleLogoutPayload(wrapper.payload()); break; case pbnetwork::WrapperMessage_Type_TYPE_PING: - LOG4CXX_INFO(logger, "PING RECEIVED"); sendPong(); break; case pbnetwork::WrapperMessage_Type_TYPE_CONV_MESSAGE: @@ -558,7 +557,6 @@ void NetworkPlugin::sendPong() { wrap.SerializeToString(&message); send(message); - LOG4CXX_INFO(logger, "PONG"); sendMemoryUsage(); } diff --git a/spectrum/src/sample.cfg b/spectrum/src/sample.cfg index 6efc9561..8e676756 100644 --- a/spectrum/src/sample.cfg +++ b/spectrum/src/sample.cfg @@ -11,9 +11,9 @@ admin_password=test #cert=server.pfx #patch to PKCS#12 certificate #cert_password=test #password to that certificate if any users_per_backend=10 -backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend +#backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend #backend=/usr/bin/mono /home/hanzz/code/networkplugin-csharp/msnp-sharp-backend/bin/Debug/msnp-sharp-backend.exe -#backend=/home/hanzz/code/libtransport/backends/frotz/spectrum2_frotz_backend +backend=/home/hanzz/code/libtransport/backends/frotz/spectrum2_frotz_backend #backend=../../backends/libircclient-qt/spectrum2_libircclient-qt_backend #protocol=prpl-msn protocol=any From b1e4aae55b26d10e0a295fa46d9f17d3759d29bd Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 18 Oct 2011 20:49:20 +0200 Subject: [PATCH 09/15] Forward StreamError in onPasswordInvalid signal --- include/Swiften/Server/ServerFromClientSession.cpp | 9 ++++++++- include/Swiften/Server/ServerFromClientSession.h | 2 +- include/transport/userregistry.h | 2 +- spectrum/src/sample.cfg | 4 ++-- src/networkpluginserver.cpp | 2 +- src/user.cpp | 2 +- src/userregistry.cpp | 4 ++-- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/Swiften/Server/ServerFromClientSession.cpp b/include/Swiften/Server/ServerFromClientSession.cpp index 2ab70237..109d0d8f 100644 --- a/include/Swiften/Server/ServerFromClientSession.cpp +++ b/include/Swiften/Server/ServerFromClientSession.cpp @@ -9,6 +9,8 @@ #include #include +#include +#include #include #include #include @@ -59,9 +61,14 @@ void ServerFromClientSession::handlePasswordValid() { } } -void ServerFromClientSession::handlePasswordInvalid() { +void ServerFromClientSession::handlePasswordInvalid(const std::string &error) { if (!isInitialized()) { getXMPPLayer()->writeElement(boost::shared_ptr(new AuthFailure)); + if (!error.empty()) { + boost::shared_ptr msg(new StreamError(StreamError::UndefinedCondition, error)); + getXMPPLayer()->writeElement(msg); + } + finishSession(AuthenticationFailedError); } } diff --git a/include/Swiften/Server/ServerFromClientSession.h b/include/Swiften/Server/ServerFromClientSession.h index 77ed0f1b..1bb51fee 100644 --- a/include/Swiften/Server/ServerFromClientSession.h +++ b/include/Swiften/Server/ServerFromClientSession.h @@ -55,7 +55,7 @@ namespace Swift { } void handlePasswordValid(); - void handlePasswordInvalid(); + void handlePasswordInvalid(const std::string &error = ""); private: void handleElement(boost::shared_ptr); diff --git a/include/transport/userregistry.h b/include/transport/userregistry.h index 7465a3c5..0b6cac14 100644 --- a/include/transport/userregistry.h +++ b/include/transport/userregistry.h @@ -82,7 +82,7 @@ class UserRegistry : public Swift::UserRegistry { /// Informs user that the password is invalid and disconnects him. /// \param user JID. - void onPasswordInvalid(const Swift::JID &user); + void onPasswordInvalid(const Swift::JID &user, const std::string &error = ""); /// Removes session later. /// \param user JID. diff --git a/spectrum/src/sample.cfg b/spectrum/src/sample.cfg index 8e676756..6efc9561 100644 --- a/spectrum/src/sample.cfg +++ b/spectrum/src/sample.cfg @@ -11,9 +11,9 @@ admin_password=test #cert=server.pfx #patch to PKCS#12 certificate #cert_password=test #password to that certificate if any users_per_backend=10 -#backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend +backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend #backend=/usr/bin/mono /home/hanzz/code/networkplugin-csharp/msnp-sharp-backend/bin/Debug/msnp-sharp-backend.exe -backend=/home/hanzz/code/libtransport/backends/frotz/spectrum2_frotz_backend +#backend=/home/hanzz/code/libtransport/backends/frotz/spectrum2_frotz_backend #backend=../../backends/libircclient-qt/spectrum2_libircclient-qt_backend #protocol=prpl-msn protocol=any diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 79717f85..e77bca35 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -369,7 +369,7 @@ void NetworkPluginServer::handleDisconnectedPayload(const std::string &data) { return; } - m_component->m_userRegistry->onPasswordInvalid(payload.user()); + m_component->m_userRegistry->onPasswordInvalid(payload.user(), payload.message()); User *user = m_userManager->getUser(payload.user()); if (!user) { diff --git a/src/user.cpp b/src/user.cpp index 2cf74cbd..3af346b8 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -299,7 +299,7 @@ void User::handleDisconnected(const std::string &error) { // 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(); - dynamic_cast(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr(new Swift::StreamError())); + dynamic_cast(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr(new Swift::StreamError(Swift::StreamError::UndefinedCondition, "test"))); if (m_userManager->getUser(jid) != NULL) { m_userManager->removeUser(this); } diff --git a/src/userregistry.cpp b/src/userregistry.cpp index 4f1a83df..b044ed49 100644 --- a/src/userregistry.cpp +++ b/src/userregistry.cpp @@ -103,11 +103,11 @@ void UserRegistry::onPasswordValid(const Swift::JID &user) { } } -void UserRegistry::onPasswordInvalid(const Swift::JID &user) { +void UserRegistry::onPasswordInvalid(const Swift::JID &user, const std::string &error) { std::string key = user.toBare().toString(); if (users.find(key) != users.end()) { LOG4CXX_INFO(logger, key << ": Password is invalid"); - users[key].session->handlePasswordInvalid(); + users[key].session->handlePasswordInvalid(error); users.erase(key); } else { From 9f2c95fe7775fa77928ec1a7abd04bc8f64b60aa Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 18 Oct 2011 22:42:36 +0200 Subject: [PATCH 10/15] Remove std::couts --- backends/libpurple/main.cpp | 3 --- src/buddy.cpp | 1 - src/mysqlbackend.cpp | 4 ++-- src/user.cpp | 1 - 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index 916294b1..86ef7dcf 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -735,7 +735,6 @@ class SpectrumNetworkPlugin : public NetworkPlugin { } m_vcards[user + name] = id; - std::cout << name << " " << purple_account_get_username(account) << "\n"; if (KEYFILE_BOOL("backend", "no_vcard_fetch") && name != purple_account_get_username(account)) { PurpleNotifyUserInfo *user_info = purple_notify_user_info_new(); notify_user_info(purple_account_get_connection(account), name.c_str(), user_info); @@ -1071,7 +1070,6 @@ static void buddyListUpdate(PurpleBuddyList *list, PurpleBlistNode *node) { } static void buddyPrivacyChanged(PurpleBlistNode *node, void *data) { - std::cout << "PRIVACY CHANGED\n"; if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) return; buddyListUpdate(NULL, node); @@ -1260,7 +1258,6 @@ static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotif } bool ownInfo = name == purple_account_get_username(account); - std::cout << "RECEIVED " << name << " " << purple_account_get_username(account) << "\n"; if (ownInfo) { const gchar *displayname = purple_connection_get_display_name(gc); diff --git a/src/buddy.cpp b/src/buddy.cpp index 2cbe4a2c..6c023539 100644 --- a/src/buddy.cpp +++ b/src/buddy.cpp @@ -130,7 +130,6 @@ std::string Buddy::getSafeName() { // Transport::instance()->protocol()->prepareUsername(name, purple_buddy_get_account(m_buddy)); if (getFlags() & BUDDY_JID_ESCAPING) { name = Swift::JID::getEscapedNode(name); - std::cout << "OUT '" << getName() << "' '" << name << "'\n"; } else { if (name.find_last_of("@") != std::string::npos) { diff --git a/src/mysqlbackend.cpp b/src/mysqlbackend.cpp index 630e8f3e..aaaae047 100644 --- a/src/mysqlbackend.cpp +++ b/src/mysqlbackend.cpp @@ -468,7 +468,7 @@ bool MySQLBackend::getBuddies(long id, std::list &roster) { BOOST_FOREACH(BuddyInfo &b, roster) { if (buddy_id == b.id) { - std::cout << "Adding buddy info setting " << key << "\n"; +// std::cout << "Adding buddy info setting " << key << "\n"; b.settings[key] = var; buddy_id = -1; } @@ -492,7 +492,7 @@ bool MySQLBackend::getBuddies(long id, std::list &roster) { break; } if (buddy_id == b.id) { - std::cout << "Adding buddy info setting " << key << "=" << val << "\n"; +// std::cout << "Adding buddy info setting " << key << "=" << val << "\n"; b.settings[key] = var; buddy_id = -1; } diff --git a/src/user.cpp b/src/user.cpp index 3af346b8..bd4c2726 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -164,7 +164,6 @@ void User::setConnected(bool connected) { } void User::handlePresence(Swift::Presence::ref presence) { - std::cout << "PRESENCE " << presence->getFrom().toString() << "\n"; if (!m_connected) { // we are not connected to legacy network, so we should do it when disco#info arrive :) if (m_readyForConnect == false) { From c86358c64f5f7c92122e74c6cfcb9cb3fd6c1fee Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Wed, 19 Oct 2011 14:35:27 +0200 Subject: [PATCH 11/15] Preparation for better tests --- .../Swiften/Network/DummyNetworkFactories.cpp | 2 + .../Swiften/Network/DummyNetworkFactories.h | 4 +- .../Server/ServerFromClientSession.cpp | 4 +- .../Swiften/Server/ServerFromClientSession.h | 3 +- .../Swiften/Server/ServerStanzaChannel.cpp | 1 - src/tests/component.cpp | 52 +++++++++++++++++-- 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/include/Swiften/Network/DummyNetworkFactories.cpp b/include/Swiften/Network/DummyNetworkFactories.cpp index cf47d7cc..4c477561 100644 --- a/include/Swiften/Network/DummyNetworkFactories.cpp +++ b/include/Swiften/Network/DummyNetworkFactories.cpp @@ -17,6 +17,7 @@ DummyNetworkFactories::DummyNetworkFactories(EventLoop* eventLoop) { connectionFactory = new DummyConnectionFactory(eventLoop); domainNameResolver = new PlatformDomainNameResolver(eventLoop); connectionServerFactory = new DummyConnectionServerFactory(eventLoop); + m_platformXMLParserFactory = new PlatformXMLParserFactory(); } DummyNetworkFactories::~DummyNetworkFactories() { @@ -24,6 +25,7 @@ DummyNetworkFactories::~DummyNetworkFactories() { delete domainNameResolver; delete connectionFactory; delete timerFactory; + delete m_platformXMLParserFactory; } } diff --git a/include/Swiften/Network/DummyNetworkFactories.h b/include/Swiften/Network/DummyNetworkFactories.h index 8942be4b..a945cdfa 100644 --- a/include/Swiften/Network/DummyNetworkFactories.h +++ b/include/Swiften/Network/DummyNetworkFactories.h @@ -7,6 +7,7 @@ #pragma once #include +#include namespace Swift { class EventLoop; @@ -37,7 +38,7 @@ namespace Swift { } Swift::XMLParserFactory* getXMLParserFactory() const { - return 0; + return m_platformXMLParserFactory; } Swift::TLSContextFactory* getTLSContextFactory() const { @@ -49,6 +50,7 @@ namespace Swift { } private: + PlatformXMLParserFactory *m_platformXMLParserFactory; TimerFactory* timerFactory; ConnectionFactory* connectionFactory; DomainNameResolver* domainNameResolver; diff --git a/include/Swiften/Server/ServerFromClientSession.cpp b/include/Swiften/Server/ServerFromClientSession.cpp index 109d0d8f..4a2bb751 100644 --- a/include/Swiften/Server/ServerFromClientSession.cpp +++ b/include/Swiften/Server/ServerFromClientSession.cpp @@ -36,7 +36,8 @@ ServerFromClientSession::ServerFromClientSession( PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, UserRegistry* userRegistry, - XMLParserFactory* factory) : + XMLParserFactory* factory, + Swift::JID remoteJID) : Session(connection, payloadParserFactories, payloadSerializers, factory), id_(id), userRegistry_(userRegistry), @@ -45,6 +46,7 @@ ServerFromClientSession::ServerFromClientSession( allowSASLEXTERNAL(false), tlsLayer(0), tlsConnected(false) { + setRemoteJID(remoteJID); } ServerFromClientSession::~ServerFromClientSession() { diff --git a/include/Swiften/Server/ServerFromClientSession.h b/include/Swiften/Server/ServerFromClientSession.h index 1bb51fee..1de5ac9b 100644 --- a/include/Swiften/Server/ServerFromClientSession.h +++ b/include/Swiften/Server/ServerFromClientSession.h @@ -39,7 +39,8 @@ namespace Swift { PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, UserRegistry* userRegistry, - XMLParserFactory* factory); + XMLParserFactory* factory, + Swift::JID remoteJID = Swift::JID()); ~ServerFromClientSession(); boost::signal onSessionStarted; diff --git a/include/Swiften/Server/ServerStanzaChannel.cpp b/include/Swiften/Server/ServerStanzaChannel.cpp index 4ac5acc8..a0f56543 100644 --- a/include/Swiften/Server/ServerStanzaChannel.cpp +++ b/include/Swiften/Server/ServerStanzaChannel.cpp @@ -29,7 +29,6 @@ namespace { } void ServerStanzaChannel::addSession(boost::shared_ptr session) { - std::cout << "ADDING SESSION\n"; sessions[session->getRemoteJID().toBare().toString()].push_back(session); session->onSessionFinished.connect(boost::bind(&ServerStanzaChannel::handleSessionFinished, this, _1, session)); session->onElementReceived.connect(boost::bind(&ServerStanzaChannel::handleElement, this, _1, session)); diff --git a/src/tests/component.cpp b/src/tests/component.cpp index 8276eaa2..ac02a5b0 100644 --- a/src/tests/component.cpp +++ b/src/tests/component.cpp @@ -5,10 +5,14 @@ #include "transport/localbuddy.h" #include #include +#include #include #include #include #include +#include "Swiften/Server/ServerStanzaChannel.h" +#include "Swiften/Server/ServerFromClientSession.h" +#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" using namespace Transport; @@ -48,9 +52,9 @@ class TestingFactory : public Factory { } }; -class ComponentTest : public CPPUNIT_NS :: TestFixture { +class ComponentTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPParserClient { CPPUNIT_TEST_SUITE(ComponentTest); - CPPUNIT_TEST(presence); + CPPUNIT_TEST(handlePresenceWithNode); CPPUNIT_TEST_SUITE_END(); public: @@ -69,24 +73,64 @@ class ComponentTest : public CPPUNIT_NS :: TestFixture { component = new Component(loop, factories, cfg, factory, userRegistry); component->start(); + payloadSerializers = new Swift::FullPayloadSerializerCollection(); + payloadParserFactories = new Swift::FullPayloadParserFactoryCollection(); + parser = new Swift::XMPPParser(this, payloadParserFactories, factories->getXMLParserFactory()); + + serverFromClientSession = boost::shared_ptr(new Swift::ServerFromClientSession("id", factories->getConnectionFactory()->createConnection(), + payloadParserFactories, payloadSerializers, userRegistry, factories->getXMLParserFactory(), Swift::JID("user@localhost/resource"))); + serverFromClientSession->startSession(); + + serverFromClientSession->onDataWritten.connect(boost::bind(&ComponentTest::handleDataReceived, this, _1)); + + dynamic_cast(component->getStanzaChannel())->addSession(serverFromClientSession); + parser->parse(""); + received.clear(); loop->processEvents(); } void tearDown (void) { + dynamic_cast(component->getStanzaChannel())->removeSession(serverFromClientSession); delete component; delete userRegistry; delete factories; delete factory; delete loop; delete cfg; + delete parser; received.clear(); } - void presence() { + void handleDataReceived(const Swift::SafeByteArray &data) { + parser->parse(safeByteArrayToString(data)); + } + + void handleStreamStart(const Swift::ProtocolHeader&) { } + void handleElement(boost::shared_ptr element) { + received.push_back(element); + } + + void handleStreamEnd() { + + } + + void handlePresenceWithNode() { + Swift::Presence::ref response = Swift::Presence::create(); + response->setTo("localhost"); + response->setFrom("user@localhost/resource"); + dynamic_cast(component->getStanzaChannel())->onPresenceReceived(response); + + loop->processEvents(); + } + private: + boost::shared_ptr serverFromClientSession; + Swift::FullPayloadSerializerCollection* payloadSerializers; + Swift::FullPayloadParserFactoryCollection* payloadParserFactories; + Swift::XMPPParser *parser; UserRegistry *userRegistry; Config *cfg; Swift::Server *server; @@ -94,7 +138,7 @@ class ComponentTest : public CPPUNIT_NS :: TestFixture { Swift::DummyEventLoop *loop; TestingFactory *factory; Component *component; - std::vector received; + std::vector > received; }; CPPUNIT_TEST_SUITE_REGISTRATION (ComponentTest); From 30cec7bb558ffebf6124419b1014d83e2875a8b1 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Wed, 19 Oct 2011 19:58:56 +0200 Subject: [PATCH 12/15] Probably working auto reconnect to mysql database --- src/mysqlbackend.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mysqlbackend.cpp b/src/mysqlbackend.cpp index aaaae047..0bad7c63 100644 --- a/src/mysqlbackend.cpp +++ b/src/mysqlbackend.cpp @@ -257,6 +257,8 @@ MySQLBackend::Statement& MySQLBackend::Statement::operator >> (std::string& t) { MySQLBackend::MySQLBackend(Config *config) { m_config = config; mysql_init(&m_conn); + my_bool my_true = 1; + mysql_options(&m_conn, MYSQL_OPT_RECONNECT, &my_true); m_prefix = CONFIG_STRING(m_config, "database.prefix"); } From 7dd1780605491b63cb8747c64fa2b24087f9901b Mon Sep 17 00:00:00 2001 From: HanzZ Date: Wed, 19 Oct 2011 22:40:47 +0200 Subject: [PATCH 13/15] Don't check PURPLE_INPUT_WRITE --- backends/libpurple/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index 86ef7dcf..92652201 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -1824,7 +1824,7 @@ int main(int argc, char **argv) { fcntl(m_sock, F_SETFL, flags); purple_input_add(m_sock, PURPLE_INPUT_READ, &transportDataReceived, NULL); - purple_input_add(m_sock, PURPLE_INPUT_WRITE, &transportDataReceived, NULL); +// purple_input_add(m_sock, PURPLE_INPUT_WRITE, &transportDataReceived, NULL); np = new SpectrumNetworkPlugin(host, port); bool libev = KEYFILE_STRING("service", "eventloop") == "libev"; From 1e3dc1ef4d6dae9111306541bc9c7eefb55da4de Mon Sep 17 00:00:00 2001 From: HanzZ Date: Wed, 19 Oct 2011 23:28:32 +0200 Subject: [PATCH 14/15] Add custom parsers/serializers also for component --- src/transport.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/transport.cpp b/src/transport.cpp index 0e63ac8a..cb2cdbb6 100644 --- a/src/transport.cpp +++ b/src/transport.cpp @@ -107,6 +107,18 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories, m_component->onError.connect(boost::bind(&Component::handleConnectionError, this, _1)); m_component->onDataRead.connect(boost::bind(&Component::handleDataRead, this, _1)); m_component->onDataWritten.connect(boost::bind(&Component::handleDataWritten, this, _1)); + + m_component->addPayloadParserFactory(new GenericPayloadParserFactory("private", "jabber:iq:private")); + m_component->addPayloadParserFactory(new GenericPayloadParserFactory("attention", "urn:xmpp:attention:0")); + m_component->addPayloadParserFactory(new GenericPayloadParserFactory("html", "http://jabber.org/protocol/xhtml-im")); + m_component->addPayloadParserFactory(new GenericPayloadParserFactory("block", "urn:xmpp:block:0")); + m_component->addPayloadParserFactory(new GenericPayloadParserFactory("invisible", "urn:xmpp:invisible:0")); + + m_component->addPayloadSerializer(new Swift::AttentionSerializer()); + m_component->addPayloadSerializer(new Swift::XHTMLIMSerializer()); + m_component->addPayloadSerializer(new Transport::BlockSerializer()); + m_component->addPayloadSerializer(new Swift::InvisibleSerializer()); + m_stanzaChannel = m_component->getStanzaChannel(); m_iqRouter = m_component->getIQRouter(); } From 97b67c84924d1bbd6eda1cdc40793ace0039e0d6 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Thu, 20 Oct 2011 00:09:08 +0200 Subject: [PATCH 15/15] Don't poll in VCardResponder every 20 ms... --- src/vcardresponder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcardresponder.cpp b/src/vcardresponder.cpp index 594df095..4277d70d 100644 --- a/src/vcardresponder.cpp +++ b/src/vcardresponder.cpp @@ -42,7 +42,7 @@ static LoggerPtr logger = Logger::getLogger("VCardResponder"); VCardResponder::VCardResponder(Swift::IQRouter *router, Swift::NetworkFactories *factories, UserManager *userManager) : Swift::Responder(router) { m_id = 0; m_userManager = userManager; - m_collectTimer = factories->getTimerFactory()->createTimer(20); + m_collectTimer = factories->getTimerFactory()->createTimer(20000); m_collectTimer->onTick.connect(boost::bind(&VCardResponder::collectTimeouted, this)); m_collectTimer->start(); }