1
0
Fork 0

Document more of the XMPP API.

This commit is contained in:
Matt Goodall 2012-07-16 17:32:42 +01:00
parent c1da50ce26
commit dde0afb688
1 changed files with 9 additions and 0 deletions

View File

@ -73,8 +73,11 @@ func (fn MatcherFunc) Match(v interface{}) bool {
return fn(v) return fn(v)
} }
// Uniquly identifies a stream fiter. Used to remove a filter that's no longer
// needed.
type FilterId int64 type FilterId int64
// Implements the error interface for a FilterId.
func (fid FilterId) Error() string { func (fid FilterId) Error() string {
return fmt.Sprintf("Invalid filter id: %d", fid) return fmt.Sprintf("Invalid filter id: %d", fid)
} }
@ -85,6 +88,9 @@ type filter struct {
ch chan interface{} ch chan interface{}
} }
// Add a filter that routes matching stanzas to the returned channel. A
// FilterId is also returned and can be pased to RemoveFilter to remove the
// filter again.
func (x *XMPP) AddFilter(m Matcher) (FilterId, chan interface{}) { func (x *XMPP) AddFilter(m Matcher) (FilterId, chan interface{}) {
// Protect against concurrent access. // Protect against concurrent access.
@ -105,6 +111,7 @@ func (x *XMPP) AddFilter(m Matcher) (FilterId, chan interface{}) {
return id, ch return id, ch
} }
// Remove a filter previously added with AddFilter.
func (x *XMPP) RemoveFilter(id FilterId) error { func (x *XMPP) RemoveFilter(id FilterId) error {
// Protect against concurrent access. // Protect against concurrent access.
@ -133,6 +140,8 @@ func (x *XMPP) RemoveFilter(id FilterId) error {
return id return id
} }
// Matcher to identify a <iq id="..." type="result" /> stanza with the given
// id.
func IqResult(id string) Matcher { func IqResult(id string) Matcher {
return MatcherFunc( return MatcherFunc(
func(v interface{}) bool { func(v interface{}) bool {