/* 0049_private_xml_storage.c generated by valac 0.56.19, the Vala compiler
 * generated from 0049_private_xml_storage.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>

#define XMPP_XEP_PRIVATE_XML_STORAGE_NS_URI "jabber:iq:private"
#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_XEP_PRIVATE_XML_STORAGE_MODULE_0_PROPERTY,
	XMPP_XEP_PRIVATE_XML_STORAGE_MODULE_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_private_xml_storage_module_properties[XMPP_XEP_PRIVATE_XML_STORAGE_MODULE_NUM_PROPERTIES];
#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)))
typedef struct _XmppXepPrivateXmlStorageModuleStoreData XmppXepPrivateXmlStorageModuleStoreData;
typedef struct _XmppXepPrivateXmlStorageModuleRetrieveData XmppXepPrivateXmlStorageModuleRetrieveData;

struct _XmppXepPrivateXmlStorageModuleStoreData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXepPrivateXmlStorageModule* self;
	XmppXmppStream* stream;
	XmppStanzaNode* node;
	XmppStanzaNode* queryNode;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppStanzaNode* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppIqStanza* iq;
	XmppIqStanza* _tmp6_;
	XmppModuleIdentity* _tmp7_;
	gpointer _tmp8_;
	XmppIqModule* _tmp9_;
	XmppIqStanza* _tmp10_;
	XmppIqStanza* _tmp11_;
	GError* _inner_error0_;
};

struct _XmppXepPrivateXmlStorageModuleRetrieveData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXepPrivateXmlStorageModule* self;
	XmppXmppStream* stream;
	XmppStanzaNode* node;
	XmppStanzaNode* result;
	XmppStanzaNode* queryNode;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppStanzaNode* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppIqStanza* iq;
	XmppIqStanza* _tmp6_;
	XmppIqStanza* iq_result;
	XmppModuleIdentity* _tmp7_;
	gpointer _tmp8_;
	XmppIqModule* _tmp9_;
	XmppIqStanza* _tmp10_;
	XmppIqStanza* _tmp11_;
	XmppStanzaNode* _tmp12_;
	XmppStanzaNode* _tmp13_;
	GError* _inner_error0_;
};

static gpointer xmpp_xep_private_xml_storage_module_parent_class = NULL;
XmppModuleIdentity* xmpp_xep_private_xml_storage_module_IDENTITY = NULL;

static void xmpp_xep_private_xml_storage_module_store_data_free (gpointer _data);
static gboolean xmpp_xep_private_xml_storage_module_store_co (XmppXepPrivateXmlStorageModuleStoreData* _data_);
static void xmpp_xep_private_xml_storage_module_store_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
static void xmpp_xep_private_xml_storage_module_retrieve_data_free (gpointer _data);
static gboolean xmpp_xep_private_xml_storage_module_retrieve_co (XmppXepPrivateXmlStorageModuleRetrieveData* _data_);
static void xmpp_xep_private_xml_storage_module_retrieve_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static void xmpp_xep_private_xml_storage_module_real_attach (XmppXmppStreamModule* base,
                                                      XmppXmppStream* stream);
static void xmpp_xep_private_xml_storage_module_real_detach (XmppXmppStreamModule* base,
                                                      XmppXmppStream* stream);
static gchar* xmpp_xep_private_xml_storage_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_xep_private_xml_storage_module_real_get_id (XmppXmppStreamModule* base);
static void xmpp_xep_private_xml_storage_module_finalize (GObject * obj);
static GType xmpp_xep_private_xml_storage_module_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

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

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

void
xmpp_xep_private_xml_storage_module_store (XmppXepPrivateXmlStorageModule* self,
                                           XmppXmppStream* stream,
                                           XmppStanzaNode* node,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	XmppXepPrivateXmlStorageModuleStoreData* _data_;
	XmppXepPrivateXmlStorageModule* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppStanzaNode* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (node != NULL);
	_data_ = g_slice_new0 (XmppXepPrivateXmlStorageModuleStoreData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_private_xml_storage_module_store_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _xmpp_stanza_entry_ref0 (node);
	_xmpp_stanza_entry_unref0 (_data_->node);
	_data_->node = _tmp2_;
	xmpp_xep_private_xml_storage_module_store_co (_data_);
}

void
xmpp_xep_private_xml_storage_module_store_finish (XmppXepPrivateXmlStorageModule* self,
                                                  GAsyncResult* _res_)
{
	XmppXepPrivateXmlStorageModuleStoreData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
xmpp_xep_private_xml_storage_module_store_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	XmppXepPrivateXmlStorageModuleStoreData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_xep_private_xml_storage_module_store_co (_data_);
}

static gboolean
xmpp_xep_private_xml_storage_module_store_co (XmppXepPrivateXmlStorageModuleStoreData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_stanza_node_new_build ("query", XMPP_XEP_PRIVATE_XML_STORAGE_NS_URI, NULL, NULL);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = xmpp_stanza_node_add_self_xmlns (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = xmpp_stanza_node_put_node (_data_->_tmp3_, _data_->node);
	_data_->_tmp5_ = _data_->_tmp4_;
	_xmpp_stanza_entry_unref0 (_data_->_tmp3_);
	_xmpp_stanza_entry_unref0 (_data_->_tmp1_);
	_data_->queryNode = _data_->_tmp5_;
	_data_->_tmp6_ = xmpp_iq_stanza_new_set (_data_->queryNode, NULL);
	_data_->iq = _data_->_tmp6_;
	_data_->_tmp7_ = xmpp_iq_module_IDENTITY;
	_data_->_tmp8_ = xmpp_xmpp_stream_get_module (_data_->stream, XMPP_IQ_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp7_);
	_data_->_tmp9_ = (XmppIqModule*) _data_->_tmp8_;
	_data_->_state_ = 1;
	xmpp_iq_module_send_iq_async (_data_->_tmp9_, _data_->stream, _data_->iq, G_PRIORITY_DEFAULT, NULL, xmpp_xep_private_xml_storage_module_store_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp10_ = xmpp_iq_module_send_iq_finish (_data_->_tmp9_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp11_);
	_g_object_unref0 (_data_->_tmp9_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->iq);
		_xmpp_stanza_entry_unref0 (_data_->queryNode);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->iq);
	_xmpp_stanza_entry_unref0 (_data_->queryNode);
	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_private_xml_storage_module_retrieve_data_free (gpointer _data)
{
	XmppXepPrivateXmlStorageModuleRetrieveData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_xmpp_stanza_entry_unref0 (_data_->node);
	_xmpp_stanza_entry_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppXepPrivateXmlStorageModuleRetrieveData, _data_);
}

void
xmpp_xep_private_xml_storage_module_retrieve (XmppXepPrivateXmlStorageModule* self,
                                              XmppXmppStream* stream,
                                              XmppStanzaNode* node,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	XmppXepPrivateXmlStorageModuleRetrieveData* _data_;
	XmppXepPrivateXmlStorageModule* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppStanzaNode* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (node != NULL);
	_data_ = g_slice_new0 (XmppXepPrivateXmlStorageModuleRetrieveData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_private_xml_storage_module_retrieve_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _xmpp_stanza_entry_ref0 (node);
	_xmpp_stanza_entry_unref0 (_data_->node);
	_data_->node = _tmp2_;
	xmpp_xep_private_xml_storage_module_retrieve_co (_data_);
}

XmppStanzaNode*
xmpp_xep_private_xml_storage_module_retrieve_finish (XmppXepPrivateXmlStorageModule* self,
                                                     GAsyncResult* _res_)
{
	XmppStanzaNode* result;
	XmppXepPrivateXmlStorageModuleRetrieveData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
xmpp_xep_private_xml_storage_module_retrieve_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	XmppXepPrivateXmlStorageModuleRetrieveData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_xep_private_xml_storage_module_retrieve_co (_data_);
}

static gboolean
xmpp_xep_private_xml_storage_module_retrieve_co (XmppXepPrivateXmlStorageModuleRetrieveData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_stanza_node_new_build ("query", XMPP_XEP_PRIVATE_XML_STORAGE_NS_URI, NULL, NULL);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = xmpp_stanza_node_add_self_xmlns (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = xmpp_stanza_node_put_node (_data_->_tmp3_, _data_->node);
	_data_->_tmp5_ = _data_->_tmp4_;
	_xmpp_stanza_entry_unref0 (_data_->_tmp3_);
	_xmpp_stanza_entry_unref0 (_data_->_tmp1_);
	_data_->queryNode = _data_->_tmp5_;
	_data_->_tmp6_ = xmpp_iq_stanza_new_get (_data_->queryNode, NULL);
	_data_->iq = _data_->_tmp6_;
	_data_->_tmp7_ = xmpp_iq_module_IDENTITY;
	_data_->_tmp8_ = xmpp_xmpp_stream_get_module (_data_->stream, XMPP_IQ_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp7_);
	_data_->_tmp9_ = (XmppIqModule*) _data_->_tmp8_;
	_data_->_state_ = 1;
	xmpp_iq_module_send_iq_async (_data_->_tmp9_, _data_->stream, _data_->iq, G_PRIORITY_DEFAULT, NULL, xmpp_xep_private_xml_storage_module_retrieve_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp10_ = xmpp_iq_module_send_iq_finish (_data_->_tmp9_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp9_);
	_data_->iq_result = _data_->_tmp11_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->iq);
		_xmpp_stanza_entry_unref0 (_data_->queryNode);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = ((XmppStanza*) _data_->iq_result)->stanza;
	_data_->_tmp13_ = xmpp_stanza_node_get_subnode (_data_->_tmp12_, "query", XMPP_XEP_PRIVATE_XML_STORAGE_NS_URI, FALSE);
	_data_->result = _data_->_tmp13_;
	_g_object_unref0 (_data_->iq_result);
	_g_object_unref0 (_data_->iq);
	_xmpp_stanza_entry_unref0 (_data_->queryNode);
	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_private_xml_storage_module_real_attach (XmppXmppStreamModule* base,
                                                 XmppXmppStream* stream)
{
	XmppXepPrivateXmlStorageModule * self;
	self = (XmppXepPrivateXmlStorageModule*) base;
	g_return_if_fail (stream != NULL);
}

static void
xmpp_xep_private_xml_storage_module_real_detach (XmppXmppStreamModule* base,
                                                 XmppXmppStream* stream)
{
	XmppXepPrivateXmlStorageModule * self;
	self = (XmppXepPrivateXmlStorageModule*) base;
	g_return_if_fail (stream != NULL);
}

static gchar*
xmpp_xep_private_xml_storage_module_real_get_ns (XmppXmppStreamModule* base)
{
	XmppXepPrivateXmlStorageModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepPrivateXmlStorageModule*) base;
	_tmp0_ = g_strdup (XMPP_XEP_PRIVATE_XML_STORAGE_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_private_xml_storage_module_real_get_id (XmppXmppStreamModule* base)
{
	XmppXepPrivateXmlStorageModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepPrivateXmlStorageModule*) base;
	_tmp0_ = xmpp_xep_private_xml_storage_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppXepPrivateXmlStorageModule*
xmpp_xep_private_xml_storage_module_construct (GType object_type)
{
	XmppXepPrivateXmlStorageModule * self = NULL;
	self = (XmppXepPrivateXmlStorageModule*) xmpp_xmpp_stream_module_construct (object_type);
	return self;
}

XmppXepPrivateXmlStorageModule*
xmpp_xep_private_xml_storage_module_new (void)
{
	return xmpp_xep_private_xml_storage_module_construct (XMPP_XEP_PRIVATE_XML_STORAGE_TYPE_MODULE);
}

static void
xmpp_xep_private_xml_storage_module_class_init (XmppXepPrivateXmlStorageModuleClass * klass,
                                                gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_xep_private_xml_storage_module_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_private_xml_storage_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_private_xml_storage_module_real_detach;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_private_xml_storage_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_private_xml_storage_module_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_private_xml_storage_module_finalize;
	_tmp0_ = xmpp_module_identity_new (XMPP_XEP_PRIVATE_XML_STORAGE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_PRIVATE_XML_STORAGE_NS_URI, "0049_private_xml_storage");
	xmpp_xep_private_xml_storage_module_IDENTITY = _tmp0_;
}

static void
xmpp_xep_private_xml_storage_module_instance_init (XmppXepPrivateXmlStorageModule * self,
                                                   gpointer klass)
{
}

static void
xmpp_xep_private_xml_storage_module_finalize (GObject * obj)
{
	XmppXepPrivateXmlStorageModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_PRIVATE_XML_STORAGE_TYPE_MODULE, XmppXepPrivateXmlStorageModule);
	G_OBJECT_CLASS (xmpp_xep_private_xml_storage_module_parent_class)->finalize (obj);
}

static GType
xmpp_xep_private_xml_storage_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepPrivateXmlStorageModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_private_xml_storage_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepPrivateXmlStorageModule), 0, (GInstanceInitFunc) xmpp_xep_private_xml_storage_module_instance_init, NULL };
	GType xmpp_xep_private_xml_storage_module_type_id;
	xmpp_xep_private_xml_storage_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_MODULE, "XmppXepPrivateXmlStorageModule", &g_define_type_info, 0);
	return xmpp_xep_private_xml_storage_module_type_id;
}

GType
xmpp_xep_private_xml_storage_module_get_type (void)
{
	static volatile gsize xmpp_xep_private_xml_storage_module_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_private_xml_storage_module_type_id__once)) {
		GType xmpp_xep_private_xml_storage_module_type_id;
		xmpp_xep_private_xml_storage_module_type_id = xmpp_xep_private_xml_storage_module_get_type_once ();
		g_once_init_leave (&xmpp_xep_private_xml_storage_module_type_id__once, xmpp_xep_private_xml_storage_module_type_id);
	}
	return xmpp_xep_private_xml_storage_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;
}

