Documentation
¶
Overview ¶
Package xmpp implements the XMPP IM protocol, as specified in RFC 6120 and 6121.
Index ¶
- Constants
- Variables
- type AccountManager
- type Auth
- type AuthedStart
- type AuthedStream
- type Client
- type ClientCaps
- type ClientError
- type ClientIQ
- type ClientMessage
- type ClientPresence
- type ClientText
- type Connect
- type Connection
- type Cookie
- type DebugExtension
- type Delay
- type Disconnect
- type Extension
- type Logging
- type Message
- type Normal
- type NormalMessageExtension
- type Roster
- type RosterEntry
- type RosterExtension
- type RosterRequest
- type RosterRequestItem
- type Server
- type Start
- type State
- type StreamError
- type TLSStartStream
- type TLSUpgrade
- type TLSUpgradeRequest
Constants ¶
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 ¶
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 ¶
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 (*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 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 Extension ¶
type Extension interface {
Process(message interface{}, from *Client)
}
Extension interface for processing normal 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.
type Start ¶
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 ¶
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