summaryrefslogtreecommitdiff
path: root/src/xmpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-06-11 02:37:11 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-06-11 02:37:11 +0200
commit7c1a38999c2eebfbd0939c9f8f8f864f10d9bc9a (patch)
tree258af2b9ab6c31640f4454dd22867ac688e8345b /src/xmpp
parent6210a9d50b216f22a8b755c2c9daea66659514f0 (diff)
downloadbiboumi-7c1a38999c2eebfbd0939c9f8f8f864f10d9bc9a.tar.gz
biboumi-7c1a38999c2eebfbd0939c9f8f8f864f10d9bc9a.tar.bz2
biboumi-7c1a38999c2eebfbd0939c9f8f8f864f10d9bc9a.tar.xz
biboumi-7c1a38999c2eebfbd0939c9f8f8f864f10d9bc9a.zip
Rewrite the whole IID usage
IRC users and channels are now distinguished by the separator used in the IID (% or !). ref #2468
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/xmpp_component.cpp40
-rw-r--r--src/xmpp/xmpp_component.hpp8
2 files changed, 43 insertions, 5 deletions
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: <nick>!<server>@" +
+ 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
@@ -131,6 +131,12 @@ public:
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
*/
void send_topic(const std::string& from, Xmpp::body&& xmpp_topic, const std::string& to);
@@ -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
*/