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

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

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

#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 _xmpp_error_stanza_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_error_stanza_unref (var), NULL)))
typedef struct _XmppXepMucSelfPingIsJoinedData XmppXepMucSelfPingIsJoinedData;

struct _XmppXepMucSelfPingIsJoinedData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXmppStream* stream;
	XmppJid* jid;
	gboolean result;
	XmppIqStanza* iq_result;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepPingModule* _tmp2_;
	XmppIqStanza* _tmp3_;
	XmppIqStanza* _tmp4_;
	XmppIqStanza* _tmp5_;
	XmppErrorStanza* error_stanza;
	XmppIqStanza* _tmp6_;
	XmppErrorStanza* _tmp7_;
	XmppErrorStanza* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar** _tmp13_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	gboolean _tmp15_;
};

static void xmpp_xep_muc_self_ping_is_joined_data_free (gpointer _data);
static gboolean xmpp_xep_muc_self_ping_is_joined_co (XmppXepMucSelfPingIsJoinedData* _data_);
static void xmpp_xep_muc_self_ping_is_joined_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      gssize stack_length,
                                      const gchar* needle);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
xmpp_xep_muc_self_ping_is_joined_data_free (gpointer _data)
{
	XmppXepMucSelfPingIsJoinedData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_xmpp_jid_unref0 (_data_->jid);
	g_slice_free (XmppXepMucSelfPingIsJoinedData, _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_muc_self_ping_is_joined (XmppXmppStream* stream,
                                  XmppJid* jid,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	XmppXepMucSelfPingIsJoinedData* _data_;
	XmppXmppStream* _tmp0_;
	XmppJid* _tmp1_;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	_data_ = g_slice_new0 (XmppXepMucSelfPingIsJoinedData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_muc_self_ping_is_joined_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_;
	xmpp_xep_muc_self_ping_is_joined_co (_data_);
}

gboolean
xmpp_xep_muc_self_ping_is_joined_finish (GAsyncResult* _res_)
{
	gboolean result;
	XmppXepMucSelfPingIsJoinedData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
xmpp_xep_muc_self_ping_is_joined_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	XmppXepMucSelfPingIsJoinedData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_xep_muc_self_ping_is_joined_co (_data_);
}

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

static gboolean
xmpp_xep_muc_self_ping_is_joined_co (XmppXepMucSelfPingIsJoinedData* _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_ping_module_IDENTITY;
	_data_->_tmp1_ = xmpp_xmpp_stream_get_module (_data_->stream, XMPP_XEP_PING_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp0_);
	_data_->_tmp2_ = (XmppXepPingModule*) _data_->_tmp1_;
	_data_->_state_ = 1;
	xmpp_xep_ping_module_send_ping (_data_->_tmp2_, _data_->stream, _data_->jid, xmpp_xep_muc_self_ping_is_joined_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp3_ = xmpp_xep_ping_module_send_ping_finish (_data_->_tmp2_, _data_->_res_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_g_object_unref0 (_data_->_tmp2_);
	_data_->iq_result = _data_->_tmp4_;
	_data_->_tmp5_ = _data_->iq_result;
	if (!xmpp_stanza_is_error ((XmppStanza*) _data_->_tmp5_)) {
		_data_->result = TRUE;
		_g_object_unref0 (_data_->iq_result);
		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;
	} else {
		_data_->_tmp6_ = _data_->iq_result;
		_data_->_tmp7_ = xmpp_stanza_get_error ((XmppStanza*) _data_->_tmp6_);
		_data_->error_stanza = _data_->_tmp7_;
		_data_->_tmp8_ = _data_->error_stanza;
		_data_->_tmp9_ = xmpp_error_stanza_get_condition (_data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = g_strdup (XMPP_ERROR_STANZA_CONDITION_SERVICE_UNAVAILABLE);
		_data_->_tmp12_ = g_strdup (XMPP_ERROR_STANZA_CONDITION_FEATURE_NOT_IMPLEMENTED);
		_data_->_tmp13_ = g_new0 (gchar*, 2 + 1);
		_data_->_tmp13_[0] = _data_->_tmp11_;
		_data_->_tmp13_[1] = _data_->_tmp12_;
		_data_->_tmp14_ = _data_->_tmp13_;
		_data_->_tmp14__length1 = 2;
		_data_->_tmp15_ = _vala_string_array_contains (_data_->_tmp14_, 2, _data_->_tmp10_);
		_data_->_tmp14_ = (_vala_array_free (_data_->_tmp14_, _data_->_tmp14__length1, (GDestroyNotify) g_free), NULL);
		if (_data_->_tmp15_) {
			_data_->result = TRUE;
			_xmpp_error_stanza_unref0 (_data_->error_stanza);
			_g_object_unref0 (_data_->iq_result);
			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;
		}
		_xmpp_error_stanza_unref0 (_data_->error_stanza);
	}
	_data_->result = FALSE;
	_g_object_unref0 (_data_->iq_result);
	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
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

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

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

