2
0
mirror of https://github.com/FluuxIO/go-xmpp synced 2024-11-05 12:00:50 +00:00
go-xmpp/stanza
2024-05-16 16:47:09 +02:00
..
commands_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
commands.go Support multiple command elements 2024-05-16 16:47:09 +02:00
component_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
component.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
datetime_profiles_test.go Support for XEP-0082. 2020-04-29 10:13:31 +02:00
datetime_profiles.go Support for XEP-0082. 2020-04-29 10:13:31 +02:00
doc.go Spelling consistency 2019-06-29 14:57:24 +02:00
error_enum.go Refactor and move parsing and stanza to a separate package 2019-06-26 17:14:52 +02:00
error_test.go We do not need the Content to be innerxml. cdata is enough. 2019-09-27 18:25:27 +02:00
error.go PubSub protocol support (#142) 2020-01-09 15:33:11 +01:00
fifo_queue.go Added missing tests 2020-03-09 17:12:32 +01:00
form_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
form.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iot_test.go We do not need the Content to be innerxml. cdata is enough. 2019-09-27 18:25:27 +02:00
iot.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq_disco_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq_disco.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq_roster_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq_roster.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq_version_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq_version.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
iq.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
jid_test.go Support partial JIDs in Bare/Full methods 2021-12-14 12:01:36 +01:00
jid.go Support partial JIDs in Bare/Full methods 2021-12-14 12:01:36 +01:00
message_test.go Fix tests after refactor 2019-06-26 17:28:54 +02:00
message.go Refactor and move parsing and stanza to a separate package 2019-06-26 17:14:52 +02:00
msg_chat_markers.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
msg_chat_state.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
msg_hint_test.go Support for XEP-0334 2020-04-09 10:02:11 +02:00
msg_hint.go Support for XEP-0334 2020-04-09 10:02:11 +02:00
msg_html_test.go Fix tests after refactor 2019-06-26 17:28:54 +02:00
msg_html.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
msg_oob.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
msg_pubsub_event_test.go PubSub protocol support (#142) 2020-01-09 15:33:11 +01:00
msg_pubsub_event.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
msg_receipts_test.go Fix tests after refactor 2019-06-26 17:28:54 +02:00
msg_receipts.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
node_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
node.go Tests for Component and code style fixes (#129) 2019-11-28 17:15:15 +01:00
ns.go Correctly open new streams after StartTLS and auth 2019-10-28 16:38:10 +01:00
open.go Transports need to handle open/close stanzas 2019-10-28 16:38:10 +01:00
packet_enum.go Tests for Component and code style fixes (#129) 2019-11-28 17:15:15 +01:00
packet.go Refactor and move parsing and stanza to a separate package 2019-06-26 17:14:52 +02:00
parser.go Changed "Disconnect" to wait for the closing stream tag. (#141) 2019-12-26 14:47:02 +01:00
pep.go PubSub protocol support (#142) 2020-01-09 15:33:11 +01:00
pres_muc_test.go Resync with Master 2019-06-26 18:42:40 +02:00
pres_muc.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
presence_enum.go Refactor and move parsing and stanza to a separate package 2019-06-26 17:14:52 +02:00
presence_test.go Fix tests after refactor 2019-06-26 17:28:54 +02:00
presence.go Refactor and move parsing and stanza to a separate package 2019-06-26 17:14:52 +02:00
pubsub_owner_test.go Various fixes 2020-01-31 15:17:59 +01:00
pubsub_owner.go Support multiple command elements 2024-05-16 16:47:09 +02:00
pubsub_test.go Various fixes 2020-01-31 15:17:59 +01:00
pubsub.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
README.md Remove Bind in the payload list, as it is intended to be used by XMPP client and not by users of the library. 2019-06-29 16:10:53 +02:00
registry_test.go Refactor and move parsing and stanza to a separate package 2019-06-26 17:14:52 +02:00
registry.go Refactor and move parsing and stanza to a separate package 2019-06-26 17:14:52 +02:00
results_sets_test.go Reset Tests 2020-01-31 12:06:53 +01:00
results_sets.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00
sasl_auth_test.go Refactor tests 2020-03-06 17:52:52 +01:00
sasl_auth.go Refactor tests 2020-03-06 17:52:52 +01:00
stanza_errors.go Refactor tests 2020-03-06 17:52:52 +01:00
starttls.go Add support for self-signed certificates 2019-07-15 12:22:21 +02:00
stream_features_test.go Transports need to handle open/close stanzas 2019-10-28 16:38:10 +01:00
stream_features.go Refactor tests 2020-03-06 17:52:52 +01:00
stream_management_test.go Added missing tests 2020-03-09 17:12:32 +01:00
stream_management.go Added missing tests 2020-03-09 17:12:32 +01:00
stream.go Added Roster IQs 2019-12-23 09:04:18 +01:00
xmpp_test.go - Changed IQ stanzas to pointer semantics 2020-01-31 11:48:03 +01:00

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"

	"gosrc.io/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{})
}