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

59 lines
1.2 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"
)
type IQExtensions []IQExtension
type IQExtension interface {
Extension
Get(*messages.IQClient, *utils.Client) bool
Set(*messages.IQClient, *utils.Client) bool
}
func (iex IQExtensions) Spaces() (result []string) {
for _, extension := range iex {
spaces := extension.Spaces()
result = append(result, spaces...)
}
return result
}
func (iex IQExtensions) Process(element *xml.StartElement, client *utils.Client) bool {
log := client.Log.WithField("extension", "iq")
// iq encode
var msg messages.IQClient
if err := client.In.DecodeElement(&msg, element); err != nil {
return false
}
log = log.WithField("id", msg.ID)
// run every extensions
count := 0
for _, extension := range iex {
switch msg.Type {
case messages.IQTypeGet:
if extension.Get(&msg, client) {
count++
}
case messages.IQTypeSet:
if extension.Set(&msg, client) {
count++
}
}
}
// not extensions found
if count != 1 {
2018-02-11 19:35:32 +01:00
log.Debugf("%s - %s: %s", msg.XMLName.Space, msg.Type, messages.XMLChildrenString(msg.Other))
}
return true
}