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 IQPrivateMetacontact struct {
|
|
|
|
iqPrivateExtension
|
2017-12-17 13:31:02 +01:00
|
|
|
}
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
func (ex *IQPrivateMetacontact) Handle(msg *messages.IQ, q *iqPrivateQuery, client *utils.Client) bool {
|
2017-12-17 13:31:02 +01:00
|
|
|
log := client.Log.WithField("extension", "private-metacontact").WithField("id", msg.ID)
|
|
|
|
|
|
|
|
// storage encode
|
|
|
|
type storage struct {
|
|
|
|
XMLName xml.Name `xml:"storage:metacontacts storage"`
|
|
|
|
}
|
|
|
|
s := &storage{}
|
2017-12-17 17:50:51 +01:00
|
|
|
if err := xml.Unmarshal(q.Body, s); err != nil {
|
2017-12-17 13:31:02 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
TODO full implement XEP-0209
|
|
|
|
https://xmpp.org/extensions/xep-0209.html
|
|
|
|
*/
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
queryByte, err := xml.Marshal(&iqPrivateQuery{
|
2017-12-17 13:31:02 +01:00
|
|
|
Body: q.Body,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
Body: queryByte,
|
2017-12-17 15:39:36 +01:00
|
|
|
}
|
2017-12-17 13:31:02 +01:00
|
|
|
|
|
|
|
log.Debug("send")
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|