structs.go
changeset 33 571713f49494
parent 32 4e68d8f89dc3
child 34 7b1f924c75e2
--- a/structs.go	Thu Dec 29 11:25:26 2011 -0700
+++ b/structs.go	Fri Dec 30 17:16:37 2011 -0700
@@ -138,10 +138,28 @@
 	Lang string `xml:"attr"`
 	Error *Error
 	Any *Generic
+	Query *RosterQuery
 }
 var _ xml.Marshaler = &Iq{}
 var _ Stanza = &Iq{}
 
+// Roster query/result
+type RosterQuery struct {
+	// Should always be query in the NsRoster namespace
+	XMLName xml.Name
+	Item []RosterItem
+}
+
+// See RFC 3921, Section 7.1.
+type RosterItem struct {
+	// Should always be "item"
+	XMLName xml.Name
+	Jid string `xml:"attr"`
+	Subscription string `xml:"attr"`
+	Name string `xml:"attr"`
+	Group []string
+}
+
 // Describes an XMPP stanza error. See RFC 3920, Section 9.3.
 type Error struct {
 	// The error type attribute.
@@ -264,6 +282,8 @@
 		u.XMLName.Local)
 }
 
+// BUG(cjyar) This is fragile. We should find a way to use go's native
+// XML marshaling.
 func marshalXML(st Stanza) ([]byte, os.Error) {
 	buf := bytes.NewBuffer(nil)
 	buf.WriteString("<")
@@ -291,6 +311,9 @@
 	if st.XChild() != nil {
 		xml.Marshal(buf, st.XChild())
 	}
+	if iq, ok := st.(*Iq) ; ok && iq.Query != nil {
+		xml.Marshal(buf, iq.Query)
+	}
 	buf.WriteString("</")
 	buf.WriteString(st.XName())
 	buf.WriteString(">")