2017-12-17 13:31:02 +01:00
|
|
|
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 13:31:02 +01:00
|
|
|
)
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
type IQPrivate struct {
|
2017-12-17 13:31:02 +01:00
|
|
|
IQExtension
|
|
|
|
}
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
type iqPrivateQuery struct {
|
2017-12-17 13:31:02 +01:00
|
|
|
XMLName xml.Name `xml:"jabber:iq:private query"`
|
|
|
|
Body []byte `xml:",innerxml"`
|
|
|
|
}
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
type iqPrivateExtension interface {
|
2018-02-07 19:32:11 +01:00
|
|
|
Handle(*messages.IQClient, *iqPrivateQuery, *utils.Client) bool
|
2017-12-17 13:31:02 +01:00
|
|
|
}
|
|
|
|
|
2017-12-17 15:39:36 +01:00
|
|
|
func (ex *IQPrivate) Spaces() []string { return []string{"jabber:iq:private"} }
|
2017-12-17 13:31:02 +01:00
|
|
|
|
2018-02-07 19:32:11 +01:00
|
|
|
func (ex *IQPrivate) Get(msg *messages.IQClient, client *utils.Client) bool {
|
2017-12-17 13:31:02 +01:00
|
|
|
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 {
|
2017-12-17 13:31:02 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// run every extensions
|
|
|
|
count := 0
|
2017-12-17 15:39:36 +01:00
|
|
|
for _, e := range []iqPrivateExtension{
|
|
|
|
&IQPrivateMetacontact{},
|
|
|
|
&IQPrivateRoster{},
|
|
|
|
&IQPrivateBookmark{},
|
2017-12-17 13:31:02 +01:00
|
|
|
} {
|
|
|
|
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
|
|
|
|
}
|