package
0.5.8
Repository: https://github.com/logicwonder/go-xmpp.git
Documentation: pkg.go.dev

# README

XMPP Stanza

XMPP stanza package is used to parse, marshal and unmarshal XMPP stanzas and nonzas.

Stanza creation

When creating stanzas, you can use two approaches:

  1. You can create IQ, Presence or Message structs, set the fields and manually prepare extensions struct to add to the stanza.
  2. You can use stanza build helper to be guided when creating the stanza, and have more controls performed on the final stanza.

The methods are equivalent and you can use whatever suits you best. The helpers will finally generate the same type of struct that you can build by hand.

Composing stanzas manually with structs

Here is for example how you would generate an IQ discovery result:

iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: iq.To, To: iq.From, Id: iq.Id})
identity := stanza.Identity{
	Name:     opts.Name,
	Category: opts.Category,
	Type:     opts.Type,
}
payload := stanza.DiscoInfo{
	XMLName: xml.Name{
		Space: stanza.NSDiscoInfo,
		Local: "query",
	},
	Identity: []stanza.Identity{identity},
	Features: []stanza.Feature{
		{Var: stanza.NSDiscoInfo},
		{Var: stanza.NSDiscoItems},
		{Var: "jabber:iq:version"},
		{Var: "urn:xmpp:delegation:1"},
	},
}
iqResp.Payload = &payload

Using helpers

Here is for example how you would generate an IQ discovery result using Builder:

iq := stanza.NewIQ(stanza.Attrs{Type: "get", To: "service.localhost", Id: "disco-get-1"})
disco := iq.DiscoInfo()
disco.AddIdentity("Test Component", "gateway", "service")
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")

Payload and extensions

Message

Here is the list of implemented message extensions:

  • Delegation

  • Markable

  • MarkAcknowledged

  • MarkDisplayed

  • MarkReceived

  • StateActive

  • StateComposing

  • StateGone

  • StateInactive

  • StatePaused

  • HTML

  • OOB

  • ReceiptReceived

  • ReceiptRequest

  • Mood

Presence

Here is the list of implemented presence extensions:

  • MucPresence

IQ

IQ (Information Queries) contain a payload associated with the request and possibly an error. The main difference with Message and Presence extension is that you can only have one payload per IQ. The XMPP specification does not support having multiple payloads.

Here is the list of structs implementing IQPayloads:

  • ControlSet
  • ControlSetResponse
  • Delegation
  • DiscoInfo
  • DiscoItems
  • Pubsub
  • Version
  • Node

Finally, when the payload of the parsed stanza is unknown, the parser will provide the unknown payload as a generic Node element. You can also use the Node struct to add custom information on stanza generation. However, in both cases, you may also consider adding your own custom extensions on stanzas.

Adding your own custom extensions on stanzas

Extensions are registered on launch using the Registry. It can be used to register you own custom payload. You may want to do so to support extensions we did not yet implement, or to add your own custom extensions to your XMPP stanzas.

To create an extension you need:

  1. to create a struct for that extension. It need to have XMLName for consistency and to tagged at the struct level with xml info.
  2. It need to implement one or several extensions interface: stanza.IQPayload, stanza.MsgExtension and / or stanza.PresExtension
  3. Add that custom extension to the stanza.TypeRegistry during the file init.

Here an example code showing how to create a custom IQPayload.

package myclient

import (
	"encoding/xml"

	"github.com/logicwonder/go-xmpp/stanza"
)

type CustomPayload struct {
	XMLName xml.Name `xml:"my:custom:payload query"`
	Node    string   `xml:"node,attr,omitempty"`
}

func (c CustomPayload) Namespace() string {
	return c.XMLName.Space
}

func init() {
	stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{"my:custom:payload", "query"}, CustomPayload{})
}

# Functions

Reads and checks the opening XMPP stream element.
NewAffiliationListRequest creates a request to list all affiliated entities See 8.9.1 Retrieve List List.
NewGetPendingSubRequests creates a new request for all pending subscriptions to be approved on a given node Upon receiving the data form for managing subscription requests, the owner then MAY request pending subscription approval requests for a given node.
NewApproveSubRequest creates a new sub approval response to a request from the service to the owner of the node In order to approve the request, the owner shall submit the form and set the "pubsub#allow" field to a value of "1" or "true" For tracking purposes the message MUST reflect the 'id' attribute originally provided in the request.
NewConfigureNode creates a request to configure a node on the given service.
NewCreateAndConfigNode makes a request for node creation that has the desired node configuration.
NewCreateNode builds a request to create a node on the service referenced by "serviceId" See 8.1 Create a Node.
NewDelItemFromNode creates a request to delete and item from a node, given its id.
NewDelNode creates a request to delete node "nodeID" from the "serviceId" service See 8.4 Delete a Node.
No description provided by the author
NewFormSubmission builds a form submission pubsub IQ Information about the subscription and the requester are separated.
NewFormSubmission builds a form submission pubsub IQ, in the Owner namespace This is typically used to respond to a form issued by the server when configuring a node.
NewGetPendingSubRequests creates a new request for all pending subscriptions to all their nodes at a service This feature MUST be implemented using the Ad-Hoc Commands (XEP-0050) protocol 8.7 Process Pending Subscription Requests.
No description provided by the author
NewItemsRequest creates a request to query existing items from a node.
No description provided by the author
No description provided by the author
No description provided by the author
NewModifAffiliationRequest creates a request to either modify one or more affiliations, or delete one or more affiliations 8.9.2 Modify Affiliation & 8.9.2.4 Multiple Simultaneous Modifications & 8.9.3 Delete an Entity (just set the status to "none").
No description provided by the author
No description provided by the author
NewPublishItemOptsRq creates a request to publish items to a node identified by its provided ID, along with configuration options A pubsub service MAY support the ability to specify options along with a publish request(if so, it MUST advertise support for the "http://jabber.org/protocol/pubsub#publish-options" feature).
NewPublishItemRq creates a request to publish a single item to a node identified by its provided ID.
NewPurgeAllItems creates a new purge request for the "nodeId" node, at "serviceId" service See 8.5 Purge All Node Items.
NewRequestDefaultConfig build a request to ask the service for the default config of its nodes See 8.3 Request Default Node Configuration Options.
NewRetrieveAllAffilsRequest builds a request to retrieve all affiliations from all nodes In order to make the request of the service, the requesting entity includes an empty <affiliations/> element with no attributes.
NewRetrieveAllSubsRequest builds a request to retrieve all subscriptions from all nodes In order to make the request, the requesting entity MUST send an IQ-get whose <pubsub/> child contains an empty <subscriptions/> element with no attributes.
NewItemsRequest creates a request to get a specific item from a node.
NewSubAndConfig builds a subscribe request that contains configuration options for the service From XEP-0060 : The <options/> element MUST follow the <subscribe/> element and MUST NOT possess a 'node' attribute or 'jid' attribute, since the value of the <subscribe/> element's 'node' attribute specifies the desired NodeID and the value of the <subscribe/> element's 'jid' attribute specifies the subscriber's JID 6.3.7 Subscribe and Configure.
NewSubListRequest creates a request to list subscriptions of the client, for all nodes at the service.
NewSubOptsRq builds a request for the subscription options.
NewSubRq builds a subscription request to a node at the given service.
No description provided by the author
No description provided by the author
NewUnsubRq builds an unsub request to a node at the given service.
NextPacket scans XML token stream for next complete XMPP stanza.
NextStart scans XML token stream to find next StartElement.
NextXmppToken scans XML token stream to find next StartElement or stream EndElement.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
********************* Associate *********************.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
********************* Disassociate *********************.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
Default.
No description provided by the author
No description provided by the author
No description provided by the author
NSDiscoInfo defines the namespace for disco IQ stanzas.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Common but not only possible namespace for query blocks in a result set context.
NSRoster is the Roster IQ namespace.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace.
No description provided by the author
No description provided by the author
********************* Delete *********************.
No description provided by the author
********************* Purge *********************.
********************* Subscription *********************.
No description provided by the author
SubscriptionBoth indicates the user and the contact have subscriptions to each other's presence (also called a "mutual subscription").
SubscriptionFrom indicates the contact has a subscription to the user's presence, but the user does not have a subscription to the contact's presence.
SubscriptionNone indicates the user does not have a subscription to the contact's presence, and the contact does not have a subscription to the user's presence; this is the default value, so if the subscription attribute is not included then the state is to be understood as "none".
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SubscriptionTo indicates the user has a subscription to the contact's presence, but the contact does not have a subscription to the user's presence.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Attr represents generic XML attributes, as used on the generic XML Node representation.
Attrs represents the common structure for base XMPP packets.
No description provided by the author
No description provided by the author
Bind is an IQ payload used during session negotiation to bind user resource to the current XMPP stream.
Capabilities Reference: https://xmpp.org/extensions/xep-0115.html#stream "A server MAY include its entity capabilities in a stream feature element so that connecting clients and peer servers do not need to send service discovery requests each time they connect." This is not a stream feature but a way to let client cache server disco info.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Delegation can be used both on message (for delegated) and IQ (for Forwarded), depending on the context.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Err is an XMPP stanza payload that is used to report error on message, presence or iq stanza.
No description provided by the author
No description provided by the author
No description provided by the author
See XEP-0004 and XEP-0068 Pointer semantics.
No description provided by the author
Forwarded is used to wrapped forwarded stanzas.
GIMSAcknowledgement implements an extenstion for sending acknowledgement for command/query.
GIMSCommand implements an extenstion for sending commands to/from GIMS client.
GIMSQuery implements an extenstion for sending query to/from GIMS client.
GIMSReply implements an extenstion for sending reply to a query.
Handshake is a stanza used by XMPP components to authenticate on XMPP component port.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
History implements XEP-0045: Multi-User Chat - 19.1.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IQ implements RFC 6120 - A.5 Client Namespace (a part).
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Message implements RFC 6120 - A.5 Client Namespace (a part).
Mood defines data model for XEP-0107 - User Mood See: https://xmpp.org/extensions/xep-0107.html.
MucPresence implements XEP-0045: Multi-User Chat - 19.1.
Node is a generic structure to represent XML data.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Presence implements RFC 6120 - A.5 Client Namespace (a part).
No description provided by the author
No description provided by the author
PublishUnread implements an extenstion for sending publish unread request.
Implementation of the http://jabber.org/protocol/pubsub#event namespace.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Used on outgoing message, to tell the recipient that you are requesting a message receipt / ack.
********************* Redirect *********************.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Roster struct represents Roster IQs.
RosterItem represents an item in the roster iq.
RosterItems represents the list of items in a roster IQ.
SASLAuth implements SASL Authentication initiation.
SASLFailure.
SASLSuccess implements SASL Success nonza, sent by server as a result of the SASL auth negotiation.
No description provided by the author
Answer as defined in Stream Management spec Reference: https://xmpp.org/extensions/xep-0198.html#acking.
No description provided by the author
Enabled as defined in Stream Management spec Reference: https://xmpp.org/extensions/xep-0198.html#enable.
Failed as defined in Stream Management spec Reference: https://xmpp.org/extensions/xep-0198.html#acking.
Request as defined in Stream Management spec Reference: https://xmpp.org/extensions/xep-0198.html#acking.
Resume as defined in Stream Management spec Reference: https://xmpp.org/extensions/xep-0198.html#acking.
Resumed as defined in Stream Management spec Reference: https://xmpp.org/extensions/xep-0198.html#acking.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Start of stream Reference: XMPP Core stream open https://tools.ietf.org/html/rfc6120#section-4.2.
This is just a closing tag and hold no information.
No description provided by the author
No description provided by the author
Session is both a stream feature and an obsolete IQ Payload, used to bind a resource to the current XMPP stream on RFC 3121 only XMPP servers.
SubInfo represents information about a subscription Node is the node related to the subscription Jid is the subscription JID of the subscribed entity SubID is the subscription ID.
No description provided by the author
No description provided by the author
Handles the "5.6 Retrieve Subscriptions" and the 6.1 Subscribe to a Node and so on of XEP-0060.
No description provided by the author
No description provided by the author
Handles the "5.6 Retrieve Subscriptions" of XEP-0060.
No description provided by the author
No description provided by the author
Used during stream initiation / session establishment.
StartTLS feature Reference: RFC 6120 - https://tools.ietf.org/html/rfc6120#section-5.4.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
UnpublishUnread implements an extenstion for sending unpublish unread request.
Unread implements an extenstion for receiving unread message notifications.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Version.
Open Packet Reference: WebSocket connections must start with this element https://tools.ietf.org/html/rfc7395#section-3.4.
No description provided by the author

# Interfaces

********************* Associate/Disassociate *********************.
No description provided by the author
No description provided by the author
FIFO queue for string contents Implementations have no guarantee regarding thread safety !.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

ErrorType is a Enum of error attribute type.
No description provided by the author
No description provided by the author
No description provided by the author
PresenceShow is a Enum of presence element show.
No description provided by the author