From 268953a4451c7454fa22f44be0097451e59405a5 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Sun, 29 Oct 2023 10:20:44 +0100 Subject: [PATCH] Reply to XEP-0092 software version requests. --- CHANGELOG.md | 2 ++ const.go | 1 + stanzahandling.go | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df1ce23..fa6cd4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## Unreleased +## Added +- Reply to XEP-0092 software version requests. ## [v0.6.2] 2023-09-29 ### Changed diff --git a/const.go b/const.go index 909fa0b..aeafd54 100644 --- a/const.go +++ b/const.go @@ -36,6 +36,7 @@ const ( nsOxPubKeys = "urn:xmpp:openpgp:0:public-keys" nsPubsub = "http://jabber.org/protocol/pubsub" nsPubsubOwner = "http://jabber.org/protocol/pubsub#owner" + nsVersion = "jabber:iq:version" nsXMPPStanzas = "urn:ietf:params:xml:ns:xmpp-stanzas" // strings oxAltBody = "This message is encrypted (XEP-0373: OpenPGP for XMPP)." diff --git a/stanzahandling.go b/stanzahandling.go index 7e1e7ae..d47ec1c 100644 --- a/stanzahandling.go +++ b/stanzahandling.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "log" + "runtime" "github.com/beevik/etree" // BSD-2-clause "github.com/mattn/go-xmpp" // BSD-3-Clause @@ -85,6 +86,31 @@ func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat, ctx identity.CreateAttr("name", "go-sendxmpp") feat := replyQuery.CreateElement("feature") feat.CreateAttr("var", nsDiscoInfo) + feat2 := replyQuery.CreateElement("feature") + feat2.CreateAttr("var", nsVersion) + xmlString, err := root.WriteToString() + if err == nil { + _, err = client.SendOrg(xmlString) + if err != nil { + log.Println(err) + } + } + case nsVersion: + root := etree.NewDocument() + root.WriteSettings.AttrSingleQuote = true + reply := root.CreateElement("iq") + reply.CreateAttr("type", "result") + reply.CreateAttr("from", client.JID()) + reply.CreateAttr("to", v.From) + reply.CreateAttr("id", v.ID) + replyQuery := reply.CreateElement("query") + replyQuery.CreateAttr("xmlns", nsVersion) + rqName := replyQuery.CreateElement("name") + rqName.CreateText("go-sendxmpp") + rqVersion := replyQuery.CreateElement("version") + rqVersion.CreateText(version) + rqOS := replyQuery.CreateElement("os") + rqOS.CreateText(runtime.GOOS) xmlString, err := root.WriteToString() if err == nil { _, err = client.SendOrg(xmlString)