Refactor attributes name

This commit is contained in:
Mickael Remond 2018-01-13 17:54:07 +01:00
parent d2765aec15
commit 01063ec284
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3
9 changed files with 14 additions and 14 deletions

View File

@ -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)

View File

@ -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")

2
iq.go
View File

@ -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

View File

@ -12,8 +12,8 @@ func TestUnmarshalIqs(t *testing.T) {
iqString string
parsedIQ ClientIQ
}{
{"<iq id=\"1\" type=\"set\" to=\"test@localhost\"/>", ClientIQ{XMLName: xml.Name{Space: "", Local: "iq"}, Packet: Packet{To: "test@localhost", Type: "set", Id: "1"}}},
//{"<iq xmlns=\"jabber:client\" id=\"2\" type=\"set\" to=\"test@localhost\" from=\"server\"><set xmlns=\"urn:xmpp:iot:control\"/></iq>", ClientIQ{XMLName: xml.Name{Space: "jabber:client", Local: "iq"}, Packet: Packet{To: "test@localhost", From: "server", Type: "set", Id: "2"}, Payload: cs1}},
{"<iq id=\"1\" type=\"set\" to=\"test@localhost\"/>", ClientIQ{XMLName: xml.Name{Space: "", Local: "iq"}, PacketAttrs: PacketAttrs{To: "test@localhost", Type: "set", Id: "1"}}},
//{"<iq xmlns=\"jabber:client\" id=\"2\" type=\"set\" to=\"test@localhost\" from=\"server\"><set xmlns=\"urn:xmpp:iot:control\"/></iq>", 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 {

View File

@ -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"`

View File

@ -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"`

View File

@ -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)
}

View File

@ -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"`

View File

@ -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