author | Chris Jones <chris@cjones.org> |
Thu, 29 Dec 2011 09:48:36 -0700 | |
changeset 28 | 78961db80bae |
parent 26 | 4d0a369079ce |
child 31 | 1dc47df5c99f |
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" |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
11 |
"flag" |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
12 |
"fmt" |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
13 |
"io" |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
14 |
"os" |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
15 |
"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
|
16 |
"strings" |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
17 |
"xml" |
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 { |
25
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
24 |
Node string |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
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 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
28 |
var _ fmt.Stringer = &JID{} |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
29 |
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
|
30 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
31 |
// XMPP's <stream:stream> XML element |
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
32 |
type stream struct { |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
33 |
To string `xml:"attr"` |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
34 |
From string `xml:"attr"` |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
35 |
Id string `xml:"attr"` |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
36 |
Lang string `xml:"attr"` |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
37 |
Version string `xml:"attr"` |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
38 |
} |
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
39 |
var _ xml.Marshaler = &stream{} |
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
40 |
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
|
41 |
|
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
42 |
// <stream:error> |
20
e119444a1119
Replaced TODO comments with Go-style BUG(me) comments.
Chris Jones <chris@cjones.org>
parents:
17
diff
changeset
|
43 |
// BUG(cjyar) Can this be consolidated with Error? Hide it if not. |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
44 |
type StreamError struct { |
24
fff79efe06f6
Removed definedCondition in favor of Generic.
Chris Jones <chris@cjones.org>
parents:
22
diff
changeset
|
45 |
Any Generic |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
46 |
Text *errText |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
47 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
48 |
var _ xml.Marshaler = &StreamError{} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
49 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
50 |
type errText struct { |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
51 |
Lang string `xml:"attr"` |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
52 |
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
|
53 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
54 |
var _ xml.Marshaler = &errText{} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
55 |
|
20
e119444a1119
Replaced TODO comments with Go-style BUG(me) comments.
Chris Jones <chris@cjones.org>
parents:
17
diff
changeset
|
56 |
// BUG(cjyar) Store this in Client and make it available to the app. |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
57 |
type Features struct { |
10 | 58 |
Starttls *starttls |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
59 |
Mechanisms mechs |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
60 |
Bind *Generic |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
61 |
} |
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 |
type starttls struct { |
10 | 64 |
XMLName xml.Name |
17 | 65 |
Required *string |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
66 |
} |
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 |
type mechs struct { |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
69 |
Mechanism []string |
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 |
|
11
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
72 |
type auth struct { |
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
73 |
XMLName xml.Name |
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
74 |
Chardata string `xml:"chardata"` |
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
75 |
Mechanism string `xml:"attr"` |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
76 |
Any *Generic |
11
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
77 |
} |
48be1ae93fd4
Added SASL digest authentication.
Chris Jones <chris@cjones.org>
parents:
10
diff
changeset
|
78 |
|
17 | 79 |
// One of the three core XMPP stanza types: iq, message, presence. See |
80 |
// RFC3920, section 9. |
|
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
81 |
type Stanza interface { |
17 | 82 |
// Returns "iq", "message", or "presence". |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
83 |
XName() string |
17 | 84 |
// The to attribute. |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
85 |
XTo() string |
17 | 86 |
// The from attribute. |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
87 |
XFrom() string |
17 | 88 |
// The id attribute. |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
89 |
XId() string |
17 | 90 |
// The type attribute. |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
91 |
XType() string |
17 | 92 |
// The xml:lang attribute. |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
93 |
XLang() string |
17 | 94 |
// A nested error element, if any. |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
95 |
XError() *Error |
17 | 96 |
// A (non-error) nested element, if any. |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
97 |
XChild() *Generic |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
98 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
99 |
|
17 | 100 |
// message stanza |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
101 |
type Message struct { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
102 |
To string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
103 |
From string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
104 |
Id string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
105 |
Type string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
106 |
Lang string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
107 |
Error *Error |
28 | 108 |
Subject *Generic |
109 |
Body *Generic |
|
110 |
Thread *Generic |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
111 |
Any *Generic |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
112 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
113 |
var _ xml.Marshaler = &Message{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
114 |
var _ Stanza = &Message{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
115 |
|
17 | 116 |
// presence stanza |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
117 |
type Presence struct { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
118 |
To string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
119 |
From string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
120 |
Id string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
121 |
Type string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
122 |
Lang string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
123 |
Error *Error |
28 | 124 |
Show *Generic |
125 |
Status *Generic |
|
126 |
Priority *Generic |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
127 |
Any *Generic |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
128 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
129 |
var _ xml.Marshaler = &Presence{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
130 |
var _ Stanza = &Presence{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
131 |
|
17 | 132 |
// iq stanza |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
133 |
type Iq struct { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
134 |
To string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
135 |
From string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
136 |
Id string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
137 |
Type string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
138 |
Lang string `xml:"attr"` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
139 |
Error *Error |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
140 |
Any *Generic |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
141 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
142 |
var _ xml.Marshaler = &Iq{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
143 |
var _ Stanza = &Iq{} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
144 |
|
17 | 145 |
// 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
|
146 |
type Error struct { |
17 | 147 |
// The error type attribute. |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
148 |
Type string `xml:"attr"` |
17 | 149 |
// Any nested element, if present. |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
150 |
Any *Generic |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
151 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
152 |
var _ xml.Marshaler = &Error{} |
28 | 153 |
var _ os.Error = &Error{} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
154 |
|
17 | 155 |
// 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
|
156 |
type Generic struct { |
5
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
157 |
XMLName xml.Name |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
158 |
Any *Generic |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
159 |
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
|
160 |
} |
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
161 |
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
|
162 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
168 |
if jid.Resource != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
169 |
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
|
170 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
171 |
return result |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
172 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
173 |
|
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
174 |
func (jid *JID) Set(val string) bool { |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
175 |
r := regexp.MustCompile("^(([^@/]+)@)?([^@/]+)(/([^@/]+))?$") |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
176 |
parts := r.FindStringSubmatch(val) |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
177 |
if parts == nil { |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
178 |
return false |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
179 |
} |
25
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
180 |
jid.Node = parts[2] |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
181 |
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
|
182 |
jid.Resource = parts[5] |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
183 |
return true |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
184 |
} |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
185 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
186 |
func (s *stream) MarshalXML() ([]byte, os.Error) { |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
187 |
buf := bytes.NewBuffer(nil) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
188 |
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
|
189 |
writeField(buf, "xmlns", "jabber:client") |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
190 |
writeField(buf, "xmlns:stream", nsStream) |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
buf.WriteString(">") |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
197 |
// We never write </stream:stream> |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
198 |
return buf.Bytes(), nil |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
199 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
200 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
201 |
func (s *stream) String() string { |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
202 |
result, _ := s.MarshalXML() |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
203 |
return string(result) |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
204 |
} |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
205 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
206 |
func parseStream(se xml.StartElement) (*stream, os.Error) { |
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
case "to": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
211 |
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
|
212 |
case "from": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
213 |
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
|
214 |
case "id": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
215 |
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
|
216 |
case "lang": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
217 |
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
|
218 |
case "version": |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
219 |
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
|
220 |
} |
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
221 |
} |
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
222 |
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
|
223 |
} |
faef59c8db05
Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents:
3
diff
changeset
|
224 |
|
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
225 |
func (s *StreamError) MarshalXML() ([]byte, os.Error) { |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
226 |
buf := bytes.NewBuffer(nil) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
227 |
buf.WriteString("<stream:error>") |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
228 |
xml.Marshal(buf, s.Any) |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
229 |
if s.Text != nil { |
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
230 |
xml.Marshal(buf, s.Text) |
2
4dabfef08c8c
Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
1
diff
changeset
|
231 |
} |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
232 |
buf.WriteString("</stream:error>") |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
233 |
return buf.Bytes(), nil |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
234 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
235 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
236 |
func (e *errText) MarshalXML() ([]byte, os.Error) { |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
237 |
buf := bytes.NewBuffer(nil) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
238 |
buf.WriteString("<text") |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
239 |
writeField(buf, "xmlns", nsStreams) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
240 |
writeField(buf, "xml:lang", e.Lang) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
241 |
buf.WriteString(">") |
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
5
diff
changeset
|
242 |
xml.Escape(buf, []byte(e.Text)) |
0
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
243 |
buf.WriteString("</text>") |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
244 |
return buf.Bytes(), nil |
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 |
|
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
247 |
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
|
248 |
if value != "" { |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
249 |
io.WriteString(w, " ") |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
250 |
io.WriteString(w, field) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
251 |
io.WriteString(w, `="`) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
252 |
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
|
253 |
io.WriteString(w, `"`) |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
254 |
} |
6dbd969c8f3a
Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
255 |
} |
8
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
256 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
257 |
func (u *Generic) String() string { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
258 |
var sub string |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
259 |
if u.Any != nil { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
260 |
sub = u.Any.String() |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
261 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
u.XMLName.Local) |
30a7752cf8f7
Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
265 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
266 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
267 |
func marshalXML(st Stanza) ([]byte, os.Error) { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
268 |
buf := bytes.NewBuffer(nil) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
269 |
buf.WriteString("<") |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
270 |
buf.WriteString(st.XName()) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
271 |
if st.XTo() != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
272 |
writeField(buf, "to", st.XTo()) |
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 |
if st.XFrom() != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
275 |
writeField(buf, "from", st.XFrom()) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
276 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
277 |
if st.XId() != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
278 |
writeField(buf, "id", st.XId()) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
279 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
280 |
if st.XType() != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
281 |
writeField(buf, "type", st.XType()) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
282 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
283 |
if st.XLang() != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
284 |
writeField(buf, "xml:lang", st.XLang()) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
285 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
286 |
buf.WriteString(">") |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
287 |
if st.XError() != nil { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
288 |
bytes, _ := st.XError().MarshalXML() |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
289 |
buf.WriteString(string(bytes)) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
290 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
291 |
if st.XChild() != nil { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
292 |
xml.Marshal(buf, st.XChild()) |
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 |
buf.WriteString("</") |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
295 |
buf.WriteString(st.XName()) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
296 |
buf.WriteString(">") |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
297 |
return buf.Bytes(), nil |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
298 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
299 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
300 |
func (er *Error) MarshalXML() ([]byte, os.Error) { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
301 |
buf := bytes.NewBuffer(nil) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
302 |
buf.WriteString("<error") |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
303 |
writeField(buf, "type", er.Type) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
304 |
buf.WriteString(">") |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
305 |
if er.Any != nil { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
306 |
xml.Marshal(buf, er.Any) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
307 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
308 |
buf.WriteString("</error>") |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
309 |
return buf.Bytes(), nil |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
310 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
311 |
|
28 | 312 |
func (er *Error) String() string { |
313 |
bytes, _ := er.MarshalXML() |
|
314 |
return string(bytes) |
|
315 |
} |
|
316 |
||
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
317 |
func (m *Message) XName() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
318 |
return "message" |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
319 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
320 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
321 |
func (m *Message) XTo() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
322 |
return m.To |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
323 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
324 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
325 |
func (m *Message) XFrom() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
326 |
return m.From |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
327 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
328 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
329 |
func (m *Message) XId() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
330 |
return m.Id |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
331 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
332 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
333 |
func (m *Message) XType() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
334 |
return m.Type |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
335 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
336 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
337 |
func (m *Message) XLang() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
338 |
return m.Lang |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
339 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
340 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
341 |
func (m *Message) XError() *Error { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
342 |
return m.Error |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
343 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
344 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
345 |
func (m *Message) XChild() *Generic { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
346 |
return m.Any |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
347 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
348 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
349 |
func (m *Message) MarshalXML() ([]byte, os.Error) { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
350 |
return marshalXML(m) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
351 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
352 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
353 |
func (p *Presence) XName() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
354 |
return "presence" |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
355 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
356 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
357 |
func (p *Presence) XTo() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
358 |
return p.To |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
359 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
360 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
361 |
func (p *Presence) XFrom() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
362 |
return p.From |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
363 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
364 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
365 |
func (p *Presence) XId() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
366 |
return p.Id |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
367 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
368 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
369 |
func (p *Presence) XType() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
370 |
return p.Type |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
371 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
372 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
373 |
func (p *Presence) XLang() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
374 |
return p.Lang |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
375 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
376 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
377 |
func (p *Presence) XError() *Error { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
378 |
return p.Error |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
379 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
380 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
381 |
func (p *Presence) XChild() *Generic { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
382 |
return p.Any |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
383 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
384 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
385 |
func (p *Presence) MarshalXML() ([]byte, os.Error) { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
386 |
return marshalXML(p) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
387 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
388 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
389 |
func (iq *Iq) XName() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
390 |
return "iq" |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
391 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
392 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
393 |
func (iq *Iq) XTo() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
394 |
return iq.To |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
395 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
396 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
397 |
func (iq *Iq) XFrom() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
398 |
return iq.From |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
399 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
400 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
401 |
func (iq *Iq) XId() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
402 |
return iq.Id |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
403 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
404 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
405 |
func (iq *Iq) XType() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
406 |
return iq.Type |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
407 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
408 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
409 |
func (iq *Iq) XLang() string { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
410 |
return iq.Lang |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
411 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
412 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
413 |
func (iq *Iq) XError() *Error { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
414 |
return iq.Error |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
415 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
416 |
|
21
8f6ae5cfc9b9
Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents:
20
diff
changeset
|
417 |
func (iq *Iq) XChild() *Generic { |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
418 |
return iq.Any |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
419 |
} |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
420 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
421 |
func (iq *Iq) MarshalXML() ([]byte, os.Error) { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
422 |
return marshalXML(iq) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
11
diff
changeset
|
423 |
} |
26 | 424 |
|
425 |
// Parse a string into a struct implementing Stanza -- this will be |
|
426 |
// either an Iq, a Message, or a Presence. |
|
427 |
func ParseStanza(str string) (Stanza, os.Error) { |
|
428 |
r := strings.NewReader(str) |
|
429 |
p := xml.NewParser(r) |
|
430 |
tok, err := p.Token() |
|
431 |
if err != nil { |
|
432 |
return nil, err |
|
433 |
} |
|
434 |
se, ok := tok.(xml.StartElement) |
|
435 |
if !ok { |
|
436 |
return nil, os.NewError("Not a start element") |
|
437 |
} |
|
438 |
var stan Stanza |
|
439 |
switch se.Name.Local { |
|
440 |
case "iq": |
|
441 |
stan = &Iq{} |
|
442 |
case "message": |
|
443 |
stan = &Message{} |
|
444 |
case "presence": |
|
445 |
stan = &Presence{} |
|
446 |
default: |
|
447 |
return nil, os.NewError("Not iq, message, or presence") |
|
448 |
} |
|
449 |
err = p.Unmarshal(stan, &se) |
|
450 |
if err != nil { |
|
451 |
return nil, err |
|
452 |
} |
|
453 |
return stan, nil |
|
454 |
} |