From 321c3529f3fedbd5eaa9cd619ee408fb683921ca Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 18 Dec 2019 18:23:31 +0100 Subject: Add (partial) support for unique stanza ids (XEP-0359) --- .../module/xep/0359_unique_stable_stanza_ids.vala | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala (limited to 'xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala') diff --git a/xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala b/xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala new file mode 100644 index 00000000..b6defc6d --- /dev/null +++ b/xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala @@ -0,0 +1,46 @@ +namespace Xmpp.Xep.UniqueStableStanzaIDs { + +private const string NS_URI = "urn:xmpp:sid:0"; + +private const string HINT_NO_PERMANENT_STORE = "no-permanent-store"; +private const string HINT_NO_STORE = "no-store"; +private const string HINT_NO_COPY = "no-copy"; +private const string HINT_STORE = "store"; + +public class Module : XmppStreamModule { + public static ModuleIdentity IDENTITY = new ModuleIdentity(NS_URI, "0359_unique_and_stable_stanza_ids"); + + public override void attach(XmppStream stream) { + stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); + } + + public override void detach(XmppStream stream) {} + + public override string get_ns() { return NS_URI; } + + public override string get_id() { return IDENTITY.id; } +} + +public static void set_origin_id(MessageStanza message, string origin_id) { + StanzaNode hint_node = (new StanzaNode.build("origin-id", NS_URI)).add_self_xmlns().put_attribute("id", origin_id); + message.stanza.put_node(hint_node); +} + +public static string? get_origin_id(MessageStanza message) { + StanzaNode? node = message.stanza.get_subnode("origin-id", NS_URI); + if (node == null) return null; + + return node.get_attribute("id"); +} + +public static string? get_stanza_id(MessageStanza message, Jid by) { + string by_str = by.to_string(); + foreach (StanzaNode node in message.stanza.get_subnodes("stanza-id", NS_URI)) { + if (node.get_attribute("by") == by_str) { + return node.get_attribute("id"); + } + } + return null; +} + +} -- cgit v1.2.3-54-g00ecf