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

#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.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_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _XmppXepRepliesParamSpecReplyTo XmppXepRepliesParamSpecReplyTo;
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))

struct _XmppXepRepliesReplyToPrivate {
	XmppJid* _to_jid;
	gchar* _to_message_id;
};

struct _XmppXepRepliesParamSpecReplyTo {
	GParamSpec parent_instance;
};

static gint XmppXepRepliesReplyTo_private_offset;
static gpointer xmpp_xep_replies_reply_to_parent_class = NULL;

static void xmpp_xep_replies_reply_to_finalize (XmppXepRepliesReplyTo * obj);
static GType xmpp_xep_replies_reply_to_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
xmpp_xep_replies_reply_to_get_instance_private (XmppXepRepliesReplyTo* self)
{
	return G_STRUCT_MEMBER_P (self, XmppXepRepliesReplyTo_private_offset);
}

XmppXepRepliesReplyTo*
xmpp_xep_replies_reply_to_construct (GType object_type,
                                     XmppJid* to_jid,
                                     const gchar* to_message_id)
{
	XmppXepRepliesReplyTo* self = NULL;
	g_return_val_if_fail (to_jid != NULL, NULL);
	g_return_val_if_fail (to_message_id != NULL, NULL);
	self = (XmppXepRepliesReplyTo*) g_type_create_instance (object_type);
	xmpp_xep_replies_reply_to_set_to_jid (self, to_jid);
	xmpp_xep_replies_reply_to_set_to_message_id (self, to_message_id);
	return self;
}

XmppXepRepliesReplyTo*
xmpp_xep_replies_reply_to_new (XmppJid* to_jid,
                               const gchar* to_message_id)
{
	return xmpp_xep_replies_reply_to_construct (XMPP_XEP_REPLIES_TYPE_REPLY_TO, to_jid, to_message_id);
}

XmppJid*
xmpp_xep_replies_reply_to_get_to_jid (XmppXepRepliesReplyTo* self)
{
	XmppJid* result;
	XmppJid* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_to_jid;
	result = _tmp0_;
	return result;
}

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

void
xmpp_xep_replies_reply_to_set_to_jid (XmppXepRepliesReplyTo* self,
                                      XmppJid* value)
{
	XmppJid* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _xmpp_jid_ref0 (value);
	_xmpp_jid_unref0 (self->priv->_to_jid);
	self->priv->_to_jid = _tmp0_;
}

const gchar*
xmpp_xep_replies_reply_to_get_to_message_id (XmppXepRepliesReplyTo* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_to_message_id;
	result = _tmp0_;
	return result;
}

void
xmpp_xep_replies_reply_to_set_to_message_id (XmppXepRepliesReplyTo* self,
                                             const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_to_message_id);
	self->priv->_to_message_id = _tmp0_;
}

static void
xmpp_xep_replies_value_reply_to_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
xmpp_xep_replies_value_reply_to_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		xmpp_xep_replies_reply_to_unref (value->data[0].v_pointer);
	}
}

static void
xmpp_xep_replies_value_reply_to_copy_value (const GValue* src_value,
                                            GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = xmpp_xep_replies_reply_to_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
xmpp_xep_replies_value_reply_to_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
xmpp_xep_replies_value_reply_to_collect_value (GValue* value,
                                               guint n_collect_values,
                                               GTypeCValue* collect_values,
                                               guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		XmppXepRepliesReplyTo * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = xmpp_xep_replies_reply_to_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
xmpp_xep_replies_value_reply_to_lcopy_value (const GValue* value,
                                             guint n_collect_values,
                                             GTypeCValue* collect_values,
                                             guint collect_flags)
{
	XmppXepRepliesReplyTo ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = xmpp_xep_replies_reply_to_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
xmpp_xep_replies_param_spec_reply_to (const gchar* name,
                                      const gchar* nick,
                                      const gchar* blurb,
                                      GType object_type,
                                      GParamFlags flags)
{
	XmppXepRepliesParamSpecReplyTo* spec;
	g_return_val_if_fail (g_type_is_a (object_type, XMPP_XEP_REPLIES_TYPE_REPLY_TO), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
xmpp_xep_replies_value_get_reply_to (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_REPLIES_TYPE_REPLY_TO), NULL);
	return value->data[0].v_pointer;
}

void
xmpp_xep_replies_value_set_reply_to (GValue* value,
                                     gpointer v_object)
{
	XmppXepRepliesReplyTo * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_REPLIES_TYPE_REPLY_TO));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_REPLIES_TYPE_REPLY_TO));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		xmpp_xep_replies_reply_to_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_replies_reply_to_unref (old);
	}
}

void
xmpp_xep_replies_value_take_reply_to (GValue* value,
                                      gpointer v_object)
{
	XmppXepRepliesReplyTo * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_REPLIES_TYPE_REPLY_TO));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_REPLIES_TYPE_REPLY_TO));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_replies_reply_to_unref (old);
	}
}

static void
xmpp_xep_replies_reply_to_class_init (XmppXepRepliesReplyToClass * klass,
                                      gpointer klass_data)
{
	xmpp_xep_replies_reply_to_parent_class = g_type_class_peek_parent (klass);
	((XmppXepRepliesReplyToClass *) klass)->finalize = xmpp_xep_replies_reply_to_finalize;
	g_type_class_adjust_private_offset (klass, &XmppXepRepliesReplyTo_private_offset);
}

static void
xmpp_xep_replies_reply_to_instance_init (XmppXepRepliesReplyTo * self,
                                         gpointer klass)
{
	self->priv = xmpp_xep_replies_reply_to_get_instance_private (self);
	self->ref_count = 1;
}

static void
xmpp_xep_replies_reply_to_finalize (XmppXepRepliesReplyTo * obj)
{
	XmppXepRepliesReplyTo * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_REPLIES_TYPE_REPLY_TO, XmppXepRepliesReplyTo);
	g_signal_handlers_destroy (self);
	_xmpp_jid_unref0 (self->priv->_to_jid);
	_g_free0 (self->priv->_to_message_id);
}

static GType
xmpp_xep_replies_reply_to_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { xmpp_xep_replies_value_reply_to_init, xmpp_xep_replies_value_reply_to_free_value, xmpp_xep_replies_value_reply_to_copy_value, xmpp_xep_replies_value_reply_to_peek_pointer, "p", xmpp_xep_replies_value_reply_to_collect_value, "p", xmpp_xep_replies_value_reply_to_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepRepliesReplyToClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_replies_reply_to_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepRepliesReplyTo), 0, (GInstanceInitFunc) xmpp_xep_replies_reply_to_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType xmpp_xep_replies_reply_to_type_id;
	xmpp_xep_replies_reply_to_type_id = g_type_register_fundamental (g_type_fundamental_next (), "XmppXepRepliesReplyTo", &g_define_type_info, &g_define_type_fundamental_info, 0);
	XmppXepRepliesReplyTo_private_offset = g_type_add_instance_private (xmpp_xep_replies_reply_to_type_id, sizeof (XmppXepRepliesReplyToPrivate));
	return xmpp_xep_replies_reply_to_type_id;
}

GType
xmpp_xep_replies_reply_to_get_type (void)
{
	static volatile gsize xmpp_xep_replies_reply_to_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_replies_reply_to_type_id__once)) {
		GType xmpp_xep_replies_reply_to_type_id;
		xmpp_xep_replies_reply_to_type_id = xmpp_xep_replies_reply_to_get_type_once ();
		g_once_init_leave (&xmpp_xep_replies_reply_to_type_id__once, xmpp_xep_replies_reply_to_type_id);
	}
	return xmpp_xep_replies_reply_to_type_id__once;
}

gpointer
xmpp_xep_replies_reply_to_ref (gpointer instance)
{
	XmppXepRepliesReplyTo * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
xmpp_xep_replies_reply_to_unref (gpointer instance)
{
	XmppXepRepliesReplyTo * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		XMPP_XEP_REPLIES_REPLY_TO_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

void
xmpp_xep_replies_set_reply_to (XmppMessageStanza* message,
                               XmppXepRepliesReplyTo* reply_to)
{
	XmppStanzaNode* reply_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	XmppStanzaNode* _tmp8_;
	XmppStanzaNode* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	XmppStanzaNode* _tmp12_;
	XmppStanzaNode* _tmp13_;
	XmppStanzaNode* _tmp14_;
	XmppStanzaNode* _tmp15_;
	XmppStanzaNode* _tmp16_;
	g_return_if_fail (message != NULL);
	g_return_if_fail (reply_to != NULL);
	_tmp0_ = xmpp_stanza_node_new_build ("reply", XMPP_XEP_REPLIES_NS_URI, NULL, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmpp_stanza_node_add_self_xmlns (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = xmpp_xep_replies_reply_to_get_to_jid (reply_to);
	_tmp5_ = _tmp4_;
	_tmp6_ = xmpp_jid_to_string (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = xmpp_stanza_node_put_attribute (_tmp3_, "to", _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	_tmp10_ = xmpp_xep_replies_reply_to_get_to_message_id (reply_to);
	_tmp11_ = _tmp10_;
	_tmp12_ = xmpp_stanza_node_put_attribute (_tmp9_, "id", _tmp11_, NULL);
	_tmp13_ = _tmp12_;
	_xmpp_stanza_entry_unref0 (_tmp9_);
	_g_free0 (_tmp7_);
	_xmpp_stanza_entry_unref0 (_tmp3_);
	_xmpp_stanza_entry_unref0 (_tmp1_);
	reply_node = _tmp13_;
	_tmp14_ = ((XmppStanza*) message)->stanza;
	_tmp15_ = xmpp_stanza_node_put_node (_tmp14_, reply_node);
	_tmp16_ = _tmp15_;
	_xmpp_stanza_entry_unref0 (_tmp16_);
	_xmpp_stanza_entry_unref0 (reply_node);
}

XmppXepRepliesReplyTo*
xmpp_xep_replies_get_reply_to (XmppMessageStanza* message)
{
	XmppStanzaNode* reply_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	gchar* to_str = NULL;
	XmppStanzaNode* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	GError* _inner_error0_ = NULL;
	XmppXepRepliesReplyTo* result;
	g_return_val_if_fail (message != NULL, NULL);
	_tmp0_ = ((XmppStanza*) message)->stanza;
	_tmp1_ = xmpp_stanza_node_get_subnode (_tmp0_, "reply", XMPP_XEP_REPLIES_NS_URI, FALSE);
	reply_node = _tmp1_;
	_tmp2_ = reply_node;
	if (_tmp2_ == NULL) {
		result = NULL;
		_xmpp_stanza_entry_unref0 (reply_node);
		return result;
	}
	_tmp3_ = reply_node;
	_tmp4_ = xmpp_stanza_node_get_attribute (_tmp3_, "to", NULL);
	_tmp5_ = g_strdup (_tmp4_);
	to_str = _tmp5_;
	_tmp6_ = to_str;
	if (_tmp6_ == NULL) {
		result = NULL;
		_g_free0 (to_str);
		_xmpp_stanza_entry_unref0 (reply_node);
		return result;
	}
	{
		XmppJid* to_jid = NULL;
		const gchar* _tmp7_;
		XmppJid* _tmp8_;
		gchar* id = NULL;
		XmppStanzaNode* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		const gchar* _tmp12_;
		XmppJid* _tmp13_;
		const gchar* _tmp14_;
		XmppXepRepliesReplyTo* _tmp15_;
		_tmp7_ = to_str;
		_tmp8_ = xmpp_jid_new (_tmp7_, &_inner_error0_);
		to_jid = _tmp8_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
				goto __catch0_xmpp_invalid_jid_error;
			}
			_g_free0 (to_str);
			_xmpp_stanza_entry_unref0 (reply_node);
			g_critical ("file %s: line %d: unexpected 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 NULL;
		}
		_tmp9_ = reply_node;
		_tmp10_ = xmpp_stanza_node_get_attribute (_tmp9_, "id", NULL);
		_tmp11_ = g_strdup (_tmp10_);
		id = _tmp11_;
		_tmp12_ = id;
		if (_tmp12_ == NULL) {
			result = NULL;
			_g_free0 (id);
			_xmpp_jid_unref0 (to_jid);
			_g_free0 (to_str);
			_xmpp_stanza_entry_unref0 (reply_node);
			return result;
		}
		_tmp13_ = to_jid;
		_tmp14_ = id;
		_tmp15_ = xmpp_xep_replies_reply_to_new (_tmp13_, _tmp14_);
		result = _tmp15_;
		_g_free0 (id);
		_xmpp_jid_unref0 (to_jid);
		_g_free0 (to_str);
		_xmpp_stanza_entry_unref0 (reply_node);
		return result;
	}
	goto __finally0;
	__catch0_xmpp_invalid_jid_error:
	{
		g_clear_error (&_inner_error0_);
		result = NULL;
		_g_free0 (to_str);
		_xmpp_stanza_entry_unref0 (reply_node);
		return result;
	}
	__finally0:
	_g_free0 (to_str);
	_xmpp_stanza_entry_unref0 (reply_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 NULL;
	result = NULL;
	_g_free0 (to_str);
	_xmpp_stanza_entry_unref0 (reply_node);
	return result;
}

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

