~samwhited/xmpp

25d92cdad7849d4841f325163fad7b81ff611a58 — Sam Whited 5 years ago 01d563d
Export the Stanza type
5 files changed, 22 insertions(+), 25 deletions(-)

M iq.go
M message.go
M message_test.go
M presence.go
M stanza.go
M iq.go => iq.go +4 -9
@@ 8,21 8,16 @@ import (
	"encoding/xml"
	"errors"
	"strings"

	"mellium.im/xmpp/jid"
)

// IQ ("Information Query") is used as a general request response mechanism.
// IQ's are one-to-one, provide get and set semantics, and always require a
// response in the form of a result or an error.
type IQ struct {
	From     *jid.JID `xml:"from,attr"`
	To       *jid.JID `xml:"to,attr"`
	ID       string   `xml:"id,attr"`
	Lang     string   `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	InnerXML []byte   `xml:",innerxml"`
	Type     iqType   `xml:"type,attr"`
	XMLName  xml.Name `xml:"iq"`
	Stanza

	Type    iqType   `xml:"type,attr"`
	XMLName xml.Name `xml:"iq"`
}

type iqType int

M message.go => message.go +3 -2
@@ 13,9 13,10 @@ import (
// messages to an individual or group chat server, or for notifications and
// alerts that don't require a response.
type Message struct {
	stanza
	Stanza

	XMLName xml.Name `xml:"message"`
	Type    messageType `xml:"type,attr,omitempty"`
	XMLName xml.Name    `xml:"message"`
}

type messageType int

M message_test.go => message_test.go +10 -10
@@ 37,11 37,11 @@ func TestUnmarshalMessage(t *testing.T) {
</message>
	`)
	m := &Message{
		stanza{
		Stanza: Stanza{
			To:   &jid.JID{},
			From: &jid.JID{},
		},
		xml.Name{},
		XMLName: xml.Name{},
	}
	err := xml.Unmarshal(mb, m)
	if err != nil {


@@ 49,16 49,16 @@ func TestUnmarshalMessage(t *testing.T) {
		t.Fail()
	}

	if m.stanza.To.String() != "romeo@example.net" {
		t.Logf("Expected %s but got %s", "romeo@example.net", m.stanza.To.String())
	if m.Stanza.To.String() != "romeo@example.net" {
		t.Logf("Expected %s but got %s", "romeo@example.net", m.Stanza.To.String())
		t.Fail()
	}
	if m.stanza.To.String() != "romeo@example.net" {
		t.Logf("Expected %s but got %s", "romeo@example.net", m.stanza.To.String())
	if m.Stanza.To.String() != "romeo@example.net" {
		t.Logf("Expected %s but got %s", "romeo@example.net", m.Stanza.To.String())
		t.Fail()
	}
	if m.stanza.ID != "ktx72v49" {
		t.Logf("Expected %s but got %s", "ktx72v49", m.stanza.To.String())
	if m.Stanza.ID != "ktx72v49" {
		t.Logf("Expected %s but got %s", "ktx72v49", m.Stanza.To.String())
		t.Fail()
	}
}


@@ 67,12 67,12 @@ func TestUnmarshalMessage(t *testing.T) {
func TestMarshalMessage(t *testing.T) {
	j := jid.MustParse("feste@shakespeare.lit")
	m := Message{
		stanza{
		Stanza: Stanza{
			ID:   "1234",
			To:   j,
			Lang: "en",
		},
		xml.Name{Space: "jabber:client", Local: "message"},
		XMLName: xml.Name{Space: "jabber:client", Local: "message"},
	}
	// TODO: Check the output; is the order guaranteed?
	if _, err := xml.Marshal(m); err != nil {

M presence.go => presence.go +3 -2
@@ 13,9 13,10 @@ import (
// availability, and advertise entity capabilities. It can be directed
// (one-to-one), or used as a broadcast mechanism (one-to-many).
type Presence struct {
	stanza
	Stanza

	XMLName xml.Name `xml:"presence"`
	Type    presenceType `xml:"type,attr,omitempty"`
	XMLName xml.Name     `xml:"presence"`
}

type presenceType int

M stanza.go => stanza.go +2 -2
@@ 11,9 11,9 @@ import (
// The default length of stanza IDs
const idLen = 16

// stanza contains fields common to any any top level XMPP stanza (Presence,
// Stanza contains fields common to any any top level XMPP stanza (Presence,
// Message, or IQ).
type stanza struct {
type Stanza struct {
	ID    string   `xml:"id,attr"`
	Inner string   `xml:",innerxml"`
	To    *jid.JID `xml:"to,attr"`