~samwhited/xmpp

ref: 8a516e9e064619dcb3d84499b66e1562546be918 xmpp/session.go -rw-r--r-- 24.3 KiB
xmpp, sasl2: use Session ConnectionState for SASL

Previously we attempted to pull the tls.ConnectionState out of the
Session's underlying net.Conn, however, even if the underlying
connection is a *tls.Conn if it is wrapped at all the connection state
would become unavailable. Instead, use the new ConnectionState method on
Session which will always proxy down into the top most *tls.Conn.

Fixes #45

Signed-off-by: Sam Whited <sam@samwhited.com>
xmpp: provide access to tls.ConnectionState

When a session's underlying net.Conn gets wrapped, the underlying
tls.ConnectionState becomes inaccessible. Saving the connState and
adding a method on Session to access it will let us proxy it forward to
things that need it (eg. SASL) so that they don't break if we negotiate
stream features that wrap the conn.

See #45

Signed-off-by: Sam Whited <sam@samwhited.com>
xmpp: use entire payload in SendElement

Previously Session.SendElement would only wrap the first element
encountered in the token stream and transmit it. However, you would
expect it to wrap the entire stream (even if it were multiple elements)
in the provided start element.

Signed-off-by: Sam Whited <sam@samwhited.com>
all: include close element in handler stream

Previously the close element was not included in the limited XML stream
passed to handlers. This made it possible to enter an infinite loop or
deadlock when trying to use the DecodeElement method of xml.Decoder's.
A regression test has also been added to make sure that we can't read
beyond the end of the element (which was previously the case but there
was no test for this, which was dangerous) and to make sure that the new
behavior (with the end element) is enforced.

Signed-off-by: Sam Whited <sam@samwhited.com>
all: move stanza wrapping to methods

Previously to wrap a payload in a stanza you would use the functions
WrapIQ, WrapMessage, and WrapPresence. Each of these took their
respective stanza types and a payload.
These have been moved to Wrap methods on the various stanza types that
take a payload to make them easier to use in handlers where you already
have the stanza.
The down side is that these methods now exist on types that embed a
stanza, which may be confusing since the payload will be ignored and
only the stanza will be used.

Signed-off-by: Sam Whited <sam@samwhited.com>
all: be strict about namespace validation

When decoding stanzas, be more strict about verifying the namespace.
Previously stanzas would have an empty namespace, but the session should
always setup the default namespace correctly now.

Signed-off-by: Sam Whited <sam@samwhited.com>
xmpp: fix error reporting unexpected token type

Previously the error reporting an unexpected token would always claim
that the token was a start token (which is the expected type). Instead,
report the unexpected token's type.

Signed-off-by: Sam Whited <sam@samwhited.com>
xmpp: remove duplicate helper function

The recent updates to attr.Get allow us to use it in place of the getID
helper function which returned the value and index of the "id" attribute
specifically.

Signed-off-by: Sam Whited <sam@samwhited.com>
xmpp: fix bug where stream processing stops
xmpp: don't count read timeouts as temporary
xmpp: factor out stream token handling
xmpp: move Negotiator into negotiator.go
all: add and use new internal/attr package

This finally removes all exported identifiers from the internal package
so that it doesn't turn into a junk drawer of functionality and
everything contains a name that's useful, not just a useless identifier
like "internal" that doesn't tell you anything about what the identifier
does.

Update everything else to use the new package as well.
internal/stream: rename idents to reduce stutter

Also update usages.
internal/stream: new package for stream parsing

Also update all uses of old internal identifiers that were moved into
internal/stream.
all: move stream namespaces into stream package
xmpp: make closing stream tag a const
xmpp: allow whitespace keepalives
all: move encoding funcs into internal/marshal
all: allow encoding structs from within handlers
xmpp: use new internal encode functions
Next