mux

package
Version: v0.21.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2022 License: BSD-2-Clause Imports: 10 Imported by: 1

Documentation

Overview

Package mux contains a simple XMPP multiplexer.

Aside from implementing its own muxer, this package contains handler interfaces designed to be standard across multiplexers. This lets you write, for example, a muxer that matches elements based on xpath expressions and take advantage of existing handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IQHandler added in v0.15.0

type IQHandler interface {
	HandleIQ(stanza.IQ, xmlstream.TokenReadEncoder, *xml.StartElement) error
}

IQHandler responds to IQ stanzas.

type IQHandlerFunc added in v0.15.0

type IQHandlerFunc func(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.

func (IQHandlerFunc) HandleIQ added in v0.15.0

HandleIQ calls f(iq, t, start).

type MessageHandler added in v0.15.0

type MessageHandler interface {
	HandleMessage(stanza.Message, xmlstream.TokenReadEncoder) error
}

MessageHandler responds to message stanzas.

type MessageHandlerFunc added in v0.15.0

type MessageHandlerFunc func(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.

func (MessageHandlerFunc) HandleMessage added in v0.15.0

HandleMessage calls f(msg, t).

type Option

type Option func(m *ServeMux)

Option configures a ServeMux.

func Feature added in v0.21.2

func Feature(iter info.FeatureIter) Option

Feature registers the provided features for service discovery.

Most features will be implemented by Handlers and do not need to be registered again, Feature is just for features that should be advertised but do not have any corresponding handler.

func Handle

func Handle(n xml.Name, h xmpp.Handler) Option

Handle returns an option that matches on the provided XML name. If a handler already exists for n when the option is applied, the option panics.

func HandleFunc added in v0.9.0

func HandleFunc(n xml.Name, h xmpp.HandlerFunc) Option

HandleFunc returns an option that matches on the provided XML name.

func IQ

func IQ(typ stanza.IQType, payload xml.Name, h IQHandler) Option

IQ returns an option that matches IQ stanzas based on their type and the name of the payload.

func IQFunc added in v0.10.0

func IQFunc(typ stanza.IQType, payload xml.Name, h IQHandlerFunc) Option

IQFunc returns an option that matches IQ stanzas. For more information see IQ.

func Ident added in v0.21.2

func Ident(iter info.IdentityIter) Option

Ident registers the provided identities for service discovery.

Most identities will be implemented by Handlers and do not need to be registered again, Ident is just for features that should be advertised but do not have any corresponding handler.

func Message

func Message(typ stanza.MessageType, payload xml.Name, h MessageHandler) Option

Message returns an option that matches message stanzas by type.

func MessageFunc added in v0.10.0

func MessageFunc(typ stanza.MessageType, payload xml.Name, h MessageHandlerFunc) Option

MessageFunc returns an option that matches message stanzas. For more information see Message.

func Presence

func Presence(typ stanza.PresenceType, payload xml.Name, h PresenceHandler) Option

Presence returns an option that matches presence stanzas by type.

func PresenceFunc added in v0.10.0

func PresenceFunc(typ stanza.PresenceType, payload xml.Name, h PresenceHandlerFunc) Option

PresenceFunc returns an option that matches on presence stanzas. For more information see Presence.

type PresenceHandler added in v0.15.0

type PresenceHandler interface {
	HandlePresence(stanza.Presence, xmlstream.TokenReadEncoder) error
}

PresenceHandler responds to message stanzas.

type PresenceHandlerFunc added in v0.15.0

type PresenceHandlerFunc func(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.

func (PresenceHandlerFunc) HandlePresence added in v0.15.0

HandlePresence calls f(p, t).

type ServeMux

type ServeMux struct {
	// contains filtered or unexported fields
}

ServeMux is an XMPP stream multiplexer. It matches the start element token of each top level stream element against a list of registered patterns and calls the handler for the pattern that most closely matches the token.

Patterns are XML names. If either the namespace or the localname is left off, any namespace or localname will be matched. Full XML names take precedence, followed by wildcard localnames, followed by wildcard namespaces.

func New

func New(stanzaNS string, opt ...Option) *ServeMux

New allocates and returns a new ServeMux.

func (*ServeMux) ForFeatures added in v0.20.0

func (m *ServeMux) ForFeatures(node string, f func(info.Feature) error) error

ForFeatures implements info.FeatureIter for the mux by iterating over all child features.

func (*ServeMux) ForForms added in v0.20.0

func (m *ServeMux) ForForms(node string, f func(*form.Data) error) error

ForForms implements form.Iter for the mux by iterating over all child handlers.

func (*ServeMux) ForIdentities added in v0.20.0

func (m *ServeMux) ForIdentities(node string, f func(info.Identity) error) error

ForIdentities implements info.IdentityIter for the mux by iterating over all child handlers.

func (*ServeMux) ForItems added in v0.20.0

func (m *ServeMux) ForItems(node string, f func(items.Item) error) error

ForItems implements items.Iter for the mux by iterating over all child items.

func (*ServeMux) HandleXMPP

func (m *ServeMux) HandleXMPP(t xmlstream.TokenReadEncoder, start *xml.StartElement) error

HandleXMPP dispatches the request to the handler that most closely matches.

func (*ServeMux) Handler

func (m *ServeMux) Handler(name xml.Name) (h xmpp.Handler, ok bool)

Handler returns the handler to use for a top level element with the provided XML name. If no exact match or wildcard handler exists, a default handler is returned (h is always non-nil) and ok will be false.

func (*ServeMux) IQHandler added in v0.15.0

func (m *ServeMux) IQHandler(typ stanza.IQType, payload xml.Name) (h IQHandler, ok bool)

IQHandler returns the handler to use for an IQ payload with the given type and payload name. If no handler exists, a default handler is returned (h is always non-nil).

func (*ServeMux) MessageHandler added in v0.15.0

func (m *ServeMux) MessageHandler(typ stanza.MessageType, payload xml.Name) (h MessageHandler, ok bool)

MessageHandler returns the handler to use for a message with the given type and payload. If no handler exists, a default handler is returned (h is always non-nil).

func (*ServeMux) PresenceHandler added in v0.15.0

func (m *ServeMux) PresenceHandler(typ stanza.PresenceType, payload xml.Name) (h PresenceHandler, ok bool)

PresenceHandler returns the handler to use for a presence payload with the given type. If no handler exists, a default handler is returned (h is always non-nil).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL