Merge branch 'user/luca/xmpp-caps' of https://codeberg.org/aninternettroll/biboumi
* 'user/luca/xmpp-caps' of https://codeberg.org/aninternettroll/biboumi: Don't hardcode ver, update node name, and add tests Allow disco queries with a node (needed for CAPS) Add gateway/irc and caps
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <xmpp/hash_disco.hpp>
|
||||
#include <xmpp/biboumi_component.hpp>
|
||||
|
||||
#include <utils/timed_events.hpp>
|
||||
@@ -13,7 +14,6 @@
|
||||
#include <xmpp/jid.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -545,7 +545,8 @@ void BiboumiComponent::handle_iq(const Stanza& stanza)
|
||||
const std::string node = query->get_tag("node");
|
||||
if (to_str == this->served_hostname)
|
||||
{
|
||||
if (node.empty() || node.rfind("https://biboumi.louiz.org/#", 0) == 0)
|
||||
const std::string expected_node_name = (NODE_NAME "#" + this->get_self_ver());
|
||||
if (node.empty() || node == expected_node_name)
|
||||
{
|
||||
// On the gateway itself
|
||||
this->send_self_disco_info(id, from, node);
|
||||
@@ -952,21 +953,18 @@ std::vector<Bridge*> BiboumiComponent::get_bridges() const
|
||||
return res;
|
||||
}
|
||||
|
||||
void BiboumiComponent::send_self_disco_info(const std::string& id, const std::string& jid_to, const std::string& node)
|
||||
Stanza BiboumiComponent::get_self_disco_info(const std::string &node)
|
||||
{
|
||||
Stanza iq("iq");
|
||||
{
|
||||
iq["type"] = "result";
|
||||
iq["id"] = id;
|
||||
if (!node.empty()) iq["node"] = node;
|
||||
iq["to"] = jid_to;
|
||||
iq["from"] = this->served_hostname;
|
||||
XmlSubNode query(iq, "query");
|
||||
query["xmlns"] = DISCO_INFO_NS;
|
||||
if (!node.empty()) query["node"] = node;
|
||||
XmlSubNode gwid(query, "identity");
|
||||
gwid["category"] = "gateway";
|
||||
gwid["type"] = "irc";
|
||||
gwid["name"] = "Biboumi";
|
||||
gwid["name"] = "Biboumi (" SOFTWARE_VERSION ")";
|
||||
XmlSubNode identity(query, "identity");
|
||||
identity["category"] = "conference";
|
||||
identity["type"] = "irc";
|
||||
@@ -977,6 +975,15 @@ void BiboumiComponent::send_self_disco_info(const std::string& id, const std::st
|
||||
feature["var"] = ns;
|
||||
}
|
||||
}
|
||||
return iq;
|
||||
}
|
||||
|
||||
void BiboumiComponent::send_self_disco_info(const std::string& id, const std::string& jid_to, const std::string& node)
|
||||
{
|
||||
Stanza iq = this->get_self_disco_info(node);
|
||||
iq["id"] = id;
|
||||
iq["to"] = jid_to;
|
||||
iq["from"] = this->served_hostname;
|
||||
this->send_stanza(iq);
|
||||
}
|
||||
|
||||
@@ -1213,8 +1220,8 @@ void BiboumiComponent::send_presence_to_contact(const std::string& from, const s
|
||||
XmlSubNode c(presence, "c");
|
||||
c["xmlns"] = CAPS_NS;
|
||||
c["hash"] = "sha-1";
|
||||
c["node"] = "https://biboumi.louiz.org/";
|
||||
c["ver"] = "URGCt+50NTdI6Ifcm1/YYNVxSjc=";
|
||||
c["node"] = NODE_NAME;
|
||||
c["ver"] = this->get_self_ver();
|
||||
}
|
||||
this->send_stanza(presence);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "xmpp/hash_disco.hpp"
|
||||
#include <database/database.hpp>
|
||||
#include <xmpp/xmpp_component.hpp>
|
||||
#include <xmpp/jid.hpp>
|
||||
@@ -90,6 +91,8 @@ public:
|
||||
void send_invitation(const std::string& room_target, const std::string& jid_to, const std::string& author_nick);
|
||||
private:
|
||||
void send_invitation_from_fulljid(const std::string& room_target, const std::string& jid_to, const std::string& from);
|
||||
static Stanza get_self_disco_info(const std::string &node);
|
||||
static std::string get_self_ver() { return Xmpp::hash_disco_sha1(get_self_disco_info("")); };
|
||||
public:
|
||||
void accept_subscription(const std::string& from, const std::string& to);
|
||||
void ask_subscription(const std::string& from, const std::string& to);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include <utils/base64.hpp>
|
||||
#include <utils/sha1.hpp>
|
||||
#include <xmpp/xmpp_component.hpp>
|
||||
|
||||
namespace Xmpp {
|
||||
const std::string hash_disco_sha1(const Stanza &stanza) {
|
||||
std::string s("");
|
||||
const Stanza *query = stanza.get_child("query", DISCO_INFO_NS);
|
||||
std::vector<const XmlNode *> identities = query->get_children("identity", "");
|
||||
|
||||
std::sort(identities.begin(), identities.end(),
|
||||
[](const XmlNode *a, const XmlNode *b) {
|
||||
const std::string category_a = a->get_tag("category");
|
||||
const std::string category_b = b->get_tag("category");
|
||||
const int category_compare = category_a > category_b;
|
||||
if (category_compare != 0)
|
||||
return category_compare;
|
||||
const std::string type_a = a->get_tag("type");
|
||||
const std::string type_b = b->get_tag("type");
|
||||
const int type_compare = type_a > type_b;
|
||||
return type_compare;
|
||||
});
|
||||
|
||||
for (const XmlNode *identity : identities) {
|
||||
const std::string category = identity->get_tag("category");
|
||||
const std::string type = identity->get_tag("type");
|
||||
const std::string name = identity->get_tag("name");
|
||||
s += category + "/" + type + "/" /* + lang + */ "/" + name + "<";
|
||||
}
|
||||
std::vector<const XmlNode *> features = query->get_children("feature", "");
|
||||
|
||||
std::sort(features.begin(), features.end(),
|
||||
[](const XmlNode *a, const XmlNode *b) {
|
||||
const std::string var_a = a->get_tag("var");
|
||||
const std::string var_b = b->get_tag("var");
|
||||
const int var_compare = var_a > var_b;
|
||||
return var_compare;
|
||||
});
|
||||
|
||||
for (const XmlNode *feature : features) {
|
||||
const std::string var = feature->get_tag("var");
|
||||
s += var + "<";
|
||||
}
|
||||
|
||||
const std::string hashed = sha1(s);
|
||||
const std::string encoded = base64::encode(hashed);
|
||||
|
||||
return encoded;
|
||||
}
|
||||
} // namespace Xmpp
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <xmpp/xmpp_stanza.hpp>
|
||||
|
||||
namespace Xmpp
|
||||
{
|
||||
/**
|
||||
* Generate a verification string according to XEP-0115
|
||||
* https://xmpp.org/extensions/xep-0115.html#ver
|
||||
*
|
||||
* This does NOT support Service Discovery Extensions (XEP-0128).
|
||||
* Nor does this sort identities by language
|
||||
*/
|
||||
const std::string hash_disco_sha1(const Stanza &stanza);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
|
||||
#define NODE_NAME "https://biboumi.codeberg.page/"
|
||||
|
||||
#define STREAM_NS "http://etherx.jabber.org/streams"
|
||||
#define COMPONENT_NS "jabber:component:accept"
|
||||
|
||||
@@ -163,4 +163,4 @@ public:
|
||||
}
|
||||
private:
|
||||
XmlNode& parent_to_add;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user