Re-organize to handle disco

This commit is contained in:
Chteufleur 2016-09-02 21:56:13 +02:00
parent f9d8cea66f
commit d64fd5cb16
2 changed files with 45 additions and 19 deletions

View File

@ -18,10 +18,20 @@ const (
var (
ChanAuthCode = make(chan string)
identity = &xmpp.DiscoIdentity{Category: "gateway", Type: "steam", Name: "Steam Gateway"}
)
func execDiscoCommand(iq *xmpp.Iq) {
log.Printf("%sDiscovery item iq received", LogInfo)
discoInfo := &xmpp.DiscoItems{}
iq.PayloadDecode(discoInfo)
if discoInfo.Node == "" {
// Disco feature
execDisco(iq)
return
} else if discoInfo.Node == xmpp.NodeAdHocCommand {
// Disco Ad-Hoc
reply := iq.Response(xmpp.IQTypeResult)
discoItem := &xmpp.DiscoItems{Node: xmpp.NodeAdHocCommand}
@ -47,6 +57,20 @@ func execDiscoCommand(iq *xmpp.Iq) {
reply.PayloadEncode(discoItem)
comp.Out <- reply
}
}
func execDisco(iq *xmpp.Iq) {
log.Printf("%sDisco Feature", LogInfo)
reply := iq.Response(xmpp.IQTypeResult)
discoInfo := &xmpp.DiscoInfo{}
discoInfo.Identity = append(discoInfo.Identity, *identity)
discoInfo.Feature = append(discoInfo.Feature, xmpp.DiscoFeature{Var: xmpp.NSJabberClient})
discoInfo.Feature = append(discoInfo.Feature, xmpp.DiscoFeature{Var: xmpp.NodeAdHocCommand})
reply.PayloadEncode(discoInfo)
comp.Out <- reply
}
func execCommandAdHoc(iq *xmpp.Iq) {
adHoc := &xmpp.AdHocCommand{}

View File

@ -89,6 +89,8 @@ func mainXMPP() {
} else {
sendNotSupportedFeature(v)
}
case xmpp.NSDiscoInfo:
execDisco(v)
case xmpp.NodeAdHocCommand:
if jidBare == jid.Domain {