xmpp

package module
v0.0.0-...-a965d2c Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Golang XMPP Server Library

Overview

This is a fork of github.com/agl/xmpp modified for use by an XMPP server.

Goal

A pluggable architecture for writing a golang xmpp server supporting the following specifications:

Usage

$ go build example/server.go
$ ./server -help
Usage of ./server:
  -debug
    	turn on debug logging
  -port int
    	port number to listen on (default 5222)

Creating a self signed certificate

$ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3650 -nodes

Documentation

Overview

Package xmpp implements the XMPP IM protocol, as specified in RFC 6120 and 6121.

Index

Constants

View Source
const (
	// NsStream stream namesapce
	NsStream = "http://etherx.jabber.org/streams"
	// NsTLS xmpp-tls xml namespace
	NsTLS = "urn:ietf:params:xml:ns:xmpp-tls"
	// NsSASL xmpp-sasl xml namespace
	NsSASL = "urn:ietf:params:xml:ns:xmpp-sasl"
	// NsBind xmpp-bind xml namespace
	NsBind = "urn:ietf:params:xml:ns:xmpp-bind"
	// NsSession xmpp-session xml namespace
	NsSession = "urn:ietf:params:xml:ns:xmpp-session"
	// NsClient jabbet client namespace
	NsClient = "jabber:client"
)

Variables

View Source
var MessageTypes = map[xml.Name]reflect.Type{
	xml.Name{Space: NsStream, Local: "error"}:    reflect.TypeOf(StreamError{}),
	xml.Name{Space: NsTLS, Local: "failure"}:     reflect.TypeOf(tlsFailure{}),
	xml.Name{Space: NsSASL, Local: "auth"}:       reflect.TypeOf(saslAuth{}),
	xml.Name{Space: NsSASL, Local: "mechanisms"}: reflect.TypeOf(saslMechanisms{}),
	xml.Name{Space: NsSASL, Local: "challenge"}:  reflect.TypeOf(""),
	xml.Name{Space: NsSASL, Local: "response"}:   reflect.TypeOf(""),
	xml.Name{Space: NsBind, Local: "bind"}:       reflect.TypeOf(bindBind{}),
	xml.Name{Space: NsClient, Local: "message"}:  reflect.TypeOf(ClientMessage{}),
	xml.Name{Space: NsClient, Local: "presence"}: reflect.TypeOf(ClientPresence{}),
	xml.Name{Space: NsClient, Local: "iq"}:       reflect.TypeOf(ClientIQ{}),
	xml.Name{Space: NsClient, Local: "error"}:    reflect.TypeOf(ClientError{}),
}

MessageTypes map of known message types

Functions

This section is empty.

Types

type AccountManager

type AccountManager interface {
	Authenticate(username, password string) (success bool, err error)
	CreateAccount(username, password string) (success bool, err error)
	OnlineRoster(jid string) (online []string, err error)
}

AccountManager performs roster management and authentication

type Auth

type Auth struct {
	Next State
}

Auth state

func (*Auth) Process

func (state *Auth) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process messages

type AuthedStart

type AuthedStart struct {
	Next State
}

AuthedStart state

func (*AuthedStart) Process

func (state *AuthedStart) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process messages

type AuthedStream

type AuthedStream struct {
	Next State
}

AuthedStream state

func (*AuthedStream) Process

func (state *AuthedStream) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process messages

type Client

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

Client xmpp connection

type ClientCaps

type ClientCaps struct {
	XMLName xml.Name `xml:"http://jabber.org/protocol/caps c"`
	Ext     string   `xml:"ext,attr"`
	Hash    string   `xml:"hash,attr"`
	Node    string   `xml:"node,attr"`
	Ver     string   `xml:"ver,attr"`
}

ClientCaps element

type ClientError

type ClientError struct {
	XMLName xml.Name `xml:"jabber:client error"`
	Code    string   `xml:"code,attr"`
	Type    string   `xml:"type,attr"`
	Any     xml.Name `xml:",any"`
	Text    string   `xml:"text"`
}

ClientError element

type ClientIQ

type ClientIQ struct {
	XMLName xml.Name    `xml:"jabber:client iq"`
	From    string      `xml:"from,attr"`
	ID      string      `xml:"id,attr"`
	To      string      `xml:"to,attr"`
	Type    string      `xml:"type,attr"` // error, get, result, set
	Error   ClientError `xml:"error"`
	Bind    bindBind    `xml:"bind"`
	Query   []byte      `xml:",innerxml"`
}

ClientIQ element

type ClientMessage

type ClientMessage struct {
	XMLName xml.Name `xml:"jabber:client message"`
	From    string   `xml:"from,attr"`
	ID      string   `xml:"id,attr"`
	To      string   `xml:"to,attr"`
	Type    string   `xml:"type,attr"` // chat, error, groupchat, headline, or normal

	// These should technically be []clientText,
	// but string is much more convenient.
	Subject string `xml:"subject"`
	Body    string `xml:"body"`
	Thread  string `xml:"thread"`
	Delay   *Delay `xml:"delay,omitempty"`
}

ClientMessage element

type ClientPresence

type ClientPresence struct {
	XMLName xml.Name `xml:"jabber:client presence"`
	From    string   `xml:"from,attr,omitempty"`
	ID      string   `xml:"id,attr,omitempty"`
	To      string   `xml:"to,attr,omitempty"`
	Type    string   `xml:"type,attr,omitempty"` // error, probe, subscribe, subscribed, unavailable, unsubscribe, unsubscribed
	Lang    string   `xml:"lang,attr,omitempty"`

	Show     string       `xml:"show,omitempty"`   // away, chat, dnd, xa
	Status   string       `xml:"status,omitempty"` // sb []clientText
	Priority string       `xml:"priority,omitempty"`
	Caps     *ClientCaps  `xml:"c"`
	Error    *ClientError `xml:"error"`
	Delay    Delay        `xml:"delay"`
}

ClientPresence element

type ClientText

type ClientText struct {
	Lang string `xml:"lang,attr"`
	Body string `xml:",chardata"`
}

ClientText element

type Connect

type Connect struct {
	Jid      string
	Receiver chan<- interface{}
}

Connect holds a channel where the server can send messages to the specific Jid

type Connection

type Connection struct {
	Raw          net.Conn
	MessageTypes map[xml.Name]reflect.Type
	// contains filtered or unexported fields
}

Connection represents a connection to an XMPP server.

func NewConn

func NewConn(raw net.Conn, MessageTypes map[xml.Name]reflect.Type) *Connection

NewConn creates a Connection struct for a given net.Conn and message system

func (*Connection) Next

func (c *Connection) Next() (xml.StartElement, error)

Next scans the stream to find the next xml.StartElement

func (*Connection) Read

func (c *Connection) Read(se xml.StartElement) (xml.Name, interface{}, error)

Read the Element from the stream and reflect interface to known message types

func (*Connection) SendRaw

func (c *Connection) SendRaw(s string) error

SendRaw sends the string across the connection

func (*Connection) SendRawf

func (c *Connection) SendRawf(format string, a ...interface{}) error

SendRawf formats and sends a string across the connection

func (*Connection) SendStanza

func (c *Connection) SendStanza(s interface{}) error

SendStanza XML encodes the interface and sends it across the connection

type Cookie uint64

Cookie is used to give a unique identifier to each request.

type DebugExtension

type DebugExtension struct {
	Log Logging
}

DebugExtension just dumps data

func (*DebugExtension) Process

func (e *DebugExtension) Process(message interface{}, from *Client)

Process a message (write to debug logger)

type Delay

type Delay struct {
	XMLName xml.Name `xml:"urn:xmpp:delay delay"`
	From    string   `xml:"from,attr,omitempty"`
	Stamp   string   `xml:"stamp,attr"`

	Body string `xml:",chardata"`
}

Delay element

type Disconnect

type Disconnect struct {
	Jid string
}

Disconnect notifies when a jid disconnects

type Extension

type Extension interface {
	Process(message interface{}, from *Client)
}

Extension interface for processing normal messages

type Logging

type Logging interface {
	Debug(string) error
	Info(string) error
	Error(string) error
}

Logging interface for library messages

type Message

type Message struct {
	To   string
	Data interface{}
}

Message is a generic XMPP message to send to the To Jid

type Normal

type Normal struct{}

Normal state

func (*Normal) Process

func (state *Normal) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process messages

type NormalMessageExtension

type NormalMessageExtension struct {
	MessageBus chan<- Message
}

NormalMessageExtension handles client messages

func (*NormalMessageExtension) Process

func (e *NormalMessageExtension) Process(message interface{}, from *Client)

Process sends `ClientMessage`s from a client down the `MessageBus`

type Roster

type Roster struct {
	XMLName xml.Name      `xml:"jabber:iq:roster query"`
	Item    []RosterEntry `xml:"item"`
}

Roster element

type RosterEntry

type RosterEntry struct {
	Jid          string   `xml:"jid,attr"`
	Subscription string   `xml:"subscription,attr"`
	Name         string   `xml:"name,attr"`
	Group        []string `xml:"group"`
}

RosterEntry element

type RosterExtension

type RosterExtension struct {
	Accounts AccountManager
}

RosterExtension handles ClientIQ presence requests and updates

func (*RosterExtension) Process

func (e *RosterExtension) Process(message interface{}, from *Client)

Process responds to Presence requests from a client

type RosterRequest

type RosterRequest struct {
	XMLName xml.Name          `xml:"jabber:iq:roster query"`
	Item    RosterRequestItem `xml:"item"`
}

RosterRequest is used to request that the server update the user's roster. See RFC 6121, section 2.3.

type RosterRequestItem

type RosterRequestItem struct {
	Jid          string   `xml:"jid,attr"`
	Subscription string   `xml:"subscription,attr"`
	Name         string   `xml:"name,attr"`
	Group        []string `xml:"group"`
}

RosterRequestItem element

type Server

type Server struct {
	// what domain to use?
	Domain string

	// SkipTLS, if true, causes the TLS handshake to be skipped.
	// WARNING: this should only be used if Conn is already secure.
	SkipTLS bool
	// TLSConfig contains the configuration to be used by the TLS
	// handshake. If nil, sensible defaults will be used.
	TLSConfig *tls.Config

	// AccountManager handles messages that the server must respond to
	// such as authentication and roster management
	Accounts AccountManager

	// Extensions are injectable handlers that process messages
	Extensions []Extension

	// How the client notifies the server who the connection is
	// and how to send messages to the connection JID
	ConnectBus chan<- Connect

	// notify server that the client has disconnected
	DisconnectBus chan<- Disconnect

	// Injectable logging interface
	Log Logging
}

Server contains options for an XMPP connection.

func (*Server) TCPAnswer

func (s *Server) TCPAnswer(conn net.Conn)

TCPAnswer sends connection through the TSLStateMachine

type Start

type Start struct {
	SkipTLS bool
	Next    State
}

Start state

func (*Start) Process

func (state *Start) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process message

type State

type State interface {
	Process(c *Connection, client *Client, s *Server) (State, *Connection, error)
}

State processes the stream and moves to the next state

func NewTLSStateMachine

func NewTLSStateMachine(skipTLS bool) State

NewTLSStateMachine return steps through TCP TLS state

type StreamError

type StreamError struct {
	XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"`
	Any     xml.Name `xml:",any"`
	Text    string   `xml:"text"`
}

StreamError element

type TLSStartStream

type TLSStartStream struct {
	Next State
}

TLSStartStream state

func (*TLSStartStream) Process

func (state *TLSStartStream) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process messages

type TLSUpgrade

type TLSUpgrade struct {
	Next State
}

TLSUpgrade state

func (*TLSUpgrade) Process

func (state *TLSUpgrade) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process message

type TLSUpgradeRequest

type TLSUpgradeRequest struct {
	Next State
}

TLSUpgradeRequest state

func (*TLSUpgradeRequest) Process

func (state *TLSUpgradeRequest) Process(c *Connection, client *Client, s *Server) (State, *Connection, error)

Process message

Jump to

Keyboard shortcuts

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