equal
deleted
inserted
replaced
136 Id string `xml:"attr"` |
136 Id string `xml:"attr"` |
137 Type string `xml:"attr"` |
137 Type string `xml:"attr"` |
138 Lang string `xml:"attr"` |
138 Lang string `xml:"attr"` |
139 Error *Error |
139 Error *Error |
140 Any *Generic |
140 Any *Generic |
|
141 Query *RosterQuery |
141 } |
142 } |
142 var _ xml.Marshaler = &Iq{} |
143 var _ xml.Marshaler = &Iq{} |
143 var _ Stanza = &Iq{} |
144 var _ Stanza = &Iq{} |
|
145 |
|
146 // Roster query/result |
|
147 type RosterQuery struct { |
|
148 // Should always be query in the NsRoster namespace |
|
149 XMLName xml.Name |
|
150 Item []RosterItem |
|
151 } |
|
152 |
|
153 // See RFC 3921, Section 7.1. |
|
154 type RosterItem struct { |
|
155 // Should always be "item" |
|
156 XMLName xml.Name |
|
157 Jid string `xml:"attr"` |
|
158 Subscription string `xml:"attr"` |
|
159 Name string `xml:"attr"` |
|
160 Group []string |
|
161 } |
144 |
162 |
145 // Describes an XMPP stanza error. See RFC 3920, Section 9.3. |
163 // Describes an XMPP stanza error. See RFC 3920, Section 9.3. |
146 type Error struct { |
164 type Error struct { |
147 // The error type attribute. |
165 // The error type attribute. |
148 Type string `xml:"attr"` |
166 Type string `xml:"attr"` |
262 return fmt.Sprintf("<%s %s>%s%s</%s %s>", u.XMLName.Space, |
280 return fmt.Sprintf("<%s %s>%s%s</%s %s>", u.XMLName.Space, |
263 u.XMLName.Local, sub, u.Chardata, u.XMLName.Space, |
281 u.XMLName.Local, sub, u.Chardata, u.XMLName.Space, |
264 u.XMLName.Local) |
282 u.XMLName.Local) |
265 } |
283 } |
266 |
284 |
|
285 // BUG(cjyar) This is fragile. We should find a way to use go's native |
|
286 // XML marshaling. |
267 func marshalXML(st Stanza) ([]byte, os.Error) { |
287 func marshalXML(st Stanza) ([]byte, os.Error) { |
268 buf := bytes.NewBuffer(nil) |
288 buf := bytes.NewBuffer(nil) |
269 buf.WriteString("<") |
289 buf.WriteString("<") |
270 buf.WriteString(st.XName()) |
290 buf.WriteString(st.XName()) |
271 if st.XTo() != "" { |
291 if st.XTo() != "" { |
288 bytes, _ := st.XError().MarshalXML() |
308 bytes, _ := st.XError().MarshalXML() |
289 buf.WriteString(string(bytes)) |
309 buf.WriteString(string(bytes)) |
290 } |
310 } |
291 if st.XChild() != nil { |
311 if st.XChild() != nil { |
292 xml.Marshal(buf, st.XChild()) |
312 xml.Marshal(buf, st.XChild()) |
|
313 } |
|
314 if iq, ok := st.(*Iq) ; ok && iq.Query != nil { |
|
315 xml.Marshal(buf, iq.Query) |
293 } |
316 } |
294 buf.WriteString("</") |
317 buf.WriteString("</") |
295 buf.WriteString(st.XName()) |
318 buf.WriteString(st.XName()) |
296 buf.WriteString(">") |
319 buf.WriteString(">") |
297 return buf.Bytes(), nil |
320 return buf.Bytes(), nil |