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

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

#define XMPP_ROSTER_NS_URI "jabber:iq:roster"
#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)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _XmppRosterParamSpecItem XmppRosterParamSpecItem;

struct _XmppRosterItemPrivate {
	XmppJid* jid_;
};

struct _XmppRosterParamSpecItem {
	GParamSpec parent_instance;
};

static gint XmppRosterItem_private_offset;
static gpointer xmpp_roster_item_parent_class = NULL;

static void xmpp_roster_item_finalize (XmppRosterItem * obj);
static GType xmpp_roster_item_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
xmpp_roster_item_get_instance_private (XmppRosterItem* self)
{
	return G_STRUCT_MEMBER_P (self, XmppRosterItem_private_offset);
}

XmppRosterItem*
xmpp_roster_item_construct (GType object_type)
{
	XmppRosterItem* self = NULL;
	XmppStanzaNode* _tmp0_;
	self = (XmppRosterItem*) g_type_create_instance (object_type);
	_tmp0_ = xmpp_stanza_node_new_build ("item", XMPP_ROSTER_NS_URI, NULL, NULL);
	_xmpp_stanza_entry_unref0 (self->stanza_node);
	self->stanza_node = _tmp0_;
	return self;
}

XmppRosterItem*
xmpp_roster_item_new (void)
{
	return xmpp_roster_item_construct (XMPP_ROSTER_TYPE_ITEM);
}

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

XmppRosterItem*
xmpp_roster_item_construct_from_stanza_node (GType object_type,
                                             XmppStanzaNode* stanza_node)
{
	XmppRosterItem* self = NULL;
	XmppStanzaNode* _tmp0_;
	g_return_val_if_fail (stanza_node != NULL, NULL);
	self = (XmppRosterItem*) g_type_create_instance (object_type);
	_tmp0_ = _xmpp_stanza_entry_ref0 (stanza_node);
	_xmpp_stanza_entry_unref0 (self->stanza_node);
	self->stanza_node = _tmp0_;
	return self;
}

XmppRosterItem*
xmpp_roster_item_new_from_stanza_node (XmppStanzaNode* stanza_node)
{
	return xmpp_roster_item_construct_from_stanza_node (XMPP_ROSTER_TYPE_ITEM, stanza_node);
}

XmppJid*
xmpp_roster_item_get_jid (XmppRosterItem* self)
{
	XmppJid* result;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	{
		XmppJid* _tmp0_ = NULL;
		XmppJid* _tmp1_;
		_tmp1_ = self->priv->jid_;
		_tmp0_ = _tmp1_;
		if (_tmp0_ == NULL) {
			XmppJid* _tmp2_ = NULL;
			XmppStanzaNode* _tmp3_;
			const gchar* _tmp4_;
			XmppJid* _tmp5_;
			XmppJid* _tmp6_;
			XmppJid* _tmp7_;
			_tmp3_ = self->stanza_node;
			_tmp4_ = xmpp_stanza_node_get_attribute (_tmp3_, "jid", NULL);
			_tmp5_ = xmpp_jid_new (_tmp4_, &_inner_error0_);
			_tmp2_ = _tmp5_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
					goto __catch0_xmpp_invalid_jid_error;
				}
				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;
			}
			_tmp6_ = _tmp2_;
			_tmp2_ = NULL;
			_xmpp_jid_unref0 (self->priv->jid_);
			self->priv->jid_ = _tmp6_;
			_tmp7_ = self->priv->jid_;
			_tmp0_ = _tmp7_;
			_xmpp_jid_unref0 (_tmp2_);
		}
		result = _tmp0_;
		return result;
	}
	goto __finally0;
	__catch0_xmpp_invalid_jid_error:
	{
		GError* e = NULL;
		GError* _tmp8_;
		const gchar* _tmp9_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp8_ = e;
		_tmp9_ = _tmp8_->message;
		g_warning ("item.vala:23: Ignoring invalid Jid in roster entry: %s", _tmp9_);
		result = NULL;
		_g_error_free0 (e);
		return result;
	}
	__finally0:
	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;
}

void
xmpp_roster_item_set_jid (XmppRosterItem* self,
                          XmppJid* value)
{
	XmppStanzaNode* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->stanza_node;
	_tmp1_ = xmpp_jid_to_string (value);
	_tmp2_ = _tmp1_;
	xmpp_stanza_node_set_attribute (_tmp0_, "jid", _tmp2_, NULL);
	_g_free0 (_tmp2_);
}

const gchar*
xmpp_roster_item_get_name (XmppRosterItem* self)
{
	const gchar* result;
	XmppStanzaNode* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->stanza_node;
	_tmp1_ = xmpp_stanza_node_get_attribute (_tmp0_, "name", NULL);
	result = _tmp1_;
	return result;
}

void
xmpp_roster_item_set_name (XmppRosterItem* self,
                           const gchar* value)
{
	g_return_if_fail (self != NULL);
	if (value != NULL) {
		XmppStanzaNode* _tmp0_;
		_tmp0_ = self->stanza_node;
		xmpp_stanza_node_set_attribute (_tmp0_, "name", value, NULL);
	}
}

const gchar*
xmpp_roster_item_get_subscription (XmppRosterItem* self)
{
	const gchar* result;
	XmppStanzaNode* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->stanza_node;
	_tmp1_ = xmpp_stanza_node_get_attribute (_tmp0_, "subscription", NULL);
	result = _tmp1_;
	return result;
}

void
xmpp_roster_item_set_subscription (XmppRosterItem* self,
                                   const gchar* value)
{
	g_return_if_fail (self != NULL);
	if (value != NULL) {
		XmppStanzaNode* _tmp0_;
		_tmp0_ = self->stanza_node;
		xmpp_stanza_node_set_attribute (_tmp0_, "subscription", value, NULL);
	}
}

const gchar*
xmpp_roster_item_get_ask (XmppRosterItem* self)
{
	const gchar* result;
	XmppStanzaNode* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->stanza_node;
	_tmp1_ = xmpp_stanza_node_get_attribute (_tmp0_, "ask", NULL);
	result = _tmp1_;
	return result;
}

gboolean
xmpp_roster_item_get_subscription_requested (XmppRosterItem* self)
{
	gboolean result;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = xmpp_roster_item_get_ask (self);
	_tmp1_ = _tmp0_;
	result = _tmp1_ != NULL;
	return result;
}

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

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

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

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

static gchar*
xmpp_roster_value_item_collect_value (GValue* value,
                                      guint n_collect_values,
                                      GTypeCValue* collect_values,
                                      guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		XmppRosterItem * 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_roster_item_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
xmpp_roster_value_item_lcopy_value (const GValue* value,
                                    guint n_collect_values,
                                    GTypeCValue* collect_values,
                                    guint collect_flags)
{
	XmppRosterItem ** 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_roster_item_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
xmpp_roster_param_spec_item (const gchar* name,
                             const gchar* nick,
                             const gchar* blurb,
                             GType object_type,
                             GParamFlags flags)
{
	XmppRosterParamSpecItem* spec;
	g_return_val_if_fail (g_type_is_a (object_type, XMPP_ROSTER_TYPE_ITEM), 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_roster_value_get_item (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_ROSTER_TYPE_ITEM), NULL);
	return value->data[0].v_pointer;
}

void
xmpp_roster_value_set_item (GValue* value,
                            gpointer v_object)
{
	XmppRosterItem * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_ROSTER_TYPE_ITEM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_ROSTER_TYPE_ITEM));
		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_roster_item_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_roster_item_unref (old);
	}
}

void
xmpp_roster_value_take_item (GValue* value,
                             gpointer v_object)
{
	XmppRosterItem * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_ROSTER_TYPE_ITEM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_ROSTER_TYPE_ITEM));
		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_roster_item_unref (old);
	}
}

static void
xmpp_roster_item_class_init (XmppRosterItemClass * klass,
                             gpointer klass_data)
{
	xmpp_roster_item_parent_class = g_type_class_peek_parent (klass);
	((XmppRosterItemClass *) klass)->finalize = xmpp_roster_item_finalize;
	g_type_class_adjust_private_offset (klass, &XmppRosterItem_private_offset);
}

static void
xmpp_roster_item_instance_init (XmppRosterItem * self,
                                gpointer klass)
{
	self->priv = xmpp_roster_item_get_instance_private (self);
	self->ref_count = 1;
}

static void
xmpp_roster_item_finalize (XmppRosterItem * obj)
{
	XmppRosterItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_ROSTER_TYPE_ITEM, XmppRosterItem);
	g_signal_handlers_destroy (self);
	_xmpp_stanza_entry_unref0 (self->stanza_node);
	_xmpp_jid_unref0 (self->priv->jid_);
}

static GType
xmpp_roster_item_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { xmpp_roster_value_item_init, xmpp_roster_value_item_free_value, xmpp_roster_value_item_copy_value, xmpp_roster_value_item_peek_pointer, "p", xmpp_roster_value_item_collect_value, "p", xmpp_roster_value_item_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (XmppRosterItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_roster_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppRosterItem), 0, (GInstanceInitFunc) xmpp_roster_item_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_roster_item_type_id;
	xmpp_roster_item_type_id = g_type_register_fundamental (g_type_fundamental_next (), "XmppRosterItem", &g_define_type_info, &g_define_type_fundamental_info, 0);
	XmppRosterItem_private_offset = g_type_add_instance_private (xmpp_roster_item_type_id, sizeof (XmppRosterItemPrivate));
	return xmpp_roster_item_type_id;
}

GType
xmpp_roster_item_get_type (void)
{
	static volatile gsize xmpp_roster_item_type_id__once = 0;
	if (g_once_init_enter (&xmpp_roster_item_type_id__once)) {
		GType xmpp_roster_item_type_id;
		xmpp_roster_item_type_id = xmpp_roster_item_get_type_once ();
		g_once_init_leave (&xmpp_roster_item_type_id__once, xmpp_roster_item_type_id);
	}
	return xmpp_roster_item_type_id__once;
}

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

void
xmpp_roster_item_unref (gpointer instance)
{
	XmppRosterItem * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		XMPP_ROSTER_ITEM_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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

