xmpp

package module
v0.0.0-...-88ed55e Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: BSD-3-Clause Imports: 19 Imported by: 1

README

go-xmpp

go xmpp library (original was written by russ cox )

Documentation

Documentation

Overview

Package xmpp implements a simple Google Talk client using the XMPP protocol described in RFC 3920 and RFC 3921.

Index

Constants

View Source
const (
	// IQTypeGet    = "get"
	// IQTypeSet    = "set"
	// IQTypeResult = "result"
	NSDiscoInfo  = "http://jabber.org/protocol/disco#info"
	NSDiscoItems = "http://jabber.org/protocol/disco#items"
)
View Source
const (
	NoHistory      = 0
	CharHistory    = 1
	StanzaHistory  = 2
	SecondsHistory = 3
	SinceHistory   = 4
)
View Source
const (
	NSBlock = "urn:xmpp:blocking"
)
View Source
const (
	NSIBB = "http://jabber.org/protocol/ibb"
)
View Source
const (
	NSRoster = "jabber:iq:roster"
)

Variables

View Source
var DefaultConfig tls.Config

Default TLS configuration options

Functions

This section is empty.

Types

type BlockList

type BlockList []BlockListItem

type BlockListItem

type BlockListItem struct {
	XMLName string `xml:"item"`
	JID     string `xml:"jid,attr"`
}

type Client

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

Client holds XMPP connection opitons

func NewClient

func NewClient(host, user, passwd string, debug bool) (*Client, error)

NewClient creates a new connection to a host given as "hostname" or "hostname:port". If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID. Default the port to 5222.

func NewClientNoTLS

func NewClientNoTLS(host, user, passwd string, debug bool) (*Client, error)

NewClientNoTLS creates a new client without TLS

func (*Client) ApproveSubscription

func (c *Client) ApproveSubscription(jid string) error

func (*Client) Ban

func (c *Client) Ban(room, jid, reason string) error

func (*Client) Block

func (c *Client) Block(jid string) error

func (*Client) ChangeNick

func (c *Client) ChangeNick(room, nick string) error

func (*Client) Close

func (c *Client) Close() error

Close closes the XMPP connection

func (*Client) ConfigureRoom

func (c *Client) ConfigureRoom(room string, form MUCForm) error

func (*Client) DirectInvite

func (c *Client) DirectInvite(room, jid, password, reason string) error

XEP-0249: Direct MUC Invitations

func (*Client) DiscoverReservedNick

func (c *Client) DiscoverReservedNick(room string) error

A user MAY have a reserved room nickname, for example through explicit room registration, database integration, or nickname "lockdown". A user SHOULD discover his or her reserved nickname before attempting to enter the room. This is done by sending a Service Discovery information request to the room JID while specifying a well-known Service Discovery node of "x-roomuser-item".

func (*Client) GetBlocked

func (c *Client) GetBlocked() error

func (*Client) GetDiscoInfo

func (c *Client) GetDiscoInfo(target, node string) error

target is server name or room's JID or full JID with resource

func (*Client) GetDiscoItems

func (c *Client) GetDiscoItems(target, node string) error

target is server name or room's JID or full JID with resource

func (*Client) GetRoomConfig

func (c *Client) GetRoomConfig(room string) error

XER-0045 10.2 Subsequent Room Configuration

func (*Client) GetRoomMembers

func (c *Client) GetRoomMembers(room string) error

func (*Client) Invite

func (c *Client) Invite(room string) error

func (*Client) IsEncrypted

func (c *Client) IsEncrypted() bool

IsEncrypted will return true if the client is connected using a TLS transport, either because it used. TLS to connect from the outset, or because it successfully used STARTTLS to promote a TCP connection to TLS.

func (*Client) JID

func (c *Client) JID() string

func (*Client) JoinMUC

func (c *Client) JoinMUC(room, nick string, history_type, history int, history_date *time.Time) (n int, err error)

xep-0045 7.2

func (*Client) JoinMUCNoHistory

func (c *Client) JoinMUCNoHistory(room, nick string) (n int, err error)

func (*Client) JoinProtectedMUC

func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_type, history int, history_date *time.Time) (n int, err error)

xep-0045 7.2.6

func (*Client) Kick

func (c *Client) Kick(room, nick, reason string) error

func (*Client) LeaveMUC

func (c *Client) LeaveMUC(room string) (n int, err error)

xep-0045 7.14

func (*Client) PingC2S

func (c *Client) PingC2S(jid, server string) error

func (*Client) PingS2S

func (c *Client) PingS2S(fromServer, toServer string) error

func (*Client) Recv

func (c *Client) Recv() (stanza interface{}, err error)

Recv waits to receive the next XMPP stanza. Return type is either a presence notification or a chat message. TODO: Merge Recv() and next()

func (*Client) RemoveRosterItem

func (c *Client) RemoveRosterItem(jid string) error

func (*Client) RequestRoomVoice

func (c *Client) RequestRoomVoice(room string) error

func (*Client) RequestSubscription

func (c *Client) RequestSubscription(jid string) error

func (*Client) RevokeSubscription

func (c *Client) RevokeSubscription(jid string) error

func (*Client) Roster

func (c *Client) Roster() error

Roster asks for the chat roster.

func (*Client) SendBytes

func (c *Client) SendBytes(b []byte) (n int, err error)

SendBytes sends raw bytes Do we need locks here?

func (*Client) SendElement

func (c *Client) SendElement(el interface{}) (n int, err error)

SendElement sends stanza or any XML element Maybe rewrite using concrete interface? e.g. interface {GetID(), SetID()} ??

func (*Client) SendHtml

func (c *Client) SendHtml(msg Message) (n int, err error)

SendHtml sends the message as HTML as defined by XEP-0071

func (*Client) SendIQ

func (c *Client) SendIQ(iq *IQ) (n int, err error)

func (*Client) SendKeepAlive

func (c *Client) SendKeepAlive() (n int, err error)

SendKeepAlive sends a "whitespace keepalive" as described in chapter 4.6.1 of RFC6120.

func (*Client) SendMessage

func (c *Client) SendMessage(msg *Message) (n int, err error)

Send sends the message wrapped inside an XMPP message stanza body.

func (*Client) SendPresence

func (c *Client) SendPresence(presence *Presence) (n int, err error)

SendPresence sends presence stanza

func (*Client) SendResultPing

func (c *Client) SendResultPing(id, toServer string) error

func (*Client) SendStreamError

func (c *Client) SendStreamError(e string) (n int, err error)

Send stream error and close stream

func (*Client) SendString

func (c *Client) SendString(s string) (n int, err error)

SendString sends the original text without being wrapped in an XMPP message stanza. Do we need locks here?

func (*Client) SendTopic

func (c *Client) SendTopic(room, topic string) (n int, err error)

Send sends room topic wrapped inside an XMPP message stanza body.

func (*Client) SetRoomAffiliation

func (c *Client) SetRoomAffiliation(room, jid, affiliation, reason string) error

func (*Client) SetRoomRole

func (c *Client) SetRoomRole(room, nick, role, reason string) error

func (*Client) Unblock

func (c *Client) Unblock(jid string) error

func (*Client) UpdateRosterItem

func (c *Client) UpdateRosterItem(item *RosterItem) error
type Cookie uint64

Cookie is a unique XMPP session identifier

type Delay

type Delay struct {
	Stamp string `xml:"stamp,attr"`
}

type DiscoItem

type DiscoItem struct {
	XMLName xml.Name `xml:"item"`
	JID     string   `xml:"jid,attr"`
	Node    string   `xml:"node,attr,omitempty"`
	Name    string   `xml:"name,attr,omitempty"`
}

type DiscoveryQuery

type DiscoveryQuery struct {
	Items      []DiscoItem `xml:",omitempty"`
	Identities []Identity  `xml:",omitempty"`
	Features   []Feature   `xml:",omitempty"`
	Node       string      `xml:"node,attr,omitempty"`
}

type Error

type Error struct {
	XMLName xml.Name //`xml:"error"` //`xml:"jabber:client error"`
	Code    string   `xml:",attr,omitempty"`
	Type    string   `xml:",attr,omitempty"`
	// Any     xml.Name `xml:",omitempty"`
	Text string `xml:"text,omitempty"`
}

Rename to StanzaError ???

type Feature

type Feature struct {
	XMLName xml.Name `xml:"feature"`
	Var     string   `xml:"var,attr"`
}

type IBBCLose

type IBBCLose struct {
	XMLName xml.Name `xml:"http://jabber.org/protocol/ibb close"`
	SID     string   `xml:"sid,attr"`
}

type IBBData

type IBBData struct {
	XMLName xml.Name `xml:"http://jabber.org/protocol/ibb data"`
	Seq     int      `xml:"seq,attr"`
	SID     string   `xml:"sid,attr"`
	Payload []byte   `xml:",chardata"`
}

type IBBOpen

type IBBOpen struct {
	XMLName   xml.Name `xml:"http://jabber.org/protocol/ibb open"`
	BlockSize int      `xml:"block-size,attr"`
	SID       string   `xml:"sid,attr"`
	Stanza    string   `xml:"stanza,attr,omitempty"`
}

type IQ

type IQ struct {
	XMLName      xml.Name  `xml:"jabber:client iq"`
	From         string    `xml:"from,attr,omitempty"`
	ID           string    `xml:"id,attr,omitempty"`
	To           string    `xml:"to,attr,omitempty"`
	Type         string    `xml:"type,attr"`      // error, get, result, set
	InnerElement Query     `xml:",any,omitempty"` //`xml:",innerxml"` // query, block, etc.
	Error        *Error    `xml:",omitempty"`
	Bind         *bindBind `xml:",omitempty"`
}

Info Query

type Identity

type Identity struct {
	XMLName  xml.Name `xml:"identity"`
	Category string   `xml:"category,attr"`
	Type     string   `xml:"type,attr"`
	Name     string   `xml:"name,attr,omitempty"`
}

type MUCForm

type MUCForm struct {
}

type Message

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

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

	// Any hasn't matched element
	OtherElements []XMLElement `xml:",any,omitempty"`

	Delay *Delay `xml:"delay,omitempty"`
}

RFC 3921 B.1 jabber:client Message is an incoming or outgoing XMPP chat message.

func (*Message) OtherStrings

func (m *Message) OtherStrings() []string

type Options

type Options struct {
	// Host specifies what host to connect to, as either "hostname" or "hostname:port"
	// If host is not specified, the  DNS SRV should be used to find the host from the domainpart of the JID.
	// Default the port to 5222.
	Host string

	// User specifies what user to authenticate to the remote server.
	User string

	// Password supplies the password to use for authentication with the remote server.
	Password string

	// Resource specifies an XMPP client resource, like "bot", instead of accepting one
	// from the server.  Use "" to let the server generate one for your client.
	Resource string

	// OAuthScope provides go-xmpp the required scope for OAuth2 authentication.
	OAuthScope string

	// OAuthToken provides go-xmpp with the required OAuth2 token used to authenticate
	OAuthToken string

	// OAuthXmlNs provides go-xmpp with the required namespaced used for OAuth2 authentication.  This is
	// provided to the server as the xmlns:auth attribute of the OAuth2 authentication request.
	OAuthXmlNs string

	// TLS Config
	TLSConfig *tls.Config

	// InsecureAllowUnencryptedAuth permits authentication over a TCP connection that has not been promoted to
	// TLS by STARTTLS; this could leak authentication information over the network, or permit man in the middle
	// attacks.
	InsecureAllowUnencryptedAuth bool

	// NoTLS directs go-xmpp to not use TLS initially to contact the server; instead, a plain old unencrypted
	// TCP connection should be used. (Can be combined with StartTLS to support STARTTLS-based servers.)
	NoTLS bool

	// StartTLS directs go-xmpp to STARTTLS if the server supports it; go-xmpp will automatically STARTTLS
	// if the server requires it regardless of this option.
	StartTLS bool

	// Debug output
	Debug bool

	// Use server sessions
	Session bool

	// Presence Status
	Status string

	// Status message
	StatusMessage string
}

Options are used to specify additional options for new clients, such as a Resource.

func (Options) NewClient

func (o Options) NewClient() (*Client, error)

NewClient establishes a new Client connection based on a set of Options.

type Presence

type Presence 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:"xml lang,attr,omitempty"`

	Show     string `xml:"show,omitempty"`   // away, chat, dnd, xa
	Status   string `xml:"status,omitempty"` // sb []clientText
	Priority string `xml:"priority,attr,omitempty"`
	Error    *Error `xml:",omitempty"`
}

Presence is an XMPP presence notification.

type Query

type Query struct {
	XMLName  xml.Name //`xml:"query"`
	InnerXML []byte   `xml:",innerxml"`
}

func (*Query) Parse

func (q *Query) Parse() (stanza interface{}, err error)

type Roster

type Roster []RosterItem

type RosterItem

type RosterItem struct {
	XMLName      xml.Name `xml:"item" json:"-"`
	JID          string   `xml:"jid,attr"`
	Subscription string   `xml:"subscription,attr,omitempty"`
	Name         string   `xml:"name,attr,omitempty"`
	Group        []string `xml:"group,omitempty"`
}

type XMLElement

type XMLElement struct {
	XMLName  xml.Name
	InnerXML []byte `xml:",innerxml"`
}

func (*XMLElement) String

func (e *XMLElement) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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