Implement the Bridge class to translate between the two protocols

Add all useful classes as well: Jid, Iid, IrcChannel, IrcUser etc to
properly keep the informations about what we receive from the IRC server.

Only handle the MUC join stanza, and send the list of users in the IRC
channel to the XMPP user, and the IRC channel’s topic, for now.
This commit is contained in:
Florent Le Coz
2013-11-06 21:01:18 +01:00
parent dea7f60fa1
commit bf7b05ef72
17 changed files with 694 additions and 14 deletions
+57
View File
@@ -0,0 +1,57 @@
#include <bridge/bridge.hpp>
#include <xmpp/xmpp_component.hpp>
#include <network/poller.hpp>
Bridge::Bridge(const std::string& user_jid, XmppComponent* xmpp, Poller* poller):
user_jid(user_jid),
xmpp(xmpp),
poller(poller)
{
}
Bridge::~Bridge()
{
}
IrcClient* Bridge::get_irc_client(const std::string& hostname, const std::string& username)
{
try
{
return this->irc_clients.at(hostname).get();
}
catch (const std::out_of_range& exception)
{
this->irc_clients.emplace(hostname, std::make_shared<IrcClient>(hostname, username, this));
std::shared_ptr<IrcClient> irc = this->irc_clients.at(hostname);
this->poller->add_socket_handler(irc);
irc->start();
return irc.get();
}
}
void Bridge::join_irc_channel(const Iid& iid, const std::string& username)
{
IrcClient* irc = this->get_irc_client(iid.server, username);
irc->send_join_command(iid.chan);
}
void Bridge::send_xmpp_message(const std::string& from, const std::string& author, const std::string& msg)
{
const std::string body = std::string("[") + author + std::string("] ") + msg;
this->xmpp->send_message(from, body, this->user_jid);
}
void Bridge::send_user_join(const std::string& hostname, const std::string& chan_name, const std::string nick)
{
this->xmpp->send_user_join(chan_name + "%" + hostname, nick, this->user_jid);
}
void Bridge::send_self_join(const std::string& hostname, const std::string& chan_name, const std::string nick)
{
this->xmpp->send_self_join(chan_name + "%" + hostname, nick, this->user_jid);
}
void Bridge::send_topic(const std::string& hostname, const std::string& chan_name, const std::string topic)
{
this->xmpp->send_topic(chan_name + "%" + hostname, topic, this->user_jid);
}