plugin

package
v0.0.0-...-77fa510 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package plugin defines the XMPP plugin interface and registry.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicatePlugin = errors.New("plugin: duplicate plugin name")
	ErrMissingDep      = errors.New("plugin: missing dependency")
	ErrCyclicDep       = errors.New("plugin: cyclic dependency")
)

Functions

This section is empty.

Types

type IncomingHandler

type IncomingHandler func(ctx context.Context, st stanza.Stanza) error

IncomingHandler processes an inbound stanza routed to a plugin.

type InitParams

type InitParams struct {
	// SendRaw sends raw bytes on the session.
	SendRaw func(ctx context.Context, data []byte) error
	// SendElement encodes and sends an XML element.
	SendElement func(ctx context.Context, v any) error
	// State returns the current session state as a uint32.
	State func() uint32
	// LocalJID returns the local JID string.
	LocalJID func() string
	// RemoteJID returns the remote JID string.
	RemoteJID func() string
	// Get retrieves another plugin by name.
	Get func(name string) (Plugin, bool)
	// Storage provides access to the pluggable storage layer. May be nil.
	Storage storage.Storage
	// Handle registers an inbound stanza handler. For IQ stanzas the name is
	// matched against the payload (child) element; for message/presence it is
	// matched against the stanza element. An empty name or stanzaType is a
	// wildcard. May be nil when the host does not support inbound dispatch.
	Handle func(name xml.Name, stanzaType string, h IncomingHandler)
	// Request sends an IQ and waits for the correlated reply. May be nil when
	// the host does not support request/response (e.g. a server session).
	Request func(ctx context.Context, iq *stanza.IQ) (*stanza.IQ, error)
}

InitParams provides parameters for plugin initialization. This avoids a circular import with the root xmpp package.

type Manager

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

Manager manages the lifecycle of plugins.

func NewManager

func NewManager() *Manager

NewManager creates a new plugin Manager.

func (*Manager) Close

func (m *Manager) Close() error

Close closes all plugins in reverse initialization order.

func (*Manager) Get

func (m *Manager) Get(name string) (Plugin, bool)

Get returns a plugin by name.

func (*Manager) Initialize

func (m *Manager) Initialize(ctx context.Context, params InitParams) error

Initialize initializes all registered plugins in dependency order.

func (*Manager) Plugins

func (m *Manager) Plugins() []Plugin

Plugins returns all registered plugins.

func (*Manager) Register

func (m *Manager) Register(p Plugin) error

Register adds a plugin to the manager.

type Plugin

type Plugin interface {
	// Name returns the unique plugin name.
	Name() string

	// Version returns the plugin version.
	Version() string

	// Initialize is called when the plugin is activated on a session.
	Initialize(ctx context.Context, params InitParams) error

	// Close releases resources held by the plugin.
	Close() error

	// Dependencies returns the names of plugins this plugin depends on.
	Dependencies() []string
}

Plugin is the interface that all XMPP plugins must implement.

Jump to

Keyboard shortcuts

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