/
stanza.go
60 lines (48 loc) · 2.01 KB
/
stanza.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2020 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.
package mux
import (
"encoding/xml"
"mellium.im/xmlstream"
"mellium.im/xmpp/stanza"
)
// IQHandler responds to IQ stanzas.
type IQHandler interface {
HandleIQ(stanza.IQ, xmlstream.TokenReadEncoder, *xml.StartElement) error
}
// The IQHandlerFunc type is an adapter to allow the use of ordinary functions
// as IQ handlers.
// If f is a function with the appropriate signature, IQHandlerFunc(f) is an
// IQHandler that calls f.
type IQHandlerFunc func(stanza.IQ, xmlstream.TokenReadEncoder, *xml.StartElement) error
// HandleIQ calls f(iq, t, start).
func (f IQHandlerFunc) HandleIQ(iq stanza.IQ, t xmlstream.TokenReadEncoder, start *xml.StartElement) error {
return f(iq, t, start)
}
// MessageHandler responds to message stanzas.
type MessageHandler interface {
HandleMessage(stanza.Message, xmlstream.TokenReadEncoder) error
}
// The MessageHandlerFunc type is an adapter to allow the use of ordinary
// functions as message handlers.
// If f is a function with the appropriate signature, MessageHandlerFunc(f) is a
// MessageHandler that calls f.
type MessageHandlerFunc func(stanza.Message, xmlstream.TokenReadEncoder) error
// HandleMessage calls f(msg, t).
func (f MessageHandlerFunc) HandleMessage(msg stanza.Message, t xmlstream.TokenReadEncoder) error {
return f(msg, t)
}
// PresenceHandler responds to message stanzas.
type PresenceHandler interface {
HandlePresence(stanza.Presence, xmlstream.TokenReadEncoder) error
}
// The PresenceHandlerFunc type is an adapter to allow the use of ordinary
// functions as presence handlers.
// If f is a function with the appropriate signature, PresenceHandlerFunc(f) is
// a PresenceHandler that calls f.
type PresenceHandlerFunc func(stanza.Presence, xmlstream.TokenReadEncoder) error
// HandlePresence calls f(p, t).
func (f PresenceHandlerFunc) HandlePresence(p stanza.Presence, t xmlstream.TokenReadEncoder) error {
return f(p, t)
}