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
1021 B
Go
Raw Normal View History

package extension
import (
"encoding/xml"
"github.com/genofire/yaja/messages"
"github.com/genofire/yaja/server/utils"
)
type Private struct {
IQExtension
}
type privateQuery struct {
XMLName xml.Name `xml:"jabber:iq:private query"`
Body []byte `xml:",innerxml"`
}
type ioPrivateExtension interface {
Handle(*messages.IQ, *privateQuery, *utils.Client) bool
}
func (p *Private) Spaces() []string { return []string{"jabber:iq:private"} }
func (p *Private) Get(msg *messages.IQ, client *utils.Client) bool {
log := client.Log.WithField("extension", "private").WithField("id", msg.ID)
// query encode
q := &privateQuery{}
err := xml.Unmarshal(msg.Body, q)
if err != nil {
return false
}
// run every extensions
count := 0
for _, e := range []ioPrivateExtension{
&PrivateMetacontact{},
&PrivateRoster{},
} {
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
}