Removed uses of Generic from the Stanza types.
authorChris Jones <chris@cjones.org>
Fri, 18 Oct 2013 18:31:18 -0600
changeset 172 36a42bc073f0
parent 171 2f6ae54a2bd1
child 173 b257c67d2491
Removed uses of Generic from the Stanza types.
xmpp/structs.go
xmpp/structs_test.go
--- a/xmpp/structs.go	Thu Oct 17 22:41:08 2013 -0600
+++ b/xmpp/structs.go	Fri Oct 18 18:31:18 2013 -0600
@@ -98,9 +98,9 @@
 type Message struct {
 	XMLName xml.Name `xml:"jabber:client message"`
 	Header
-	Subject *Generic `xml:"jabber:client subject"`
-	Body    *Generic `xml:"jabber:client body"`
-	Thread  *Generic `xml:"jabber:client thread"`
+	Subject []Text   `xml:"jabber:client subject"`
+	Body    []Text   `xml:"jabber:client body"`
+	Thread  *Data  `xml:"jabber:client thread"`
 }
 
 var _ Stanza = &Message{}
@@ -109,9 +109,9 @@
 type Presence struct {
 	XMLName xml.Name `xml:"presence"`
 	Header
-	Show     *Generic `xml:"jabber:client show"`
-	Status   *Generic `xml:"jabber:client status"`
-	Priority *Generic `xml:"jabber:client priority"`
+	Show     *Data   `xml:"jabber:client show"`
+	Status   []Text  `xml:"jabber:client status"`
+	Priority *Data   `xml:"jabber:client priority"`
 }
 
 var _ Stanza = &Presence{}
@@ -142,6 +142,22 @@
 	Jid      *string  `xml:"jid"`
 }
 
+// Holds human-readable text, with an optional language
+// specification. Generally multiple instances of these can be found
+// together, allowing the software to choose which language to present
+// to the user.
+type Text struct {
+	XMLName xml.Name
+	Lang     string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
+	Chardata string `xml:",chardata"`
+}
+
+// Non-human-readable content of some sort, used by the protocol.
+type Data struct {
+	XMLName xml.Name
+	Chardata string `xml:",chardata"`
+}
+
 // Holds an XML element not described by the more specific types.
 type Generic struct {
 	XMLName  xml.Name
--- a/xmpp/structs_test.go	Thu Oct 17 22:41:08 2013 -0600
+++ b/xmpp/structs_test.go	Fri Oct 18 18:31:18 2013 -0600
@@ -108,8 +108,8 @@
 }
 
 func TestMarshalEscaping(t *testing.T) {
-	msg := &Message{Body: &Generic{XMLName: xml.Name{Local: "body"},
-		Chardata: `&<!-- "`}}
+	msg := &Message{Body: []Text{Text{XMLName: xml.Name{Local: "body"},
+		Chardata: `&<!-- "`}}}
 	exp := `<message xmlns="jabber:client"><body>&amp;&lt;!-- &#34;</body></message>`
 	assertMarshal(t, exp, msg)
 }
@@ -123,8 +123,8 @@
 	obs := <-ch
 	exp := &Message{XMLName: xml.Name{Local: "message", Space: "jabber:client"},
 		Header: Header{To: "a@b.c", Innerxml: "<body>foo!</body>"},
-		Body: &Generic{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
-			Chardata: "foo!"}}
+		Body: []Text{Text{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
+			Chardata: "foo!"}}}
 	if !reflect.DeepEqual(obs, exp) {
 		t.Errorf("read %s\ngot:  %#v\nwant: %#v\n", str, obs, exp)
 	}