merging latest changes

This commit is contained in:
Vitaly Takmazov 2011-10-20 09:22:15 +04:00
commit f4b6ded084
24 changed files with 211 additions and 89 deletions

View file

@ -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)

View file

@ -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<Swift::Connection> 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<Swift::SafeByteArray> 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<std::string> lst = getGames();

View file

@ -500,47 +500,48 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
}
void setDefaultAccountOptions(PurpleAccount *account) {
// for (std::map<std::string,std::string>::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<bool>((*it).second));
// break;
//
// case PURPLE_PREF_INT:
// purple_account_set_int(account, key.c_str(), fromString<int>((*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<bool>(KEYFILE_STRING("purple", key)));
break;
case PURPLE_PREF_INT:
purple_account_set_int(account, key.c_str(), fromString<int>(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";

View file

@ -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}")

View file

@ -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;
}
}

View file

@ -7,6 +7,7 @@
#pragma once
#include <Swiften/Network/NetworkFactories.h>
#include <Swiften/Parser/PlatformXMLParserFactory.h>
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;

View file

@ -9,6 +9,8 @@
#include <boost/bind.hpp>
#include <Swiften/Elements/ProtocolHeader.h>
#include <Swiften/Elements/StreamError.h>
#include <Swiften/Elements/Message.h>
#include <Swiften/Server/UserRegistry.h>
#include <Swiften/Network/Connection.h>
#include <Swiften/StreamStack/XMPPLayer.h>
@ -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<AuthFailure>(new AuthFailure));
if (!error.empty()) {
boost::shared_ptr<StreamError> msg(new StreamError(StreamError::UndefinedCondition, error));
getXMPPLayer()->writeElement(msg);
}
finishSession(AuthenticationFailedError);
}
}

View file

@ -39,7 +39,8 @@ namespace Swift {
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
UserRegistry* userRegistry,
XMLParserFactory* factory);
XMLParserFactory* factory,
Swift::JID remoteJID = Swift::JID());
~ServerFromClientSession();
boost::signal<void ()> onSessionStarted;
@ -55,7 +56,7 @@ namespace Swift {
}
void handlePasswordValid();
void handlePasswordInvalid();
void handlePasswordInvalid(const std::string &error = "");
private:
void handleElement(boost::shared_ptr<Element>);

View file

@ -29,7 +29,6 @@ namespace {
}
void ServerStanzaChannel::addSession(boost::shared_ptr<ServerFromClientSession> 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));

View file

@ -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)

View file

@ -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.

1
plugin/CMakeLists.txt Normal file
View file

@ -0,0 +1 @@
ADD_SUBDIRECTORY(src)

19
plugin/src/CMakeLists.txt Normal file
View file

@ -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)

View file

@ -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();
}

View file

@ -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)

View file

@ -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)

View file

@ -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) {

View file

@ -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<BuddyInfo> &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<BuddyInfo> &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;
}

View file

@ -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) {

View file

@ -5,10 +5,14 @@
#include "transport/localbuddy.h"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <Swiften/Swiften.h>
#include <Swiften/EventLoop/DummyEventLoop.h>
#include <Swiften/Server/Server.h>
#include <Swiften/Network/DummyNetworkFactories.h>
#include <Swiften/Network/DummyConnectionServer.h>
#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<Swift::ServerFromClientSession>(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<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->addSession(serverFromClientSession);
parser->parse("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>");
received.clear();
loop->processEvents();
}
void tearDown (void) {
dynamic_cast<Swift::ServerStanzaChannel *>(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<Swift::Element> 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<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->onPresenceReceived(response);
loop->processEvents();
}
private:
boost::shared_ptr<Swift::ServerFromClientSession> 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<std::string> received;
std::vector<boost::shared_ptr<Swift::Element> > received;
};
CPPUNIT_TEST_SUITE_REGISTRATION (ComponentTest);

View file

@ -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<StorageParser>("private", "jabber:iq:private"));
m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0"));
m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im"));
m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0"));
m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0"));
m_component->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();
}

View file

@ -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<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>(new Swift::StreamError()));
dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>(new Swift::StreamError(Swift::StreamError::UndefinedCondition, "test")));
if (m_userManager->getUser(jid) != NULL) {
m_userManager->removeUser(this);
}

View file

@ -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 {

View file

@ -42,7 +42,7 @@ static LoggerPtr logger = Logger::getLogger("VCardResponder");
VCardResponder::VCardResponder(Swift::IQRouter *router, Swift::NetworkFactories *factories, UserManager *userManager) : Swift::Responder<VCard>(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();
}