80 |
80 |
81 type auth struct { |
81 type auth struct { |
82 XMLName xml.Name |
82 XMLName xml.Name |
83 Chardata string `xml:"chardata"` |
83 Chardata string `xml:"chardata"` |
84 Mechanism string `xml:"attr"` |
84 Mechanism string `xml:"attr"` |
85 Any *Unrecognized |
85 Any *Generic |
86 } |
86 } |
87 |
87 |
88 // One of the three core XMPP stanza types: iq, message, presence. See |
88 // One of the three core XMPP stanza types: iq, message, presence. See |
89 // RFC3920, section 9. |
89 // RFC3920, section 9. |
90 type Stanza interface { |
90 type Stanza interface { |
101 // The xml:lang attribute. |
101 // The xml:lang attribute. |
102 XLang() string |
102 XLang() string |
103 // A nested error element, if any. |
103 // A nested error element, if any. |
104 XError() *Error |
104 XError() *Error |
105 // A (non-error) nested element, if any. |
105 // A (non-error) nested element, if any. |
106 XChild() *Unrecognized |
106 XChild() *Generic |
107 } |
107 } |
108 |
108 |
109 // message stanza |
109 // message stanza |
110 type Message struct { |
110 type Message struct { |
111 To string `xml:"attr"` |
111 To string `xml:"attr"` |
112 From string `xml:"attr"` |
112 From string `xml:"attr"` |
113 Id string `xml:"attr"` |
113 Id string `xml:"attr"` |
114 Type string `xml:"attr"` |
114 Type string `xml:"attr"` |
115 Lang string `xml:"attr"` |
115 Lang string `xml:"attr"` |
116 Error *Error |
116 Error *Error |
117 Any *Unrecognized |
117 Any *Generic |
118 } |
118 } |
119 var _ xml.Marshaler = &Message{} |
119 var _ xml.Marshaler = &Message{} |
120 var _ Stanza = &Message{} |
120 var _ Stanza = &Message{} |
121 |
121 |
122 // presence stanza |
122 // presence stanza |
125 From string `xml:"attr"` |
125 From string `xml:"attr"` |
126 Id string `xml:"attr"` |
126 Id string `xml:"attr"` |
127 Type string `xml:"attr"` |
127 Type string `xml:"attr"` |
128 Lang string `xml:"attr"` |
128 Lang string `xml:"attr"` |
129 Error *Error |
129 Error *Error |
130 Any *Unrecognized |
130 Any *Generic |
131 } |
131 } |
132 var _ xml.Marshaler = &Presence{} |
132 var _ xml.Marshaler = &Presence{} |
133 var _ Stanza = &Presence{} |
133 var _ Stanza = &Presence{} |
134 |
134 |
135 // iq stanza |
135 // iq stanza |
138 From string `xml:"attr"` |
138 From string `xml:"attr"` |
139 Id string `xml:"attr"` |
139 Id string `xml:"attr"` |
140 Type string `xml:"attr"` |
140 Type string `xml:"attr"` |
141 Lang string `xml:"attr"` |
141 Lang string `xml:"attr"` |
142 Error *Error |
142 Error *Error |
143 Any *Unrecognized |
143 Any *Generic |
144 } |
144 } |
145 var _ xml.Marshaler = &Iq{} |
145 var _ xml.Marshaler = &Iq{} |
146 var _ Stanza = &Iq{} |
146 var _ Stanza = &Iq{} |
147 |
147 |
148 // Describes an XMPP stanza error. See RFC 3920, Section 9.3. |
148 // Describes an XMPP stanza error. See RFC 3920, Section 9.3. |
149 type Error struct { |
149 type Error struct { |
150 // The error type attribute. |
150 // The error type attribute. |
151 Type string `xml:"attr"` |
151 Type string `xml:"attr"` |
152 // Any nested element, if present. |
152 // Any nested element, if present. |
153 Any *Unrecognized |
153 Any *Generic |
154 } |
154 } |
155 var _ xml.Marshaler = &Error{} |
155 var _ xml.Marshaler = &Error{} |
156 |
156 |
157 // Holds an XML element not described by the more specific types. |
157 // Holds an XML element not described by the more specific types. |
158 // BUG(cjyar) Rename this to something like Generic. |
158 type Generic struct { |
159 type Unrecognized struct { |
|
160 XMLName xml.Name |
159 XMLName xml.Name |
161 Any *Unrecognized |
160 Any *Generic |
162 Chardata string `xml:"chardata"` |
161 Chardata string `xml:"chardata"` |
163 } |
162 } |
164 var _ fmt.Stringer = &Unrecognized{} |
163 var _ fmt.Stringer = &Generic{} |
165 |
164 |
166 func (jid *JID) String() string { |
165 func (jid *JID) String() string { |
167 result := jid.Domain |
166 result := jid.Domain |
168 if jid.Node != nil { |
167 if jid.Node != nil { |
169 result = *jid.Node + "@" + result |
168 result = *jid.Node + "@" + result |
259 xml.Escape(w, []byte(value)) |
258 xml.Escape(w, []byte(value)) |
260 io.WriteString(w, `"`) |
259 io.WriteString(w, `"`) |
261 } |
260 } |
262 } |
261 } |
263 |
262 |
264 func (u *Unrecognized) String() string { |
263 func (u *Generic) String() string { |
265 var sub string |
264 var sub string |
266 if u.Any != nil { |
265 if u.Any != nil { |
267 sub = u.Any.String() |
266 sub = u.Any.String() |
268 } |
267 } |
269 return fmt.Sprintf("<%s %s>%s%s</%s %s>", u.XMLName.Space, |
268 return fmt.Sprintf("<%s %s>%s%s</%s %s>", u.XMLName.Space, |