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