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

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

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

#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
enum  {
	XMPP_XEP_OCCUPANT_IDS_MODULE_0_PROPERTY,
	XMPP_XEP_OCCUPANT_IDS_MODULE_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_occupant_ids_module_properties[XMPP_XEP_OCCUPANT_IDS_MODULE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
enum  {
	XMPP_XEP_OCCUPANT_IDS_MODULE_RECEIVED_OCCUPANT_ID_SIGNAL,
	XMPP_XEP_OCCUPANT_IDS_MODULE_RECEIVED_OWN_OCCUPANT_ID_SIGNAL,
	XMPP_XEP_OCCUPANT_IDS_MODULE_NUM_SIGNALS
};
static guint xmpp_xep_occupant_ids_module_signals[XMPP_XEP_OCCUPANT_IDS_MODULE_NUM_SIGNALS] = {0};

static gpointer xmpp_xep_occupant_ids_module_parent_class = NULL;
XmppModuleIdentity* xmpp_xep_occupant_ids_module_IDENTITY = NULL;

static void xmpp_xep_occupant_ids_module_real_attach (XmppXmppStreamModule* base,
                                               XmppXmppStream* stream);
static void _xmpp_xep_occupant_ids_module_parse_occupant_id_from_presence_xmpp_presence_module_received_available (XmppPresenceModule* _sender,
                                                                                                            XmppXmppStream* stream,
                                                                                                            XmppPresenceStanza* presence,
                                                                                                            gpointer self);
static void xmpp_xep_occupant_ids_module_real_detach (XmppXmppStreamModule* base,
                                               XmppXmppStream* stream);
static gchar* xmpp_xep_occupant_ids_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_xep_occupant_ids_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 xmpp_xep_occupant_ids_module_finalize (GObject * obj);
static GType xmpp_xep_occupant_ids_module_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gchar*
xmpp_xep_occupant_ids_get_occupant_id (XmppStanzaNode* stanza)
{
	XmppStanzaNode* node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (stanza != NULL, NULL);
	_tmp0_ = xmpp_stanza_node_get_subnode (stanza, "occupant-id", XMPP_XEP_OCCUPANT_IDS_NS_URI, FALSE);
	node = _tmp0_;
	_tmp1_ = node;
	if (_tmp1_ == NULL) {
		result = NULL;
		_xmpp_stanza_entry_unref0 (node);
		return result;
	}
	_tmp2_ = node;
	_tmp3_ = xmpp_stanza_node_get_attribute (_tmp2_, "id", NULL);
	_tmp4_ = g_strdup (_tmp3_);
	result = _tmp4_;
	_xmpp_stanza_entry_unref0 (node);
	return result;
}

static void
_xmpp_xep_occupant_ids_module_parse_occupant_id_from_presence_xmpp_presence_module_received_available (XmppPresenceModule* _sender,
                                                                                                       XmppXmppStream* stream,
                                                                                                       XmppPresenceStanza* presence,
                                                                                                       gpointer self)
{
	xmpp_xep_occupant_ids_module_parse_occupant_id_from_presence ((XmppXepOccupantIdsModule*) self, stream, presence);
}

static void
xmpp_xep_occupant_ids_module_real_attach (XmppXmppStreamModule* base,
                                          XmppXmppStream* stream)
{
	XmppXepOccupantIdsModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppPresenceModule* _tmp2_;
	self = (XmppXepOccupantIdsModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_presence_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppPresenceModule*) _tmp1_;
	g_signal_connect_object (_tmp2_, "received-available", (GCallback) _xmpp_xep_occupant_ids_module_parse_occupant_id_from_presence_xmpp_presence_module_received_available, self, 0);
	_g_object_unref0 (_tmp2_);
}

static void
xmpp_xep_occupant_ids_module_real_detach (XmppXmppStreamModule* base,
                                          XmppXmppStream* stream)
{
	XmppXepOccupantIdsModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppPresenceModule* _tmp2_;
	guint _tmp3_;
	self = (XmppXepOccupantIdsModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_presence_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppPresenceModule*) _tmp1_;
	g_signal_parse_name ("received-available", XMPP_PRESENCE_TYPE_MODULE, &_tmp3_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp2_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp3_, 0, NULL, (GCallback) _xmpp_xep_occupant_ids_module_parse_occupant_id_from_presence_xmpp_presence_module_received_available, self);
	_g_object_unref0 (_tmp2_);
}

static gchar*
xmpp_xep_occupant_ids_module_real_get_ns (XmppXmppStreamModule* base)
{
	XmppXepOccupantIdsModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepOccupantIdsModule*) base;
	_tmp0_ = g_strdup (XMPP_XEP_OCCUPANT_IDS_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_occupant_ids_module_real_get_id (XmppXmppStreamModule* base)
{
	XmppXepOccupantIdsModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepOccupantIdsModule*) base;
	_tmp0_ = xmpp_xep_occupant_ids_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

void
xmpp_xep_occupant_ids_module_parse_occupant_id_from_presence (XmppXepOccupantIdsModule* self,
                                                              XmppXmppStream* stream,
                                                              XmppPresenceStanza* presence)
{
	gchar* occupant_id = NULL;
	XmppStanzaNode* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	XmppJid* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	const gchar* _tmp6_;
	XmppStanzaNode* x_node = NULL;
	XmppStanzaNode* _tmp7_;
	XmppStanzaNode* _tmp8_;
	XmppStanzaNode* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (presence != NULL);
	_tmp0_ = ((XmppStanza*) presence)->stanza;
	_tmp1_ = xmpp_xep_occupant_ids_get_occupant_id (_tmp0_);
	occupant_id = _tmp1_;
	_tmp2_ = occupant_id;
	if (_tmp2_ == NULL) {
		_g_free0 (occupant_id);
		return;
	}
	_tmp3_ = xmpp_stanza_get_from ((XmppStanza*) presence);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp6_ = occupant_id;
	g_signal_emit (self, xmpp_xep_occupant_ids_module_signals[XMPP_XEP_OCCUPANT_IDS_MODULE_RECEIVED_OCCUPANT_ID_SIGNAL], 0, stream, _tmp5_, _tmp6_);
	_xmpp_jid_unref0 (_tmp5_);
	_tmp7_ = ((XmppStanza*) presence)->stanza;
	_tmp8_ = xmpp_stanza_node_get_subnode (_tmp7_, "x", "http://jabber.org/protocol/muc#user", FALSE);
	x_node = _tmp8_;
	_tmp9_ = x_node;
	if (_tmp9_ == NULL) {
		_xmpp_stanza_entry_unref0 (x_node);
		_g_free0 (occupant_id);
		return;
	}
	{
		GeeList* _status_node_list = NULL;
		XmppStanzaNode* _tmp10_;
		GeeList* _tmp11_;
		gint _status_node_size = 0;
		GeeList* _tmp12_;
		gint _tmp13_;
		gint _tmp14_;
		gint _status_node_index = 0;
		_tmp10_ = x_node;
		_tmp11_ = xmpp_stanza_node_get_subnodes (_tmp10_, "status", "http://jabber.org/protocol/muc#user", FALSE);
		_status_node_list = _tmp11_;
		_tmp12_ = _status_node_list;
		_tmp13_ = gee_collection_get_size ((GeeCollection*) _tmp12_);
		_tmp14_ = _tmp13_;
		_status_node_size = _tmp14_;
		_status_node_index = -1;
		while (TRUE) {
			gint _tmp15_;
			gint _tmp16_;
			XmppStanzaNode* status_node = NULL;
			GeeList* _tmp17_;
			gpointer _tmp18_;
			XmppStanzaNode* _tmp19_;
			const gchar* _tmp20_;
			_status_node_index = _status_node_index + 1;
			_tmp15_ = _status_node_index;
			_tmp16_ = _status_node_size;
			if (!(_tmp15_ < _tmp16_)) {
				break;
			}
			_tmp17_ = _status_node_list;
			_tmp18_ = gee_list_get (_tmp17_, _status_node_index);
			status_node = (XmppStanzaNode*) _tmp18_;
			_tmp19_ = status_node;
			_tmp20_ = xmpp_stanza_node_get_attribute (_tmp19_, "code", NULL);
			if (atoi (_tmp20_) == 110) {
				XmppJid* _tmp21_;
				XmppJid* _tmp22_;
				XmppJid* _tmp23_;
				const gchar* _tmp24_;
				_tmp21_ = xmpp_stanza_get_from ((XmppStanza*) presence);
				_tmp22_ = _tmp21_;
				_tmp23_ = _tmp22_;
				_tmp24_ = occupant_id;
				g_signal_emit (self, xmpp_xep_occupant_ids_module_signals[XMPP_XEP_OCCUPANT_IDS_MODULE_RECEIVED_OWN_OCCUPANT_ID_SIGNAL], 0, stream, _tmp23_, _tmp24_);
				_xmpp_jid_unref0 (_tmp23_);
			}
			_xmpp_stanza_entry_unref0 (status_node);
		}
		_g_object_unref0 (_status_node_list);
	}
	_xmpp_stanza_entry_unref0 (x_node);
	_g_free0 (occupant_id);
}

XmppXepOccupantIdsModule*
xmpp_xep_occupant_ids_module_construct (GType object_type)
{
	XmppXepOccupantIdsModule * self = NULL;
	self = (XmppXepOccupantIdsModule*) xmpp_xmpp_stream_module_construct (object_type);
	return self;
}

XmppXepOccupantIdsModule*
xmpp_xep_occupant_ids_module_new (void)
{
	return xmpp_xep_occupant_ids_module_construct (XMPP_XEP_OCCUPANT_IDS_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
xmpp_xep_occupant_ids_module_class_init (XmppXepOccupantIdsModuleClass * klass,
                                         gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_xep_occupant_ids_module_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_occupant_ids_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_occupant_ids_module_real_detach;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_occupant_ids_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_occupant_ids_module_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_occupant_ids_module_finalize;
	xmpp_xep_occupant_ids_module_signals[XMPP_XEP_OCCUPANT_IDS_MODULE_RECEIVED_OCCUPANT_ID_SIGNAL] = g_signal_new ("received-occupant-id", XMPP_XEP_OCCUPANT_IDS_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_occupant_ids_module_signals[XMPP_XEP_OCCUPANT_IDS_MODULE_RECEIVED_OWN_OCCUPANT_ID_SIGNAL] = g_signal_new ("received-own-occupant-id", XMPP_XEP_OCCUPANT_IDS_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);
	_tmp0_ = xmpp_module_identity_new (XMPP_XEP_OCCUPANT_IDS_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_OCCUPANT_IDS_NS_URI, "0421_occupant_ids");
	xmpp_xep_occupant_ids_module_IDENTITY = _tmp0_;
}

static void
xmpp_xep_occupant_ids_module_instance_init (XmppXepOccupantIdsModule * self,
                                            gpointer klass)
{
}

static void
xmpp_xep_occupant_ids_module_finalize (GObject * obj)
{
	XmppXepOccupantIdsModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_OCCUPANT_IDS_TYPE_MODULE, XmppXepOccupantIdsModule);
	G_OBJECT_CLASS (xmpp_xep_occupant_ids_module_parent_class)->finalize (obj);
}

static GType
xmpp_xep_occupant_ids_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepOccupantIdsModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_occupant_ids_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepOccupantIdsModule), 0, (GInstanceInitFunc) xmpp_xep_occupant_ids_module_instance_init, NULL };
	GType xmpp_xep_occupant_ids_module_type_id;
	xmpp_xep_occupant_ids_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_MODULE, "XmppXepOccupantIdsModule", &g_define_type_info, 0);
	return xmpp_xep_occupant_ids_module_type_id;
}

GType
xmpp_xep_occupant_ids_module_get_type (void)
{
	static volatile gsize xmpp_xep_occupant_ids_module_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_occupant_ids_module_type_id__once)) {
		GType xmpp_xep_occupant_ids_module_type_id;
		xmpp_xep_occupant_ids_module_type_id = xmpp_xep_occupant_ids_module_get_type_once ();
		g_once_init_leave (&xmpp_xep_occupant_ids_module_type_id__once, xmpp_xep_occupant_ids_module_type_id);
	}
	return xmpp_xep_occupant_ids_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;
}

