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.
2019-06-01 04:38:35 +02:00
|
|
|
package component
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bdlm/log"
|
|
|
|
"gosrc.io/xmpp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Config) sender(packets chan xmpp.Packet) {
|
|
|
|
for packet := range packets {
|
2019-06-02 10:41:19 +02:00
|
|
|
if p := c.sending(packet); p != nil {
|
2019-06-01 04:38:35 +02:00
|
|
|
c.xmpp.Send(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 10:41:19 +02:00
|
|
|
func (c *Config) sending(packet xmpp.Packet) xmpp.Packet {
|
2019-06-01 04:38:35 +02:00
|
|
|
logger := log.WithField("type", c.Type)
|
|
|
|
switch p := packet.(type) {
|
|
|
|
case xmpp.Message:
|
|
|
|
if p.PacketAttrs.From == "" {
|
|
|
|
p.PacketAttrs.From = c.Host
|
|
|
|
} else {
|
|
|
|
p.PacketAttrs.From += "@" + c.Host
|
|
|
|
}
|
2019-06-06 20:53:06 +02:00
|
|
|
if c.XMPPLog {
|
|
|
|
logger.WithFields(map[string]interface{}{
|
|
|
|
"from": p.PacketAttrs.From,
|
|
|
|
"to": p.PacketAttrs.To,
|
|
|
|
"id": p.PacketAttrs.Id,
|
|
|
|
}).Debug(p.XMPPFormat())
|
|
|
|
}
|
2019-06-01 04:38:35 +02:00
|
|
|
return p
|
|
|
|
default:
|
|
|
|
log.Warn("ignoring packet:", packet)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|