Make sure we keep the stable-id and origin-id nodes when required
See https://xmpp.org/extensions/xep-0359.html
This commit is contained in:
+14
-6
@@ -196,7 +196,7 @@ bool Bridge::join_irc_channel(const Iid& iid, std::string nickname,
|
||||
return false;
|
||||
}
|
||||
|
||||
void Bridge::send_channel_message(const Iid& iid, const std::string& body, std::string id)
|
||||
void Bridge::send_channel_message(const Iid& iid, const std::string& body, std::string id, std::vector<XmlNode> nodes_to_reflect)
|
||||
{
|
||||
if (iid.get_server().empty())
|
||||
{
|
||||
@@ -234,15 +234,21 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body, std::
|
||||
if (!first || id.empty())
|
||||
id = utils::gen_uuid();
|
||||
|
||||
MessageCallback mirror_to_all_resources = [this, iid, uuid, id](const IrcClient* irc, const IrcMessage& message) {
|
||||
MessageCallback mirror_to_all_resources = [this, iid, uuid, id, nodes_to_reflect](const IrcClient* irc, const IrcMessage& message) {
|
||||
std::string line = message.arguments[1];
|
||||
// “temporary” workaround for \01ACTION…\01 -> /me messages
|
||||
if ((line.size() > strlen("\01ACTION\01")) &&
|
||||
(line.substr(0, 7) == "\01ACTION") && line[line.size() - 1] == '\01')
|
||||
line = "/me " + line.substr(8, line.size() - 9);
|
||||
for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
|
||||
this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line),
|
||||
this->user_jid + "/" + resource, uuid, id);
|
||||
{
|
||||
auto stanza = this->xmpp.make_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line),
|
||||
this->user_jid + "/"
|
||||
+ resource, uuid, id);
|
||||
for (const auto& node: nodes_to_reflect)
|
||||
stanza.add_child(node);
|
||||
this->xmpp.send_stanza(stanza);
|
||||
}
|
||||
};
|
||||
|
||||
if (line.substr(0, 5) == "/mode")
|
||||
@@ -859,8 +865,10 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
|
||||
#endif
|
||||
for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
|
||||
{
|
||||
this->xmpp.send_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding),
|
||||
this->user_jid + "/" + resource, uuid, utils::gen_uuid());
|
||||
auto stanza = this->xmpp.make_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding),
|
||||
this->user_jid + "/"
|
||||
+ resource, uuid, utils::gen_uuid());
|
||||
this->xmpp.send_stanza(stanza);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
HistoryLimit history_limit,
|
||||
const bool force_join);
|
||||
|
||||
void send_channel_message(const Iid& iid, const std::string& body, std::string id);
|
||||
void send_channel_message(const Iid& iid, const std::string& body, std::string id, std::vector<XmlNode> nodes_to_reflect);
|
||||
void send_private_message(const Iid& iid, const std::string& body, const std::string& type="PRIVMSG");
|
||||
void send_raw_message(const std::string& hostname, const std::string& body);
|
||||
void leave_irc_channel(Iid&& iid, const std::string& status_message, const std::string& resource);
|
||||
|
||||
@@ -286,7 +286,26 @@ void BiboumiComponent::handle_message(const Stanza& stanza)
|
||||
if (body && !body->get_inner().empty())
|
||||
{
|
||||
if (bridge->is_resource_in_chan(iid.to_tuple(), from.resource))
|
||||
bridge->send_channel_message(iid, body->get_inner(), id);
|
||||
{
|
||||
// Extract some XML nodes that we must include in the
|
||||
// reflection (if any), because XMPP says so
|
||||
std::vector<XmlNode> nodes_to_reflect;
|
||||
const XmlNode* origin_id = stanza.get_child("origin-id", STABLE_ID_NS);
|
||||
if (origin_id)
|
||||
nodes_to_reflect.push_back(*origin_id);
|
||||
const auto own_address = std::to_string(iid) + '@' + this->served_hostname;
|
||||
for (const XmlNode* stable_id: stanza.get_children("stable-id", STABLE_ID_NS))
|
||||
{
|
||||
// Stanza ID generating entities, which encounter a
|
||||
// <stanza-id/> element where the 'by' attribute matches
|
||||
// the 'by' attribute they would otherwise set, MUST
|
||||
// delete that element even if they are not adding their
|
||||
// own stanza ID.
|
||||
if (stable_id->get_tag("by") != own_address)
|
||||
nodes_to_reflect.push_back(*stable_id);
|
||||
}
|
||||
bridge->send_channel_message(iid, body->get_inner(), id, std::move(nodes_to_reflect));
|
||||
}
|
||||
else
|
||||
{
|
||||
error_type = "modify";
|
||||
|
||||
@@ -367,7 +367,7 @@ void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, cons
|
||||
this->send_stanza(message);
|
||||
}
|
||||
|
||||
void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to, std::string uuid, std::string id)
|
||||
Stanza XmppComponent::make_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to, std::string uuid, std::string id)
|
||||
{
|
||||
Stanza message("message");
|
||||
message["to"] = jid_to;
|
||||
@@ -399,7 +399,7 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str
|
||||
stanza_id["id"] = std::move(uuid);
|
||||
}
|
||||
|
||||
this->send_stanza(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
#ifdef USE_DATABASE
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
/**
|
||||
* Send a (non-private) message to the MUC
|
||||
*/
|
||||
void send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& body, const std::string& jid_to,
|
||||
Stanza make_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to,
|
||||
std::string uuid, std::string id);
|
||||
#ifdef USE_DATABASE
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from scenarios import *
|
||||
|
||||
import scenarios.simple_channel_join
|
||||
|
||||
# see https://xmpp.org/extensions/xep-0359.html
|
||||
|
||||
scenario = (
|
||||
scenarios.simple_channel_join.scenario,
|
||||
|
||||
send_stanza("""<message id='first_id' from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'>
|
||||
<origin-id xmlns='urn:xmpp:sid:0' id='client-origin-id'/>
|
||||
<stanza-id xmlns='urn:xmpp:sid:0' id='client-stanza-id'/>
|
||||
<body>coucou</body></message>"""),
|
||||
|
||||
# Entities, which are routing stanzas, SHOULD NOT strip any elements
|
||||
# qualified by the 'urn:xmpp:sid:0' namespace from message stanzas
|
||||
# unless the preceding rule applied to those elements.
|
||||
expect_stanza("/message/stable_id:origin-id[@id='client-origin-id']",
|
||||
# Stanza ID generating entities, which encounter a <stanza-id/>
|
||||
# element where the 'by' attribute matches the 'by' attribute they
|
||||
# would otherwise set, MUST delete that element even if they are not
|
||||
# adding their own stanza ID.
|
||||
"/message/stable_id:stanza-id[@id][@by='#foo%{irc_server_one}']",
|
||||
"!/message/stable_id:stanza-id[@id='client-stanza-id']",
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user