Simplify disco and software version

Make use of helpers.
This commit is contained in:
Mickael Remond 2019-07-09 18:05:26 +02:00 committed by Mickaël Rémond
parent 61adf7e414
commit 176dcdce33

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"encoding/xml"
"fmt" "fmt"
"log" "log"
@ -61,25 +60,9 @@ func discoInfo(c xmpp.Sender, p stanza.Packet, opts xmpp.ComponentOptions) {
} }
iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: iq.To, To: iq.From, Id: iq.Id, Lang: "en"}) iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: iq.To, To: iq.From, Id: iq.Id, Lang: "en"})
identity := stanza.Identity{ disco := iqResp.DiscoInfo()
Name: opts.Name, disco.AddIdentity(opts.Name, opts.Category, opts.Type)
Category: opts.Category, disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")
Type: opts.Type,
}
payload := stanza.DiscoInfo{
XMLName: xml.Name{
Space: stanza.NSDiscoInfo,
Local: "query",
},
Identity: []stanza.Identity{identity},
Features: []stanza.Feature{
{Var: stanza.NSDiscoInfo},
{Var: stanza.NSDiscoItems},
{Var: "jabber:iq:version"},
{Var: "urn:xmpp:delegation:1"},
},
}
iqResp.Payload = &payload
_ = c.Send(iqResp) _ = c.Send(iqResp)
} }
@ -97,16 +80,11 @@ func discoItems(c xmpp.Sender, p stanza.Packet) {
} }
iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: iq.To, To: iq.From, Id: iq.Id, Lang: "en"}) iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: iq.To, To: iq.From, Id: iq.Id, Lang: "en"})
items := iqResp.DiscoItems()
var payload stanza.DiscoItems
if discoItems.Node == "" { if discoItems.Node == "" {
payload = stanza.DiscoItems{ items.AddItem("service.localhost", "node1", "test node")
Items: []stanza.DiscoItem{
{Name: "test node", JID: "service.localhost", Node: "node1"},
},
} }
}
iqResp.Payload = &payload
_ = c.Send(iqResp) _ = c.Send(iqResp)
} }
@ -118,9 +96,6 @@ func handleVersion(c xmpp.Sender, p stanza.Packet) {
} }
iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: iq.To, To: iq.From, Id: iq.Id, Lang: "en"}) iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: iq.To, To: iq.From, Id: iq.Id, Lang: "en"})
var payload stanza.Version iqResp.Version().SetInfo("Fluux XMPP Component", "0.0.1", "")
payload.Name = "Fluux XMPP Component"
payload.Version = "0.0.1"
iq.Payload = &payload
_ = c.Send(iqResp) _ = c.Send(iqResp)
} }