c2s

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2018 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExistingAccount will be returned by Route method
	// if destination user does not exist.
	ErrNotExistingAccount = errors.New("c2s: account does not exist")

	// ErrResourceNotFound will be returned by Route method
	// if destination resource does not match any of user's available resources.
	ErrResourceNotFound = errors.New("c2s: resource not found")

	// ErrNotAuthenticated will be returned by Route method if
	// destination user is not available at this moment.
	ErrNotAuthenticated = errors.New("c2s: user not authenticated")

	// ErrBlockedJID will be returned by Route method if
	// destination JID matches any of the user's blocked JID.
	ErrBlockedJID = errors.New("c2s: destination jid is blocked")
)

Functions

func Initialize

func Initialize(cfg *Config)

Initialize initializes the c2s session manager.

func Shutdown

func Shutdown()

Shutdown shuts down c2s manager system. This method should be used only for testing purposes.

Types

type Config added in v0.2.0

type Config struct {
	Domains []string
}

Config represents a client-to-server manager configuration.

func (*Config) UnmarshalYAML added in v0.2.0

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML satisfies Unmarshaler interface.

type Manager

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

Manager manages the sessions associated with an account.

func Instance

func Instance() *Manager

Instance returns the c2s session manager instance.

func (*Manager) AuthenticateStream

func (m *Manager) AuthenticateStream(stm Stream) error

AuthenticateStream sets a previously registered stream as authenticated. An error will be returned in case no assigned resource is found.

func (*Manager) DefaultLocalDomain

func (m *Manager) DefaultLocalDomain() string

DefaultLocalDomain returns default local domain.

func (*Manager) IsBlockedJID added in v0.2.0

func (m *Manager) IsBlockedJID(jid *xml.JID, username string) bool

IsBlockedJID returns whether or not the passed jid matches any of a user's blocking list JID.

func (*Manager) IsLocalDomain

func (m *Manager) IsLocalDomain(domain string) bool

IsLocalDomain returns true if domain is a local server domain.

func (*Manager) MustRoute added in v0.2.0

func (m *Manager) MustRoute(elem xml.Stanza) error

MustRoute routes a stanza applying server rules for handling XML stanzas and ignoring blocking lists.

func (*Manager) RegisterStream

func (m *Manager) RegisterStream(stm Stream) error

RegisterStream registers the specified client stream. An error will be returned in case the stream has been previously registered.

func (*Manager) ReloadBlockList added in v0.2.0

func (m *Manager) ReloadBlockList(username string)

ReloadBlockList reloads in-memstorage block list for a given user and starts applying it for future stanza routing.

func (*Manager) Route added in v0.2.0

func (m *Manager) Route(elem xml.Stanza) error

Route routes a stanza applying server rules for handling XML stanzas. (https://xmpp.org/rfcs/rfc3921.html#rules)

func (*Manager) StreamsMatchingJID added in v0.2.0

func (m *Manager) StreamsMatchingJID(jid *xml.JID) []Stream

StreamsMatchingJID returns all available streams that match a given JID.

func (*Manager) UnregisterStream

func (m *Manager) UnregisterStream(stm Stream) error

UnregisterStream unregisters the specified client stream removing associated resource from the manager. An error will be returned in case the stream has not been previously registered.

type MockStream

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

MockStream represents a mocked c2s stream.

func NewMockStream

func NewMockStream(id string, jid *xml.JID) *MockStream

NewMockStream returns a new mocked stream instance.

func (*MockStream) Context added in v0.2.0

func (m *MockStream) Context() *stream.Context

Context returns mocked stream associated context.

func (*MockStream) Disconnect

func (m *MockStream) Disconnect(err error)

Disconnect disconnects mocked stream.

func (*MockStream) Domain

func (m *MockStream) Domain() string

Domain returns current mocked stream domain.

func (*MockStream) FetchElement

func (m *MockStream) FetchElement() xml.XElement

FetchElement waits until a new XML element is sent to the mocked stream and returns it.

func (*MockStream) ID

func (m *MockStream) ID() string

ID returns mocked stream identifier.

func (*MockStream) IsAuthenticated

func (m *MockStream) IsAuthenticated() bool

IsAuthenticated returns whether or not the mocked stream has successfully authenticated.

func (*MockStream) IsCompressed

func (m *MockStream) IsCompressed() bool

IsCompressed returns whether or not the mocked stream has enabled a compression method.

func (*MockStream) IsDisconnected

func (m *MockStream) IsDisconnected() bool

IsDisconnected returns whether or not the mocked stream has been disconnected.

func (*MockStream) IsSecured

func (m *MockStream) IsSecured() bool

IsSecured returns whether or not the mocked stream has been secured.

func (*MockStream) JID

func (m *MockStream) JID() *xml.JID

JID returns current user JID.

func (*MockStream) Presence added in v0.2.0

func (m *MockStream) Presence() *xml.Presence

Presence returns last sent presence element.

func (*MockStream) Resource

func (m *MockStream) Resource() string

Resource returns current mocked stream resource.

func (*MockStream) SendElement

func (m *MockStream) SendElement(element xml.XElement)

SendElement sends the given XML element.

func (*MockStream) SetAuthenticated

func (m *MockStream) SetAuthenticated(authenticated bool)

SetAuthenticated sets whether or not the a mocked stream has been authenticated.

func (*MockStream) SetCompressed

func (m *MockStream) SetCompressed(compressed bool)

SetCompressed sets whether or not the a mocked stream has been compressed.

func (*MockStream) SetDomain

func (m *MockStream) SetDomain(domain string)

SetDomain sets the mocked stream domain value.

func (*MockStream) SetJID

func (m *MockStream) SetJID(jid *xml.JID)

SetJID sets the mocked stream JID value.

func (*MockStream) SetPresence added in v0.2.0

func (m *MockStream) SetPresence(presence *xml.Presence)

SetPresence sets the mocked stream last received presence element.

func (*MockStream) SetResource

func (m *MockStream) SetResource(resource string)

SetResource sets the mocked stream resource value.

func (*MockStream) SetSecured

func (m *MockStream) SetSecured(secured bool)

SetSecured sets whether or not the a mocked stream has been secured.

func (*MockStream) SetUsername

func (m *MockStream) SetUsername(username string)

SetUsername sets the mocked stream username value.

func (*MockStream) Username

func (m *MockStream) Username() string

Username returns current mocked stream username.

func (*MockStream) WaitDisconnection

func (m *MockStream) WaitDisconnection() error

WaitDisconnection waits until the mocked stream disconnects.

type Stream

type Stream interface {
	ID() string

	Context() *stream.Context

	Username() string
	Domain() string
	Resource() string

	JID() *xml.JID

	IsSecured() bool
	IsAuthenticated() bool
	IsCompressed() bool

	Presence() *xml.Presence

	SendElement(element xml.XElement)
	Disconnect(err error)
}

Stream represents a client-to-server XMPP stream.

Jump to

Keyboard shortcuts

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