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 c54466f9..b1e433a4 100644 --- a/backends/frotz/main.cpp +++ b/backends/frotz/main.cpp @@ -146,8 +146,27 @@ 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->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(data->begin(), data->end()); + handleDataRead(d); } void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) { @@ -220,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 b5e4d279..92652201 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 = 0; + gchar **keys = g_key_file_get_keys (keyfile, "purple", NULL, NULL); + while (keys && 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) { @@ -734,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); @@ -1016,7 +1016,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); @@ -1070,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); @@ -1259,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); @@ -1700,15 +1698,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 +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); np = new SpectrumNetworkPlugin(host, port); bool libev = KEYFILE_STRING("service", "eventloop") == "libev"; diff --git a/cmake_modules/SwiftenConfig.cmake b/cmake_modules/SwiftenConfig.cmake index e5ef19e7..319d29d9 100644 --- a/cmake_modules/SwiftenConfig.cmake +++ b/cmake_modules/SwiftenConfig.cmake @@ -6,7 +6,7 @@ if( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR ) set( SWIFTEN_CFLAGS "" ) if (SWIFTEN_CONFIG_EXECUTABLE) execute_process( - COMMAND swiften-config --libs + COMMAND SWIFTEN_CONFIG_EXECUTABLE --libs OUTPUT_VARIABLE SWIFTEN_LIBRARY) string(REGEX REPLACE "[\r\n]" " " SWIFTEN_LIBRARY "${SWIFTEN_LIBRARY}") string(REGEX REPLACE " +$" "" SWIFTEN_LIBRARY "${SWIFTEN_LIBRARY}") 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 0ba99113..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,10 +38,19 @@ namespace Swift { } Swift::XMLParserFactory* getXMLParserFactory() const { - return 0; + return m_platformXMLParserFactory; } + Swift::TLSContextFactory* getTLSContextFactory() const { + return 0; + } + + Swift::ProxyProvider* getProxyProvider() const { + return 0; + } + 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 2ab70237..4a2bb751 100644 --- a/include/Swiften/Server/ServerFromClientSession.cpp +++ b/include/Swiften/Server/ServerFromClientSession.cpp @@ -9,6 +9,8 @@ #include #include +#include +#include #include #include #include @@ -34,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), @@ -43,6 +46,7 @@ ServerFromClientSession::ServerFromClientSession( allowSASLEXTERNAL(false), tlsLayer(0), tlsConnected(false) { + setRemoteJID(remoteJID); } ServerFromClientSession::~ServerFromClientSession() { @@ -59,9 +63,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..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; @@ -55,7 +56,7 @@ namespace Swift { } void handlePasswordValid(); - void handlePasswordInvalid(); + void handlePasswordInvalid(const std::string &error = ""); private: void handleElement(boost::shared_ptr); 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/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/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/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..f432ff6c --- /dev/null +++ b/plugin/src/CMakeLists.txt @@ -0,0 +1,19 @@ +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 ${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}) + +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) 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/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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25d76dee..2ad42174 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,13 +20,15 @@ endif() if (PROTOBUF_FOUND) if (CMAKE_COMPILER_IS_GNUCXX) - 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) else() - ADD_LIBRARY(transport STATIC ${HEADERS} ${SRC} ${SWIFTEN_SRC} ../include/transport/protocol.pb.cc) + ADD_LIBRARY(transport STATIC ${HEADERS} ${SRC} ${SWIFTEN_SRC} ${CMAKE_CURRENT_BINARY_DIR}/../include/transport/protocol.pb.cc) +endif() + SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/../include/transport/protocol.pb.cc PROPERTIES GENERATED 1) endif() - ADD_DEPENDENCIES(transport pb) + ADD_DEPENDENCIES(transport pb) else() - ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC}) + ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC}) endif() if (CMAKE_COMPILER_IS_GNUCXX) 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..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"); } @@ -468,7 +470,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 +494,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/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/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); 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(); } diff --git a/src/user.cpp b/src/user.cpp index 2cf74cbd..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) { @@ -299,7 +298,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 { 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(); }