92 // The xml:lang attribute. |
92 // The xml:lang attribute. |
93 XLang() string |
93 XLang() string |
94 // A nested error element, if any. |
94 // A nested error element, if any. |
95 XError() *Error |
95 XError() *Error |
96 // A (non-error) nested element, if any. |
96 // A (non-error) nested element, if any. |
97 XChild() *Generic |
97 XNested() interface{} |
|
98 setNested(interface{}) |
|
99 generic() *Generic |
98 innerxml() string |
100 innerxml() string |
99 } |
|
100 |
|
101 type ExtendedStanza interface { |
|
102 Stanza |
|
103 InnerMarshal(io.Writer) os.Error |
|
104 } |
101 } |
105 |
102 |
106 // message stanza |
103 // message stanza |
107 type Message struct { |
104 type Message struct { |
108 To string `xml:"attr"` |
105 To string `xml:"attr"` |
114 Error *Error |
111 Error *Error |
115 Subject *Generic |
112 Subject *Generic |
116 Body *Generic |
113 Body *Generic |
117 Thread *Generic |
114 Thread *Generic |
118 Any *Generic |
115 Any *Generic |
|
116 Nested interface{} |
119 } |
117 } |
120 var _ xml.Marshaler = &Message{} |
118 var _ xml.Marshaler = &Message{} |
121 var _ Stanza = &Message{} |
119 var _ Stanza = &Message{} |
122 var _ ExtendedStanza = &Message{} |
|
123 |
120 |
124 // presence stanza |
121 // presence stanza |
125 type Presence struct { |
122 type Presence struct { |
126 To string `xml:"attr"` |
123 To string `xml:"attr"` |
127 From string `xml:"attr"` |
124 From string `xml:"attr"` |
147 Type string `xml:"attr"` |
144 Type string `xml:"attr"` |
148 Lang string `xml:"attr"` |
145 Lang string `xml:"attr"` |
149 Innerxml string `xml:"innerxml"` |
146 Innerxml string `xml:"innerxml"` |
150 Error *Error |
147 Error *Error |
151 Any *Generic |
148 Any *Generic |
|
149 Nested interface{} |
152 } |
150 } |
153 var _ xml.Marshaler = &Iq{} |
151 var _ xml.Marshaler = &Iq{} |
154 var _ Stanza = &Iq{} |
152 var _ Stanza = &Iq{} |
155 |
153 |
156 // Describes an XMPP stanza error. See RFC 3920, Section 9.3. |
154 // Describes an XMPP stanza error. See RFC 3920, Section 9.3. |
293 } |
291 } |
294 if st.XLang() != "" { |
292 if st.XLang() != "" { |
295 writeField(buf, "xml:lang", st.XLang()) |
293 writeField(buf, "xml:lang", st.XLang()) |
296 } |
294 } |
297 buf.WriteString(">") |
295 buf.WriteString(">") |
298 if ext, ok := st.(ExtendedStanza) ; ok { |
296 |
299 if st.XError() != nil { |
297 if st.XNested() != nil { |
300 bytes, _ := st.XError().MarshalXML() |
298 xml.Marshal(buf, st.XNested()) |
301 buf.WriteString(string(bytes)) |
299 } else if st.generic() != nil { |
302 } |
300 xml.Marshal(buf, st.generic()) |
303 err := ext.InnerMarshal(buf) |
301 } else if st.innerxml() != "" { |
304 if err != nil { |
302 buf.WriteString(st.innerxml()) |
305 return nil, err |
303 } |
306 } |
304 |
307 } else { |
|
308 inner := st.innerxml() |
|
309 if inner == "" { |
|
310 xml.Marshal(buf, st.XChild()) |
|
311 } else { |
|
312 buf.WriteString(st.innerxml()) |
|
313 } |
|
314 } |
|
315 buf.WriteString("</") |
305 buf.WriteString("</") |
316 buf.WriteString(st.XName()) |
306 buf.WriteString(st.XName()) |
317 buf.WriteString(">") |
307 buf.WriteString(">") |
318 return buf.Bytes(), nil |
308 return buf.Bytes(), nil |
319 } |
309 } |