This commit is contained in:
Mickael Remond 2018-01-23 09:08:21 +01:00
parent cb2af43fe3
commit 8cb1e1264e
No known key found for this signature in database
GPG key ID: E6F6045D79965AA3
4 changed files with 6 additions and 50 deletions

View file

@ -44,6 +44,10 @@ func main() {
reply := p.MakeError(xError)
component.xmpp.Send(&reply)
}
case xmpp.Message:
fmt.Println("Received message:", p.Body)
case xmpp.Presence:
fmt.Println("Received presence:", p.Type)
default:
fmt.Println("ignoring packet:", packet)
}

49
iq.go
View file

@ -3,63 +3,14 @@ package xmpp // import "fluux.io/xmpp"
import (
"encoding/xml"
"fmt"
"reflect"
"strconv"
"fluux.io/xmpp/iot"
)
/*
TODO I would like to be able to write
NewIQ(Id, From, To, Type, Lang).AddPayload(IQPayload)
Payload would be:
payload := Node{
Ns: "http://jabber.org/protocol/disco#info",
Tag: "identity",
Attrs: map[string]string{
"category":"gateway",
"type": "skype",
"name": "Test Gateway",
},
Nodes: []Node{},
}
AddPayload(Ns, Tag, Attrs)
ex:
NewIQ("get", "test@localhost", "admin@localhost", "en")
.AddPayload("http://jabber.org/protocol/disco#info",
"identity",
map[string]string{
"category":"gateway",
"type": "skype",
"name": "Test Gateway",
})
NewNode(Ns, Tag, Attrs)
NewNodeWithChildren(Ns, Tag, Attrs, Nodes)
Attr {
K string
V string
}
xmpp.Elt.DiscoInfo("identity", "gateway", "skype", "Test Gateway")
xmppElt.DiscoInfo.identity("
import xmpp/node/discoinfo
discoinfo.Identity("gateway", "skype", "Test Gateway")
[]Attr{{"category", "gateway"}
TODO support ability to put Raw payload
*/
// ============================================================================

View file

@ -70,7 +70,7 @@ func next(p *xml.Decoder) (Packet, error) {
return nil, err
}
// TODO: general case = Parse IQ / presence / message => split SASL Stream and component cases
// Decode one of the top level XMPP namespace
switch se.Name.Space {
case NSStream:
return decodeStream(p, se)

View file

@ -25,5 +25,6 @@ var presence presenceDecoder
func (presenceDecoder) decode(p *xml.Decoder, se xml.StartElement) (Presence, error) {
var packet Presence
err := p.DecodeElement(&packet, &se)
// TODO Add default presence type (when omitted)
return packet, err
}