xmpp

package
v0.0.0-...-0fa8041 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2016 License: BSD-3-Clause Imports: 19 Imported by: 2

Documentation

Overview

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

Index

Constants

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

Variables

This section is empty.

Functions

func RemoveResourceFromJid

func RemoveResourceFromJid(jid string) (udom string)

RemoveResourceFromJid returns the user@domain portion of a JID.

func Resolve

func Resolve(domain string) (host string, port uint16, err error)

Resolve performs a DNS SRV lookup for the XMPP server that serves the given domain.

func SplitJid

func SplitJid(jid string) (udom string, resource string)

Types

type BooleanFormField

type BooleanFormField struct {
	FormField

	Result bool
}

BooleanFormField is for a yes/no answer. The Result member should be set to the user's answer.

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"`
}

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"`
}

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"`
}

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"`
}

RFC 3921 B.1 jabber:client

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"`
	UserItems []PresenceItem `xml:"x>item"`
	Error     *ClientError   `xml:"error"`
	Delay     Delay          `xml:"delay"`
}

type ClientText

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

type Config

type Config struct {
	// Conn is the connection to the server, if non-nill.
	Conn net.Conn
	// InLog is an optional Writer which receives the raw contents of the
	// XML from the server.
	InLog io.Writer
	// OutLog is an optional Writer which receives the raw XML sent to the
	// server.
	OutLog io.Writer
	// Log is an optional Writer which receives human readable log messages
	// during the connection.
	Log io.Writer
	// CreateCallback, if not nil, causes a new account to be created on
	// the server. The callback is needed in order to be able to handle
	// XMPP forms.
	CreateCallback FormCallback
	// TrustedAddress, if true, means that the address passed to Dial is
	// trusted and that certificates for that name should be accepted.
	TrustedAddress bool
	// Archive determines whether we disable archiving for messages. If
	// false, XML is sent with each message to disable recording on the
	// server.
	Archive bool
	// ServerCertificateSHA256 contains the SHA-256 hash of the server's
	// leaf certificate, or may be empty to use normal X.509 verification.
	// If this is specified then normal X.509 verification is disabled.
	ServerCertificateSHA256 []byte
	// 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
}

Config contains options for an XMPP connection.

type Conn

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

Conn represents a connection to an XMPP server.

func Dial

func Dial(address, user, domain, resource, password string, config *Config) (c *Conn, err error)

Dial creates a new connection to an XMPP server, authenticates as the given user.

func (*Conn) ArchiveOpts

func (c *Conn) ArchiveOpts() string

func (*Conn) Cancel

func (c *Conn) Cancel(cookie Cookie) bool

Cancel cancels and outstanding request. The request's channel is closed.

func (*Conn) IsMUC

func (c *Conn) IsMUC(jid string) bool

func (*Conn) JoinMUC

func (c *Conn) JoinMUC(to, nick, password string) error

XEP-0045 7.2 & 7.2.6

func (*Conn) LeaveMUC

func (c *Conn) LeaveMUC(to string) error

XEP-0045 7.14

func (*Conn) Next

func (c *Conn) Next() (stanza Stanza, err error)

Next reads stanzas from the server. If the stanza is a reply, it dispatches it to the correct channel and reads the next message. Otherwise it returns the stanza for processing.

func (*Conn) RequestRoster

func (c *Conn) RequestRoster() (<-chan Stanza, Cookie, error)

RequestRoster requests the user's roster from the server. It returns a channel on which the reply can be read when received and a Cookie that can be used to cancel the request.

func (*Conn) Send

func (c *Conn) Send(to, msg string) error

Send sends an IM message to the given user.

func (*Conn) SendIQ

func (c *Conn) SendIQ(to, typ string, value interface{}) (reply chan Stanza, cookie Cookie, err error)

SendIQ sends an info/query message to the given user. It returns a channel on which the reply can be read when received and a Cookie that can be used to cancel the request.

func (*Conn) SendIQReply

func (c *Conn) SendIQReply(to, typ, id string, value interface{}) error

SendIQReply sends a reply to an IQ query.

func (*Conn) SendPresence

func (c *Conn) SendPresence(to, typ, id string) error

SendPresence sends a presence stanza. If id is empty, a unique id is generated.

func (*Conn) SendStanza

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

func (*Conn) SetCustomStorage

func (c *Conn) SetCustomStorage(space, local string, s interface{})

func (*Conn) SetMUCSubject

func (c *Conn) SetMUCSubject(jid, subject string) error

func (*Conn) SignalPresence

func (c *Conn) SignalPresence(state string) error
type Cookie uint64

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

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"`
}

XEP-0203: Delayed Delivery of <message/> and <presence/> stanzas.

type DiscoveryFeature

type DiscoveryFeature struct {
	XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info feature"`
	Var     string   `xml:"var,attr"`
}

type DiscoveryIdentity

type DiscoveryIdentity struct {
	XMLName  xml.Name `xml:"http://jabber.org/protocol/disco#info identity"`
	Lang     string   `xml:"lang,attr,omitempty"`
	Category string   `xml:"category,attr"`
	Type     string   `xml:"type,attr"`
	Name     string   `xml:"name,attr"`
}

type DiscoveryReply

type DiscoveryReply struct {
	XMLName    xml.Name            `xml:"http://jabber.org/protocol/disco#info query"`
	Node       string              `xml:"node"`
	Identities []DiscoveryIdentity `xml:"identity"`
	Features   []DiscoveryFeature  `xml:"feature"`
	Forms      []Form              `xml:"jabber:x:data x"`
}

func (*DiscoveryReply) VerificationString

func (r *DiscoveryReply) VerificationString() (string, error)

VerificationString returns a SHA-1 verification string as defined in XEP-0115. See http://xmpp.org/extensions/xep-0115.html#ver

type EmptyReply

type EmptyReply struct {
}

An EmptyReply results in in no XML.

type ErrorBadRequest

type ErrorBadRequest struct {
	XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas bad-request"`
}

ErrorBadRequest reflects a bad-request stanza. See http://xmpp.org/rfcs/rfc6120.html#stanzas-error-conditions-bad-request

type ErrorReply

type ErrorReply struct {
	XMLName xml.Name    `xml:"error"`
	Type    string      `xml:"type,attr"`
	Error   interface{} `xml:"error"`
}

ErrorReply reflects an XMPP error stanza. See http://xmpp.org/rfcs/rfc6120.html#stanzas-error-syntax

type FixedFormField

type FixedFormField struct {
	FormField

	Text string
}

FixedFormField is used to indicate a section heading. It's for the form to send data to the user rather than the other way around.

type Form

type Form struct {
	XMLName      xml.Name    `xml:"jabber:x:data x"`
	Type         string      `xml:"type,attr"`
	Title        string      `xml:"title,omitempty"`
	Instructions string      `xml:"instructions,omitempty"`
	Fields       []formField `xml:"field"`
}

type FormCallback

type FormCallback func(title, instructions string, fields []interface{}) error

FormCallback is the type of a function called to process a form. The argument is a list of pointers to FormField types. The function should type cast the elements, prompt the user and fill in the result field in each struct.

type FormField

type FormField struct {
	// Label is a human readable label for this field.
	Label string
	// Type is the XMPP-internal type of this field. One should type cast
	// rather than inspect this.
	Type string
	// Name gives the internal name of the field.
	Name     string
	Required bool
	// Media contains one of more items of media associated with this
	// field and, for each item, one or more representations of it.
	Media [][]Media
}

FormField is the type of a generic form field. One should type cast to a specific type of field before processing.

type Media

type Media struct {
	MIMEType string
	// URI contains a URI to the data. It may be empty if Data is not.
	URI string
	// Data contains the raw data itself. It may be empty if URI is not.
	Data []byte
}

type MultiSelectionFormField

type MultiSelectionFormField struct {
	FormField

	Values  []string
	Ids     []string
	Results []int
}

MultiSelectionFormField asks the user to pick a subset of possible choices. The Result member should be set to a series of indexes of the Results array.

type MultiTextFormField

type MultiTextFormField struct {
	FormField

	Defaults []string
	Results  []string
}

MultiTextFormField is for the entry of a several textual items. The Results member should be set to the data entered.

type PresenceItem

type PresenceItem struct {
	Jid string `xml:"jid,attr"`
}

type RegisterQuery

type RegisterQuery struct {
	XMLName  xml.Name  `xml:"jabber:iq:register query"`
	Username *xml.Name `xml:"username"`
	Password *xml.Name `xml:"password"`
	Form     Form      `xml:"x"`
	Datas    []bobData `xml:"data"`
}

type Roster

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

type RosterEntry

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

func ParseRoster

func ParseRoster(reply Stanza) ([]RosterEntry, error)

ParseRoster extracts roster information from the given Stanza.

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"`
}

type SelectionFormField

type SelectionFormField struct {
	FormField

	Values []string
	Ids    []string
	Result int
}

SelectionFormField asks the user to pick a single element from a set of choices. The Result member should be set to an index of the Values array.

type Stanza

type Stanza struct {
	Name  xml.Name
	Value interface{}
}

Stanza represents a message from the XMPP server.

type StreamError

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

type TextFormField

type TextFormField struct {
	FormField

	Default string
	Result  string
	// Private is true if this is a password or other sensitive entry.
	Private bool
}

TextFormField is for the entry of a single textual item. The Result member should be set to the data entered.

type VersionQuery

type VersionQuery struct {
	XMLName xml.Name `xml:"jabber:iq:version query"`
}

type VersionReply

type VersionReply struct {
	XMLName xml.Name `xml:"jabber:iq:version query"`
	Name    string   `xml:"name"`
	Version string   `xml:"version"`
	OS      string   `xml:"os"`
}

Jump to

Keyboard shortcuts

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