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

#include "xmpp-vala.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.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

enum  {
	XMPP_MESSAGE_STANZA_0_PROPERTY,
	XMPP_MESSAGE_STANZA_BODY_PROPERTY,
	XMPP_MESSAGE_STANZA_TYPE__PROPERTY,
	XMPP_MESSAGE_STANZA_NUM_PROPERTIES
};
static GParamSpec* xmpp_message_stanza_properties[XMPP_MESSAGE_STANZA_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	XMPP_MESSAGE_FLAG_0_PROPERTY,
	XMPP_MESSAGE_FLAG_NUM_PROPERTIES
};
static GParamSpec* xmpp_message_flag_properties[XMPP_MESSAGE_FLAG_NUM_PROPERTIES];

struct _XmppMessageStanzaPrivate {
	GeeArrayList* flags;
};

static gint XmppMessageStanza_private_offset;
static gpointer xmpp_message_stanza_parent_class = NULL;
static gpointer xmpp_message_flag_parent_class = NULL;

static void xmpp_message_stanza_finalize (GObject * obj);
static GType xmpp_message_stanza_get_type_once (void);
static void _vala_xmpp_message_stanza_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_xmpp_message_stanza_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec);
static gchar* xmpp_message_flag_real_get_ns (XmppMessageFlag* self);
static gchar* xmpp_message_flag_real_get_id (XmppMessageFlag* self);
static GType xmpp_message_flag_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
xmpp_message_stanza_get_instance_private (XmppMessageStanza* self)
{
	return G_STRUCT_MEMBER_P (self, XmppMessageStanza_private_offset);
}

XmppMessageStanza*
xmpp_message_stanza_construct (GType object_type,
                               const gchar* id)
{
	XmppMessageStanza * self = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_;
	XmppStanzaNode* _tmp5_;
	_tmp0_ = xmpp_stanza_node_new_build ("message", "jabber:client", NULL, NULL);
	_tmp1_ = _tmp0_;
	self = (XmppMessageStanza*) xmpp_stanza_construct_outgoing (object_type, _tmp1_);
	_xmpp_stanza_entry_unref0 (_tmp1_);
	_tmp3_ = g_strdup (id);
	_tmp2_ = _tmp3_;
	if (_tmp2_ == NULL) {
		gchar* _tmp4_;
		_tmp4_ = xmpp_random_uuid ();
		_g_free0 (_tmp2_);
		_tmp2_ = _tmp4_;
	}
	_tmp5_ = ((XmppStanza*) self)->stanza;
	xmpp_stanza_node_set_attribute (_tmp5_, XMPP_STANZA_ATTRIBUTE_ID, _tmp2_, NULL);
	_g_free0 (_tmp2_);
	return self;
}

XmppMessageStanza*
xmpp_message_stanza_new (const gchar* id)
{
	return xmpp_message_stanza_construct (XMPP_TYPE_MESSAGE_STANZA, id);
}

XmppMessageStanza*
xmpp_message_stanza_construct_from_stanza (GType object_type,
                                           XmppStanzaNode* stanza_node,
                                           XmppJid* my_jid)
{
	XmppMessageStanza * self = NULL;
	g_return_val_if_fail (stanza_node != NULL, NULL);
	g_return_val_if_fail (my_jid != NULL, NULL);
	self = (XmppMessageStanza*) xmpp_stanza_construct_incoming (object_type, stanza_node, my_jid);
	return self;
}

XmppMessageStanza*
xmpp_message_stanza_new_from_stanza (XmppStanzaNode* stanza_node,
                                     XmppJid* my_jid)
{
	return xmpp_message_stanza_construct_from_stanza (XMPP_TYPE_MESSAGE_STANZA, stanza_node, my_jid);
}

void
xmpp_message_stanza_add_flag (XmppMessageStanza* self,
                              XmppMessageFlag* flag)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (flag != NULL);
	_tmp0_ = self->priv->flags;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, flag);
}

XmppMessageFlag*
xmpp_message_stanza_get_flag (XmppMessageStanza* self,
                              const gchar* ns,
                              const gchar* id)
{
	XmppMessageFlag* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (ns != NULL, NULL);
	g_return_val_if_fail (id != NULL, NULL);
	{
		GeeArrayList* _flag_list = NULL;
		GeeArrayList* _tmp0_;
		gint _flag_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _flag_index = 0;
		_tmp0_ = self->priv->flags;
		_flag_list = _tmp0_;
		_tmp1_ = _flag_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_flag_size = _tmp3_;
		_flag_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			XmppMessageFlag* flag = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			XmppMessageFlag* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			gboolean _tmp12_;
			_flag_index = _flag_index + 1;
			_tmp4_ = _flag_index;
			_tmp5_ = _flag_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _flag_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _flag_index);
			flag = (XmppMessageFlag*) _tmp7_;
			_tmp9_ = flag;
			_tmp10_ = xmpp_message_flag_get_ns (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = g_strcmp0 (_tmp11_, ns) == 0;
			_g_free0 (_tmp11_);
			if (_tmp12_) {
				XmppMessageFlag* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				_tmp13_ = flag;
				_tmp14_ = xmpp_message_flag_get_id (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp8_ = g_strcmp0 (_tmp15_, id) == 0;
				_g_free0 (_tmp15_);
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				result = flag;
				return result;
			}
			_g_object_unref0 (flag);
		}
	}
	result = NULL;
	return result;
}

const gchar*
xmpp_message_stanza_get_body (XmppMessageStanza* self)
{
	const gchar* result;
	XmppStanzaNode* body_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	const gchar* _tmp2_ = NULL;
	XmppStanzaNode* _tmp3_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = ((XmppStanza*) self)->stanza;
	_tmp1_ = xmpp_stanza_node_get_subnode (_tmp0_, XMPP_MESSAGE_STANZA_NODE_BODY, NULL, FALSE);
	body_node = _tmp1_;
	_tmp3_ = body_node;
	if (_tmp3_ == NULL) {
		_tmp2_ = NULL;
	} else {
		XmppStanzaNode* _tmp4_;
		const gchar* _tmp5_;
		_tmp4_ = body_node;
		_tmp5_ = xmpp_stanza_entry_get_string_content ((XmppStanzaEntry*) _tmp4_);
		_tmp2_ = _tmp5_;
	}
	result = _tmp2_;
	_xmpp_stanza_entry_unref0 (body_node);
	return result;
}

void
xmpp_message_stanza_set_body (XmppMessageStanza* self,
                              const gchar* value)
{
	XmppStanzaNode* body_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp6_;
	XmppStanzaNode* _tmp12_;
	GeeList* _tmp13_;
	XmppStanzaNode* _tmp14_;
	XmppStanzaNode* _tmp15_;
	XmppStanzaNode* _tmp16_;
	XmppStanzaNode* _tmp17_;
	XmppStanzaNode* _tmp18_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ((XmppStanza*) self)->stanza;
	_tmp1_ = xmpp_stanza_node_get_subnode (_tmp0_, XMPP_MESSAGE_STANZA_NODE_BODY, NULL, FALSE);
	body_node = _tmp1_;
	if (value == NULL) {
		XmppStanzaNode* _tmp2_;
		_tmp2_ = body_node;
		if (_tmp2_ != NULL) {
			XmppStanzaNode* _tmp3_;
			GeeList* _tmp4_;
			XmppStanzaNode* _tmp5_;
			_tmp3_ = ((XmppStanza*) self)->stanza;
			_tmp4_ = _tmp3_->sub_nodes;
			_tmp5_ = body_node;
			gee_collection_remove ((GeeCollection*) _tmp4_, _tmp5_);
		}
		_xmpp_stanza_entry_unref0 (body_node);
		return;
	}
	_tmp6_ = body_node;
	if (_tmp6_ == NULL) {
		XmppStanzaNode* _tmp7_;
		XmppStanzaNode* _tmp8_;
		XmppStanzaNode* _tmp9_;
		XmppStanzaNode* _tmp10_;
		XmppStanzaNode* _tmp11_;
		_tmp7_ = xmpp_stanza_node_new_build (XMPP_MESSAGE_STANZA_NODE_BODY, "jabber:client", NULL, NULL);
		_xmpp_stanza_entry_unref0 (body_node);
		body_node = _tmp7_;
		_tmp8_ = ((XmppStanza*) self)->stanza;
		_tmp9_ = body_node;
		_tmp10_ = xmpp_stanza_node_put_node (_tmp8_, _tmp9_);
		_tmp11_ = _tmp10_;
		_xmpp_stanza_entry_unref0 (_tmp11_);
	}
	_tmp12_ = body_node;
	_tmp13_ = _tmp12_->sub_nodes;
	gee_collection_clear ((GeeCollection*) _tmp13_);
	_tmp14_ = body_node;
	_tmp15_ = xmpp_stanza_node_new_text (value);
	_tmp16_ = _tmp15_;
	_tmp17_ = xmpp_stanza_node_put_node (_tmp14_, _tmp16_);
	_tmp18_ = _tmp17_;
	_xmpp_stanza_entry_unref0 (_tmp18_);
	_xmpp_stanza_entry_unref0 (_tmp16_);
	_xmpp_stanza_entry_unref0 (body_node);
	g_object_notify_by_pspec ((GObject *) self, xmpp_message_stanza_properties[XMPP_MESSAGE_STANZA_BODY_PROPERTY]);
}

static const gchar*
xmpp_message_stanza_real_get_type_ (XmppStanza* base)
{
	const gchar* result;
	XmppMessageStanza* self;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	self = (XmppMessageStanza*) base;
	_tmp1_ = XMPP_STANZA_CLASS (xmpp_message_stanza_parent_class)->get_type_ (G_TYPE_CHECK_INSTANCE_CAST (self, XMPP_TYPE_STANZA, XmppStanza));
	_tmp0_ = _tmp1_;
	if (_tmp0_ == NULL) {
		_tmp0_ = XMPP_MESSAGE_STANZA_TYPE_NORMAL;
	}
	result = _tmp0_;
	return result;
}

static void
xmpp_message_stanza_real_set_type_ (XmppStanza* base,
                                    const gchar* value)
{
	XmppMessageStanza* self;
	self = (XmppMessageStanza*) base;
	XMPP_STANZA_CLASS (xmpp_message_stanza_parent_class)->set_type_ (G_TYPE_CHECK_INSTANCE_CAST (self, XMPP_TYPE_STANZA, XmppStanza), value);
	g_object_notify_by_pspec ((GObject *) self, xmpp_message_stanza_properties[XMPP_MESSAGE_STANZA_TYPE__PROPERTY]);
}

static void
xmpp_message_stanza_class_init (XmppMessageStanzaClass * klass,
                                gpointer klass_data)
{
	xmpp_message_stanza_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppMessageStanza_private_offset);
	XMPP_STANZA_CLASS (klass)->get_type_ = (const gchar* (*) (XmppStanza*)) xmpp_message_stanza_real_get_type_;
	XMPP_STANZA_CLASS (klass)->set_type_ = (void (*) (XmppStanza*, const gchar*)) xmpp_message_stanza_real_set_type_;
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_message_stanza_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_xmpp_message_stanza_set_property;
	G_OBJECT_CLASS (klass)->finalize = xmpp_message_stanza_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_MESSAGE_STANZA_BODY_PROPERTY, xmpp_message_stanza_properties[XMPP_MESSAGE_STANZA_BODY_PROPERTY] = g_param_spec_string ("body", "body", "body", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_MESSAGE_STANZA_TYPE__PROPERTY, xmpp_message_stanza_properties[XMPP_MESSAGE_STANZA_TYPE__PROPERTY] = g_param_spec_string ("type-", "type-", "type-", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
xmpp_message_stanza_instance_init (XmppMessageStanza * self,
                                   gpointer klass)
{
	GeeArrayList* _tmp0_;
	self->priv = xmpp_message_stanza_get_instance_private (self);
	self->rerun_parsing = FALSE;
	_tmp0_ = gee_array_list_new (XMPP_TYPE_MESSAGE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->flags = _tmp0_;
}

static void
xmpp_message_stanza_finalize (GObject * obj)
{
	XmppMessageStanza * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_TYPE_MESSAGE_STANZA, XmppMessageStanza);
	_g_object_unref0 (self->priv->flags);
	G_OBJECT_CLASS (xmpp_message_stanza_parent_class)->finalize (obj);
}

static GType
xmpp_message_stanza_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppMessageStanzaClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_message_stanza_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppMessageStanza), 0, (GInstanceInitFunc) xmpp_message_stanza_instance_init, NULL };
	GType xmpp_message_stanza_type_id;
	xmpp_message_stanza_type_id = g_type_register_static (XMPP_TYPE_STANZA, "XmppMessageStanza", &g_define_type_info, 0);
	XmppMessageStanza_private_offset = g_type_add_instance_private (xmpp_message_stanza_type_id, sizeof (XmppMessageStanzaPrivate));
	return xmpp_message_stanza_type_id;
}

GType
xmpp_message_stanza_get_type (void)
{
	static volatile gsize xmpp_message_stanza_type_id__once = 0;
	if (g_once_init_enter (&xmpp_message_stanza_type_id__once)) {
		GType xmpp_message_stanza_type_id;
		xmpp_message_stanza_type_id = xmpp_message_stanza_get_type_once ();
		g_once_init_leave (&xmpp_message_stanza_type_id__once, xmpp_message_stanza_type_id);
	}
	return xmpp_message_stanza_type_id__once;
}

static void
_vala_xmpp_message_stanza_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	XmppMessageStanza * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_TYPE_MESSAGE_STANZA, XmppMessageStanza);
	switch (property_id) {
		case XMPP_MESSAGE_STANZA_BODY_PROPERTY:
		g_value_set_string (value, xmpp_message_stanza_get_body (self));
		break;
		case XMPP_MESSAGE_STANZA_TYPE__PROPERTY:
		g_value_set_string (value, xmpp_stanza_get_type_ ((XmppStanza*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_xmpp_message_stanza_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	XmppMessageStanza * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_TYPE_MESSAGE_STANZA, XmppMessageStanza);
	switch (property_id) {
		case XMPP_MESSAGE_STANZA_BODY_PROPERTY:
		xmpp_message_stanza_set_body (self, g_value_get_string (value));
		break;
		case XMPP_MESSAGE_STANZA_TYPE__PROPERTY:
		xmpp_stanza_set_type_ ((XmppStanza*) self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static gchar*
xmpp_message_flag_real_get_ns (XmppMessageFlag* self)
{
	g_critical ("Type `%s' does not implement abstract method `xmpp_message_flag_get_ns'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

gchar*
xmpp_message_flag_get_ns (XmppMessageFlag* self)
{
	XmppMessageFlagClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = XMPP_MESSAGE_FLAG_GET_CLASS (self);
	if (_klass_->get_ns) {
		return _klass_->get_ns (self);
	}
	return NULL;
}

static gchar*
xmpp_message_flag_real_get_id (XmppMessageFlag* self)
{
	g_critical ("Type `%s' does not implement abstract method `xmpp_message_flag_get_id'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

gchar*
xmpp_message_flag_get_id (XmppMessageFlag* self)
{
	XmppMessageFlagClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = XMPP_MESSAGE_FLAG_GET_CLASS (self);
	if (_klass_->get_id) {
		return _klass_->get_id (self);
	}
	return NULL;
}

XmppMessageFlag*
xmpp_message_flag_construct (GType object_type)
{
	XmppMessageFlag * self = NULL;
	self = (XmppMessageFlag*) g_object_new (object_type, NULL);
	return self;
}

static void
xmpp_message_flag_class_init (XmppMessageFlagClass * klass,
                              gpointer klass_data)
{
	xmpp_message_flag_parent_class = g_type_class_peek_parent (klass);
	((XmppMessageFlagClass *) klass)->get_ns = (gchar* (*) (XmppMessageFlag*)) xmpp_message_flag_real_get_ns;
	((XmppMessageFlagClass *) klass)->get_id = (gchar* (*) (XmppMessageFlag*)) xmpp_message_flag_real_get_id;
}

static void
xmpp_message_flag_instance_init (XmppMessageFlag * self,
                                 gpointer klass)
{
}

static GType
xmpp_message_flag_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppMessageFlagClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_message_flag_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppMessageFlag), 0, (GInstanceInitFunc) xmpp_message_flag_instance_init, NULL };
	GType xmpp_message_flag_type_id;
	xmpp_message_flag_type_id = g_type_register_static (G_TYPE_OBJECT, "XmppMessageFlag", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	return xmpp_message_flag_type_id;
}

GType
xmpp_message_flag_get_type (void)
{
	static volatile gsize xmpp_message_flag_type_id__once = 0;
	if (g_once_init_enter (&xmpp_message_flag_type_id__once)) {
		GType xmpp_message_flag_type_id;
		xmpp_message_flag_type_id = xmpp_message_flag_get_type_once ();
		g_once_init_leave (&xmpp_message_flag_type_id__once, xmpp_message_flag_type_id);
	}
	return xmpp_message_flag_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;
}

