74 Chardata string `xml:"chardata"` |
74 Chardata string `xml:"chardata"` |
75 Mechanism string `xml:"attr"` |
75 Mechanism string `xml:"attr"` |
76 Any *Generic |
76 Any *Generic |
77 } |
77 } |
78 |
78 |
79 // BUG(cjyar) Change XTo() to GetTo(), etc. |
|
80 |
|
81 // One of the three core XMPP stanza types: iq, message, presence. See |
79 // One of the three core XMPP stanza types: iq, message, presence. See |
82 // RFC3920, section 9. |
80 // RFC3920, section 9. |
83 type Stanza interface { |
81 type Stanza interface { |
84 // Returns "iq", "message", or "presence". |
82 // Returns "iq", "message", or "presence". |
85 XName() string |
83 GetName() string |
86 // The to attribute. |
84 // The to attribute. |
87 XTo() string |
85 GetTo() string |
88 // The from attribute. |
86 // The from attribute. |
89 XFrom() string |
87 GetFrom() string |
90 // The id attribute. |
88 // The id attribute. |
91 XId() string |
89 GetId() string |
92 // The type attribute. |
90 // The type attribute. |
93 XType() string |
91 GetType() string |
94 // The xml:lang attribute. |
92 // The xml:lang attribute. |
95 XLang() string |
93 GetLang() string |
96 // A nested error element, if any. |
94 // A nested error element, if any. |
97 XError() *Error |
95 GetError() *Error |
98 // A (non-error) nested element, if any. |
96 // A (non-error) nested element, if any. |
99 XNested() interface{} |
97 GetNested() interface{} |
100 setNested(interface{}) |
98 setNested(interface{}) |
101 generic() *Generic |
99 generic() *Generic |
102 innerxml() string |
100 innerxml() string |
103 } |
101 } |
104 |
102 |
286 } |
284 } |
287 |
285 |
288 func marshalXML(st Stanza) ([]byte, os.Error) { |
286 func marshalXML(st Stanza) ([]byte, os.Error) { |
289 buf := bytes.NewBuffer(nil) |
287 buf := bytes.NewBuffer(nil) |
290 buf.WriteString("<") |
288 buf.WriteString("<") |
291 buf.WriteString(st.XName()) |
289 buf.WriteString(st.GetName()) |
292 if st.XTo() != "" { |
290 if st.GetTo() != "" { |
293 writeField(buf, "to", st.XTo()) |
291 writeField(buf, "to", st.GetTo()) |
294 } |
292 } |
295 if st.XFrom() != "" { |
293 if st.GetFrom() != "" { |
296 writeField(buf, "from", st.XFrom()) |
294 writeField(buf, "from", st.GetFrom()) |
297 } |
295 } |
298 if st.XId() != "" { |
296 if st.GetId() != "" { |
299 writeField(buf, "id", st.XId()) |
297 writeField(buf, "id", st.GetId()) |
300 } |
298 } |
301 if st.XType() != "" { |
299 if st.GetType() != "" { |
302 writeField(buf, "type", st.XType()) |
300 writeField(buf, "type", st.GetType()) |
303 } |
301 } |
304 if st.XLang() != "" { |
302 if st.GetLang() != "" { |
305 writeField(buf, "xml:lang", st.XLang()) |
303 writeField(buf, "xml:lang", st.GetLang()) |
306 } |
304 } |
307 buf.WriteString(">") |
305 buf.WriteString(">") |
308 |
306 |
309 if st.XNested() != nil { |
307 if st.GetNested() != nil { |
310 xml.Marshal(buf, st.XNested()) |
308 xml.Marshal(buf, st.GetNested()) |
311 } else if st.generic() != nil { |
309 } else if st.generic() != nil { |
312 xml.Marshal(buf, st.generic()) |
310 xml.Marshal(buf, st.generic()) |
313 } else if st.innerxml() != "" { |
311 } else if st.innerxml() != "" { |
314 buf.WriteString(st.innerxml()) |
312 buf.WriteString(st.innerxml()) |
315 } |
313 } |
316 |
314 |
317 buf.WriteString("</") |
315 buf.WriteString("</") |
318 buf.WriteString(st.XName()) |
316 buf.WriteString(st.GetName()) |
319 buf.WriteString(">") |
317 buf.WriteString(">") |
320 return buf.Bytes(), nil |
318 return buf.Bytes(), nil |
321 } |
319 } |
322 |
320 |
323 // BUG(cjyar) We can probably eliminate this if we add an XMLName |
321 // BUG(cjyar) We can probably eliminate this if we add an XMLName |
337 func (er *Error) String() string { |
335 func (er *Error) String() string { |
338 bytes, _ := er.MarshalXML() |
336 bytes, _ := er.MarshalXML() |
339 return string(bytes) |
337 return string(bytes) |
340 } |
338 } |
341 |
339 |
342 func (m *Message) XName() string { |
340 func (m *Message) GetName() string { |
343 return "message" |
341 return "message" |
344 } |
342 } |
345 |
343 |
346 func (m *Message) XTo() string { |
344 func (m *Message) GetTo() string { |
347 return m.To |
345 return m.To |
348 } |
346 } |
349 |
347 |
350 func (m *Message) XFrom() string { |
348 func (m *Message) GetFrom() string { |
351 return m.From |
349 return m.From |
352 } |
350 } |
353 |
351 |
354 func (m *Message) XId() string { |
352 func (m *Message) GetId() string { |
355 return m.Id |
353 return m.Id |
356 } |
354 } |
357 |
355 |
358 func (m *Message) XType() string { |
356 func (m *Message) GetType() string { |
359 return m.Type |
357 return m.Type |
360 } |
358 } |
361 |
359 |
362 func (m *Message) XLang() string { |
360 func (m *Message) GetLang() string { |
363 return m.Lang |
361 return m.Lang |
364 } |
362 } |
365 |
363 |
366 func (m *Message) XError() *Error { |
364 func (m *Message) GetError() *Error { |
367 return m.Error |
365 return m.Error |
368 } |
366 } |
369 |
367 |
370 func (m *Message) XNested() interface{} { |
368 func (m *Message) GetNested() interface{} { |
371 return m.Nested |
369 return m.Nested |
372 } |
370 } |
373 |
371 |
374 func (m *Message) setNested(n interface{}) { |
372 func (m *Message) setNested(n interface{}) { |
375 m.Nested = n |
373 m.Nested = n |
401 return err |
399 return err |
402 } |
400 } |
403 return nil |
401 return nil |
404 } |
402 } |
405 |
403 |
406 func (p *Presence) XName() string { |
404 func (p *Presence) GetName() string { |
407 return "presence" |
405 return "presence" |
408 } |
406 } |
409 |
407 |
410 func (p *Presence) XTo() string { |
408 func (p *Presence) GetTo() string { |
411 return p.To |
409 return p.To |
412 } |
410 } |
413 |
411 |
414 func (p *Presence) XFrom() string { |
412 func (p *Presence) GetFrom() string { |
415 return p.From |
413 return p.From |
416 } |
414 } |
417 |
415 |
418 func (p *Presence) XId() string { |
416 func (p *Presence) GetId() string { |
419 return p.Id |
417 return p.Id |
420 } |
418 } |
421 |
419 |
422 func (p *Presence) XType() string { |
420 func (p *Presence) GetType() string { |
423 return p.Type |
421 return p.Type |
424 } |
422 } |
425 |
423 |
426 func (p *Presence) XLang() string { |
424 func (p *Presence) GetLang() string { |
427 return p.Lang |
425 return p.Lang |
428 } |
426 } |
429 |
427 |
430 func (p *Presence) XError() *Error { |
428 func (p *Presence) GetError() *Error { |
431 return p.Error |
429 return p.Error |
432 } |
430 } |
433 |
431 |
434 func (p *Presence) XNested() interface{} { |
432 func (p *Presence) GetNested() interface{} { |
435 return p.Nested |
433 return p.Nested |
436 } |
434 } |
437 |
435 |
438 func (p *Presence) setNested(n interface{}) { |
436 func (p *Presence) setNested(n interface{}) { |
439 p.Nested = n |
437 p.Nested = n |
465 return err |
463 return err |
466 } |
464 } |
467 return nil |
465 return nil |
468 } |
466 } |
469 |
467 |
470 func (iq *Iq) XName() string { |
468 func (iq *Iq) GetName() string { |
471 return "iq" |
469 return "iq" |
472 } |
470 } |
473 |
471 |
474 func (iq *Iq) XTo() string { |
472 func (iq *Iq) GetTo() string { |
475 return iq.To |
473 return iq.To |
476 } |
474 } |
477 |
475 |
478 func (iq *Iq) XFrom() string { |
476 func (iq *Iq) GetFrom() string { |
479 return iq.From |
477 return iq.From |
480 } |
478 } |
481 |
479 |
482 func (iq *Iq) XId() string { |
480 func (iq *Iq) GetId() string { |
483 return iq.Id |
481 return iq.Id |
484 } |
482 } |
485 |
483 |
486 func (iq *Iq) XType() string { |
484 func (iq *Iq) GetType() string { |
487 return iq.Type |
485 return iq.Type |
488 } |
486 } |
489 |
487 |
490 func (iq *Iq) XLang() string { |
488 func (iq *Iq) GetLang() string { |
491 return iq.Lang |
489 return iq.Lang |
492 } |
490 } |
493 |
491 |
494 func (iq *Iq) XError() *Error { |
492 func (iq *Iq) GetError() *Error { |
495 return iq.Error |
493 return iq.Error |
496 } |
494 } |
497 |
495 |
498 func (iq *Iq) XNested() interface{} { |
496 func (iq *Iq) GetNested() interface{} { |
499 return iq.Nested |
497 return iq.Nested |
500 } |
498 } |
501 |
499 |
502 func (iq *Iq) setNested(n interface{}) { |
500 func (iq *Iq) setNested(n interface{}) { |
503 iq.Nested = n |
501 iq.Nested = n |