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

#include "xmpp-vala.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.h>
#include <gee.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_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _XmppMessageArchiveManagementV2ParamSpecMamQueryParams XmppMessageArchiveManagementV2ParamSpecMamQueryParams;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_message_archive_management_v2_mam_query_params_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_message_archive_management_v2_mam_query_params_unref (var), NULL)))
#define _xmpp_message_archive_management_query_result_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_message_archive_management_query_result_unref (var), NULL)))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
typedef struct _XmppMessageArchiveManagementV2QueryArchiveData XmppMessageArchiveManagementV2QueryArchiveData;
typedef struct _XmppMessageArchiveManagementV2PageThroughResultsData XmppMessageArchiveManagementV2PageThroughResultsData;

struct _XmppMessageArchiveManagementV2MamQueryParamsPrivate {
	XmppJid* _mam_server;
	XmppJid* _with;
	GDateTime* _start;
	GDateTime* _end;
	gchar* _start_id;
	gchar* _end_id;
};

struct _XmppMessageArchiveManagementV2ParamSpecMamQueryParams {
	GParamSpec parent_instance;
};

struct _XmppMessageArchiveManagementV2QueryArchiveData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXmppStream* stream;
	XmppMessageArchiveManagementV2MamQueryParams* mam_params;
	GCancellable* cancellable;
	XmppMessageArchiveManagementQueryResult* result;
	XmppStanzaNode* query_node;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	XmppStanzaNode* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppStanzaNode* _tmp6_;
	XmppStanzaNode* _tmp7_;
	XmppJid* _tmp8_;
	XmppJid* _tmp9_;
	XmppStanzaNode* _tmp10_;
	XmppMessageArchiveManagementQueryResult* _tmp11_;
};

struct _XmppMessageArchiveManagementV2PageThroughResultsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXmppStream* stream;
	XmppMessageArchiveManagementV2MamQueryParams* mam_params;
	XmppMessageArchiveManagementQueryResult* prev_result;
	GCancellable* cancellable;
	XmppMessageArchiveManagementQueryResult* result;
	XmppStanzaNode* query_node;
	XmppStanzaNode* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppStanzaNode* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppStanzaNode* _tmp6_;
	XmppJid* _tmp7_;
	XmppJid* _tmp8_;
	XmppMessageArchiveManagementQueryResult* _tmp9_;
};

static gint XmppMessageArchiveManagementV2MamQueryParams_private_offset;
static gpointer xmpp_message_archive_management_v2_mam_query_params_parent_class = NULL;

static void xmpp_message_archive_management_v2_mam_query_params_finalize (XmppMessageArchiveManagementV2MamQueryParams * obj);
static GType xmpp_message_archive_management_v2_mam_query_params_get_type_once (void);
VALA_EXTERN XmppStanzaNode* xmpp_message_archive_management_v2_create_base_query (XmppXmppStream* stream,
                                                                      XmppMessageArchiveManagementV2MamQueryParams* mam_params);
VALA_EXTERN XmppStanzaNode* xmpp_message_archive_management_create_base_query (XmppXmppStream* stream,
                                                                   const gchar* queryid,
                                                                   GeeList* fields);
static void xmpp_message_archive_management_v2_query_archive_data_free (gpointer _data);
static gboolean xmpp_message_archive_management_v2_query_archive_co (XmppMessageArchiveManagementV2QueryArchiveData* _data_);
VALA_EXTERN void xmpp_message_archive_management_query_archive (XmppXmppStream* stream,
                                                    XmppJid* mam_server,
                                                    XmppStanzaNode* query_node,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
VALA_EXTERN XmppMessageArchiveManagementQueryResult* xmpp_message_archive_management_query_archive_finish (GAsyncResult* _res_);
static void xmpp_message_archive_management_v2_query_archive_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
static void xmpp_message_archive_management_v2_page_through_results_data_free (gpointer _data);
static gboolean xmpp_message_archive_management_v2_page_through_results_co (XmppMessageArchiveManagementV2PageThroughResultsData* _data_);
static void xmpp_message_archive_management_v2_page_through_results_ready (GObject* source_object,
                                                                    GAsyncResult* _res_,
                                                                    gpointer _user_data_);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
xmpp_message_archive_management_v2_mam_query_params_get_instance_private (XmppMessageArchiveManagementV2MamQueryParams* self)
{
	return G_STRUCT_MEMBER_P (self, XmppMessageArchiveManagementV2MamQueryParams_private_offset);
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_construct_query_latest (GType object_type,
                                                                            XmppJid* mam_server,
                                                                            GDateTime* latest_known_time,
                                                                            const gchar* latest_known_id)
{
	XmppMessageArchiveManagementV2MamQueryParams* self = NULL;
	g_return_val_if_fail (mam_server != NULL, NULL);
	self = (XmppMessageArchiveManagementV2MamQueryParams*) g_type_create_instance (object_type);
	xmpp_message_archive_management_v2_mam_query_params_set_mam_server (self, mam_server);
	xmpp_message_archive_management_v2_mam_query_params_set_start (self, latest_known_time);
	xmpp_message_archive_management_v2_mam_query_params_set_start_id (self, latest_known_id);
	return self;
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_new_query_latest (XmppJid* mam_server,
                                                                      GDateTime* latest_known_time,
                                                                      const gchar* latest_known_id)
{
	return xmpp_message_archive_management_v2_mam_query_params_construct_query_latest (XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_TYPE_MAM_QUERY_PARAMS, mam_server, latest_known_time, latest_known_id);
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_construct_query_between (GType object_type,
                                                                             XmppJid* mam_server,
                                                                             GDateTime* earliest_time,
                                                                             const gchar* earliest_id,
                                                                             GDateTime* latest_time,
                                                                             const gchar* latest_id)
{
	XmppMessageArchiveManagementV2MamQueryParams* self = NULL;
	g_return_val_if_fail (mam_server != NULL, NULL);
	self = (XmppMessageArchiveManagementV2MamQueryParams*) g_type_create_instance (object_type);
	xmpp_message_archive_management_v2_mam_query_params_set_mam_server (self, mam_server);
	xmpp_message_archive_management_v2_mam_query_params_set_start (self, earliest_time);
	xmpp_message_archive_management_v2_mam_query_params_set_start_id (self, earliest_id);
	xmpp_message_archive_management_v2_mam_query_params_set_end (self, latest_time);
	xmpp_message_archive_management_v2_mam_query_params_set_end_id (self, latest_id);
	return self;
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_new_query_between (XmppJid* mam_server,
                                                                       GDateTime* earliest_time,
                                                                       const gchar* earliest_id,
                                                                       GDateTime* latest_time,
                                                                       const gchar* latest_id)
{
	return xmpp_message_archive_management_v2_mam_query_params_construct_query_between (XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_TYPE_MAM_QUERY_PARAMS, mam_server, earliest_time, earliest_id, latest_time, latest_id);
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_construct_query_before (GType object_type,
                                                                            XmppJid* mam_server,
                                                                            GDateTime* earliest_time,
                                                                            const gchar* earliest_id)
{
	XmppMessageArchiveManagementV2MamQueryParams* self = NULL;
	g_return_val_if_fail (mam_server != NULL, NULL);
	self = (XmppMessageArchiveManagementV2MamQueryParams*) g_type_create_instance (object_type);
	xmpp_message_archive_management_v2_mam_query_params_set_mam_server (self, mam_server);
	xmpp_message_archive_management_v2_mam_query_params_set_end (self, earliest_time);
	xmpp_message_archive_management_v2_mam_query_params_set_end_id (self, earliest_id);
	return self;
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_new_query_before (XmppJid* mam_server,
                                                                      GDateTime* earliest_time,
                                                                      const gchar* earliest_id)
{
	return xmpp_message_archive_management_v2_mam_query_params_construct_query_before (XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_TYPE_MAM_QUERY_PARAMS, mam_server, earliest_time, earliest_id);
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_construct (GType object_type)
{
	XmppMessageArchiveManagementV2MamQueryParams* self = NULL;
	self = (XmppMessageArchiveManagementV2MamQueryParams*) g_type_create_instance (object_type);
	return self;
}

XmppMessageArchiveManagementV2MamQueryParams*
xmpp_message_archive_management_v2_mam_query_params_new (void)
{
	return xmpp_message_archive_management_v2_mam_query_params_construct (XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_TYPE_MAM_QUERY_PARAMS);
}

XmppJid*
xmpp_message_archive_management_v2_mam_query_params_get_mam_server (XmppMessageArchiveManagementV2MamQueryParams* self)
{
	XmppJid* result;
	XmppJid* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_mam_server;
	result = _tmp0_;
	return result;
}

static gpointer
_xmpp_jid_ref0 (gpointer self)
{
	return self ? xmpp_jid_ref (self) : NULL;
}

void
xmpp_message_archive_management_v2_mam_query_params_set_mam_server (XmppMessageArchiveManagementV2MamQueryParams* self,
                                                                    XmppJid* value)
{
	XmppJid* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _xmpp_jid_ref0 (value);
	_xmpp_jid_unref0 (self->priv->_mam_server);
	self->priv->_mam_server = _tmp0_;
}

XmppJid*
xmpp_message_archive_management_v2_mam_query_params_get_with (XmppMessageArchiveManagementV2MamQueryParams* self)
{
	XmppJid* result;
	XmppJid* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_with;
	result = _tmp0_;
	return result;
}

void
xmpp_message_archive_management_v2_mam_query_params_set_with (XmppMessageArchiveManagementV2MamQueryParams* self,
                                                              XmppJid* value)
{
	XmppJid* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _xmpp_jid_ref0 (value);
	_xmpp_jid_unref0 (self->priv->_with);
	self->priv->_with = _tmp0_;
}

GDateTime*
xmpp_message_archive_management_v2_mam_query_params_get_start (XmppMessageArchiveManagementV2MamQueryParams* self)
{
	GDateTime* result;
	GDateTime* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_start;
	result = _tmp0_;
	return result;
}

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

void
xmpp_message_archive_management_v2_mam_query_params_set_start (XmppMessageArchiveManagementV2MamQueryParams* self,
                                                               GDateTime* value)
{
	GDateTime* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_date_time_ref0 (value);
	_g_date_time_unref0 (self->priv->_start);
	self->priv->_start = _tmp0_;
}

GDateTime*
xmpp_message_archive_management_v2_mam_query_params_get_end (XmppMessageArchiveManagementV2MamQueryParams* self)
{
	GDateTime* result;
	GDateTime* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_end;
	result = _tmp0_;
	return result;
}

void
xmpp_message_archive_management_v2_mam_query_params_set_end (XmppMessageArchiveManagementV2MamQueryParams* self,
                                                             GDateTime* value)
{
	GDateTime* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_date_time_ref0 (value);
	_g_date_time_unref0 (self->priv->_end);
	self->priv->_end = _tmp0_;
}

const gchar*
xmpp_message_archive_management_v2_mam_query_params_get_start_id (XmppMessageArchiveManagementV2MamQueryParams* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_start_id;
	result = _tmp0_;
	return result;
}

void
xmpp_message_archive_management_v2_mam_query_params_set_start_id (XmppMessageArchiveManagementV2MamQueryParams* self,
                                                                  const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_start_id);
	self->priv->_start_id = _tmp0_;
}

const gchar*
xmpp_message_archive_management_v2_mam_query_params_get_end_id (XmppMessageArchiveManagementV2MamQueryParams* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_end_id;
	result = _tmp0_;
	return result;
}

void
xmpp_message_archive_management_v2_mam_query_params_set_end_id (XmppMessageArchiveManagementV2MamQueryParams* self,
                                                                const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_end_id);
	self->priv->_end_id = _tmp0_;
}

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

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

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

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

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

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

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

void
xmpp_message_archive_management_v2_value_set_mam_query_params (GValue* value,
                                                               gpointer v_object)
{
	XmppMessageArchiveManagementV2MamQueryParams * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_TYPE_MAM_QUERY_PARAMS));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_TYPE_MAM_QUERY_PARAMS));
		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_message_archive_management_v2_mam_query_params_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_message_archive_management_v2_mam_query_params_unref (old);
	}
}

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

static void
xmpp_message_archive_management_v2_mam_query_params_class_init (XmppMessageArchiveManagementV2MamQueryParamsClass * klass,
                                                                gpointer klass_data)
{
	xmpp_message_archive_management_v2_mam_query_params_parent_class = g_type_class_peek_parent (klass);
	((XmppMessageArchiveManagementV2MamQueryParamsClass *) klass)->finalize = xmpp_message_archive_management_v2_mam_query_params_finalize;
	g_type_class_adjust_private_offset (klass, &XmppMessageArchiveManagementV2MamQueryParams_private_offset);
}

static void
xmpp_message_archive_management_v2_mam_query_params_instance_init (XmppMessageArchiveManagementV2MamQueryParams * self,
                                                                   gpointer klass)
{
	gchar* _tmp0_;
	self->priv = xmpp_message_archive_management_v2_mam_query_params_get_instance_private (self);
	self->use_ns2_extended = FALSE;
	_tmp0_ = xmpp_random_uuid ();
	self->query_id = _tmp0_;
	self->ref_count = 1;
}

static void
xmpp_message_archive_management_v2_mam_query_params_finalize (XmppMessageArchiveManagementV2MamQueryParams * obj)
{
	XmppMessageArchiveManagementV2MamQueryParams * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_TYPE_MAM_QUERY_PARAMS, XmppMessageArchiveManagementV2MamQueryParams);
	g_signal_handlers_destroy (self);
	_g_free0 (self->query_id);
	_xmpp_jid_unref0 (self->priv->_mam_server);
	_xmpp_jid_unref0 (self->priv->_with);
	_g_date_time_unref0 (self->priv->_start);
	_g_date_time_unref0 (self->priv->_end);
	_g_free0 (self->priv->_start_id);
	_g_free0 (self->priv->_end_id);
}

static GType
xmpp_message_archive_management_v2_mam_query_params_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { xmpp_message_archive_management_v2_value_mam_query_params_init, xmpp_message_archive_management_v2_value_mam_query_params_free_value, xmpp_message_archive_management_v2_value_mam_query_params_copy_value, xmpp_message_archive_management_v2_value_mam_query_params_peek_pointer, "p", xmpp_message_archive_management_v2_value_mam_query_params_collect_value, "p", xmpp_message_archive_management_v2_value_mam_query_params_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (XmppMessageArchiveManagementV2MamQueryParamsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_message_archive_management_v2_mam_query_params_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppMessageArchiveManagementV2MamQueryParams), 0, (GInstanceInitFunc) xmpp_message_archive_management_v2_mam_query_params_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_message_archive_management_v2_mam_query_params_type_id;
	xmpp_message_archive_management_v2_mam_query_params_type_id = g_type_register_fundamental (g_type_fundamental_next (), "XmppMessageArchiveManagementV2MamQueryParams", &g_define_type_info, &g_define_type_fundamental_info, 0);
	XmppMessageArchiveManagementV2MamQueryParams_private_offset = g_type_add_instance_private (xmpp_message_archive_management_v2_mam_query_params_type_id, sizeof (XmppMessageArchiveManagementV2MamQueryParamsPrivate));
	return xmpp_message_archive_management_v2_mam_query_params_type_id;
}

GType
xmpp_message_archive_management_v2_mam_query_params_get_type (void)
{
	static volatile gsize xmpp_message_archive_management_v2_mam_query_params_type_id__once = 0;
	if (g_once_init_enter (&xmpp_message_archive_management_v2_mam_query_params_type_id__once)) {
		GType xmpp_message_archive_management_v2_mam_query_params_type_id;
		xmpp_message_archive_management_v2_mam_query_params_type_id = xmpp_message_archive_management_v2_mam_query_params_get_type_once ();
		g_once_init_leave (&xmpp_message_archive_management_v2_mam_query_params_type_id__once, xmpp_message_archive_management_v2_mam_query_params_type_id);
	}
	return xmpp_message_archive_management_v2_mam_query_params_type_id__once;
}

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

void
xmpp_message_archive_management_v2_mam_query_params_unref (gpointer instance)
{
	XmppMessageArchiveManagementV2MamQueryParams * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		XMPP_MESSAGE_ARCHIVE_MANAGEMENT_V2_MAM_QUERY_PARAMS_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

XmppStanzaNode*
xmpp_message_archive_management_v2_create_base_query (XmppXmppStream* stream,
                                                      XmppMessageArchiveManagementV2MamQueryParams* mam_params)
{
	GeeArrayList* fields = NULL;
	GeeArrayList* _tmp0_;
	XmppJid* _tmp1_;
	XmppJid* _tmp2_;
	GDateTime* _tmp12_;
	GDateTime* _tmp13_;
	gboolean _tmp23_ = FALSE;
	gboolean _tmp24_ = FALSE;
	GDateTime* _tmp25_;
	GDateTime* _tmp26_;
	const gchar* _tmp38_;
	GeeArrayList* _tmp39_;
	XmppStanzaNode* _tmp40_;
	XmppStanzaNode* result;
	g_return_val_if_fail (stream != NULL, NULL);
	g_return_val_if_fail (mam_params != NULL, NULL);
	_tmp0_ = gee_array_list_new (XMPP_XEP_DATA_FORMS_DATA_FORM_TYPE_FIELD, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	fields = _tmp0_;
	_tmp1_ = xmpp_message_archive_management_v2_mam_query_params_get_with (mam_params);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != NULL) {
		XmppXepDataFormsDataFormField* field = NULL;
		gchar* _tmp3_;
		XmppXepDataFormsDataFormField* _tmp4_ = NULL;
		XmppXepDataFormsDataFormField* _tmp5_;
		XmppJid* _tmp6_;
		XmppJid* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		GeeArrayList* _tmp10_;
		XmppXepDataFormsDataFormField* _tmp11_;
		_tmp3_ = g_strdup ("with");
		_tmp4_ = xmpp_xep_data_forms_data_form_field_new ();
		xmpp_xep_data_forms_data_form_field_set_var (_tmp4_, _tmp3_);
		_g_free0 (_tmp3_);
		field = _tmp4_;
		_tmp5_ = field;
		_tmp6_ = xmpp_message_archive_management_v2_mam_query_params_get_with (mam_params);
		_tmp7_ = _tmp6_;
		_tmp8_ = xmpp_jid_to_string (_tmp7_);
		_tmp9_ = _tmp8_;
		xmpp_xep_data_forms_data_form_field_set_value_string (_tmp5_, _tmp9_);
		_g_free0 (_tmp9_);
		_tmp10_ = fields;
		_tmp11_ = field;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, _tmp11_);
		_g_object_unref0 (field);
	}
	_tmp12_ = xmpp_message_archive_management_v2_mam_query_params_get_start (mam_params);
	_tmp13_ = _tmp12_;
	if (_tmp13_ != NULL) {
		XmppXepDataFormsDataFormField* field = NULL;
		gchar* _tmp14_;
		XmppXepDataFormsDataFormField* _tmp15_ = NULL;
		XmppXepDataFormsDataFormField* _tmp16_;
		GDateTime* _tmp17_;
		GDateTime* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		GeeArrayList* _tmp21_;
		XmppXepDataFormsDataFormField* _tmp22_;
		_tmp14_ = g_strdup ("start");
		_tmp15_ = xmpp_xep_data_forms_data_form_field_new ();
		xmpp_xep_data_forms_data_form_field_set_var (_tmp15_, _tmp14_);
		_g_free0 (_tmp14_);
		field = _tmp15_;
		_tmp16_ = field;
		_tmp17_ = xmpp_message_archive_management_v2_mam_query_params_get_start (mam_params);
		_tmp18_ = _tmp17_;
		_tmp19_ = xmpp_xep_date_time_profiles_to_datetime (_tmp18_);
		_tmp20_ = _tmp19_;
		xmpp_xep_data_forms_data_form_field_set_value_string (_tmp16_, _tmp20_);
		_g_free0 (_tmp20_);
		_tmp21_ = fields;
		_tmp22_ = field;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp21_, _tmp22_);
		_g_object_unref0 (field);
	}
	_tmp25_ = xmpp_message_archive_management_v2_mam_query_params_get_end (mam_params);
	_tmp26_ = _tmp25_;
	if (_tmp26_ != NULL) {
		const gchar* _tmp27_;
		const gchar* _tmp28_;
		_tmp27_ = xmpp_message_archive_management_v2_mam_query_params_get_end_id (mam_params);
		_tmp28_ = _tmp27_;
		_tmp24_ = _tmp28_ == NULL;
	} else {
		_tmp24_ = FALSE;
	}
	if (_tmp24_) {
		_tmp23_ = !mam_params->use_ns2_extended;
	} else {
		_tmp23_ = FALSE;
	}
	if (_tmp23_) {
		XmppXepDataFormsDataFormField* field = NULL;
		gchar* _tmp29_;
		XmppXepDataFormsDataFormField* _tmp30_ = NULL;
		XmppXepDataFormsDataFormField* _tmp31_;
		GDateTime* _tmp32_;
		GDateTime* _tmp33_;
		gchar* _tmp34_;
		gchar* _tmp35_;
		GeeArrayList* _tmp36_;
		XmppXepDataFormsDataFormField* _tmp37_;
		_tmp29_ = g_strdup ("end");
		_tmp30_ = xmpp_xep_data_forms_data_form_field_new ();
		xmpp_xep_data_forms_data_form_field_set_var (_tmp30_, _tmp29_);
		_g_free0 (_tmp29_);
		field = _tmp30_;
		_tmp31_ = field;
		_tmp32_ = xmpp_message_archive_management_v2_mam_query_params_get_end (mam_params);
		_tmp33_ = _tmp32_;
		_tmp34_ = xmpp_xep_date_time_profiles_to_datetime (_tmp33_);
		_tmp35_ = _tmp34_;
		xmpp_xep_data_forms_data_form_field_set_value_string (_tmp31_, _tmp35_);
		_g_free0 (_tmp35_);
		_tmp36_ = fields;
		_tmp37_ = field;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp36_, _tmp37_);
		_g_object_unref0 (field);
	}
	_tmp38_ = mam_params->query_id;
	_tmp39_ = fields;
	_tmp40_ = xmpp_message_archive_management_create_base_query (stream, _tmp38_, (GeeList*) _tmp39_);
	result = _tmp40_;
	_g_object_unref0 (fields);
	return result;
}

static void
xmpp_message_archive_management_v2_query_archive_data_free (gpointer _data)
{
	XmppMessageArchiveManagementV2QueryArchiveData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->mam_params);
	_g_object_unref0 (_data_->cancellable);
	_xmpp_message_archive_management_query_result_unref0 (_data_->result);
	g_slice_free (XmppMessageArchiveManagementV2QueryArchiveData, _data_);
}

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

static gpointer
_xmpp_message_archive_management_v2_mam_query_params_ref0 (gpointer self)
{
	return self ? xmpp_message_archive_management_v2_mam_query_params_ref (self) : NULL;
}

void
xmpp_message_archive_management_v2_query_archive (XmppXmppStream* stream,
                                                  XmppMessageArchiveManagementV2MamQueryParams* mam_params,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	XmppMessageArchiveManagementV2QueryArchiveData* _data_;
	XmppXmppStream* _tmp0_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (mam_params != NULL);
	_data_ = g_slice_new0 (XmppMessageArchiveManagementV2QueryArchiveData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_message_archive_management_v2_query_archive_data_free);
	_tmp0_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp0_;
	_tmp1_ = _xmpp_message_archive_management_v2_mam_query_params_ref0 (mam_params);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->mam_params);
	_data_->mam_params = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	xmpp_message_archive_management_v2_query_archive_co (_data_);
}

XmppMessageArchiveManagementQueryResult*
xmpp_message_archive_management_v2_query_archive_finish (GAsyncResult* _res_)
{
	XmppMessageArchiveManagementQueryResult* result;
	XmppMessageArchiveManagementV2QueryArchiveData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
xmpp_message_archive_management_v2_query_archive_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	XmppMessageArchiveManagementV2QueryArchiveData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_message_archive_management_v2_query_archive_co (_data_);
}

static gboolean
xmpp_message_archive_management_v2_query_archive_co (XmppMessageArchiveManagementV2QueryArchiveData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_message_archive_management_v2_create_base_query (_data_->stream, _data_->mam_params);
	_data_->query_node = _data_->_tmp0_;
	if (!_data_->mam_params->use_ns2_extended) {
		_data_->_tmp1_ = _data_->query_node;
		_data_->_tmp2_ = xmpp_message_archive_management_v2_mam_query_params_get_end_id (_data_->mam_params);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = xmpp_result_set_management_create_set_rsm_node_before (_data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp6_ = xmpp_stanza_node_put_node (_data_->_tmp1_, _data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_xmpp_stanza_entry_unref0 (_data_->_tmp7_);
		_xmpp_stanza_entry_unref0 (_data_->_tmp5_);
	}
	_data_->_tmp8_ = xmpp_message_archive_management_v2_mam_query_params_get_mam_server (_data_->mam_params);
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_tmp10_ = _data_->query_node;
	_data_->_state_ = 1;
	xmpp_message_archive_management_query_archive (_data_->stream, _data_->_tmp9_, _data_->_tmp10_, _data_->cancellable, xmpp_message_archive_management_v2_query_archive_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp11_ = xmpp_message_archive_management_query_archive_finish (_data_->_res_);
	_data_->result = _data_->_tmp11_;
	_xmpp_stanza_entry_unref0 (_data_->query_node);
	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;
}

static void
xmpp_message_archive_management_v2_page_through_results_data_free (gpointer _data)
{
	XmppMessageArchiveManagementV2PageThroughResultsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->mam_params);
	_xmpp_message_archive_management_query_result_unref0 (_data_->prev_result);
	_g_object_unref0 (_data_->cancellable);
	_xmpp_message_archive_management_query_result_unref0 (_data_->result);
	g_slice_free (XmppMessageArchiveManagementV2PageThroughResultsData, _data_);
}

static gpointer
_xmpp_message_archive_management_query_result_ref0 (gpointer self)
{
	return self ? xmpp_message_archive_management_query_result_ref (self) : NULL;
}

void
xmpp_message_archive_management_v2_page_through_results (XmppXmppStream* stream,
                                                         XmppMessageArchiveManagementV2MamQueryParams* mam_params,
                                                         XmppMessageArchiveManagementQueryResult* prev_result,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_)
{
	XmppMessageArchiveManagementV2PageThroughResultsData* _data_;
	XmppXmppStream* _tmp0_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp1_;
	XmppMessageArchiveManagementQueryResult* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (mam_params != NULL);
	g_return_if_fail (prev_result != NULL);
	_data_ = g_slice_new0 (XmppMessageArchiveManagementV2PageThroughResultsData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_message_archive_management_v2_page_through_results_data_free);
	_tmp0_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp0_;
	_tmp1_ = _xmpp_message_archive_management_v2_mam_query_params_ref0 (mam_params);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->mam_params);
	_data_->mam_params = _tmp1_;
	_tmp2_ = _xmpp_message_archive_management_query_result_ref0 (prev_result);
	_xmpp_message_archive_management_query_result_unref0 (_data_->prev_result);
	_data_->prev_result = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	xmpp_message_archive_management_v2_page_through_results_co (_data_);
}

XmppMessageArchiveManagementQueryResult*
xmpp_message_archive_management_v2_page_through_results_finish (GAsyncResult* _res_)
{
	XmppMessageArchiveManagementQueryResult* result;
	XmppMessageArchiveManagementV2PageThroughResultsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
xmpp_message_archive_management_v2_page_through_results_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_)
{
	XmppMessageArchiveManagementV2PageThroughResultsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_message_archive_management_v2_page_through_results_co (_data_);
}

static gboolean
xmpp_message_archive_management_v2_page_through_results_co (XmppMessageArchiveManagementV2PageThroughResultsData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_message_archive_management_v2_create_base_query (_data_->stream, _data_->mam_params);
	_data_->query_node = _data_->_tmp0_;
	_data_->_tmp1_ = xmpp_message_archive_management_query_result_get_first (_data_->prev_result);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = xmpp_result_set_management_create_set_rsm_node_before (_data_->_tmp2_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = xmpp_stanza_node_put_node (_data_->query_node, _data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	_xmpp_stanza_entry_unref0 (_data_->_tmp6_);
	_xmpp_stanza_entry_unref0 (_data_->_tmp4_);
	_data_->_tmp7_ = xmpp_message_archive_management_v2_mam_query_params_get_mam_server (_data_->mam_params);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->_state_ = 1;
	xmpp_message_archive_management_query_archive (_data_->stream, _data_->_tmp8_, _data_->query_node, _data_->cancellable, xmpp_message_archive_management_v2_page_through_results_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp9_ = xmpp_message_archive_management_query_archive_finish (_data_->_res_);
	_data_->result = _data_->_tmp9_;
	_xmpp_stanza_entry_unref0 (_data_->query_node);
	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;
}

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

