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.
2017-12-17 13:31:02 +01:00
|
|
|
package extension
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
|
|
|
|
"github.com/genofire/yaja/messages"
|
|
|
|
"github.com/genofire/yaja/server/utils"
|
|
|
|
)
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
type IQPing struct {
|
2017-12-17 13:31:02 +01:00
|
|
|
IQExtension
|
|
|
|
}
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
func (ex *IQPing) Spaces() []string { return []string{"urn:xmpp:ping"} }
|
2017-12-17 13:31:02 +01:00
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
func (ex *IQPing) Get(msg *messages.IQ, client *utils.Client) bool {
|
2017-12-17 13:31:02 +01:00
|
|
|
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{}
|
2017-12-17 17:50:51 +01:00
|
|
|
if err := xml.Unmarshal(msg.Body, pq); err != nil {
|
2017-12-17 13:31:02 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// reply
|
2017-12-17 15:39:36 +01:00
|
|
|
client.Messages <- &messages.IQ{
|
2017-12-17 13:31:02 +01:00
|
|
|
Type: messages.IQTypeResult,
|
|
|
|
To: client.JID.String(),
|
|
|
|
From: client.JID.Domain,
|
|
|
|
ID: msg.ID,
|
2017-12-17 15:39:36 +01:00
|
|
|
}
|
2017-12-17 13:31:02 +01:00
|
|
|
|
|
|
|
log.Debug("send")
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|