structs.go
changeset 21 8f6ae5cfc9b9
parent 20 e119444a1119
child 22 d6b7b4cbf50d
equal deleted inserted replaced
20:e119444a1119 21:8f6ae5cfc9b9
    64 
    64 
    65 // BUG(cjyar) Store this in Client and make it available to the app.
    65 // BUG(cjyar) Store this in Client and make it available to the app.
    66 type Features struct {
    66 type Features struct {
    67 	Starttls *starttls
    67 	Starttls *starttls
    68 	Mechanisms mechs
    68 	Mechanisms mechs
    69 	Bind *Unrecognized
    69 	Bind *Generic
    70 }
    70 }
    71 
    71 
    72 type starttls struct {
    72 type starttls struct {
    73 	XMLName xml.Name
    73 	XMLName xml.Name
    74 	Required *string
    74 	Required *string
    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,
   342 
   341 
   343 func (m *Message) XError() *Error {
   342 func (m *Message) XError() *Error {
   344 	return m.Error
   343 	return m.Error
   345 }
   344 }
   346 
   345 
   347 func (m *Message) XChild() *Unrecognized {
   346 func (m *Message) XChild() *Generic {
   348 	return m.Any
   347 	return m.Any
   349 }
   348 }
   350 
   349 
   351 func (m *Message) MarshalXML() ([]byte, os.Error) {
   350 func (m *Message) MarshalXML() ([]byte, os.Error) {
   352 	return marshalXML(m)
   351 	return marshalXML(m)
   378 
   377 
   379 func (p *Presence) XError() *Error {
   378 func (p *Presence) XError() *Error {
   380 	return p.Error
   379 	return p.Error
   381 }
   380 }
   382 
   381 
   383 func (p *Presence) XChild() *Unrecognized {
   382 func (p *Presence) XChild() *Generic {
   384 	return p.Any
   383 	return p.Any
   385 }
   384 }
   386 
   385 
   387 func (p *Presence) MarshalXML() ([]byte, os.Error) {
   386 func (p *Presence) MarshalXML() ([]byte, os.Error) {
   388 	return marshalXML(p)
   387 	return marshalXML(p)
   414 
   413 
   415 func (iq *Iq) XError() *Error {
   414 func (iq *Iq) XError() *Error {
   416 	return iq.Error
   415 	return iq.Error
   417 }
   416 }
   418 
   417 
   419 func (iq *Iq) XChild() *Unrecognized {
   418 func (iq *Iq) XChild() *Generic {
   420 	return iq.Any
   419 	return iq.Any
   421 }
   420 }
   422 
   421 
   423 func (iq *Iq) MarshalXML() ([]byte, os.Error) {
   422 func (iq *Iq) MarshalXML() ([]byte, os.Error) {
   424 	return marshalXML(iq)
   423 	return marshalXML(iq)