~samwhited/xmpp

46002ff5f97041f97023e42431400200b24917fa — Sam Whited 5 years ago c67f48d
Remove Stanza struct (it was pointless)

At first I thought it would be useful when creating Nonzas, but they're
not likely to actually share any properties with stanzas since they're
not routable.
5 files changed, 32 insertions(+), 43 deletions(-)

M iq.go
M message.go
M message_test.go
M presence.go
D stanza.go
M iq.go => iq.go +7 -2
@@ 8,14 8,19 @@ 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 {
	Stanza

	ID      string   `xml:"id,attr"`
	Inner   string   `xml:",innerxml"`
	To      *jid.JID `xml:"to,attr"`
	From    *jid.JID `xml:"from,attr"`
	Lang    string   `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	Type    iqType   `xml:"type,attr"`
	XMLName xml.Name `xml:"iq"`
}

M message.go => message.go +7 -2
@@ 6,6 6,8 @@ package xmpp

import (
	"encoding/xml"

	"mellium.im/xmpp/jid"
)

// Message is an XMPP stanza that contains a payload for direct one-to-one


@@ 13,8 15,11 @@ import (
// messages to an individual or group chat server, or for notifications and
// alerts that don't require a response.
type Message struct {
	Stanza

	ID      string      `xml:"id,attr"`
	Inner   string      `xml:",innerxml"`
	To      *jid.JID    `xml:"to,attr"`
	From    *jid.JID    `xml:"from,attr"`
	Lang    string      `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	Type    messageType `xml:"type,attr,omitempty"`
	XMLName xml.Name    `xml:"message"`
}

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


@@ 55,16 53,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.To.String() != "romeo@example.net" {
		t.Logf("Expected %s but got %s", "romeo@example.net", m.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.To.String() != "romeo@example.net" {
		t.Logf("Expected %s but got %s", "romeo@example.net", m.To.String())
		t.Fail()
	}
	if m.Stanza.ID != "ktx72v49" {
		t.Logf("Expected %s but got %s", "ktx72v49", m.Stanza.To.String())
	if m.ID != "ktx72v49" {
		t.Logf("Expected %s but got %s", "ktx72v49", m.To.String())
		t.Fail()
	}
}


@@ 73,11 71,9 @@ func TestUnmarshalMessage(t *testing.T) {
func TestMarshalMessage(t *testing.T) {
	j := jid.MustParse("feste@shakespeare.lit")
	m := Message{
		Stanza: Stanza{
			ID:   "1234",
			To:   j,
			Lang: "en",
		},
		ID:      "1234",
		To:      j,
		Lang:    "en",
		XMLName: xml.Name{Space: "jabber:client", Local: "message"},
	}
	// TODO: Check the output; is the order guaranteed?

M presence.go => presence.go +7 -2
@@ 6,6 6,8 @@ package xmpp

import (
	"encoding/xml"

	"mellium.im/xmpp/jid"
)

// Presence is an XMPP stanza that is used as an indication that an entity is


@@ 13,8 15,11 @@ 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

	ID      string       `xml:"id,attr"`
	Inner   string       `xml:",innerxml"`
	To      *jid.JID     `xml:"to,attr"`
	From    *jid.JID     `xml:"from,attr"`
	Lang    string       `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	Type    presenceType `xml:"type,attr,omitempty"`
	XMLName xml.Name     `xml:"presence"`
}

D stanza.go => stanza.go +0 -22
@@ 1,22 0,0 @@
// Copyright 2015 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

package xmpp

import (
	"mellium.im/xmpp/jid"
)

// The default length of stanza IDs
const idLen = 16

// Stanza contains fields common to any any top level XMPP stanza (Presence,
// Message, or IQ).
type Stanza struct {
	ID    string   `xml:"id,attr"`
	Inner string   `xml:",innerxml"`
	To    *jid.JID `xml:"to,attr"`
	From  *jid.JID `xml:"from,attr"`
	Lang  string   `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
}