structs.go
author Chris Jones <chris@cjones.org>
Sun, 08 Jan 2012 13:04:50 -0700
branch20120108-close
changeset 70 bb629d22148a
parent 61 16513974d273
child 72 53f15893a1a7
permissions -rw-r--r--
Closing this branch.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     1
// 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>
31
1dc47df5c99f Made streamError non-public, and made a first attempt at a stream
Chris Jones <chris@cjones.org>
parents: 28
diff changeset
    43
type streamError struct {
24
fff79efe06f6 Removed definedCondition in favor of Generic.
Chris Jones <chris@cjones.org>
parents: 22
diff changeset
    44
	Any Generic
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
    45
	Text *errText
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    46
}
31
1dc47df5c99f Made streamError non-public, and made a first attempt at a stream
Chris Jones <chris@cjones.org>
parents: 28
diff changeset
    47
var _ xml.Marshaler = &streamError{}
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    48
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    49
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
    50
	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
    51
	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
    52
}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    53
var _ xml.Marshaler = &errText{}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    54
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    55
type Features struct {
10
f38b0ee7b1c1 Added TLS negotiation.
Chris Jones <chris@cjones.org>
parents: 8
diff changeset
    56
	Starttls *starttls
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    57
	Mechanisms mechs
41
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
    58
	Bind *bindIq
32
4e68d8f89dc3 Make the server's advertised features available to the app.
Chris Jones <chris@cjones.org>
parents: 31
diff changeset
    59
	Session *Generic
4e68d8f89dc3 Make the server's advertised features available to the app.
Chris Jones <chris@cjones.org>
parents: 31
diff changeset
    60
	Any *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
f38b0ee7b1c1 Added TLS negotiation.
Chris Jones <chris@cjones.org>
parents: 8
diff changeset
    64
	XMLName xml.Name
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    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
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    79
// One of the three core XMPP stanza types: iq, message, presence. See
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    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
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    82
	// Returns "iq", "message", or "presence".
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
    83
	GetName() string
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    84
	// The to attribute.
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
    85
	GetTo() string
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    86
	// The from attribute.
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
    87
	GetFrom() string
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    88
	// The id attribute.
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
    89
	GetId() string
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    90
	// The type attribute.
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
    91
	GetType() string
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    92
	// The xml:lang attribute.
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
    93
	GetLang() string
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
    94
	// A nested error element, if any.
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
    95
	GetError() *Error
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    96
	// Zero or more (non-error) nested elements. These will be in
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    97
	// namespaces managed by extensions.
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    98
	GetNested() []interface{}
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    99
	addNested(interface{})
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   100
	innerxml() string
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   101
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   102
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   103
// message stanza
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   104
type Message struct {
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   105
	To string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   106
	From string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   107
	Id string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   108
	Type string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   109
	Lang string `xml:"attr"`
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   110
	Innerxml string `xml:"innerxml"`
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   111
	Error *Error
28
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   112
	Subject *Generic
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   113
	Body *Generic
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   114
	Thread *Generic
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   115
	Nested []interface{}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   116
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   117
var _ xml.Marshaler = &Message{}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   118
var _ Stanza = &Message{}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   119
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   120
// presence stanza
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   121
type Presence struct {
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   122
	To string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   123
	From string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   124
	Id string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   125
	Type string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   126
	Lang string `xml:"attr"`
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   127
	Innerxml string `xml:"innerxml"`
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   128
	Error *Error
28
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   129
	Show *Generic
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   130
	Status *Generic
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   131
	Priority *Generic
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   132
	Nested []interface{}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   133
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   134
var _ xml.Marshaler = &Presence{}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   135
var _ Stanza = &Presence{}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   136
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   137
// iq stanza
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   138
type Iq struct {
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   139
	To string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   140
	From string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   141
	Id string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   142
	Type string `xml:"attr"`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   143
	Lang string `xml:"attr"`
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   144
	Innerxml string `xml:"innerxml"`
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   145
	Error *Error
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   146
	Nested []interface{}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   147
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   148
var _ xml.Marshaler = &Iq{}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   149
var _ Stanza = &Iq{}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   150
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   151
// 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
   152
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
   153
	XMLName xml.Name `xml:"error"`
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   154
	// 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
   155
	Type string `xml:"attr"`
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   156
	// Any nested element, if present.
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   157
	Any *Generic
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   158
}
28
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   159
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
   160
41
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   161
// 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
   162
type bindIq struct {
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   163
	XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   164
	Resource *string `xml:"resource"`
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   165
	Jid *string `xml:"jid"`
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   166
}
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   167
17
d269d9c0fc8e Code review.
Chris Jones <chris@cjones.org>
parents: 12
diff changeset
   168
// 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
   169
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
   170
	XMLName xml.Name
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   171
	Any *Generic
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   172
	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
   173
}
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   174
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
   175
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   176
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
   177
	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
   178
	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
   179
		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
   180
	}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   181
	if jid.Resource != "" {
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   182
		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
   183
	}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   184
	return result
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   185
}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   186
52
9b664fde0ec3 Comment fixes.
Chris Jones <chris@cjones.org>
parents: 51
diff changeset
   187
// Set implements flag.Value. It returns true if it successfully
9b664fde0ec3 Comment fixes.
Chris Jones <chris@cjones.org>
parents: 51
diff changeset
   188
// parses the string.
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   189
func (jid *JID) Set(val string) bool {
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   190
	r := regexp.MustCompile("^(([^@/]+)@)?([^@/]+)(/([^@/]+))?$")
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   191
	parts := r.FindStringSubmatch(val)
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   192
	if parts == nil {
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   193
		return false
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   194
	}
25
7437d6eed227 Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents: 24
diff changeset
   195
	jid.Node = parts[2]
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   196
	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
   197
	jid.Resource = parts[5]
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   198
	return true
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   199
}
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
   200
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
   201
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
   202
	buf := bytes.NewBuffer(nil)
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   203
	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
   204
	writeField(buf, "xmlns", "jabber:client")
34
7b1f924c75e2 Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents: 33
diff changeset
   205
	writeField(buf, "xmlns:stream", NsStream)
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   206
	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
   207
	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
   208
	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
   209
	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
   210
	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
   211
	buf.WriteString(">")
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   212
	// 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
   213
	return buf.Bytes(), nil
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   214
}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   215
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
   216
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
   217
	result, _ := s.MarshalXML()
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   218
	return string(result)
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   219
}
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   220
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
   221
func parseStream(se xml.StartElement) (*stream, os.Error) {
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
   222
	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
   223
	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
   224
		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
   225
		case "to":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   226
			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
   227
		case "from":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   228
			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
   229
		case "id":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   230
			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
   231
		case "lang":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   232
			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
   233
		case "version":
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   234
			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
   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
	}
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   237
	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
   238
}
faef59c8db05 Added a goroutine to read data from the remote and parse it into
Chris Jones <chris@cjones.org>
parents: 3
diff changeset
   239
31
1dc47df5c99f Made streamError non-public, and made a first attempt at a stream
Chris Jones <chris@cjones.org>
parents: 28
diff changeset
   240
func (s *streamError) 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
   241
	buf := bytes.NewBuffer(nil)
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   242
	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
   243
	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
   244
	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
   245
		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
   246
	}
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   247
	buf.WriteString("</stream:error>")
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   248
	return buf.Bytes(), nil
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   249
}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   250
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   251
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
   252
	buf := bytes.NewBuffer(nil)
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   253
	buf.WriteString("<text")
34
7b1f924c75e2 Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents: 33
diff changeset
   254
	writeField(buf, "xmlns", NsStreams)
0
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   255
	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
   256
	buf.WriteString(">")
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 5
diff changeset
   257
	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
   258
	buf.WriteString("</text>")
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   259
	return buf.Bytes(), nil
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   260
}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   261
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   262
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
   263
	if value != "" {
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   264
		io.WriteString(w, " ")
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   265
		io.WriteString(w, field)
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   266
		io.WriteString(w, `="`)
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   267
		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
   268
		io.WriteString(w, `"`)
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   269
	}
6dbd969c8f3a Some initial data structures from RFC 3920, up through section 4.
Chris Jones <chris@cjones.org>
parents:
diff changeset
   270
}
8
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
   271
21
8f6ae5cfc9b9 Renamed Unrecognized to Generic.
Chris Jones <chris@cjones.org>
parents: 20
diff changeset
   272
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
   273
	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
   274
		return "nil"
1af366d10d32 Nil checks and a greatly simplified filter manager which is less buggy.
Chris Jones <chris@cjones.org>
parents: 49
diff changeset
   275
	}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   276
	var sub string
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   277
	if u.Any != nil {
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   278
		sub = u.Any.String()
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
	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
   281
		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
   282
		u.XMLName.Local)
30a7752cf8f7 Added the ability to parse <stream:features>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
   283
}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   284
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   285
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
   286
	buf := bytes.NewBuffer(nil)
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   287
	buf.WriteString("<")
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   288
	buf.WriteString(st.GetName())
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   289
	if st.GetTo() != "" {
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   290
		writeField(buf, "to", st.GetTo())
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   291
	}
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   292
	if st.GetFrom() != "" {
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   293
		writeField(buf, "from", st.GetFrom())
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   294
	}
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   295
	if st.GetId() != "" {
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   296
		writeField(buf, "id", st.GetId())
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   297
	}
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   298
	if st.GetType() != "" {
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   299
		writeField(buf, "type", st.GetType())
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   300
	}
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   301
	if st.GetLang() != "" {
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   302
		writeField(buf, "xml:lang", st.GetLang())
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   303
	}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   304
	buf.WriteString(">")
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   305
49
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   306
	if m, ok := st.(*Message) ; ok {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   307
		err := xml.Marshal(buf, m.Subject)
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   308
		if err != nil {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   309
			return nil, err
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   310
		}
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   311
		err = xml.Marshal(buf, m.Body)
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   312
		if err != nil {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   313
			return nil, err
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   314
		}
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   315
		err = xml.Marshal(buf, m.Thread)
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   316
		if err != nil {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   317
			return nil, err
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   318
		}
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   319
	}
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   320
	if p, ok := st.(*Presence) ; ok {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   321
		err := xml.Marshal(buf, p.Show)
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   322
		if err != nil {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   323
			return nil, err
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   324
		}
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   325
		err = xml.Marshal(buf, p.Status)
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   326
		if err != nil {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   327
			return nil, err
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   328
		}
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   329
		err = xml.Marshal(buf, p.Priority)
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   330
		if err != nil {
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   331
			return nil, err
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   332
		}
8e140810be02 Fixed up marshaling of the extra fields in presence and message.
Chris Jones <chris@cjones.org>
parents: 43
diff changeset
   333
	}
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   334
	if nested := st.GetNested() ; nested != nil {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   335
		for _, n := range(nested) {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   336
			xml.Marshal(buf, n)
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   337
		}
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   338
	} else if st.innerxml() != "" {
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   339
		buf.WriteString(st.innerxml())
33
571713f49494 Added roster retrieval to StartSession().
Chris Jones <chris@cjones.org>
parents: 32
diff changeset
   340
	}
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   341
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   342
	buf.WriteString("</")
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   343
	buf.WriteString(st.GetName())
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   344
	buf.WriteString(">")
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   345
	return buf.Bytes(), nil
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   346
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   347
43
82e90aa25dad Making a little more use of XMLName for marshaling instead of having a
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   348
func (er *Error) String() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   349
	buf := bytes.NewBuffer(nil)
43
82e90aa25dad Making a little more use of XMLName for marshaling instead of having a
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   350
	xml.Marshal(buf, er)
82e90aa25dad Making a little more use of XMLName for marshaling instead of having a
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   351
	return buf.String()
28
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   352
}
78961db80bae Added Client.StartSession().
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
   353
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   354
func (m *Message) GetName() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   355
	return "message"
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   358
func (m *Message) GetTo() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   359
	return m.To
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   362
func (m *Message) GetFrom() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   363
	return m.From
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   366
func (m *Message) GetId() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   367
	return m.Id
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   370
func (m *Message) GetType() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   371
	return m.Type
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   374
func (m *Message) GetLang() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   375
	return m.Lang
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   378
func (m *Message) GetError() *Error {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   379
	return m.Error
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   380
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   381
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   382
func (m *Message) GetNested() []interface{} {
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   383
	return m.Nested
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   384
}
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   385
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   386
func (m *Message) addNested(n interface{}) {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   387
	m.Nested = append(m.Nested, n)
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   388
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   389
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   390
func (m *Message) innerxml() string {
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   391
	return m.Innerxml
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   392
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   393
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   394
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
   395
	return marshalXML(m)
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   398
func (p *Presence) GetName() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   399
	return "presence"
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   402
func (p *Presence) GetTo() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   403
	return p.To
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   406
func (p *Presence) GetFrom() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   407
	return p.From
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   410
func (p *Presence) GetId() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   411
	return p.Id
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   414
func (p *Presence) GetType() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   415
	return p.Type
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   416
	}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   417
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   418
func (p *Presence) GetLang() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   419
	return p.Lang
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
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   422
func (p *Presence) GetError() *Error {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   423
	return p.Error
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   424
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   425
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   426
func (p *Presence) GetNested() []interface{} {
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   427
	return p.Nested
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   428
}
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   429
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   430
func (p *Presence) addNested(n interface{}) {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   431
	p.Nested = append(p.Nested, n)
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   432
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   433
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   434
func (p *Presence) innerxml() string {
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   435
	return p.Innerxml
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   436
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   437
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   438
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
   439
	return marshalXML(p)
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   440
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   441
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   442
func (iq *Iq) GetName() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   443
	return "iq"
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   444
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   445
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   446
func (iq *Iq) GetTo() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   447
	return iq.To
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   448
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   449
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   450
func (iq *Iq) GetFrom() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   451
	return iq.From
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   452
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   453
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   454
func (iq *Iq) GetId() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   455
	return iq.Id
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   456
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   457
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   458
func (iq *Iq) GetType() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   459
	return iq.Type
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   460
	}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   461
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   462
func (iq *Iq) GetLang() string {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   463
	return iq.Lang
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   464
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   465
42
f6bb47ca12f2 Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents: 41
diff changeset
   466
func (iq *Iq) GetError() *Error {
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   467
	return iq.Error
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   468
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   469
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   470
func (iq *Iq) GetNested() []interface{} {
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   471
	return iq.Nested
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   472
}
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
   473
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   474
func (iq *Iq) addNested(n interface{}) {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   475
	iq.Nested = append(iq.Nested, n)
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   476
}
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   477
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   478
func (iq *Iq) innerxml() string {
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   479
	return iq.Innerxml
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   480
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents: 34
diff changeset
   481
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   482
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
   483
	return marshalXML(iq)
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 11
diff changeset
   484
}
26
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   485
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   486
// Parse a string into a struct implementing Stanza -- this will be
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   487
// either an Iq, a Message, or a Presence.
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   488
func ParseStanza(str string) (Stanza, os.Error) {
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   489
	r := strings.NewReader(str)
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   490
	p := xml.NewParser(r)
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   491
	tok, err := p.Token()
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   492
	if err != nil {
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   493
		return nil, err
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   494
	}
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   495
	se, ok := tok.(xml.StartElement)
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   496
	if !ok {
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   497
		return nil, os.NewError("Not a start element")
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   498
	}
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   499
	var stan Stanza
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   500
	switch se.Name.Local {
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   501
	case "iq":
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   502
		stan = &Iq{}
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   503
	case "message":
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   504
		stan = &Message{}
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   505
	case "presence":
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   506
		stan = &Presence{}
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   507
	default:
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   508
		return nil, os.NewError("Not iq, message, or presence")
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   509
	}
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   510
	err = p.Unmarshal(stan, &se)
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   511
	if err != nil {
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   512
		return nil, err
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   513
	}
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   514
	return stan, nil
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   515
}
41
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   516
60
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 59
diff changeset
   517
var bindExt Extension = Extension{StanzaHandlers:
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 59
diff changeset
   518
	map[string] func(*xml.Name) interface{}{NsBind: newBind},
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 59
diff changeset
   519
		Start: func(cl *Client) {}}
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 59
diff changeset
   520
41
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   521
func newBind(name *xml.Name) interface{} {
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   522
	return &bindIq{}
c8c9e6a7e6c9 Made a special-purpose bind structure for resource binding.
Chris Jones <chris@cjones.org>
parents: 40
diff changeset
   523
}