Add Disco support
This commit is contained in:
parent
a06062e714
commit
a070b03c0f
38
xmpp/xmpp.go
38
xmpp/xmpp.go
|
|
@ -37,6 +37,8 @@ var (
|
||||||
|
|
||||||
Debug = true
|
Debug = true
|
||||||
VerifyCertValidity = true
|
VerifyCertValidity = true
|
||||||
|
|
||||||
|
identity = &xmpp.DiscoIdentity{Category: "client", Type: "bot", Name: "HTTP authentication over XMPP"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
|
|
@ -107,8 +109,11 @@ func mainXMPP() {
|
||||||
|
|
||||||
case *xmpp.Iq:
|
case *xmpp.Iq:
|
||||||
switch v.PayloadName().Space {
|
switch v.PayloadName().Space {
|
||||||
|
case xmpp.NSDiscoInfo:
|
||||||
|
execDisco(v)
|
||||||
|
|
||||||
case xmpp.NSDiscoItems:
|
case xmpp.NSDiscoItems:
|
||||||
execDiscoCommand(v)
|
execDisco(v)
|
||||||
|
|
||||||
case xmpp.NSVCardTemp:
|
case xmpp.NSVCardTemp:
|
||||||
reply := v.Response(xmpp.IQTypeResult)
|
reply := v.Response(xmpp.IQTypeResult)
|
||||||
|
|
@ -188,8 +193,37 @@ func must(v interface{}, err error) interface{} {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func execDisco(iq *xmpp.Iq) {
|
||||||
|
log.Printf("%sDisco Feature", LogInfo)
|
||||||
|
|
||||||
|
discoInfoReceived := &xmpp.DiscoItems{}
|
||||||
|
iq.PayloadDecode(discoInfoReceived)
|
||||||
|
|
||||||
|
switch iq.PayloadName().Space {
|
||||||
|
case xmpp.NSDiscoInfo:
|
||||||
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
|
|
||||||
|
discoInfo := &xmpp.DiscoInfo{}
|
||||||
|
discoInfo.Identity = append(discoInfo.Identity, *identity)
|
||||||
|
//discoInfo.Feature = append(discoInfo.Feature, xmpp.DiscoFeature{Var: xmpp.NSHTTPAuth})
|
||||||
|
|
||||||
|
reply.PayloadEncode(discoInfo)
|
||||||
|
comp.Out <- reply
|
||||||
|
|
||||||
|
case xmpp.NSDiscoItems:
|
||||||
|
if discoInfoReceived.Node == xmpp.NodeAdHocCommand {
|
||||||
|
execDiscoCommand(iq)
|
||||||
|
} else {
|
||||||
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
|
discoItems := &xmpp.DiscoItems{}
|
||||||
|
reply.PayloadEncode(discoItems)
|
||||||
|
comp.Out <- reply
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func execDiscoCommand(iq *xmpp.Iq) {
|
func execDiscoCommand(iq *xmpp.Iq) {
|
||||||
log.Printf("%sDiscovery item iq received", LogInfo)
|
log.Printf("%sAd-Hoc Command", LogInfo)
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
discoItem := &xmpp.DiscoItems{Node: xmpp.NodeAdHocCommand}
|
discoItem := &xmpp.DiscoItems{Node: xmpp.NodeAdHocCommand}
|
||||||
reply.PayloadEncode(discoItem)
|
reply.PayloadEncode(discoItem)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue