all: prepare release v0.16.0

Signed-off-by: Sam Whited <sam@samwhited.com>
receipts: limit the amount of locking required

Limiting the amount of output stream locking required to just the actual
sending of the element means we don't have to block the entire output
stream while we wait for a response, which will likely lead to deadlock.

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>
receipts: fix resource leak

Previously messages weren't removed from being tracked by the handler
after they were acked or after the context was canceled. This patch
makes sure they are removed, and adds a regression test to double check
that they're removed on context cancelation.

Signed-off-by: Sam Whited <sam@samwhited.com>
.builds: change CI to use OpenBSD temporarily

The FreeBSD image on SourceHut is broken and they have indicated that
they intend to wait for FreeBSD to issue a release instead of working
around the issue themselves. For now, change the builder to OpenBSD.

Signed-off-by: Sam Whited <sam@samwhited.com>
roster: fix iter bug in Go 1.13

Sometimes Go 1.13 leaks an io.EOF out of xml.Decoder's even when things
worked successfully. Temporarily ignoring this error will allow tests to
pass in Go 1.13 and the workaround can be removed when Go 1.15 comes
out. For the removal timeline and any updates see:

Signed-off-by: Sam Whited <sam@samwhited.com>
receipts: new Message Delivery Receipts package

This patch imlements XEP-0184: Message Delivery Receipts

Signed-off-by: Sam Whited <sam@samwhited.com>
mux: close mux iterator

An element iterator used in the muxer was previously unclosed. In this
case, the close method will likely always be a noop, but just in case
close it so that if we make changes later we don't introduce a lock
contention or resource freeing issue.

Signed-off-by: Sam Whited <sam@samwhited.com>
stanza: create stanzas from any start element

Previously stanzas were unmarshaled from the start element using an
xml.Decoder. This is slow and inefficient, and if the name of the stanza
differs an error will be returned. Implementing manual decoding of the
start element should make things faster (though this has not been
verified) and allows the name of the initial start element to be
disregarded. This will not change the name when the stanza typed value
is marshaled back into an XML stream.

Signed-off-by: Sam Whited <sam@samwhited.com>
.builds: let the DCO check work on master branch

Previously we compared the branch against whatever the current master
branch was to find new commits, so if you push to your own master branch
or we test a merged master there would never be any commits to check.
Instead, check against origin/master so that we're always comparing with
whatever we pulled down from upstream.

Signed-off-by: Sam Whited <sam@samwhited.com>
mux: fix a possible infinite loop

Previously a bug in EOF error handling could have lead to the last token
of a message stream being cut off. This could lead to Decode entering an
infinite loop of nil tokens and nil errors being returned. This is
likely a bug in the encoding/xml package which should be fixed as well,
but for now we can just make sure that we don't trigger it.

Signed-off-by: Sam Whited <sam@samwhited.com>
roster: support handling roster pushes

Add a handler to support handling roster pushes as defined in RFC 6121
and an option for easily registering the handler on a mux.ServeMux.

Signed-off-by: Sam Whited <sam@samwhited.com>
xtime: minor fix to test failure comment

Previously a test error was copied from the ping package and still
mentioned handling pings.

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>
mux: use xml.CopyToken instead of manual copying

Previously we were manually copying the token for token types that have
bufferes that get reused. Instead, use a function out of the
encoding/xml package that can copy any valid token type.

Signed-off-by: Sam Whited <sam@samwhited.com>
mux: use existing child element iterator

An iterator already exists in the mellium.im/xmpp/internal/iter package
that can be used to iterate over child elements. Reusing this keeps
things simple.

Signed-off-by: Sam Whited <sam@samwhited.com>
mux: simplify buffer state tracking

Previously we kept separate state for any buffered token readers and
jumped back and forth between the start of the stream (when handing them
off to handlers) and the last read start element. This patch simplifies
the code by creating a new buffered reader sharing the underlying buffer
for handlers so that the offset never has to be changed in the original
buffered reader.

Signed-off-by: Sam Whited <sam@samwhited.com>
docs: add rules for creating extensions

Signed-off-by: Sam Whited <sam@samwhited.com>
roster: minor simplification to logic in Next

Signed-off-by: Sam Whited <sam@samwhited.com>
all: update changelog for v0.15.0

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>