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

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

#define XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI "jabber:x:conference"
#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_DIRECT_MUC_INVITATIONS_MODULE_0_PROPERTY,
	XMPP_XEP_DIRECT_MUC_INVITATIONS_MODULE_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_direct_muc_invitations_module_properties[XMPP_XEP_DIRECT_MUC_INVITATIONS_MODULE_NUM_PROPERTIES];
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	XMPP_XEP_DIRECT_MUC_INVITATIONS_MODULE_INVITE_RECEIVED_SIGNAL,
	XMPP_XEP_DIRECT_MUC_INVITATIONS_MODULE_NUM_SIGNALS
};
static guint xmpp_xep_direct_muc_invitations_module_signals[XMPP_XEP_DIRECT_MUC_INVITATIONS_MODULE_NUM_SIGNALS] = {0};

static gpointer xmpp_xep_direct_muc_invitations_module_parent_class = NULL;
XmppModuleIdentity* xmpp_xep_direct_muc_invitations_module_IDENTITY = NULL;

static void xmpp_xep_direct_muc_invitations_module_received_message (XmppXepDirectMucInvitationsModule* self,
                                                              XmppXmppStream* stream,
                                                              XmppMessageStanza* message);
static void xmpp_xep_direct_muc_invitations_module_real_attach (XmppXmppStreamModule* base,
                                                         XmppXmppStream* stream);
static void _xmpp_xep_direct_muc_invitations_module_received_message_xmpp_message_module_received_message (XmppMessageModule* _sender,
                                                                                                    XmppXmppStream* stream,
                                                                                                    XmppMessageStanza* message,
                                                                                                    gpointer self);
static void xmpp_xep_direct_muc_invitations_module_real_detach (XmppXmppStreamModule* base,
                                                         XmppXmppStream* stream);
static gchar* xmpp_xep_direct_muc_invitations_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_xep_direct_muc_invitations_module_real_get_id (XmppXmppStreamModule* base);
static void g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_XMPP_JID_STRING_STRING (GClosure * closure,
                                                                           GValue * return_value,
                                                                           guint n_param_values,
                                                                           const GValue * param_values,
                                                                           gpointer invocation_hint,
                                                                           gpointer marshal_data);
static void xmpp_xep_direct_muc_invitations_module_finalize (GObject * obj);
static GType xmpp_xep_direct_muc_invitations_module_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

void
xmpp_xep_direct_muc_invitations_module_invite (XmppXepDirectMucInvitationsModule* self,
                                               XmppXmppStream* stream,
                                               XmppJid* to_muc,
                                               XmppJid* jid)
{
	XmppMessageStanza* message = NULL;
	XmppJid* _tmp0_;
	XmppMessageStanza* _tmp1_ = NULL;
	XmppStanzaNode* invite_node = NULL;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppStanzaNode* _tmp4_;
	XmppStanzaNode* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	XmppStanzaNode* _tmp8_;
	XmppStanzaNode* _tmp9_;
	XmppStanzaNode* _tmp10_;
	XmppStanzaNode* _tmp11_;
	XmppStanzaNode* _tmp12_;
	XmppModuleIdentity* _tmp13_;
	gpointer _tmp14_;
	XmppMessageModule* _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (to_muc != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = _xmpp_jid_ref0 (jid);
	_tmp1_ = xmpp_message_stanza_new (NULL);
	xmpp_stanza_set_to ((XmppStanza*) _tmp1_, _tmp0_);
	_xmpp_jid_unref0 (_tmp0_);
	message = _tmp1_;
	_tmp2_ = xmpp_stanza_node_new_build ("x", XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI, NULL, NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = xmpp_stanza_node_add_self_xmlns (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = xmpp_jid_to_string (to_muc);
	_tmp7_ = _tmp6_;
	_tmp8_ = xmpp_stanza_node_put_attribute (_tmp5_, "jid", _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	_xmpp_stanza_entry_unref0 (_tmp5_);
	_xmpp_stanza_entry_unref0 (_tmp3_);
	invite_node = _tmp9_;
	_tmp10_ = ((XmppStanza*) message)->stanza;
	_tmp11_ = xmpp_stanza_node_put_node (_tmp10_, invite_node);
	_tmp12_ = _tmp11_;
	_xmpp_stanza_entry_unref0 (_tmp12_);
	_tmp13_ = xmpp_message_module_IDENTITY;
	_tmp14_ = xmpp_xmpp_stream_get_module (stream, XMPP_TYPE_MESSAGE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp13_);
	_tmp15_ = (XmppMessageModule*) _tmp14_;
	xmpp_message_module_send_message (_tmp15_, stream, message, NULL, NULL);
	_g_object_unref0 (_tmp15_);
	_xmpp_stanza_entry_unref0 (invite_node);
	_g_object_unref0 (message);
}

static void
xmpp_xep_direct_muc_invitations_module_received_message (XmppXepDirectMucInvitationsModule* self,
                                                         XmppXmppStream* stream,
                                                         XmppMessageStanza* message)
{
	XmppStanzaNode* x_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	gchar* room_str = NULL;
	XmppStanzaNode* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	XmppJid* room_jid = NULL;
	XmppJid* _tmp11_;
	gchar* password = NULL;
	XmppStanzaNode* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* reason = NULL;
	XmppStanzaNode* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	XmppJid* _tmp18_;
	XmppJid* _tmp19_;
	XmppJid* _tmp20_;
	XmppJid* _tmp21_;
	const gchar* _tmp22_;
	const gchar* _tmp23_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (message != NULL);
	_tmp0_ = ((XmppStanza*) message)->stanza;
	_tmp1_ = xmpp_stanza_node_get_subnode (_tmp0_, "x", XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI, FALSE);
	x_node = _tmp1_;
	_tmp2_ = x_node;
	if (_tmp2_ == NULL) {
		_xmpp_stanza_entry_unref0 (x_node);
		return;
	}
	_tmp3_ = x_node;
	_tmp4_ = xmpp_stanza_node_get_attribute (_tmp3_, "jid", XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI);
	_tmp5_ = g_strdup (_tmp4_);
	room_str = _tmp5_;
	_tmp6_ = room_str;
	if (_tmp6_ == NULL) {
		_g_free0 (room_str);
		_xmpp_stanza_entry_unref0 (x_node);
		return;
	}
	room_jid = NULL;
	{
		XmppJid* _tmp7_ = NULL;
		const gchar* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		_tmp8_ = room_str;
		_tmp9_ = xmpp_jid_new (_tmp8_, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		_xmpp_jid_unref0 (room_jid);
		room_jid = _tmp10_;
		_xmpp_jid_unref0 (_tmp7_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		_xmpp_jid_unref0 (room_jid);
		_g_free0 (room_str);
		_xmpp_stanza_entry_unref0 (x_node);
		return;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_xmpp_jid_unref0 (room_jid);
		_g_free0 (room_str);
		_xmpp_stanza_entry_unref0 (x_node);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_tmp11_ = room_jid;
	if (_tmp11_ == NULL) {
		_xmpp_jid_unref0 (room_jid);
		_g_free0 (room_str);
		_xmpp_stanza_entry_unref0 (x_node);
		return;
	}
	_tmp12_ = x_node;
	_tmp13_ = xmpp_stanza_node_get_attribute (_tmp12_, "password", XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI);
	_tmp14_ = g_strdup (_tmp13_);
	password = _tmp14_;
	_tmp15_ = x_node;
	_tmp16_ = xmpp_stanza_node_get_attribute (_tmp15_, "reason", XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI);
	_tmp17_ = g_strdup (_tmp16_);
	reason = _tmp17_;
	_tmp18_ = room_jid;
	_tmp19_ = xmpp_stanza_get_from ((XmppStanza*) message);
	_tmp20_ = _tmp19_;
	_tmp21_ = _tmp20_;
	_tmp22_ = password;
	_tmp23_ = reason;
	g_signal_emit (self, xmpp_xep_direct_muc_invitations_module_signals[XMPP_XEP_DIRECT_MUC_INVITATIONS_MODULE_INVITE_RECEIVED_SIGNAL], 0, stream, _tmp18_, _tmp21_, _tmp22_, _tmp23_);
	_xmpp_jid_unref0 (_tmp21_);
	_g_free0 (reason);
	_g_free0 (password);
	_xmpp_jid_unref0 (room_jid);
	_g_free0 (room_str);
	_xmpp_stanza_entry_unref0 (x_node);
}

static void
_xmpp_xep_direct_muc_invitations_module_received_message_xmpp_message_module_received_message (XmppMessageModule* _sender,
                                                                                               XmppXmppStream* stream,
                                                                                               XmppMessageStanza* message,
                                                                                               gpointer self)
{
	xmpp_xep_direct_muc_invitations_module_received_message ((XmppXepDirectMucInvitationsModule*) self, stream, message);
}

static void
xmpp_xep_direct_muc_invitations_module_real_attach (XmppXmppStreamModule* base,
                                                    XmppXmppStream* stream)
{
	XmppXepDirectMucInvitationsModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppMessageModule* _tmp2_;
	self = (XmppXepDirectMucInvitationsModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_message_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_TYPE_MESSAGE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppMessageModule*) _tmp1_;
	g_signal_connect_object (_tmp2_, "received-message", (GCallback) _xmpp_xep_direct_muc_invitations_module_received_message_xmpp_message_module_received_message, self, 0);
	_g_object_unref0 (_tmp2_);
}

static void
xmpp_xep_direct_muc_invitations_module_real_detach (XmppXmppStreamModule* base,
                                                    XmppXmppStream* stream)
{
	XmppXepDirectMucInvitationsModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppMessageModule* _tmp2_;
	self = (XmppXepDirectMucInvitationsModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_message_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_TYPE_MESSAGE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppMessageModule*) _tmp1_;
	g_signal_connect_object (_tmp2_, "received-message", (GCallback) _xmpp_xep_direct_muc_invitations_module_received_message_xmpp_message_module_received_message, self, 0);
	_g_object_unref0 (_tmp2_);
}

static gchar*
xmpp_xep_direct_muc_invitations_module_real_get_ns (XmppXmppStreamModule* base)
{
	XmppXepDirectMucInvitationsModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepDirectMucInvitationsModule*) base;
	_tmp0_ = g_strdup (XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_direct_muc_invitations_module_real_get_id (XmppXmppStreamModule* base)
{
	XmppXepDirectMucInvitationsModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepDirectMucInvitationsModule*) base;
	_tmp0_ = xmpp_xep_direct_muc_invitations_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppXepDirectMucInvitationsModule*
xmpp_xep_direct_muc_invitations_module_construct (GType object_type)
{
	XmppXepDirectMucInvitationsModule * self = NULL;
	self = (XmppXepDirectMucInvitationsModule*) xmpp_xmpp_stream_module_construct (object_type);
	return self;
}

XmppXepDirectMucInvitationsModule*
xmpp_xep_direct_muc_invitations_module_new (void)
{
	return xmpp_xep_direct_muc_invitations_module_construct (XMPP_XEP_DIRECT_MUC_INVITATIONS_TYPE_MODULE);
}

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

static void
xmpp_xep_direct_muc_invitations_module_class_init (XmppXepDirectMucInvitationsModuleClass * klass,
                                                   gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_xep_direct_muc_invitations_module_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_direct_muc_invitations_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_direct_muc_invitations_module_real_detach;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_direct_muc_invitations_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_direct_muc_invitations_module_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_direct_muc_invitations_module_finalize;
	xmpp_xep_direct_muc_invitations_module_signals[XMPP_XEP_DIRECT_MUC_INVITATIONS_MODULE_INVITE_RECEIVED_SIGNAL] = g_signal_new ("invite-received", XMPP_XEP_DIRECT_MUC_INVITATIONS_TYPE_MODULE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_XMPP_JID_STRING_STRING, G_TYPE_NONE, 5, XMPP_TYPE_XMPP_STREAM, XMPP_TYPE_JID, XMPP_TYPE_JID, G_TYPE_STRING, G_TYPE_STRING);
	_tmp0_ = xmpp_module_identity_new (XMPP_XEP_DIRECT_MUC_INVITATIONS_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_DIRECT_MUC_INVITATIONS_NS_URI, "0249_direct_muc_invitations");
	xmpp_xep_direct_muc_invitations_module_IDENTITY = _tmp0_;
}

static void
xmpp_xep_direct_muc_invitations_module_instance_init (XmppXepDirectMucInvitationsModule * self,
                                                      gpointer klass)
{
}

static void
xmpp_xep_direct_muc_invitations_module_finalize (GObject * obj)
{
	XmppXepDirectMucInvitationsModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_DIRECT_MUC_INVITATIONS_TYPE_MODULE, XmppXepDirectMucInvitationsModule);
	G_OBJECT_CLASS (xmpp_xep_direct_muc_invitations_module_parent_class)->finalize (obj);
}

static GType
xmpp_xep_direct_muc_invitations_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepDirectMucInvitationsModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_direct_muc_invitations_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepDirectMucInvitationsModule), 0, (GInstanceInitFunc) xmpp_xep_direct_muc_invitations_module_instance_init, NULL };
	GType xmpp_xep_direct_muc_invitations_module_type_id;
	xmpp_xep_direct_muc_invitations_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_MODULE, "XmppXepDirectMucInvitationsModule", &g_define_type_info, 0);
	return xmpp_xep_direct_muc_invitations_module_type_id;
}

GType
xmpp_xep_direct_muc_invitations_module_get_type (void)
{
	static volatile gsize xmpp_xep_direct_muc_invitations_module_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_direct_muc_invitations_module_type_id__once)) {
		GType xmpp_xep_direct_muc_invitations_module_type_id;
		xmpp_xep_direct_muc_invitations_module_type_id = xmpp_xep_direct_muc_invitations_module_get_type_once ();
		g_once_init_leave (&xmpp_xep_direct_muc_invitations_module_type_id__once, xmpp_xep_direct_muc_invitations_module_type_id);
	}
	return xmpp_xep_direct_muc_invitations_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;
}

