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

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

#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_STRING_FORMAT "{%s}:%s='%s'"
#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_STRING_NO_NS_FORMAT "%s='%s'"
#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_STRING_ANSI_FORMAT XMPP_STANZA_ENTRY_ANSI_COLOR_GRAY "{%s}:" XMPP_STANZA_ENTRY_ANSI_COLOR_END "%s=" XMPP_STANZA_ENTRY_ANSI_COLOR_GREEN "'%s'" XMPP_STANZA_ENTRY_ANSI_COLOR_END
#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT "%s=" XMPP_STANZA_ENTRY_ANSI_COLOR_GREEN "'%s'" XMPP_STANZA_ENTRY_ANSI_COLOR_END
#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_FORMAT "%s:%s='%s'"
#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_NO_NS_FORMAT "%s='%s'"
#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_ANSI_FORMAT "%s:%s=" XMPP_STANZA_ENTRY_ANSI_COLOR_GREEN "'%s'" XMPP_STANZA_ENTRY_ANSI_COLOR_END
#define XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_ANSI_NO_NS_FORMAT "%s=" XMPP_STANZA_ENTRY_ANSI_COLOR_GREEN "'%s'" XMPP_STANZA_ENTRY_ANSI_COLOR_END
#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 _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_namespace_state_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_namespace_state_unref (var), NULL)))

static gpointer xmpp_stanza_attribute_parent_class = NULL;

VALA_EXTERN XmppStanzaAttribute* xmpp_stanza_attribute_new (void);
VALA_EXTERN XmppStanzaAttribute* xmpp_stanza_attribute_construct (GType object_type);
VALA_EXTERN gchar* xmpp_stanza_attribute_printf (XmppStanzaAttribute* self,
                                     const gchar* fmt,
                                     gboolean no_ns,
                                     const gchar* ns_name);
static gchar* xmpp_stanza_attribute_real_to_string (XmppStanzaEntry* base,
                                             gint i);
static GType xmpp_stanza_attribute_get_type_once (void);

XmppStanzaAttribute*
xmpp_stanza_attribute_construct (GType object_type)
{
	XmppStanzaAttribute* self = NULL;
	self = (XmppStanzaAttribute*) xmpp_stanza_entry_construct (object_type);
	return self;
}

XmppStanzaAttribute*
xmpp_stanza_attribute_new (void)
{
	return xmpp_stanza_attribute_construct (XMPP_TYPE_STANZA_ATTRIBUTE);
}

XmppStanzaAttribute*
xmpp_stanza_attribute_construct_build (GType object_type,
                                       const gchar* ns_uri,
                                       const gchar* name,
                                       const gchar* val)
{
	XmppStanzaAttribute* self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (ns_uri != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (val != NULL, NULL);
	self = (XmppStanzaAttribute*) xmpp_stanza_entry_construct (object_type);
	_tmp0_ = g_strdup (ns_uri);
	_g_free0 (((XmppStanzaEntry*) self)->ns_uri);
	((XmppStanzaEntry*) self)->ns_uri = _tmp0_;
	_tmp1_ = g_strdup (name);
	_g_free0 (((XmppStanzaEntry*) self)->name);
	((XmppStanzaEntry*) self)->name = _tmp1_;
	_tmp2_ = g_strdup (val);
	_g_free0 (((XmppStanzaEntry*) self)->val);
	((XmppStanzaEntry*) self)->val = _tmp2_;
	return self;
}

XmppStanzaAttribute*
xmpp_stanza_attribute_new_build (const gchar* ns_uri,
                                 const gchar* name,
                                 const gchar* val)
{
	return xmpp_stanza_attribute_construct_build (XMPP_TYPE_STANZA_ATTRIBUTE, ns_uri, name, val);
}

gboolean
xmpp_stanza_attribute_equals (XmppStanzaAttribute* self,
                              XmppStanzaAttribute* other)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (other != NULL, FALSE);
	_tmp0_ = ((XmppStanzaEntry*) other)->ns_uri;
	_tmp1_ = ((XmppStanzaEntry*) self)->ns_uri;
	if (g_strcmp0 (_tmp0_, _tmp1_) != 0) {
		result = FALSE;
		return result;
	}
	_tmp2_ = ((XmppStanzaEntry*) other)->name;
	_tmp3_ = ((XmppStanzaEntry*) self)->name;
	if (g_strcmp0 (_tmp2_, _tmp3_) != 0) {
		result = FALSE;
		return result;
	}
	_tmp4_ = ((XmppStanzaEntry*) other)->val;
	_tmp5_ = ((XmppStanzaEntry*) self)->val;
	if (g_strcmp0 (_tmp4_, _tmp5_) != 0) {
		result = FALSE;
		return result;
	}
	result = TRUE;
	return result;
}

gchar*
xmpp_stanza_attribute_printf (XmppStanzaAttribute* self,
                              const gchar* fmt,
                              gboolean no_ns,
                              const gchar* ns_name)
{
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (fmt != NULL, NULL);
	if (no_ns) {
		const gchar* _tmp0_;
		gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp0_ = ((XmppStanzaEntry*) self)->name;
		_tmp1_ = xmpp_stanza_entry_get_encoded_val ((XmppStanzaEntry*) self);
		_tmp2_ = _tmp1_;
		_tmp3_ = (gchar*) _tmp2_;
		_tmp4_ = g_strdup_printf (fmt, _tmp0_, _tmp3_);
		_tmp5_ = _tmp4_;
		_g_free0 (_tmp3_);
		result = _tmp5_;
		return result;
	} else {
		if (ns_name == NULL) {
			const gchar* _tmp6_;
			const gchar* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			_tmp6_ = ((XmppStanzaEntry*) self)->ns_uri;
			_tmp7_ = ((XmppStanzaEntry*) self)->name;
			_tmp8_ = xmpp_stanza_entry_get_encoded_val ((XmppStanzaEntry*) self);
			_tmp9_ = _tmp8_;
			_tmp10_ = (gchar*) _tmp9_;
			_tmp11_ = g_strdup_printf (fmt, (const gchar*) _tmp6_, _tmp7_, _tmp10_);
			_tmp12_ = _tmp11_;
			_g_free0 (_tmp10_);
			result = _tmp12_;
			return result;
		} else {
			const gchar* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			gchar* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			_tmp13_ = ((XmppStanzaEntry*) self)->name;
			_tmp14_ = xmpp_stanza_entry_get_encoded_val ((XmppStanzaEntry*) self);
			_tmp15_ = _tmp14_;
			_tmp16_ = (gchar*) _tmp15_;
			_tmp17_ = g_strdup_printf (fmt, (const gchar*) ns_name, _tmp13_, _tmp16_);
			_tmp18_ = _tmp17_;
			_g_free0 (_tmp16_);
			result = _tmp18_;
			return result;
		}
	}
}

static gchar*
xmpp_stanza_attribute_real_to_string (XmppStanzaEntry* base,
                                      gint i)
{
	XmppStanzaAttribute * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppStanzaAttribute*) base;
	_tmp0_ = xmpp_stanza_attribute_printf (self, XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_STRING_FORMAT, FALSE, NULL);
	result = _tmp0_;
	return result;
}

gchar*
xmpp_stanza_attribute_to_ansi_string (XmppStanzaAttribute* self,
                                      gboolean hide_ns)
{
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (hide_ns) {
		gchar* _tmp0_;
		_tmp0_ = xmpp_stanza_attribute_printf (self, XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT, TRUE, NULL);
		result = _tmp0_;
		return result;
	} else {
		gchar* _tmp1_;
		_tmp1_ = xmpp_stanza_attribute_printf (self, XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_STRING_ANSI_FORMAT, FALSE, NULL);
		result = _tmp1_;
		return result;
	}
}

static gpointer
_xmpp_namespace_state_ref0 (gpointer self)
{
	return self ? xmpp_namespace_state_ref (self) : NULL;
}

gchar*
xmpp_stanza_attribute_to_xml (XmppStanzaAttribute* self,
                              XmppNamespaceState* state_)
{
	XmppNamespaceState* _tmp0_ = NULL;
	XmppNamespaceState* _tmp1_;
	XmppNamespaceState* state = NULL;
	XmppNamespaceState* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	XmppNamespaceState* _tmp6_;
	const gchar* _tmp7_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = _xmpp_namespace_state_ref0 (state_);
	_tmp0_ = _tmp1_;
	if (_tmp0_ == NULL) {
		XmppNamespaceState* _tmp2_;
		_tmp2_ = xmpp_namespace_state_new ();
		_xmpp_namespace_state_unref0 (_tmp0_);
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	state = _tmp3_;
	_tmp5_ = ((XmppStanzaEntry*) self)->ns_uri;
	_tmp6_ = state;
	_tmp7_ = _tmp6_->current_ns_uri;
	if (g_strcmp0 (_tmp5_, _tmp7_) == 0) {
		_tmp4_ = TRUE;
	} else {
		gboolean _tmp8_ = FALSE;
		const gchar* _tmp9_;
		_tmp9_ = ((XmppStanzaEntry*) self)->ns_uri;
		if (g_strcmp0 (_tmp9_, XMPP_XMLNS_URI) == 0) {
			const gchar* _tmp10_;
			_tmp10_ = ((XmppStanzaEntry*) self)->name;
			_tmp8_ = g_strcmp0 (_tmp10_, "xmlns") == 0;
		} else {
			_tmp8_ = FALSE;
		}
		_tmp4_ = _tmp8_;
	}
	if (_tmp4_) {
		gchar* _tmp11_;
		_tmp11_ = xmpp_stanza_attribute_printf (self, XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_NO_NS_FORMAT, TRUE, NULL);
		result = _tmp11_;
		_xmpp_namespace_state_unref0 (state);
		_xmpp_namespace_state_unref0 (_tmp0_);
		return result;
	} else {
		gchar* _tmp12_ = NULL;
		XmppNamespaceState* _tmp13_;
		const gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp13_ = state;
		_tmp14_ = ((XmppStanzaEntry*) self)->ns_uri;
		_tmp15_ = xmpp_namespace_state_find_name (_tmp13_, (const gchar*) _tmp14_, &_inner_error0_);
		_tmp12_ = _tmp15_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_xmpp_namespace_state_unref0 (state);
			_xmpp_namespace_state_unref0 (_tmp0_);
			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;
		}
		_tmp16_ = xmpp_stanza_attribute_printf (self, XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_FORMAT, FALSE, _tmp12_);
		result = _tmp16_;
		_g_free0 (_tmp12_);
		_xmpp_namespace_state_unref0 (state);
		_xmpp_namespace_state_unref0 (_tmp0_);
		return result;
	}
}

gchar*
xmpp_stanza_attribute_to_ansi_xml (XmppStanzaAttribute* self,
                                   XmppNamespaceState* state_)
{
	XmppNamespaceState* _tmp0_ = NULL;
	XmppNamespaceState* _tmp1_;
	XmppNamespaceState* state = NULL;
	XmppNamespaceState* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	XmppNamespaceState* _tmp6_;
	const gchar* _tmp7_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = _xmpp_namespace_state_ref0 (state_);
	_tmp0_ = _tmp1_;
	if (_tmp0_ == NULL) {
		XmppNamespaceState* _tmp2_;
		_tmp2_ = xmpp_namespace_state_new ();
		_xmpp_namespace_state_unref0 (_tmp0_);
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	state = _tmp3_;
	_tmp5_ = ((XmppStanzaEntry*) self)->ns_uri;
	_tmp6_ = state;
	_tmp7_ = _tmp6_->current_ns_uri;
	if (g_strcmp0 (_tmp5_, _tmp7_) == 0) {
		_tmp4_ = TRUE;
	} else {
		gboolean _tmp8_ = FALSE;
		const gchar* _tmp9_;
		_tmp9_ = ((XmppStanzaEntry*) self)->ns_uri;
		if (g_strcmp0 (_tmp9_, XMPP_XMLNS_URI) == 0) {
			const gchar* _tmp10_;
			_tmp10_ = ((XmppStanzaEntry*) self)->name;
			_tmp8_ = g_strcmp0 (_tmp10_, "xmlns") == 0;
		} else {
			_tmp8_ = FALSE;
		}
		_tmp4_ = _tmp8_;
	}
	if (_tmp4_) {
		gchar* _tmp11_;
		_tmp11_ = xmpp_stanza_attribute_printf (self, XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_ANSI_NO_NS_FORMAT, TRUE, NULL);
		result = _tmp11_;
		_xmpp_namespace_state_unref0 (state);
		_xmpp_namespace_state_unref0 (_tmp0_);
		return result;
	} else {
		gchar* _tmp12_ = NULL;
		XmppNamespaceState* _tmp13_;
		const gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp13_ = state;
		_tmp14_ = ((XmppStanzaEntry*) self)->ns_uri;
		_tmp15_ = xmpp_namespace_state_find_name (_tmp13_, (const gchar*) _tmp14_, &_inner_error0_);
		_tmp12_ = _tmp15_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_xmpp_namespace_state_unref0 (state);
			_xmpp_namespace_state_unref0 (_tmp0_);
			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;
		}
		_tmp16_ = xmpp_stanza_attribute_printf (self, XMPP_STANZA_ATTRIBUTE_ATTRIBUTE_XML_ANSI_FORMAT, FALSE, _tmp12_);
		result = _tmp16_;
		_g_free0 (_tmp12_);
		_xmpp_namespace_state_unref0 (state);
		_xmpp_namespace_state_unref0 (_tmp0_);
		return result;
	}
}

static void
xmpp_stanza_attribute_class_init (XmppStanzaAttributeClass * klass,
                                  gpointer klass_data)
{
	xmpp_stanza_attribute_parent_class = g_type_class_peek_parent (klass);
	((XmppStanzaEntryClass *) klass)->to_string = (gchar* (*) (XmppStanzaEntry*, gint)) xmpp_stanza_attribute_real_to_string;
}

static void
xmpp_stanza_attribute_instance_init (XmppStanzaAttribute * self,
                                     gpointer klass)
{
}

static GType
xmpp_stanza_attribute_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppStanzaAttributeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_stanza_attribute_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppStanzaAttribute), 0, (GInstanceInitFunc) xmpp_stanza_attribute_instance_init, NULL };
	GType xmpp_stanza_attribute_type_id;
	xmpp_stanza_attribute_type_id = g_type_register_static (XMPP_TYPE_STANZA_ENTRY, "XmppStanzaAttribute", &g_define_type_info, 0);
	return xmpp_stanza_attribute_type_id;
}

GType
xmpp_stanza_attribute_get_type (void)
{
	static volatile gsize xmpp_stanza_attribute_type_id__once = 0;
	if (g_once_init_enter (&xmpp_stanza_attribute_type_id__once)) {
		GType xmpp_stanza_attribute_type_id;
		xmpp_stanza_attribute_type_id = xmpp_stanza_attribute_get_type_once ();
		g_once_init_leave (&xmpp_stanza_attribute_type_id__once, xmpp_stanza_attribute_type_id);
	}
	return xmpp_stanza_attribute_type_id__once;
}

