From 7c1a38999c2eebfbd0939c9f8f8f864f10d9bc9a Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 11 Jun 2014 02:37:11 +0200 Subject: Rewrite the whole IID usage IRC users and channels are now distinguished by the separator used in the IID (% or !). ref #2468 --- src/xmpp/xmpp_component.cpp | 40 ++++++++++++++++++++++++++++++++++++---- src/xmpp/xmpp_component.hpp | 8 +++++++- 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'src/xmpp') diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 4c9c8ff..ec8517c 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -306,7 +306,7 @@ void XmppComponent::handle_presence(const Stanza& stanza) error_type, error_name, ""); }); - if (!iid.server.empty()) + if (iid.is_channel && !iid.get_server().empty()) { // presence toward a MUC that corresponds to an irc channel, or a // dummy channel if iid.chan is empty if (type.empty()) @@ -353,7 +353,7 @@ void XmppComponent::handle_message(const Stanza& stanza) error_type, error_name, ""); }); XmlNode* body = stanza.get_child("body", COMPONENT_NS); - if (type == "groupchat") + if (type == "groupchat" && iid.is_channel) { if (to.resource.empty()) if (body && !body->get_inner().empty()) @@ -379,11 +379,13 @@ void XmppComponent::handle_message(const Stanza& stanza) if (kickable_error) bridge->shutdown("Error from remote client"); } - else if (type == "chat") + else if (type == "chat" && iid.is_user && !iid.get_local().empty()) { if (body && !body->get_inner().empty()) bridge->send_private_message(iid, body->get_inner()); } + else if (iid.is_user) + this->send_invalid_user_error(to.local, from); stanza_error.disable(); } @@ -671,6 +673,36 @@ void XmppComponent::send_invalid_room_error(const std::string& muc_name, this->send_stanza(presence); } +void XmppComponent::send_invalid_user_error(const std::string& user_name, const std::string& to) +{ + Stanza message("message"); + message["from"] = user_name + "@" + this->served_hostname; + message["to"] = to; + message["type"] = "error"; + XmlNode x("x"); + x["xmlns"] = MUC_NS; + x.close(); + message.add_child(std::move(x)); + XmlNode error("error"); + error["type"] = "cancel"; + XmlNode item_not_found("item-not-found"); + item_not_found["xmlns"] = STANZA_NS; + item_not_found.close(); + error.add_child(std::move(item_not_found)); + XmlNode text("text"); + text["xmlns"] = STANZA_NS; + text["xml:lang"] = "en"; + text.set_inner(user_name + + " is not a valid IRC user name. A correct user jid is of the form: !@" + + this->served_hostname); + text.close(); + error.add_child(std::move(text)); + error.close(); + message.add_child(std::move(error)); + message.close(); + this->send_stanza(message); +} + void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, const std::string& to) { XmlNode message("message"); @@ -711,7 +743,7 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str this->send_stanza(message); } -void XmppComponent::send_muc_leave(std::string&& muc_name, std::string&& nick, Xmpp::body&& message, const std::string& jid_to, const bool self) +void XmppComponent::send_muc_leave(const std::string& muc_name, std::string&& nick, Xmpp::body&& message, const std::string& jid_to, const bool self) { Stanza presence("presence"); presence["to"] = jid_to; diff --git a/src/xmpp/xmpp_component.hpp b/src/xmpp/xmpp_component.hpp index 5de471c..f1806de 100644 --- a/src/xmpp/xmpp_component.hpp +++ b/src/xmpp/xmpp_component.hpp @@ -130,6 +130,12 @@ public: void send_invalid_room_error(const std::string& muc_jid, const std::string& nick, const std::string& to); + /** + * Send an error to indicate that the user tried to send a message to an + * invalid user. + */ + void send_invalid_user_error(const std::string& user_name, + const std::string& to); /** * Send the MUC topic to the user */ @@ -141,7 +147,7 @@ public: /** * Send an unavailable presence for this nick */ - void send_muc_leave(std::string&& muc_name, std::string&& nick, Xmpp::body&& message, const std::string& jid_to, const bool self); + void send_muc_leave(const std::string& muc_name, std::string&& nick, Xmpp::body&& message, const std::string& jid_to, const bool self); /** * Indicate that a participant changed his nick */ -- cgit v1.2.3