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

#include "xmpp-vala.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

#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))

static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

void
xmpp_xep_explicit_encryption_add_encryption_tag_to_message (XmppMessageStanza* message,
                                                            const gchar* ns,
                                                            const gchar* name)
{
	XmppStanzaNode* encryption = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppStanzaNode* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppStanzaNode* _tmp9_;
	XmppStanzaNode* _tmp10_;
	XmppStanzaNode* _tmp11_;
	XmppStanzaNode* _tmp12_;
	g_return_if_fail (message != NULL);
	g_return_if_fail (ns != NULL);
	_tmp0_ = xmpp_stanza_node_new_build ("encryption", XMPP_XEP_EXPLICIT_ENCRYPTION_NS_URI, NULL, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmpp_stanza_node_add_self_xmlns (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = xmpp_stanza_node_put_attribute (_tmp3_, "namespace", ns, NULL);
	_tmp5_ = _tmp4_;
	_xmpp_stanza_entry_unref0 (_tmp3_);
	_xmpp_stanza_entry_unref0 (_tmp1_);
	encryption = _tmp5_;
	if (name != NULL) {
		XmppStanzaNode* _tmp6_;
		XmppStanzaNode* _tmp7_;
		XmppStanzaNode* _tmp8_;
		_tmp6_ = encryption;
		_tmp7_ = xmpp_stanza_node_put_attribute (_tmp6_, "name", name, NULL);
		_tmp8_ = _tmp7_;
		_xmpp_stanza_entry_unref0 (_tmp8_);
	}
	_tmp9_ = ((XmppStanza*) message)->stanza;
	_tmp10_ = encryption;
	_tmp11_ = xmpp_stanza_node_put_node (_tmp9_, _tmp10_);
	_tmp12_ = _tmp11_;
	_xmpp_stanza_entry_unref0 (_tmp12_);
	_xmpp_stanza_entry_unref0 (encryption);
}

gchar*
xmpp_xep_explicit_encryption_get_encryption_tag (XmppMessageStanza* message)
{
	XmppStanzaNode* encryption_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	gchar* result;
	g_return_val_if_fail (message != NULL, NULL);
	_tmp0_ = ((XmppStanza*) message)->stanza;
	_tmp1_ = xmpp_stanza_node_get_subnode (_tmp0_, "encryption", XMPP_XEP_EXPLICIT_ENCRYPTION_NS_URI, FALSE);
	encryption_node = _tmp1_;
	_tmp2_ = encryption_node;
	if (_tmp2_ != NULL) {
		XmppStanzaNode* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp3_ = encryption_node;
		_tmp4_ = xmpp_stanza_node_get_attribute (_tmp3_, "namespace", XMPP_XEP_EXPLICIT_ENCRYPTION_NS_URI);
		_tmp5_ = g_strdup (_tmp4_);
		result = _tmp5_;
		_xmpp_stanza_entry_unref0 (encryption_node);
		return result;
	}
	result = NULL;
	_xmpp_stanza_entry_unref0 (encryption_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;
}

