From 0b0c0fa5abbd9f53d341f02c9091068cb1a66dc8 Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Tue, 9 Jul 2019 18:05:26 +0200 Subject: [PATCH] Simplify disco and software version Make use of helpers. --- _examples/xmpp_component/xmpp_component.go | 37 ++++------------------ 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/_examples/xmpp_component/xmpp_component.go b/_examples/xmpp_component/xmpp_component.go index 4bc906b..77a3099 100644 --- a/_examples/xmpp_component/xmpp_component.go +++ b/_examples/xmpp_component/xmpp_component.go @@ -1,7 +1,6 @@ package main import ( - "encoding/xml" "fmt" "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"}) - identity := stanza.Identity{ - Name: opts.Name, - Category: opts.Category, - 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 + disco := iqResp.DiscoInfo() + disco.AddIdentity(opts.Name, opts.Category, opts.Type) + disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1") _ = 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"}) + items := iqResp.DiscoItems() - var payload stanza.DiscoItems if discoItems.Node == "" { - payload = stanza.DiscoItems{ - Items: []stanza.DiscoItem{ - {Name: "test node", JID: "service.localhost", Node: "node1"}, - }, - } + items.AddItem("service.localhost", "node1", "test node") } - iqResp.Payload = &payload _ = 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"}) - var payload stanza.Version - payload.Name = "Fluux XMPP Component" - payload.Version = "0.0.1" - iq.Payload = &payload + iqResp.Version().SetInfo("Fluux XMPP Component", "0.0.1", "") _ = c.Send(iqResp) }