sum7
/
yaja
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
yaja/server/extension/iq_ping.go

41 lines
731 B
Go
Raw Normal View History

package extension
import (
"encoding/xml"
"github.com/genofire/yaja/messages"
"github.com/genofire/yaja/server/utils"
)
type Ping struct {
IQExtension
}
func (p *Ping) Spaces() []string { return []string{"urn:xmpp:ping"} }
func (p *Ping) Get(msg *messages.IQ, client *utils.Client) bool {
log := client.Log.WithField("extension", "ping").WithField("id", msg.ID)
// ping encode
type ping struct {
XMLName xml.Name `xml:"urn:xmpp:ping ping"`
}
pq := &ping{}
err := xml.Unmarshal(msg.Body, pq)
if err != nil {
return false
}
// reply
client.Out.Encode(&messages.IQ{
Type: messages.IQTypeResult,
To: client.JID.String(),
From: client.JID.Domain,
ID: msg.ID,
})
log.Debug("send")
return true
}