author | Chris Jones <chris@cjones.org> |
Thu, 24 May 2012 23:27:31 -0600 | |
branch | go.weekly.2012-01-15 |
changeset 94 | 0ef947611eec |
parent 93 | fbd51fa6b7ea |
permissions | -rw-r--r-- |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
1 |
// Copyright 2011 The Go Authors. All rights reserved. |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
2 |
// Use of this source code is governed by a BSD-style |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
3 |
// license that can be found in the LICENSE file. |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
4 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
5 |
package xmpp |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
6 |
|
1
a01e06faf0db
Added code to look up SRV records and open a TCP connection.
Chris Jones <chris@cjones.org>
parents:
0
diff
changeset
|
7 |
// 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
|
8 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
9 |
import ( |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
10 |
"bytes" |
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
11 |
"encoding/xml" |
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
12 |
"errors" |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
13 |
"flag" |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
14 |
"fmt" |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
15 |
"io" |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
16 |
"regexp" |
5
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
17 |
"strings" |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
18 |
) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
19 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
20 |
// 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
|
21 |
// 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
|
22 |
// sometimes optional. |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
23 |
type JID struct { |
72 | 24 |
Node string |
25 |
Domain string |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
26 |
Resource string |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
27 |
} |
72 | 28 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
29 |
var _ fmt.Stringer = &JID{} |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
30 |
var _ flag.Value = &JID{} |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
31 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
32 |
// XMPP's <stream:stream> XML element |
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
33 |
type stream struct { |
94 | 34 |
XMLName xml.Name `xml:"stream http://etherx.jabber.org/streams"` |
35 |
To string `xml:"to,attr,omitempty"` |
|
36 |
From string `xml:"from,attr,omitempty"` |
|
37 |
Id string `xml:"id,attr,omitempty"` |
|
38 |
Lang string `xml:"lang,attr,omitempty"` |
|
39 |
Version string `xml:"version,attr,omitempty"` |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
40 |
} |
72 | 41 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
42 |
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
|
43 |
|
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
44 |
// <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
|
45 |
type streamError struct { |
94 | 46 |
XMLName xml.Name `xml:"stream:error"` |
93 | 47 |
Any Generic `xml:",any"` |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
48 |
Text *errText `xml:"text"` |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
49 |
} |
72 | 50 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
51 |
type errText struct { |
93 | 52 |
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams text"` |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
53 |
Lang string `xml:"lang,attr"` |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
54 |
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
|
55 |
} |
72 | 56 |
|
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
57 |
type Features struct { |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
58 |
Starttls *starttls `xml:"starttls"` |
93 | 59 |
Mechanisms mechs `xml:"mechanisms"` |
60 |
Bind *bindIq `xml:"bind"` |
|
61 |
Session *Generic `xml:"session"` |
|
62 |
Any *Generic `xml:",any"` |
|
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
63 |
} |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
64 |
|
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
65 |
type starttls struct { |
72 | 66 |
XMLName xml.Name |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
67 |
Required *string `xml:"required"` |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
68 |
} |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
69 |
|
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
70 |
type mechs struct { |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
71 |
Mechanism []string `xml:"mechanism"` |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
72 |
} |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
73 |
|
11
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
74 |
type auth struct { |
72 | 75 |
XMLName xml.Name |
93 | 76 |
Chardata string `xml:",chardata"` |
77 |
Mechanism string `xml:"mechanism,attr"` |
|
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
78 |
Any *Generic `xml:",any"` |
11
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
79 |
} |
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
80 |
|
17 | 81 |
// One of the three core XMPP stanza types: iq, message, presence. See |
82 |
// RFC3920, section 9. |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
83 |
type Stanza interface { |
17 | 84 |
// Returns "iq", "message", or "presence". |
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
85 |
GetName() string |
17 | 86 |
// The to attribute. |
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
87 |
GetTo() string |
17 | 88 |
// The from attribute. |
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
89 |
GetFrom() string |
17 | 90 |
// The id attribute. |
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
91 |
GetId() string |
17 | 92 |
// The type attribute. |
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
93 |
GetType() string |
17 | 94 |
// The xml:lang attribute. |
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
95 |
GetLang() string |
17 | 96 |
// A nested error element, if any. |
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
97 |
GetError() *Error |
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
98 |
// Zero or more (non-error) nested elements. These will be in |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
99 |
// namespaces managed by extensions. |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
100 |
GetNested() []interface{} |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
101 |
addNested(interface{}) |
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
102 |
innerxml() string |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
103 |
} |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
104 |
|
17 | 105 |
// message stanza |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
106 |
type Message struct { |
93 | 107 |
XMLName xml.Name `xml:"message"` |
108 |
To string `xml:"to,attr,omitempty"` |
|
109 |
From string `xml:"from,attr,omitempty"` |
|
110 |
Id string `xml:"id,attr,omitempty"` |
|
111 |
Type string `xml:"type,attr,omitempty"` |
|
112 |
Lang string `xml:"lang,attr,omitempty"` |
|
113 |
Innerxml string `xml:",innerxml"` |
|
114 |
Error *Error `xml:"error"` |
|
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
115 |
Subject *Generic `xml:"subject"` |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
116 |
Body *Generic `xml:"body"` |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
117 |
Thread *Generic `xml:"thread"` |
72 | 118 |
Nested []interface{} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
119 |
} |
72 | 120 |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
121 |
var _ Stanza = &Message{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
122 |
|
17 | 123 |
// presence stanza |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
124 |
type Presence struct { |
93 | 125 |
XMLName xml.Name `xml:"presence"` |
126 |
To string `xml:"to,attr,omitempty"` |
|
127 |
From string `xml:"from,attr,omitempty"` |
|
128 |
Id string `xml:"id,attr,omitempty"` |
|
129 |
Type string `xml:"type,attr,omitempty"` |
|
130 |
Lang string `xml:"lang,attr,omitempty"` |
|
131 |
Innerxml string `xml:",innerxml"` |
|
132 |
Error *Error `xml:"error"` |
|
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
133 |
Show *Generic `xml:"show"` |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
134 |
Status *Generic `xml:"status"` |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
135 |
Priority *Generic `xml:"priority"` |
72 | 136 |
Nested []interface{} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
137 |
} |
72 | 138 |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
139 |
var _ Stanza = &Presence{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
140 |
|
17 | 141 |
// iq stanza |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
142 |
type Iq struct { |
93 | 143 |
XMLName xml.Name `xml:"iq"` |
144 |
To string `xml:"to,attr,omitempty"` |
|
145 |
From string `xml:"from,attr,omitempty"` |
|
146 |
Id string `xml:"id,attr,omitempty"` |
|
147 |
Type string `xml:"type,attr,omitempty"` |
|
148 |
Lang string `xml:"xml lang,attr,omitempty"` |
|
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
149 |
Innerxml string `xml:",innerxml"` |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
150 |
Error *Error `xml:"error"` |
72 | 151 |
Nested []interface{} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
152 |
} |
72 | 153 |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
154 |
var _ Stanza = &Iq{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
155 |
|
17 | 156 |
// 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
|
157 |
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
|
158 |
XMLName xml.Name `xml:"error"` |
17 | 159 |
// The error type attribute. |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
160 |
Type string `xml:"type,attr"` |
17 | 161 |
// Any nested element, if present. |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
162 |
Any *Generic `xml:",any"` |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
163 |
} |
72 | 164 |
|
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
165 |
var _ error = &Error{} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
166 |
|
41
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
167 |
// 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
|
168 |
type bindIq struct { |
72 | 169 |
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` |
170 |
Resource *string `xml:"resource"` |
|
171 |
Jid *string `xml:"jid"` |
|
41
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
172 |
} |
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
173 |
|
17 | 174 |
// 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
|
175 |
type Generic struct { |
72 | 176 |
XMLName xml.Name |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
177 |
Any *Generic `xml:",any"` |
93 | 178 |
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
|
179 |
} |
72 | 180 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
181 |
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
|
182 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
183 |
func (jid *JID) String() string { |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
184 |
result := jid.Domain |
25
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
185 |
if jid.Node != "" { |
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
186 |
result = jid.Node + "@" + result |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
187 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
188 |
if jid.Resource != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
189 |
result = result + "/" + jid.Resource |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
190 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
191 |
return result |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
192 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
193 |
|
52 | 194 |
// Set implements flag.Value. It returns true if it successfully |
195 |
// parses the string. |
|
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
196 |
func (jid *JID) Set(val string) error { |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
197 |
r := regexp.MustCompile("^(([^@/]+)@)?([^@/]+)(/([^@/]+))?$") |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
198 |
parts := r.FindStringSubmatch(val) |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
199 |
if parts == nil { |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
200 |
return errors.New("Can't parse as JID: " + val) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
201 |
} |
25
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
202 |
jid.Node = parts[2] |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
203 |
jid.Domain = parts[3] |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
204 |
jid.Resource = parts[5] |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
205 |
return nil |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
206 |
} |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
207 |
|
93 | 208 |
func (s *stream) String() string { |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
209 |
buf := bytes.NewBuffer(nil) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
210 |
buf.WriteString("<stream:stream") |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
211 |
writeField(buf, "to", s.To) |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
212 |
writeField(buf, "from", s.From) |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
213 |
writeField(buf, "id", s.Id) |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
214 |
writeField(buf, "xml:lang", s.Lang) |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
215 |
writeField(buf, "version", s.Version) |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
216 |
buf.WriteString(">") |
93 | 217 |
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
|
218 |
} |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
219 |
|
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
220 |
func parseStream(se xml.StartElement) (*stream, error) { |
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
case "to": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
225 |
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
|
226 |
case "from": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
227 |
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
|
228 |
case "id": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
229 |
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
|
230 |
case "lang": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
231 |
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
|
232 |
case "version": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
233 |
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
|
234 |
} |
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
235 |
} |
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
236 |
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
|
237 |
} |
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
238 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
239 |
func writeField(w io.Writer, field, value string) { |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
240 |
if value != "" { |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
241 |
io.WriteString(w, " ") |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
242 |
io.WriteString(w, field) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
243 |
io.WriteString(w, `="`) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
244 |
xml.Escape(w, []byte(value)) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
245 |
io.WriteString(w, `"`) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
246 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
247 |
} |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
248 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
249 |
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
|
250 |
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
|
251 |
return "nil" |
1af366d10d32
Nil checks and a greatly simplified filter manager which is less buggy.
Chris Jones <chris@cjones.org>
parents:
49
diff
changeset
|
252 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
253 |
var sub string |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
254 |
if u.Any != nil { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
255 |
sub = u.Any.String() |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
256 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
u.XMLName.Local) |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
260 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
261 |
|
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
262 |
func (er *Error) Error() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
263 |
buf := bytes.NewBuffer(nil) |
93 | 264 |
xml.NewEncoder(buf).Encode(er) |
43
82e90aa25dad
Making a little more use of XMLName for marshaling instead of having a
Chris Jones <chris@cjones.org>
parents:
42
diff
changeset
|
265 |
return buf.String() |
28 | 266 |
} |
267 |
||
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
268 |
func (m *Message) GetName() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
269 |
return "message" |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
270 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
271 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
272 |
func (m *Message) GetTo() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
273 |
return m.To |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
274 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
275 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
276 |
func (m *Message) GetFrom() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
277 |
return m.From |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
278 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
279 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
280 |
func (m *Message) GetId() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
281 |
return m.Id |
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 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
284 |
func (m *Message) GetType() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
285 |
return m.Type |
72 | 286 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
287 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
288 |
func (m *Message) GetLang() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
289 |
return m.Lang |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
290 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
291 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
292 |
func (m *Message) GetError() *Error { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
293 |
return m.Error |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
294 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
295 |
|
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
296 |
func (m *Message) GetNested() []interface{} { |
38 | 297 |
return m.Nested |
298 |
} |
|
299 |
||
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
300 |
func (m *Message) addNested(n interface{}) { |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
301 |
m.Nested = append(m.Nested, n) |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
302 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
303 |
|
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
304 |
func (m *Message) innerxml() string { |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
305 |
return m.Innerxml |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
306 |
} |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
307 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
308 |
func (p *Presence) GetName() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
309 |
return "presence" |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
310 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
311 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
312 |
func (p *Presence) GetTo() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
313 |
return p.To |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
314 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
315 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
316 |
func (p *Presence) GetFrom() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
317 |
return p.From |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
318 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
319 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
320 |
func (p *Presence) GetId() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
321 |
return p.Id |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
322 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
323 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
324 |
func (p *Presence) GetType() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
325 |
return p.Type |
72 | 326 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
327 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
328 |
func (p *Presence) GetLang() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
329 |
return p.Lang |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
330 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
331 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
332 |
func (p *Presence) GetError() *Error { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
333 |
return p.Error |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
334 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
335 |
|
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
336 |
func (p *Presence) GetNested() []interface{} { |
38 | 337 |
return p.Nested |
338 |
} |
|
339 |
||
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
340 |
func (p *Presence) addNested(n interface{}) { |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
341 |
p.Nested = append(p.Nested, n) |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
342 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
343 |
|
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
344 |
func (p *Presence) innerxml() string { |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
345 |
return p.Innerxml |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
346 |
} |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
347 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
348 |
func (iq *Iq) GetName() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
349 |
return "iq" |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
350 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
351 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
352 |
func (iq *Iq) GetTo() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
353 |
return iq.To |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
354 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
355 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
356 |
func (iq *Iq) GetFrom() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
357 |
return iq.From |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
358 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
359 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
360 |
func (iq *Iq) GetId() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
361 |
return iq.Id |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
362 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
363 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
364 |
func (iq *Iq) GetType() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
365 |
return iq.Type |
72 | 366 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
367 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
368 |
func (iq *Iq) GetLang() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
369 |
return iq.Lang |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
370 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
371 |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
41
diff
changeset
|
372 |
func (iq *Iq) GetError() *Error { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
373 |
return iq.Error |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
374 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
375 |
|
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
376 |
func (iq *Iq) GetNested() []interface{} { |
38 | 377 |
return iq.Nested |
378 |
} |
|
379 |
||
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
380 |
func (iq *Iq) addNested(n interface{}) { |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
60
diff
changeset
|
381 |
iq.Nested = append(iq.Nested, n) |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
382 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
383 |
|
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
384 |
func (iq *Iq) innerxml() string { |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
385 |
return iq.Innerxml |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
386 |
} |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
34
diff
changeset
|
387 |
|
26 | 388 |
// Parse a string into a struct implementing Stanza -- this will be |
389 |
// either an Iq, a Message, or a Presence. |
|
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
390 |
func ParseStanza(str string) (Stanza, error) { |
26 | 391 |
r := strings.NewReader(str) |
93 | 392 |
p := xml.NewDecoder(r) |
26 | 393 |
tok, err := p.Token() |
394 |
if err != nil { |
|
395 |
return nil, err |
|
396 |
} |
|
397 |
se, ok := tok.(xml.StartElement) |
|
398 |
if !ok { |
|
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
399 |
return nil, errors.New("Not a start element") |
26 | 400 |
} |
401 |
var stan Stanza |
|
402 |
switch se.Name.Local { |
|
403 |
case "iq": |
|
404 |
stan = &Iq{} |
|
405 |
case "message": |
|
406 |
stan = &Message{} |
|
407 |
case "presence": |
|
408 |
stan = &Presence{} |
|
409 |
default: |
|
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
410 |
return nil, errors.New("Not iq, message, or presence") |
26 | 411 |
} |
93 | 412 |
err = p.DecodeElement(stan, &se) |
26 | 413 |
if err != nil { |
414 |
return nil, err |
|
415 |
} |
|
416 |
return stan, nil |
|
417 |
} |
|
41
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
418 |
|
72 | 419 |
var bindExt Extension = Extension{StanzaHandlers: map[string]func(*xml.Name) interface{}{NsBind: newBind}, |
420 |
Start: func(cl *Client) {}} |
|
60
6d4f43f7dc19
Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents:
59
diff
changeset
|
421 |
|
41
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
422 |
func newBind(name *xml.Name) interface{} { |
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
423 |
return &bindIq{} |
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
424 |
} |