xmpp/structs.go
author Chris Jones <christian.jones@sri.com>
Thu, 20 Feb 2014 15:55:19 -0700
changeset 184 ce49140fe60b
parent 180 3010996c1928
permissions -rw-r--r--
Added support for SASL PLAIN, from "Ildar Hizbulin" <hizel@vyborg.ru>.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     1
package xmpp
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     2
1
a01e06faf0db Added code to look up SRV records and open a TCP connection.
Chris Jones <chris@cjones.org>
parents: 0
diff changeset
     3
// This file contains data structures.
a01e06faf0db Added code to look up SRV records and open a TCP connection.
Chris Jones <chris@cjones.org>
parents: 0
diff changeset
     4
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     5
import (
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     6
	"bytes"
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
     7
	"encoding/xml"
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     8
	"fmt"
163
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 158
diff changeset
     9
	"log"
128
8342afcffc92 Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents: 126
diff changeset
    10
	"reflect"
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
    11
	"strings"
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    12
)
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    13
163
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 158
diff changeset
    14
// BUG(cjyar): Doesn't use stringprep. Could try the implementation at
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 158
diff changeset
    15
// "code.google.com/p/go-idn/src/stringprep"
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 158
diff changeset
    16
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    17
// JID represents an entity that can communicate with other
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    18
// entities. It looks like node@domain/resource. Node and resource are
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    19
// sometimes optional.
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    20
type JID string
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    21
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    22
// XMPP's <stream:stream> XML element
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
    23
type stream struct {
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    24
	XMLName xml.Name `xml:"stream=http://etherx.jabber.org/streams stream"`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    25
	To      string   `xml:"to,attr"`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    26
	From    string   `xml:"from,attr"`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    27
	Id      string   `xml:"id,attr"`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    28
	Lang    string   `xml:"http://www.w3.org/XML/1998/namespace lang,attr"`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    29
	Version string   `xml:"version,attr"`
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    30
}
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    31
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
    32
var _ fmt.Stringer = &stream{}
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    33
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
    34
// <stream:error>
31
1dc47df5c99f Made streamError non-public, and made a first attempt at a stream
Chris Jones <chris@cjones.org>
parents: 28
diff changeset
    35
type streamError struct {
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    36
	XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"`
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    37
	Any     Generic  `xml:",any"`
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    38
	Text    *errText
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    39
}
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    40
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    41
type errText struct {
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    42
	XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams text"`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
    43
	Lang    string   `xml:"http://www.w3.org/XML/1998/namespace lang,attr"`
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    44
	Text    string   `xml:",chardata"`
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    45
}
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    46
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    47
type Features struct {
102
872e936f9f3f Reworked the logging again, and also added namespaces to a couple of fields on Features.
Chris Jones <christian.jones@sri.com>
parents: 100
diff changeset
    48
	Starttls   *starttls `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"`
872e936f9f3f Reworked the logging again, and also added namespaces to a couple of fields on Features.
Chris Jones <christian.jones@sri.com>
parents: 100
diff changeset
    49
	Mechanisms mechs     `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    50
	Bind       *bindIq
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    51
	Session    *Generic
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    52
	Any        *Generic
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    53
}
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    54
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    55
type starttls struct {
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    56
	XMLName  xml.Name
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    57
	Required *string
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    58
}
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    59
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    60
type mechs struct {
107
3a01bd8e3f8c Fixed up some more attribute labels.
Chris Jones <christian.jones@sri.com>
parents: 105
diff changeset
    61
	Mechanism []string `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanism"`
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    62
}
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    63
11
48be1ae93fd4 Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents: 10
diff changeset
    64
type auth struct {
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    65
	XMLName   xml.Name
107
3a01bd8e3f8c Fixed up some more attribute labels.
Chris Jones <christian.jones@sri.com>
parents: 105
diff changeset
    66
	Chardata  string `xml:",chardata"`
108
8ec06aff386e Another little XML tag tweak.
Chris Jones <chris@cjones.org>
parents: 107
diff changeset
    67
	Mechanism string `xml:"mechanism,attr,omitempty"`
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    68
	Any       *Generic
11
48be1ae93fd4 Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents: 10
diff changeset
    69
}
48be1ae93fd4 Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents: 10
diff changeset
    70
112
bd56fb741f69 Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 111
diff changeset
    71
type Stanza interface {
111
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
    72
	GetHeader() *Header
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
    73
}
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
    74
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    75
// One of the three core XMPP stanza types: iq, message, presence. See
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    76
// RFC3920, section 9.
111
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
    77
type Header struct {
180
3010996c1928 Changed the type of structure fields which hold JIDs from string to JID.
Chris Jones <chris@cjones.org>
parents: 179
diff changeset
    78
	To       JID    `xml:"to,attr,omitempty"`
3010996c1928 Changed the type of structure fields which hold JIDs from string to JID.
Chris Jones <chris@cjones.org>
parents: 179
diff changeset
    79
	From     JID    `xml:"from,attr,omitempty"`
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    80
	Id       string `xml:"id,attr,omitempty"`
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    81
	Type     string `xml:"type,attr,omitempty"`
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    82
	Lang     string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    83
	Innerxml string `xml:",innerxml"`
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    84
	Error    *Error
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
    85
	Nested   []interface{}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
    86
}
110
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
    87
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
    88
// message stanza
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
    89
type Message struct {
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    90
	XMLName xml.Name `xml:"jabber:client message"`
111
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
    91
	Header
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    92
	Subject []Text `xml:"jabber:client subject"`
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    93
	Body    []Text `xml:"jabber:client body"`
172
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
    94
	Thread  *Data  `xml:"jabber:client thread"`
110
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
    95
}
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
    96
112
bd56fb741f69 Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 111
diff changeset
    97
var _ Stanza = &Message{}
110
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
    98
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
    99
// presence stanza
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
   100
type Presence struct {
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   101
	XMLName xml.Name `xml:"presence"`
111
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   102
	Header
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   103
	Show     *Data  `xml:"jabber:client show"`
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   104
	Status   []Text `xml:"jabber:client status"`
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   105
	Priority *Data  `xml:"jabber:client priority"`
110
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
   106
}
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   107
112
bd56fb741f69 Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 111
diff changeset
   108
var _ Stanza = &Presence{}
110
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
   109
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
   110
// iq stanza
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
   111
type Iq struct {
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   112
	XMLName xml.Name `xml:"iq"`
111
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   113
	Header
110
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 108
diff changeset
   114
}
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   115
112
bd56fb741f69 Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 111
diff changeset
   116
var _ Stanza = &Iq{}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   117
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   118
// Describes an XMPP stanza error. See RFC 3920, Section 9.3.
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   119
type Error struct {
43
82e90aa25dad Making a little more use of XMLName for marshaling instead of having a
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   120
	XMLName xml.Name `xml:"error"`
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   121
	// The error type attribute.
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   122
	Type string `xml:"type,attr"`
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   123
	// Any nested element, if present.
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   124
	Any *Generic
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   125
}
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   126
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   127
var _ error = &Error{}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   128
41
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   129
// Used for resource binding as a nested element inside <iq/>.
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   130
type bindIq struct {
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
   131
	XMLName  xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
   132
	Resource *string  `xml:"resource"`
180
3010996c1928 Changed the type of structure fields which hold JIDs from string to JID.
Chris Jones <chris@cjones.org>
parents: 179
diff changeset
   133
	Jid      *JID     `xml:"jid"`
41
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   134
}
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   135
172
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   136
// Holds human-readable text, with an optional language
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   137
// specification. Generally multiple instances of these can be found
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   138
// together, allowing the software to choose which language to present
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   139
// to the user.
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   140
type Text struct {
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   141
	XMLName  xml.Name
172
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   142
	Lang     string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   143
	Chardata string `xml:",chardata"`
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   144
}
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   145
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   146
// Non-human-readable content of some sort, used by the protocol.
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   147
type Data struct {
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   148
	XMLName  xml.Name
172
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   149
	Chardata string `xml:",chardata"`
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   150
}
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 171
diff changeset
   151
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   152
// Holds an XML element not described by the more specific types.
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   153
type Generic struct {
72
Chris Jones <christian.jones@sri.com>
parents: 61
diff changeset
   154
	XMLName  xml.Name
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   155
	Any      *Generic `xml:",any"`
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   156
	Chardata string   `xml:",chardata"`
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   157
}
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   158
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   159
var _ fmt.Stringer = &Generic{}
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   160
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   161
func (j JID) Node() string {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   162
	at := strings.Index(string(j), "@")
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   163
	if at == -1 {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   164
		return ""
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   165
	}
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   166
	return string(j[:at])
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   167
}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   168
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   169
func (j JID) Domain() string {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   170
	at := strings.Index(string(j), "@")
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   171
	slash := strings.LastIndex(string(j), "/")
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   172
	if slash == -1 {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   173
		slash = len(j)
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   174
	}
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   175
	return string(j[at+1 : slash])
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   176
}
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   177
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   178
func (j JID) Resource() string {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   179
	slash := strings.LastIndex(string(j), "/")
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   180
	if slash == -1 {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   181
		return ""
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   182
	}
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
   183
	return string(j[slash+1:])
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   184
}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   185
179
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   186
// Returns the bare JID, which is the JID without the resource part.
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   187
func (j JID) Bare() JID {
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   188
	node := j.Node()
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   189
	if node == "" {
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   190
		return JID(j.Domain())
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   191
	}
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   192
	return JID(fmt.Sprintf("%s@%s", node, j.Domain()))
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   193
}
4477c9f31f43 Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Chris Jones <chris@cjones.org>
parents: 178
diff changeset
   194
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
   195
func (s *stream) String() string {
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   196
	var buf bytes.Buffer
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   197
	buf.WriteString(`<stream:stream xmlns="`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   198
	buf.WriteString(NsClient)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   199
	buf.WriteString(`" xmlns:stream="`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   200
	buf.WriteString(NsStream)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   201
	buf.WriteString(`"`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   202
	if s.To != "" {
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   203
		buf.WriteString(` to="`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   204
		xml.Escape(&buf, []byte(s.To))
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   205
		buf.WriteString(`"`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   206
	}
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   207
	if s.From != "" {
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   208
		buf.WriteString(` from="`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   209
		xml.Escape(&buf, []byte(s.From))
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   210
		buf.WriteString(`"`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   211
	}
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   212
	if s.Id != "" {
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   213
		buf.WriteString(` id="`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   214
		xml.Escape(&buf, []byte(s.Id))
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   215
		buf.WriteString(`"`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   216
	}
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   217
	if s.Lang != "" {
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   218
		buf.WriteString(` xml:lang="`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   219
		xml.Escape(&buf, []byte(s.Lang))
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   220
		buf.WriteString(`"`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   221
	}
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   222
	if s.Version != "" {
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   223
		buf.WriteString(` version="`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   224
		xml.Escape(&buf, []byte(s.Version))
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   225
		buf.WriteString(`"`)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   226
	}
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   227
	buf.WriteString(">")
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   228
	return buf.String()
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   229
}
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   230
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   231
func parseStream(se xml.StartElement) (*stream, error) {
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
   232
	s := &stream{}
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   233
	for _, attr := range se.Attr {
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   234
		switch strings.ToLower(attr.Name.Local) {
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   235
		case "to":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   236
			s.To = attr.Value
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   237
		case "from":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   238
			s.From = attr.Value
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   239
		case "id":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   240
			s.Id = attr.Value
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   241
		case "lang":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   242
			s.Lang = attr.Value
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   243
		case "version":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   244
			s.Version = attr.Value
5
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   245
		}
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   246
	}
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   247
	return s, nil
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   248
}
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   249
111
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   250
func (iq *Iq) GetHeader() *Header {
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   251
	return &iq.Header
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   252
}
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   253
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   254
func (m *Message) GetHeader() *Header {
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   255
	return &m.Header
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   256
}
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   257
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   258
func (p *Presence) GetHeader() *Header {
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   259
	return &p.Header
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   260
}
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
   261
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   262
func (u *Generic) String() string {
51
1af366d10d32 Nil checks and a greatly simplified filter manager which is less buggy.
Chris Jones <chris@cjones.org>
parents: 49
diff changeset
   263
	if u == nil {
1af366d10d32 Nil checks and a greatly simplified filter manager which is less buggy.
Chris Jones <chris@cjones.org>
parents: 49
diff changeset
   264
		return "nil"
1af366d10d32 Nil checks and a greatly simplified filter manager which is less buggy.
Chris Jones <chris@cjones.org>
parents: 49
diff changeset
   265
	}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   266
	var sub string
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   267
	if u.Any != nil {
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   268
		sub = u.Any.String()
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   269
	}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   270
	return fmt.Sprintf("<%s %s>%s%s</%s %s>", u.XMLName.Space,
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   271
		u.XMLName.Local, sub, u.Chardata, u.XMLName.Space,
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
   272
		u.XMLName.Local)
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
   273
}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   274
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   275
func (er *Error) Error() string {
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   276
	buf, err := xml.Marshal(er)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   277
	if err != nil {
163
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 158
diff changeset
   278
		log.Println("double bad error: couldn't marshal error")
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   279
		return "unreadable error"
33
571713f49494 Added roster retrieval to StartSession().
Chris Jones <chris@cjones.org>
parents: 32
diff changeset
   280
	}
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 88
diff changeset
   281
	return string(buf)
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   282
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   283
128
8342afcffc92 Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents: 126
diff changeset
   284
var bindExt Extension = Extension{}
60
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 59
diff changeset
   285
128
8342afcffc92 Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents: 126
diff changeset
   286
func init() {
158
2d948fcbb5d7 Renamed Extension.StanzaHandlers to StanzaTypes, and updated the doc comment.
Chris Jones <chris@cjones.org>
parents: 142
diff changeset
   287
	bindExt.StanzaTypes = make(map[xml.Name]reflect.Type)
128
8342afcffc92 Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents: 126
diff changeset
   288
	bName := xml.Name{Space: NsBind, Local: "bind"}
158
2d948fcbb5d7 Renamed Extension.StanzaHandlers to StanzaTypes, and updated the doc comment.
Chris Jones <chris@cjones.org>
parents: 142
diff changeset
   289
	bindExt.StanzaTypes[bName] = reflect.TypeOf(bindIq{})
41
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   290
}