diff options
author | Florent Le Coz <louiz@louiz.org> | 2013-12-27 15:34:58 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-01-04 01:59:35 +0100 |
commit | 43cc60e4a9e2859fdf67c89e58ee18cf7571f186 (patch) | |
tree | fcf3335a4bc80a825a798cf80dec97fbe06182c7 /src/xmpp | |
parent | e8e592d1ace5413a1e7d8b59b9467c78d8d68ea9 (diff) | |
download | biboumi-43cc60e4a9e2859fdf67c89e58ee18cf7571f186.tar.gz biboumi-43cc60e4a9e2859fdf67c89e58ee18cf7571f186.tar.bz2 biboumi-43cc60e4a9e2859fdf67c89e58ee18cf7571f186.tar.xz biboumi-43cc60e4a9e2859fdf67c89e58ee18cf7571f186.zip |
Handle nickname conflicts by sending the correct XMPP error presence
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/xmpp_component.cpp | 29 | ||||
-rw-r--r-- | src/xmpp/xmpp_component.hpp | 6 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 3c37eb1..1cc4c25 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -20,6 +20,7 @@ #define DISCO_ITEMS_NS DISCO_NS"#items" #define DISCO_INFO_NS DISCO_NS"#info" #define XHTMLIM_NS "http://jabber.org/protocol/xhtml-im" +#define STANZA_NS "urn:ietf:params:xml:ns:xmpp-stanzas" XmppComponent::XmppComponent(const std::string& hostname, const std::string& secret): served_hostname(hostname), @@ -195,8 +196,7 @@ void XmppComponent::handle_presence(const Stanza& stanza) const std::string own_nick = bridge->get_own_nick(iid); if (!own_nick.empty() && own_nick != to.resource) bridge->send_irc_nick_change(iid, to.resource); - else - bridge->join_irc_channel(iid, to.resource); + bridge->join_irc_channel(iid, to.resource); } else if (type == "unavailable") { @@ -479,3 +479,28 @@ void XmppComponent::kick_user(const std::string& muc_name, presence.close(); this->send_stanza(presence); } + +void XmppComponent::send_nickname_conflict_error(const std::string& muc_name, + const std::string& nickname, + const std::string& jid_to) +{ + Stanza presence("presence"); + presence["from"] = muc_name + "@" + this->served_hostname + "/" + nickname; + presence["to"] = jid_to; + XmlNode x("x"); + x["xmlns"] = MUC_NS; + x.close(); + presence.add_child(std::move(x)); + XmlNode error("error"); + error["by"] = muc_name + "@" + this->served_hostname; + error["type"] = "cancel"; + error["code"] = "409"; + XmlNode conflict("conflict"); + conflict["xmlns"] = STANZA_NS; + conflict.close(); + error.add_child(std::move(conflict)); + error.close(); + presence.add_child(std::move(error)); + presence.close(); + this->send_stanza(presence); +} diff --git a/src/xmpp/xmpp_component.hpp b/src/xmpp/xmpp_component.hpp index d76a2c3..63eb88f 100644 --- a/src/xmpp/xmpp_component.hpp +++ b/src/xmpp/xmpp_component.hpp @@ -108,6 +108,12 @@ public: const std::string& author, const std::string& jid_to); /** + * Send a presence type=error with a conflict element + */ + void send_nickname_conflict_error(const std::string& muc_name, + const std::string& nickname, + const std::string& jid_to); + /** * Handle the various stanza types */ void handle_handshake(const Stanza& stanza); |