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

#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gobject/gvaluecollector.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

#define XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM (xmpp_xep_stream_management_module_queue_item_get_type ())
#define XMPP_XEP_STREAM_MANAGEMENT_MODULE_QUEUE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM, XmppXepStreamManagementModuleQueueItem))
#define XMPP_XEP_STREAM_MANAGEMENT_MODULE_QUEUE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM, XmppXepStreamManagementModuleQueueItemClass))
#define XMPP_XEP_STREAM_MANAGEMENT_MODULE_IS_QUEUE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM))
#define XMPP_XEP_STREAM_MANAGEMENT_MODULE_IS_QUEUE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM))
#define XMPP_XEP_STREAM_MANAGEMENT_MODULE_QUEUE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM, XmppXepStreamManagementModuleQueueItemClass))

typedef struct _XmppXepStreamManagementModuleQueueItem XmppXepStreamManagementModuleQueueItem;
typedef struct _XmppXepStreamManagementModuleQueueItemClass XmppXepStreamManagementModuleQueueItemClass;
enum  {
	XMPP_XEP_STREAM_MANAGEMENT_MODULE_0_PROPERTY,
	XMPP_XEP_STREAM_MANAGEMENT_MODULE_SESSION_ID_PROPERTY,
	XMPP_XEP_STREAM_MANAGEMENT_MODULE_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_stream_management_module_properties[XMPP_XEP_STREAM_MANAGEMENT_MODULE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _XmppXepStreamManagementModuleQueueItemPrivate XmppXepStreamManagementModuleQueueItemPrivate;
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _XmppXepStreamManagementModuleWriteStanzaData XmppXepStreamManagementModuleWriteStanzaData;
#define _xmpp_xep_stream_management_module_queue_item_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_stream_management_module_queue_item_unref (var), NULL)))
#define _xmpp_stanza_writer_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_writer_unref (var), NULL)))
typedef struct _XmppXepStreamManagementModuleWriteNodeData XmppXepStreamManagementModuleWriteNodeData;
#define _gee_promise_unref0(var) ((var == NULL) ? NULL : (var = (gee_promise_unref (var), NULL)))
typedef struct _XmppXepStreamManagementModuleParamSpecQueueItem XmppXepStreamManagementModuleParamSpecQueueItem;
enum  {
	XMPP_XEP_STREAM_MANAGEMENT_FLAG_0_PROPERTY,
	XMPP_XEP_STREAM_MANAGEMENT_FLAG_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_stream_management_flag_properties[XMPP_XEP_STREAM_MANAGEMENT_FLAG_NUM_PROPERTIES];

struct _XmppXepStreamManagementModulePrivate {
	gchar* _session_id;
	GeeHashMap* in_flight_stanzas;
	GeeQueue* node_queue;
};

struct _XmppXepStreamManagementModuleQueueItem {
	GTypeInstance parent_instance;
	volatile int ref_count;
	XmppXepStreamManagementModuleQueueItemPrivate * priv;
	XmppStanzaNode* node;
	gint io_priority;
	GCancellable* cancellable;
	GeePromise* promise;
};

struct _XmppXepStreamManagementModuleQueueItemClass {
	GTypeClass parent_class;
	void (*finalize) (XmppXepStreamManagementModuleQueueItem *self);
};

struct _XmppXepStreamManagementModuleWriteStanzaData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXepStreamManagementModule* self;
	XmppXmppStream* stream;
	XmppStanzaNode* node;
	gint io_priority;
	GCancellable* cancellable;
	GeeFuture* future;
	GeeFuture* _tmp0_;
	GeeFuture* _tmp1_;
	GError* e;
	GError* _tmp2_;
	GError* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError* _tmp7_;
	GError* _tmp8_;
	GError* _tmp9_;
	GeeFuture* _tmp10_;
	GError* _tmp11_;
	GError* _tmp12_;
	GeeFuture* _tmp13_;
	GError* _tmp14_;
	GError* _tmp15_;
	GError* _tmp16_;
	GeeFuture* _tmp17_;
	GError* _tmp18_;
	GError* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	GError* _tmp23_;
	GError* _tmp24_;
	GError* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	GError* _tmp29_;
	GError* _tmp30_;
	GError* _inner_error0_;
};

struct _XmppXepStreamManagementModuleWriteNodeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXepStreamManagementModule* self;
	XmppXmppStream* stream;
	XmppStanzaNode* node;
	gint io_priority;
	GCancellable* cancellable;
	XmppStanzaWriter* writer;
	XmppStanzaWriter* _tmp0_;
	XmppStanzaWriter* _tmp1_;
	XmppStanzaWriter* _tmp2_;
	XmppXmppLog* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	XmppStanzaNode* r_node;
	XmppStanzaNode* _tmp9_;
	XmppStanzaNode* _tmp10_;
	XmppStanzaNode* _tmp11_;
	XmppStanzaNode* _tmp12_;
	XmppXmppLog* _tmp13_;
	XmppStanzaNode* _tmp14_;
	XmppStanzaWriter* _tmp15_;
	XmppStanzaNode* _tmp16_;
	XmppStanzaWriter* _tmp17_;
	GError* _inner_error0_;
};

struct _XmppXepStreamManagementModuleParamSpecQueueItem {
	GParamSpec parent_instance;
};

static gint XmppXepStreamManagementModule_private_offset;
static gpointer xmpp_xep_stream_management_module_parent_class = NULL;
XmppModuleIdentity* xmpp_xep_stream_management_module_IDENTITY = NULL;
static gpointer xmpp_xep_stream_management_module_queue_item_parent_class = NULL;
static XmppWriteNodeFuncIface * xmpp_xep_stream_management_module_xmpp_write_node_func_parent_iface = NULL;
static gpointer xmpp_xep_stream_management_flag_parent_class = NULL;
XmppFlagIdentity* xmpp_xep_stream_management_flag_IDENTITY = NULL;

static gpointer xmpp_xep_stream_management_module_queue_item_ref (gpointer instance);
static void xmpp_xep_stream_management_module_queue_item_unref (gpointer instance);
static GParamSpec* xmpp_xep_stream_management_module_param_spec_queue_item (const gchar* name,
                                                                     const gchar* nick,
                                                                     const gchar* blurb,
                                                                     GType object_type,
                                                                     GParamFlags flags) G_GNUC_UNUSED ;
static void xmpp_xep_stream_management_module_value_set_queue_item (GValue* value,
                                                             gpointer v_object) G_GNUC_UNUSED ;
static void xmpp_xep_stream_management_module_value_take_queue_item (GValue* value,
                                                              gpointer v_object) G_GNUC_UNUSED ;
static gpointer xmpp_xep_stream_management_module_value_get_queue_item (const GValue* value) G_GNUC_UNUSED ;
static GType xmpp_xep_stream_management_module_queue_item_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static gint _xmpp_xep_stream_management_module_node_queue_lambda26_ (XmppXepStreamManagementModuleQueueItem* a,
                                                              XmppXepStreamManagementModuleQueueItem* b);
static gint __xmpp_xep_stream_management_module_node_queue_lambda26__gcompare_data_func (gconstpointer a,
                                                                                  gconstpointer b,
                                                                                  gpointer self);
static void xmpp_xep_stream_management_module_real_write_stanza_data_free (gpointer _data);
static void xmpp_xep_stream_management_module_real_write_stanza (XmppWriteNodeFunc* base,
                                                          XmppXmppStream* stream,
                                                          XmppStanzaNode* node,
                                                          gint io_priority,
                                                          GCancellable* cancellable,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
static gboolean xmpp_xep_stream_management_module_real_write_stanza_co (XmppXepStreamManagementModuleWriteStanzaData* _data_);
static GeeFuture* xmpp_xep_stream_management_module_enqueue_stanza (XmppXepStreamManagementModule* self,
                                                             XmppXmppStream* stream,
                                                             XmppStanzaNode* node,
                                                             gint io_priority,
                                                             GCancellable* cancellable);
static void xmpp_xep_stream_management_module_write_stanza_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static XmppXepStreamManagementModuleQueueItem* xmpp_xep_stream_management_module_queue_item_new (XmppStanzaNode* node,
                                                                                          gint io_priority,
                                                                                          GCancellable* cancellable);
static XmppXepStreamManagementModuleQueueItem* xmpp_xep_stream_management_module_queue_item_construct (GType object_type,
                                                                                                XmppStanzaNode* node,
                                                                                                gint io_priority,
                                                                                                GCancellable* cancellable);
static void xmpp_xep_stream_management_module_check_queue (XmppXepStreamManagementModule* self,
                                                    XmppXmppStream* stream);
static void xmpp_xep_stream_management_module_write_node_data_free (gpointer _data);
VALA_EXTERN void xmpp_xep_stream_management_module_write_node (XmppXepStreamManagementModule* self,
                                                   XmppXmppStream* stream,
                                                   XmppStanzaNode* node,
                                                   gint io_priority,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
VALA_EXTERN void xmpp_xep_stream_management_module_write_node_finish (XmppXepStreamManagementModule* self,
                                                          GAsyncResult* _res_);
static gboolean xmpp_xep_stream_management_module_write_node_co (XmppXepStreamManagementModuleWriteNodeData* _data_);
static void xmpp_xep_stream_management_module_write_node_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static void xmpp_xep_stream_management_module_real_attach (XmppXmppStreamModule* base,
                                                    XmppXmppStream* stream);
static void xmpp_xep_stream_management_module_check_enable (XmppXepStreamManagementModule* self,
                                                     XmppXmppStream* stream);
static void _xmpp_xep_stream_management_module_check_enable_xmpp_bind_module_bound_to_resource (XmppBindModule* _sender,
                                                                                         XmppXmppStream* stream,
                                                                                         XmppJid* my_jid,
                                                                                         gpointer self);
static void xmpp_xep_stream_management_module_check_resume (XmppXepStreamManagementModule* self,
                                                     XmppXmppStream* stream);
static void _xmpp_xep_stream_management_module_check_resume_xmpp_xmpp_stream_received_features_node (XmppXmppStream* _sender,
                                                                                              XmppXmppStream* stream,
                                                                                              gpointer self);
static void xmpp_xep_stream_management_module_on_received_nonza (XmppXepStreamManagementModule* self,
                                                          XmppXmppStream* stream,
                                                          XmppStanzaNode* node);
static void _xmpp_xep_stream_management_module_on_received_nonza_xmpp_xmpp_stream_received_nonza (XmppXmppStream* _sender,
                                                                                           XmppXmppStream* stream,
                                                                                           XmppStanzaNode* node,
                                                                                           gpointer self);
static void xmpp_xep_stream_management_module_on_stanza_received (XmppXepStreamManagementModule* self,
                                                           XmppXmppStream* stream,
                                                           XmppStanzaNode* node);
static void _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_message_stanza (XmppXmppStream* _sender,
                                                                                                     XmppXmppStream* stream,
                                                                                                     XmppStanzaNode* node,
                                                                                                     gpointer self);
static void _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_presence_stanza (XmppXmppStream* _sender,
                                                                                                      XmppXmppStream* stream,
                                                                                                      XmppStanzaNode* node,
                                                                                                      gpointer self);
static void _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_iq_stanza (XmppXmppStream* _sender,
                                                                                                XmppXmppStream* stream,
                                                                                                XmppStanzaNode* node,
                                                                                                gpointer self);
static void xmpp_xep_stream_management_module_real_detach (XmppXmppStreamModule* base,
                                                    XmppXmppStream* stream);
static gboolean xmpp_xep_stream_management_module_real_mandatory_outstanding (XmppXmppStreamNegotiationModule* base,
                                                                       XmppXmppStream* stream);
static gboolean xmpp_xep_stream_management_module_real_negotiation_active (XmppXmppStreamNegotiationModule* base,
                                                                    XmppXmppStream* stream);
static gchar* xmpp_xep_stream_management_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_xep_stream_management_module_real_get_id (XmppXmppStreamModule* base);
static gboolean xmpp_xep_stream_management_module_stream_has_sm_feature (XmppXepStreamManagementModule* self,
                                                                  XmppXmppStream* stream);
static void xmpp_xep_stream_management_module_send_ack (XmppXepStreamManagementModule* self,
                                                 XmppXmppStream* stream);
static void xmpp_xep_stream_management_module_handle_ack (XmppXepStreamManagementModule* self,
                                                   XmppXmppStream* stream,
                                                   XmppStanzaNode* node);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      gssize stack_length,
                                      const gchar* needle);
static void xmpp_xep_stream_management_module_handle_incoming_h (XmppXepStreamManagementModule* self,
                                                          XmppXmppStream* stream,
                                                          gint h);
static void xmpp_xep_stream_management_module_queue_item_finalize (XmppXepStreamManagementModuleQueueItem * obj);
static GType xmpp_xep_stream_management_module_queue_item_get_type_once (void);
static void xmpp_xep_stream_management_module_finalize (GObject * obj);
static GType xmpp_xep_stream_management_module_get_type_once (void);
static void _vala_xmpp_xep_stream_management_module_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec);
static void _vala_xmpp_xep_stream_management_module_set_property (GObject * object,
                                                           guint property_id,
                                                           const GValue * value,
                                                           GParamSpec * pspec);
static gchar* xmpp_xep_stream_management_flag_real_get_ns (XmppXmppStreamFlag* base);
static gchar* xmpp_xep_stream_management_flag_real_get_id (XmppXmppStreamFlag* base);
static void xmpp_xep_stream_management_flag_finalize (GObject * obj);
static GType xmpp_xep_stream_management_flag_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
xmpp_xep_stream_management_module_get_instance_private (XmppXepStreamManagementModule* self)
{
	return G_STRUCT_MEMBER_P (self, XmppXepStreamManagementModule_private_offset);
}

static gint
_xmpp_xep_stream_management_module_node_queue_lambda26_ (XmppXepStreamManagementModuleQueueItem* a,
                                                         XmppXepStreamManagementModuleQueueItem* b)
{
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	result = a->io_priority - b->io_priority;
	return result;
}

static gint
__xmpp_xep_stream_management_module_node_queue_lambda26__gcompare_data_func (gconstpointer a,
                                                                             gconstpointer b,
                                                                             gpointer self)
{
	gint result;
	result = _xmpp_xep_stream_management_module_node_queue_lambda26_ ((XmppXepStreamManagementModuleQueueItem*) a, (XmppXepStreamManagementModuleQueueItem*) b);
	return result;
}

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

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

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

static void
xmpp_xep_stream_management_module_real_write_stanza (XmppWriteNodeFunc* base,
                                                     XmppXmppStream* stream,
                                                     XmppStanzaNode* node,
                                                     gint io_priority,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	XmppXepStreamManagementModule * self;
	XmppXepStreamManagementModuleWriteStanzaData* _data_;
	XmppXepStreamManagementModule* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppStanzaNode* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (node != NULL);
	self = (XmppXepStreamManagementModule*) base;
	_data_ = g_slice_new0 (XmppXepStreamManagementModuleWriteStanzaData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_stream_management_module_real_write_stanza_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _xmpp_stanza_entry_ref0 (node);
	_xmpp_stanza_entry_unref0 (_data_->node);
	_data_->node = _tmp2_;
	_data_->io_priority = io_priority;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	xmpp_xep_stream_management_module_real_write_stanza_co (_data_);
}

static void
xmpp_xep_stream_management_module_write_stanza_finish (XmppWriteNodeFunc* base,
                                                       GAsyncResult* _res_,
                                                       GError** error)
{
	XmppXepStreamManagementModuleWriteStanzaData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
xmpp_xep_stream_management_module_write_stanza_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	XmppXepStreamManagementModuleWriteStanzaData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_xep_stream_management_module_real_write_stanza_co (_data_);
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static gboolean
xmpp_xep_stream_management_module_real_write_stanza_co (XmppXepStreamManagementModuleWriteStanzaData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_xep_stream_management_module_enqueue_stanza (_data_->self, _data_->stream, _data_->node, _data_->io_priority, _data_->cancellable);
	_data_->future = _data_->_tmp0_;
	{
		_data_->_tmp1_ = _data_->future;
		_data_->_state_ = 1;
		gee_future_wait_async (_data_->_tmp1_, xmpp_xep_stream_management_module_write_stanza_ready, _data_);
		return FALSE;
		_state_1:
		gee_future_wait_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			if (_data_->_inner_error0_->domain == GEE_FUTURE_ERROR) {
				goto __catch0_gee_future_error;
			}
			_g_object_unref0 (_data_->future);
			g_critical ("file %s: line %d: unexpected 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;
		}
	}
	goto __finally0;
	__catch0_gee_future_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp2_ = _data_->e;
		if (g_error_matches (_data_->_tmp2_, GEE_FUTURE_ERROR, GEE_FUTURE_ERROR_ABANDON_PROMISE)) {
			_data_->_tmp3_ = _data_->e;
			_data_->_tmp4_ = _data_->_tmp3_->message;
			_data_->_tmp5_ = g_strdup_printf ("Future abandoned: %s", _data_->_tmp4_);
			_data_->_tmp6_ = _data_->_tmp5_;
			_data_->_tmp7_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp6_);
			_data_->_tmp8_ = _data_->_tmp7_;
			_g_free0 (_data_->_tmp6_);
			_data_->_inner_error0_ = _data_->_tmp8_;
			_g_error_free0 (_data_->e);
			goto __finally0;
		} else {
			_data_->_tmp9_ = _data_->e;
			if (g_error_matches (_data_->_tmp9_, GEE_FUTURE_ERROR, GEE_FUTURE_ERROR_EXCEPTION)) {
				_data_->_tmp10_ = _data_->future;
				_data_->_tmp11_ = gee_future_get_exception (_data_->_tmp10_);
				_data_->_tmp12_ = _data_->_tmp11_;
				if (_data_->_tmp12_->domain == G_IO_ERROR) {
					_data_->_tmp13_ = _data_->future;
					_data_->_tmp14_ = gee_future_get_exception (_data_->_tmp13_);
					_data_->_tmp15_ = _data_->_tmp14_;
					_data_->_tmp16_ = _g_error_copy0 ((GError*) _data_->_tmp15_);
					_data_->_inner_error0_ = _data_->_tmp16_;
					_g_error_free0 (_data_->e);
					goto __finally0;
				} else {
					_data_->_tmp17_ = _data_->future;
					_data_->_tmp18_ = gee_future_get_exception (_data_->_tmp17_);
					_data_->_tmp19_ = _data_->_tmp18_;
					_data_->_tmp20_ = _data_->_tmp19_->message;
					_data_->_tmp21_ = g_strdup_printf ("Unknown error %s", _data_->_tmp20_);
					_data_->_tmp22_ = _data_->_tmp21_;
					_data_->_tmp23_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp22_);
					_data_->_tmp24_ = _data_->_tmp23_;
					_g_free0 (_data_->_tmp22_);
					_data_->_inner_error0_ = _data_->_tmp24_;
					_g_error_free0 (_data_->e);
					goto __finally0;
				}
			} else {
				_data_->_tmp25_ = _data_->e;
				_data_->_tmp26_ = _data_->_tmp25_->message;
				_data_->_tmp27_ = g_strdup_printf ("Unknown future error: %s", _data_->_tmp26_);
				_data_->_tmp28_ = _data_->_tmp27_;
				_data_->_tmp29_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp28_);
				_data_->_tmp30_ = _data_->_tmp29_;
				_g_free0 (_data_->_tmp28_);
				_data_->_inner_error0_ = _data_->_tmp30_;
				_g_error_free0 (_data_->e);
				goto __finally0;
			}
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	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_unref0 (_data_->future);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_g_object_unref0 (_data_->future);
			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_object_unref0 (_data_->future);
	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 GeeFuture*
xmpp_xep_stream_management_module_enqueue_stanza (XmppXepStreamManagementModule* self,
                                                  XmppXmppStream* stream,
                                                  XmppStanzaNode* node,
                                                  gint io_priority,
                                                  GCancellable* cancellable)
{
	XmppXepStreamManagementModuleQueueItem* queue_item = NULL;
	XmppXepStreamManagementModuleQueueItem* _tmp0_;
	GeeQueue* _tmp1_;
	GeePromise* _tmp2_;
	GeeFuture* _tmp3_;
	GeeFuture* _tmp4_;
	GeeFuture* _tmp5_;
	GeeFuture* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (stream != NULL, NULL);
	g_return_val_if_fail (node != NULL, NULL);
	_tmp0_ = xmpp_xep_stream_management_module_queue_item_new (node, io_priority, cancellable);
	queue_item = _tmp0_;
	_tmp1_ = self->priv->node_queue;
	gee_queue_offer (_tmp1_, queue_item);
	xmpp_xep_stream_management_module_check_queue (self, stream);
	_tmp2_ = queue_item->promise;
	_tmp3_ = gee_promise_get_future (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	result = _tmp5_;
	_xmpp_xep_stream_management_module_queue_item_unref0 (queue_item);
	return result;
}

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

void
xmpp_xep_stream_management_module_write_node (XmppXepStreamManagementModule* self,
                                              XmppXmppStream* stream,
                                              XmppStanzaNode* node,
                                              gint io_priority,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	XmppXepStreamManagementModuleWriteNodeData* _data_;
	XmppXepStreamManagementModule* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppStanzaNode* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (node != NULL);
	_data_ = g_slice_new0 (XmppXepStreamManagementModuleWriteNodeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_stream_management_module_write_node_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _xmpp_stanza_entry_ref0 (node);
	_xmpp_stanza_entry_unref0 (_data_->node);
	_data_->node = _tmp2_;
	_data_->io_priority = io_priority;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	xmpp_xep_stream_management_module_write_node_co (_data_);
}

void
xmpp_xep_stream_management_module_write_node_finish (XmppXepStreamManagementModule* self,
                                                     GAsyncResult* _res_)
{
	XmppXepStreamManagementModuleWriteNodeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

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

static void
xmpp_xep_stream_management_module_write_node_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	XmppXepStreamManagementModuleWriteNodeData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_xep_stream_management_module_write_node_co (_data_);
}

static gboolean
xmpp_xep_stream_management_module_write_node_co (XmppXepStreamManagementModuleWriteNodeData* _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_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->stream, XMPP_TYPE_IO_XMPP_STREAM, XmppIoXmppStream)->writer;
	_data_->_tmp1_ = _xmpp_stanza_writer_ref0 (_data_->_tmp0_);
	_data_->writer = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->writer;
	if (_data_->_tmp2_ == NULL) {
		_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;
	}
	{
		_data_->_tmp3_ = _data_->stream->log;
		xmpp_xmpp_log_node (_data_->_tmp3_, "OUT", _data_->node, _data_->stream);
		_data_->_tmp6_ = ((XmppStanzaEntry*) _data_->node)->name;
		if (g_strcmp0 (_data_->_tmp6_, "message") == 0) {
			_data_->_tmp5_ = TRUE;
		} else {
			_data_->_tmp7_ = ((XmppStanzaEntry*) _data_->node)->name;
			_data_->_tmp5_ = g_strcmp0 (_data_->_tmp7_, "iq") == 0;
		}
		if (_data_->_tmp5_) {
			_data_->_tmp4_ = TRUE;
		} else {
			_data_->_tmp8_ = ((XmppStanzaEntry*) _data_->node)->name;
			_data_->_tmp4_ = g_strcmp0 (_data_->_tmp8_, "presence") == 0;
		}
		if (_data_->_tmp4_) {
			_data_->_tmp9_ = xmpp_stanza_node_new_build ("r", XMPP_XEP_STREAM_MANAGEMENT_NS_URI, NULL, NULL);
			_data_->_tmp10_ = _data_->_tmp9_;
			_data_->_tmp11_ = xmpp_stanza_node_add_self_xmlns (_data_->_tmp10_);
			_data_->_tmp12_ = _data_->_tmp11_;
			_xmpp_stanza_entry_unref0 (_data_->_tmp10_);
			_data_->r_node = _data_->_tmp12_;
			_data_->_tmp13_ = _data_->stream->log;
			_data_->_tmp14_ = _data_->r_node;
			xmpp_xmpp_log_node (_data_->_tmp13_, "OUT", _data_->_tmp14_, _data_->stream);
			_data_->_tmp15_ = _data_->writer;
			_data_->_tmp16_ = _data_->r_node;
			_data_->_state_ = 1;
			xmpp_stanza_writer_write_nodes (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, XMPP_TYPE_STANZA_WRITER, XmppStanzaWriter), _data_->node, _data_->_tmp16_, _data_->io_priority, _data_->cancellable, xmpp_xep_stream_management_module_write_node_ready, _data_);
			return FALSE;
			_state_1:
			xmpp_stanza_writer_write_nodes_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, XMPP_TYPE_STANZA_WRITER, XmppStanzaWriter), _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_xmpp_stanza_entry_unref0 (_data_->r_node);
				if (_data_->_inner_error0_->domain == G_IO_ERROR) {
					goto __catch0_g_io_error;
				}
				_xmpp_stanza_writer_unref0 (_data_->writer);
				g_critical ("file %s: line %d: unexpected 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_entry_unref0 (_data_->r_node);
		} else {
			_data_->_tmp17_ = _data_->writer;
			_data_->_state_ = 2;
			xmpp_stanza_writer_write_node (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, XMPP_TYPE_STANZA_WRITER, XmppStanzaWriter), _data_->node, _data_->io_priority, _data_->cancellable, xmpp_xep_stream_management_module_write_node_ready, _data_);
			return FALSE;
			_state_2:
			xmpp_stanza_writer_write_node_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, 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) {
					goto __catch0_g_io_error;
				}
				_xmpp_stanza_writer_unref0 (_data_->writer);
				g_critical ("file %s: line %d: unexpected 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;
			}
		}
	}
	goto __finally0;
	__catch0_g_io_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_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;
}

static void
xmpp_xep_stream_management_module_check_queue (XmppXepStreamManagementModule* self,
                                               XmppXmppStream* stream)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	while (TRUE) {
		gboolean _tmp0_ = FALSE;
		GeeQueue* _tmp1_;
		gboolean _tmp2_;
		gboolean _tmp3_;
		XmppXepStreamManagementModuleQueueItem* queue_item = NULL;
		GeeQueue* _tmp7_;
		gpointer _tmp8_;
		XmppStanzaNode* node = NULL;
		XmppXepStreamManagementModuleQueueItem* _tmp15_;
		XmppStanzaNode* _tmp16_;
		XmppStanzaNode* _tmp17_;
		gboolean _tmp18_ = FALSE;
		gboolean _tmp19_ = FALSE;
		XmppStanzaNode* _tmp20_;
		const gchar* _tmp21_;
		XmppStanzaNode* _tmp29_;
		XmppXepStreamManagementModuleQueueItem* _tmp30_;
		XmppXepStreamManagementModuleQueueItem* _tmp31_;
		GCancellable* _tmp32_;
		_tmp1_ = self->priv->node_queue;
		_tmp2_ = gee_collection_get_is_empty ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		if (!_tmp3_) {
			GeeHashMap* _tmp4_;
			gint _tmp5_;
			gint _tmp6_;
			_tmp4_ = self->priv->in_flight_stanzas;
			_tmp5_ = gee_abstract_map_get_size ((GeeAbstractMap*) _tmp4_);
			_tmp6_ = _tmp5_;
			_tmp0_ = _tmp6_ < 10;
		} else {
			_tmp0_ = FALSE;
		}
		if (!_tmp0_) {
			break;
		}
		_tmp7_ = self->priv->node_queue;
		_tmp8_ = gee_queue_poll (_tmp7_);
		queue_item = (XmppXepStreamManagementModuleQueueItem*) _tmp8_;
		{
			XmppXepStreamManagementModuleQueueItem* _tmp9_;
			GCancellable* _tmp10_;
			_tmp9_ = queue_item;
			_tmp10_ = _tmp9_->cancellable;
			g_cancellable_set_error_if_cancelled (_tmp10_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == G_IO_ERROR) {
					goto __catch0_g_io_error;
				}
				_xmpp_xep_stream_management_module_queue_item_unref0 (queue_item);
				g_critical ("file %s: line %d: unexpected 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;
			}
		}
		goto __finally0;
		__catch0_g_io_error:
		{
			GError* e = NULL;
			XmppXepStreamManagementModuleQueueItem* _tmp11_;
			GeePromise* _tmp12_;
			GError* _tmp13_;
			GError* _tmp14_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp11_ = queue_item;
			_tmp12_ = _tmp11_->promise;
			_tmp13_ = e;
			_tmp14_ = _g_error_copy0 (_tmp13_);
			gee_promise_set_exception (_tmp12_, _tmp14_);
			_g_error_free0 (e);
			_xmpp_xep_stream_management_module_queue_item_unref0 (queue_item);
			continue;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_xmpp_xep_stream_management_module_queue_item_unref0 (queue_item);
			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;
		}
		_tmp15_ = queue_item;
		_tmp16_ = _tmp15_->node;
		_tmp17_ = _xmpp_stanza_entry_ref0 (_tmp16_);
		node = _tmp17_;
		_tmp20_ = node;
		_tmp21_ = ((XmppStanzaEntry*) _tmp20_)->name;
		if (g_strcmp0 (_tmp21_, "message") == 0) {
			_tmp19_ = TRUE;
		} else {
			XmppStanzaNode* _tmp22_;
			const gchar* _tmp23_;
			_tmp22_ = node;
			_tmp23_ = ((XmppStanzaEntry*) _tmp22_)->name;
			_tmp19_ = g_strcmp0 (_tmp23_, "iq") == 0;
		}
		if (_tmp19_) {
			_tmp18_ = TRUE;
		} else {
			XmppStanzaNode* _tmp24_;
			const gchar* _tmp25_;
			_tmp24_ = node;
			_tmp25_ = ((XmppStanzaEntry*) _tmp24_)->name;
			_tmp18_ = g_strcmp0 (_tmp25_, "presence") == 0;
		}
		if (_tmp18_) {
			GeeHashMap* _tmp26_;
			gint _tmp27_;
			XmppXepStreamManagementModuleQueueItem* _tmp28_;
			_tmp26_ = self->priv->in_flight_stanzas;
			self->h_outbound = self->h_outbound + 1;
			_tmp27_ = self->h_outbound;
			_tmp28_ = queue_item;
			gee_abstract_map_set ((GeeAbstractMap*) _tmp26_, (gpointer) ((gintptr) _tmp27_), _tmp28_);
		}
		_tmp29_ = node;
		_tmp30_ = queue_item;
		_tmp31_ = queue_item;
		_tmp32_ = _tmp31_->cancellable;
		xmpp_xep_stream_management_module_write_node (self, stream, _tmp29_, _tmp30_->io_priority, _tmp32_, NULL, NULL);
		_xmpp_stanza_entry_unref0 (node);
		_xmpp_xep_stream_management_module_queue_item_unref0 (queue_item);
	}
}

static void
_xmpp_xep_stream_management_module_check_enable_xmpp_bind_module_bound_to_resource (XmppBindModule* _sender,
                                                                                    XmppXmppStream* stream,
                                                                                    XmppJid* my_jid,
                                                                                    gpointer self)
{
	xmpp_xep_stream_management_module_check_enable ((XmppXepStreamManagementModule*) self, stream);
}

static void
_xmpp_xep_stream_management_module_check_resume_xmpp_xmpp_stream_received_features_node (XmppXmppStream* _sender,
                                                                                         XmppXmppStream* stream,
                                                                                         gpointer self)
{
	xmpp_xep_stream_management_module_check_resume ((XmppXepStreamManagementModule*) self, stream);
}

static void
_xmpp_xep_stream_management_module_on_received_nonza_xmpp_xmpp_stream_received_nonza (XmppXmppStream* _sender,
                                                                                      XmppXmppStream* stream,
                                                                                      XmppStanzaNode* node,
                                                                                      gpointer self)
{
	xmpp_xep_stream_management_module_on_received_nonza ((XmppXepStreamManagementModule*) self, stream, node);
}

static void
_xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_message_stanza (XmppXmppStream* _sender,
                                                                                                XmppXmppStream* stream,
                                                                                                XmppStanzaNode* node,
                                                                                                gpointer self)
{
	xmpp_xep_stream_management_module_on_stanza_received ((XmppXepStreamManagementModule*) self, stream, node);
}

static void
_xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_presence_stanza (XmppXmppStream* _sender,
                                                                                                 XmppXmppStream* stream,
                                                                                                 XmppStanzaNode* node,
                                                                                                 gpointer self)
{
	xmpp_xep_stream_management_module_on_stanza_received ((XmppXepStreamManagementModule*) self, stream, node);
}

static void
_xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_iq_stanza (XmppXmppStream* _sender,
                                                                                           XmppXmppStream* stream,
                                                                                           XmppStanzaNode* node,
                                                                                           gpointer self)
{
	xmpp_xep_stream_management_module_on_stanza_received ((XmppXepStreamManagementModule*) self, stream, node);
}

static void
xmpp_xep_stream_management_module_real_attach (XmppXmppStreamModule* base,
                                               XmppXmppStream* stream)
{
	XmppXepStreamManagementModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppBindModule* _tmp2_;
	self = (XmppXepStreamManagementModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_bind_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_BIND_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppBindModule*) _tmp1_;
	g_signal_connect_object (_tmp2_, "bound-to-resource", (GCallback) _xmpp_xep_stream_management_module_check_enable_xmpp_bind_module_bound_to_resource, self, 0);
	_g_object_unref0 (_tmp2_);
	g_signal_connect_object (stream, "received-features-node", (GCallback) _xmpp_xep_stream_management_module_check_resume_xmpp_xmpp_stream_received_features_node, self, 0);
	g_signal_connect_object (stream, "received-nonza", (GCallback) _xmpp_xep_stream_management_module_on_received_nonza_xmpp_xmpp_stream_received_nonza, self, 0);
	g_signal_connect_object (stream, "received-message-stanza", (GCallback) _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_message_stanza, self, 0);
	g_signal_connect_object (stream, "received-presence-stanza", (GCallback) _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_presence_stanza, self, 0);
	g_signal_connect_object (stream, "received-iq-stanza", (GCallback) _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_iq_stanza, self, 0);
}

static void
xmpp_xep_stream_management_module_real_detach (XmppXmppStreamModule* base,
                                               XmppXmppStream* stream)
{
	XmppXepStreamManagementModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppBindModule* _tmp2_;
	guint _tmp3_;
	guint _tmp4_;
	guint _tmp5_;
	guint _tmp6_;
	guint _tmp7_;
	guint _tmp8_;
	self = (XmppXepStreamManagementModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_bind_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_BIND_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppBindModule*) _tmp1_;
	g_signal_parse_name ("bound-to-resource", XMPP_BIND_TYPE_MODULE, &_tmp3_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp2_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp3_, 0, NULL, (GCallback) _xmpp_xep_stream_management_module_check_enable_xmpp_bind_module_bound_to_resource, self);
	_g_object_unref0 (_tmp2_);
	g_signal_parse_name ("received-features-node", XMPP_TYPE_XMPP_STREAM, &_tmp4_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (stream, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _xmpp_xep_stream_management_module_check_resume_xmpp_xmpp_stream_received_features_node, self);
	g_signal_parse_name ("received-nonza", XMPP_TYPE_XMPP_STREAM, &_tmp5_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (stream, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp5_, 0, NULL, (GCallback) _xmpp_xep_stream_management_module_on_received_nonza_xmpp_xmpp_stream_received_nonza, self);
	g_signal_parse_name ("received-message-stanza", XMPP_TYPE_XMPP_STREAM, &_tmp6_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (stream, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp6_, 0, NULL, (GCallback) _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_message_stanza, self);
	g_signal_parse_name ("received-presence-stanza", XMPP_TYPE_XMPP_STREAM, &_tmp7_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (stream, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp7_, 0, NULL, (GCallback) _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_presence_stanza, self);
	g_signal_parse_name ("received-iq-stanza", XMPP_TYPE_XMPP_STREAM, &_tmp8_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (stream, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp8_, 0, NULL, (GCallback) _xmpp_xep_stream_management_module_on_stanza_received_xmpp_xmpp_stream_received_iq_stanza, self);
}

void
xmpp_xep_stream_management_module_require (XmppXmppStream* stream)
{
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepStreamManagementModule* _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_xep_stream_management_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_STREAM_MANAGEMENT_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppXepStreamManagementModule*) _tmp1_;
	_tmp3_ = _tmp2_ == NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		XmppXepPrivateXmlStorageModule* _tmp4_;
		XmppXepPrivateXmlStorageModule* _tmp5_;
		XmppXmppStream* _tmp6_;
		XmppXmppStream* _tmp7_;
		_tmp4_ = xmpp_xep_private_xml_storage_module_new ();
		_tmp5_ = _tmp4_;
		_tmp6_ = xmpp_xmpp_stream_add_module (stream, (XmppXmppStreamModule*) _tmp5_);
		_tmp7_ = _tmp6_;
		_g_object_unref0 (_tmp7_);
		_g_object_unref0 (_tmp5_);
	}
}

static gboolean
xmpp_xep_stream_management_module_real_mandatory_outstanding (XmppXmppStreamNegotiationModule* base,
                                                              XmppXmppStream* stream)
{
	XmppXepStreamManagementModule * self;
	gboolean result;
	self = (XmppXepStreamManagementModule*) base;
	g_return_val_if_fail (stream != NULL, FALSE);
	result = FALSE;
	return result;
}

static gboolean
xmpp_xep_stream_management_module_real_negotiation_active (XmppXmppStreamNegotiationModule* base,
                                                           XmppXmppStream* stream)
{
	XmppXepStreamManagementModule * self;
	gboolean _tmp0_ = FALSE;
	XmppFlagIdentity* _tmp1_;
	gboolean result;
	self = (XmppXepStreamManagementModule*) base;
	g_return_val_if_fail (stream != NULL, FALSE);
	_tmp1_ = xmpp_xep_stream_management_flag_IDENTITY;
	if (xmpp_xmpp_stream_has_flag (stream, XMPP_XEP_STREAM_MANAGEMENT_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_)) {
		XmppFlagIdentity* _tmp2_;
		gpointer _tmp3_;
		XmppXepStreamManagementFlag* _tmp4_;
		_tmp2_ = xmpp_xep_stream_management_flag_IDENTITY;
		_tmp3_ = xmpp_xmpp_stream_get_flag (stream, XMPP_XEP_STREAM_MANAGEMENT_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
		_tmp4_ = (XmppXepStreamManagementFlag*) _tmp3_;
		_tmp0_ = !_tmp4_->finished;
		_g_object_unref0 (_tmp4_);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_stream_management_module_real_get_ns (XmppXmppStreamModule* base)
{
	XmppXepStreamManagementModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepStreamManagementModule*) base;
	_tmp0_ = g_strdup (XMPP_XEP_STREAM_MANAGEMENT_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_stream_management_module_real_get_id (XmppXmppStreamModule* base)
{
	XmppXepStreamManagementModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepStreamManagementModule*) base;
	_tmp0_ = xmpp_xep_stream_management_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

static void
xmpp_xep_stream_management_module_on_stanza_received (XmppXepStreamManagementModule* self,
                                                      XmppXmppStream* stream,
                                                      XmppStanzaNode* node)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = self->h_inbound;
	self->h_inbound = _tmp0_ + 1;
}

static void
xmpp_xep_stream_management_module_check_resume (XmppXepStreamManagementModule* self,
                                                XmppXmppStream* stream)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	if (xmpp_xep_stream_management_module_stream_has_sm_feature (self, stream)) {
		const gchar* _tmp1_;
		_tmp1_ = self->priv->_session_id;
		_tmp0_ = _tmp1_ != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		XmppStanzaNode* node = NULL;
		XmppStanzaNode* _tmp2_;
		XmppStanzaNode* _tmp3_;
		XmppStanzaNode* _tmp4_;
		XmppStanzaNode* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		XmppStanzaNode* _tmp8_;
		XmppStanzaNode* _tmp9_;
		const gchar* _tmp10_;
		XmppStanzaNode* _tmp11_;
		XmppStanzaNode* _tmp12_;
		XmppStanzaNode* _tmp13_;
		XmppXepStreamManagementFlag* _tmp14_;
		XmppXepStreamManagementFlag* _tmp15_;
		_tmp2_ = xmpp_stanza_node_new_build ("resume", XMPP_XEP_STREAM_MANAGEMENT_NS_URI, NULL, NULL);
		_tmp3_ = _tmp2_;
		_tmp4_ = xmpp_stanza_node_add_self_xmlns (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_strdup_printf ("%i", self->h_inbound);
		_tmp7_ = _tmp6_;
		_tmp8_ = xmpp_stanza_node_put_attribute (_tmp5_, "h", _tmp7_, NULL);
		_tmp9_ = _tmp8_;
		_tmp10_ = self->priv->_session_id;
		_tmp11_ = xmpp_stanza_node_put_attribute (_tmp9_, "previd", _tmp10_, NULL);
		_tmp12_ = _tmp11_;
		_xmpp_stanza_entry_unref0 (_tmp9_);
		_g_free0 (_tmp7_);
		_xmpp_stanza_entry_unref0 (_tmp5_);
		_xmpp_stanza_entry_unref0 (_tmp3_);
		node = _tmp12_;
		_tmp13_ = node;
		xmpp_xep_stream_management_module_write_node (self, stream, _tmp13_, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
		_tmp14_ = xmpp_xep_stream_management_flag_new ();
		_tmp15_ = _tmp14_;
		xmpp_xmpp_stream_add_flag (stream, (XmppXmppStreamFlag*) _tmp15_);
		_g_object_unref0 (_tmp15_);
		_xmpp_stanza_entry_unref0 (node);
	}
}

static void
xmpp_xep_stream_management_module_check_enable (XmppXepStreamManagementModule* self,
                                                XmppXmppStream* stream)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	if (xmpp_xep_stream_management_module_stream_has_sm_feature (self, stream)) {
		const gchar* _tmp1_;
		_tmp1_ = self->priv->_session_id;
		_tmp0_ = _tmp1_ == NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		XmppStanzaNode* node = NULL;
		XmppStanzaNode* _tmp2_;
		XmppStanzaNode* _tmp3_;
		XmppStanzaNode* _tmp4_;
		XmppStanzaNode* _tmp5_;
		XmppStanzaNode* _tmp6_;
		XmppStanzaNode* _tmp7_;
		XmppStanzaNode* _tmp8_;
		XmppXepStreamManagementFlag* _tmp9_;
		XmppXepStreamManagementFlag* _tmp10_;
		_tmp2_ = xmpp_stanza_node_new_build ("enable", XMPP_XEP_STREAM_MANAGEMENT_NS_URI, NULL, NULL);
		_tmp3_ = _tmp2_;
		_tmp4_ = xmpp_stanza_node_add_self_xmlns (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = xmpp_stanza_node_put_attribute (_tmp5_, "resume", "true", NULL);
		_tmp7_ = _tmp6_;
		_xmpp_stanza_entry_unref0 (_tmp5_);
		_xmpp_stanza_entry_unref0 (_tmp3_);
		node = _tmp7_;
		_tmp8_ = node;
		xmpp_xep_stream_management_module_write_node (self, stream, _tmp8_, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
		_tmp9_ = xmpp_xep_stream_management_flag_new ();
		_tmp10_ = _tmp9_;
		xmpp_xmpp_stream_add_flag (stream, (XmppXmppStreamFlag*) _tmp10_);
		_g_object_unref0 (_tmp10_);
		self->h_outbound = 0;
		_xmpp_stanza_entry_unref0 (node);
	}
}

static gboolean
_vala_string_array_contains (gchar* * stack,
                             gssize stack_length,
                             const gchar* needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}

static void
xmpp_xep_stream_management_module_on_received_nonza (XmppXepStreamManagementModule* self,
                                                     XmppXmppStream* stream,
                                                     XmppStanzaNode* node)
{
	const gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = ((XmppStanzaEntry*) node)->ns_uri;
	if (g_strcmp0 (_tmp0_, XMPP_XEP_STREAM_MANAGEMENT_NS_URI) == 0) {
		const gchar* _tmp1_;
		_tmp1_ = ((XmppStanzaEntry*) node)->name;
		if (g_strcmp0 (_tmp1_, "r") == 0) {
			xmpp_xep_stream_management_module_send_ack (self, stream);
		} else {
			const gchar* _tmp2_;
			_tmp2_ = ((XmppStanzaEntry*) node)->name;
			if (g_strcmp0 (_tmp2_, "a") == 0) {
				xmpp_xep_stream_management_module_handle_ack (self, stream, node);
			} else {
				const gchar* _tmp3_;
				gchar* _tmp4_;
				gchar* _tmp5_;
				gchar* _tmp6_;
				gchar** _tmp7_;
				gchar** _tmp8_;
				gint _tmp8__length1;
				gboolean _tmp9_;
				_tmp3_ = ((XmppStanzaEntry*) node)->name;
				_tmp4_ = g_strdup ("enabled");
				_tmp5_ = g_strdup ("resumed");
				_tmp6_ = g_strdup ("failed");
				_tmp7_ = g_new0 (gchar*, 3 + 1);
				_tmp7_[0] = _tmp4_;
				_tmp7_[1] = _tmp5_;
				_tmp7_[2] = _tmp6_;
				_tmp8_ = _tmp7_;
				_tmp8__length1 = 3;
				_tmp9_ = _vala_string_array_contains (_tmp8_, 3, _tmp3_);
				_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
				if (_tmp9_) {
					XmppFlagIdentity* _tmp10_;
					gpointer _tmp11_;
					XmppXepStreamManagementFlag* _tmp12_;
					const gchar* _tmp13_;
					_tmp10_ = xmpp_xep_stream_management_flag_IDENTITY;
					_tmp11_ = xmpp_xmpp_stream_get_flag (stream, XMPP_XEP_STREAM_MANAGEMENT_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp10_);
					_tmp12_ = (XmppXepStreamManagementFlag*) _tmp11_;
					_tmp12_->finished = TRUE;
					_g_object_unref0 (_tmp12_);
					_tmp13_ = ((XmppStanzaEntry*) node)->name;
					if (g_strcmp0 (_tmp13_, "enabled") == 0) {
						const gchar* _tmp14_;
						GeeList* _tmp15_;
						GeeList* _tmp16_;
						GeeList* _tmp17_;
						XmppWriteNodeFunc* _tmp18_;
						self->h_inbound = 0;
						_tmp14_ = xmpp_stanza_node_get_attribute (node, "id", XMPP_XEP_STREAM_MANAGEMENT_NS_URI);
						xmpp_xep_stream_management_module_set_session_id (self, _tmp14_);
						_tmp15_ = xmpp_xmpp_stream_get_flags (stream);
						_tmp16_ = _tmp15_;
						_tmp17_ = _g_object_ref0 (_tmp16_);
						_g_object_unref0 (self->flags);
						self->flags = _tmp17_;
						_tmp18_ = _g_object_ref0 ((XmppWriteNodeFunc*) self);
						_g_object_unref0 (G_TYPE_CHECK_INSTANCE_CAST (stream, XMPP_TYPE_IO_XMPP_STREAM, XmppIoXmppStream)->write_obj);
						G_TYPE_CHECK_INSTANCE_CAST (stream, XMPP_TYPE_IO_XMPP_STREAM, XmppIoXmppStream)->write_obj = _tmp18_;
					} else {
						const gchar* _tmp19_;
						_tmp19_ = ((XmppStanzaEntry*) node)->name;
						if (g_strcmp0 (_tmp19_, "resumed") == 0) {
							XmppFlagIdentity* _tmp20_;
							gpointer _tmp21_;
							XmppXepStreamManagementFlag* _tmp22_;
							const gchar* _tmp32_;
							GeeHashMap* _tmp46_;
							XmppWriteNodeFunc* _tmp47_;
							_tmp20_ = xmpp_xep_stream_management_flag_IDENTITY;
							_tmp21_ = xmpp_xmpp_stream_get_flag (stream, XMPP_XEP_STREAM_MANAGEMENT_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp20_);
							_tmp22_ = (XmppXepStreamManagementFlag*) _tmp21_;
							_tmp22_->resumed = TRUE;
							_g_object_unref0 (_tmp22_);
							{
								GeeList* _flag_list = NULL;
								GeeList* _tmp23_;
								gint _flag_size = 0;
								GeeList* _tmp24_;
								gint _tmp25_;
								gint _tmp26_;
								gint _flag_index = 0;
								_tmp23_ = self->flags;
								_flag_list = _tmp23_;
								_tmp24_ = _flag_list;
								_tmp25_ = gee_collection_get_size ((GeeCollection*) _tmp24_);
								_tmp26_ = _tmp25_;
								_flag_size = _tmp26_;
								_flag_index = -1;
								while (TRUE) {
									gint _tmp27_;
									gint _tmp28_;
									XmppXmppStreamFlag* flag = NULL;
									GeeList* _tmp29_;
									gpointer _tmp30_;
									XmppXmppStreamFlag* _tmp31_;
									_flag_index = _flag_index + 1;
									_tmp27_ = _flag_index;
									_tmp28_ = _flag_size;
									if (!(_tmp27_ < _tmp28_)) {
										break;
									}
									_tmp29_ = _flag_list;
									_tmp30_ = gee_list_get (_tmp29_, _flag_index);
									flag = (XmppXmppStreamFlag*) _tmp30_;
									_tmp31_ = flag;
									xmpp_xmpp_stream_add_flag (stream, _tmp31_);
									_g_object_unref0 (flag);
								}
							}
							_tmp32_ = xmpp_stanza_node_get_attribute (node, "h", XMPP_XEP_STREAM_MANAGEMENT_NS_URI);
							self->h_outbound = atoi (_tmp32_);
							xmpp_xep_stream_management_module_handle_incoming_h (self, stream, self->h_outbound);
							{
								GeeIterator* _id_it = NULL;
								GeeHashMap* _tmp33_;
								GeeSet* _tmp34_;
								GeeSet* _tmp35_;
								GeeSet* _tmp36_;
								GeeIterator* _tmp37_;
								GeeIterator* _tmp38_;
								_tmp33_ = self->priv->in_flight_stanzas;
								_tmp34_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp33_);
								_tmp35_ = _tmp34_;
								_tmp36_ = _tmp35_;
								_tmp37_ = gee_iterable_iterator ((GeeIterable*) _tmp36_);
								_tmp38_ = _tmp37_;
								_g_object_unref0 (_tmp36_);
								_id_it = _tmp38_;
								while (TRUE) {
									GeeIterator* _tmp39_;
									gint id = 0;
									GeeIterator* _tmp40_;
									gpointer _tmp41_;
									GeeQueue* _tmp42_;
									GeeHashMap* _tmp43_;
									gpointer _tmp44_;
									XmppXepStreamManagementModuleQueueItem* _tmp45_;
									_tmp39_ = _id_it;
									if (!gee_iterator_next (_tmp39_)) {
										break;
									}
									_tmp40_ = _id_it;
									_tmp41_ = gee_iterator_get (_tmp40_);
									id = (gint) ((gintptr) _tmp41_);
									_tmp42_ = self->priv->node_queue;
									_tmp43_ = self->priv->in_flight_stanzas;
									_tmp44_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp43_, (gpointer) ((gintptr) id));
									_tmp45_ = (XmppXepStreamManagementModuleQueueItem*) _tmp44_;
									gee_collection_add ((GeeCollection*) _tmp42_, _tmp45_);
									_xmpp_xep_stream_management_module_queue_item_unref0 (_tmp45_);
								}
								_g_object_unref0 (_id_it);
							}
							_tmp46_ = self->priv->in_flight_stanzas;
							gee_abstract_map_clear ((GeeAbstractMap*) _tmp46_);
							xmpp_xep_stream_management_module_check_queue (self, stream);
							_tmp47_ = _g_object_ref0 ((XmppWriteNodeFunc*) self);
							_g_object_unref0 (G_TYPE_CHECK_INSTANCE_CAST (stream, XMPP_TYPE_IO_XMPP_STREAM, XmppIoXmppStream)->write_obj);
							G_TYPE_CHECK_INSTANCE_CAST (stream, XMPP_TYPE_IO_XMPP_STREAM, XmppIoXmppStream)->write_obj = _tmp47_;
						} else {
							const gchar* _tmp48_;
							_tmp48_ = ((XmppStanzaEntry*) node)->name;
							if (g_strcmp0 (_tmp48_, "failed") == 0) {
								gchar* h_acked = NULL;
								const gchar* _tmp49_;
								gchar* _tmp50_;
								const gchar* _tmp51_;
								GeeHashMap* _tmp67_;
								xmpp_xep_stream_management_module_set_session_id (self, NULL);
								_tmp49_ = xmpp_stanza_node_get_attribute (node, "h", XMPP_XEP_STREAM_MANAGEMENT_NS_URI);
								_tmp50_ = g_strdup (_tmp49_);
								h_acked = _tmp50_;
								_tmp51_ = h_acked;
								if (_tmp51_ != NULL) {
									const gchar* _tmp52_;
									_tmp52_ = h_acked;
									self->h_outbound = atoi (_tmp52_);
									xmpp_xep_stream_management_module_handle_incoming_h (self, stream, self->h_outbound);
								}
								{
									GeeIterator* _id_it = NULL;
									GeeHashMap* _tmp53_;
									GeeSet* _tmp54_;
									GeeSet* _tmp55_;
									GeeSet* _tmp56_;
									GeeIterator* _tmp57_;
									GeeIterator* _tmp58_;
									_tmp53_ = self->priv->in_flight_stanzas;
									_tmp54_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp53_);
									_tmp55_ = _tmp54_;
									_tmp56_ = _tmp55_;
									_tmp57_ = gee_iterable_iterator ((GeeIterable*) _tmp56_);
									_tmp58_ = _tmp57_;
									_g_object_unref0 (_tmp56_);
									_id_it = _tmp58_;
									while (TRUE) {
										GeeIterator* _tmp59_;
										gint id = 0;
										GeeIterator* _tmp60_;
										gpointer _tmp61_;
										GeeHashMap* _tmp62_;
										gpointer _tmp63_;
										XmppXepStreamManagementModuleQueueItem* _tmp64_;
										GeePromise* _tmp65_;
										GError* _tmp66_;
										_tmp59_ = _id_it;
										if (!gee_iterator_next (_tmp59_)) {
											break;
										}
										_tmp60_ = _id_it;
										_tmp61_ = gee_iterator_get (_tmp60_);
										id = (gint) ((gintptr) _tmp61_);
										_tmp62_ = self->priv->in_flight_stanzas;
										_tmp63_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp62_, (gpointer) ((gintptr) id));
										_tmp64_ = (XmppXepStreamManagementModuleQueueItem*) _tmp63_;
										_tmp65_ = _tmp64_->promise;
										_tmp66_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Stanza not acked and session not resumed");
										gee_promise_set_exception (_tmp65_, _tmp66_);
										_xmpp_xep_stream_management_module_queue_item_unref0 (_tmp64_);
									}
									_g_object_unref0 (_id_it);
								}
								_tmp67_ = self->priv->in_flight_stanzas;
								gee_abstract_map_clear ((GeeAbstractMap*) _tmp67_);
								xmpp_xep_stream_management_module_check_queue (self, stream);
								g_signal_emit_by_name (stream, "received-features-node", stream);
								_g_free0 (h_acked);
							}
						}
					}
				}
			}
		}
	}
}

static void
xmpp_xep_stream_management_module_send_ack (XmppXepStreamManagementModule* self,
                                            XmppXmppStream* stream)
{
	XmppStanzaNode* node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	XmppStanzaNode* _tmp6_;
	XmppStanzaNode* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_stanza_node_new_build ("a", XMPP_XEP_STREAM_MANAGEMENT_NS_URI, NULL, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmpp_stanza_node_add_self_xmlns (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf ("%i", self->h_inbound);
	_tmp5_ = _tmp4_;
	_tmp6_ = xmpp_stanza_node_put_attribute (_tmp3_, "h", _tmp5_, NULL);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	_xmpp_stanza_entry_unref0 (_tmp3_);
	_xmpp_stanza_entry_unref0 (_tmp1_);
	node = _tmp7_;
	xmpp_xep_stream_management_module_write_node (self, stream, node, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
	_xmpp_stanza_entry_unref0 (node);
}

static void
xmpp_xep_stream_management_module_handle_ack (XmppXepStreamManagementModule* self,
                                              XmppXmppStream* stream,
                                              XmppStanzaNode* node)
{
	gchar* h_acked = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gint parsed_int = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = xmpp_stanza_node_get_attribute (node, "h", XMPP_XEP_STREAM_MANAGEMENT_NS_URI);
	_tmp1_ = g_strdup (_tmp0_);
	h_acked = _tmp1_;
	parsed_int = atoi (h_acked);
	xmpp_xep_stream_management_module_handle_incoming_h (self, stream, parsed_int);
	xmpp_xep_stream_management_module_check_queue (self, stream);
	_g_free0 (h_acked);
}

static void
xmpp_xep_stream_management_module_handle_incoming_h (XmppXepStreamManagementModule* self,
                                                     XmppXmppStream* stream,
                                                     gint h)
{
	GeeArrayList* remove_nrs = NULL;
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	_tmp0_ = gee_array_list_new (G_TYPE_INT, NULL, NULL, NULL, NULL, NULL);
	remove_nrs = _tmp0_;
	{
		GeeIterator* _nr_it = NULL;
		GeeHashMap* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeSet* _tmp4_;
		GeeIterator* _tmp5_;
		GeeIterator* _tmp6_;
		_tmp1_ = self->priv->in_flight_stanzas;
		_tmp2_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		_tmp5_ = gee_iterable_iterator ((GeeIterable*) _tmp4_);
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp4_);
		_nr_it = _tmp6_;
		while (TRUE) {
			GeeIterator* _tmp7_;
			gint nr = 0;
			GeeIterator* _tmp8_;
			gpointer _tmp9_;
			_tmp7_ = _nr_it;
			if (!gee_iterator_next (_tmp7_)) {
				break;
			}
			_tmp8_ = _nr_it;
			_tmp9_ = gee_iterator_get (_tmp8_);
			nr = (gint) ((gintptr) _tmp9_);
			if (nr <= h) {
				GeeArrayList* _tmp10_;
				_tmp10_ = remove_nrs;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, (gpointer) ((gintptr) nr));
			}
		}
		_g_object_unref0 (_nr_it);
	}
	{
		GeeArrayList* _nr_list = NULL;
		GeeArrayList* _tmp11_;
		gint _nr_size = 0;
		GeeArrayList* _tmp12_;
		gint _tmp13_;
		gint _tmp14_;
		gint _nr_index = 0;
		_tmp11_ = remove_nrs;
		_nr_list = _tmp11_;
		_tmp12_ = _nr_list;
		_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp12_);
		_tmp14_ = _tmp13_;
		_nr_size = _tmp14_;
		_nr_index = -1;
		while (TRUE) {
			gint _tmp15_;
			gint _tmp16_;
			gint nr = 0;
			GeeArrayList* _tmp17_;
			gpointer _tmp18_;
			GeeHashMap* _tmp19_;
			gpointer _tmp20_;
			XmppXepStreamManagementModuleQueueItem* _tmp21_;
			GeePromise* _tmp22_;
			GeeHashMap* _tmp23_;
			_nr_index = _nr_index + 1;
			_tmp15_ = _nr_index;
			_tmp16_ = _nr_size;
			if (!(_tmp15_ < _tmp16_)) {
				break;
			}
			_tmp17_ = _nr_list;
			_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) _tmp17_, _nr_index);
			nr = (gint) ((gintptr) _tmp18_);
			_tmp19_ = self->priv->in_flight_stanzas;
			_tmp20_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp19_, (gpointer) ((gintptr) nr));
			_tmp21_ = (XmppXepStreamManagementModuleQueueItem*) _tmp20_;
			_tmp22_ = _tmp21_->promise;
			gee_promise_set_value (_tmp22_, NULL);
			_xmpp_xep_stream_management_module_queue_item_unref0 (_tmp21_);
			_tmp23_ = self->priv->in_flight_stanzas;
			gee_abstract_map_unset ((GeeAbstractMap*) _tmp23_, (gpointer) ((gintptr) nr), NULL);
		}
	}
	_g_object_unref0 (remove_nrs);
}

static gboolean
xmpp_xep_stream_management_module_stream_has_sm_feature (XmppXepStreamManagementModule* self,
                                                         XmppXmppStream* stream)
{
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (stream != NULL, FALSE);
	_tmp0_ = xmpp_xmpp_stream_get_features (stream);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmpp_stanza_node_get_subnode (_tmp1_, "sm", XMPP_XEP_STREAM_MANAGEMENT_NS_URI, FALSE);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_ != NULL;
	_xmpp_stanza_entry_unref0 (_tmp3_);
	result = _tmp4_;
	return result;
}

XmppXepStreamManagementModule*
xmpp_xep_stream_management_module_construct (GType object_type)
{
	XmppXepStreamManagementModule * self = NULL;
	self = (XmppXepStreamManagementModule*) xmpp_xmpp_stream_negotiation_module_construct (object_type);
	return self;
}

XmppXepStreamManagementModule*
xmpp_xep_stream_management_module_new (void)
{
	return xmpp_xep_stream_management_module_construct (XMPP_XEP_STREAM_MANAGEMENT_TYPE_MODULE);
}

const gchar*
xmpp_xep_stream_management_module_get_session_id (XmppXepStreamManagementModule* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_session_id;
	result = _tmp0_;
	return result;
}

void
xmpp_xep_stream_management_module_set_session_id (XmppXepStreamManagementModule* self,
                                                  const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = xmpp_xep_stream_management_module_get_session_id (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_session_id);
		self->priv->_session_id = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, xmpp_xep_stream_management_module_properties[XMPP_XEP_STREAM_MANAGEMENT_MODULE_SESSION_ID_PROPERTY]);
	}
}

static XmppXepStreamManagementModuleQueueItem*
xmpp_xep_stream_management_module_queue_item_construct (GType object_type,
                                                        XmppStanzaNode* node,
                                                        gint io_priority,
                                                        GCancellable* cancellable)
{
	XmppXepStreamManagementModuleQueueItem* self = NULL;
	XmppStanzaNode* _tmp0_;
	GCancellable* _tmp1_;
	GeePromise* _tmp2_;
	g_return_val_if_fail (node != NULL, NULL);
	self = (XmppXepStreamManagementModuleQueueItem*) g_type_create_instance (object_type);
	_tmp0_ = _xmpp_stanza_entry_ref0 (node);
	_xmpp_stanza_entry_unref0 (self->node);
	self->node = _tmp0_;
	self->io_priority = io_priority;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (self->cancellable);
	self->cancellable = _tmp1_;
	_tmp2_ = gee_promise_new (G_TYPE_POINTER, NULL, NULL);
	_gee_promise_unref0 (self->promise);
	self->promise = _tmp2_;
	return self;
}

static XmppXepStreamManagementModuleQueueItem*
xmpp_xep_stream_management_module_queue_item_new (XmppStanzaNode* node,
                                                  gint io_priority,
                                                  GCancellable* cancellable)
{
	return xmpp_xep_stream_management_module_queue_item_construct (XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM, node, io_priority, cancellable);
}

static void
xmpp_xep_stream_management_module_value_queue_item_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
xmpp_xep_stream_management_module_value_queue_item_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		xmpp_xep_stream_management_module_queue_item_unref (value->data[0].v_pointer);
	}
}

static void
xmpp_xep_stream_management_module_value_queue_item_copy_value (const GValue* src_value,
                                                               GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = xmpp_xep_stream_management_module_queue_item_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
xmpp_xep_stream_management_module_value_queue_item_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
xmpp_xep_stream_management_module_value_queue_item_collect_value (GValue* value,
                                                                  guint n_collect_values,
                                                                  GTypeCValue* collect_values,
                                                                  guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		XmppXepStreamManagementModuleQueueItem * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = xmpp_xep_stream_management_module_queue_item_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
xmpp_xep_stream_management_module_value_queue_item_lcopy_value (const GValue* value,
                                                                guint n_collect_values,
                                                                GTypeCValue* collect_values,
                                                                guint collect_flags)
{
	XmppXepStreamManagementModuleQueueItem ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = xmpp_xep_stream_management_module_queue_item_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
xmpp_xep_stream_management_module_param_spec_queue_item (const gchar* name,
                                                         const gchar* nick,
                                                         const gchar* blurb,
                                                         GType object_type,
                                                         GParamFlags flags)
{
	XmppXepStreamManagementModuleParamSpecQueueItem* spec;
	g_return_val_if_fail (g_type_is_a (object_type, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
xmpp_xep_stream_management_module_value_get_queue_item (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM), NULL);
	return value->data[0].v_pointer;
}

static void
xmpp_xep_stream_management_module_value_set_queue_item (GValue* value,
                                                        gpointer v_object)
{
	XmppXepStreamManagementModuleQueueItem * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		xmpp_xep_stream_management_module_queue_item_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_stream_management_module_queue_item_unref (old);
	}
}

static void
xmpp_xep_stream_management_module_value_take_queue_item (GValue* value,
                                                         gpointer v_object)
{
	XmppXepStreamManagementModuleQueueItem * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_stream_management_module_queue_item_unref (old);
	}
}

static void
xmpp_xep_stream_management_module_queue_item_class_init (XmppXepStreamManagementModuleQueueItemClass * klass,
                                                         gpointer klass_data)
{
	xmpp_xep_stream_management_module_queue_item_parent_class = g_type_class_peek_parent (klass);
	((XmppXepStreamManagementModuleQueueItemClass *) klass)->finalize = xmpp_xep_stream_management_module_queue_item_finalize;
}

static void
xmpp_xep_stream_management_module_queue_item_instance_init (XmppXepStreamManagementModuleQueueItem * self,
                                                            gpointer klass)
{
	self->ref_count = 1;
}

static void
xmpp_xep_stream_management_module_queue_item_finalize (XmppXepStreamManagementModuleQueueItem * obj)
{
	XmppXepStreamManagementModuleQueueItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM, XmppXepStreamManagementModuleQueueItem);
	g_signal_handlers_destroy (self);
	_xmpp_stanza_entry_unref0 (self->node);
	_g_object_unref0 (self->cancellable);
	_gee_promise_unref0 (self->promise);
}

static GType
xmpp_xep_stream_management_module_queue_item_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { xmpp_xep_stream_management_module_value_queue_item_init, xmpp_xep_stream_management_module_value_queue_item_free_value, xmpp_xep_stream_management_module_value_queue_item_copy_value, xmpp_xep_stream_management_module_value_queue_item_peek_pointer, "p", xmpp_xep_stream_management_module_value_queue_item_collect_value, "p", xmpp_xep_stream_management_module_value_queue_item_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepStreamManagementModuleQueueItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_stream_management_module_queue_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepStreamManagementModuleQueueItem), 0, (GInstanceInitFunc) xmpp_xep_stream_management_module_queue_item_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType xmpp_xep_stream_management_module_queue_item_type_id;
	xmpp_xep_stream_management_module_queue_item_type_id = g_type_register_fundamental (g_type_fundamental_next (), "XmppXepStreamManagementModuleQueueItem", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return xmpp_xep_stream_management_module_queue_item_type_id;
}

static GType
xmpp_xep_stream_management_module_queue_item_get_type (void)
{
	static volatile gsize xmpp_xep_stream_management_module_queue_item_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_stream_management_module_queue_item_type_id__once)) {
		GType xmpp_xep_stream_management_module_queue_item_type_id;
		xmpp_xep_stream_management_module_queue_item_type_id = xmpp_xep_stream_management_module_queue_item_get_type_once ();
		g_once_init_leave (&xmpp_xep_stream_management_module_queue_item_type_id__once, xmpp_xep_stream_management_module_queue_item_type_id);
	}
	return xmpp_xep_stream_management_module_queue_item_type_id__once;
}

static gpointer
xmpp_xep_stream_management_module_queue_item_ref (gpointer instance)
{
	XmppXepStreamManagementModuleQueueItem * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
xmpp_xep_stream_management_module_queue_item_unref (gpointer instance)
{
	XmppXepStreamManagementModuleQueueItem * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		XMPP_XEP_STREAM_MANAGEMENT_MODULE_QUEUE_ITEM_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
xmpp_xep_stream_management_module_class_init (XmppXepStreamManagementModuleClass * klass,
                                              gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_xep_stream_management_module_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppXepStreamManagementModule_private_offset);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_stream_management_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_stream_management_module_real_detach;
	((XmppXmppStreamNegotiationModuleClass *) klass)->mandatory_outstanding = (gboolean (*) (XmppXmppStreamNegotiationModule*, XmppXmppStream*)) xmpp_xep_stream_management_module_real_mandatory_outstanding;
	((XmppXmppStreamNegotiationModuleClass *) klass)->negotiation_active = (gboolean (*) (XmppXmppStreamNegotiationModule*, XmppXmppStream*)) xmpp_xep_stream_management_module_real_negotiation_active;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_stream_management_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_stream_management_module_real_get_id;
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_xep_stream_management_module_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_xmpp_xep_stream_management_module_set_property;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_stream_management_module_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_XEP_STREAM_MANAGEMENT_MODULE_SESSION_ID_PROPERTY, xmpp_xep_stream_management_module_properties[XMPP_XEP_STREAM_MANAGEMENT_MODULE_SESSION_ID_PROPERTY] = g_param_spec_string ("session-id", "session-id", "session-id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	_tmp0_ = xmpp_module_identity_new (XMPP_XEP_STREAM_MANAGEMENT_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_STREAM_MANAGEMENT_NS_URI, "0198_stream_management");
	xmpp_xep_stream_management_module_IDENTITY = _tmp0_;
}

static void
xmpp_xep_stream_management_module_xmpp_write_node_func_interface_init (XmppWriteNodeFuncIface * iface,
                                                                       gpointer iface_data)
{
	xmpp_xep_stream_management_module_xmpp_write_node_func_parent_iface = g_type_interface_peek_parent (iface);
	iface->write_stanza = (void (*) (XmppWriteNodeFunc*, XmppXmppStream*, XmppStanzaNode*, gint, GCancellable*, GAsyncReadyCallback, gpointer)) xmpp_xep_stream_management_module_real_write_stanza;
	iface->write_stanza_finish = (void (*) (XmppWriteNodeFunc*, GAsyncResult*, GError**)) xmpp_xep_stream_management_module_write_stanza_finish;
}

static void
xmpp_xep_stream_management_module_instance_init (XmppXepStreamManagementModule * self,
                                                 gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeePriorityQueue* _tmp1_;
	self->priv = xmpp_xep_stream_management_module_get_instance_private (self);
	self->h_inbound = 0;
	self->h_outbound = 0;
	self->priv->_session_id = NULL;
	self->flags = NULL;
	_tmp0_ = gee_hash_map_new (G_TYPE_INT, NULL, NULL, XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM, (GBoxedCopyFunc) xmpp_xep_stream_management_module_queue_item_ref, (GDestroyNotify) xmpp_xep_stream_management_module_queue_item_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->in_flight_stanzas = _tmp0_;
	_tmp1_ = gee_priority_queue_new (XMPP_XEP_STREAM_MANAGEMENT_MODULE_TYPE_QUEUE_ITEM, (GBoxedCopyFunc) xmpp_xep_stream_management_module_queue_item_ref, (GDestroyNotify) xmpp_xep_stream_management_module_queue_item_unref, __xmpp_xep_stream_management_module_node_queue_lambda26__gcompare_data_func, NULL, NULL);
	self->priv->node_queue = (GeeQueue*) _tmp1_;
}

static void
xmpp_xep_stream_management_module_finalize (GObject * obj)
{
	XmppXepStreamManagementModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_STREAM_MANAGEMENT_TYPE_MODULE, XmppXepStreamManagementModule);
	_g_free0 (self->priv->_session_id);
	_g_object_unref0 (self->flags);
	_g_object_unref0 (self->priv->in_flight_stanzas);
	_g_object_unref0 (self->priv->node_queue);
	G_OBJECT_CLASS (xmpp_xep_stream_management_module_parent_class)->finalize (obj);
}

static GType
xmpp_xep_stream_management_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepStreamManagementModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_stream_management_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepStreamManagementModule), 0, (GInstanceInitFunc) xmpp_xep_stream_management_module_instance_init, NULL };
	static const GInterfaceInfo xmpp_write_node_func_info = { (GInterfaceInitFunc) xmpp_xep_stream_management_module_xmpp_write_node_func_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType xmpp_xep_stream_management_module_type_id;
	xmpp_xep_stream_management_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_NEGOTIATION_MODULE, "XmppXepStreamManagementModule", &g_define_type_info, 0);
	g_type_add_interface_static (xmpp_xep_stream_management_module_type_id, XMPP_TYPE_WRITE_NODE_FUNC, &xmpp_write_node_func_info);
	XmppXepStreamManagementModule_private_offset = g_type_add_instance_private (xmpp_xep_stream_management_module_type_id, sizeof (XmppXepStreamManagementModulePrivate));
	return xmpp_xep_stream_management_module_type_id;
}

GType
xmpp_xep_stream_management_module_get_type (void)
{
	static volatile gsize xmpp_xep_stream_management_module_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_stream_management_module_type_id__once)) {
		GType xmpp_xep_stream_management_module_type_id;
		xmpp_xep_stream_management_module_type_id = xmpp_xep_stream_management_module_get_type_once ();
		g_once_init_leave (&xmpp_xep_stream_management_module_type_id__once, xmpp_xep_stream_management_module_type_id);
	}
	return xmpp_xep_stream_management_module_type_id__once;
}

static void
_vala_xmpp_xep_stream_management_module_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec)
{
	XmppXepStreamManagementModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_XEP_STREAM_MANAGEMENT_TYPE_MODULE, XmppXepStreamManagementModule);
	switch (property_id) {
		case XMPP_XEP_STREAM_MANAGEMENT_MODULE_SESSION_ID_PROPERTY:
		g_value_set_string (value, xmpp_xep_stream_management_module_get_session_id (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_xmpp_xep_stream_management_module_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec)
{
	XmppXepStreamManagementModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_XEP_STREAM_MANAGEMENT_TYPE_MODULE, XmppXepStreamManagementModule);
	switch (property_id) {
		case XMPP_XEP_STREAM_MANAGEMENT_MODULE_SESSION_ID_PROPERTY:
		xmpp_xep_stream_management_module_set_session_id (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static gchar*
xmpp_xep_stream_management_flag_real_get_ns (XmppXmppStreamFlag* base)
{
	XmppXepStreamManagementFlag * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepStreamManagementFlag*) base;
	_tmp0_ = g_strdup (XMPP_XEP_STREAM_MANAGEMENT_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_stream_management_flag_real_get_id (XmppXmppStreamFlag* base)
{
	XmppXepStreamManagementFlag * self;
	XmppFlagIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepStreamManagementFlag*) base;
	_tmp0_ = xmpp_xep_stream_management_flag_IDENTITY;
	_tmp1_ = xmpp_flag_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppXepStreamManagementFlag*
xmpp_xep_stream_management_flag_construct (GType object_type)
{
	XmppXepStreamManagementFlag * self = NULL;
	self = (XmppXepStreamManagementFlag*) xmpp_xmpp_stream_flag_construct (object_type);
	return self;
}

XmppXepStreamManagementFlag*
xmpp_xep_stream_management_flag_new (void)
{
	return xmpp_xep_stream_management_flag_construct (XMPP_XEP_STREAM_MANAGEMENT_TYPE_FLAG);
}

static void
xmpp_xep_stream_management_flag_class_init (XmppXepStreamManagementFlagClass * klass,
                                            gpointer klass_data)
{
	XmppFlagIdentity* _tmp0_;
	xmpp_xep_stream_management_flag_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamFlagClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamFlag*)) xmpp_xep_stream_management_flag_real_get_ns;
	((XmppXmppStreamFlagClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamFlag*)) xmpp_xep_stream_management_flag_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_stream_management_flag_finalize;
	_tmp0_ = xmpp_flag_identity_new (XMPP_XEP_STREAM_MANAGEMENT_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_STREAM_MANAGEMENT_NS_URI, "stream_management");
	xmpp_xep_stream_management_flag_IDENTITY = _tmp0_;
}

static void
xmpp_xep_stream_management_flag_instance_init (XmppXepStreamManagementFlag * self,
                                               gpointer klass)
{
	self->finished = FALSE;
	self->resumed = FALSE;
}

static void
xmpp_xep_stream_management_flag_finalize (GObject * obj)
{
	XmppXepStreamManagementFlag * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_STREAM_MANAGEMENT_TYPE_FLAG, XmppXepStreamManagementFlag);
	G_OBJECT_CLASS (xmpp_xep_stream_management_flag_parent_class)->finalize (obj);
}

static GType
xmpp_xep_stream_management_flag_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepStreamManagementFlagClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_stream_management_flag_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepStreamManagementFlag), 0, (GInstanceInitFunc) xmpp_xep_stream_management_flag_instance_init, NULL };
	GType xmpp_xep_stream_management_flag_type_id;
	xmpp_xep_stream_management_flag_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_FLAG, "XmppXepStreamManagementFlag", &g_define_type_info, 0);
	return xmpp_xep_stream_management_flag_type_id;
}

GType
xmpp_xep_stream_management_flag_get_type (void)
{
	static volatile gsize xmpp_xep_stream_management_flag_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_stream_management_flag_type_id__once)) {
		GType xmpp_xep_stream_management_flag_type_id;
		xmpp_xep_stream_management_flag_type_id = xmpp_xep_stream_management_flag_get_type_once ();
		g_once_init_leave (&xmpp_xep_stream_management_flag_type_id__once, xmpp_xep_stream_management_flag_type_id);
	}
	return xmpp_xep_stream_management_flag_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

