~samwhited/xmpp

internal/marshal: add TokenReader API

While thinking about whether or not it would be difficult to add
EncodeIQ and EncodeIQElement methods to Session I realized that I
wouldn't be able to implement them in terms of SendIQ and SendIQ element
because these use a token reader based API as opposed to the token
writer based API used by the functions in Marshal. However, internally
the marshal functions create a token reader and then copy from it into
the writer, so by exposing this functionality we can make it possible to
create reader or writer based functionality with the marshal package.

Signed-off-by: Sam Whited <sam@samwhited.com>
all: add missing copyright notices

Signed-off-by: Sam Whited <sam@samwhited.com>
all: use xmlstream.Iter and remove internal/iter

The internal/iter package previously contained an API for iterating over
child elements and decoding them lazily.

This is needed by any package that exposes an iterator such as the
roster package, and is mentioned in the documentation
(https://mellium.im/docs/extensions) as the API to use when creating
your own extensions, but it was internal and not actually usable by this
package. Its own doc comment said that it would eventually be exported
when the API stabalized. It hasn't been necessary to change the API
since creating it so it became time to let it graduate to the
mellium.im/xmlstream module where it can be more broadly useful.

This patch bumps the version of xmlstream used and makes the minor
changes necessary to use the xmlstream version of the iterator. It also
removes the old internal/iter package and updates the documentation to
mention its new location as part of xmlstream.

They grow up so fast!

Signed-off-by: Sam Whited <sam@samwhited.com>
docs: add issue templates

Adding issue templates will help guide users to submitting good bug
reports and feature requests that can be actioned without pestering the
OP for more information.

Signed-off-by: Sam Whited <sam@samwhited.com>
all: improve documentation about multiplexers

I noticed that the main package already contained documentation about
the Serve function and writing a handler, but did not mention the mux
package or its more granular handler types.
Similarly, the mux package itself didn't have much in the way of
description and one would be forgiven for thinking that you couldn't
write your own, compatible, muxer.

Improving this documentation will go a long way towards making it easier
to get started with this library.

Signed-off-by: Sam Whited <sam@samwhited.com>
receipts: fix broken doc comment

Fix some copy/pasta from the xtime package that had leaked into
receipts.

Signed-off-by: Sam Whited <sam@samwhited.com>
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:
https://mellium.im/issue/29

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

This patch imlements XEP-0184: Message Delivery Receipts
(https://xmpp.org/extensions/xep-0184.html).

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>
Next