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

#include "xmpp-vala.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <glib-object.h>
#include <gio/gio.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 _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	XMPP_XEP_DELAYED_DELIVERY_MODULE_0_PROPERTY,
	XMPP_XEP_DELAYED_DELIVERY_MODULE_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_delayed_delivery_module_properties[XMPP_XEP_DELAYED_DELIVERY_MODULE_NUM_PROPERTIES];
enum  {
	XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_0_PROPERTY,
	XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_ACTION_GROUP_PROPERTY,
	XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_AFTER_ACTIONS_PROPERTY,
	XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_delayed_delivery_received_pipeline_listener_properties[XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_NUM_PROPERTIES];
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _XmppXepDelayedDeliveryReceivedPipelineListenerRunData XmppXepDelayedDeliveryReceivedPipelineListenerRunData;
enum  {
	XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_0_PROPERTY,
	XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_DATETIME_PROPERTY,
	XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_delayed_delivery_message_flag_properties[XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_NUM_PROPERTIES];

struct _XmppXepDelayedDeliveryModulePrivate {
	XmppXepDelayedDeliveryReceivedPipelineListener* received_pipeline_listener;
};

struct _XmppXepDelayedDeliveryReceivedPipelineListenerPrivate {
	gchar** after_actions_const;
	gint after_actions_const_length1;
	gint _after_actions_const_size_;
};

struct _XmppXepDelayedDeliveryReceivedPipelineListenerRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXepDelayedDeliveryReceivedPipelineListener* self;
	XmppXmppStream* stream;
	XmppMessageStanza* message;
	gboolean result;
	GDateTime* datetime;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	XmppXepDelayedDeliveryMessageFlag* _tmp3_;
	XmppXepDelayedDeliveryMessageFlag* _tmp4_;
};

struct _XmppXepDelayedDeliveryMessageFlagPrivate {
	GDateTime* _datetime;
};

static gint XmppXepDelayedDeliveryModule_private_offset;
static gpointer xmpp_xep_delayed_delivery_module_parent_class = NULL;
XmppModuleIdentity* xmpp_xep_delayed_delivery_module_IDENTITY = NULL;
static gint XmppXepDelayedDeliveryReceivedPipelineListener_private_offset;
static gpointer xmpp_xep_delayed_delivery_received_pipeline_listener_parent_class = NULL;
static gint XmppXepDelayedDeliveryMessageFlag_private_offset;
static gpointer xmpp_xep_delayed_delivery_message_flag_parent_class = NULL;

static void xmpp_xep_delayed_delivery_module_real_attach (XmppXmppStreamModule* base,
                                                   XmppXmppStream* stream);
static void xmpp_xep_delayed_delivery_module_real_detach (XmppXmppStreamModule* base,
                                                   XmppXmppStream* stream);
static gchar* xmpp_xep_delayed_delivery_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_xep_delayed_delivery_module_real_get_id (XmppXmppStreamModule* base);
static void xmpp_xep_delayed_delivery_module_finalize (GObject * obj);
static GType xmpp_xep_delayed_delivery_module_get_type_once (void);
static void xmpp_xep_delayed_delivery_received_pipeline_listener_real_run_data_free (gpointer _data);
static void xmpp_xep_delayed_delivery_received_pipeline_listener_real_run (XmppStanzaListener* base,
                                                                    XmppXmppStream* stream,
                                                                    XmppMessageStanza* message,
                                                                    GAsyncReadyCallback _callback_,
                                                                    gpointer _user_data_);
static gboolean xmpp_xep_delayed_delivery_received_pipeline_listener_real_run_co (XmppXepDelayedDeliveryReceivedPipelineListenerRunData* _data_);
static void xmpp_xep_delayed_delivery_received_pipeline_listener_finalize (GObject * obj);
static GType xmpp_xep_delayed_delivery_received_pipeline_listener_get_type_once (void);
static void _vala_xmpp_xep_delayed_delivery_received_pipeline_listener_get_property (GObject * object,
                                                                              guint property_id,
                                                                              GValue * value,
                                                                              GParamSpec * pspec);
static void xmpp_xep_delayed_delivery_message_flag_set_datetime (XmppXepDelayedDeliveryMessageFlag* self,
                                                          GDateTime* value);
static gchar* xmpp_xep_delayed_delivery_message_flag_real_get_ns (XmppMessageFlag* base);
static gchar* xmpp_xep_delayed_delivery_message_flag_real_get_id (XmppMessageFlag* base);
static void xmpp_xep_delayed_delivery_message_flag_finalize (GObject * obj);
static GType xmpp_xep_delayed_delivery_message_flag_get_type_once (void);
static void _vala_xmpp_xep_delayed_delivery_message_flag_get_property (GObject * object,
                                                                guint property_id,
                                                                GValue * value,
                                                                GParamSpec * pspec);
static void _vala_xmpp_xep_delayed_delivery_message_flag_set_property (GObject * object,
                                                                guint property_id,
                                                                const GValue * value,
                                                                GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

GDateTime*
xmpp_xep_delayed_delivery_get_time_for_node (XmppStanzaNode* node)
{
	gchar* time = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	GDateTime* result;
	g_return_val_if_fail (node != NULL, NULL);
	_tmp0_ = xmpp_stanza_node_get_attribute (node, "stamp", NULL);
	_tmp1_ = g_strdup (_tmp0_);
	time = _tmp1_;
	_tmp2_ = time;
	if (_tmp2_ != NULL) {
		const gchar* _tmp3_;
		GDateTime* _tmp4_;
		_tmp3_ = time;
		_tmp4_ = xmpp_xep_date_time_profiles_parse_string (_tmp3_);
		result = _tmp4_;
		_g_free0 (time);
		return result;
	}
	result = NULL;
	_g_free0 (time);
	return result;
}

GDateTime*
xmpp_xep_delayed_delivery_get_time_for_message (XmppMessageStanza* message,
                                                XmppJid* jid)
{
	GDateTime* result;
	g_return_val_if_fail (message != NULL, NULL);
	{
		GeeList* _delay_node_list = NULL;
		XmppStanzaNode* _tmp0_;
		GeeList* _tmp1_;
		gint _delay_node_size = 0;
		GeeList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _delay_node_index = 0;
		_tmp0_ = ((XmppStanza*) message)->stanza;
		_tmp1_ = xmpp_stanza_node_get_subnodes (_tmp0_, "delay", XMPP_XEP_DELAYED_DELIVERY_NS_URI, FALSE);
		_delay_node_list = _tmp1_;
		_tmp2_ = _delay_node_list;
		_tmp3_ = gee_collection_get_size ((GeeCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_delay_node_size = _tmp4_;
		_delay_node_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			XmppStanzaNode* delay_node = NULL;
			GeeList* _tmp7_;
			gpointer _tmp8_;
			gboolean _tmp9_ = FALSE;
			_delay_node_index = _delay_node_index + 1;
			_tmp5_ = _delay_node_index;
			_tmp6_ = _delay_node_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _delay_node_list;
			_tmp8_ = gee_list_get (_tmp7_, _delay_node_index);
			delay_node = (XmppStanzaNode*) _tmp8_;
			if (jid == NULL) {
				_tmp9_ = TRUE;
			} else {
				XmppStanzaNode* _tmp10_;
				const gchar* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				_tmp10_ = delay_node;
				_tmp11_ = xmpp_stanza_node_get_attribute (_tmp10_, "from", NULL);
				_tmp12_ = xmpp_jid_to_string (jid);
				_tmp13_ = _tmp12_;
				_tmp9_ = g_strcmp0 (_tmp11_, _tmp13_) == 0;
				_g_free0 (_tmp13_);
			}
			if (_tmp9_) {
				XmppStanzaNode* _tmp14_;
				GDateTime* _tmp15_;
				_tmp14_ = delay_node;
				_tmp15_ = xmpp_xep_delayed_delivery_get_time_for_node (_tmp14_);
				result = _tmp15_;
				_xmpp_stanza_entry_unref0 (delay_node);
				_g_object_unref0 (_delay_node_list);
				return result;
			}
			_xmpp_stanza_entry_unref0 (delay_node);
		}
		_g_object_unref0 (_delay_node_list);
	}
	result = NULL;
	return result;
}

static inline gpointer
xmpp_xep_delayed_delivery_module_get_instance_private (XmppXepDelayedDeliveryModule* self)
{
	return G_STRUCT_MEMBER_P (self, XmppXepDelayedDeliveryModule_private_offset);
}

void
xmpp_xep_delayed_delivery_module_set_message_delay (XmppMessageStanza* message,
                                                    GDateTime* datetime)
{
	XmppStanzaNode* delay_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	XmppStanzaNode* _tmp6_;
	XmppStanzaNode* _tmp7_;
	XmppStanzaNode* _tmp8_;
	XmppStanzaNode* _tmp9_;
	XmppStanzaNode* _tmp10_;
	g_return_if_fail (message != NULL);
	g_return_if_fail (datetime != NULL);
	_tmp0_ = xmpp_stanza_node_new_build ("delay", XMPP_XEP_DELAYED_DELIVERY_NS_URI, NULL, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmpp_stanza_node_add_self_xmlns (_tmp1_);
	_tmp3_ = _tmp2_;
	_xmpp_stanza_entry_unref0 (_tmp1_);
	delay_node = _tmp3_;
	_tmp4_ = xmpp_xep_date_time_profiles_to_datetime (datetime);
	_tmp5_ = _tmp4_;
	_tmp6_ = xmpp_stanza_node_put_attribute (delay_node, "stamp", _tmp5_, NULL);
	_tmp7_ = _tmp6_;
	_xmpp_stanza_entry_unref0 (_tmp7_);
	_g_free0 (_tmp5_);
	_tmp8_ = ((XmppStanza*) message)->stanza;
	_tmp9_ = xmpp_stanza_node_put_node (_tmp8_, delay_node);
	_tmp10_ = _tmp9_;
	_xmpp_stanza_entry_unref0 (_tmp10_);
	_xmpp_stanza_entry_unref0 (delay_node);
}

static void
xmpp_xep_delayed_delivery_module_real_attach (XmppXmppStreamModule* base,
                                              XmppXmppStream* stream)
{
	XmppXepDelayedDeliveryModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppMessageModule* _tmp2_;
	XmppStanzaListenerHolder* _tmp3_;
	XmppXepDelayedDeliveryReceivedPipelineListener* _tmp4_;
	self = (XmppXepDelayedDeliveryModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_message_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_TYPE_MESSAGE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppMessageModule*) _tmp1_;
	_tmp3_ = _tmp2_->received_pipeline;
	_tmp4_ = self->priv->received_pipeline_listener;
	xmpp_listener_holder_connect ((XmppListenerHolder*) _tmp3_, (XmppOrderedListener*) _tmp4_);
	_g_object_unref0 (_tmp2_);
}

static void
xmpp_xep_delayed_delivery_module_real_detach (XmppXmppStreamModule* base,
                                              XmppXmppStream* stream)
{
	XmppXepDelayedDeliveryModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppMessageModule* _tmp2_;
	XmppStanzaListenerHolder* _tmp3_;
	XmppXepDelayedDeliveryReceivedPipelineListener* _tmp4_;
	self = (XmppXepDelayedDeliveryModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_message_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_TYPE_MESSAGE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppMessageModule*) _tmp1_;
	_tmp3_ = _tmp2_->received_pipeline;
	_tmp4_ = self->priv->received_pipeline_listener;
	xmpp_listener_holder_disconnect ((XmppListenerHolder*) _tmp3_, (XmppOrderedListener*) _tmp4_);
	_g_object_unref0 (_tmp2_);
}

static gchar*
xmpp_xep_delayed_delivery_module_real_get_ns (XmppXmppStreamModule* base)
{
	XmppXepDelayedDeliveryModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepDelayedDeliveryModule*) base;
	_tmp0_ = g_strdup (XMPP_XEP_DELAYED_DELIVERY_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_delayed_delivery_module_real_get_id (XmppXmppStreamModule* base)
{
	XmppXepDelayedDeliveryModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepDelayedDeliveryModule*) base;
	_tmp0_ = xmpp_xep_delayed_delivery_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppXepDelayedDeliveryModule*
xmpp_xep_delayed_delivery_module_construct (GType object_type)
{
	XmppXepDelayedDeliveryModule * self = NULL;
	self = (XmppXepDelayedDeliveryModule*) xmpp_xmpp_stream_module_construct (object_type);
	return self;
}

XmppXepDelayedDeliveryModule*
xmpp_xep_delayed_delivery_module_new (void)
{
	return xmpp_xep_delayed_delivery_module_construct (XMPP_XEP_DELAYED_DELIVERY_TYPE_MODULE);
}

static void
xmpp_xep_delayed_delivery_module_class_init (XmppXepDelayedDeliveryModuleClass * klass,
                                             gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_xep_delayed_delivery_module_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppXepDelayedDeliveryModule_private_offset);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_delayed_delivery_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_delayed_delivery_module_real_detach;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_delayed_delivery_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_delayed_delivery_module_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_delayed_delivery_module_finalize;
	_tmp0_ = xmpp_module_identity_new (XMPP_XEP_DELAYED_DELIVERY_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_DELAYED_DELIVERY_NS_URI, "0203_delayed_delivery");
	xmpp_xep_delayed_delivery_module_IDENTITY = _tmp0_;
}

static void
xmpp_xep_delayed_delivery_module_instance_init (XmppXepDelayedDeliveryModule * self,
                                                gpointer klass)
{
	XmppXepDelayedDeliveryReceivedPipelineListener* _tmp0_;
	self->priv = xmpp_xep_delayed_delivery_module_get_instance_private (self);
	_tmp0_ = xmpp_xep_delayed_delivery_received_pipeline_listener_new ();
	self->priv->received_pipeline_listener = _tmp0_;
}

static void
xmpp_xep_delayed_delivery_module_finalize (GObject * obj)
{
	XmppXepDelayedDeliveryModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_DELAYED_DELIVERY_TYPE_MODULE, XmppXepDelayedDeliveryModule);
	_g_object_unref0 (self->priv->received_pipeline_listener);
	G_OBJECT_CLASS (xmpp_xep_delayed_delivery_module_parent_class)->finalize (obj);
}

static GType
xmpp_xep_delayed_delivery_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepDelayedDeliveryModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_delayed_delivery_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepDelayedDeliveryModule), 0, (GInstanceInitFunc) xmpp_xep_delayed_delivery_module_instance_init, NULL };
	GType xmpp_xep_delayed_delivery_module_type_id;
	xmpp_xep_delayed_delivery_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_MODULE, "XmppXepDelayedDeliveryModule", &g_define_type_info, 0);
	XmppXepDelayedDeliveryModule_private_offset = g_type_add_instance_private (xmpp_xep_delayed_delivery_module_type_id, sizeof (XmppXepDelayedDeliveryModulePrivate));
	return xmpp_xep_delayed_delivery_module_type_id;
}

GType
xmpp_xep_delayed_delivery_module_get_type (void)
{
	static volatile gsize xmpp_xep_delayed_delivery_module_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_delayed_delivery_module_type_id__once)) {
		GType xmpp_xep_delayed_delivery_module_type_id;
		xmpp_xep_delayed_delivery_module_type_id = xmpp_xep_delayed_delivery_module_get_type_once ();
		g_once_init_leave (&xmpp_xep_delayed_delivery_module_type_id__once, xmpp_xep_delayed_delivery_module_type_id);
	}
	return xmpp_xep_delayed_delivery_module_type_id__once;
}

static inline gpointer
xmpp_xep_delayed_delivery_received_pipeline_listener_get_instance_private (XmppXepDelayedDeliveryReceivedPipelineListener* self)
{
	return G_STRUCT_MEMBER_P (self, XmppXepDelayedDeliveryReceivedPipelineListener_private_offset);
}

static void
xmpp_xep_delayed_delivery_received_pipeline_listener_real_run_data_free (gpointer _data)
{
	XmppXepDelayedDeliveryReceivedPipelineListenerRunData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_g_object_unref0 (_data_->message);
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppXepDelayedDeliveryReceivedPipelineListenerRunData, _data_);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
xmpp_xep_delayed_delivery_received_pipeline_listener_real_run (XmppStanzaListener* base,
                                                               XmppXmppStream* stream,
                                                               XmppMessageStanza* message,
                                                               GAsyncReadyCallback _callback_,
                                                               gpointer _user_data_)
{
	XmppXepDelayedDeliveryReceivedPipelineListener * self;
	XmppXepDelayedDeliveryReceivedPipelineListenerRunData* _data_;
	XmppXepDelayedDeliveryReceivedPipelineListener* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppMessageStanza* _tmp2_;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (message != NULL);
	self = (XmppXepDelayedDeliveryReceivedPipelineListener*) base;
	_data_ = g_slice_new0 (XmppXepDelayedDeliveryReceivedPipelineListenerRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_delayed_delivery_received_pipeline_listener_real_run_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _g_object_ref0 (message);
	_g_object_unref0 (_data_->message);
	_data_->message = _tmp2_;
	xmpp_xep_delayed_delivery_received_pipeline_listener_real_run_co (_data_);
}

static gboolean
xmpp_xep_delayed_delivery_received_pipeline_listener_run_finish (XmppStanzaListener* base,
                                                                 GAsyncResult* _res_)
{
	gboolean result;
	XmppXepDelayedDeliveryReceivedPipelineListenerRunData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static gboolean
xmpp_xep_delayed_delivery_received_pipeline_listener_real_run_co (XmppXepDelayedDeliveryReceivedPipelineListenerRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_xep_delayed_delivery_get_time_for_message (_data_->message, NULL);
	_data_->datetime = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->datetime;
	if (_data_->_tmp1_ != NULL) {
		_data_->_tmp2_ = _data_->datetime;
		_data_->_tmp3_ = xmpp_xep_delayed_delivery_message_flag_new (_data_->_tmp2_);
		_data_->_tmp4_ = _data_->_tmp3_;
		xmpp_message_stanza_add_flag (_data_->message, (XmppMessageFlag*) _data_->_tmp4_);
		_g_object_unref0 (_data_->_tmp4_);
	}
	_data_->result = FALSE;
	_g_date_time_unref0 (_data_->datetime);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

XmppXepDelayedDeliveryReceivedPipelineListener*
xmpp_xep_delayed_delivery_received_pipeline_listener_construct (GType object_type)
{
	XmppXepDelayedDeliveryReceivedPipelineListener * self = NULL;
	self = (XmppXepDelayedDeliveryReceivedPipelineListener*) xmpp_stanza_listener_construct (object_type, XMPP_TYPE_MESSAGE_STANZA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref);
	return self;
}

XmppXepDelayedDeliveryReceivedPipelineListener*
xmpp_xep_delayed_delivery_received_pipeline_listener_new (void)
{
	return xmpp_xep_delayed_delivery_received_pipeline_listener_construct (XMPP_XEP_DELAYED_DELIVERY_TYPE_RECEIVED_PIPELINE_LISTENER);
}

static const gchar*
xmpp_xep_delayed_delivery_received_pipeline_listener_real_get_action_group (XmppOrderedListener* base)
{
	const gchar* result;
	XmppXepDelayedDeliveryReceivedPipelineListener* self;
	self = (XmppXepDelayedDeliveryReceivedPipelineListener*) base;
	result = "ADD_NODE";
	return result;
}

static gchar**
xmpp_xep_delayed_delivery_received_pipeline_listener_real_get_after_actions (XmppOrderedListener* base,
                                                                             gint* result_length1)
{
	gchar** result;
	XmppXepDelayedDeliveryReceivedPipelineListener* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	self = (XmppXepDelayedDeliveryReceivedPipelineListener*) base;
	_tmp0_ = self->priv->after_actions_const;
	_tmp0__length1 = self->priv->after_actions_const_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static void
xmpp_xep_delayed_delivery_received_pipeline_listener_class_init (XmppXepDelayedDeliveryReceivedPipelineListenerClass * klass,
                                                                 gpointer klass_data)
{
	xmpp_xep_delayed_delivery_received_pipeline_listener_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppXepDelayedDeliveryReceivedPipelineListener_private_offset);
	((XmppStanzaListenerClass *) klass)->run = (void (*) (XmppStanzaListener*, XmppXmppStream*, gconstpointer, GAsyncReadyCallback, gpointer)) xmpp_xep_delayed_delivery_received_pipeline_listener_real_run;
	((XmppStanzaListenerClass *) klass)->run_finish = (gboolean (*) (XmppStanzaListener*, GAsyncResult*)) xmpp_xep_delayed_delivery_received_pipeline_listener_run_finish;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_action_group = (const gchar* (*) (XmppOrderedListener*)) xmpp_xep_delayed_delivery_received_pipeline_listener_real_get_action_group;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_after_actions = (gchar** (*) (XmppOrderedListener*, gint*)) xmpp_xep_delayed_delivery_received_pipeline_listener_real_get_after_actions;
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_xep_delayed_delivery_received_pipeline_listener_get_property;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_delayed_delivery_received_pipeline_listener_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_ACTION_GROUP_PROPERTY, xmpp_xep_delayed_delivery_received_pipeline_listener_properties[XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_ACTION_GROUP_PROPERTY] = g_param_spec_string ("action-group", "action-group", "action-group", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_AFTER_ACTIONS_PROPERTY, xmpp_xep_delayed_delivery_received_pipeline_listener_properties[XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_AFTER_ACTIONS_PROPERTY] = g_param_spec_boxed ("after-actions", "after-actions", "after-actions", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
xmpp_xep_delayed_delivery_received_pipeline_listener_instance_init (XmppXepDelayedDeliveryReceivedPipelineListener * self,
                                                                    gpointer klass)
{
	gchar** _tmp0_;
	self->priv = xmpp_xep_delayed_delivery_received_pipeline_listener_get_instance_private (self);
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	self->priv->after_actions_const = _tmp0_;
	self->priv->after_actions_const_length1 = 0;
	self->priv->_after_actions_const_size_ = self->priv->after_actions_const_length1;
}

static void
xmpp_xep_delayed_delivery_received_pipeline_listener_finalize (GObject * obj)
{
	XmppXepDelayedDeliveryReceivedPipelineListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_DELAYED_DELIVERY_TYPE_RECEIVED_PIPELINE_LISTENER, XmppXepDelayedDeliveryReceivedPipelineListener);
	self->priv->after_actions_const = (_vala_array_free (self->priv->after_actions_const, self->priv->after_actions_const_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (xmpp_xep_delayed_delivery_received_pipeline_listener_parent_class)->finalize (obj);
}

static GType
xmpp_xep_delayed_delivery_received_pipeline_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepDelayedDeliveryReceivedPipelineListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_delayed_delivery_received_pipeline_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepDelayedDeliveryReceivedPipelineListener), 0, (GInstanceInitFunc) xmpp_xep_delayed_delivery_received_pipeline_listener_instance_init, NULL };
	GType xmpp_xep_delayed_delivery_received_pipeline_listener_type_id;
	xmpp_xep_delayed_delivery_received_pipeline_listener_type_id = g_type_register_static (XMPP_TYPE_STANZA_LISTENER, "XmppXepDelayedDeliveryReceivedPipelineListener", &g_define_type_info, 0);
	XmppXepDelayedDeliveryReceivedPipelineListener_private_offset = g_type_add_instance_private (xmpp_xep_delayed_delivery_received_pipeline_listener_type_id, sizeof (XmppXepDelayedDeliveryReceivedPipelineListenerPrivate));
	return xmpp_xep_delayed_delivery_received_pipeline_listener_type_id;
}

GType
xmpp_xep_delayed_delivery_received_pipeline_listener_get_type (void)
{
	static volatile gsize xmpp_xep_delayed_delivery_received_pipeline_listener_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_delayed_delivery_received_pipeline_listener_type_id__once)) {
		GType xmpp_xep_delayed_delivery_received_pipeline_listener_type_id;
		xmpp_xep_delayed_delivery_received_pipeline_listener_type_id = xmpp_xep_delayed_delivery_received_pipeline_listener_get_type_once ();
		g_once_init_leave (&xmpp_xep_delayed_delivery_received_pipeline_listener_type_id__once, xmpp_xep_delayed_delivery_received_pipeline_listener_type_id);
	}
	return xmpp_xep_delayed_delivery_received_pipeline_listener_type_id__once;
}

static void
_vala_xmpp_xep_delayed_delivery_received_pipeline_listener_get_property (GObject * object,
                                                                         guint property_id,
                                                                         GValue * value,
                                                                         GParamSpec * pspec)
{
	XmppXepDelayedDeliveryReceivedPipelineListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_XEP_DELAYED_DELIVERY_TYPE_RECEIVED_PIPELINE_LISTENER, XmppXepDelayedDeliveryReceivedPipelineListener);
	switch (property_id) {
		case XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_ACTION_GROUP_PROPERTY:
		g_value_set_string (value, xmpp_ordered_listener_get_action_group ((XmppOrderedListener*) self));
		break;
		case XMPP_XEP_DELAYED_DELIVERY_RECEIVED_PIPELINE_LISTENER_AFTER_ACTIONS_PROPERTY:
		{
			int length;
			g_value_set_boxed (value, xmpp_ordered_listener_get_after_actions ((XmppOrderedListener*) self, &length));
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
xmpp_xep_delayed_delivery_message_flag_get_instance_private (XmppXepDelayedDeliveryMessageFlag* self)
{
	return G_STRUCT_MEMBER_P (self, XmppXepDelayedDeliveryMessageFlag_private_offset);
}

XmppXepDelayedDeliveryMessageFlag*
xmpp_xep_delayed_delivery_message_flag_construct (GType object_type,
                                                  GDateTime* datetime)
{
	XmppXepDelayedDeliveryMessageFlag * self = NULL;
	g_return_val_if_fail (datetime != NULL, NULL);
	self = (XmppXepDelayedDeliveryMessageFlag*) xmpp_message_flag_construct (object_type);
	xmpp_xep_delayed_delivery_message_flag_set_datetime (self, datetime);
	return self;
}

XmppXepDelayedDeliveryMessageFlag*
xmpp_xep_delayed_delivery_message_flag_new (GDateTime* datetime)
{
	return xmpp_xep_delayed_delivery_message_flag_construct (XMPP_XEP_DELAYED_DELIVERY_TYPE_MESSAGE_FLAG, datetime);
}

XmppXepDelayedDeliveryMessageFlag*
xmpp_xep_delayed_delivery_message_flag_get_flag (XmppMessageStanza* message)
{
	XmppMessageFlag* _tmp0_;
	XmppXepDelayedDeliveryMessageFlag* result;
	g_return_val_if_fail (message != NULL, NULL);
	_tmp0_ = xmpp_message_stanza_get_flag (message, XMPP_XEP_DELAYED_DELIVERY_NS_URI, XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_ID);
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, XMPP_XEP_DELAYED_DELIVERY_TYPE_MESSAGE_FLAG, XmppXepDelayedDeliveryMessageFlag);
	return result;
}

static gchar*
xmpp_xep_delayed_delivery_message_flag_real_get_ns (XmppMessageFlag* base)
{
	XmppXepDelayedDeliveryMessageFlag * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepDelayedDeliveryMessageFlag*) base;
	_tmp0_ = g_strdup (XMPP_XEP_DELAYED_DELIVERY_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_delayed_delivery_message_flag_real_get_id (XmppMessageFlag* base)
{
	XmppXepDelayedDeliveryMessageFlag * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepDelayedDeliveryMessageFlag*) base;
	_tmp0_ = g_strdup (XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_ID);
	result = _tmp0_;
	return result;
}

GDateTime*
xmpp_xep_delayed_delivery_message_flag_get_datetime (XmppXepDelayedDeliveryMessageFlag* self)
{
	GDateTime* result;
	GDateTime* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_datetime;
	result = _tmp0_;
	return result;
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

static void
xmpp_xep_delayed_delivery_message_flag_set_datetime (XmppXepDelayedDeliveryMessageFlag* self,
                                                     GDateTime* value)
{
	GDateTime* old_value;
	g_return_if_fail (self != NULL);
	old_value = xmpp_xep_delayed_delivery_message_flag_get_datetime (self);
	if (old_value != value) {
		GDateTime* _tmp0_;
		_tmp0_ = _g_date_time_ref0 (value);
		_g_date_time_unref0 (self->priv->_datetime);
		self->priv->_datetime = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, xmpp_xep_delayed_delivery_message_flag_properties[XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_DATETIME_PROPERTY]);
	}
}

static void
xmpp_xep_delayed_delivery_message_flag_class_init (XmppXepDelayedDeliveryMessageFlagClass * klass,
                                                   gpointer klass_data)
{
	xmpp_xep_delayed_delivery_message_flag_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppXepDelayedDeliveryMessageFlag_private_offset);
	((XmppMessageFlagClass *) klass)->get_ns = (gchar* (*) (XmppMessageFlag*)) xmpp_xep_delayed_delivery_message_flag_real_get_ns;
	((XmppMessageFlagClass *) klass)->get_id = (gchar* (*) (XmppMessageFlag*)) xmpp_xep_delayed_delivery_message_flag_real_get_id;
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_xep_delayed_delivery_message_flag_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_xmpp_xep_delayed_delivery_message_flag_set_property;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_delayed_delivery_message_flag_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_DATETIME_PROPERTY, xmpp_xep_delayed_delivery_message_flag_properties[XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_DATETIME_PROPERTY] = g_param_spec_boxed ("datetime", "datetime", "datetime", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
xmpp_xep_delayed_delivery_message_flag_instance_init (XmppXepDelayedDeliveryMessageFlag * self,
                                                      gpointer klass)
{
	self->priv = xmpp_xep_delayed_delivery_message_flag_get_instance_private (self);
}

static void
xmpp_xep_delayed_delivery_message_flag_finalize (GObject * obj)
{
	XmppXepDelayedDeliveryMessageFlag * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_DELAYED_DELIVERY_TYPE_MESSAGE_FLAG, XmppXepDelayedDeliveryMessageFlag);
	_g_date_time_unref0 (self->priv->_datetime);
	G_OBJECT_CLASS (xmpp_xep_delayed_delivery_message_flag_parent_class)->finalize (obj);
}

static GType
xmpp_xep_delayed_delivery_message_flag_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepDelayedDeliveryMessageFlagClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_delayed_delivery_message_flag_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepDelayedDeliveryMessageFlag), 0, (GInstanceInitFunc) xmpp_xep_delayed_delivery_message_flag_instance_init, NULL };
	GType xmpp_xep_delayed_delivery_message_flag_type_id;
	xmpp_xep_delayed_delivery_message_flag_type_id = g_type_register_static (XMPP_TYPE_MESSAGE_FLAG, "XmppXepDelayedDeliveryMessageFlag", &g_define_type_info, 0);
	XmppXepDelayedDeliveryMessageFlag_private_offset = g_type_add_instance_private (xmpp_xep_delayed_delivery_message_flag_type_id, sizeof (XmppXepDelayedDeliveryMessageFlagPrivate));
	return xmpp_xep_delayed_delivery_message_flag_type_id;
}

GType
xmpp_xep_delayed_delivery_message_flag_get_type (void)
{
	static volatile gsize xmpp_xep_delayed_delivery_message_flag_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_delayed_delivery_message_flag_type_id__once)) {
		GType xmpp_xep_delayed_delivery_message_flag_type_id;
		xmpp_xep_delayed_delivery_message_flag_type_id = xmpp_xep_delayed_delivery_message_flag_get_type_once ();
		g_once_init_leave (&xmpp_xep_delayed_delivery_message_flag_type_id__once, xmpp_xep_delayed_delivery_message_flag_type_id);
	}
	return xmpp_xep_delayed_delivery_message_flag_type_id__once;
}

static void
_vala_xmpp_xep_delayed_delivery_message_flag_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec)
{
	XmppXepDelayedDeliveryMessageFlag * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_XEP_DELAYED_DELIVERY_TYPE_MESSAGE_FLAG, XmppXepDelayedDeliveryMessageFlag);
	switch (property_id) {
		case XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_DATETIME_PROPERTY:
		g_value_set_boxed (value, xmpp_xep_delayed_delivery_message_flag_get_datetime (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_xmpp_xep_delayed_delivery_message_flag_set_property (GObject * object,
                                                           guint property_id,
                                                           const GValue * value,
                                                           GParamSpec * pspec)
{
	XmppXepDelayedDeliveryMessageFlag * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_XEP_DELAYED_DELIVERY_TYPE_MESSAGE_FLAG, XmppXepDelayedDeliveryMessageFlag);
	switch (property_id) {
		case XMPP_XEP_DELAYED_DELIVERY_MESSAGE_FLAG_DATETIME_PROPERTY:
		xmpp_xep_delayed_delivery_message_flag_set_datetime (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

