diff options
author | Florent Le Coz <louiz@louiz.org> | 2013-11-06 20:51:05 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2013-11-06 21:01:18 +0100 |
commit | bf7b05ef72bbdac97704d262ddfe418908267535 (patch) | |
tree | b23b3a5a5d469c47c37422559be76ee34238649a /src/irc/irc_client.hpp | |
parent | dea7f60fa1ae6a46228daa36bcb3fec1a6c6ffc3 (diff) | |
download | biboumi-bf7b05ef72bbdac97704d262ddfe418908267535.tar.gz biboumi-bf7b05ef72bbdac97704d262ddfe418908267535.tar.bz2 biboumi-bf7b05ef72bbdac97704d262ddfe418908267535.tar.xz biboumi-bf7b05ef72bbdac97704d262ddfe418908267535.zip |
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.
Diffstat (limited to 'src/irc/irc_client.hpp')
-rw-r--r-- | src/irc/irc_client.hpp | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp index e380f5b..db1b83b 100644 --- a/src/irc/irc_client.hpp +++ b/src/irc/irc_client.hpp @@ -2,11 +2,16 @@ # define IRC_CLIENT_INCLUDED #include <irc/irc_message.hpp> +#include <irc/irc_channel.hpp> +#include <irc/iid.hpp> #include <network/socket_handler.hpp> +#include <unordered_map> #include <string> +class Bridge; + /** * Represent one IRC client, i.e. an endpoint connected to a single IRC * server, through a TCP socket, receiving and sending commands to it. @@ -16,9 +21,13 @@ class IrcClient: public SocketHandler { public: - explicit IrcClient(); + explicit IrcClient(const std::string& hostname, const std::string& username, Bridge* bridge); ~IrcClient(); /** + * Connect to the IRC server + */ + void start(); + /** * Called when successfully connected to the server */ void on_connected(); @@ -32,12 +41,20 @@ public: */ void parse_in_buffer(); /** + * Return the channel with this name, create it if it does not yet exist + */ + IrcChannel* get_channel(const std::string& name); + /** * Serialize the given message into a line, and send that into the socket * (actually, into our out_buf and signal the poller that we want to wach * for send events to be ready) */ void send_message(IrcMessage&& message); /** + * Send the PONG irc command + */ + void send_pong_command(); + /** * Send the USER irc command */ void send_user_command(const std::string& username, const std::string& realname); @@ -49,8 +66,49 @@ public: * Send the JOIN irc command */ void send_join_command(const std::string& chan_name); + /** + * Forward the server message received from IRC to the XMPP component + */ + void forward_server_message(const IrcMessage& message); + /** + * Forward the join of an other user into an IRC channel, and save the + * IrcUsers in the IrcChannel + */ + void set_and_forward_user_list(const IrcMessage& message); + /** + * Remember our nick and host, when we are joined to the channel. The list + * of user comes after so we do not send the self-presence over XMPP yet. + */ + void on_self_channel_join(const IrcMessage& message); + /** + * Save the topic in the IrcChannel + */ + void on_topic_received(const IrcMessage& message); + /** + * The channel has been completely joined (self presence, topic, all names + * received etc), send the self presence and topic to the XMPP user. + */ + void on_channel_completely_joined(const IrcMessage& message); private: + /** + * The hostname of the server we are connected to. + */ + const std::string hostname; + /** + * The user name used in the USER irc command + */ + const std::string username; + /** + * Raw pointer because the bridge owns us. + */ + Bridge* bridge; + + /** + * The list of joined channels, indexed by name + */ + std::unordered_map<std::string, std::unique_ptr<IrcChannel>> channels; + IrcClient(const IrcClient&) = delete; IrcClient(IrcClient&&) = delete; IrcClient& operator=(const IrcClient&) = delete; |