Gateway interaction

This commit is contained in:
HanzZ 2012-02-26 14:03:48 +01:00
parent 54dff8d280
commit 320738eda8
7 changed files with 122 additions and 1 deletions

View file

@ -1,6 +1,7 @@
Version 2.0.0-beta (X-X-X): Version 2.0.0-beta (X-X-X):
General: General:
* Added PostreSQL support (thanks to Jadestorm). * Added PostreSQL support (thanks to Jadestorm).
* Added XEP-0100 (Gateway interaction) support.
* Send presences only "from" bare JID (fixed bug with buddies appearing * Send presences only "from" bare JID (fixed bug with buddies appearing
twice in the roster and potential unregistering issues). twice in the roster and potential unregistering issues).
* Fixed potential MySQL/SQLite3 deadlocks. * Fixed potential MySQL/SQLite3 deadlocks.

View file

@ -20,7 +20,7 @@ GatewayPayloadSerializer::GatewayPayloadSerializer()
std::string GatewayPayloadSerializer::serializePayload(boost::shared_ptr<GatewayPayload> payload) const { std::string GatewayPayloadSerializer::serializePayload(boost::shared_ptr<GatewayPayload> payload) const {
XMLElement query("query", "jabber:iq:gateway"); XMLElement query("query", "jabber:iq:gateway");
if (!payload->getJID().isValid()) { if (payload->getJID().isValid()) {
boost::shared_ptr<XMLElement> jid(new XMLElement("jid", "", payload->getJID().toBare().toString())); boost::shared_ptr<XMLElement> jid(new XMLElement("jid", "", payload->getJID().toBare().toString()));
query.addNode(jid); query.addNode(jid);
} }

View file

@ -0,0 +1,43 @@
/**
* 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
*/
#pragma once
#include <vector>
#include "Swiften/Swiften.h"
#include "Swiften/Queries/Responder.h"
#include "Swiften/Elements/GatewayPayload.h"
namespace Transport {
class UserManager;
class GatewayResponder : public Swift::Responder<Swift::GatewayPayload> {
public:
GatewayResponder(Swift::IQRouter *router, UserManager *userManager);
~GatewayResponder();
private:
virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::GatewayPayload> payload);
virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::GatewayPayload> payload);
UserManager *m_userManager;
};
}

View file

@ -104,6 +104,10 @@ class UserManager : public Swift::EntityCapsProvider {
return m_userRegistry; return m_userRegistry;
} }
Component *getComponent() {
return m_component;
}
/// Connects user manually. /// Connects user manually.
/// \param user JID of user. /// \param user JID of user.
void connectUser(const Swift::JID &user); void connectUser(const Swift::JID &user);

View file

@ -12,6 +12,7 @@
#include "transport/statsresponder.h" #include "transport/statsresponder.h"
#include "transport/usersreconnecter.h" #include "transport/usersreconnecter.h"
#include "transport/util.h" #include "transport/util.h"
#include "transport/gatewayresponder.h"
#include "Swiften/EventLoop/SimpleEventLoop.h" #include "Swiften/EventLoop/SimpleEventLoop.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -421,6 +422,9 @@ int main(int argc, char **argv)
StatsResponder statsResponder(&transport, &userManager, &plugin, storageBackend); StatsResponder statsResponder(&transport, &userManager, &plugin, storageBackend);
statsResponder.start(); statsResponder.start();
GatewayResponder gatewayResponder(transport.getIQRouter(), &userManager);
gatewayResponder.start();
eventLoop_ = &eventLoop; eventLoop_ = &eventLoop;
eventLoop.run(); eventLoop.run();

63
src/gatewayresponder.cpp Normal file
View file

@ -0,0 +1,63 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
*
* 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/gatewayresponder.h"
#include <iostream>
#include <boost/bind.hpp>
#include "Swiften/Queries/IQRouter.h"
#include "Swiften/Elements/RawXMLPayload.h"
#include "Swiften/Swiften.h"
#include "transport/usermanager.h"
#include "transport/user.h"
#include "transport/transport.h"
#include "log4cxx/logger.h"
using namespace log4cxx;
using namespace Swift;
using namespace boost;
namespace Transport {
static LoggerPtr logger = Logger::getLogger("GatewayResponder");
GatewayResponder::GatewayResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::Responder<GatewayPayload>(router) {
m_userManager = userManager;
}
GatewayResponder::~GatewayResponder() {
}
bool GatewayResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::GatewayPayload> payload) {
sendResponse(from, id, boost::shared_ptr<GatewayPayload>(new GatewayPayload(Swift::JID(), "Enter legacy network contact ID.", "Contact ID")));
return true;
}
bool GatewayResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::GatewayPayload> payload) {
std::string prompt = payload->getPrompt();
std::string escaped = Swift::JID::getEscapedNode(prompt);
std::string jid = escaped + "@" + m_userManager->getComponent()->getJID().toBare().toString();
sendResponse(from, id, boost::shared_ptr<GatewayPayload>(new GatewayPayload(jid)));
return true;
}
}

View file

@ -36,6 +36,8 @@
#include "Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h" #include "Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h"
#include "Swiften/Parser/PayloadParsers/StatsParser.h" #include "Swiften/Parser/PayloadParsers/StatsParser.h"
#include "Swiften/Serializer/PayloadSerializers/StatsSerializer.h" #include "Swiften/Serializer/PayloadSerializers/StatsSerializer.h"
#include "Swiften/Parser/PayloadParsers/GatewayPayloadParser.h"
#include "Swiften/Serializer/PayloadSerializers/GatewayPayloadSerializer.h"
#include "Swiften/Serializer/PayloadSerializers/SpectrumErrorSerializer.h" #include "Swiften/Serializer/PayloadSerializers/SpectrumErrorSerializer.h"
#include "transport/BlockParser.h" #include "transport/BlockParser.h"
#include "transport/BlockSerializer.h" #include "transport/BlockSerializer.h"
@ -95,6 +97,7 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0"));
m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0"));
m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats"));
m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway"));
m_server->addPayloadSerializer(new Swift::AttentionSerializer()); m_server->addPayloadSerializer(new Swift::AttentionSerializer());
m_server->addPayloadSerializer(new Swift::XHTMLIMSerializer()); m_server->addPayloadSerializer(new Swift::XHTMLIMSerializer());
@ -102,6 +105,7 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
m_server->addPayloadSerializer(new Swift::InvisibleSerializer()); m_server->addPayloadSerializer(new Swift::InvisibleSerializer());
m_server->addPayloadSerializer(new Swift::StatsSerializer()); m_server->addPayloadSerializer(new Swift::StatsSerializer());
m_server->addPayloadSerializer(new Swift::SpectrumErrorSerializer()); m_server->addPayloadSerializer(new Swift::SpectrumErrorSerializer());
m_server->addPayloadSerializer(new Swift::GatewayPayloadSerializer());
m_server->onDataRead.connect(boost::bind(&Component::handleDataRead, this, _1)); m_server->onDataRead.connect(boost::bind(&Component::handleDataRead, this, _1));
m_server->onDataWritten.connect(boost::bind(&Component::handleDataWritten, this, _1)); m_server->onDataWritten.connect(boost::bind(&Component::handleDataWritten, this, _1));
@ -121,6 +125,7 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0")); 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->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0"));
m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats"));
m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway"));
m_component->addPayloadSerializer(new Swift::AttentionSerializer()); m_component->addPayloadSerializer(new Swift::AttentionSerializer());
m_component->addPayloadSerializer(new Swift::XHTMLIMSerializer()); m_component->addPayloadSerializer(new Swift::XHTMLIMSerializer());
@ -128,6 +133,7 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
m_component->addPayloadSerializer(new Swift::InvisibleSerializer()); m_component->addPayloadSerializer(new Swift::InvisibleSerializer());
m_component->addPayloadSerializer(new Swift::StatsSerializer()); m_component->addPayloadSerializer(new Swift::StatsSerializer());
m_component->addPayloadSerializer(new Swift::SpectrumErrorSerializer()); m_component->addPayloadSerializer(new Swift::SpectrumErrorSerializer());
m_component->addPayloadSerializer(new Swift::GatewayPayloadSerializer());
m_stanzaChannel = m_component->getStanzaChannel(); m_stanzaChannel = m_component->getStanzaChannel();
m_iqRouter = m_component->getIQRouter(); m_iqRouter = m_component->getIQRouter();