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

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

#define XMPP_XEP_USER_AVATARS_NS_URI "urn:xmpp:avatar"
#define XMPP_XEP_USER_AVATARS_NS_URI_DATA XMPP_XEP_USER_AVATARS_NS_URI ":data"
#define XMPP_XEP_USER_AVATARS_NS_URI_METADATA XMPP_XEP_USER_AVATARS_NS_URI ":metadata"
#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_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
typedef struct _XmppXepUserAvatarsFetchImageData XmppXepUserAvatarsFetchImageData;
enum  {
	XMPP_XEP_USER_AVATARS_MODULE_0_PROPERTY,
	XMPP_XEP_USER_AVATARS_MODULE_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_user_avatars_module_properties[XMPP_XEP_USER_AVATARS_MODULE_NUM_PROPERTIES];
enum  {
	XMPP_XEP_USER_AVATARS_MODULE_RECEIVED_AVATAR_HASH_SIGNAL,
	XMPP_XEP_USER_AVATARS_MODULE_AVATAR_REMOVED_SIGNAL,
	XMPP_XEP_USER_AVATARS_MODULE_NUM_SIGNALS
};
static guint xmpp_xep_user_avatars_module_signals[XMPP_XEP_USER_AVATARS_MODULE_NUM_SIGNALS] = {0};

struct _XmppXepUserAvatarsFetchImageData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXmppStream* stream;
	XmppJid* jid;
	gchar* hash;
	GBytes* result;
	GeeList* items;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepPubsubModule* _tmp2_;
	GeeList* _tmp3_;
	GeeList* _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	GeeList* _tmp7_;
	GeeList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GeeList* _tmp11_;
	gpointer _tmp12_;
	XmppStanzaNode* _tmp13_;
	GeeList* _tmp14_;
	gint _tmp15_;
	gint _tmp16_;
	XmppStanzaNode* node;
	GeeList* _tmp17_;
	gpointer _tmp18_;
	XmppStanzaNode* _tmp19_;
	GeeList* _tmp20_;
	gpointer _tmp21_;
	XmppStanzaNode* _tmp22_;
	gchar* id;
	GeeList* _tmp23_;
	gpointer _tmp24_;
	XmppStanzaNode* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	const gchar* _tmp29_;
	GBytes* image;
	XmppStanzaNode* _tmp30_;
	const gchar* _tmp31_;
	gsize _tmp32_;
	guchar* _tmp33_;
	GBytes* _tmp34_;
	gchar* sha1;
	GBytes* _tmp35_;
	gchar* _tmp36_;
	const gchar* _tmp37_;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	gchar* _tmp40_;
	const gchar* _tmp41_;
	const gchar* _tmp42_;
};

static gpointer xmpp_xep_user_avatars_module_parent_class = NULL;
XmppModuleIdentity* xmpp_xep_user_avatars_module_IDENTITY = NULL;

static void xmpp_xep_user_avatars_fetch_image_data_free (gpointer _data);
static gboolean xmpp_xep_user_avatars_fetch_image_co (XmppXepUserAvatarsFetchImageData* _data_);
static void xmpp_xep_user_avatars_fetch_image_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void xmpp_xep_user_avatars_module_real_attach (XmppXmppStreamModule* base,
                                               XmppXmppStream* stream);
static void _xmpp_xep_user_avatars_module_on_pupsub_item_xmpp_xep_pubsub_item_listener_delegate_result_func (XmppXmppStream* stream,
                                                                                                      XmppJid* jid,
                                                                                                      const gchar* id,
                                                                                                      XmppStanzaNode* node,
                                                                                                      gpointer self);
static void _xmpp_xep_user_avatars_module_on_pubsub_delete_xmpp_xep_pubsub_delete_listener_delegate_result_func (XmppXmppStream* stream,
                                                                                                          XmppJid* jid,
                                                                                                          gpointer self);
static void xmpp_xep_user_avatars_module_real_detach (XmppXmppStreamModule* base,
                                               XmppXmppStream* stream);
static gchar* xmpp_xep_user_avatars_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_xep_user_avatars_module_real_get_id (XmppXmppStreamModule* base);
static void g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_STRING (GClosure * closure,
                                                           GValue * return_value,
                                                           guint n_param_values,
                                                           const GValue * param_values,
                                                           gpointer invocation_hint,
                                                           gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID (GClosure * closure,
                                                    GValue * return_value,
                                                    guint n_param_values,
                                                    const GValue * param_values,
                                                    gpointer invocation_hint,
                                                    gpointer marshal_data);
static void xmpp_xep_user_avatars_module_finalize (GObject * obj);
static GType xmpp_xep_user_avatars_module_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

void
xmpp_xep_user_avatars_publish_png (XmppXmppStream* stream,
                                   guint8* image,
                                   gint image_length1,
                                   gint width,
                                   gint height)
{
	gchar* sha1 = NULL;
	gchar* _tmp0_;
	XmppStanzaNode* data_node = NULL;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppStanzaNode* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	XmppStanzaNode* _tmp7_;
	XmppStanzaNode* _tmp8_;
	XmppStanzaNode* _tmp9_;
	XmppStanzaNode* _tmp10_;
	XmppModuleIdentity* _tmp11_;
	gpointer _tmp12_;
	XmppXepPubsubModule* _tmp13_;
	XmppStanzaNode* metadata_node = NULL;
	XmppStanzaNode* _tmp14_;
	XmppStanzaNode* _tmp15_;
	XmppStanzaNode* _tmp16_;
	XmppStanzaNode* _tmp17_;
	XmppStanzaNode* info_node = NULL;
	XmppStanzaNode* _tmp18_;
	XmppStanzaNode* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	XmppStanzaNode* _tmp22_;
	XmppStanzaNode* _tmp23_;
	XmppStanzaNode* _tmp24_;
	XmppStanzaNode* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	XmppStanzaNode* _tmp28_;
	XmppStanzaNode* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	XmppStanzaNode* _tmp32_;
	XmppStanzaNode* _tmp33_;
	XmppStanzaNode* _tmp34_;
	XmppStanzaNode* _tmp35_;
	XmppStanzaNode* _tmp36_;
	XmppStanzaNode* _tmp37_;
	XmppModuleIdentity* _tmp38_;
	gpointer _tmp39_;
	XmppXepPubsubModule* _tmp40_;
	g_return_if_fail (stream != NULL);
	_tmp0_ = g_compute_checksum_for_data (G_CHECKSUM_SHA1, image, (gint) image_length1);
	sha1 = _tmp0_;
	_tmp1_ = xmpp_stanza_node_new_build ("data", XMPP_XEP_USER_AVATARS_NS_URI_DATA, NULL, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = xmpp_stanza_node_add_self_xmlns (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_base64_encode (image, (gint) image_length1);
	_tmp6_ = _tmp5_;
	_tmp7_ = xmpp_stanza_node_new_text (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = xmpp_stanza_node_put_node (_tmp4_, _tmp8_);
	_tmp10_ = _tmp9_;
	_xmpp_stanza_entry_unref0 (_tmp8_);
	_g_free0 (_tmp6_);
	_xmpp_stanza_entry_unref0 (_tmp4_);
	_xmpp_stanza_entry_unref0 (_tmp2_);
	data_node = _tmp10_;
	_tmp11_ = xmpp_xep_pubsub_module_IDENTITY;
	_tmp12_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_PUBSUB_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp11_);
	_tmp13_ = (XmppXepPubsubModule*) _tmp12_;
	xmpp_xep_pubsub_module_publish (_tmp13_, stream, NULL, XMPP_XEP_USER_AVATARS_NS_URI_DATA, sha1, data_node, NULL, TRUE, NULL, NULL);
	_g_object_unref0 (_tmp13_);
	_tmp14_ = xmpp_stanza_node_new_build ("metadata", XMPP_XEP_USER_AVATARS_NS_URI_METADATA, NULL, NULL);
	_tmp15_ = _tmp14_;
	_tmp16_ = xmpp_stanza_node_add_self_xmlns (_tmp15_);
	_tmp17_ = _tmp16_;
	_xmpp_stanza_entry_unref0 (_tmp15_);
	metadata_node = _tmp17_;
	_tmp18_ = xmpp_stanza_node_new_build ("info", XMPP_XEP_USER_AVATARS_NS_URI_METADATA, NULL, NULL);
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strdup_printf ("%i", image_length1);
	_tmp21_ = _tmp20_;
	_tmp22_ = xmpp_stanza_node_put_attribute (_tmp19_, "bytes", _tmp21_, NULL);
	_tmp23_ = _tmp22_;
	_tmp24_ = xmpp_stanza_node_put_attribute (_tmp23_, "id", sha1, NULL);
	_tmp25_ = _tmp24_;
	_tmp26_ = g_strdup_printf ("%i", width);
	_tmp27_ = _tmp26_;
	_tmp28_ = xmpp_stanza_node_put_attribute (_tmp25_, "width", _tmp27_, NULL);
	_tmp29_ = _tmp28_;
	_tmp30_ = g_strdup_printf ("%i", height);
	_tmp31_ = _tmp30_;
	_tmp32_ = xmpp_stanza_node_put_attribute (_tmp29_, "height", _tmp31_, NULL);
	_tmp33_ = _tmp32_;
	_tmp34_ = xmpp_stanza_node_put_attribute (_tmp33_, "type", "image/png", NULL);
	_tmp35_ = _tmp34_;
	_xmpp_stanza_entry_unref0 (_tmp33_);
	_g_free0 (_tmp31_);
	_xmpp_stanza_entry_unref0 (_tmp29_);
	_g_free0 (_tmp27_);
	_xmpp_stanza_entry_unref0 (_tmp25_);
	_xmpp_stanza_entry_unref0 (_tmp23_);
	_g_free0 (_tmp21_);
	_xmpp_stanza_entry_unref0 (_tmp19_);
	info_node = _tmp35_;
	_tmp36_ = xmpp_stanza_node_put_node (metadata_node, info_node);
	_tmp37_ = _tmp36_;
	_xmpp_stanza_entry_unref0 (_tmp37_);
	_tmp38_ = xmpp_xep_pubsub_module_IDENTITY;
	_tmp39_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_PUBSUB_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp38_);
	_tmp40_ = (XmppXepPubsubModule*) _tmp39_;
	xmpp_xep_pubsub_module_publish (_tmp40_, stream, NULL, XMPP_XEP_USER_AVATARS_NS_URI_METADATA, sha1, metadata_node, NULL, TRUE, NULL, NULL);
	_g_object_unref0 (_tmp40_);
	_xmpp_stanza_entry_unref0 (info_node);
	_xmpp_stanza_entry_unref0 (metadata_node);
	_xmpp_stanza_entry_unref0 (data_node);
	_g_free0 (sha1);
}

void
xmpp_xep_user_avatars_unset_avatar (XmppXmppStream* stream)
{
	XmppStanzaNode* metadata_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppModuleIdentity* _tmp4_;
	gpointer _tmp5_;
	XmppXepPubsubModule* _tmp6_;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_stanza_node_new_build ("metadata", XMPP_XEP_USER_AVATARS_NS_URI_METADATA, NULL, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmpp_stanza_node_add_self_xmlns (_tmp1_);
	_tmp3_ = _tmp2_;
	_xmpp_stanza_entry_unref0 (_tmp1_);
	metadata_node = _tmp3_;
	_tmp4_ = xmpp_xep_pubsub_module_IDENTITY;
	_tmp5_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_PUBSUB_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
	_tmp6_ = (XmppXepPubsubModule*) _tmp5_;
	xmpp_xep_pubsub_module_delete_node (_tmp6_, stream, NULL, XMPP_XEP_USER_AVATARS_NS_URI_METADATA);
	_g_object_unref0 (_tmp6_);
	_xmpp_stanza_entry_unref0 (metadata_node);
}

static void
xmpp_xep_user_avatars_fetch_image_data_free (gpointer _data)
{
	XmppXepUserAvatarsFetchImageData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_xmpp_jid_unref0 (_data_->jid);
	_g_free0 (_data_->hash);
	_g_bytes_unref0 (_data_->result);
	g_slice_free (XmppXepUserAvatarsFetchImageData, _data_);
}

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

static gpointer
_xmpp_jid_ref0 (gpointer self)
{
	return self ? xmpp_jid_ref (self) : NULL;
}

void
xmpp_xep_user_avatars_fetch_image (XmppXmppStream* stream,
                                   XmppJid* jid,
                                   const gchar* hash,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	XmppXepUserAvatarsFetchImageData* _data_;
	XmppXmppStream* _tmp0_;
	XmppJid* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (hash != NULL);
	_data_ = g_slice_new0 (XmppXepUserAvatarsFetchImageData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_user_avatars_fetch_image_data_free);
	_tmp0_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp0_;
	_tmp1_ = _xmpp_jid_ref0 (jid);
	_xmpp_jid_unref0 (_data_->jid);
	_data_->jid = _tmp1_;
	_tmp2_ = g_strdup (hash);
	_g_free0 (_data_->hash);
	_data_->hash = _tmp2_;
	xmpp_xep_user_avatars_fetch_image_co (_data_);
}

GBytes*
xmpp_xep_user_avatars_fetch_image_finish (GAsyncResult* _res_)
{
	GBytes* result;
	XmppXepUserAvatarsFetchImageData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
xmpp_xep_user_avatars_fetch_image_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	XmppXepUserAvatarsFetchImageData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_xep_user_avatars_fetch_image_co (_data_);
}

static gboolean
xmpp_xep_user_avatars_fetch_image_co (XmppXepUserAvatarsFetchImageData* _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_pubsub_module_IDENTITY;
	_data_->_tmp1_ = xmpp_xmpp_stream_get_module (_data_->stream, XMPP_XEP_PUBSUB_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp0_);
	_data_->_tmp2_ = (XmppXepPubsubModule*) _data_->_tmp1_;
	_data_->_state_ = 1;
	xmpp_xep_pubsub_module_request_all (_data_->_tmp2_, _data_->stream, _data_->jid, XMPP_XEP_USER_AVATARS_NS_URI_DATA, xmpp_xep_user_avatars_fetch_image_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp3_ = xmpp_xep_pubsub_module_request_all_finish (_data_->_tmp2_, _data_->_res_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_g_object_unref0 (_data_->_tmp2_);
	_data_->items = _data_->_tmp4_;
	_data_->_tmp7_ = _data_->items;
	if (_data_->_tmp7_ == NULL) {
		_data_->_tmp6_ = TRUE;
	} else {
		_data_->_tmp8_ = _data_->items;
		_data_->_tmp9_ = gee_collection_get_size ((GeeCollection*) _data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp6_ = _data_->_tmp10_ == 0;
	}
	if (_data_->_tmp6_) {
		_data_->_tmp5_ = TRUE;
	} else {
		_data_->_tmp11_ = _data_->items;
		_data_->_tmp12_ = gee_list_get (_data_->_tmp11_, 0);
		_data_->_tmp13_ = (XmppStanzaNode*) _data_->_tmp12_;
		_data_->_tmp14_ = _data_->_tmp13_->sub_nodes;
		_data_->_tmp15_ = gee_collection_get_size ((GeeCollection*) _data_->_tmp14_);
		_data_->_tmp16_ = _data_->_tmp15_;
		_data_->_tmp5_ = _data_->_tmp16_ == 0;
		_xmpp_stanza_entry_unref0 (_data_->_tmp13_);
	}
	if (_data_->_tmp5_) {
		_data_->result = NULL;
		_g_object_unref0 (_data_->items);
		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_->_tmp17_ = _data_->items;
	_data_->_tmp18_ = gee_list_get (_data_->_tmp17_, 0);
	_data_->_tmp19_ = (XmppStanzaNode*) _data_->_tmp18_;
	_data_->_tmp20_ = _data_->_tmp19_->sub_nodes;
	_data_->_tmp21_ = gee_list_get (_data_->_tmp20_, 0);
	_data_->_tmp22_ = (XmppStanzaNode*) _data_->_tmp21_;
	_xmpp_stanza_entry_unref0 (_data_->_tmp19_);
	_data_->node = _data_->_tmp22_;
	_data_->_tmp23_ = _data_->items;
	_data_->_tmp24_ = gee_list_get (_data_->_tmp23_, 0);
	_data_->_tmp25_ = (XmppStanzaNode*) _data_->_tmp24_;
	_data_->_tmp26_ = xmpp_stanza_node_get_attribute (_data_->_tmp25_, "id", XMPP_XEP_PUBSUB_NS_URI);
	_data_->_tmp27_ = g_strdup (_data_->_tmp26_);
	_data_->_tmp28_ = _data_->_tmp27_;
	_xmpp_stanza_entry_unref0 (_data_->_tmp25_);
	_data_->id = _data_->_tmp28_;
	_data_->_tmp29_ = _data_->id;
	if (_data_->_tmp29_ == NULL) {
		_data_->result = NULL;
		_g_free0 (_data_->id);
		_xmpp_stanza_entry_unref0 (_data_->node);
		_g_object_unref0 (_data_->items);
		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_->_tmp30_ = _data_->node;
	_data_->_tmp31_ = xmpp_stanza_entry_get_string_content ((XmppStanzaEntry*) _data_->_tmp30_);
	_data_->_tmp32_ = 0;
	_data_->_tmp33_ = g_base64_decode (_data_->_tmp31_, &_data_->_tmp32_);
	_data_->_tmp34_ = g_bytes_new_take (_data_->_tmp33_, _data_->_tmp32_);
	_data_->image = _data_->_tmp34_;
	_data_->_tmp35_ = _data_->image;
	_data_->_tmp36_ = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, _data_->_tmp35_);
	_data_->sha1 = _data_->_tmp36_;
	_data_->_tmp37_ = _data_->sha1;
	_data_->_tmp38_ = _data_->id;
	if (g_strcmp0 (_data_->_tmp37_, _data_->_tmp38_) != 0) {
		_data_->_tmp39_ = xmpp_jid_to_string (_data_->jid);
		_data_->_tmp40_ = _data_->_tmp39_;
		_data_->_tmp41_ = _data_->id;
		_data_->_tmp42_ = _data_->sha1;
		g_warning ("0084_user_avatars.vala:39: sha sum did not match for avatar from %s ex" \
"pected=%s actual=%s", _data_->_tmp40_, _data_->_tmp41_, _data_->_tmp42_);
		_g_free0 (_data_->_tmp40_);
		_data_->result = NULL;
		_g_free0 (_data_->sha1);
		_g_bytes_unref0 (_data_->image);
		_g_free0 (_data_->id);
		_xmpp_stanza_entry_unref0 (_data_->node);
		_g_object_unref0 (_data_->items);
		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_->result = _data_->image;
	_g_free0 (_data_->sha1);
	_g_free0 (_data_->id);
	_xmpp_stanza_entry_unref0 (_data_->node);
	_g_object_unref0 (_data_->items);
	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_user_avatars_module_on_pupsub_item_xmpp_xep_pubsub_item_listener_delegate_result_func (XmppXmppStream* stream,
                                                                                                 XmppJid* jid,
                                                                                                 const gchar* id,
                                                                                                 XmppStanzaNode* node,
                                                                                                 gpointer self)
{
	xmpp_xep_user_avatars_module_on_pupsub_item ((XmppXepUserAvatarsModule*) self, stream, jid, id, node);
}

static void
_xmpp_xep_user_avatars_module_on_pubsub_delete_xmpp_xep_pubsub_delete_listener_delegate_result_func (XmppXmppStream* stream,
                                                                                                     XmppJid* jid,
                                                                                                     gpointer self)
{
	xmpp_xep_user_avatars_module_on_pubsub_delete ((XmppXepUserAvatarsModule*) self, stream, jid);
}

static void
xmpp_xep_user_avatars_module_real_attach (XmppXmppStreamModule* base,
                                          XmppXmppStream* stream)
{
	XmppXepUserAvatarsModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepPubsubModule* _tmp2_;
	self = (XmppXepUserAvatarsModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_xep_pubsub_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_PUBSUB_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppXepPubsubModule*) _tmp1_;
	xmpp_xep_pubsub_module_add_filtered_notification (_tmp2_, stream, XMPP_XEP_USER_AVATARS_NS_URI_METADATA, _xmpp_xep_user_avatars_module_on_pupsub_item_xmpp_xep_pubsub_item_listener_delegate_result_func, g_object_ref (self), g_object_unref, NULL, NULL, NULL, _xmpp_xep_user_avatars_module_on_pubsub_delete_xmpp_xep_pubsub_delete_listener_delegate_result_func, g_object_ref (self), g_object_unref);
	_g_object_unref0 (_tmp2_);
}

static void
xmpp_xep_user_avatars_module_real_detach (XmppXmppStreamModule* base,
                                          XmppXmppStream* stream)
{
	XmppXepUserAvatarsModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepPubsubModule* _tmp2_;
	self = (XmppXepUserAvatarsModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_xep_pubsub_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_PUBSUB_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppXepPubsubModule*) _tmp1_;
	xmpp_xep_pubsub_module_remove_filtered_notification (_tmp2_, stream, XMPP_XEP_USER_AVATARS_NS_URI_METADATA);
	_g_object_unref0 (_tmp2_);
}

void
xmpp_xep_user_avatars_module_on_pupsub_item (XmppXepUserAvatarsModule* self,
                                             XmppXmppStream* stream,
                                             XmppJid* jid,
                                             const gchar* hash,
                                             XmppStanzaNode* node)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (hash != NULL);
	{
		GeeList* _info_node_list = NULL;
		GeeList* _tmp0_;
		gint _info_node_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _info_node_index = 0;
		_tmp0_ = xmpp_stanza_node_get_subnodes (node, "info", XMPP_XEP_USER_AVATARS_NS_URI_METADATA, FALSE);
		_info_node_list = _tmp0_;
		_tmp1_ = _info_node_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_info_node_size = _tmp3_;
		_info_node_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			XmppStanzaNode* info_node = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			XmppStanzaNode* _tmp8_;
			const gchar* _tmp9_;
			_info_node_index = _info_node_index + 1;
			_tmp4_ = _info_node_index;
			_tmp5_ = _info_node_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _info_node_list;
			_tmp7_ = gee_list_get (_tmp6_, _info_node_index);
			info_node = (XmppStanzaNode*) _tmp7_;
			_tmp8_ = info_node;
			_tmp9_ = xmpp_stanza_node_get_attribute (_tmp8_, "id", NULL);
			if (g_strcmp0 (_tmp9_, hash) == 0) {
				const gchar* _tmp10_ = NULL;
				XmppStanzaNode* _tmp11_;
				gchar* type = NULL;
				gchar* _tmp14_;
				gboolean _tmp15_ = FALSE;
				const gchar* _tmp16_;
				_tmp11_ = info_node;
				if (_tmp11_ == NULL) {
					_tmp10_ = NULL;
				} else {
					XmppStanzaNode* _tmp12_;
					const gchar* _tmp13_;
					_tmp12_ = info_node;
					_tmp13_ = xmpp_stanza_node_get_attribute (_tmp12_, "type", NULL);
					_tmp10_ = _tmp13_;
				}
				_tmp14_ = g_strdup (_tmp10_);
				type = _tmp14_;
				_tmp16_ = type;
				if (g_strcmp0 (_tmp16_, "image/png") != 0) {
					const gchar* _tmp17_;
					_tmp17_ = type;
					_tmp15_ = g_strcmp0 (_tmp17_, "image/jpeg") != 0;
				} else {
					_tmp15_ = FALSE;
				}
				if (_tmp15_) {
					_g_free0 (type);
					_xmpp_stanza_entry_unref0 (info_node);
					_g_object_unref0 (_info_node_list);
					return;
				}
				g_signal_emit (self, xmpp_xep_user_avatars_module_signals[XMPP_XEP_USER_AVATARS_MODULE_RECEIVED_AVATAR_HASH_SIGNAL], 0, stream, jid, hash);
				_g_free0 (type);
				_xmpp_stanza_entry_unref0 (info_node);
				_g_object_unref0 (_info_node_list);
				return;
			}
			_xmpp_stanza_entry_unref0 (info_node);
		}
		_g_object_unref0 (_info_node_list);
	}
}

void
xmpp_xep_user_avatars_module_on_pubsub_delete (XmppXepUserAvatarsModule* self,
                                               XmppXmppStream* stream,
                                               XmppJid* jid)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_signal_emit (self, xmpp_xep_user_avatars_module_signals[XMPP_XEP_USER_AVATARS_MODULE_AVATAR_REMOVED_SIGNAL], 0, stream, jid);
}

static gchar*
xmpp_xep_user_avatars_module_real_get_ns (XmppXmppStreamModule* base)
{
	XmppXepUserAvatarsModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepUserAvatarsModule*) base;
	_tmp0_ = g_strdup (XMPP_XEP_USER_AVATARS_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_user_avatars_module_real_get_id (XmppXmppStreamModule* base)
{
	XmppXepUserAvatarsModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepUserAvatarsModule*) base;
	_tmp0_ = xmpp_xep_user_avatars_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppXepUserAvatarsModule*
xmpp_xep_user_avatars_module_construct (GType object_type)
{
	XmppXepUserAvatarsModule * self = NULL;
	self = (XmppXepUserAvatarsModule*) xmpp_xmpp_stream_module_construct (object_type);
	return self;
}

XmppXepUserAvatarsModule*
xmpp_xep_user_avatars_module_new (void)
{
	return xmpp_xep_user_avatars_module_construct (XMPP_XEP_USER_AVATARS_TYPE_MODULE);
}

static void
g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_STRING (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_JID_STRING) (gpointer data1, gpointer arg_1, gpointer arg_2, const char* arg_3, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_XMPP_JID_STRING callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	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_JID_STRING) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), xmpp_value_get_jid (param_values + 2), g_value_get_string (param_values + 3), data2);
}

static void
g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID (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_JID) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_XMPP_JID 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_JID) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), xmpp_value_get_jid (param_values + 2), data2);
}

static void
xmpp_xep_user_avatars_module_class_init (XmppXepUserAvatarsModuleClass * klass,
                                         gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_xep_user_avatars_module_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_user_avatars_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_user_avatars_module_real_detach;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_user_avatars_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_user_avatars_module_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_user_avatars_module_finalize;
	xmpp_xep_user_avatars_module_signals[XMPP_XEP_USER_AVATARS_MODULE_RECEIVED_AVATAR_HASH_SIGNAL] = g_signal_new ("received-avatar-hash", XMPP_XEP_USER_AVATARS_TYPE_MODULE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_STRING, G_TYPE_NONE, 3, XMPP_TYPE_XMPP_STREAM, XMPP_TYPE_JID, G_TYPE_STRING);
	xmpp_xep_user_avatars_module_signals[XMPP_XEP_USER_AVATARS_MODULE_AVATAR_REMOVED_SIGNAL] = g_signal_new ("avatar-removed", XMPP_XEP_USER_AVATARS_TYPE_MODULE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID, G_TYPE_NONE, 2, XMPP_TYPE_XMPP_STREAM, XMPP_TYPE_JID);
	_tmp0_ = xmpp_module_identity_new (XMPP_XEP_USER_AVATARS_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_USER_AVATARS_NS_URI, "0084_user_avatars");
	xmpp_xep_user_avatars_module_IDENTITY = _tmp0_;
}

static void
xmpp_xep_user_avatars_module_instance_init (XmppXepUserAvatarsModule * self,
                                            gpointer klass)
{
}

static void
xmpp_xep_user_avatars_module_finalize (GObject * obj)
{
	XmppXepUserAvatarsModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_USER_AVATARS_TYPE_MODULE, XmppXepUserAvatarsModule);
	G_OBJECT_CLASS (xmpp_xep_user_avatars_module_parent_class)->finalize (obj);
}

static GType
xmpp_xep_user_avatars_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepUserAvatarsModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_user_avatars_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepUserAvatarsModule), 0, (GInstanceInitFunc) xmpp_xep_user_avatars_module_instance_init, NULL };
	GType xmpp_xep_user_avatars_module_type_id;
	xmpp_xep_user_avatars_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_MODULE, "XmppXepUserAvatarsModule", &g_define_type_info, 0);
	return xmpp_xep_user_avatars_module_type_id;
}

GType
xmpp_xep_user_avatars_module_get_type (void)
{
	static volatile gsize xmpp_xep_user_avatars_module_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_user_avatars_module_type_id__once)) {
		GType xmpp_xep_user_avatars_module_type_id;
		xmpp_xep_user_avatars_module_type_id = xmpp_xep_user_avatars_module_get_type_once ();
		g_once_init_leave (&xmpp_xep_user_avatars_module_type_id__once, xmpp_xep_user_avatars_module_type_id);
	}
	return xmpp_xep_user_avatars_module_type_id__once;
}

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

