From 01063ec284aebbf1a01e75466d059b7435363ffc Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Sat, 13 Jan 2018 17:54:07 +0100 Subject: [PATCH] Refactor attributes name --- cmd/xmpp_echo/xmpp_echo.go | 2 +- cmd/xmpp_jukebox/xmpp_jukebox.go | 2 +- iq.go | 2 +- iq_test.go | 4 ++-- message.go | 2 +- packet.go | 4 ++-- pep/user_tune.go | 8 ++++---- presence.go | 2 +- stream.go | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/xmpp_echo/xmpp_echo.go b/cmd/xmpp_echo/xmpp_echo.go index 69067be..012c713 100644 --- a/cmd/xmpp_echo/xmpp_echo.go +++ b/cmd/xmpp_echo/xmpp_echo.go @@ -33,7 +33,7 @@ func main() { switch packet := packet.(type) { case *xmpp.ClientMessage: fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", packet.Body, packet.From) - reply := xmpp.ClientMessage{Packet: xmpp.Packet{To: packet.From}, Body: packet.Body} + reply := xmpp.ClientMessage{PacketAttrs: xmpp.PacketAttrs{To: packet.From}, Body: packet.Body} client.Send(reply.XMPPFormat()) default: fmt.Fprintf(os.Stdout, "Ignoring packet: %T\n", packet) diff --git a/cmd/xmpp_jukebox/xmpp_jukebox.go b/cmd/xmpp_jukebox/xmpp_jukebox.go index 0591b4b..a1737e6 100644 --- a/cmd/xmpp_jukebox/xmpp_jukebox.go +++ b/cmd/xmpp_jukebox/xmpp_jukebox.go @@ -76,7 +76,7 @@ func processIq(client *xmpp.Client, p *mpg123.Player, packet *xmpp.ClientIQ) { playSCURL(p, url) setResponse := new(iot.ControlSetResponse) - reply := xmpp.ClientIQ{Packet: xmpp.Packet{To: packet.From, Type: "result", Id: packet.Id}, Payload: setResponse} + reply := xmpp.ClientIQ{PacketAttrs: xmpp.PacketAttrs{To: packet.From, Type: "result", Id: packet.Id}, Payload: setResponse} client.Send(reply.XMPPFormat()) // TODO add Soundclound artist / title retrieval sendUserTune(client, "Radiohead", "Spectre") diff --git a/iq.go b/iq.go index f737e82..9c02dc1 100644 --- a/iq.go +++ b/iq.go @@ -10,7 +10,7 @@ import ( // info/query type ClientIQ struct { XMLName xml.Name `xml:"jabber:client iq"` - Packet + PacketAttrs Payload IQPayload `xml:",omitempty"` RawXML string `xml:",innerxml"` // TODO We need to support detecting the IQ namespace / Query packet diff --git a/iq_test.go b/iq_test.go index b8859c0..71e9edd 100644 --- a/iq_test.go +++ b/iq_test.go @@ -12,8 +12,8 @@ func TestUnmarshalIqs(t *testing.T) { iqString string parsedIQ ClientIQ }{ - {"", ClientIQ{XMLName: xml.Name{Space: "", Local: "iq"}, Packet: Packet{To: "test@localhost", Type: "set", Id: "1"}}}, - //{"", ClientIQ{XMLName: xml.Name{Space: "jabber:client", Local: "iq"}, Packet: Packet{To: "test@localhost", From: "server", Type: "set", Id: "2"}, Payload: cs1}}, + {"", ClientIQ{XMLName: xml.Name{Space: "", Local: "iq"}, PacketAttrs: PacketAttrs{To: "test@localhost", Type: "set", Id: "1"}}}, + //{"", ClientIQ{XMLName: xml.Name{Space: "jabber:client", Local: "iq"}, PacketAttrs: PacketAttrs{To: "test@localhost", From: "server", Type: "set", Id: "2"}, Payload: cs1}}, } for _, test := range tests { diff --git a/message.go b/message.go index dbcd0ad..5ae14d2 100644 --- a/message.go +++ b/message.go @@ -8,7 +8,7 @@ import ( // XMPP Packet Parsing type ClientMessage struct { XMLName xml.Name `xml:"jabber:client message"` - Packet + PacketAttrs Subject string `xml:"subject,omitempty"` Body string `xml:"body,omitempty"` Thread string `xml:"thread,omitempty"` diff --git a/packet.go b/packet.go index a896440..9e58773 100644 --- a/packet.go +++ b/packet.go @@ -1,7 +1,7 @@ package xmpp // import "fluux.io/xmpp" -// Packet represents the root default structure for an XMPP packet. -type Packet struct { +// PacketAttrs represents the common structure for base XMPP packets. +type PacketAttrs struct { Id string `xml:"id,attr,omitempty"` From string `xml:"from,attr,omitempty"` To string `xml:"to,attr,omitempty"` diff --git a/pep/user_tune.go b/pep/user_tune.go index 846dda0..70b4b47 100644 --- a/pep/user_tune.go +++ b/pep/user_tune.go @@ -7,9 +7,9 @@ import ( ) type iq struct { - XMLName xml.Name `xml:"jabber:client iq"` - C pubSub // c for "contains" - xmpp.Packet // Rename h for "header" ? + XMLName xml.Name `xml:"jabber:client iq"` + C pubSub // c for "contains" + xmpp.PacketAttrs // Rename h for "header" ? } type pubSub struct { @@ -68,7 +68,7 @@ type Tune struct { */ func (t *Tune) XMPPFormat() (s string) { - packet, _ := xml.Marshal(iq{Packet: xmpp.Packet{Id: "tunes", Type: "set"}, C: pubSub{Publish: publish{Node: "http://jabber.org/protocol/tune", Item: item{Tune: *t}}}}) + packet, _ := xml.Marshal(iq{PacketAttrs: xmpp.PacketAttrs{Id: "tunes", Type: "set"}, C: pubSub{Publish: publish{Node: "http://jabber.org/protocol/tune", Item: item{Tune: *t}}}}) return string(packet) } diff --git a/presence.go b/presence.go index 21cfd77..6c9eb29 100644 --- a/presence.go +++ b/presence.go @@ -5,7 +5,7 @@ import "encoding/xml" // XMPP Packet Parsing type ClientPresence struct { XMLName xml.Name `xml:"jabber:client presence"` - Packet + PacketAttrs Show string `xml:"show,attr,omitempty"` // away, chat, dnd, xa Status string `xml:"status,attr,omitempty"` Priority string `xml:"priority,attr,omitempty"` diff --git a/stream.go b/stream.go index 510169c..e5173c6 100644 --- a/stream.go +++ b/stream.go @@ -2,7 +2,7 @@ package xmpp // import "fluux.io/xmpp" import "encoding/xml" -// XMPP Packet Parsing +// XMPP PacketAttrs Parsing type streamFeatures struct { XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"` StartTLS tlsStartTLS