mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 10:02:00 -08:00
Simplify disco and software version
Make use of helpers.
This commit is contained in:
parent
61adf7e414
commit
176dcdce33
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user