xmpp

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: BSD-3-Clause Imports: 28 Imported by: 0

README

go-xmpp

go xmpp library.

Original work done by Russ Cox, then Yasuhiro Matsumoto fork it and continue to improve it.

Since both of them have almost zero interest to continue develop this lib, I decide to fork it.

Documentation can be found at godoc project

This fork maintains my needs for xmpp protocol. Feel free to contribute via PR-s if you find it interesting too and feel that it needs more love than it already has. And of course fell free to for it if needed.

Documentation

Overview

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

TODO(flo):

  • cleanup signatures of join/leave functions

Index

Constants

View Source
const (
	XMPPNS_AVATAR_PEP_DATA     = "urn:xmpp:avatar:data"     //nocritic:revive
	XMPPNS_AVATAR_PEP_METADATA = "urn:xmpp:avatar:metadata" //nocritic:revive
)
View Source
const (
	XMPPNS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items" //nocritic:revive
	XMPPNS_DISCO_INFO  = "http://jabber.org/protocol/disco#info"  //nocritic:revive
)
View Source
const (
	NoHistory      = 0
	CharHistory    = 1
	StanzaHistory  = 2
	SecondsHistory = 3
	SinceHistory   = 4
)
View Source
const (
	XMPPNS_PUBSUB       = "http://jabber.org/protocol/pubsub"       //nolint:revive
	XMPPNS_PUBSUB_EVENT = "http://jabber.org/protocol/pubsub#event" //nolint:revive
)
View Source
const IQTypeError = "error"
View Source
const IQTypeGet = "get"
View Source
const IQTypeResult = "result"
View Source
const IQTypeSet = "set"

Variables

View Source
var DebugWriter io.Writer = os.Stderr

DebugWriter is the writer used to write debugging output to.

View Source
var DefaultConfig = &tls.Config{} //nolint:gosec // go fuck yourself, gosec

DefaultConfig is default TLS configuration options.

View Source
var StanzaWriter io.Writer

Functions

This section is empty.

Types

type AvatarData

type AvatarData struct {
	Data []byte
	From string
}

type AvatarMetadata

type AvatarMetadata struct {
	From   string
	Bytes  int
	Width  int
	Height int
	ID     string
	Type   string
	URL    string
}

type Chat

type Chat struct {
	Remote    string
	Type      string
	Text      string
	Subject   string
	Thread    string
	Ooburl    string
	Oobdesc   string
	Roster    Roster
	Other     []string
	OtherElem []XMLElement
	Stamp     time.Time
}

Chat is an incoming or outgoing XMPP chat message.

type Client

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

Client holds XMPP connection options.

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) AvatarRequestData

func (c *Client) AvatarRequestData(jid string) (string, error)

func (*Client) AvatarRequestDataByID

func (c *Client) AvatarRequestDataByID(jid, id string) (string, error)

func (*Client) AvatarRequestMetadata

func (c *Client) AvatarRequestMetadata(jid string) (string, error)

func (*Client) AvatarSubscribeMetadata

func (c *Client) AvatarSubscribeMetadata(jid string) (string, error)

func (*Client) AvatarUnsubscribeMetadata

func (c *Client) AvatarUnsubscribeMetadata(jid string) (string, error)

func (*Client) Close

func (c *Client) Close() error

Close closes the XMPP connection.

func (*Client) DiscoverEntityItems

func (c *Client) DiscoverEntityItems(jid string) (string, error)

DiscoverEntityItems discovers items that an entity exposes.

func (*Client) DiscoverInfo added in v1.1.0

func (c *Client) DiscoverInfo(from string, to string) (string, error)

DiscoverInfo discovers information about given item from given jid.

func (*Client) DiscoverNodeInfo

func (c *Client) DiscoverNodeInfo(node string) (string, error)

DiscoverNodeInfo discovers information about a node. Empty node queries info about server itself.

func (*Client) DiscoverServerItems

func (c *Client) DiscoverServerItems() (string, error)

DiscoverServerItems discover items that the server exposes.

func (*Client) Discovery

func (c *Client) Discovery() (string, error)

func (*Client) ErrorNotImplemented added in v1.5.0

func (c *Client) ErrorNotImplemented(v IQ, xmlns, feature string) (string, error)

ErrorNotImplemented implements error response about feature that is not (yet?) implemented. Xmlns is about not implemented feature.

If queried feature is not here because of it under development or for similar reasons, standards suggest answer with this stanza.

func (*Client) ErrorServiceUnavailable added in v1.5.0

func (c *Client) ErrorServiceUnavailable(v IQ, queryXmlns, node string) (string, error)

ErrorServiceUnavailable implements error response about feature that is not available. Currently implemented for xep-0030. QueryXmlns is about incoming xmlns attribute in query tag. Node is about incoming node attribute in query tag (looks like it used only in disco#commands).

If queried feature is not here on purpose, standards suggest answer with this stanza.

func (*Client) IqVersionResponse added in v1.5.0

func (c *Client) IqVersionResponse(v IQ, name, version, os string) (string, error)

IqVersionResponse responding with software version, according to xep-0092.

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) JabberIqLastResponse added in v1.5.0

func (c *Client) JabberIqLastResponse(v IQ, lastActivity int64) (string, error)

JabberIqLastResponse responding with relative time since last activity. Here lastActivity is unix time stamp when last activity took place since.

func (*Client) JoinMUC

func (c *Client) JoinMUC(jid, nick string, historyType, history int, historyDate *time.Time) (int, error)

JoinMUC joins room, xep-0045 7.2.

func (*Client) JoinMUCNoHistory

func (c *Client) JoinMUCNoHistory(jid, nick string) (int, error)

JoinMUCNoHistory joins room and instructs server that no history data required.

func (*Client) JoinProtectedMUC

func (c *Client) JoinProtectedMUC(jid, nick string, password string, historyType, history int, historyDate *time.Time) (int, error)

JoinProtectedMUC joins password protected room, xep-0045 7.2.6.

func (*Client) LeaveMUC

func (c *Client) LeaveMUC(jid string) (int, error)

LeaveMUC quits from room xep-0045 7.14.

func (*Client) PingC2S

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

func (*Client) PingResponse added in v1.5.0

func (c *Client) PingResponse(v IQ) (string, error)

PingResponse responding to ping query according to xep-0199.

func (*Client) PingS2S

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

func (*Client) PubsubRequestItem

func (c *Client) PubsubRequestItem(node, jid, id string) (string, error)

func (*Client) PubsubRequestLastItems

func (c *Client) PubsubRequestLastItems(node, jid string) (string, error)

func (*Client) PubsubSubscribeNode

func (c *Client) PubsubSubscribeNode(node, jid string) (string, error)

func (*Client) PubsubUnsubscribeNode

func (c *Client) PubsubUnsubscribeNode(node, jid string) (string, error)

func (*Client) RawInformation

func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error)

RawInformation sends a IQ request with the payload body to the server.

func (*Client) RawInformationQuery

func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error)

RawInformationQuery sends an information query request to the server.

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.

func (*Client) RequestSubscription

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

func (*Client) RetrieveSubscription

func (c *Client) RetrieveSubscription(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) Send

func (c *Client) Send(chat Chat) (int, error)

Send sends the message wrapped inside an XMPP message stanza body. Returns amount bytes sent and error (if any).

func (*Client) SendHtml

func (c *Client) SendHtml(chat Chat) (int, error)

SendHtml sends the message as HTML as defined by XEP-0071. Returns amount bytes sent and error (if any).

func (*Client) SendKeepAlive

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

SendKeepAlive sends a "whitespace keepalive" as described in chapter 4.6.1 of RFC6120. Returns amount bytes sent and error (if any).

func (*Client) SendOOB

func (c *Client) SendOOB(chat Chat) (int, error)

SendOOB sends OOB data wrapped inside an XMPP message stanza, without actual body. Returns amount bytes sent and error (if any).

func (*Client) SendOrg

func (c *Client) SendOrg(org string) (int, error)

SendOrg sends the original text without being wrapped in an XMPP message stanza. Returns amount bytes sent and error (if any).

func (*Client) SendPresence

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

SendPresence sends Presence wrapped inside XMPP presence stanza.

func (*Client) SendResultPing

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

func (*Client) SendTopic

func (c *Client) SendTopic(chat Chat) (int, error)

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

func (*Client) UrnXMPPTimeResponse added in v1.6.0

func (c *Client) UrnXMPPTimeResponse(v IQ, timezoneOffset string) (string, error)

UrnXMPPTimeResponse implements response to query entity's current time (xep-0202). TimezoneOffset have format +HH:MM or -HH:MM.

type Contact

type Contact struct {
	Remote string
	Name   string
	Group  []string
}
type Cookie uint64

Cookie is a unique XMPP session identifier.

type Delay

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

type DiscoIdentity

type DiscoIdentity struct {
	Category string
	Type     string
	Name     string
}

type DiscoItem

type DiscoItem struct {
	Jid  string
	Name string
	Node string
}

type DiscoItems

type DiscoItems struct {
	Jid   string
	Items []DiscoItem
}

type DiscoResult

type DiscoResult struct {
	ID         string
	From       string
	To         string
	Features   []string
	Identities []DiscoIdentity
}

type IQ

type IQ struct {
	ID    string
	From  string
	To    string
	Type  string
	Query []byte
}

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

	// DialTimeout is the time limit for establishing a connection. A
	// DialTimeout of zero means no timeout.
	DialTimeout time.Duration

	// 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 {
	From        string
	To          string
	Type        string
	Show        string
	Status      string
	Priority    string
	ID          string
	Affiliation string
	Role        string
	JID         string
}

Presence is an XMPP presence notification.

type PubsubEvent

type PubsubEvent struct {
	Node  string
	Items []PubsubItem
}

type PubsubItem

type PubsubItem struct {
	ID       string
	InnerXML []byte
}

type PubsubItems

type PubsubItems struct {
	Node  string
	Items []PubsubItem
}

type PubsubSubscription

type PubsubSubscription struct {
	SubID  string
	JID    string
	Node   string
	Errors []string
}

type PubsubUnsubscription

type PubsubUnsubscription PubsubSubscription

type Roster

type Roster []Contact

type XMLElement

type XMLElement struct {
	XMLName  xml.Name
	Attr     []xml.Attr `xml:",any,attr"` // Save the attributes of the xml element
	InnerXML string     `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