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_private_roster.go

55 lines
1.0 KiB
Go

package extension
import (
"encoding/xml"
"dev.sum7.eu/genofire/yaja/messages"
"dev.sum7.eu/genofire/yaja/server/utils"
)
type IQPrivateRoster struct {
iqPrivateExtension
}
func (ex *IQPrivateRoster) Handle(msg *messages.IQClient, q *iqPrivateQuery, client *utils.Client) bool {
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{}
if err := xml.Unmarshal(q.Body, r); err != nil {
return false
}
rosterByte, err := xml.Marshal(&roster{
Body: []byte("::"),
})
if err != nil {
log.Warn(err)
return true
}
queryByte, err := xml.Marshal(&iqPrivateQuery{
Body: rosterByte,
})
if err != nil {
log.Warn(err)
return true
}
// reply
client.Messages <- &messages.IQClient{
Type: messages.IQTypeResult,
To: client.JID.String(),
From: client.JID.Domain,
ID: msg.ID,
Body: queryByte,
}
log.Debug("send")
return true
}