Refactor attributes name

pull/4/head
Mickael Remond 7 years ago
parent d2765aec15
commit 01063ec284
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3

@ -33,7 +33,7 @@ func main() {
switch packet := packet.(type) { switch packet := packet.(type) {
case *xmpp.ClientMessage: case *xmpp.ClientMessage:
fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", packet.Body, packet.From) 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()) client.Send(reply.XMPPFormat())
default: default:
fmt.Fprintf(os.Stdout, "Ignoring packet: %T\n", packet) fmt.Fprintf(os.Stdout, "Ignoring packet: %T\n", packet)

@ -76,7 +76,7 @@ func processIq(client *xmpp.Client, p *mpg123.Player, packet *xmpp.ClientIQ) {
playSCURL(p, url) playSCURL(p, url)
setResponse := new(iot.ControlSetResponse) 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()) client.Send(reply.XMPPFormat())
// TODO add Soundclound artist / title retrieval // TODO add Soundclound artist / title retrieval
sendUserTune(client, "Radiohead", "Spectre") sendUserTune(client, "Radiohead", "Spectre")

@ -10,7 +10,7 @@ import (
// info/query // info/query
type ClientIQ struct { type ClientIQ struct {
XMLName xml.Name `xml:"jabber:client iq"` XMLName xml.Name `xml:"jabber:client iq"`
Packet PacketAttrs
Payload IQPayload `xml:",omitempty"` Payload IQPayload `xml:",omitempty"`
RawXML string `xml:",innerxml"` RawXML string `xml:",innerxml"`
// TODO We need to support detecting the IQ namespace / Query packet // TODO We need to support detecting the IQ namespace / Query packet

@ -12,8 +12,8 @@ func TestUnmarshalIqs(t *testing.T) {
iqString string iqString string
parsedIQ ClientIQ 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 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"}, Packet: Packet{To: "test@localhost", From: "server", Type: "set", Id: "2"}, Payload: cs1}}, //{"<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 { for _, test := range tests {

@ -8,7 +8,7 @@ import (
// XMPP Packet Parsing // XMPP Packet Parsing
type ClientMessage struct { type ClientMessage struct {
XMLName xml.Name `xml:"jabber:client message"` XMLName xml.Name `xml:"jabber:client message"`
Packet PacketAttrs
Subject string `xml:"subject,omitempty"` Subject string `xml:"subject,omitempty"`
Body string `xml:"body,omitempty"` Body string `xml:"body,omitempty"`
Thread string `xml:"thread,omitempty"` Thread string `xml:"thread,omitempty"`

@ -1,7 +1,7 @@
package xmpp // import "fluux.io/xmpp" package xmpp // import "fluux.io/xmpp"
// Packet represents the root default structure for an XMPP packet. // PacketAttrs represents the common structure for base XMPP packets.
type Packet struct { type PacketAttrs struct {
Id string `xml:"id,attr,omitempty"` Id string `xml:"id,attr,omitempty"`
From string `xml:"from,attr,omitempty"` From string `xml:"from,attr,omitempty"`
To string `xml:"to,attr,omitempty"` To string `xml:"to,attr,omitempty"`

@ -7,9 +7,9 @@ import (
) )
type iq struct { type iq struct {
XMLName xml.Name `xml:"jabber:client iq"` XMLName xml.Name `xml:"jabber:client iq"`
C pubSub // c for "contains" C pubSub // c for "contains"
xmpp.Packet // Rename h for "header" ? xmpp.PacketAttrs // Rename h for "header" ?
} }
type pubSub struct { type pubSub struct {
@ -68,7 +68,7 @@ type Tune struct {
*/ */
func (t *Tune) XMPPFormat() (s string) { 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) return string(packet)
} }

@ -5,7 +5,7 @@ import "encoding/xml"
// XMPP Packet Parsing // XMPP Packet Parsing
type ClientPresence struct { type ClientPresence struct {
XMLName xml.Name `xml:"jabber:client presence"` XMLName xml.Name `xml:"jabber:client presence"`
Packet PacketAttrs
Show string `xml:"show,attr,omitempty"` // away, chat, dnd, xa Show string `xml:"show,attr,omitempty"` // away, chat, dnd, xa
Status string `xml:"status,attr,omitempty"` Status string `xml:"status,attr,omitempty"`
Priority string `xml:"priority,attr,omitempty"` Priority string `xml:"priority,attr,omitempty"`

@ -2,7 +2,7 @@ package xmpp // import "fluux.io/xmpp"
import "encoding/xml" import "encoding/xml"
// XMPP Packet Parsing // XMPP PacketAttrs Parsing
type streamFeatures struct { type streamFeatures struct {
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"` XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
StartTLS tlsStartTLS StartTLS tlsStartTLS

Loading…
Cancel
Save