xeme/xeme

Add a simple unit test for the input stream and fix a few issues
/*
* Copyright (C) 2023 Dodo Developers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DODO_OUTPUT_STREAM_H
#define DODO_OUTPUT_STREAM_H
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <dodo/dodostream.h>
G_BEGIN_DECLS
#define DODO_TYPE_OUTPUT_STREAM (dodo_output_stream_get_type())
G_DECLARE_FINAL_TYPE(DodoOutputStream, dodo_output_stream, DODO, OUTPUT_STREAM, DodoStream)
/**
* dodo_output_stream_new:
* @to: The jid of the recipient.
* @from: The jid of the sender.
* @cancellable: (nullable): A [class@Gio.Cancellable] for the stream.
* Creates a new output stream.
*
* > Note: this is typically only necessary for [class@Client].
*
* Returns: (transfer full): The new instance.
*
* Since: 0.1.0
*/
DodoOutputStream *dodo_output_stream_new(const char *to, const char *from, GCancellable *cancellable);
/**
* dodo_output_stream_start:
* @stream: The instance.
* @output: (transfer none): A [class@Gio.OutputStream] for writing data to the
* server.
* @error: (nullable): A return address for a #GError.
*
* Initiates @output as an outgoing XMPP stream. It is the responsibility of
* the caller to establish any necessary connections as this writes raw XMPP
* data to @output.
*
* Output is handled asynchronously so this function will always return
* immediately. If setup and processing was successful, %TRUE will be returned,
* otherwise %FALSE will be returned with @error set.
*
* Returns: %TRUE on success, otherwise %FALSE with @error set.
*
* Since: 0.1.0
*/
gboolean dodo_output_stream_start(DodoOutputStream *stream, GOutputStream *output, GError **error);
/**
* dodo_output_stream_stop:
* @stream: The instance.
* @error: (nullable): A return address for a #GError.
*
* Stops the stream by sending the ending `</stream>` if possible and then
* closes the output stream.
*
* Returns: %TRUE on success, otherwise %FALSE with @error possibly set.
*
* Since: 0.1.0
*/
gboolean dodo_output_stream_stop(DodoOutputStream *stream, GError **error);
G_END_DECLS
#endif /* DODO_OUTPUT_STREAM_H */