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

53 lines
1.1 KiB
Go
Raw Normal View History

package extension
import (
"encoding/xml"
2018-02-07 15:34:18 +01:00
"dev.sum7.eu/genofire/yaja/messages"
"dev.sum7.eu/genofire/yaja/server/utils"
)
2017-12-17 15:39:36 +01:00
type IQPrivate struct {
IQExtension
}
2017-12-17 15:39:36 +01:00
type iqPrivateQuery struct {
XMLName xml.Name `xml:"jabber:iq:private query"`
Body []byte `xml:",innerxml"`
}
2017-12-17 15:39:36 +01:00
type iqPrivateExtension interface {
Handle(*messages.IQClient, *iqPrivateQuery, *utils.Client) bool
}
2017-12-17 15:39:36 +01:00
func (ex *IQPrivate) Spaces() []string { return []string{"jabber:iq:private"} }
func (ex *IQPrivate) Get(msg *messages.IQClient, client *utils.Client) bool {
log := client.Log.WithField("extension", "private").WithField("id", msg.ID)
// query encode
2017-12-17 15:39:36 +01:00
q := &iqPrivateQuery{}
2017-12-17 17:50:51 +01:00
if err := xml.Unmarshal(msg.Body, q); err != nil {
return false
}
// run every extensions
count := 0
2017-12-17 15:39:36 +01:00
for _, e := range []iqPrivateExtension{
&IQPrivateMetacontact{},
&IQPrivateRoster{},
&IQPrivateBookmark{},
} {
if e.Handle(msg, q, client) {
count++
}
}
// not extensions found
if count != 1 {
log.Debug(msg.XMLName.Space, " - ", msg.Type, ": ", string(q.Body))
}
return true
}