2017-12-17 13:31:02 +01:00
|
|
|
package extension
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
"dev.sum7.eu/genofire/yaja/xmpp"
|
2018-02-10 13:34:42 +01:00
|
|
|
"dev.sum7.eu/genofire/yaja/model"
|
2018-02-07 15:34:18 +01:00
|
|
|
"dev.sum7.eu/genofire/yaja/server/utils"
|
2017-12-17 13:31:02 +01:00
|
|
|
)
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
type IQPrivateRoster struct {
|
2018-02-10 13:34:42 +01:00
|
|
|
IQExtension
|
2017-12-17 13:31:02 +01:00
|
|
|
}
|
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
func (ex *IQPrivateRoster) Handle(msg *xmpp.IQClient, client *utils.Client) bool {
|
2017-12-17 13:31:02 +01:00
|
|
|
log := client.Log.WithField("extension", "private").WithField("id", msg.ID)
|
|
|
|
|
|
|
|
// roster encode
|
|
|
|
type roster struct {
|
|
|
|
XMLName xml.Name `xml:"roster:delimiter roster"`
|
|
|
|
Body []byte `xml:",innerxml"`
|
|
|
|
}
|
|
|
|
r := &roster{}
|
2017-12-17 17:50:51 +01:00
|
|
|
if err := xml.Unmarshal(q.Body, r); err != nil {
|
2017-12-17 13:31:02 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
rosterByte, err := xml.Marshal(&roster{
|
|
|
|
Body: []byte("::"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err)
|
|
|
|
return true
|
|
|
|
}
|
2017-12-17 15:39:36 +01:00
|
|
|
queryByte, err := xml.Marshal(&iqPrivateQuery{
|
2017-12-17 13:31:02 +01:00
|
|
|
Body: rosterByte,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// reply
|
2018-02-14 18:49:26 +01:00
|
|
|
client.Messages <- &xmpp.IQClient{
|
|
|
|
Type: xmpp.IQTypeResult,
|
2018-02-10 13:34:42 +01:00
|
|
|
To: client.JID,
|
2018-02-14 18:49:26 +01:00
|
|
|
From: xmpp.NewJID(client.JID.Domain),
|
2017-12-17 13:31:02 +01:00
|
|
|
ID: msg.ID,
|
|
|
|
Body: queryByte,
|
2017-12-17 15:39:36 +01:00
|
|
|
}
|
2017-12-17 13:31:02 +01:00
|
|
|
|
|
|
|
log.Debug("send")
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|