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

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp-vala.h"
#include <glib-object.h>
#include <gee.h>
#include <stdio.h>

#define XMPP_SASL_NS_URI "urn:ietf:params:xml:ns:xmpp-sasl"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	XMPP_SASL_FLAG_0_PROPERTY,
	XMPP_SASL_FLAG_NUM_PROPERTIES
};
static GParamSpec* xmpp_sasl_flag_properties[XMPP_SASL_FLAG_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	XMPP_SASL_MODULE_0_PROPERTY,
	XMPP_SASL_MODULE_NAME_PROPERTY,
	XMPP_SASL_MODULE_PASSWORD_PROPERTY,
	XMPP_SASL_MODULE_NUM_PROPERTIES
};
static GParamSpec* xmpp_sasl_module_properties[XMPP_SASL_MODULE_NUM_PROPERTIES];
#define _g_checksum_free0(var) ((var == NULL) ? NULL : (var = (g_checksum_free (var), NULL)))
#define _g_hmac_unref0(var) ((var == NULL) ? NULL : (var = (g_hmac_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
enum  {
	XMPP_SASL_MODULE_RECEIVED_AUTH_FAILURE_SIGNAL,
	XMPP_SASL_MODULE_NUM_SIGNALS
};
static guint xmpp_sasl_module_signals[XMPP_SASL_MODULE_NUM_SIGNALS] = {0};

struct _XmppSaslModulePrivate {
	gchar* _name;
	gchar* _password;
};

static gpointer xmpp_sasl_flag_parent_class = NULL;
XmppFlagIdentity* xmpp_sasl_flag_IDENTITY = NULL;
static gint XmppSaslModule_private_offset;
static gpointer xmpp_sasl_module_parent_class = NULL;
XmppModuleIdentity* xmpp_sasl_module_IDENTITY = NULL;
static gsize xmpp_sasl_module_SHA1_SIZE;
static gsize xmpp_sasl_module_SHA1_SIZE = (gsize) 20;

static gchar* xmpp_sasl_flag_real_get_ns (XmppXmppStreamFlag* base);
static gchar* xmpp_sasl_flag_real_get_id (XmppXmppStreamFlag* base);
static void xmpp_sasl_flag_finalize (GObject * obj);
static GType xmpp_sasl_flag_get_type_once (void);
static void xmpp_sasl_module_real_attach (XmppXmppStreamModule* base,
                                   XmppXmppStream* stream);
static void _xmpp_sasl_module_received_features_node_xmpp_xmpp_stream_received_features_node (XmppXmppStream* _sender,
                                                                                       XmppXmppStream* stream,
                                                                                       gpointer self);
static void _xmpp_sasl_module_received_nonza_xmpp_xmpp_stream_received_nonza (XmppXmppStream* _sender,
                                                                       XmppXmppStream* stream,
                                                                       XmppStanzaNode* node,
                                                                       gpointer self);
static void xmpp_sasl_module_real_detach (XmppXmppStreamModule* base,
                                   XmppXmppStream* stream);
static guint8* xmpp_sasl_module_sha1 (guint8* data,
                               gint data_length1,
                               gint* result_length1);
static guint8* xmpp_sasl_module_hmac_sha1 (guint8* key,
                                    gint key_length1,
                                    guint8* data,
                                    gint data_length1,
                                    gint* result_length1);
static guint8* xmpp_sasl_module_pbkdf2_sha1 (const gchar* password,
                                      guint8* salt,
                                      gint salt_length1,
                                      guint iterations,
                                      gint* result_length1);
static void xmpp_sasl_module_xor_inplace (guint8* mix,
                                   gint mix_length1,
                                   guint8* a2,
                                   gint a2_length1);
static guint8* xmpp_sasl_module_xor (guint8* a1,
                              gint a1_length1,
                              guint8* a2,
                              gint a2_length1,
                              gint* result_length1);
static void _vala_array_add1 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      gssize stack_length,
                                      const gchar* needle);
static guchar* xmpp_sasl_module_get_plain_bytes (const gchar* name_s,
                                          const gchar* password_s,
                                          gint* result_length1);
static gboolean xmpp_sasl_module_real_mandatory_outstanding (XmppXmppStreamNegotiationModule* base,
                                                      XmppXmppStream* stream);
static gboolean xmpp_sasl_module_real_negotiation_active (XmppXmppStreamNegotiationModule* base,
                                                   XmppXmppStream* stream);
static gchar* xmpp_sasl_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_sasl_module_real_get_id (XmppXmppStreamModule* base);
static void g_cclosure_user_marshal_VOID__OBJECT_XMPP_STANZA_ENTRY (GClosure * closure,
                                                             GValue * return_value,
                                                             guint n_param_values,
                                                             const GValue * param_values,
                                                             gpointer invocation_hint,
                                                             gpointer marshal_data);
static void xmpp_sasl_module_finalize (GObject * obj);
static GType xmpp_sasl_module_get_type_once (void);
static void _vala_xmpp_sasl_module_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_xmpp_sasl_module_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);
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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gchar*
xmpp_sasl_flag_real_get_ns (XmppXmppStreamFlag* base)
{
	XmppSaslFlag * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppSaslFlag*) base;
	_tmp0_ = g_strdup (XMPP_SASL_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_sasl_flag_real_get_id (XmppXmppStreamFlag* base)
{
	XmppSaslFlag * self;
	XmppFlagIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppSaslFlag*) base;
	_tmp0_ = xmpp_sasl_flag_IDENTITY;
	_tmp1_ = xmpp_flag_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppSaslFlag*
xmpp_sasl_flag_construct (GType object_type)
{
	XmppSaslFlag * self = NULL;
	self = (XmppSaslFlag*) xmpp_xmpp_stream_flag_construct (object_type);
	return self;
}

XmppSaslFlag*
xmpp_sasl_flag_new (void)
{
	return xmpp_sasl_flag_construct (XMPP_SASL_TYPE_FLAG);
}

static void
xmpp_sasl_flag_class_init (XmppSaslFlagClass * klass,
                           gpointer klass_data)
{
	XmppFlagIdentity* _tmp0_;
	xmpp_sasl_flag_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamFlagClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamFlag*)) xmpp_sasl_flag_real_get_ns;
	((XmppXmppStreamFlagClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamFlag*)) xmpp_sasl_flag_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_sasl_flag_finalize;
	_tmp0_ = xmpp_flag_identity_new (XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_SASL_NS_URI, "sasl");
	xmpp_sasl_flag_IDENTITY = _tmp0_;
}

static void
xmpp_sasl_flag_instance_init (XmppSaslFlag * self,
                              gpointer klass)
{
	self->finished = FALSE;
}

static void
xmpp_sasl_flag_finalize (GObject * obj)
{
	XmppSaslFlag * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_SASL_TYPE_FLAG, XmppSaslFlag);
	_g_free0 (self->mechanism);
	_g_free0 (self->name);
	_g_free0 (self->password);
	_g_free0 (self->client_nonce);
	self->server_signature = (g_free (self->server_signature), NULL);
	G_OBJECT_CLASS (xmpp_sasl_flag_parent_class)->finalize (obj);
}

static GType
xmpp_sasl_flag_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppSaslFlagClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_sasl_flag_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppSaslFlag), 0, (GInstanceInitFunc) xmpp_sasl_flag_instance_init, NULL };
	GType xmpp_sasl_flag_type_id;
	xmpp_sasl_flag_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_FLAG, "XmppSaslFlag", &g_define_type_info, 0);
	return xmpp_sasl_flag_type_id;
}

GType
xmpp_sasl_flag_get_type (void)
{
	static volatile gsize xmpp_sasl_flag_type_id__once = 0;
	if (g_once_init_enter (&xmpp_sasl_flag_type_id__once)) {
		GType xmpp_sasl_flag_type_id;
		xmpp_sasl_flag_type_id = xmpp_sasl_flag_get_type_once ();
		g_once_init_leave (&xmpp_sasl_flag_type_id__once, xmpp_sasl_flag_type_id);
	}
	return xmpp_sasl_flag_type_id__once;
}

static inline gpointer
xmpp_sasl_module_get_instance_private (XmppSaslModule* self)
{
	return G_STRUCT_MEMBER_P (self, XmppSaslModule_private_offset);
}

XmppSaslModule*
xmpp_sasl_module_construct (GType object_type,
                            const gchar* name,
                            const gchar* password)
{
	XmppSaslModule * self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (password != NULL, NULL);
	self = (XmppSaslModule*) xmpp_xmpp_stream_negotiation_module_construct (object_type);
	xmpp_sasl_module_set_name (self, name);
	xmpp_sasl_module_set_password (self, password);
	return self;
}

XmppSaslModule*
xmpp_sasl_module_new (const gchar* name,
                      const gchar* password)
{
	return xmpp_sasl_module_construct (XMPP_SASL_TYPE_MODULE, name, password);
}

static void
_xmpp_sasl_module_received_features_node_xmpp_xmpp_stream_received_features_node (XmppXmppStream* _sender,
                                                                                  XmppXmppStream* stream,
                                                                                  gpointer self)
{
	xmpp_sasl_module_received_features_node ((XmppSaslModule*) self, stream);
}

static void
_xmpp_sasl_module_received_nonza_xmpp_xmpp_stream_received_nonza (XmppXmppStream* _sender,
                                                                  XmppXmppStream* stream,
                                                                  XmppStanzaNode* node,
                                                                  gpointer self)
{
	xmpp_sasl_module_received_nonza ((XmppSaslModule*) self, stream, node);
}

static void
xmpp_sasl_module_real_attach (XmppXmppStreamModule* base,
                              XmppXmppStream* stream)
{
	XmppSaslModule * self;
	self = (XmppSaslModule*) base;
	g_return_if_fail (stream != NULL);
	g_signal_connect_object (stream, "received-features-node", (GCallback) _xmpp_sasl_module_received_features_node_xmpp_xmpp_stream_received_features_node, self, 0);
	g_signal_connect_object (stream, "received-nonza", (GCallback) _xmpp_sasl_module_received_nonza_xmpp_xmpp_stream_received_nonza, self, 0);
}

static void
xmpp_sasl_module_real_detach (XmppXmppStreamModule* base,
                              XmppXmppStream* stream)
{
	XmppSaslModule * self;
	guint _tmp0_;
	guint _tmp1_;
	self = (XmppSaslModule*) base;
	g_return_if_fail (stream != NULL);
	g_signal_parse_name ("received-features-node", XMPP_TYPE_XMPP_STREAM, &_tmp0_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (stream, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, 0, NULL, (GCallback) _xmpp_sasl_module_received_features_node_xmpp_xmpp_stream_received_features_node, self);
	g_signal_parse_name ("received-nonza", XMPP_TYPE_XMPP_STREAM, &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (stream, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _xmpp_sasl_module_received_nonza_xmpp_xmpp_stream_received_nonza, self);
}

static guint8*
xmpp_sasl_module_sha1 (guint8* data,
                       gint data_length1,
                       gint* result_length1)
{
	GChecksum* checksum = NULL;
	GChecksum* _tmp0_;
	guint8* res = NULL;
	guint8* _tmp1_;
	gint res_length1;
	gint _res_size_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	guint8* result;
	_tmp0_ = g_checksum_new (G_CHECKSUM_SHA1);
	checksum = _tmp0_;
	g_checksum_update (checksum, data, (gsize) data_length1);
	_tmp1_ = g_new0 (guint8, xmpp_sasl_module_SHA1_SIZE);
	res = _tmp1_;
	res_length1 = xmpp_sasl_module_SHA1_SIZE;
	_res_size_ = res_length1;
	g_checksum_get_digest (checksum, res, &xmpp_sasl_module_SHA1_SIZE);
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	_g_checksum_free0 (checksum);
	return result;
}

static guint8*
xmpp_sasl_module_hmac_sha1 (guint8* key,
                            gint key_length1,
                            guint8* data,
                            gint data_length1,
                            gint* result_length1)
{
	GHmac* hmac = NULL;
	GHmac* _tmp0_;
	guint8* res = NULL;
	guint8* _tmp1_;
	gint res_length1;
	gint _res_size_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	guint8* result;
	_tmp0_ = g_hmac_new (G_CHECKSUM_SHA1, key, key_length1);
	hmac = _tmp0_;
	g_hmac_update (hmac, data, (gssize) data_length1);
	_tmp1_ = g_new0 (guint8, xmpp_sasl_module_SHA1_SIZE);
	res = _tmp1_;
	res_length1 = xmpp_sasl_module_SHA1_SIZE;
	_res_size_ = res_length1;
	g_hmac_get_digest (hmac, res, &xmpp_sasl_module_SHA1_SIZE);
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	_g_hmac_unref0 (hmac);
	return result;
}

static gchar*
string_to_utf8 (const gchar* self,
                gint* result_length1)
{
	gint string_length = 0;
	gint _tmp0_;
	gint _tmp1_;
	gchar* _result_ = NULL;
	gchar* _tmp2_;
	gint _result__length1;
	gint __result__size_;
	gint _tmp3_;
	gchar* _tmp4_;
	gint _tmp4__length1;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = _tmp1_;
	_tmp2_ = g_new0 (gchar, string_length + 1);
	_result_ = _tmp2_;
	_result__length1 = string_length + 1;
	__result__size_ = _result__length1;
	_tmp3_ = _result__length1;
	_result__length1 = _tmp3_ - 1;
	memcpy (_result_, self, (gsize) string_length);
	_tmp4_ = _result_;
	_tmp4__length1 = _result__length1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}

static guint8*
xmpp_sasl_module_pbkdf2_sha1 (const gchar* password,
                              guint8* salt,
                              gint salt_length1,
                              guint iterations,
                              gint* result_length1)
{
	guint8* res = NULL;
	guint8* _tmp0_;
	gint res_length1;
	gint _res_size_;
	guint8* last = NULL;
	guint8* _tmp1_;
	gint last_length1;
	gint _last_size_;
	guint8* _tmp6_;
	gint _tmp6__length1;
	guint8* _tmp17_;
	gint _tmp17__length1;
	guint8* result;
	g_return_val_if_fail (password != NULL, NULL);
	_tmp0_ = g_new0 (guint8, xmpp_sasl_module_SHA1_SIZE);
	res = _tmp0_;
	res_length1 = xmpp_sasl_module_SHA1_SIZE;
	_res_size_ = res_length1;
	_tmp1_ = g_new0 (guint8, salt_length1 + 4);
	last = _tmp1_;
	last_length1 = salt_length1 + 4;
	_last_size_ = last_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				guint8* _tmp4_;
				gint _tmp4__length1;
				guint8 _tmp5_;
				if (!_tmp2_) {
					gint _tmp3_;
					_tmp3_ = i;
					i = _tmp3_ + 1;
				}
				_tmp2_ = FALSE;
				if (!(i < salt_length1)) {
					break;
				}
				_tmp4_ = last;
				_tmp4__length1 = last_length1;
				_tmp5_ = salt[i];
				_tmp4_[i] = _tmp5_;
			}
		}
	}
	_tmp6_ = last;
	_tmp6__length1 = last_length1;
	_tmp6_[salt_length1 + 3] = (guint8) 1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp7_ = FALSE;
			_tmp7_ = TRUE;
			while (TRUE) {
				gint _tmp9_ = 0;
				gchar* _tmp10_;
				guint8* _tmp11_;
				gint _tmp11__length1;
				guint8* _tmp12_;
				gint _tmp12__length1;
				gint _tmp13_ = 0;
				guint8* _tmp14_;
				guint8* _tmp15_;
				gint _tmp15__length1;
				guint8* _tmp16_;
				gint _tmp16__length1;
				if (!_tmp7_) {
					gint _tmp8_;
					_tmp8_ = i;
					i = _tmp8_ + 1;
				}
				_tmp7_ = FALSE;
				if (!(((guint) i) < iterations)) {
					break;
				}
				_tmp10_ = string_to_utf8 (password, &_tmp9_);
				_tmp11_ = (guint8*) _tmp10_;
				_tmp11__length1 = (_tmp9_ * sizeof (gchar)) / sizeof (guint8);
				_tmp12_ = last;
				_tmp12__length1 = last_length1;
				_tmp14_ = xmpp_sasl_module_hmac_sha1 (_tmp11_, (gint) ((_tmp9_ * sizeof (gchar)) / sizeof (guint8)), _tmp12_, (gint) _tmp12__length1, &_tmp13_);
				last = (g_free (last), NULL);
				last = _tmp14_;
				last_length1 = _tmp13_;
				_last_size_ = last_length1;
				_tmp11_ = (g_free (_tmp11_), NULL);
				_tmp15_ = res;
				_tmp15__length1 = res_length1;
				_tmp16_ = last;
				_tmp16__length1 = last_length1;
				xmpp_sasl_module_xor_inplace (_tmp15_, (gint) _tmp15__length1, _tmp16_, (gint) _tmp16__length1);
			}
		}
	}
	_tmp17_ = res;
	_tmp17__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp17__length1;
	}
	result = _tmp17_;
	last = (g_free (last), NULL);
	return result;
}

static void
xmpp_sasl_module_xor_inplace (guint8* mix,
                              gint mix_length1,
                              guint8* a2,
                              gint a2_length1)
{
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				guint8 _tmp2_;
				guint8 _tmp3_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < mix_length1)) {
					break;
				}
				_tmp2_ = mix[i];
				_tmp3_ = a2[i];
				mix[i] = _tmp2_ ^ _tmp3_;
			}
		}
	}
}

static guint8*
xmpp_sasl_module_xor (guint8* a1,
                      gint a1_length1,
                      guint8* a2,
                      gint a2_length1,
                      gint* result_length1)
{
	guint8* mix = NULL;
	guint8* _tmp0_;
	gint mix_length1;
	gint _mix_size_;
	guint8* _tmp6_;
	gint _tmp6__length1;
	guint8* result;
	_tmp0_ = g_new0 (guint8, a1_length1);
	mix = _tmp0_;
	mix_length1 = a1_length1;
	_mix_size_ = mix_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				guint8* _tmp3_;
				gint _tmp3__length1;
				guint8 _tmp4_;
				guint8 _tmp5_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				if (!(i < a1_length1)) {
					break;
				}
				_tmp3_ = mix;
				_tmp3__length1 = mix_length1;
				_tmp4_ = a1[i];
				_tmp5_ = a2[i];
				_tmp3_[i] = _tmp4_ ^ _tmp5_;
			}
		}
	}
	_tmp6_ = mix;
	_tmp6__length1 = mix_length1;
	if (result_length1) {
		*result_length1 = _tmp6__length1;
	}
	result = _tmp6_;
	return result;
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

void
xmpp_sasl_module_received_nonza (XmppSaslModule* 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_SASL_NS_URI) == 0) {
		const gchar* _tmp1_;
		_tmp1_ = ((XmppStanzaEntry*) node)->name;
		if (g_strcmp0 (_tmp1_, "success") == 0) {
			XmppSaslFlag* flag = NULL;
			XmppFlagIdentity* _tmp2_;
			gpointer _tmp3_;
			XmppSaslFlag* _tmp4_;
			const gchar* _tmp5_;
			XmppSaslFlag* _tmp38_;
			XmppSaslFlag* _tmp39_;
			_tmp2_ = xmpp_sasl_flag_IDENTITY;
			_tmp3_ = xmpp_xmpp_stream_get_flag (stream, XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
			flag = (XmppSaslFlag*) _tmp3_;
			_tmp4_ = flag;
			_tmp5_ = _tmp4_->mechanism;
			if (g_strcmp0 (_tmp5_, XMPP_SASL_MECHANISM_SCRAM_SHA_1) == 0) {
				gchar* confirm = NULL;
				const gchar* _tmp6_;
				gsize _tmp7_ = 0;
				guchar* _tmp8_;
				guint8* server_signature = NULL;
				gint server_signature_length1;
				gint _server_signature_size_;
				const gchar* _tmp9_;
				gchar** _tmp10_;
				gchar** _tmp11_;
				guint8* _tmp26_;
				gint _tmp26__length1;
				guint8* _tmp27_;
				gint _tmp27__length1;
				XmppSaslFlag* _tmp28_;
				guint8* _tmp29_;
				gint _tmp29__length1;
				_tmp6_ = xmpp_stanza_entry_get_string_content ((XmppStanzaEntry*) node);
				_tmp8_ = g_base64_decode (_tmp6_, &_tmp7_);
				confirm = (gchar*) _tmp8_;
				server_signature = NULL;
				server_signature_length1 = 0;
				_server_signature_size_ = server_signature_length1;
				_tmp9_ = confirm;
				_tmp11_ = _tmp10_ = g_strsplit (_tmp9_, ",", 0);
				{
					gchar** c_collection = NULL;
					gint c_collection_length1 = 0;
					gint _c_collection_size_ = 0;
					gint c_it = 0;
					c_collection = _tmp11_;
					c_collection_length1 = _vala_array_length (_tmp10_);
					for (c_it = 0; c_it < c_collection_length1; c_it = c_it + 1) {
						gchar* _tmp12_;
						gchar* c = NULL;
						_tmp12_ = g_strdup (c_collection[c_it]);
						c = _tmp12_;
						{
							gchar** split = NULL;
							const gchar* _tmp13_;
							gchar** _tmp14_;
							gchar** _tmp15_;
							gint split_length1;
							gint _split_size_;
							gchar** _tmp16_;
							gint _tmp16__length1;
							gchar** _tmp17_;
							gint _tmp17__length1;
							const gchar* _tmp18_;
							const gchar* _tmp19_;
							GQuark _tmp21_ = 0U;
							static GQuark _tmp20_label0 = 0;
							_tmp13_ = c;
							_tmp15_ = _tmp14_ = g_strsplit (_tmp13_, "=", 2);
							split = _tmp15_;
							split_length1 = _vala_array_length (_tmp14_);
							_split_size_ = split_length1;
							_tmp16_ = split;
							_tmp16__length1 = split_length1;
							if (_tmp16__length1 != 2) {
								split = (_vala_array_free (split, split_length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (c);
								continue;
							}
							_tmp17_ = split;
							_tmp17__length1 = split_length1;
							_tmp18_ = _tmp17_[0];
							_tmp19_ = _tmp18_;
							_tmp21_ = (NULL == _tmp19_) ? 0 : g_quark_from_string (_tmp19_);
							if (_tmp21_ == ((0 != _tmp20_label0) ? _tmp20_label0 : (_tmp20_label0 = g_quark_from_static_string ("v")))) {
								switch (0) {
									default:
									{
										gchar** _tmp22_;
										gint _tmp22__length1;
										const gchar* _tmp23_;
										gsize _tmp24_ = 0;
										guchar* _tmp25_;
										_tmp22_ = split;
										_tmp22__length1 = split_length1;
										_tmp23_ = _tmp22_[1];
										_tmp25_ = g_base64_decode (_tmp23_, &_tmp24_);
										server_signature = (g_free (server_signature), NULL);
										server_signature = _tmp25_;
										server_signature_length1 = _tmp24_;
										_server_signature_size_ = server_signature_length1;
										break;
									}
								}
							}
							split = (_vala_array_free (split, split_length1, (GDestroyNotify) g_free), NULL);
							_g_free0 (c);
						}
					}
					c_collection = (_vala_array_free (c_collection, c_collection_length1, (GDestroyNotify) g_free), NULL);
				}
				_tmp26_ = server_signature;
				_tmp26__length1 = server_signature_length1;
				if (_tmp26_ == NULL) {
					server_signature = (g_free (server_signature), NULL);
					_g_free0 (confirm);
					_g_object_unref0 (flag);
					return;
				}
				_tmp27_ = server_signature;
				_tmp27__length1 = server_signature_length1;
				_tmp28_ = flag;
				_tmp29_ = _tmp28_->server_signature;
				_tmp29__length1 = _tmp28_->server_signature_length1;
				if (_tmp27__length1 != _tmp29__length1) {
					server_signature = (g_free (server_signature), NULL);
					_g_free0 (confirm);
					_g_object_unref0 (flag);
					return;
				}
				{
					gint i = 0;
					i = 0;
					{
						gboolean _tmp30_ = FALSE;
						_tmp30_ = TRUE;
						while (TRUE) {
							guint8* _tmp32_;
							gint _tmp32__length1;
							guint8* _tmp33_;
							gint _tmp33__length1;
							guint8 _tmp34_;
							XmppSaslFlag* _tmp35_;
							guint8* _tmp36_;
							gint _tmp36__length1;
							guint8 _tmp37_;
							if (!_tmp30_) {
								gint _tmp31_;
								_tmp31_ = i;
								i = _tmp31_ + 1;
							}
							_tmp30_ = FALSE;
							_tmp32_ = server_signature;
							_tmp32__length1 = server_signature_length1;
							if (!(i < _tmp32__length1)) {
								break;
							}
							_tmp33_ = server_signature;
							_tmp33__length1 = server_signature_length1;
							_tmp34_ = _tmp33_[i];
							_tmp35_ = flag;
							_tmp36_ = _tmp35_->server_signature;
							_tmp36__length1 = _tmp35_->server_signature_length1;
							_tmp37_ = _tmp36_[i];
							if (_tmp34_ != _tmp37_) {
								server_signature = (g_free (server_signature), NULL);
								_g_free0 (confirm);
								_g_object_unref0 (flag);
								return;
							}
						}
					}
				}
				server_signature = (g_free (server_signature), NULL);
				_g_free0 (confirm);
			}
			xmpp_xmpp_stream_require_setup (stream);
			_tmp38_ = flag;
			_g_free0 (_tmp38_->password);
			_tmp38_->password = NULL;
			_tmp39_ = flag;
			_tmp39_->finished = TRUE;
			_g_object_unref0 (flag);
		} else {
			const gchar* _tmp40_;
			_tmp40_ = ((XmppStanzaEntry*) node)->name;
			if (g_strcmp0 (_tmp40_, "failure") == 0) {
				XmppFlagIdentity* _tmp41_;
				gpointer _tmp42_;
				XmppSaslFlag* _tmp43_;
				_tmp41_ = xmpp_sasl_flag_IDENTITY;
				_tmp42_ = xmpp_xmpp_stream_get_flag (stream, XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp41_);
				_tmp43_ = (XmppSaslFlag*) _tmp42_;
				xmpp_xmpp_stream_remove_flag (stream, (XmppXmppStreamFlag*) _tmp43_);
				_g_object_unref0 (_tmp43_);
				g_signal_emit (self, xmpp_sasl_module_signals[XMPP_SASL_MODULE_RECEIVED_AUTH_FAILURE_SIGNAL], 0, stream, node);
			} else {
				gboolean _tmp44_ = FALSE;
				const gchar* _tmp45_;
				_tmp45_ = ((XmppStanzaEntry*) node)->name;
				if (g_strcmp0 (_tmp45_, "challenge") == 0) {
					XmppFlagIdentity* _tmp46_;
					_tmp46_ = xmpp_sasl_flag_IDENTITY;
					_tmp44_ = xmpp_xmpp_stream_has_flag (stream, XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp46_);
				} else {
					_tmp44_ = FALSE;
				}
				if (_tmp44_) {
					XmppSaslFlag* flag = NULL;
					XmppFlagIdentity* _tmp47_;
					gpointer _tmp48_;
					XmppSaslFlag* _tmp49_;
					const gchar* _tmp50_;
					_tmp47_ = xmpp_sasl_flag_IDENTITY;
					_tmp48_ = xmpp_xmpp_stream_get_flag (stream, XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp47_);
					flag = (XmppSaslFlag*) _tmp48_;
					_tmp49_ = flag;
					_tmp50_ = _tmp49_->mechanism;
					if (g_strcmp0 (_tmp50_, XMPP_SASL_MECHANISM_SCRAM_SHA_1) == 0) {
						gchar* challenge = NULL;
						const gchar* _tmp51_;
						gsize _tmp52_ = 0;
						guchar* _tmp53_;
						gchar* server_nonce = NULL;
						guint8* salt = NULL;
						gint salt_length1;
						gint _salt_size_;
						guint iterations = 0U;
						const gchar* _tmp54_;
						gchar** _tmp55_;
						gchar** _tmp56_;
						gboolean _tmp76_ = FALSE;
						gboolean _tmp77_ = FALSE;
						const gchar* _tmp78_;
						const gchar* _tmp80_;
						XmppSaslFlag* _tmp81_;
						const gchar* _tmp82_;
						gchar* client_final_message_bare = NULL;
						const gchar* _tmp83_;
						const gchar* _tmp84_;
						gchar* _tmp85_;
						guint8* salted_password = NULL;
						XmppSaslFlag* _tmp86_;
						const gchar* _tmp87_;
						guint8* _tmp88_;
						gint _tmp88__length1;
						gint _tmp89_ = 0;
						guint8* _tmp90_;
						gint salted_password_length1;
						gint _salted_password_size_;
						guint8* client_key = NULL;
						guint8* _tmp91_;
						gint _tmp91__length1;
						gint _tmp92_ = 0;
						gchar* _tmp93_;
						guint8* _tmp94_;
						gint _tmp94__length1;
						gint _tmp95_ = 0;
						guint8* _tmp96_;
						guint8* _tmp97_;
						gint _tmp97__length1;
						gint client_key_length1;
						gint _client_key_size_;
						guint8* stored_key = NULL;
						guint8* _tmp98_;
						gint _tmp98__length1;
						gint _tmp99_ = 0;
						guint8* _tmp100_;
						gint stored_key_length1;
						gint _stored_key_size_;
						gchar* auth_message = NULL;
						XmppSaslFlag* _tmp101_;
						const gchar* _tmp102_;
						const gchar* _tmp103_;
						XmppSaslFlag* _tmp104_;
						const gchar* _tmp105_;
						const gchar* _tmp106_;
						const gchar* _tmp107_;
						const gchar* _tmp108_;
						const gchar* _tmp109_;
						const gchar* _tmp110_;
						gchar* _tmp111_;
						guint8* client_signature = NULL;
						guint8* _tmp112_;
						gint _tmp112__length1;
						const gchar* _tmp113_;
						gint _tmp114_ = 0;
						gchar* _tmp115_;
						guint8* _tmp116_;
						gint _tmp116__length1;
						gint _tmp117_ = 0;
						guint8* _tmp118_;
						guint8* _tmp119_;
						gint _tmp119__length1;
						gint client_signature_length1;
						gint _client_signature_size_;
						guint8* client_proof = NULL;
						guint8* _tmp120_;
						gint _tmp120__length1;
						guint8* _tmp121_;
						gint _tmp121__length1;
						gint _tmp122_ = 0;
						guint8* _tmp123_;
						gint client_proof_length1;
						gint _client_proof_size_;
						guint8* server_key = NULL;
						guint8* _tmp124_;
						gint _tmp124__length1;
						gint _tmp125_ = 0;
						gchar* _tmp126_;
						guint8* _tmp127_;
						gint _tmp127__length1;
						gint _tmp128_ = 0;
						guint8* _tmp129_;
						guint8* _tmp130_;
						gint _tmp130__length1;
						gint server_key_length1;
						gint _server_key_size_;
						XmppSaslFlag* _tmp131_;
						guint8* _tmp132_;
						gint _tmp132__length1;
						const gchar* _tmp133_;
						gint _tmp134_ = 0;
						gchar* _tmp135_;
						guint8* _tmp136_;
						gint _tmp136__length1;
						gint _tmp137_ = 0;
						guint8* _tmp138_;
						gchar* client_final_message = NULL;
						const gchar* _tmp139_;
						const gchar* _tmp140_;
						guint8* _tmp141_;
						gint _tmp141__length1;
						gchar* _tmp142_;
						gchar* _tmp143_;
						const gchar* _tmp144_;
						gchar* _tmp145_;
						gchar* _tmp146_;
						XmppStanzaNode* _tmp147_;
						XmppStanzaNode* _tmp148_;
						XmppStanzaNode* _tmp149_;
						XmppStanzaNode* _tmp150_;
						const gchar* _tmp151_;
						gint _tmp152_ = 0;
						gchar* _tmp153_;
						guchar* _tmp154_;
						gint _tmp154__length1;
						gchar* _tmp155_;
						gchar* _tmp156_;
						XmppStanzaNode* _tmp157_;
						XmppStanzaNode* _tmp158_;
						XmppStanzaNode* _tmp159_;
						XmppStanzaNode* _tmp160_;
						_tmp51_ = xmpp_stanza_entry_get_string_content ((XmppStanzaEntry*) node);
						_tmp53_ = g_base64_decode (_tmp51_, &_tmp52_);
						challenge = (gchar*) _tmp53_;
						server_nonce = NULL;
						salt = NULL;
						salt_length1 = 0;
						_salt_size_ = salt_length1;
						iterations = (guint) 0;
						_tmp54_ = challenge;
						_tmp56_ = _tmp55_ = g_strsplit (_tmp54_, ",", 0);
						{
							gchar** c_collection = NULL;
							gint c_collection_length1 = 0;
							gint _c_collection_size_ = 0;
							gint c_it = 0;
							c_collection = _tmp56_;
							c_collection_length1 = _vala_array_length (_tmp55_);
							for (c_it = 0; c_it < c_collection_length1; c_it = c_it + 1) {
								gchar* _tmp57_;
								gchar* c = NULL;
								_tmp57_ = g_strdup (c_collection[c_it]);
								c = _tmp57_;
								{
									gchar** split = NULL;
									const gchar* _tmp58_;
									gchar** _tmp59_;
									gchar** _tmp60_;
									gint split_length1;
									gint _split_size_;
									gchar** _tmp61_;
									gint _tmp61__length1;
									gchar** _tmp62_;
									gint _tmp62__length1;
									const gchar* _tmp63_;
									const gchar* _tmp64_;
									GQuark _tmp66_ = 0U;
									static GQuark _tmp65_label0 = 0;
									static GQuark _tmp65_label1 = 0;
									static GQuark _tmp65_label2 = 0;
									_tmp58_ = c;
									_tmp60_ = _tmp59_ = g_strsplit (_tmp58_, "=", 2);
									split = _tmp60_;
									split_length1 = _vala_array_length (_tmp59_);
									_split_size_ = split_length1;
									_tmp61_ = split;
									_tmp61__length1 = split_length1;
									if (_tmp61__length1 != 2) {
										split = (_vala_array_free (split, split_length1, (GDestroyNotify) g_free), NULL);
										_g_free0 (c);
										continue;
									}
									_tmp62_ = split;
									_tmp62__length1 = split_length1;
									_tmp63_ = _tmp62_[0];
									_tmp64_ = _tmp63_;
									_tmp66_ = (NULL == _tmp64_) ? 0 : g_quark_from_string (_tmp64_);
									if (_tmp66_ == ((0 != _tmp65_label0) ? _tmp65_label0 : (_tmp65_label0 = g_quark_from_static_string ("r")))) {
										switch (0) {
											default:
											{
												gchar** _tmp67_;
												gint _tmp67__length1;
												const gchar* _tmp68_;
												gchar* _tmp69_;
												_tmp67_ = split;
												_tmp67__length1 = split_length1;
												_tmp68_ = _tmp67_[1];
												_tmp69_ = g_strdup (_tmp68_);
												_g_free0 (server_nonce);
												server_nonce = _tmp69_;
												break;
											}
										}
									} else if (_tmp66_ == ((0 != _tmp65_label1) ? _tmp65_label1 : (_tmp65_label1 = g_quark_from_static_string ("s")))) {
										switch (0) {
											default:
											{
												gchar** _tmp70_;
												gint _tmp70__length1;
												const gchar* _tmp71_;
												gsize _tmp72_ = 0;
												guchar* _tmp73_;
												_tmp70_ = split;
												_tmp70__length1 = split_length1;
												_tmp71_ = _tmp70_[1];
												_tmp73_ = g_base64_decode (_tmp71_, &_tmp72_);
												salt = (g_free (salt), NULL);
												salt = _tmp73_;
												salt_length1 = _tmp72_;
												_salt_size_ = salt_length1;
												break;
											}
										}
									} else if (_tmp66_ == ((0 != _tmp65_label2) ? _tmp65_label2 : (_tmp65_label2 = g_quark_from_static_string ("i")))) {
										switch (0) {
											default:
											{
												gchar** _tmp74_;
												gint _tmp74__length1;
												const gchar* _tmp75_;
												_tmp74_ = split;
												_tmp74__length1 = split_length1;
												_tmp75_ = _tmp74_[1];
												iterations = (guint) atoi (_tmp75_);
												break;
											}
										}
									}
									split = (_vala_array_free (split, split_length1, (GDestroyNotify) g_free), NULL);
									_g_free0 (c);
								}
							}
							c_collection = (_vala_array_free (c_collection, c_collection_length1, (GDestroyNotify) g_free), NULL);
						}
						_tmp78_ = server_nonce;
						if (_tmp78_ == NULL) {
							_tmp77_ = TRUE;
						} else {
							guint8* _tmp79_;
							gint _tmp79__length1;
							_tmp79_ = salt;
							_tmp79__length1 = salt_length1;
							_tmp77_ = _tmp79_ == NULL;
						}
						if (_tmp77_) {
							_tmp76_ = TRUE;
						} else {
							_tmp76_ = iterations == ((guint) 0);
						}
						if (_tmp76_) {
							salt = (g_free (salt), NULL);
							_g_free0 (server_nonce);
							_g_free0 (challenge);
							_g_object_unref0 (flag);
							return;
						}
						_tmp80_ = server_nonce;
						_tmp81_ = flag;
						_tmp82_ = _tmp81_->client_nonce;
						if (!g_str_has_prefix (_tmp80_, _tmp82_)) {
							salt = (g_free (salt), NULL);
							_g_free0 (server_nonce);
							_g_free0 (challenge);
							_g_object_unref0 (flag);
							return;
						}
						_tmp83_ = server_nonce;
						_tmp84_ = string_to_string (_tmp83_);
						_tmp85_ = g_strconcat ("c=biws,r=", _tmp84_, NULL);
						client_final_message_bare = _tmp85_;
						_tmp86_ = flag;
						_tmp87_ = _tmp86_->password;
						_tmp88_ = salt;
						_tmp88__length1 = salt_length1;
						_tmp90_ = xmpp_sasl_module_pbkdf2_sha1 (_tmp87_, _tmp88_, (gint) _tmp88__length1, iterations, &_tmp89_);
						salted_password = _tmp90_;
						salted_password_length1 = _tmp89_;
						_salted_password_size_ = salted_password_length1;
						_tmp91_ = salted_password;
						_tmp91__length1 = salted_password_length1;
						_tmp93_ = string_to_utf8 ("Client Key", &_tmp92_);
						_tmp94_ = (guint8*) _tmp93_;
						_tmp94__length1 = (_tmp92_ * sizeof (gchar)) / sizeof (guint8);
						_tmp96_ = xmpp_sasl_module_hmac_sha1 (_tmp91_, (gint) _tmp91__length1, _tmp94_, (gint) ((_tmp92_ * sizeof (gchar)) / sizeof (guint8)), &_tmp95_);
						_tmp97_ = _tmp96_;
						_tmp97__length1 = _tmp95_;
						_tmp94_ = (g_free (_tmp94_), NULL);
						client_key = _tmp97_;
						client_key_length1 = _tmp97__length1;
						_client_key_size_ = client_key_length1;
						_tmp98_ = client_key;
						_tmp98__length1 = client_key_length1;
						_tmp100_ = xmpp_sasl_module_sha1 (_tmp98_, (gint) _tmp98__length1, &_tmp99_);
						stored_key = _tmp100_;
						stored_key_length1 = _tmp99_;
						_stored_key_size_ = stored_key_length1;
						_tmp101_ = flag;
						_tmp102_ = _tmp101_->name;
						_tmp103_ = string_to_string (_tmp102_);
						_tmp104_ = flag;
						_tmp105_ = _tmp104_->client_nonce;
						_tmp106_ = string_to_string (_tmp105_);
						_tmp107_ = challenge;
						_tmp108_ = string_to_string (_tmp107_);
						_tmp109_ = client_final_message_bare;
						_tmp110_ = string_to_string (_tmp109_);
						_tmp111_ = g_strconcat ("n=", _tmp103_, ",r=", _tmp106_, ",", _tmp108_, ",", _tmp110_, NULL);
						auth_message = _tmp111_;
						_tmp112_ = stored_key;
						_tmp112__length1 = stored_key_length1;
						_tmp113_ = auth_message;
						_tmp115_ = string_to_utf8 (_tmp113_, &_tmp114_);
						_tmp116_ = (guint8*) _tmp115_;
						_tmp116__length1 = (_tmp114_ * sizeof (gchar)) / sizeof (guint8);
						_tmp118_ = xmpp_sasl_module_hmac_sha1 (_tmp112_, (gint) _tmp112__length1, _tmp116_, (gint) ((_tmp114_ * sizeof (gchar)) / sizeof (guint8)), &_tmp117_);
						_tmp119_ = _tmp118_;
						_tmp119__length1 = _tmp117_;
						_tmp116_ = (g_free (_tmp116_), NULL);
						client_signature = _tmp119_;
						client_signature_length1 = _tmp119__length1;
						_client_signature_size_ = client_signature_length1;
						_tmp120_ = client_key;
						_tmp120__length1 = client_key_length1;
						_tmp121_ = client_signature;
						_tmp121__length1 = client_signature_length1;
						_tmp123_ = xmpp_sasl_module_xor (_tmp120_, (gint) _tmp120__length1, _tmp121_, (gint) _tmp121__length1, &_tmp122_);
						client_proof = _tmp123_;
						client_proof_length1 = _tmp122_;
						_client_proof_size_ = client_proof_length1;
						_tmp124_ = salted_password;
						_tmp124__length1 = salted_password_length1;
						_tmp126_ = string_to_utf8 ("Server Key", &_tmp125_);
						_tmp127_ = (guint8*) _tmp126_;
						_tmp127__length1 = (_tmp125_ * sizeof (gchar)) / sizeof (guint8);
						_tmp129_ = xmpp_sasl_module_hmac_sha1 (_tmp124_, (gint) _tmp124__length1, _tmp127_, (gint) ((_tmp125_ * sizeof (gchar)) / sizeof (guint8)), &_tmp128_);
						_tmp130_ = _tmp129_;
						_tmp130__length1 = _tmp128_;
						_tmp127_ = (g_free (_tmp127_), NULL);
						server_key = _tmp130_;
						server_key_length1 = _tmp130__length1;
						_server_key_size_ = server_key_length1;
						_tmp131_ = flag;
						_tmp132_ = server_key;
						_tmp132__length1 = server_key_length1;
						_tmp133_ = auth_message;
						_tmp135_ = string_to_utf8 (_tmp133_, &_tmp134_);
						_tmp136_ = (guint8*) _tmp135_;
						_tmp136__length1 = (_tmp134_ * sizeof (gchar)) / sizeof (guint8);
						_tmp138_ = xmpp_sasl_module_hmac_sha1 (_tmp132_, (gint) _tmp132__length1, _tmp136_, (gint) ((_tmp134_ * sizeof (gchar)) / sizeof (guint8)), &_tmp137_);
						_tmp131_->server_signature = (g_free (_tmp131_->server_signature), NULL);
						_tmp131_->server_signature = _tmp138_;
						_tmp131_->server_signature_length1 = _tmp137_;
						_tmp136_ = (g_free (_tmp136_), NULL);
						_tmp139_ = client_final_message_bare;
						_tmp140_ = string_to_string (_tmp139_);
						_tmp141_ = client_proof;
						_tmp141__length1 = client_proof_length1;
						_tmp142_ = g_base64_encode (_tmp141_, (gint) _tmp141__length1);
						_tmp143_ = _tmp142_;
						_tmp144_ = string_to_string (_tmp143_);
						_tmp145_ = g_strconcat (_tmp140_, ",p=", _tmp144_, NULL);
						_tmp146_ = _tmp145_;
						_g_free0 (_tmp143_);
						client_final_message = _tmp146_;
						_tmp147_ = xmpp_stanza_node_new_build ("response", XMPP_SASL_NS_URI, NULL, NULL);
						_tmp148_ = _tmp147_;
						_tmp149_ = xmpp_stanza_node_add_self_xmlns (_tmp148_);
						_tmp150_ = _tmp149_;
						_tmp151_ = client_final_message;
						_tmp153_ = string_to_utf8 (_tmp151_, &_tmp152_);
						_tmp154_ = (guchar*) _tmp153_;
						_tmp154__length1 = (_tmp152_ * sizeof (gchar)) / sizeof (guchar);
						_tmp155_ = g_base64_encode (_tmp154_, (gint) ((_tmp152_ * sizeof (gchar)) / sizeof (guchar)));
						_tmp156_ = _tmp155_;
						_tmp157_ = xmpp_stanza_node_new_text (_tmp156_);
						_tmp158_ = _tmp157_;
						_tmp159_ = xmpp_stanza_node_put_node (_tmp150_, _tmp158_);
						_tmp160_ = _tmp159_;
						xmpp_xmpp_stream_write (stream, _tmp160_, G_PRIORITY_DEFAULT);
						_xmpp_stanza_entry_unref0 (_tmp160_);
						_xmpp_stanza_entry_unref0 (_tmp158_);
						_g_free0 (_tmp156_);
						_tmp154_ = (g_free (_tmp154_), NULL);
						_xmpp_stanza_entry_unref0 (_tmp150_);
						_xmpp_stanza_entry_unref0 (_tmp148_);
						_g_free0 (client_final_message);
						server_key = (g_free (server_key), NULL);
						client_proof = (g_free (client_proof), NULL);
						client_signature = (g_free (client_signature), NULL);
						_g_free0 (auth_message);
						stored_key = (g_free (stored_key), NULL);
						client_key = (g_free (client_key), NULL);
						salted_password = (g_free (salted_password), NULL);
						_g_free0 (client_final_message_bare);
						salt = (g_free (salt), NULL);
						_g_free0 (server_nonce);
						_g_free0 (challenge);
					}
					_g_object_unref0 (flag);
				}
			}
		}
	}
}

static void
_vala_array_add1 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

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;
}

void
xmpp_sasl_module_received_features_node (XmppSaslModule* self,
                                         XmppXmppStream* stream)
{
	XmppFlagIdentity* _tmp0_;
	XmppStanzaNode* mechanisms = NULL;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	gchar** supported_mechanisms = NULL;
	gchar** _tmp4_;
	gint supported_mechanisms_length1;
	gint _supported_mechanisms_size_;
	const gchar* _tmp22_;
	gboolean _tmp29_ = FALSE;
	gchar* name = NULL;
	const gchar* _tmp42_;
	gchar* _tmp43_;
	gboolean _tmp44_ = FALSE;
	gchar** _tmp58_;
	gint _tmp58__length1;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_sasl_flag_IDENTITY;
	if (xmpp_xmpp_stream_has_flag (stream, XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_)) {
		return;
	}
	if (xmpp_xmpp_stream_is_setup_needed (stream)) {
		return;
	}
	_tmp1_ = xmpp_xmpp_stream_get_features (stream);
	_tmp2_ = _tmp1_;
	_tmp3_ = xmpp_stanza_node_get_subnode (_tmp2_, "mechanisms", XMPP_SASL_NS_URI, FALSE);
	mechanisms = _tmp3_;
	_tmp4_ = g_new0 (gchar*, 0 + 1);
	supported_mechanisms = _tmp4_;
	supported_mechanisms_length1 = 0;
	_supported_mechanisms_size_ = supported_mechanisms_length1;
	{
		GeeList* _mechanism_list = NULL;
		XmppStanzaNode* _tmp5_;
		GeeList* _tmp6_;
		gint _mechanism_size = 0;
		GeeList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		gint _mechanism_index = 0;
		_tmp5_ = mechanisms;
		_tmp6_ = _tmp5_->sub_nodes;
		_mechanism_list = _tmp6_;
		_tmp7_ = _mechanism_list;
		_tmp8_ = gee_collection_get_size ((GeeCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		_mechanism_size = _tmp9_;
		_mechanism_index = -1;
		while (TRUE) {
			gint _tmp10_;
			gint _tmp11_;
			XmppStanzaNode* mechanism = NULL;
			GeeList* _tmp12_;
			gpointer _tmp13_;
			gboolean _tmp14_ = FALSE;
			XmppStanzaNode* _tmp15_;
			const gchar* _tmp16_;
			XmppStanzaNode* _tmp19_;
			const gchar* _tmp20_;
			gchar* _tmp21_;
			_mechanism_index = _mechanism_index + 1;
			_tmp10_ = _mechanism_index;
			_tmp11_ = _mechanism_size;
			if (!(_tmp10_ < _tmp11_)) {
				break;
			}
			_tmp12_ = _mechanism_list;
			_tmp13_ = gee_list_get (_tmp12_, _mechanism_index);
			mechanism = (XmppStanzaNode*) _tmp13_;
			_tmp15_ = mechanism;
			_tmp16_ = ((XmppStanzaEntry*) _tmp15_)->name;
			if (g_strcmp0 (_tmp16_, "mechanism") != 0) {
				_tmp14_ = TRUE;
			} else {
				XmppStanzaNode* _tmp17_;
				const gchar* _tmp18_;
				_tmp17_ = mechanism;
				_tmp18_ = ((XmppStanzaEntry*) _tmp17_)->ns_uri;
				_tmp14_ = g_strcmp0 (_tmp18_, XMPP_SASL_NS_URI) != 0;
			}
			if (_tmp14_) {
				_xmpp_stanza_entry_unref0 (mechanism);
				continue;
			}
			_tmp19_ = mechanism;
			_tmp20_ = xmpp_stanza_entry_get_string_content ((XmppStanzaEntry*) _tmp19_);
			_tmp21_ = g_strdup (_tmp20_);
			_vala_array_add1 (&supported_mechanisms, &supported_mechanisms_length1, &_supported_mechanisms_size_, _tmp21_);
			_xmpp_stanza_entry_unref0 (mechanism);
		}
	}
	_tmp22_ = self->priv->_name;
	if (!string_contains (_tmp22_, "@")) {
		const gchar* _tmp23_;
		XmppJid* _tmp24_;
		gchar* _tmp25_;
		gchar* _tmp26_;
		gchar* _tmp27_;
		gchar* _tmp28_;
		_tmp23_ = self->priv->_name;
		_tmp24_ = stream->remote_name;
		_tmp25_ = xmpp_jid_to_string (_tmp24_);
		_tmp26_ = _tmp25_;
		_tmp27_ = g_strdup_printf ("%s@%s", _tmp23_, _tmp26_);
		_tmp28_ = _tmp27_;
		xmpp_sasl_module_set_name (self, _tmp28_);
		_g_free0 (_tmp28_);
		_g_free0 (_tmp26_);
	}
	if (!self->use_full_name) {
		const gchar* _tmp30_;
		_tmp30_ = self->priv->_name;
		_tmp29_ = string_contains (_tmp30_, "@");
	} else {
		_tmp29_ = FALSE;
	}
	if (_tmp29_) {
		gchar** split = NULL;
		const gchar* _tmp31_;
		gchar** _tmp32_;
		gchar** _tmp33_;
		gint split_length1;
		gint _split_size_;
		gchar** _tmp34_;
		gint _tmp34__length1;
		const gchar* _tmp35_;
		XmppJid* _tmp36_;
		gchar* _tmp37_;
		gchar* _tmp38_;
		gboolean _tmp39_;
		_tmp31_ = self->priv->_name;
		_tmp33_ = _tmp32_ = g_strsplit (_tmp31_, "@", 0);
		split = _tmp33_;
		split_length1 = _vala_array_length (_tmp32_);
		_split_size_ = split_length1;
		_tmp34_ = split;
		_tmp34__length1 = split_length1;
		_tmp35_ = _tmp34_[1];
		_tmp36_ = stream->remote_name;
		_tmp37_ = xmpp_jid_to_string (_tmp36_);
		_tmp38_ = _tmp37_;
		_tmp39_ = g_strcmp0 (_tmp35_, _tmp38_) == 0;
		_g_free0 (_tmp38_);
		if (_tmp39_) {
			gchar** _tmp40_;
			gint _tmp40__length1;
			const gchar* _tmp41_;
			_tmp40_ = split;
			_tmp40__length1 = split_length1;
			_tmp41_ = _tmp40_[0];
			xmpp_sasl_module_set_name (self, _tmp41_);
		} else {
			self->use_full_name = TRUE;
		}
		split = (_vala_array_free (split, split_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp42_ = self->priv->_name;
	_tmp43_ = g_strdup (_tmp42_);
	name = _tmp43_;
	if (!self->use_full_name) {
		const gchar* _tmp45_;
		_tmp45_ = name;
		_tmp44_ = string_contains (_tmp45_, "@");
	} else {
		_tmp44_ = FALSE;
	}
	if (_tmp44_) {
		gchar** split = NULL;
		const gchar* _tmp46_;
		gchar** _tmp47_;
		gchar** _tmp48_;
		gint split_length1;
		gint _split_size_;
		gchar** _tmp49_;
		gint _tmp49__length1;
		const gchar* _tmp50_;
		XmppJid* _tmp51_;
		gchar* _tmp52_;
		gchar* _tmp53_;
		gboolean _tmp54_;
		_tmp46_ = name;
		_tmp48_ = _tmp47_ = g_strsplit (_tmp46_, "@", 0);
		split = _tmp48_;
		split_length1 = _vala_array_length (_tmp47_);
		_split_size_ = split_length1;
		_tmp49_ = split;
		_tmp49__length1 = split_length1;
		_tmp50_ = _tmp49_[1];
		_tmp51_ = stream->remote_name;
		_tmp52_ = xmpp_jid_to_string (_tmp51_);
		_tmp53_ = _tmp52_;
		_tmp54_ = g_strcmp0 (_tmp50_, _tmp53_) == 0;
		_g_free0 (_tmp53_);
		if (_tmp54_) {
			gchar** _tmp55_;
			gint _tmp55__length1;
			const gchar* _tmp56_;
			gchar* _tmp57_;
			_tmp55_ = split;
			_tmp55__length1 = split_length1;
			_tmp56_ = _tmp55_[0];
			_tmp57_ = g_strdup (_tmp56_);
			_g_free0 (name);
			name = _tmp57_;
		}
		split = (_vala_array_free (split, split_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp58_ = supported_mechanisms;
	_tmp58__length1 = supported_mechanisms_length1;
	if (_vala_string_array_contains (_tmp58_, _tmp58__length1, XMPP_SASL_MECHANISM_SCRAM_SHA_1)) {
		gchar* normalized_password = NULL;
		const gchar* _tmp59_;
		gchar* _tmp60_;
		gchar* client_nonce = NULL;
		gchar* _tmp61_;
		gchar* _tmp62_;
		gchar* _tmp63_;
		gchar* _tmp64_;
		gchar* _tmp65_;
		gchar* _tmp66_;
		gchar* _tmp67_;
		gchar* _tmp68_;
		gchar* _tmp69_;
		gchar* _tmp70_;
		gchar* initial_message = NULL;
		const gchar* _tmp71_;
		const gchar* _tmp72_;
		const gchar* _tmp73_;
		const gchar* _tmp74_;
		gchar* _tmp75_;
		XmppStanzaNode* _tmp76_;
		XmppStanzaNode* _tmp77_;
		XmppStanzaNode* _tmp78_;
		XmppStanzaNode* _tmp79_;
		XmppStanzaNode* _tmp80_;
		XmppStanzaNode* _tmp81_;
		const gchar* _tmp82_;
		gchar* _tmp83_;
		gchar* _tmp84_;
		gint _tmp85_ = 0;
		gchar* _tmp86_;
		guchar* _tmp87_;
		gint _tmp87__length1;
		gchar* _tmp88_;
		gchar* _tmp89_;
		XmppStanzaNode* _tmp90_;
		XmppStanzaNode* _tmp91_;
		XmppStanzaNode* _tmp92_;
		XmppStanzaNode* _tmp93_;
		XmppSaslFlag* flag = NULL;
		XmppSaslFlag* _tmp94_;
		XmppSaslFlag* _tmp95_;
		gchar* _tmp96_;
		XmppSaslFlag* _tmp97_;
		const gchar* _tmp98_;
		gchar* _tmp99_;
		XmppSaslFlag* _tmp100_;
		const gchar* _tmp101_;
		gchar* _tmp102_;
		XmppSaslFlag* _tmp103_;
		const gchar* _tmp104_;
		gchar* _tmp105_;
		XmppSaslFlag* _tmp106_;
		_tmp59_ = self->priv->_password;
		_tmp60_ = g_utf8_normalize (_tmp59_, (gssize) -1, G_NORMALIZE_NFKC);
		normalized_password = _tmp60_;
		_tmp61_ = g_strdup_printf ("%.8x", g_random_int ());
		_tmp62_ = _tmp61_;
		_tmp63_ = g_strdup_printf ("%.8x", g_random_int ());
		_tmp64_ = _tmp63_;
		_tmp65_ = g_strconcat (_tmp62_, _tmp64_, NULL);
		_tmp66_ = _tmp65_;
		_tmp67_ = g_strdup_printf ("%.8x", g_random_int ());
		_tmp68_ = _tmp67_;
		_tmp69_ = g_strconcat (_tmp66_, _tmp68_, NULL);
		_tmp70_ = _tmp69_;
		_g_free0 (_tmp68_);
		_g_free0 (_tmp66_);
		_g_free0 (_tmp64_);
		_g_free0 (_tmp62_);
		client_nonce = _tmp70_;
		_tmp71_ = name;
		_tmp72_ = string_to_string (_tmp71_);
		_tmp73_ = client_nonce;
		_tmp74_ = string_to_string (_tmp73_);
		_tmp75_ = g_strconcat ("n=", _tmp72_, ",r=", _tmp74_, NULL);
		initial_message = _tmp75_;
		_tmp76_ = xmpp_stanza_node_new_build ("auth", XMPP_SASL_NS_URI, NULL, NULL);
		_tmp77_ = _tmp76_;
		_tmp78_ = xmpp_stanza_node_add_self_xmlns (_tmp77_);
		_tmp79_ = _tmp78_;
		_tmp80_ = xmpp_stanza_node_put_attribute (_tmp79_, "mechanism", XMPP_SASL_MECHANISM_SCRAM_SHA_1, NULL);
		_tmp81_ = _tmp80_;
		_tmp82_ = initial_message;
		_tmp83_ = g_strconcat ("n,,", _tmp82_, NULL);
		_tmp84_ = _tmp83_;
		_tmp86_ = string_to_utf8 (_tmp84_, &_tmp85_);
		_tmp87_ = (guchar*) _tmp86_;
		_tmp87__length1 = (_tmp85_ * sizeof (gchar)) / sizeof (guchar);
		_tmp88_ = g_base64_encode (_tmp87_, (gint) ((_tmp85_ * sizeof (gchar)) / sizeof (guchar)));
		_tmp89_ = _tmp88_;
		_tmp90_ = xmpp_stanza_node_new_text (_tmp89_);
		_tmp91_ = _tmp90_;
		_tmp92_ = xmpp_stanza_node_put_node (_tmp81_, _tmp91_);
		_tmp93_ = _tmp92_;
		xmpp_xmpp_stream_write (stream, _tmp93_, G_PRIORITY_DEFAULT);
		_xmpp_stanza_entry_unref0 (_tmp93_);
		_xmpp_stanza_entry_unref0 (_tmp91_);
		_g_free0 (_tmp89_);
		_tmp87_ = (g_free (_tmp87_), NULL);
		_g_free0 (_tmp84_);
		_xmpp_stanza_entry_unref0 (_tmp81_);
		_xmpp_stanza_entry_unref0 (_tmp79_);
		_xmpp_stanza_entry_unref0 (_tmp77_);
		_tmp94_ = xmpp_sasl_flag_new ();
		flag = _tmp94_;
		_tmp95_ = flag;
		_tmp96_ = g_strdup (XMPP_SASL_MECHANISM_SCRAM_SHA_1);
		_g_free0 (_tmp95_->mechanism);
		_tmp95_->mechanism = _tmp96_;
		_tmp97_ = flag;
		_tmp98_ = name;
		_tmp99_ = g_strdup (_tmp98_);
		_g_free0 (_tmp97_->name);
		_tmp97_->name = _tmp99_;
		_tmp100_ = flag;
		_tmp101_ = normalized_password;
		_tmp102_ = g_strdup (_tmp101_);
		_g_free0 (_tmp100_->password);
		_tmp100_->password = _tmp102_;
		_tmp103_ = flag;
		_tmp104_ = client_nonce;
		_tmp105_ = g_strdup (_tmp104_);
		_g_free0 (_tmp103_->client_nonce);
		_tmp103_->client_nonce = _tmp105_;
		_tmp106_ = flag;
		xmpp_xmpp_stream_add_flag (stream, (XmppXmppStreamFlag*) _tmp106_);
		_g_object_unref0 (flag);
		_g_free0 (initial_message);
		_g_free0 (client_nonce);
		_g_free0 (normalized_password);
	} else {
		gchar** _tmp107_;
		gint _tmp107__length1;
		_tmp107_ = supported_mechanisms;
		_tmp107__length1 = supported_mechanisms_length1;
		if (_vala_string_array_contains (_tmp107_, _tmp107__length1, XMPP_SASL_MECHANISM_PLAIN)) {
			XmppStanzaNode* _tmp108_;
			XmppStanzaNode* _tmp109_;
			XmppStanzaNode* _tmp110_;
			XmppStanzaNode* _tmp111_;
			XmppStanzaNode* _tmp112_;
			XmppStanzaNode* _tmp113_;
			const gchar* _tmp114_;
			const gchar* _tmp115_;
			gint _tmp116_ = 0;
			guchar* _tmp117_;
			guchar* _tmp118_;
			gint _tmp118__length1;
			gchar* _tmp119_;
			gchar* _tmp120_;
			XmppStanzaNode* _tmp121_;
			XmppStanzaNode* _tmp122_;
			XmppStanzaNode* _tmp123_;
			XmppStanzaNode* _tmp124_;
			XmppSaslFlag* flag = NULL;
			XmppSaslFlag* _tmp125_;
			XmppSaslFlag* _tmp126_;
			gchar* _tmp127_;
			XmppSaslFlag* _tmp128_;
			const gchar* _tmp129_;
			gchar* _tmp130_;
			XmppSaslFlag* _tmp131_;
			_tmp108_ = xmpp_stanza_node_new_build ("auth", XMPP_SASL_NS_URI, NULL, NULL);
			_tmp109_ = _tmp108_;
			_tmp110_ = xmpp_stanza_node_add_self_xmlns (_tmp109_);
			_tmp111_ = _tmp110_;
			_tmp112_ = xmpp_stanza_node_put_attribute (_tmp111_, "mechanism", XMPP_SASL_MECHANISM_PLAIN, NULL);
			_tmp113_ = _tmp112_;
			_tmp114_ = name;
			_tmp115_ = self->priv->_password;
			_tmp117_ = xmpp_sasl_module_get_plain_bytes (_tmp114_, _tmp115_, &_tmp116_);
			_tmp118_ = _tmp117_;
			_tmp118__length1 = _tmp116_;
			_tmp119_ = g_base64_encode (_tmp118_, (gint) _tmp116_);
			_tmp120_ = _tmp119_;
			_tmp121_ = xmpp_stanza_node_new_text (_tmp120_);
			_tmp122_ = _tmp121_;
			_tmp123_ = xmpp_stanza_node_put_node (_tmp113_, _tmp122_);
			_tmp124_ = _tmp123_;
			xmpp_xmpp_stream_write (stream, _tmp124_, G_PRIORITY_DEFAULT);
			_xmpp_stanza_entry_unref0 (_tmp124_);
			_xmpp_stanza_entry_unref0 (_tmp122_);
			_g_free0 (_tmp120_);
			_tmp118_ = (g_free (_tmp118_), NULL);
			_xmpp_stanza_entry_unref0 (_tmp113_);
			_xmpp_stanza_entry_unref0 (_tmp111_);
			_xmpp_stanza_entry_unref0 (_tmp109_);
			_tmp125_ = xmpp_sasl_flag_new ();
			flag = _tmp125_;
			_tmp126_ = flag;
			_tmp127_ = g_strdup (XMPP_SASL_MECHANISM_PLAIN);
			_g_free0 (_tmp126_->mechanism);
			_tmp126_->mechanism = _tmp127_;
			_tmp128_ = flag;
			_tmp129_ = name;
			_tmp130_ = g_strdup (_tmp129_);
			_g_free0 (_tmp128_->name);
			_tmp128_->name = _tmp130_;
			_tmp131_ = flag;
			xmpp_xmpp_stream_add_flag (stream, (XmppXmppStreamFlag*) _tmp131_);
			_g_object_unref0 (flag);
		} else {
			FILE* _tmp132_;
			XmppJid* _tmp133_;
			gchar* _tmp134_;
			gchar* _tmp135_;
			_tmp132_ = stderr;
			_tmp133_ = stream->remote_name;
			_tmp134_ = xmpp_jid_to_string (_tmp133_);
			_tmp135_ = _tmp134_;
			fprintf (_tmp132_, "No supported mechanism provided by server at %s\n", _tmp135_);
			_g_free0 (_tmp135_);
			_g_free0 (name);
			supported_mechanisms = (_vala_array_free (supported_mechanisms, supported_mechanisms_length1, (GDestroyNotify) g_free), NULL);
			_xmpp_stanza_entry_unref0 (mechanisms);
			return;
		}
	}
	_g_free0 (name);
	supported_mechanisms = (_vala_array_free (supported_mechanisms, supported_mechanisms_length1, (GDestroyNotify) g_free), NULL);
	_xmpp_stanza_entry_unref0 (mechanisms);
}

static guchar*
xmpp_sasl_module_get_plain_bytes (const gchar* name_s,
                                  const gchar* password_s,
                                  gint* result_length1)
{
	gchar* name = NULL;
	gint _tmp0_ = 0;
	gchar* _tmp1_;
	gint name_length1;
	gint _name_size_;
	gchar* password = NULL;
	gint _tmp2_ = 0;
	gchar* _tmp3_;
	gint password_length1;
	gint _password_size_;
	guchar* res = NULL;
	gchar* _tmp4_;
	gint _tmp4__length1;
	gchar* _tmp5_;
	gint _tmp5__length1;
	guchar* _tmp6_;
	gint res_length1;
	gint _res_size_;
	guchar* _tmp7_;
	gint _tmp7__length1;
	guchar* _tmp8_;
	gint _tmp8__length1;
	gchar* _tmp9_;
	gint _tmp9__length1;
	guchar* _tmp23_;
	gint _tmp23__length1;
	guchar* result;
	g_return_val_if_fail (name_s != NULL, NULL);
	g_return_val_if_fail (password_s != NULL, NULL);
	_tmp1_ = string_to_utf8 (name_s, &_tmp0_);
	name = _tmp1_;
	name_length1 = _tmp0_;
	_name_size_ = name_length1;
	_tmp3_ = string_to_utf8 (password_s, &_tmp2_);
	password = _tmp3_;
	password_length1 = _tmp2_;
	_password_size_ = password_length1;
	_tmp4_ = name;
	_tmp4__length1 = name_length1;
	_tmp5_ = password;
	_tmp5__length1 = password_length1;
	_tmp6_ = g_new0 (guchar, (_tmp4__length1 + _tmp5__length1) + 2);
	res = _tmp6_;
	res_length1 = (_tmp4__length1 + _tmp5__length1) + 2;
	_res_size_ = res_length1;
	_tmp7_ = res;
	_tmp7__length1 = res_length1;
	_tmp7_[0] = (guchar) 0;
	_tmp8_ = res;
	_tmp8__length1 = res_length1;
	_tmp9_ = name;
	_tmp9__length1 = name_length1;
	_tmp8_[_tmp9__length1 + 1] = (guchar) 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp10_ = FALSE;
			_tmp10_ = TRUE;
			while (TRUE) {
				gchar* _tmp12_;
				gint _tmp12__length1;
				guchar* _tmp13_;
				gint _tmp13__length1;
				gchar* _tmp14_;
				gint _tmp14__length1;
				gchar _tmp15_;
				if (!_tmp10_) {
					gint _tmp11_;
					_tmp11_ = i;
					i = _tmp11_ + 1;
				}
				_tmp10_ = FALSE;
				_tmp12_ = name;
				_tmp12__length1 = name_length1;
				if (!(i < _tmp12__length1)) {
					break;
				}
				_tmp13_ = res;
				_tmp13__length1 = res_length1;
				_tmp14_ = name;
				_tmp14__length1 = name_length1;
				_tmp15_ = _tmp14_[i];
				_tmp13_[i + 1] = (guchar) _tmp15_;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp16_ = FALSE;
			_tmp16_ = TRUE;
			while (TRUE) {
				gchar* _tmp18_;
				gint _tmp18__length1;
				guchar* _tmp19_;
				gint _tmp19__length1;
				gchar* _tmp20_;
				gint _tmp20__length1;
				gchar* _tmp21_;
				gint _tmp21__length1;
				gchar _tmp22_;
				if (!_tmp16_) {
					gint _tmp17_;
					_tmp17_ = i;
					i = _tmp17_ + 1;
				}
				_tmp16_ = FALSE;
				_tmp18_ = password;
				_tmp18__length1 = password_length1;
				if (!(i < _tmp18__length1)) {
					break;
				}
				_tmp19_ = res;
				_tmp19__length1 = res_length1;
				_tmp20_ = name;
				_tmp20__length1 = name_length1;
				_tmp21_ = password;
				_tmp21__length1 = password_length1;
				_tmp22_ = _tmp21_[i];
				_tmp19_[(i + _tmp20__length1) + 2] = (guchar) _tmp22_;
			}
		}
	}
	_tmp23_ = res;
	_tmp23__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp23__length1;
	}
	result = _tmp23_;
	password = (g_free (password), NULL);
	name = (g_free (name), NULL);
	return result;
}

static gboolean
xmpp_sasl_module_real_mandatory_outstanding (XmppXmppStreamNegotiationModule* base,
                                             XmppXmppStream* stream)
{
	XmppSaslModule * self;
	gboolean _tmp0_ = FALSE;
	XmppFlagIdentity* _tmp1_;
	gboolean result;
	self = (XmppSaslModule*) base;
	g_return_val_if_fail (stream != NULL, FALSE);
	_tmp1_ = xmpp_sasl_flag_IDENTITY;
	if (!xmpp_xmpp_stream_has_flag (stream, XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_)) {
		_tmp0_ = TRUE;
	} else {
		XmppFlagIdentity* _tmp2_;
		gpointer _tmp3_;
		XmppSaslFlag* _tmp4_;
		_tmp2_ = xmpp_sasl_flag_IDENTITY;
		_tmp3_ = xmpp_xmpp_stream_get_flag (stream, XMPP_SASL_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
		_tmp4_ = (XmppSaslFlag*) _tmp3_;
		_tmp0_ = !_tmp4_->finished;
		_g_object_unref0 (_tmp4_);
	}
	result = _tmp0_;
	return result;
}

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

static gchar*
xmpp_sasl_module_real_get_ns (XmppXmppStreamModule* base)
{
	XmppSaslModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppSaslModule*) base;
	_tmp0_ = g_strdup (XMPP_SASL_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_sasl_module_real_get_id (XmppXmppStreamModule* base)
{
	XmppSaslModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppSaslModule*) base;
	_tmp0_ = xmpp_sasl_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

const gchar*
xmpp_sasl_module_get_name (XmppSaslModule* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}

void
xmpp_sasl_module_set_name (XmppSaslModule* self,
                           const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = xmpp_sasl_module_get_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_name);
		self->priv->_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, xmpp_sasl_module_properties[XMPP_SASL_MODULE_NAME_PROPERTY]);
	}
}

const gchar*
xmpp_sasl_module_get_password (XmppSaslModule* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_password;
	result = _tmp0_;
	return result;
}

void
xmpp_sasl_module_set_password (XmppSaslModule* self,
                               const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = xmpp_sasl_module_get_password (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_password);
		self->priv->_password = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, xmpp_sasl_module_properties[XMPP_SASL_MODULE_PASSWORD_PROPERTY]);
	}
}

static void
g_cclosure_user_marshal_VOID__OBJECT_XMPP_STANZA_ENTRY (GClosure * closure,
                                                        GValue * return_value,
                                                        guint n_param_values,
                                                        const GValue * param_values,
                                                        gpointer invocation_hint,
                                                        gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_XMPP_STANZA_ENTRY) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_XMPP_STANZA_ENTRY callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_XMPP_STANZA_ENTRY) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), xmpp_value_get_stanza_entry (param_values + 2), data2);
}

static void
xmpp_sasl_module_class_init (XmppSaslModuleClass * klass,
                             gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_sasl_module_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppSaslModule_private_offset);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_sasl_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_sasl_module_real_detach;
	((XmppXmppStreamNegotiationModuleClass *) klass)->mandatory_outstanding = (gboolean (*) (XmppXmppStreamNegotiationModule*, XmppXmppStream*)) xmpp_sasl_module_real_mandatory_outstanding;
	((XmppXmppStreamNegotiationModuleClass *) klass)->negotiation_active = (gboolean (*) (XmppXmppStreamNegotiationModule*, XmppXmppStream*)) xmpp_sasl_module_real_negotiation_active;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_sasl_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_sasl_module_real_get_id;
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_sasl_module_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_xmpp_sasl_module_set_property;
	G_OBJECT_CLASS (klass)->finalize = xmpp_sasl_module_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_SASL_MODULE_NAME_PROPERTY, xmpp_sasl_module_properties[XMPP_SASL_MODULE_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_SASL_MODULE_PASSWORD_PROPERTY, xmpp_sasl_module_properties[XMPP_SASL_MODULE_PASSWORD_PROPERTY] = g_param_spec_string ("password", "password", "password", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	xmpp_sasl_module_signals[XMPP_SASL_MODULE_RECEIVED_AUTH_FAILURE_SIGNAL] = g_signal_new ("received-auth-failure", XMPP_SASL_TYPE_MODULE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_STANZA_ENTRY, G_TYPE_NONE, 2, XMPP_TYPE_XMPP_STREAM, XMPP_TYPE_STANZA_NODE);
	_tmp0_ = xmpp_module_identity_new (XMPP_SASL_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_SASL_NS_URI, "sasl");
	xmpp_sasl_module_IDENTITY = _tmp0_;
}

static void
xmpp_sasl_module_instance_init (XmppSaslModule * self,
                                gpointer klass)
{
	self->priv = xmpp_sasl_module_get_instance_private (self);
	self->use_full_name = FALSE;
}

static void
xmpp_sasl_module_finalize (GObject * obj)
{
	XmppSaslModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_SASL_TYPE_MODULE, XmppSaslModule);
	_g_free0 (self->priv->_name);
	_g_free0 (self->priv->_password);
	G_OBJECT_CLASS (xmpp_sasl_module_parent_class)->finalize (obj);
}

static GType
xmpp_sasl_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppSaslModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_sasl_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppSaslModule), 0, (GInstanceInitFunc) xmpp_sasl_module_instance_init, NULL };
	GType xmpp_sasl_module_type_id;
	xmpp_sasl_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_NEGOTIATION_MODULE, "XmppSaslModule", &g_define_type_info, 0);
	XmppSaslModule_private_offset = g_type_add_instance_private (xmpp_sasl_module_type_id, sizeof (XmppSaslModulePrivate));
	return xmpp_sasl_module_type_id;
}

GType
xmpp_sasl_module_get_type (void)
{
	static volatile gsize xmpp_sasl_module_type_id__once = 0;
	if (g_once_init_enter (&xmpp_sasl_module_type_id__once)) {
		GType xmpp_sasl_module_type_id;
		xmpp_sasl_module_type_id = xmpp_sasl_module_get_type_once ();
		g_once_init_leave (&xmpp_sasl_module_type_id__once, xmpp_sasl_module_type_id);
	}
	return xmpp_sasl_module_type_id__once;
}

static void
_vala_xmpp_sasl_module_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	XmppSaslModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_SASL_TYPE_MODULE, XmppSaslModule);
	switch (property_id) {
		case XMPP_SASL_MODULE_NAME_PROPERTY:
		g_value_set_string (value, xmpp_sasl_module_get_name (self));
		break;
		case XMPP_SASL_MODULE_PASSWORD_PROPERTY:
		g_value_set_string (value, xmpp_sasl_module_get_password (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_xmpp_sasl_module_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	XmppSaslModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_SASL_TYPE_MODULE, XmppSaslModule);
	switch (property_id) {
		case XMPP_SASL_MODULE_NAME_PROPERTY:
		xmpp_sasl_module_set_name (self, g_value_get_string (value));
		break;
		case XMPP_SASL_MODULE_PASSWORD_PROPERTY:
		xmpp_sasl_module_set_password (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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;
}

