author | Chris Jones <christian.jones@sri.com> |
Sat, 07 Sep 2013 11:46:42 -0700 | |
changeset 129 | cccf2b2fe34d |
parent 128 | 8342afcffc92 |
child 142 | 0ff033eed887 |
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" |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
11 |
"encoding/xml" |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
12 |
"flag" |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
13 |
"fmt" |
119
712aa5780660
Documentation cleanup.
Chris Jones <christian.jones@sri.com>
parents:
116
diff
changeset
|
14 |
// BUG(cjyar): Doesn't use stringprep. Could try the implementation at |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
15 |
// "code.google.com/p/go-idn/src/stringprep" |
128
8342afcffc92
Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents:
126
diff
changeset
|
16 |
"reflect" |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
17 |
"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
|
18 |
"strings" |
0
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 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
21 |
// 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
|
22 |
// 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
|
23 |
// sometimes optional. |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
24 |
type JID struct { |
72 | 25 |
Node string |
26 |
Domain string |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
27 |
Resource string |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
28 |
} |
72 | 29 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
30 |
var _ fmt.Stringer = &JID{} |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
31 |
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
|
32 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
33 |
// XMPP's <stream:stream> XML element |
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
34 |
type stream struct { |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
35 |
XMLName xml.Name `xml:"stream=http://etherx.jabber.org/streams stream"` |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
36 |
To string `xml:"to,attr"` |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
37 |
From string `xml:"from,attr"` |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
38 |
Id string `xml:"id,attr"` |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
39 |
Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr"` |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
40 |
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
|
41 |
} |
116 | 42 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
43 |
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
|
44 |
|
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
45 |
// <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
|
46 |
type streamError struct { |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
47 |
XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"` |
116 | 48 |
Any Generic `xml:",any"` |
49 |
Text *errText |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
50 |
} |
72 | 51 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
52 |
type errText struct { |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
53 |
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams text"` |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
54 |
Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr"` |
116 | 55 |
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
|
56 |
} |
72 | 57 |
|
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
58 |
type Features struct { |
102
872e936f9f3f
Reworked the logging again, and also added namespaces to a couple of fields on Features.
Chris Jones <christian.jones@sri.com>
parents:
100
diff
changeset
|
59 |
Starttls *starttls `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"` |
872e936f9f3f
Reworked the logging again, and also added namespaces to a couple of fields on Features.
Chris Jones <christian.jones@sri.com>
parents:
100
diff
changeset
|
60 |
Mechanisms mechs `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"` |
72 | 61 |
Bind *bindIq |
62 |
Session *Generic |
|
63 |
Any *Generic |
|
8
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 |
|
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
66 |
type starttls struct { |
72 | 67 |
XMLName xml.Name |
17 | 68 |
Required *string |
8
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 |
|
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
71 |
type mechs struct { |
107
3a01bd8e3f8c
Fixed up some more attribute labels.
Chris Jones <christian.jones@sri.com>
parents:
105
diff
changeset
|
72 |
Mechanism []string `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanism"` |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
73 |
} |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
74 |
|
11
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
75 |
type auth struct { |
72 | 76 |
XMLName xml.Name |
107
3a01bd8e3f8c
Fixed up some more attribute labels.
Chris Jones <christian.jones@sri.com>
parents:
105
diff
changeset
|
77 |
Chardata string `xml:",chardata"` |
108
8ec06aff386e
Another little XML tag tweak.
Chris Jones <chris@cjones.org>
parents:
107
diff
changeset
|
78 |
Mechanism string `xml:"mechanism,attr,omitempty"` |
72 | 79 |
Any *Generic |
11
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
80 |
} |
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
81 |
|
112
bd56fb741f69
Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
111
diff
changeset
|
82 |
type Stanza interface { |
111
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
83 |
GetHeader() *Header |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
84 |
} |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
85 |
|
17 | 86 |
// One of the three core XMPP stanza types: iq, message, presence. See |
87 |
// RFC3920, section 9. |
|
111
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
88 |
type Header struct { |
116 | 89 |
To string `xml:"to,attr,omitempty"` |
90 |
From string `xml:"from,attr,omitempty"` |
|
91 |
Id string `xml:"id,attr,omitempty"` |
|
92 |
Type string `xml:"type,attr,omitempty"` |
|
93 |
Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"` |
|
94 |
Innerxml string `xml:",innerxml"` |
|
72 | 95 |
Error *Error |
96 |
Nested []interface{} |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
97 |
} |
110
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
98 |
|
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
99 |
// message stanza |
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
100 |
type Message struct { |
116 | 101 |
XMLName xml.Name `xml:"jabber:client message"` |
111
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
102 |
Header |
116 | 103 |
Subject *Generic `xml:"jabber:client subject"` |
104 |
Body *Generic `xml:"jabber:client body"` |
|
105 |
Thread *Generic `xml:"jabber:client thread"` |
|
110
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
106 |
} |
116 | 107 |
|
112
bd56fb741f69
Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
111
diff
changeset
|
108 |
var _ Stanza = &Message{} |
110
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
109 |
|
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
110 |
// presence stanza |
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
111 |
type Presence struct { |
116 | 112 |
XMLName xml.Name `xml:"presence"` |
111
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
113 |
Header |
115
7c45fc3f524a
Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents:
112
diff
changeset
|
114 |
Show *Generic `xml:"jabber:client show"` |
7c45fc3f524a
Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents:
112
diff
changeset
|
115 |
Status *Generic `xml:"jabber:client status"` |
7c45fc3f524a
Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents:
112
diff
changeset
|
116 |
Priority *Generic `xml:"jabber:client priority"` |
110
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
117 |
} |
116 | 118 |
|
112
bd56fb741f69
Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
111
diff
changeset
|
119 |
var _ Stanza = &Presence{} |
110
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
120 |
|
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
121 |
// iq stanza |
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
122 |
type Iq struct { |
116 | 123 |
XMLName xml.Name `xml:"iq"` |
111
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
124 |
Header |
110
7696e6a01709
Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents:
108
diff
changeset
|
125 |
} |
116 | 126 |
|
112
bd56fb741f69
Step 2 of converting to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
111
diff
changeset
|
127 |
var _ Stanza = &Iq{} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
128 |
|
17 | 129 |
// 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
|
130 |
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
|
131 |
XMLName xml.Name `xml:"error"` |
17 | 132 |
// The error type attribute. |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
133 |
Type string `xml:"type,attr"` |
17 | 134 |
// Any nested element, if present. |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
135 |
Any *Generic |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
136 |
} |
116 | 137 |
|
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
138 |
var _ error = &Error{} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
139 |
|
41
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
140 |
// 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
|
141 |
type bindIq struct { |
72 | 142 |
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` |
143 |
Resource *string `xml:"resource"` |
|
144 |
Jid *string `xml:"jid"` |
|
41
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
145 |
} |
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
146 |
|
17 | 147 |
// 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
|
148 |
type Generic struct { |
72 | 149 |
XMLName xml.Name |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
150 |
Any *Generic `xml:",any"` |
116 | 151 |
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
|
152 |
} |
116 | 153 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
154 |
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
|
155 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
161 |
if jid.Resource != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
162 |
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
|
163 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
164 |
return result |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
165 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
166 |
|
52 | 167 |
// Set implements flag.Value. It returns true if it successfully |
168 |
// parses the string. |
|
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
169 |
func (jid *JID) Set(val string) error { |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
170 |
r := regexp.MustCompile("^(([^@/]+)@)?([^@/]+)(/([^@/]+))?$") |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
171 |
parts := r.FindStringSubmatch(val) |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
172 |
if parts == nil { |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
173 |
return fmt.Errorf("%s doesn't match user@domain/resource", val) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
174 |
} |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
175 |
// jid.Node = stringprep.Nodeprep(parts[2]) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
176 |
// jid.Domain = stringprep.Nodeprep(parts[3]) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
177 |
// jid.Resource = stringprep.Resourceprep(parts[5]) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
178 |
jid.Node = parts[2] |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
179 |
jid.Domain = parts[3] |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
180 |
jid.Resource = parts[5] |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
181 |
return nil |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
182 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
183 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
184 |
func (s *stream) String() string { |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
185 |
var buf bytes.Buffer |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
186 |
buf.WriteString(`<stream:stream xmlns="`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
187 |
buf.WriteString(NsClient) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
188 |
buf.WriteString(`" xmlns:stream="`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
189 |
buf.WriteString(NsStream) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
190 |
buf.WriteString(`"`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
191 |
if s.To != "" { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
192 |
buf.WriteString(` to="`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
193 |
xml.Escape(&buf, []byte(s.To)) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
194 |
buf.WriteString(`"`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
195 |
} |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
196 |
if s.From != "" { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
197 |
buf.WriteString(` from="`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
198 |
xml.Escape(&buf, []byte(s.From)) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
199 |
buf.WriteString(`"`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
200 |
} |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
201 |
if s.Id != "" { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
202 |
buf.WriteString(` id="`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
203 |
xml.Escape(&buf, []byte(s.Id)) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
204 |
buf.WriteString(`"`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
205 |
} |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
206 |
if s.Lang != "" { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
207 |
buf.WriteString(` xml:lang="`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
208 |
xml.Escape(&buf, []byte(s.Lang)) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
209 |
buf.WriteString(`"`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
210 |
} |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
211 |
if s.Version != "" { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
212 |
buf.WriteString(` version="`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
213 |
xml.Escape(&buf, []byte(s.Version)) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
214 |
buf.WriteString(`"`) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
215 |
} |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
216 |
buf.WriteString(">") |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
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 |
|
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
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 |
|
111
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
239 |
func (iq *Iq) GetHeader() *Header { |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
240 |
return &iq.Header |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
241 |
} |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
242 |
|
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
243 |
func (m *Message) GetHeader() *Header { |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
244 |
return &m.Header |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
245 |
} |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
246 |
|
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
247 |
func (p *Presence) GetHeader() *Header { |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
248 |
return &p.Header |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
249 |
} |
36287f2cf06e
Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents:
110
diff
changeset
|
250 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
return "nil" |
1af366d10d32
Nil checks and a greatly simplified filter manager which is less buggy.
Chris Jones <chris@cjones.org>
parents:
49
diff
changeset
|
254 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
255 |
var sub string |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
256 |
if u.Any != nil { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
257 |
sub = u.Any.String() |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
258 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
259 |
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
|
260 |
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
|
261 |
u.XMLName.Local) |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
262 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
263 |
|
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
264 |
func (er *Error) Error() string { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
265 |
buf, err := xml.Marshal(er) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
266 |
if err != nil { |
105
aa895dfae3f6
Allow the user to override the TLS config. Also fixed up some log statements.
Chris Jones <christian.jones@sri.com>
parents:
102
diff
changeset
|
267 |
Warn.Log("double bad error: couldn't marshal error") |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
268 |
return "unreadable error" |
33
571713f49494
Added roster retrieval to StartSession().
Chris Jones <chris@cjones.org>
parents:
32
diff
changeset
|
269 |
} |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
88
diff
changeset
|
270 |
return string(buf) |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
271 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
272 |
|
128
8342afcffc92
Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents:
126
diff
changeset
|
273 |
var bindExt Extension = Extension{} |
60
6d4f43f7dc19
Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents:
59
diff
changeset
|
274 |
|
128
8342afcffc92
Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents:
126
diff
changeset
|
275 |
func init() { |
8342afcffc92
Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents:
126
diff
changeset
|
276 |
bindExt.StanzaHandlers = make(map[xml.Name]reflect.Type) |
8342afcffc92
Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents:
126
diff
changeset
|
277 |
bName := xml.Name{Space: NsBind, Local: "bind"} |
8342afcffc92
Use reflection instead of constructor functions to create extended stanza structures.
Chris Jones <christian.jones@sri.com>
parents:
126
diff
changeset
|
278 |
bindExt.StanzaHandlers[bName] = reflect.TypeOf(bindIq{}) |
41
c8c9e6a7e6c9
Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents:
40
diff
changeset
|
279 |
} |