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