/* io_xmpp_stream.c generated by valac 0.56.19, the Vala compiler
 * generated from io_xmpp_stream.vala, do not modify */

#include "xmpp-vala.h"
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	XMPP_IO_XMPP_STREAM_0_PROPERTY,
	XMPP_IO_XMPP_STREAM_NUM_PROPERTIES
};
static GParamSpec* xmpp_io_xmpp_stream_properties[XMPP_IO_XMPP_STREAM_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_stanza_reader_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_reader_unref (var), NULL)))
#define _xmpp_stanza_writer_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_writer_unref (var), NULL)))
typedef struct _XmppIoXmppStreamDisconnectData XmppIoXmppStreamDisconnectData;
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
typedef struct _XmppIoXmppStreamReadData XmppIoXmppStreamReadData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _XmppIoXmppStreamWriteAsyncData XmppIoXmppStreamWriteAsyncData;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _XmppIoXmppStreamSetupData XmppIoXmppStreamSetupData;
typedef struct _XmppIoXmppStreamReadRootData XmppIoXmppStreamReadRootData;

struct _XmppIoXmppStreamPrivate {
	GIOStream* stream;
};

struct _XmppIoXmppStreamDisconnectData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppIoXmppStream* self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	XmppStanzaWriter* _tmp2_;
	XmppStanzaReader* _tmp3_;
	GIOStream* _tmp4_;
	GError* _tmp5_;
	XmppXmppLog* _tmp6_;
	XmppStanzaWriter* _tmp7_;
	GCancellable* _tmp8_;
	GCancellable* _tmp9_;
	GIOStream* _tmp10_;
	GError* _inner_error0_;
};

struct _XmppIoXmppStreamReadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppIoXmppStream* self;
	XmppStanzaNode* result;
	XmppStanzaReader* reader;
	XmppStanzaReader* _tmp0_;
	XmppStanzaReader* _tmp1_;
	XmppStanzaReader* _tmp2_;
	GError* _tmp3_;
	XmppStanzaNode* node;
	XmppStanzaReader* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppXmppLog* _tmp6_;
	GError* _inner_error0_;
};

struct _XmppIoXmppStreamWriteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppIoXmppStream* self;
	XmppStanzaNode* node;
	gint io_priority;
	GCancellable* cancellable;
	XmppWriteNodeFunc* _tmp0_;
	GCancellable* _tmp1_;
	GCancellable* _tmp2_;
	XmppWriteNodeFunc* _tmp3_;
	XmppStanzaWriter* writer;
	XmppStanzaWriter* _tmp4_;
	XmppStanzaWriter* _tmp5_;
	XmppStanzaWriter* _tmp6_;
	GError* _tmp7_;
	XmppXmppLog* _tmp8_;
	GCancellable* _tmp9_;
	GCancellable* _tmp10_;
	XmppStanzaWriter* _tmp11_;
	GError* _inner_error0_;
};

struct _XmppIoXmppStreamSetupData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppIoXmppStream* self;
	XmppStanzaNode* outs;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppJid* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppStanzaNode* _tmp6_;
	XmppStanzaNode* _tmp7_;
	XmppStanzaNode* _tmp8_;
	XmppStanzaNode* _tmp9_;
	XmppStanzaNode* _tmp10_;
	XmppStanzaNode* _tmp11_;
	XmppStanzaNode* _tmp12_;
	XmppStanzaNode* _tmp13_;
	XmppXmppLog* _tmp14_;
	XmppStanzaNode* _tmp15_;
	XmppStanzaNode* _tmp16_;
	GCancellable* _tmp17_;
	XmppStanzaNode* _tmp18_;
	XmppStanzaNode* _tmp19_;
	GError* _inner_error0_;
};

struct _XmppIoXmppStreamReadRootData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppIoXmppStream* self;
	XmppStanzaNode* result;
	XmppStanzaReader* reader;
	XmppStanzaReader* _tmp0_;
	XmppStanzaReader* _tmp1_;
	XmppStanzaReader* _tmp2_;
	GError* _tmp3_;
	XmppStanzaNode* node;
	XmppStanzaReader* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppXmppLog* _tmp6_;
	GError* _inner_error0_;
};

static gint XmppIoXmppStream_private_offset;
static gpointer xmpp_io_xmpp_stream_parent_class = NULL;

static GType xmpp_write_node_func_get_type_once (void);
static void xmpp_io_xmpp_stream_real_disconnect_data_free (gpointer _data);
static void xmpp_io_xmpp_stream_real_disconnect (XmppXmppStream* base,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
static gboolean xmpp_io_xmpp_stream_real_disconnect_co (XmppIoXmppStreamDisconnectData* _data_);
static void xmpp_io_xmpp_stream_disconnect_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void xmpp_io_xmpp_stream_real_read_data_free (gpointer _data);
static void xmpp_io_xmpp_stream_real_read (XmppXmppStream* base,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
static gboolean xmpp_io_xmpp_stream_real_read_co (XmppIoXmppStreamReadData* _data_);
static void xmpp_io_xmpp_stream_read_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_);
static void xmpp_io_xmpp_stream_real_write (XmppXmppStream* base,
                                     XmppStanzaNode* node,
                                     gint io_priority) G_GNUC_DEPRECATED ;
static void __lambda4_ (XmppIoXmppStream* self,
                 GObject* obj,
                 GAsyncResult* res);
static void ___lambda4__gasync_ready_callback (GObject* source_object,
                                        GAsyncResult* res,
                                        gpointer self);
static void xmpp_io_xmpp_stream_real_write_async_data_free (gpointer _data);
static void xmpp_io_xmpp_stream_real_write_async (XmppXmppStream* base,
                                           XmppStanzaNode* node,
                                           gint io_priority,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static gboolean xmpp_io_xmpp_stream_real_write_async_co (XmppIoXmppStreamWriteAsyncData* _data_);
static void xmpp_io_xmpp_stream_write_async_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
VALA_EXTERN GIOStream* xmpp_io_xmpp_stream_get_stream (XmppIoXmppStream* self);
static void xmpp_io_xmpp_stream_real_setup_data_free (gpointer _data);
static void xmpp_io_xmpp_stream_real_setup (XmppXmppStream* base,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
static gboolean xmpp_io_xmpp_stream_real_setup_co (XmppIoXmppStreamSetupData* _data_);
static void xmpp_io_xmpp_stream_setup_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_);
static void xmpp_io_xmpp_stream_read_root (XmppIoXmppStream* self,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
static XmppStanzaNode* xmpp_io_xmpp_stream_read_root_finish (XmppIoXmppStream* self,
                                                      GAsyncResult* _res_,
                                                      GError** error);
static void xmpp_io_xmpp_stream_read_root_data_free (gpointer _data);
static gboolean xmpp_io_xmpp_stream_read_root_co (XmppIoXmppStreamReadRootData* _data_);
static void xmpp_io_xmpp_stream_read_root_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void xmpp_io_xmpp_stream_finalize (GObject * obj);
static GType xmpp_io_xmpp_stream_get_type_once (void);

void
xmpp_write_node_func_write_stanza (XmppWriteNodeFunc* self,
                                   XmppXmppStream* stream,
                                   XmppStanzaNode* node,
                                   gint io_priority,
                                   GCancellable* cancellable,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	XmppWriteNodeFuncIface* _iface_;
	_iface_ = XMPP_WRITE_NODE_FUNC_GET_INTERFACE (self);
	if (_iface_->write_stanza) {
		_iface_->write_stanza (self, stream, node, io_priority, cancellable, _callback_, _user_data_);
	}
}

void
xmpp_write_node_func_write_stanza_finish (XmppWriteNodeFunc* self,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	XmppWriteNodeFuncIface* _iface_;
	_iface_ = XMPP_WRITE_NODE_FUNC_GET_INTERFACE (self);
	if (_iface_->write_stanza_finish) {
		_iface_->write_stanza_finish (self, _res_, error);
	}
}

static void
xmpp_write_node_func_default_init (XmppWriteNodeFuncIface * iface,
                                   gpointer iface_data)
{
}

static GType
xmpp_write_node_func_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppWriteNodeFuncIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_write_node_func_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType xmpp_write_node_func_type_id;
	xmpp_write_node_func_type_id = g_type_register_static (G_TYPE_INTERFACE, "XmppWriteNodeFunc", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (xmpp_write_node_func_type_id, G_TYPE_OBJECT);
	return xmpp_write_node_func_type_id;
}

GType
xmpp_write_node_func_get_type (void)
{
	static volatile gsize xmpp_write_node_func_type_id__once = 0;
	if (g_once_init_enter (&xmpp_write_node_func_type_id__once)) {
		GType xmpp_write_node_func_type_id;
		xmpp_write_node_func_type_id = xmpp_write_node_func_get_type_once ();
		g_once_init_leave (&xmpp_write_node_func_type_id__once, xmpp_write_node_func_type_id);
	}
	return xmpp_write_node_func_type_id__once;
}

static inline gpointer
xmpp_io_xmpp_stream_get_instance_private (XmppIoXmppStream* self)
{
	return G_STRUCT_MEMBER_P (self, XmppIoXmppStream_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

XmppIoXmppStream*
xmpp_io_xmpp_stream_construct (GType object_type,
                               XmppJid* remote_name,
                               GCancellable* cancellable)
{
	XmppIoXmppStream * self = NULL;
	GCancellable* _tmp0_ = NULL;
	GCancellable* _tmp1_;
	GCancellable* _tmp3_;
	g_return_val_if_fail (remote_name != NULL, NULL);
	self = (XmppIoXmppStream*) xmpp_xmpp_stream_construct (object_type, remote_name);
	_tmp1_ = _g_object_ref0 (cancellable);
	_tmp0_ = _tmp1_;
	if (_tmp0_ == NULL) {
		GCancellable* _tmp2_;
		_tmp2_ = g_cancellable_new ();
		_g_object_unref0 (_tmp0_);
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	_g_object_unref0 (self->cancellable);
	self->cancellable = _tmp3_;
	_g_object_unref0 (_tmp0_);
	return self;
}

void
xmpp_io_xmpp_stream_cancel (XmppIoXmppStream* self)
{
	GCancellable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->cancellable;
	g_cancellable_cancel (_tmp0_);
}

static void
xmpp_io_xmpp_stream_real_disconnect_data_free (gpointer _data)
{
	XmppIoXmppStreamDisconnectData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppIoXmppStreamDisconnectData, _data_);
}

static void
xmpp_io_xmpp_stream_real_disconnect (XmppXmppStream* base,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	XmppIoXmppStream * self;
	XmppIoXmppStreamDisconnectData* _data_;
	XmppIoXmppStream* _tmp0_;
	self = (XmppIoXmppStream*) base;
	_data_ = g_slice_new0 (XmppIoXmppStreamDisconnectData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_io_xmpp_stream_real_disconnect_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	xmpp_io_xmpp_stream_real_disconnect_co (_data_);
}

static void
xmpp_io_xmpp_stream_disconnect_finish (XmppXmppStream* base,
                                       GAsyncResult* _res_,
                                       GError** error)
{
	XmppIoXmppStreamDisconnectData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
xmpp_io_xmpp_stream_disconnect_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	XmppIoXmppStreamDisconnectData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_io_xmpp_stream_real_disconnect_co (_data_);
}

static gboolean
xmpp_io_xmpp_stream_real_disconnect_co (XmppIoXmppStreamDisconnectData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	((XmppXmppStream*) _data_->self)->disconnected = TRUE;
	xmpp_io_xmpp_stream_cancel (_data_->self);
	_data_->_tmp2_ = _data_->self->writer;
	if (_data_->_tmp2_ == NULL) {
		_data_->_tmp1_ = TRUE;
	} else {
		_data_->_tmp3_ = _data_->self->reader;
		_data_->_tmp1_ = _data_->_tmp3_ == NULL;
	}
	if (_data_->_tmp1_) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp4_ = _data_->self->priv->stream;
		_data_->_tmp0_ = _data_->_tmp4_ == NULL;
	}
	if (_data_->_tmp0_) {
		_data_->_tmp5_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CLOSED, "trying to disconnect, but no stream open");
		_data_->_inner_error0_ = _data_->_tmp5_;
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp6_ = ((XmppXmppStream*) _data_->self)->log;
	xmpp_xmpp_log_str (_data_->_tmp6_, "OUT", "</stream:stream>", (XmppXmppStream*) _data_->self);
	_data_->_tmp7_ = _data_->self->writer;
	_data_->_tmp8_ = g_cancellable_new ();
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_state_ = 1;
	xmpp_stanza_writer_write (_data_->_tmp7_, "</stream:stream>", G_PRIORITY_LOW, _data_->_tmp9_, xmpp_io_xmpp_stream_disconnect_ready, _data_);
	return FALSE;
	_state_1:
	xmpp_stanza_writer_write_finish (_data_->_tmp7_, _data_->_res_, &_data_->_inner_error0_);
	_g_object_unref0 (_data_->_tmp9_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp10_ = _data_->self->priv->stream;
	_data_->_state_ = 2;
	g_io_stream_close_async (_data_->_tmp10_, G_PRIORITY_DEFAULT, NULL, xmpp_io_xmpp_stream_disconnect_ready, _data_);
	return FALSE;
	_state_2:
	g_io_stream_close_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
xmpp_io_xmpp_stream_reset_stream (XmppIoXmppStream* self,
                                  GIOStream* stream)
{
	GIOStream* _tmp0_;
	GInputStream* _tmp1_;
	GInputStream* _tmp2_;
	GCancellable* _tmp3_;
	XmppStanzaReader* _tmp4_;
	GOutputStream* _tmp5_;
	GOutputStream* _tmp6_;
	GCancellable* _tmp7_;
	XmppStanzaWriter* _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	_tmp0_ = _g_object_ref0 (stream);
	_g_object_unref0 (self->priv->stream);
	self->priv->stream = _tmp0_;
	_tmp1_ = g_io_stream_get_input_stream (stream);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->cancellable;
	_tmp4_ = xmpp_stanza_reader_new_for_stream (_tmp2_, _tmp3_);
	_xmpp_stanza_reader_unref0 (self->reader);
	self->reader = _tmp4_;
	_tmp5_ = g_io_stream_get_output_stream (stream);
	_tmp6_ = _tmp5_;
	_tmp7_ = self->cancellable;
	_tmp8_ = xmpp_stanza_writer_new_for_stream (_tmp6_, _tmp7_);
	_xmpp_stanza_writer_unref0 (self->writer);
	self->writer = _tmp8_;
	xmpp_xmpp_stream_require_setup ((XmppXmppStream*) self);
}

static void
xmpp_io_xmpp_stream_real_read_data_free (gpointer _data)
{
	XmppIoXmppStreamReadData* _data_;
	_data_ = _data;
	_xmpp_stanza_entry_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppIoXmppStreamReadData, _data_);
}

static void
xmpp_io_xmpp_stream_real_read (XmppXmppStream* base,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	XmppIoXmppStream * self;
	XmppIoXmppStreamReadData* _data_;
	XmppIoXmppStream* _tmp0_;
	self = (XmppIoXmppStream*) base;
	_data_ = g_slice_new0 (XmppIoXmppStreamReadData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_io_xmpp_stream_real_read_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	xmpp_io_xmpp_stream_real_read_co (_data_);
}

static XmppStanzaNode*
xmpp_io_xmpp_stream_read_finish (XmppXmppStream* base,
                                 GAsyncResult* _res_,
                                 GError** error)
{
	XmppStanzaNode* result;
	XmppIoXmppStreamReadData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gpointer
_xmpp_stanza_reader_ref0 (gpointer self)
{
	return self ? xmpp_stanza_reader_ref (self) : NULL;
}

static void
xmpp_io_xmpp_stream_read_ready (GObject* source_object,
                                GAsyncResult* _res_,
                                gpointer _user_data_)
{
	XmppIoXmppStreamReadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_io_xmpp_stream_real_read_co (_data_);
}

static gboolean
xmpp_io_xmpp_stream_real_read_co (XmppIoXmppStreamReadData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->reader;
	_data_->_tmp1_ = _xmpp_stanza_reader_ref0 (_data_->_tmp0_);
	_data_->reader = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->reader;
	if (_data_->_tmp2_ == NULL) {
		_data_->_tmp3_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "trying to read, but no stream open");
		_data_->_inner_error0_ = _data_->_tmp3_;
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp4_ = _data_->reader;
	_data_->_state_ = 1;
	xmpp_stanza_reader_read_node (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, XMPP_TYPE_STANZA_READER, XmppStanzaReader), xmpp_io_xmpp_stream_read_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp5_ = xmpp_stanza_reader_read_node_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, XMPP_TYPE_STANZA_READER, XmppStanzaReader), _data_->_res_, &_data_->_inner_error0_);
	_data_->node = _data_->_tmp5_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp6_ = ((XmppXmppStream*) _data_->self)->log;
	xmpp_xmpp_log_node (_data_->_tmp6_, "IN", _data_->node, (XmppXmppStream*) _data_->self);
	_data_->result = _data_->node;
	_xmpp_stanza_reader_unref0 (_data_->reader);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
__lambda4_ (XmppIoXmppStream* self,
            GObject* obj,
            GAsyncResult* res)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (res != NULL);
	{
		xmpp_xmpp_stream_write_finish ((XmppXmppStream*) self, res, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = e;
		_tmp1_ = _tmp0_->message;
		g_warning ("io_xmpp_stream.vala:56: Error while writing: %s", _tmp1_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
___lambda4__gasync_ready_callback (GObject* source_object,
                                   GAsyncResult* res,
                                   gpointer self)
{
	__lambda4_ ((XmppIoXmppStream*) self, source_object, res);
	g_object_unref (self);
}

static void
xmpp_io_xmpp_stream_real_write (XmppXmppStream* base,
                                XmppStanzaNode* node,
                                gint io_priority)
{
	XmppIoXmppStream * self;
	self = (XmppIoXmppStream*) base;
	g_return_if_fail (node != NULL);
	xmpp_xmpp_stream_write_async ((XmppXmppStream*) self, node, io_priority, NULL, ___lambda4__gasync_ready_callback, g_object_ref (self));
}

static void
xmpp_io_xmpp_stream_real_write_async_data_free (gpointer _data)
{
	XmppIoXmppStreamWriteAsyncData* _data_;
	_data_ = _data;
	_xmpp_stanza_entry_unref0 (_data_->node);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppIoXmppStreamWriteAsyncData, _data_);
}

static gpointer
_xmpp_stanza_entry_ref0 (gpointer self)
{
	return self ? xmpp_stanza_entry_ref (self) : NULL;
}

static void
xmpp_io_xmpp_stream_real_write_async (XmppXmppStream* base,
                                      XmppStanzaNode* node,
                                      gint io_priority,
                                      GCancellable* cancellable,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	XmppIoXmppStream * self;
	XmppIoXmppStreamWriteAsyncData* _data_;
	XmppIoXmppStream* _tmp0_;
	XmppStanzaNode* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (node != NULL);
	self = (XmppIoXmppStream*) base;
	_data_ = g_slice_new0 (XmppIoXmppStreamWriteAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_io_xmpp_stream_real_write_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _xmpp_stanza_entry_ref0 (node);
	_xmpp_stanza_entry_unref0 (_data_->node);
	_data_->node = _tmp1_;
	_data_->io_priority = io_priority;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	xmpp_io_xmpp_stream_real_write_async_co (_data_);
}

static void
xmpp_io_xmpp_stream_write_finish (XmppXmppStream* base,
                                  GAsyncResult* _res_,
                                  GError** error)
{
	XmppIoXmppStreamWriteAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
xmpp_io_xmpp_stream_write_async_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	XmppIoXmppStreamWriteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_io_xmpp_stream_real_write_async_co (_data_);
}

static gpointer
_xmpp_stanza_writer_ref0 (gpointer self)
{
	return self ? xmpp_stanza_writer_ref (self) : NULL;
}

static gboolean
xmpp_io_xmpp_stream_real_write_async_co (XmppIoXmppStreamWriteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->write_obj;
	if (_data_->_tmp0_ != NULL) {
		_data_->_tmp1_ = _data_->cancellable;
		if (_data_->_tmp1_ == NULL) {
			_data_->_tmp2_ = _data_->self->cancellable;
			_data_->_tmp1_ = _data_->_tmp2_;
		}
		_data_->_tmp3_ = _data_->self->write_obj;
		_data_->_state_ = 1;
		xmpp_write_node_func_write_stanza (_data_->_tmp3_, (XmppXmppStream*) _data_->self, _data_->node, _data_->io_priority, _data_->_tmp1_, xmpp_io_xmpp_stream_write_async_ready, _data_);
		return FALSE;
		_state_1:
		xmpp_write_node_func_write_stanza_finish (_data_->_tmp3_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			if (_data_->_inner_error0_->domain == G_IO_ERROR) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			} else {
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
	} else {
		_data_->_tmp4_ = _data_->self->writer;
		_data_->_tmp5_ = _xmpp_stanza_writer_ref0 (_data_->_tmp4_);
		_data_->writer = _data_->_tmp5_;
		_data_->_tmp6_ = _data_->writer;
		if (_data_->_tmp6_ == NULL) {
			_data_->_tmp7_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "trying to write, but no stream open");
			_data_->_inner_error0_ = _data_->_tmp7_;
			if (_data_->_inner_error0_->domain == G_IO_ERROR) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_xmpp_stanza_writer_unref0 (_data_->writer);
				g_object_unref (_data_->_async_result);
				return FALSE;
			} else {
				_xmpp_stanza_writer_unref0 (_data_->writer);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
		_data_->_tmp8_ = ((XmppXmppStream*) _data_->self)->log;
		xmpp_xmpp_log_node (_data_->_tmp8_, "OUT", _data_->node, (XmppXmppStream*) _data_->self);
		_data_->_tmp9_ = _data_->cancellable;
		if (_data_->_tmp9_ == NULL) {
			_data_->_tmp10_ = _data_->self->cancellable;
			_data_->_tmp9_ = _data_->_tmp10_;
		}
		_data_->_tmp11_ = _data_->writer;
		_data_->_state_ = 2;
		xmpp_stanza_writer_write_node (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, XMPP_TYPE_STANZA_WRITER, XmppStanzaWriter), _data_->node, _data_->io_priority, _data_->_tmp9_, xmpp_io_xmpp_stream_write_async_ready, _data_);
		return FALSE;
		_state_2:
		xmpp_stanza_writer_write_node_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp11_, XMPP_TYPE_STANZA_WRITER, XmppStanzaWriter), _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			if (_data_->_inner_error0_->domain == G_IO_ERROR) {
				g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
				_xmpp_stanza_writer_unref0 (_data_->writer);
				g_object_unref (_data_->_async_result);
				return FALSE;
			} else {
				_xmpp_stanza_writer_unref0 (_data_->writer);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
		_xmpp_stanza_writer_unref0 (_data_->writer);
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

GIOStream*
xmpp_io_xmpp_stream_get_stream (XmppIoXmppStream* self)
{
	GIOStream* _tmp0_;
	GIOStream* _tmp1_;
	GIOStream* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->stream;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
xmpp_io_xmpp_stream_real_setup_data_free (gpointer _data)
{
	XmppIoXmppStreamSetupData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppIoXmppStreamSetupData, _data_);
}

static void
xmpp_io_xmpp_stream_real_setup (XmppXmppStream* base,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	XmppIoXmppStream * self;
	XmppIoXmppStreamSetupData* _data_;
	XmppIoXmppStream* _tmp0_;
	self = (XmppIoXmppStream*) base;
	_data_ = g_slice_new0 (XmppIoXmppStreamSetupData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_io_xmpp_stream_real_setup_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	xmpp_io_xmpp_stream_real_setup_co (_data_);
}

static void
xmpp_io_xmpp_stream_setup_finish (XmppXmppStream* base,
                                  GAsyncResult* _res_,
                                  GError** error)
{
	XmppIoXmppStreamSetupData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
xmpp_io_xmpp_stream_setup_ready (GObject* source_object,
                                 GAsyncResult* _res_,
                                 gpointer _user_data_)
{
	XmppIoXmppStreamSetupData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_io_xmpp_stream_real_setup_co (_data_);
}

static gboolean
xmpp_io_xmpp_stream_real_setup_co (XmppIoXmppStreamSetupData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_stanza_node_new_build ("stream", "http://etherx.jabber.org/streams", NULL, NULL);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = ((XmppXmppStream*) _data_->self)->remote_name;
	_data_->_tmp3_ = xmpp_jid_to_string (_data_->_tmp2_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = xmpp_stanza_node_put_attribute (_data_->_tmp1_, "to", _data_->_tmp4_, NULL);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = xmpp_stanza_node_put_attribute (_data_->_tmp6_, "version", "1.0", NULL);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->_tmp9_ = xmpp_stanza_node_put_attribute (_data_->_tmp8_, "xmlns", "jabber:client", NULL);
	_data_->_tmp10_ = _data_->_tmp9_;
	_data_->_tmp11_ = xmpp_stanza_node_put_attribute (_data_->_tmp10_, "stream", "http://etherx.jabber.org/streams", XMPP_XMLNS_URI);
	_data_->_tmp12_ = _data_->_tmp11_;
	_xmpp_stanza_entry_unref0 (_data_->_tmp10_);
	_xmpp_stanza_entry_unref0 (_data_->_tmp8_);
	_xmpp_stanza_entry_unref0 (_data_->_tmp6_);
	_g_free0 (_data_->_tmp4_);
	_xmpp_stanza_entry_unref0 (_data_->_tmp1_);
	_data_->outs = _data_->_tmp12_;
	_data_->_tmp13_ = _data_->outs;
	_data_->_tmp13_->has_nodes = TRUE;
	_data_->_tmp14_ = ((XmppXmppStream*) _data_->self)->log;
	_data_->_tmp15_ = _data_->outs;
	xmpp_xmpp_log_node (_data_->_tmp14_, "OUT ROOT", _data_->_tmp15_, (XmppXmppStream*) _data_->self);
	_data_->_tmp16_ = _data_->outs;
	_data_->_tmp17_ = _data_->self->cancellable;
	_data_->_state_ = 1;
	xmpp_xmpp_stream_write_async ((XmppXmppStream*) _data_->self, _data_->_tmp16_, G_PRIORITY_HIGH, _data_->_tmp17_, xmpp_io_xmpp_stream_setup_ready, _data_);
	return FALSE;
	_state_1:
	xmpp_xmpp_stream_write_finish ((XmppXmppStream*) _data_->self, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_xmpp_stanza_entry_unref0 (_data_->outs);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_xmpp_stanza_entry_unref0 (_data_->outs);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_state_ = 2;
	xmpp_io_xmpp_stream_read_root (_data_->self, xmpp_io_xmpp_stream_setup_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp19_ = xmpp_io_xmpp_stream_read_root_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp18_ = _data_->_tmp19_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_xmpp_stanza_entry_unref0 (_data_->outs);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_xmpp_stanza_entry_unref0 (_data_->outs);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	g_signal_emit_by_name ((XmppXmppStream*) _data_->self, "received-root-node", (XmppXmppStream*) _data_->self, _data_->_tmp18_);
	((XmppXmppStream*) _data_->self)->setup_needed = FALSE;
	_xmpp_stanza_entry_unref0 (_data_->_tmp18_);
	_xmpp_stanza_entry_unref0 (_data_->outs);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
xmpp_io_xmpp_stream_read_root_data_free (gpointer _data)
{
	XmppIoXmppStreamReadRootData* _data_;
	_data_ = _data;
	_xmpp_stanza_entry_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppIoXmppStreamReadRootData, _data_);
}

static void
xmpp_io_xmpp_stream_read_root (XmppIoXmppStream* self,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	XmppIoXmppStreamReadRootData* _data_;
	XmppIoXmppStream* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (XmppIoXmppStreamReadRootData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_io_xmpp_stream_read_root_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	xmpp_io_xmpp_stream_read_root_co (_data_);
}

static XmppStanzaNode*
xmpp_io_xmpp_stream_read_root_finish (XmppIoXmppStream* self,
                                      GAsyncResult* _res_,
                                      GError** error)
{
	XmppStanzaNode* result;
	XmppIoXmppStreamReadRootData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
xmpp_io_xmpp_stream_read_root_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	XmppIoXmppStreamReadRootData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_io_xmpp_stream_read_root_co (_data_);
}

static gboolean
xmpp_io_xmpp_stream_read_root_co (XmppIoXmppStreamReadRootData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->reader;
	_data_->_tmp1_ = _xmpp_stanza_reader_ref0 (_data_->_tmp0_);
	_data_->reader = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->reader;
	if (_data_->_tmp2_ == NULL) {
		_data_->_tmp3_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "trying to read, but no stream open");
		_data_->_inner_error0_ = _data_->_tmp3_;
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp4_ = _data_->reader;
	_data_->_state_ = 1;
	xmpp_stanza_reader_read_root_node (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, XMPP_TYPE_STANZA_READER, XmppStanzaReader), xmpp_io_xmpp_stream_read_root_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp5_ = xmpp_stanza_reader_read_root_node_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, XMPP_TYPE_STANZA_READER, XmppStanzaReader), _data_->_res_, &_data_->_inner_error0_);
	_data_->node = _data_->_tmp5_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == G_IO_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_xmpp_stanza_reader_unref0 (_data_->reader);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp6_ = ((XmppXmppStream*) _data_->self)->log;
	xmpp_xmpp_log_node (_data_->_tmp6_, "IN ROOT", _data_->node, (XmppXmppStream*) _data_->self);
	_data_->result = _data_->node;
	_xmpp_stanza_reader_unref0 (_data_->reader);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
xmpp_io_xmpp_stream_class_init (XmppIoXmppStreamClass * klass,
                                gpointer klass_data)
{
	xmpp_io_xmpp_stream_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppIoXmppStream_private_offset);
	((XmppXmppStreamClass *) klass)->disconnect = (void (*) (XmppXmppStream*, GAsyncReadyCallback, gpointer)) xmpp_io_xmpp_stream_real_disconnect;
	((XmppXmppStreamClass *) klass)->disconnect_finish = (void (*) (XmppXmppStream*, GAsyncResult*, GError**)) xmpp_io_xmpp_stream_disconnect_finish;
	((XmppXmppStreamClass *) klass)->read = (void (*) (XmppXmppStream*, GAsyncReadyCallback, gpointer)) xmpp_io_xmpp_stream_real_read;
	((XmppXmppStreamClass *) klass)->read_finish = (XmppStanzaNode* (*) (XmppXmppStream*, GAsyncResult*, GError**)) xmpp_io_xmpp_stream_read_finish;
	((XmppXmppStreamClass *) klass)->write = (void (*) (XmppXmppStream*, XmppStanzaNode*, gint)) xmpp_io_xmpp_stream_real_write;
	((XmppXmppStreamClass *) klass)->write_async = (void (*) (XmppXmppStream*, XmppStanzaNode*, gint, GCancellable*, GAsyncReadyCallback, gpointer)) xmpp_io_xmpp_stream_real_write_async;
	((XmppXmppStreamClass *) klass)->write_finish = (void (*) (XmppXmppStream*, GAsyncResult*, GError**)) xmpp_io_xmpp_stream_write_finish;
	((XmppXmppStreamClass *) klass)->setup = (void (*) (XmppXmppStream*, GAsyncReadyCallback, gpointer)) xmpp_io_xmpp_stream_real_setup;
	((XmppXmppStreamClass *) klass)->setup_finish = (void (*) (XmppXmppStream*, GAsyncResult*, GError**)) xmpp_io_xmpp_stream_setup_finish;
	G_OBJECT_CLASS (klass)->finalize = xmpp_io_xmpp_stream_finalize;
}

static void
xmpp_io_xmpp_stream_instance_init (XmppIoXmppStream * self,
                                   gpointer klass)
{
	self->priv = xmpp_io_xmpp_stream_get_instance_private (self);
	self->write_obj = NULL;
}

static void
xmpp_io_xmpp_stream_finalize (GObject * obj)
{
	XmppIoXmppStream * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_TYPE_IO_XMPP_STREAM, XmppIoXmppStream);
	_g_object_unref0 (self->priv->stream);
	_g_object_unref0 (self->cancellable);
	_xmpp_stanza_reader_unref0 (self->reader);
	_xmpp_stanza_writer_unref0 (self->writer);
	_g_object_unref0 (self->write_obj);
	G_OBJECT_CLASS (xmpp_io_xmpp_stream_parent_class)->finalize (obj);
}

static GType
xmpp_io_xmpp_stream_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppIoXmppStreamClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_io_xmpp_stream_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppIoXmppStream), 0, (GInstanceInitFunc) xmpp_io_xmpp_stream_instance_init, NULL };
	GType xmpp_io_xmpp_stream_type_id;
	xmpp_io_xmpp_stream_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM, "XmppIoXmppStream", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	XmppIoXmppStream_private_offset = g_type_add_instance_private (xmpp_io_xmpp_stream_type_id, sizeof (XmppIoXmppStreamPrivate));
	return xmpp_io_xmpp_stream_type_id;
}

GType
xmpp_io_xmpp_stream_get_type (void)
{
	static volatile gsize xmpp_io_xmpp_stream_type_id__once = 0;
	if (g_once_init_enter (&xmpp_io_xmpp_stream_type_id__once)) {
		GType xmpp_io_xmpp_stream_type_id;
		xmpp_io_xmpp_stream_type_id = xmpp_io_xmpp_stream_get_type_once ();
		g_once_init_leave (&xmpp_io_xmpp_stream_type_id__once, xmpp_io_xmpp_stream_type_id);
	}
	return xmpp_io_xmpp_stream_type_id__once;
}

