In fixed mode, server messages come from biboumi’s hostname directly
Instead of irc.example.com@biboumi, because that’s actually user named “irc.example.com”, in that case. And that fixes the raw messages in fixed mode. fix #3286
This commit is contained in:
1 parent
2c717d347d
commit
25243f53c2
4 files changed
+57
-19
No files matched your search
@@ -932,7 +932,10 @@ void Bridge::send_xmpp_message(const std::string& from, const std::string& autho
|
|||||||
const auto encoding = in_encoding_for(*this, {from, this});
|
const auto encoding = in_encoding_for(*this, {from, this});
|
||||||
for (const auto& resource: this->resources_in_server[from])
|
for (const auto& resource: this->resources_in_server[from])
|
||||||
{
|
{
|
||||||
|
if (Config::get("fixed_irc_server", "").empty())
|
||||||
this->xmpp.send_message(from, this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false);
|
this->xmpp.send_message(from, this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false);
|
||||||
|
else
|
||||||
|
this->xmpp.send_message("", this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ void BiboumiComponent::handle_message(const Stanza& stanza)
|
|||||||
{
|
{
|
||||||
if (body && !body->get_inner().empty())
|
if (body && !body->get_inner().empty())
|
||||||
{
|
{
|
||||||
|
const auto fixed_irc_server = Config::get("fixed_irc_server", "");
|
||||||
// a message for nick!server
|
// a message for nick!server
|
||||||
if (iid.type == Iid::Type::User && !iid.get_local().empty())
|
if (iid.type == Iid::Type::User && !iid.get_local().empty())
|
||||||
{
|
{
|
||||||
@@ -296,9 +297,11 @@ void BiboumiComponent::handle_message(const Stanza& stanza)
|
|||||||
bridge->set_preferred_from_jid(user_iid.get_local(), to_str);
|
bridge->set_preferred_from_jid(user_iid.get_local(), to_str);
|
||||||
}
|
}
|
||||||
else if (iid.type == Iid::Type::Server)
|
else if (iid.type == Iid::Type::Server)
|
||||||
|
bridge->send_raw_message(iid.get_server(), body->get_inner());
|
||||||
|
else if (iid.type == Iid::Type::None && !fixed_irc_server.empty())
|
||||||
{ // Message sent to the server JID
|
{ // Message sent to the server JID
|
||||||
// Convert the message body into a raw IRC message
|
// Convert the message body into a raw IRC message
|
||||||
bridge->send_raw_message(iid.get_server(), body->get_inner());
|
bridge->send_raw_message(fixed_irc_server, body->get_inner());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -277,7 +277,12 @@ void XmppComponent::send_message(const std::string& from, Xmpp::body&& body, con
|
|||||||
if (fulljid)
|
if (fulljid)
|
||||||
message["from"] = from;
|
message["from"] = from;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (!from.empty())
|
||||||
message["from"] = from + "@" + this->served_hostname;
|
message["from"] = from + "@" + this->served_hostname;
|
||||||
|
else
|
||||||
|
message["from"] = this->served_hostname;
|
||||||
|
}
|
||||||
if (!type.empty())
|
if (!type.empty())
|
||||||
message["type"] = type;
|
message["type"] = type;
|
||||||
XmlSubNode body_node(message, "body");
|
XmlSubNode body_node(message, "body");
|
||||||
|
|||||||
@@ -403,8 +403,12 @@ def handshake_sequence():
|
|||||||
partial(send_stanza, "<handshake xmlns='jabber:component:accept'/>"))
|
partial(send_stanza, "<handshake xmlns='jabber:component:accept'/>"))
|
||||||
|
|
||||||
|
|
||||||
def connection_begin_sequence(irc_host, jid, expected_irc_presence=False):
|
def connection_begin_sequence(irc_host, jid, expected_irc_presence=False, fixed_irc_server=False):
|
||||||
jid = jid.format_map(common_replacements)
|
jid = jid.format_map(common_replacements)
|
||||||
|
if fixed_irc_server:
|
||||||
|
xpath = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[text()='%s']"
|
||||||
|
xpath_re = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
|
else:
|
||||||
xpath = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[text()='%s']"
|
xpath = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[text()='%s']"
|
||||||
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
result = (
|
result = (
|
||||||
@@ -440,8 +444,12 @@ def connection_begin_sequence(irc_host, jid, expected_irc_presence=False):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def connection_tls_begin_sequence(irc_host, jid):
|
def connection_tls_begin_sequence(irc_host, jid, fixed_irc_server):
|
||||||
jid = jid.format_map(common_replacements)
|
jid = jid.format_map(common_replacements)
|
||||||
|
if fixed_irc_server:
|
||||||
|
xpath = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[text()='%s']"
|
||||||
|
xpath_re = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
|
else:
|
||||||
xpath = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[text()='%s']"
|
xpath = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[text()='%s']"
|
||||||
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
irc_host = 'irc.localhost'
|
irc_host = 'irc.localhost'
|
||||||
@@ -463,8 +471,12 @@ def connection_tls_begin_sequence(irc_host, jid):
|
|||||||
xpath_re % (r'^%s: (\*\*\* Checking Ident|\*\*\* Looking up your hostname\.\.\.|\*\*\* Found your hostname: .*|ACK multi-prefix|\*\*\* Got Ident response)$' % irc_host)),
|
xpath_re % (r'^%s: (\*\*\* Checking Ident|\*\*\* Looking up your hostname\.\.\.|\*\*\* Found your hostname: .*|ACK multi-prefix|\*\*\* Got Ident response)$' % irc_host)),
|
||||||
)
|
)
|
||||||
|
|
||||||
def connection_end_sequence(irc_host, jid):
|
def connection_end_sequence(irc_host, jid, fixed_irc_server=False):
|
||||||
jid = jid.format_map(common_replacements)
|
jid = jid.format_map(common_replacements)
|
||||||
|
if fixed_irc_server:
|
||||||
|
xpath = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[text()='%s']"
|
||||||
|
xpath_re = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
|
else:
|
||||||
xpath = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[text()='%s']"
|
xpath = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[text()='%s']"
|
||||||
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
irc_host = 'irc.localhost'
|
irc_host = 'irc.localhost'
|
||||||
@@ -493,7 +505,10 @@ def connection_end_sequence(irc_host, jid):
|
|||||||
xpath_re % r'^User mode for \w+ is \[\+Z?i\]$'),
|
xpath_re % r'^User mode for \w+ is \[\+Z?i\]$'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def connection_middle_sequence(irc_host, jid):
|
def connection_middle_sequence(irc_host, jid, fixed_irc_server=False):
|
||||||
|
if fixed_irc_server:
|
||||||
|
xpath_re = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
|
else:
|
||||||
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
xpath_re = "/message[@to='" + jid + "'][@from='" + irc_host + "@biboumi.localhost']/body[re:test(text(), '%s')]"
|
||||||
irc_host = 'irc.localhost'
|
irc_host = 'irc.localhost'
|
||||||
return (
|
return (
|
||||||
@@ -501,15 +516,15 @@ def connection_middle_sequence(irc_host, jid):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def connection_sequence(irc_host, jid, expected_irc_presence=False):
|
def connection_sequence(irc_host, jid, expected_irc_presence=False, fixed_irc_server=False):
|
||||||
return connection_begin_sequence(irc_host, jid, expected_irc_presence) +\
|
return connection_begin_sequence(irc_host, jid, expected_irc_presence, fixed_irc_server=fixed_irc_server) +\
|
||||||
connection_middle_sequence(irc_host, jid) +\
|
connection_middle_sequence(irc_host, jid, fixed_irc_server=fixed_irc_server) +\
|
||||||
connection_end_sequence(irc_host, jid)
|
connection_end_sequence(irc_host, jid, fixed_irc_server=fixed_irc_server)
|
||||||
|
|
||||||
def connection_tls_sequence(irc_host, jid):
|
def connection_tls_sequence(irc_host, jid, fixed_irc_server=False):
|
||||||
return connection_tls_begin_sequence(irc_host, jid) + \
|
return connection_tls_begin_sequence(irc_host, jid, fixed_irc_server) + \
|
||||||
connection_middle_sequence(irc_host, jid) +\
|
connection_middle_sequence(irc_host, jid, fixed_irc_server) +\
|
||||||
connection_end_sequence(irc_host, jid)
|
connection_end_sequence(irc_host, jid, fixed_irc_server)
|
||||||
|
|
||||||
|
|
||||||
def extract_attribute(xpath, name, stanza):
|
def extract_attribute(xpath, name, stanza):
|
||||||
@@ -824,7 +839,7 @@ if __name__ == '__main__':
|
|||||||
handshake_sequence(),
|
handshake_sequence(),
|
||||||
partial(send_stanza,
|
partial(send_stanza,
|
||||||
"<presence from='{jid_one}/{resource_one}' to='#zgeg@{biboumi_host}/{nick_one}' />"),
|
"<presence from='{jid_one}/{resource_one}' to='#zgeg@{biboumi_host}/{nick_one}' />"),
|
||||||
connection_sequence("irc.localhost", '{jid_one}/{resource_one}'),
|
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', fixed_irc_server=True),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
"/message/body[text()='Mode #zgeg [+nt] by {irc_host_one}']"),
|
"/message/body[text()='Mode #zgeg [+nt] by {irc_host_one}']"),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
@@ -1437,7 +1452,7 @@ if __name__ == '__main__':
|
|||||||
handshake_sequence(),
|
handshake_sequence(),
|
||||||
partial(send_stanza,
|
partial(send_stanza,
|
||||||
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
||||||
connection_sequence("irc.localhost", '{jid_one}/{resource_one}'),
|
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', fixed_irc_server=True),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
@@ -1933,7 +1948,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
partial(send_stanza,
|
partial(send_stanza,
|
||||||
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
||||||
connection_sequence("irc.localhost", '{jid_one}/{resource_one}'),
|
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', fixed_irc_server=True),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
@@ -2011,7 +2026,7 @@ if __name__ == '__main__':
|
|||||||
# First user join
|
# First user join
|
||||||
partial(send_stanza,
|
partial(send_stanza,
|
||||||
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
||||||
connection_sequence("irc.localhost", '{jid_one}/{resource_one}'),
|
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', fixed_irc_server=True),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
@@ -2402,6 +2417,18 @@ if __name__ == '__main__':
|
|||||||
partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='{irc_server_one}' type='chat'><body>WHOIS {nick_one}</body></message>"),
|
partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='{irc_server_one}' type='chat'><body>WHOIS {nick_one}</body></message>"),
|
||||||
partial(expect_stanza, "/message[@from='{irc_server_one}'][@type='chat']/body[text()='irc.localhost: {nick_one} ~{nick_one} localhost * {nick_one}']"),
|
partial(expect_stanza, "/message[@from='{irc_server_one}'][@type='chat']/body[text()='irc.localhost: {nick_one} ~{nick_one} localhost * {nick_one}']"),
|
||||||
]),
|
]),
|
||||||
|
Scenario("raw_message_fixed_irc_server",
|
||||||
|
[
|
||||||
|
handshake_sequence(),
|
||||||
|
partial(send_stanza, "<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' />"),
|
||||||
|
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', fixed_irc_server=True),
|
||||||
|
partial(expect_stanza, "/message"),
|
||||||
|
partial(expect_stanza, "/presence"),
|
||||||
|
partial(expect_stanza, "/message"),
|
||||||
|
|
||||||
|
partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='{biboumi_host}' type='chat'><body>WHOIS {nick_one}</body></message>"),
|
||||||
|
partial(expect_stanza, "/message[@from='{biboumi_host}'][@type='chat']/body[text()='irc.localhost: {nick_one} ~{nick_one} localhost * {nick_one}']"),
|
||||||
|
], conf='fixed_server'),
|
||||||
Scenario("self_disco_info",
|
Scenario("self_disco_info",
|
||||||
[
|
[
|
||||||
handshake_sequence(),
|
handshake_sequence(),
|
||||||
@@ -2752,7 +2779,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
partial(send_stanza,
|
partial(send_stanza,
|
||||||
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
"<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"),
|
||||||
connection_sequence("irc.localhost", '{jid_one}/{resource_one}'),
|
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', fixed_irc_server=True),
|
||||||
partial(expect_stanza, "/message"),
|
partial(expect_stanza, "/message"),
|
||||||
partial(expect_stanza, "/presence"),
|
partial(expect_stanza, "/presence"),
|
||||||
partial(expect_stanza, "/message"),
|
partial(expect_stanza, "/message"),
|
||||||
@@ -2827,7 +2854,7 @@ if __name__ == '__main__':
|
|||||||
"<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' />"),
|
"<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' />"),
|
||||||
|
|
||||||
# We must receive the IRC server presence, in the connection sequence
|
# We must receive the IRC server presence, in the connection sequence
|
||||||
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', True),
|
connection_sequence("irc.localhost", '{jid_one}/{resource_one}', expected_irc_presence=True),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
|
||||||
partial(expect_stanza,
|
partial(expect_stanza,
|
||||||
|
|||||||
Reference in new issue
Block a user