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

#include "omemo.h"
#include "libdino.h"
#include <glib-object.h>
#include <gee.h>
#include <glib.h>
#include "xmpp-vala.h"
#include "qlite.h"
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gobject/gvaluecollector.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 DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER (dino_plugins_omemo_trust_manager_tag_message_listener_get_type ())
#define DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER, DinoPluginsOmemoTrustManagerTagMessageListener))
#define DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER, DinoPluginsOmemoTrustManagerTagMessageListenerClass))
#define DINO_PLUGINS_OMEMO_TRUST_MANAGER_IS_TAG_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER))
#define DINO_PLUGINS_OMEMO_TRUST_MANAGER_IS_TAG_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER))
#define DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER, DinoPluginsOmemoTrustManagerTagMessageListenerClass))

typedef struct _DinoPluginsOmemoTrustManagerTagMessageListener DinoPluginsOmemoTrustManagerTagMessageListener;
typedef struct _DinoPluginsOmemoTrustManagerTagMessageListenerClass DinoPluginsOmemoTrustManagerTagMessageListenerClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
#define _qlite_row_iterator_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_iterator_unref (var), NULL)))
typedef struct _DinoPluginsOmemoTrustManagerTagMessageListenerPrivate DinoPluginsOmemoTrustManagerTagMessageListenerPrivate;
enum  {
	DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_0_PROPERTY,
	DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY,
	DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY,
	DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_trust_manager_tag_message_listener_properties[DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_NUM_PROPERTIES];
#define _dino_plugins_omemo_trust_manager_unref0(var) ((var == NULL) ? NULL : (var = (dino_plugins_omemo_trust_manager_unref (var), NULL)))
typedef struct _DinoPluginsOmemoTrustManagerTagMessageListenerRunData DinoPluginsOmemoTrustManagerTagMessageListenerRunData;
typedef struct _DinoPluginsOmemoParamSpecTrustManager DinoPluginsOmemoParamSpecTrustManager;
enum  {
	DINO_PLUGINS_OMEMO_TRUST_MANAGER_BAD_MESSAGE_STATE_UPDATED_SIGNAL,
	DINO_PLUGINS_OMEMO_TRUST_MANAGER_NUM_SIGNALS
};
static guint dino_plugins_omemo_trust_manager_signals[DINO_PLUGINS_OMEMO_TRUST_MANAGER_NUM_SIGNALS] = {0};

struct _DinoPluginsOmemoTrustManagerPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoPluginsOmemoDatabase* db;
	DinoPluginsOmemoTrustManagerTagMessageListener* tag_message_listener;
};

struct _DinoPluginsOmemoTrustManagerTagMessageListener {
	DinoMessageListener parent_instance;
	DinoPluginsOmemoTrustManagerTagMessageListenerPrivate * priv;
	gchar** after_actions_const;
	gint after_actions_const_length1;
	gint _after_actions_const_size_;
};

struct _DinoPluginsOmemoTrustManagerTagMessageListenerClass {
	DinoMessageListenerClass parent_class;
};

struct _DinoPluginsOmemoTrustManagerTagMessageListenerPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoPluginsOmemoTrustManager* trust_manager;
	DinoPluginsOmemoDatabase* db;
	GeeHashMap* message_device_id_map;
};

struct _DinoPluginsOmemoTrustManagerTagMessageListenerRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoPluginsOmemoTrustManagerTagMessageListener* self;
	DinoEntitiesMessage* message;
	XmppMessageStanza* stanza;
	DinoEntitiesConversation* conversation;
	gboolean result;
	gint device_id;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	gpointer _tmp2_;
	GeeHashMap* _tmp3_;
	DinoContentItem* content_item;
	DinoStreamInteractor* _tmp4_;
	DinoModuleIdentity* _tmp5_;
	gpointer _tmp6_;
	DinoContentItemStore* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	DinoContentItem* _tmp10_;
	DinoContentItem* _tmp11_;
	gboolean _tmp12_;
	DinoContentItem* _tmp13_;
	XmppJid* jid;
	DinoContentItem* _tmp14_;
	XmppJid* _tmp15_;
	XmppJid* _tmp16_;
	XmppJid* _tmp17_;
	DinoEntitiesConversationType _tmp18_;
	DinoEntitiesConversationType _tmp19_;
	XmppJid* _tmp20_;
	XmppJid* _tmp21_;
	XmppJid* _tmp22_;
	gint identity_id;
	DinoPluginsOmemoDatabase* _tmp23_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp24_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp25_;
	DinoEntitiesAccount* _tmp26_;
	DinoEntitiesAccount* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	DinoPluginsOmemoTrustLevel trust_level;
	DinoPluginsOmemoDatabase* _tmp30_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp31_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp32_;
	XmppJid* _tmp33_;
	XmppJid* _tmp34_;
	XmppJid* _tmp35_;
	XmppJid* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	QliteRow* _tmp39_;
	QliteRow* _tmp40_;
	DinoPluginsOmemoDatabase* _tmp41_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp42_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp43_;
	QliteColumn* _tmp44_;
	gpointer _tmp45_;
	DinoPluginsOmemoTrustLevel _tmp46_;
	gboolean _tmp47_;
	DinoStreamInteractor* _tmp48_;
	DinoModuleIdentity* _tmp49_;
	gpointer _tmp50_;
	DinoContentItemStore* _tmp51_;
	DinoContentItem* _tmp52_;
	DinoPluginsOmemoDatabase* _tmp53_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp54_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp55_;
	GDateTime* _tmp56_;
	GDateTime* _tmp57_;
	DinoPluginsOmemoTrustManager* _tmp58_;
	DinoEntitiesAccount* _tmp59_;
	DinoEntitiesAccount* _tmp60_;
	XmppJid* _tmp61_;
	DinoPluginsOmemoDatabase* _tmp62_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp63_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp64_;
	QliteInsertBuilder* _tmp65_;
	QliteInsertBuilder* _tmp66_;
	DinoPluginsOmemoDatabase* _tmp67_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp68_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp69_;
	QliteColumn* _tmp70_;
	DinoContentItem* _tmp71_;
	gint _tmp72_;
	gint _tmp73_;
	QliteInsertBuilder* _tmp74_;
	QliteInsertBuilder* _tmp75_;
	DinoPluginsOmemoDatabase* _tmp76_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp77_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp78_;
	QliteColumn* _tmp79_;
	QliteInsertBuilder* _tmp80_;
	QliteInsertBuilder* _tmp81_;
	DinoPluginsOmemoDatabase* _tmp82_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp83_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp84_;
	QliteColumn* _tmp85_;
	XmppJid* _tmp86_;
	XmppJid* _tmp87_;
	XmppJid* _tmp88_;
	XmppJid* _tmp89_;
	gchar* _tmp90_;
	gchar* _tmp91_;
	QliteInsertBuilder* _tmp92_;
	QliteInsertBuilder* _tmp93_;
	DinoPluginsOmemoDatabase* _tmp94_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp95_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp96_;
	QliteColumn* _tmp97_;
	QliteInsertBuilder* _tmp98_;
	QliteInsertBuilder* _tmp99_;
	DinoPluginsOmemoDatabase* _tmp100_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp101_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp102_;
	QliteColumn* _tmp103_;
	QliteInsertBuilder* _tmp104_;
	QliteInsertBuilder* _tmp105_;
};

struct _DinoPluginsOmemoParamSpecTrustManager {
	GParamSpec parent_instance;
};

static gint DinoPluginsOmemoTrustManager_private_offset;
static gpointer dino_plugins_omemo_trust_manager_parent_class = NULL;
static gint DinoPluginsOmemoTrustManagerTagMessageListener_private_offset;
static gpointer dino_plugins_omemo_trust_manager_tag_message_listener_parent_class = NULL;

static GType dino_plugins_omemo_trust_manager_tag_message_listener_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static guint _dino_entities_message_hash_func_gee_hash_data_func (gconstpointer v,
                                                           gpointer self);
static gboolean _dino_entities_message_equals_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
static DinoPluginsOmemoTrustManagerTagMessageListener* dino_plugins_omemo_trust_manager_tag_message_listener_new (DinoStreamInteractor* stream_interactor,
                                                                                                           DinoPluginsOmemoTrustManager* trust_manager,
                                                                                                           DinoPluginsOmemoDatabase* db,
                                                                                                           GeeHashMap* message_device_id_map);
static DinoPluginsOmemoTrustManagerTagMessageListener* dino_plugins_omemo_trust_manager_tag_message_listener_construct (GType object_type,
                                                                                                                 DinoStreamInteractor* stream_interactor,
                                                                                                                 DinoPluginsOmemoTrustManager* trust_manager,
                                                                                                                 DinoPluginsOmemoDatabase* db,
                                                                                                                 GeeHashMap* message_device_id_map);
static void _vala_array_add1 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_INT (GClosure * closure,
                                                        GValue * return_value,
                                                        guint n_param_values,
                                                        const GValue * param_values,
                                                        gpointer invocation_hint,
                                                        gpointer marshal_data);
static void dino_plugins_omemo_trust_manager_tag_message_listener_real_run_data_free (gpointer _data);
static void dino_plugins_omemo_trust_manager_tag_message_listener_real_run (DinoMessageListener* base,
                                                                     DinoEntitiesMessage* message,
                                                                     XmppMessageStanza* stanza,
                                                                     DinoEntitiesConversation* conversation,
                                                                     GAsyncReadyCallback _callback_,
                                                                     gpointer _user_data_);
static gboolean dino_plugins_omemo_trust_manager_tag_message_listener_real_run_co (DinoPluginsOmemoTrustManagerTagMessageListenerRunData* _data_);
static void dino_plugins_omemo_trust_manager_tag_message_listener_finalize (GObject * obj);
static GType dino_plugins_omemo_trust_manager_tag_message_listener_get_type_once (void);
static void _vala_dino_plugins_omemo_trust_manager_tag_message_listener_get_property (GObject * object,
                                                                               guint property_id,
                                                                               GValue * value,
                                                                               GParamSpec * pspec);
static void dino_plugins_omemo_trust_manager_finalize (DinoPluginsOmemoTrustManager * obj);
static GType dino_plugins_omemo_trust_manager_get_type_once (void);
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);

static inline gpointer
dino_plugins_omemo_trust_manager_get_instance_private (DinoPluginsOmemoTrustManager* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoTrustManager_private_offset);
}

static guint
_dino_entities_message_hash_func_gee_hash_data_func (gconstpointer v,
                                                     gpointer self)
{
	guint result;
	result = dino_entities_message_hash_func ((DinoEntitiesMessage*) v);
	return result;
}

static gboolean
_dino_entities_message_equals_func_gee_equal_data_func (gconstpointer a,
                                                        gconstpointer b,
                                                        gpointer self)
{
	gboolean result;
	result = dino_entities_message_equals_func ((DinoEntitiesMessage*) a, (DinoEntitiesMessage*) b);
	return result;
}

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

static gpointer
_qlite_database_ref0 (gpointer self)
{
	return self ? qlite_database_ref (self) : NULL;
}

DinoPluginsOmemoTrustManager*
dino_plugins_omemo_trust_manager_construct (GType object_type,
                                            DinoStreamInteractor* stream_interactor,
                                            DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoTrustManager* self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoPluginsOmemoDatabase* _tmp1_;
	GeeHashMap* _tmp2_;
	DinoPluginsOmemoTrustManagerTagMessageListener* _tmp3_;
	DinoModuleIdentity* _tmp4_;
	gpointer _tmp5_;
	DinoMessageProcessor* _tmp6_;
	DinoMessageListenerHolder* _tmp7_;
	DinoPluginsOmemoTrustManagerTagMessageListener* _tmp8_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoTrustManager*) g_type_create_instance (object_type);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	_tmp1_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp1_;
	_tmp2_ = self->message_device_id_map;
	_tmp3_ = dino_plugins_omemo_trust_manager_tag_message_listener_new (stream_interactor, self, db, _tmp2_);
	_g_object_unref0 (self->priv->tag_message_listener);
	self->priv->tag_message_listener = _tmp3_;
	_tmp4_ = dino_message_processor_IDENTITY;
	_tmp5_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
	_tmp6_ = (DinoMessageProcessor*) _tmp5_;
	_tmp7_ = _tmp6_->received_pipeline;
	_tmp8_ = self->priv->tag_message_listener;
	xmpp_listener_holder_connect ((XmppListenerHolder*) _tmp7_, (XmppOrderedListener*) _tmp8_);
	_g_object_unref0 (_tmp6_);
	return self;
}

DinoPluginsOmemoTrustManager*
dino_plugins_omemo_trust_manager_new (DinoStreamInteractor* stream_interactor,
                                      DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_trust_manager_construct (DINO_PLUGINS_OMEMO_TYPE_TRUST_MANAGER, stream_interactor, db);
}

void
dino_plugins_omemo_trust_manager_set_blind_trust (DinoPluginsOmemoTrustManager* self,
                                                  DinoEntitiesAccount* account,
                                                  XmppJid* jid,
                                                  gboolean blind_trust)
{
	gint identity_id = 0;
	DinoPluginsOmemoDatabase* _tmp0_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp1_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	DinoPluginsOmemoDatabase* _tmp5_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp6_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp7_;
	QliteUpdateBuilder* _tmp8_;
	QliteUpdateBuilder* _tmp9_;
	DinoPluginsOmemoDatabase* _tmp10_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp11_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp12_;
	QliteColumn* _tmp13_;
	QliteUpdateBuilder* _tmp14_;
	QliteUpdateBuilder* _tmp15_;
	DinoPluginsOmemoDatabase* _tmp16_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp17_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp18_;
	QliteColumn* _tmp19_;
	XmppJid* _tmp20_;
	XmppJid* _tmp21_;
	XmppJid* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	QliteUpdateBuilder* _tmp25_;
	QliteUpdateBuilder* _tmp26_;
	DinoPluginsOmemoDatabase* _tmp27_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp28_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp29_;
	QliteColumn* _tmp30_;
	QliteUpdateBuilder* _tmp31_;
	QliteUpdateBuilder* _tmp32_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_plugins_omemo_database_get_identity (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = dino_entities_account_get_id (account);
	_tmp4_ = _tmp3_;
	identity_id = dino_plugins_omemo_database_identity_table_get_id (_tmp2_, _tmp4_);
	if (identity_id < 0) {
		return;
	}
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_plugins_omemo_database_get_trust (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = qlite_table_update ((QliteTable*) _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = self->priv->db;
	_tmp11_ = dino_plugins_omemo_database_get_trust (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = _tmp12_->identity_id;
	_tmp14_ = qlite_update_builder_with (_tmp9_, G_TYPE_INT, NULL, NULL, _tmp13_, "=", (gpointer) ((gintptr) identity_id));
	_tmp15_ = _tmp14_;
	_tmp16_ = self->priv->db;
	_tmp17_ = dino_plugins_omemo_database_get_trust (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = _tmp18_->address_name;
	_tmp20_ = xmpp_jid_get_bare_jid (jid);
	_tmp21_ = _tmp20_;
	_tmp22_ = _tmp21_;
	_tmp23_ = xmpp_jid_to_string (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = qlite_update_builder_with (_tmp15_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp19_, "=", _tmp24_);
	_tmp26_ = _tmp25_;
	_tmp27_ = self->priv->db;
	_tmp28_ = dino_plugins_omemo_database_get_trust (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = _tmp29_->blind_trust;
	_tmp31_ = qlite_update_builder_set (_tmp26_, G_TYPE_BOOLEAN, NULL, NULL, _tmp30_, (gpointer) ((gintptr) blind_trust));
	_tmp32_ = _tmp31_;
	qlite_update_builder_perform (_tmp32_);
	_qlite_statement_builder_unref0 (_tmp32_);
	_qlite_statement_builder_unref0 (_tmp26_);
	_g_free0 (_tmp24_);
	_xmpp_jid_unref0 (_tmp22_);
	_qlite_statement_builder_unref0 (_tmp15_);
	_qlite_statement_builder_unref0 (_tmp9_);
}

static void
_vala_array_add1 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

void
dino_plugins_omemo_trust_manager_set_device_trust (DinoPluginsOmemoTrustManager* self,
                                                   DinoEntitiesAccount* account,
                                                   XmppJid* jid,
                                                   gint device_id,
                                                   DinoPluginsOmemoTrustLevel trust_level)
{
	gint identity_id = 0;
	DinoPluginsOmemoDatabase* _tmp0_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp1_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	DinoPluginsOmemoDatabase* _tmp5_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp6_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp7_;
	QliteUpdateBuilder* _tmp8_;
	QliteUpdateBuilder* _tmp9_;
	DinoPluginsOmemoDatabase* _tmp10_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp11_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp12_;
	QliteColumn* _tmp13_;
	QliteUpdateBuilder* _tmp14_;
	QliteUpdateBuilder* _tmp15_;
	DinoPluginsOmemoDatabase* _tmp16_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp17_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp18_;
	QliteColumn* _tmp19_;
	XmppJid* _tmp20_;
	XmppJid* _tmp21_;
	XmppJid* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	QliteUpdateBuilder* _tmp25_;
	QliteUpdateBuilder* _tmp26_;
	DinoPluginsOmemoDatabase* _tmp27_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp28_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp29_;
	QliteColumn* _tmp30_;
	QliteUpdateBuilder* _tmp31_;
	QliteUpdateBuilder* _tmp32_;
	DinoPluginsOmemoDatabase* _tmp33_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp34_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp35_;
	QliteColumn* _tmp36_;
	QliteUpdateBuilder* _tmp37_;
	QliteUpdateBuilder* _tmp38_;
	gchar* selection = NULL;
	gchar** selection_args = NULL;
	gchar** _tmp39_;
	gint selection_args_length1;
	gint _selection_args_size_;
	DinoDatabase* app_db = NULL;
	DinoApplication* _tmp40_;
	DinoDatabase* _tmp41_;
	DinoDatabase* _tmp42_;
	DinoDatabase* _tmp43_;
	const gchar* _tmp90_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_plugins_omemo_database_get_identity (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = dino_entities_account_get_id (account);
	_tmp4_ = _tmp3_;
	identity_id = dino_plugins_omemo_database_identity_table_get_id (_tmp2_, _tmp4_);
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_plugins_omemo_database_get_identity_meta (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = qlite_table_update ((QliteTable*) _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = self->priv->db;
	_tmp11_ = dino_plugins_omemo_database_get_identity_meta (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = _tmp12_->identity_id;
	_tmp14_ = qlite_update_builder_with (_tmp9_, G_TYPE_INT, NULL, NULL, _tmp13_, "=", (gpointer) ((gintptr) identity_id));
	_tmp15_ = _tmp14_;
	_tmp16_ = self->priv->db;
	_tmp17_ = dino_plugins_omemo_database_get_identity_meta (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = _tmp18_->address_name;
	_tmp20_ = xmpp_jid_get_bare_jid (jid);
	_tmp21_ = _tmp20_;
	_tmp22_ = _tmp21_;
	_tmp23_ = xmpp_jid_to_string (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = qlite_update_builder_with (_tmp15_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp19_, "=", _tmp24_);
	_tmp26_ = _tmp25_;
	_tmp27_ = self->priv->db;
	_tmp28_ = dino_plugins_omemo_database_get_identity_meta (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = _tmp29_->device_id;
	_tmp31_ = qlite_update_builder_with (_tmp26_, G_TYPE_INT, NULL, NULL, _tmp30_, "=", (gpointer) ((gintptr) device_id));
	_tmp32_ = _tmp31_;
	_tmp33_ = self->priv->db;
	_tmp34_ = dino_plugins_omemo_database_get_identity_meta (_tmp33_);
	_tmp35_ = _tmp34_;
	_tmp36_ = _tmp35_->trust_level;
	_tmp37_ = qlite_update_builder_set (_tmp32_, G_TYPE_INT, NULL, NULL, _tmp36_, (gpointer) ((gintptr) trust_level));
	_tmp38_ = _tmp37_;
	qlite_update_builder_perform (_tmp38_);
	_qlite_statement_builder_unref0 (_tmp38_);
	_qlite_statement_builder_unref0 (_tmp32_);
	_qlite_statement_builder_unref0 (_tmp26_);
	_g_free0 (_tmp24_);
	_xmpp_jid_unref0 (_tmp22_);
	_qlite_statement_builder_unref0 (_tmp15_);
	_qlite_statement_builder_unref0 (_tmp9_);
	selection = NULL;
	_tmp39_ = g_new0 (gchar*, 0 + 1);
	selection_args = _tmp39_;
	selection_args_length1 = 0;
	_selection_args_size_ = selection_args_length1;
	_tmp40_ = dino_application_get_default ();
	_tmp41_ = dino_application_get_db (_tmp40_);
	_tmp42_ = _tmp41_;
	_tmp43_ = _qlite_database_ref0 (_tmp42_);
	app_db = _tmp43_;
	{
		QliteRowIterator* _row_it = NULL;
		DinoPluginsOmemoDatabase* _tmp44_;
		DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp45_;
		DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp46_;
		XmppJid* _tmp47_;
		XmppJid* _tmp48_;
		XmppJid* _tmp49_;
		gchar* _tmp50_;
		gchar* _tmp51_;
		QliteQueryBuilder* _tmp52_;
		QliteQueryBuilder* _tmp53_;
		DinoPluginsOmemoDatabase* _tmp54_;
		DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp55_;
		DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp56_;
		QliteColumn* _tmp57_;
		QliteQueryBuilder* _tmp58_;
		QliteQueryBuilder* _tmp59_;
		QliteRowIterator* _tmp60_;
		QliteRowIterator* _tmp61_;
		_tmp44_ = self->priv->db;
		_tmp45_ = dino_plugins_omemo_database_get_content_item_meta (_tmp44_);
		_tmp46_ = _tmp45_;
		_tmp47_ = xmpp_jid_get_bare_jid (jid);
		_tmp48_ = _tmp47_;
		_tmp49_ = _tmp48_;
		_tmp50_ = xmpp_jid_to_string (_tmp49_);
		_tmp51_ = _tmp50_;
		_tmp52_ = dino_plugins_omemo_database_content_item_meta_table_with_device (_tmp46_, identity_id, _tmp51_, device_id);
		_tmp53_ = _tmp52_;
		_tmp54_ = self->priv->db;
		_tmp55_ = dino_plugins_omemo_database_get_content_item_meta (_tmp54_);
		_tmp56_ = _tmp55_;
		_tmp57_ = _tmp56_->trusted_when_received;
		_tmp58_ = qlite_query_builder_with (_tmp53_, G_TYPE_BOOLEAN, NULL, NULL, _tmp57_, "=", (gpointer) ((gintptr) FALSE));
		_tmp59_ = _tmp58_;
		_tmp60_ = qlite_query_builder_iterator (_tmp59_);
		_tmp61_ = _tmp60_;
		_qlite_statement_builder_unref0 (_tmp59_);
		_qlite_statement_builder_unref0 (_tmp53_);
		_g_free0 (_tmp51_);
		_xmpp_jid_unref0 (_tmp49_);
		_row_it = _tmp61_;
		while (TRUE) {
			QliteRowIterator* _tmp62_;
			QliteRow* row = NULL;
			QliteRowIterator* _tmp63_;
			QliteRow* _tmp64_;
			const gchar* _tmp65_;
			QliteRow* _tmp83_;
			DinoPluginsOmemoDatabase* _tmp84_;
			DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp85_;
			DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp86_;
			QliteColumn* _tmp87_;
			gpointer _tmp88_;
			gchar* _tmp89_;
			_tmp62_ = _row_it;
			if (!qlite_row_iterator_next (_tmp62_)) {
				break;
			}
			_tmp63_ = _row_it;
			_tmp64_ = qlite_row_iterator_get (_tmp63_);
			row = _tmp64_;
			_tmp65_ = selection;
			if (_tmp65_ == NULL) {
				DinoDatabase* _tmp66_;
				DinoDatabaseContentItemTable* _tmp67_;
				DinoDatabaseContentItemTable* _tmp68_;
				QliteColumn* _tmp69_;
				gchar* _tmp70_;
				gchar* _tmp71_;
				gchar* _tmp72_;
				_tmp66_ = app_db;
				_tmp67_ = dino_database_get_content_item (_tmp66_);
				_tmp68_ = _tmp67_;
				_tmp69_ = _tmp68_->id;
				_tmp70_ = qlite_column_to_string (_tmp69_);
				_tmp71_ = _tmp70_;
				_tmp72_ = g_strconcat (_tmp71_, " = ?", NULL);
				_g_free0 (selection);
				selection = _tmp72_;
				_g_free0 (_tmp71_);
			} else {
				const gchar* _tmp73_;
				DinoDatabase* _tmp74_;
				DinoDatabaseContentItemTable* _tmp75_;
				DinoDatabaseContentItemTable* _tmp76_;
				QliteColumn* _tmp77_;
				gchar* _tmp78_;
				gchar* _tmp79_;
				gchar* _tmp80_;
				gchar* _tmp81_;
				gchar* _tmp82_;
				_tmp73_ = selection;
				_tmp74_ = app_db;
				_tmp75_ = dino_database_get_content_item (_tmp74_);
				_tmp76_ = _tmp75_;
				_tmp77_ = _tmp76_->id;
				_tmp78_ = qlite_column_to_string (_tmp77_);
				_tmp79_ = _tmp78_;
				_tmp80_ = g_strconcat (" OR ", _tmp79_, " = ?", NULL);
				_tmp81_ = _tmp80_;
				_tmp82_ = g_strconcat (_tmp73_, _tmp81_, NULL);
				_g_free0 (selection);
				selection = _tmp82_;
				_g_free0 (_tmp81_);
				_g_free0 (_tmp79_);
			}
			_tmp83_ = row;
			_tmp84_ = self->priv->db;
			_tmp85_ = dino_plugins_omemo_database_get_content_item_meta (_tmp84_);
			_tmp86_ = _tmp85_;
			_tmp87_ = _tmp86_->content_item_id;
			_tmp88_ = qlite_row_get (_tmp83_, G_TYPE_INT, NULL, NULL, _tmp87_);
			_tmp89_ = g_strdup_printf ("%i", (gint) ((gintptr) _tmp88_));
			_vala_array_add1 (&selection_args, &selection_args_length1, &_selection_args_size_, _tmp89_);
			_qlite_row_unref0 (row);
		}
		_qlite_row_iterator_unref0 (_row_it);
	}
	_tmp90_ = selection;
	if (_tmp90_ != NULL) {
		gboolean _tmp91_ = FALSE;
		DinoDatabase* _tmp92_;
		DinoDatabaseContentItemTable* _tmp93_;
		DinoDatabaseContentItemTable* _tmp94_;
		QliteUpdateBuilder* _tmp95_;
		QliteUpdateBuilder* _tmp96_;
		DinoDatabase* _tmp97_;
		DinoDatabaseContentItemTable* _tmp98_;
		DinoDatabaseContentItemTable* _tmp99_;
		QliteColumn* _tmp100_;
		QliteUpdateBuilder* _tmp101_;
		QliteUpdateBuilder* _tmp102_;
		const gchar* _tmp103_;
		gchar** _tmp104_;
		gint _tmp104__length1;
		QliteUpdateBuilder* _tmp105_;
		QliteUpdateBuilder* _tmp106_;
		if (trust_level == DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNTRUSTED) {
			_tmp91_ = TRUE;
		} else {
			_tmp91_ = trust_level == DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNKNOWN;
		}
		_tmp92_ = app_db;
		_tmp93_ = dino_database_get_content_item (_tmp92_);
		_tmp94_ = _tmp93_;
		_tmp95_ = qlite_table_update ((QliteTable*) _tmp94_);
		_tmp96_ = _tmp95_;
		_tmp97_ = app_db;
		_tmp98_ = dino_database_get_content_item (_tmp97_);
		_tmp99_ = _tmp98_;
		_tmp100_ = _tmp99_->hide;
		_tmp101_ = qlite_update_builder_set (_tmp96_, G_TYPE_BOOLEAN, NULL, NULL, _tmp100_, (gpointer) ((gintptr) _tmp91_));
		_tmp102_ = _tmp101_;
		_tmp103_ = selection;
		_tmp104_ = selection_args;
		_tmp104__length1 = selection_args_length1;
		_tmp105_ = qlite_update_builder_where (_tmp102_, _tmp103_, _tmp104_, (gint) _tmp104__length1);
		_tmp106_ = _tmp105_;
		qlite_update_builder_perform (_tmp106_);
		_qlite_statement_builder_unref0 (_tmp106_);
		_qlite_statement_builder_unref0 (_tmp102_);
		_qlite_statement_builder_unref0 (_tmp96_);
	}
	if (trust_level == DINO_PLUGINS_OMEMO_TRUST_LEVEL_TRUSTED) {
		DinoPluginsOmemoDatabase* _tmp107_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp108_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp109_;
		_tmp107_ = self->priv->db;
		_tmp108_ = dino_plugins_omemo_database_get_identity_meta (_tmp107_);
		_tmp109_ = _tmp108_;
		dino_plugins_omemo_database_identity_meta_table_update_last_message_untrusted (_tmp109_, identity_id, device_id, NULL);
		g_signal_emit (self, dino_plugins_omemo_trust_manager_signals[DINO_PLUGINS_OMEMO_TRUST_MANAGER_BAD_MESSAGE_STATE_UPDATED_SIGNAL], 0, account, jid, device_id);
	}
	_qlite_database_unref0 (app_db);
	selection_args = (_vala_array_free (selection_args, selection_args_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (selection);
}

gboolean
dino_plugins_omemo_trust_manager_is_known_address (DinoPluginsOmemoTrustManager* self,
                                                   DinoEntitiesAccount* account,
                                                   XmppJid* jid)
{
	gint identity_id = 0;
	DinoPluginsOmemoDatabase* _tmp0_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp1_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	DinoPluginsOmemoDatabase* _tmp5_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp6_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	QliteQueryBuilder* _tmp10_;
	QliteQueryBuilder* _tmp11_;
	DinoPluginsOmemoDatabase* _tmp12_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp13_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp14_;
	QliteColumn* _tmp15_;
	QliteQueryBuilder* _tmp16_;
	QliteQueryBuilder* _tmp17_;
	gboolean _tmp18_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (account != NULL, FALSE);
	g_return_val_if_fail (jid != NULL, FALSE);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_plugins_omemo_database_get_identity (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = dino_entities_account_get_id (account);
	_tmp4_ = _tmp3_;
	identity_id = dino_plugins_omemo_database_identity_table_get_id (_tmp2_, _tmp4_);
	if (identity_id < 0) {
		result = FALSE;
		return result;
	}
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_plugins_omemo_database_get_identity_meta (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = xmpp_jid_to_string (jid);
	_tmp9_ = _tmp8_;
	_tmp10_ = dino_plugins_omemo_database_identity_meta_table_with_address (_tmp7_, identity_id, _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->db;
	_tmp13_ = dino_plugins_omemo_database_get_identity_meta (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _tmp14_->last_active;
	_tmp16_ = qlite_query_builder_with (_tmp11_, G_TYPE_LONG, NULL, NULL, _tmp15_, ">", (gpointer) ((gintptr) 0));
	_tmp17_ = _tmp16_;
	_tmp18_ = qlite_query_builder_count (_tmp17_) > ((gint64) 0);
	_qlite_statement_builder_unref0 (_tmp17_);
	_qlite_statement_builder_unref0 (_tmp11_);
	_g_free0 (_tmp9_);
	result = _tmp18_;
	return result;
}

GeeList*
dino_plugins_omemo_trust_manager_get_trusted_devices (DinoPluginsOmemoTrustManager* self,
                                                      DinoEntitiesAccount* account,
                                                      XmppJid* jid)
{
	GeeList* devices = NULL;
	GeeArrayList* _tmp0_;
	gint identity_id = 0;
	DinoPluginsOmemoDatabase* _tmp1_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp2_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	_tmp0_ = gee_array_list_new (G_TYPE_INT, NULL, NULL, NULL, NULL, NULL);
	devices = (GeeList*) _tmp0_;
	_tmp1_ = self->priv->db;
	_tmp2_ = dino_plugins_omemo_database_get_identity (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = dino_entities_account_get_id (account);
	_tmp5_ = _tmp4_;
	identity_id = dino_plugins_omemo_database_identity_table_get_id (_tmp3_, _tmp5_);
	if (identity_id < 0) {
		result = devices;
		return result;
	}
	{
		QliteRowIterator* _device_it = NULL;
		DinoPluginsOmemoDatabase* _tmp6_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp7_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		XmppJid* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		QliteQueryBuilder* _tmp14_;
		QliteQueryBuilder* _tmp15_;
		QliteRowIterator* _tmp16_;
		QliteRowIterator* _tmp17_;
		_tmp6_ = self->priv->db;
		_tmp7_ = dino_plugins_omemo_database_get_identity_meta (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = xmpp_jid_get_bare_jid (jid);
		_tmp10_ = _tmp9_;
		_tmp11_ = _tmp10_;
		_tmp12_ = xmpp_jid_to_string (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = dino_plugins_omemo_database_identity_meta_table_get_trusted_devices (_tmp8_, identity_id, _tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = qlite_query_builder_iterator (_tmp15_);
		_tmp17_ = _tmp16_;
		_qlite_statement_builder_unref0 (_tmp15_);
		_g_free0 (_tmp13_);
		_xmpp_jid_unref0 (_tmp11_);
		_device_it = _tmp17_;
		while (TRUE) {
			QliteRowIterator* _tmp18_;
			QliteRow* device = NULL;
			QliteRowIterator* _tmp19_;
			QliteRow* _tmp20_;
			gboolean _tmp21_ = FALSE;
			QliteRow* _tmp22_;
			DinoPluginsOmemoDatabase* _tmp23_;
			DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp24_;
			DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp25_;
			QliteColumn* _tmp26_;
			gpointer _tmp27_;
			_tmp18_ = _device_it;
			if (!qlite_row_iterator_next (_tmp18_)) {
				break;
			}
			_tmp19_ = _device_it;
			_tmp20_ = qlite_row_iterator_get (_tmp19_);
			device = _tmp20_;
			_tmp22_ = device;
			_tmp23_ = self->priv->db;
			_tmp24_ = dino_plugins_omemo_database_get_identity_meta (_tmp23_);
			_tmp25_ = _tmp24_;
			_tmp26_ = _tmp25_->trust_level;
			_tmp27_ = qlite_row_get (_tmp22_, G_TYPE_INT, NULL, NULL, _tmp26_);
			if (((gint) ((gintptr) _tmp27_)) != ((gint) DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNKNOWN)) {
				_tmp21_ = TRUE;
			} else {
				QliteRow* _tmp28_;
				DinoPluginsOmemoDatabase* _tmp29_;
				DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp30_;
				DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp31_;
				QliteColumn* _tmp32_;
				gpointer _tmp33_;
				gchar* _tmp34_;
				_tmp28_ = device;
				_tmp29_ = self->priv->db;
				_tmp30_ = dino_plugins_omemo_database_get_identity_meta (_tmp29_);
				_tmp31_ = _tmp30_;
				_tmp32_ = _tmp31_->identity_key_public_base64;
				_tmp33_ = qlite_row_get (_tmp28_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp32_);
				_tmp34_ = (gchar*) _tmp33_;
				_tmp21_ = _tmp34_ == NULL;
				_g_free0 (_tmp34_);
			}
			if (_tmp21_) {
				GeeList* _tmp35_;
				QliteRow* _tmp36_;
				DinoPluginsOmemoDatabase* _tmp37_;
				DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp38_;
				DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp39_;
				QliteColumn* _tmp40_;
				gpointer _tmp41_;
				_tmp35_ = devices;
				_tmp36_ = device;
				_tmp37_ = self->priv->db;
				_tmp38_ = dino_plugins_omemo_database_get_identity_meta (_tmp37_);
				_tmp39_ = _tmp38_;
				_tmp40_ = _tmp39_->device_id;
				_tmp41_ = qlite_row_get (_tmp36_, G_TYPE_INT, NULL, NULL, _tmp40_);
				gee_collection_add ((GeeCollection*) _tmp35_, (gpointer) ((gintptr) _tmp41_));
			}
			_qlite_row_unref0 (device);
		}
		_qlite_row_iterator_unref0 (_device_it);
	}
	result = devices;
	return result;
}

static void
g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_INT (GClosure * closure,
                                                   GValue * return_value,
                                                   guint n_param_values,
                                                   const GValue * param_values,
                                                   gpointer invocation_hint,
                                                   gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_XMPP_JID_INT) (gpointer data1, gpointer arg_1, gpointer arg_2, gint arg_3, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_XMPP_JID_INT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_XMPP_JID_INT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), xmpp_value_get_jid (param_values + 2), g_value_get_int (param_values + 3), data2);
}

static inline gpointer
dino_plugins_omemo_trust_manager_tag_message_listener_get_instance_private (DinoPluginsOmemoTrustManagerTagMessageListener* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoTrustManagerTagMessageListener_private_offset);
}

static gpointer
_dino_plugins_omemo_trust_manager_ref0 (gpointer self)
{
	return self ? dino_plugins_omemo_trust_manager_ref (self) : NULL;
}

static DinoPluginsOmemoTrustManagerTagMessageListener*
dino_plugins_omemo_trust_manager_tag_message_listener_construct (GType object_type,
                                                                 DinoStreamInteractor* stream_interactor,
                                                                 DinoPluginsOmemoTrustManager* trust_manager,
                                                                 DinoPluginsOmemoDatabase* db,
                                                                 GeeHashMap* message_device_id_map)
{
	DinoPluginsOmemoTrustManagerTagMessageListener * self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoPluginsOmemoTrustManager* _tmp1_;
	DinoPluginsOmemoDatabase* _tmp2_;
	GeeHashMap* _tmp3_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (trust_manager != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	g_return_val_if_fail (message_device_id_map != NULL, NULL);
	self = (DinoPluginsOmemoTrustManagerTagMessageListener*) dino_message_listener_construct (object_type);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	_tmp1_ = _dino_plugins_omemo_trust_manager_ref0 (trust_manager);
	_dino_plugins_omemo_trust_manager_unref0 (self->priv->trust_manager);
	self->priv->trust_manager = _tmp1_;
	_tmp2_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp2_;
	_tmp3_ = _g_object_ref0 (message_device_id_map);
	_g_object_unref0 (self->priv->message_device_id_map);
	self->priv->message_device_id_map = _tmp3_;
	return self;
}

static DinoPluginsOmemoTrustManagerTagMessageListener*
dino_plugins_omemo_trust_manager_tag_message_listener_new (DinoStreamInteractor* stream_interactor,
                                                           DinoPluginsOmemoTrustManager* trust_manager,
                                                           DinoPluginsOmemoDatabase* db,
                                                           GeeHashMap* message_device_id_map)
{
	return dino_plugins_omemo_trust_manager_tag_message_listener_construct (DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER, stream_interactor, trust_manager, db, message_device_id_map);
}

static void
dino_plugins_omemo_trust_manager_tag_message_listener_real_run_data_free (gpointer _data)
{
	DinoPluginsOmemoTrustManagerTagMessageListenerRunData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->message);
	_g_object_unref0 (_data_->stanza);
	_g_object_unref0 (_data_->conversation);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoPluginsOmemoTrustManagerTagMessageListenerRunData, _data_);
}

static void
dino_plugins_omemo_trust_manager_tag_message_listener_real_run (DinoMessageListener* base,
                                                                DinoEntitiesMessage* message,
                                                                XmppMessageStanza* stanza,
                                                                DinoEntitiesConversation* conversation,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_)
{
	DinoPluginsOmemoTrustManagerTagMessageListener * self;
	DinoPluginsOmemoTrustManagerTagMessageListenerRunData* _data_;
	DinoPluginsOmemoTrustManagerTagMessageListener* _tmp0_;
	DinoEntitiesMessage* _tmp1_;
	XmppMessageStanza* _tmp2_;
	DinoEntitiesConversation* _tmp3_;
	g_return_if_fail (message != NULL);
	g_return_if_fail (stanza != NULL);
	g_return_if_fail (conversation != NULL);
	self = (DinoPluginsOmemoTrustManagerTagMessageListener*) base;
	_data_ = g_slice_new0 (DinoPluginsOmemoTrustManagerTagMessageListenerRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_plugins_omemo_trust_manager_tag_message_listener_real_run_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (message);
	_g_object_unref0 (_data_->message);
	_data_->message = _tmp1_;
	_tmp2_ = _g_object_ref0 (stanza);
	_g_object_unref0 (_data_->stanza);
	_data_->stanza = _tmp2_;
	_tmp3_ = _g_object_ref0 (conversation);
	_g_object_unref0 (_data_->conversation);
	_data_->conversation = _tmp3_;
	dino_plugins_omemo_trust_manager_tag_message_listener_real_run_co (_data_);
}

static gboolean
dino_plugins_omemo_trust_manager_tag_message_listener_run_finish (DinoMessageListener* base,
                                                                  GAsyncResult* _res_)
{
	gboolean result;
	DinoPluginsOmemoTrustManagerTagMessageListenerRunData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

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

static gboolean
dino_plugins_omemo_trust_manager_tag_message_listener_real_run_co (DinoPluginsOmemoTrustManagerTagMessageListenerRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->device_id = 0;
	_data_->_tmp0_ = _data_->self->priv->message_device_id_map;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp0_, _data_->message)) {
		_data_->_tmp1_ = _data_->self->priv->message_device_id_map;
		_data_->_tmp2_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp1_, _data_->message);
		_data_->device_id = (gint) ((gintptr) _data_->_tmp2_);
		_data_->_tmp3_ = _data_->self->priv->message_device_id_map;
		gee_abstract_map_unset ((GeeAbstractMap*) _data_->_tmp3_, _data_->message, NULL);
	}
	_data_->_tmp4_ = _data_->self->priv->stream_interactor;
	_data_->_tmp5_ = dino_content_item_store_IDENTITY;
	_data_->_tmp6_ = dino_stream_interactor_get_module (_data_->_tmp4_, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp5_);
	_data_->_tmp7_ = (DinoContentItemStore*) _data_->_tmp6_;
	_data_->_tmp8_ = dino_entities_message_get_id (_data_->message);
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_tmp10_ = dino_content_item_store_get_item_by_foreign (_data_->_tmp7_, _data_->conversation, 1, _data_->_tmp9_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp7_);
	_data_->content_item = _data_->_tmp11_;
	_data_->_tmp13_ = _data_->content_item;
	if (_data_->_tmp13_ != NULL) {
		_data_->_tmp12_ = _data_->device_id != 0;
	} else {
		_data_->_tmp12_ = FALSE;
	}
	if (_data_->_tmp12_) {
		_data_->_tmp14_ = _data_->content_item;
		_data_->_tmp15_ = dino_content_item_get_jid (_data_->_tmp14_);
		_data_->_tmp16_ = _data_->_tmp15_;
		_data_->_tmp17_ = _xmpp_jid_ref0 (_data_->_tmp16_);
		_data_->jid = _data_->_tmp17_;
		_data_->_tmp18_ = dino_entities_conversation_get_type_ (_data_->conversation);
		_data_->_tmp19_ = _data_->_tmp18_;
		if (_data_->_tmp19_ == DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT) {
			_data_->_tmp20_ = dino_entities_message_get_real_jid (_data_->message);
			_data_->_tmp21_ = _data_->_tmp20_;
			_data_->_tmp22_ = _xmpp_jid_ref0 (_data_->_tmp21_);
			_xmpp_jid_unref0 (_data_->jid);
			_data_->jid = _data_->_tmp22_;
		}
		_data_->_tmp23_ = _data_->self->priv->db;
		_data_->_tmp24_ = dino_plugins_omemo_database_get_identity (_data_->_tmp23_);
		_data_->_tmp25_ = _data_->_tmp24_;
		_data_->_tmp26_ = dino_entities_conversation_get_account (_data_->conversation);
		_data_->_tmp27_ = _data_->_tmp26_;
		_data_->_tmp28_ = dino_entities_account_get_id (_data_->_tmp27_);
		_data_->_tmp29_ = _data_->_tmp28_;
		_data_->identity_id = dino_plugins_omemo_database_identity_table_get_id (_data_->_tmp25_, _data_->_tmp29_);
		_data_->_tmp30_ = _data_->self->priv->db;
		_data_->_tmp31_ = dino_plugins_omemo_database_get_identity_meta (_data_->_tmp30_);
		_data_->_tmp32_ = _data_->_tmp31_;
		_data_->_tmp33_ = _data_->jid;
		_data_->_tmp34_ = xmpp_jid_get_bare_jid (_data_->_tmp33_);
		_data_->_tmp35_ = _data_->_tmp34_;
		_data_->_tmp36_ = _data_->_tmp35_;
		_data_->_tmp37_ = xmpp_jid_to_string (_data_->_tmp36_);
		_data_->_tmp38_ = _data_->_tmp37_;
		_data_->_tmp39_ = dino_plugins_omemo_database_identity_meta_table_get_device (_data_->_tmp32_, _data_->identity_id, _data_->_tmp38_, _data_->device_id);
		_data_->_tmp40_ = _data_->_tmp39_;
		_data_->_tmp41_ = _data_->self->priv->db;
		_data_->_tmp42_ = dino_plugins_omemo_database_get_identity_meta (_data_->_tmp41_);
		_data_->_tmp43_ = _data_->_tmp42_;
		_data_->_tmp44_ = _data_->_tmp43_->trust_level;
		_data_->_tmp45_ = qlite_row_get (_data_->_tmp40_, G_TYPE_INT, NULL, NULL, _data_->_tmp44_);
		_data_->_tmp46_ = (DinoPluginsOmemoTrustLevel) ((gint) ((gintptr) _data_->_tmp45_));
		_qlite_row_unref0 (_data_->_tmp40_);
		_g_free0 (_data_->_tmp38_);
		_xmpp_jid_unref0 (_data_->_tmp36_);
		_data_->trust_level = _data_->_tmp46_;
		if (_data_->trust_level == DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNTRUSTED) {
			_data_->_tmp47_ = TRUE;
		} else {
			_data_->_tmp47_ = _data_->trust_level == DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNKNOWN;
		}
		if (_data_->_tmp47_) {
			_data_->_tmp48_ = _data_->self->priv->stream_interactor;
			_data_->_tmp49_ = dino_content_item_store_IDENTITY;
			_data_->_tmp50_ = dino_stream_interactor_get_module (_data_->_tmp48_, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp49_);
			_data_->_tmp51_ = (DinoContentItemStore*) _data_->_tmp50_;
			_data_->_tmp52_ = _data_->content_item;
			dino_content_item_store_set_item_hide (_data_->_tmp51_, _data_->_tmp52_, TRUE);
			_g_object_unref0 (_data_->_tmp51_);
			_data_->_tmp53_ = _data_->self->priv->db;
			_data_->_tmp54_ = dino_plugins_omemo_database_get_identity_meta (_data_->_tmp53_);
			_data_->_tmp55_ = _data_->_tmp54_;
			_data_->_tmp56_ = dino_entities_message_get_time (_data_->message);
			_data_->_tmp57_ = _data_->_tmp56_;
			dino_plugins_omemo_database_identity_meta_table_update_last_message_untrusted (_data_->_tmp55_, _data_->identity_id, _data_->device_id, _data_->_tmp57_);
			_data_->_tmp58_ = _data_->self->priv->trust_manager;
			_data_->_tmp59_ = dino_entities_conversation_get_account (_data_->conversation);
			_data_->_tmp60_ = _data_->_tmp59_;
			_data_->_tmp61_ = _data_->jid;
			g_signal_emit (_data_->_tmp58_, dino_plugins_omemo_trust_manager_signals[DINO_PLUGINS_OMEMO_TRUST_MANAGER_BAD_MESSAGE_STATE_UPDATED_SIGNAL], 0, _data_->_tmp60_, _data_->_tmp61_, _data_->device_id);
		}
		_data_->_tmp62_ = _data_->self->priv->db;
		_data_->_tmp63_ = dino_plugins_omemo_database_get_content_item_meta (_data_->_tmp62_);
		_data_->_tmp64_ = _data_->_tmp63_;
		_data_->_tmp65_ = qlite_table_insert ((QliteTable*) _data_->_tmp64_);
		_data_->_tmp66_ = _data_->_tmp65_;
		_data_->_tmp67_ = _data_->self->priv->db;
		_data_->_tmp68_ = dino_plugins_omemo_database_get_content_item_meta (_data_->_tmp67_);
		_data_->_tmp69_ = _data_->_tmp68_;
		_data_->_tmp70_ = _data_->_tmp69_->content_item_id;
		_data_->_tmp71_ = _data_->content_item;
		_data_->_tmp72_ = dino_content_item_get_id (_data_->_tmp71_);
		_data_->_tmp73_ = _data_->_tmp72_;
		_data_->_tmp74_ = qlite_insert_builder_value (_data_->_tmp66_, G_TYPE_INT, NULL, NULL, _data_->_tmp70_, (gpointer) ((gintptr) _data_->_tmp73_));
		_data_->_tmp75_ = _data_->_tmp74_;
		_data_->_tmp76_ = _data_->self->priv->db;
		_data_->_tmp77_ = dino_plugins_omemo_database_get_content_item_meta (_data_->_tmp76_);
		_data_->_tmp78_ = _data_->_tmp77_;
		_data_->_tmp79_ = _data_->_tmp78_->identity_id;
		_data_->_tmp80_ = qlite_insert_builder_value (_data_->_tmp75_, G_TYPE_INT, NULL, NULL, _data_->_tmp79_, (gpointer) ((gintptr) _data_->identity_id));
		_data_->_tmp81_ = _data_->_tmp80_;
		_data_->_tmp82_ = _data_->self->priv->db;
		_data_->_tmp83_ = dino_plugins_omemo_database_get_content_item_meta (_data_->_tmp82_);
		_data_->_tmp84_ = _data_->_tmp83_;
		_data_->_tmp85_ = _data_->_tmp84_->address_name;
		_data_->_tmp86_ = _data_->jid;
		_data_->_tmp87_ = xmpp_jid_get_bare_jid (_data_->_tmp86_);
		_data_->_tmp88_ = _data_->_tmp87_;
		_data_->_tmp89_ = _data_->_tmp88_;
		_data_->_tmp90_ = xmpp_jid_to_string (_data_->_tmp89_);
		_data_->_tmp91_ = _data_->_tmp90_;
		_data_->_tmp92_ = qlite_insert_builder_value (_data_->_tmp81_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp85_, _data_->_tmp91_);
		_data_->_tmp93_ = _data_->_tmp92_;
		_data_->_tmp94_ = _data_->self->priv->db;
		_data_->_tmp95_ = dino_plugins_omemo_database_get_content_item_meta (_data_->_tmp94_);
		_data_->_tmp96_ = _data_->_tmp95_;
		_data_->_tmp97_ = _data_->_tmp96_->device_id;
		_data_->_tmp98_ = qlite_insert_builder_value (_data_->_tmp93_, G_TYPE_INT, NULL, NULL, _data_->_tmp97_, (gpointer) ((gintptr) _data_->device_id));
		_data_->_tmp99_ = _data_->_tmp98_;
		_data_->_tmp100_ = _data_->self->priv->db;
		_data_->_tmp101_ = dino_plugins_omemo_database_get_content_item_meta (_data_->_tmp100_);
		_data_->_tmp102_ = _data_->_tmp101_;
		_data_->_tmp103_ = _data_->_tmp102_->trusted_when_received;
		_data_->_tmp104_ = qlite_insert_builder_value (_data_->_tmp99_, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp103_, (gpointer) ((gintptr) (_data_->trust_level != DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNTRUSTED)));
		_data_->_tmp105_ = _data_->_tmp104_;
		qlite_insert_builder_perform (_data_->_tmp105_);
		_qlite_statement_builder_unref0 (_data_->_tmp105_);
		_qlite_statement_builder_unref0 (_data_->_tmp99_);
		_qlite_statement_builder_unref0 (_data_->_tmp93_);
		_g_free0 (_data_->_tmp91_);
		_xmpp_jid_unref0 (_data_->_tmp89_);
		_qlite_statement_builder_unref0 (_data_->_tmp81_);
		_qlite_statement_builder_unref0 (_data_->_tmp75_);
		_qlite_statement_builder_unref0 (_data_->_tmp66_);
		_xmpp_jid_unref0 (_data_->jid);
	}
	_data_->result = FALSE;
	_g_object_unref0 (_data_->content_item);
	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 const gchar*
dino_plugins_omemo_trust_manager_tag_message_listener_real_get_action_group (XmppOrderedListener* base)
{
	const gchar* result;
	DinoPluginsOmemoTrustManagerTagMessageListener* self;
	self = (DinoPluginsOmemoTrustManagerTagMessageListener*) base;
	result = "DECRYPT_TAG";
	return result;
}

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

static void
dino_plugins_omemo_trust_manager_tag_message_listener_class_init (DinoPluginsOmemoTrustManagerTagMessageListenerClass * klass,
                                                                  gpointer klass_data)
{
	dino_plugins_omemo_trust_manager_tag_message_listener_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoTrustManagerTagMessageListener_private_offset);
	((DinoMessageListenerClass *) klass)->run = (void (*) (DinoMessageListener*, DinoEntitiesMessage*, XmppMessageStanza*, DinoEntitiesConversation*, GAsyncReadyCallback, gpointer)) dino_plugins_omemo_trust_manager_tag_message_listener_real_run;
	((DinoMessageListenerClass *) klass)->run_finish = (gboolean (*) (DinoMessageListener*, GAsyncResult*)) dino_plugins_omemo_trust_manager_tag_message_listener_run_finish;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_action_group = (const gchar* (*) (XmppOrderedListener*)) dino_plugins_omemo_trust_manager_tag_message_listener_real_get_action_group;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_after_actions = (gchar** (*) (XmppOrderedListener*, gint*)) dino_plugins_omemo_trust_manager_tag_message_listener_real_get_after_actions;
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_plugins_omemo_trust_manager_tag_message_listener_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_omemo_trust_manager_tag_message_listener_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY, dino_plugins_omemo_trust_manager_tag_message_listener_properties[DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_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), DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY, dino_plugins_omemo_trust_manager_tag_message_listener_properties[DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_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
dino_plugins_omemo_trust_manager_tag_message_listener_instance_init (DinoPluginsOmemoTrustManagerTagMessageListener * self,
                                                                     gpointer klass)
{
	gchar* _tmp0_;
	gchar** _tmp1_;
	self->priv = dino_plugins_omemo_trust_manager_tag_message_listener_get_instance_private (self);
	_tmp0_ = g_strdup ("STORE");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	self->after_actions_const = _tmp1_;
	self->after_actions_const_length1 = 1;
	self->_after_actions_const_size_ = self->after_actions_const_length1;
}

static void
dino_plugins_omemo_trust_manager_tag_message_listener_finalize (GObject * obj)
{
	DinoPluginsOmemoTrustManagerTagMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER, DinoPluginsOmemoTrustManagerTagMessageListener);
	self->after_actions_const = (_vala_array_free (self->after_actions_const, self->after_actions_const_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->stream_interactor);
	_dino_plugins_omemo_trust_manager_unref0 (self->priv->trust_manager);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->message_device_id_map);
	G_OBJECT_CLASS (dino_plugins_omemo_trust_manager_tag_message_listener_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_trust_manager_tag_message_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoTrustManagerTagMessageListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_trust_manager_tag_message_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoTrustManagerTagMessageListener), 0, (GInstanceInitFunc) dino_plugins_omemo_trust_manager_tag_message_listener_instance_init, NULL };
	GType dino_plugins_omemo_trust_manager_tag_message_listener_type_id;
	dino_plugins_omemo_trust_manager_tag_message_listener_type_id = g_type_register_static (DINO_TYPE_MESSAGE_LISTENER, "DinoPluginsOmemoTrustManagerTagMessageListener", &g_define_type_info, 0);
	DinoPluginsOmemoTrustManagerTagMessageListener_private_offset = g_type_add_instance_private (dino_plugins_omemo_trust_manager_tag_message_listener_type_id, sizeof (DinoPluginsOmemoTrustManagerTagMessageListenerPrivate));
	return dino_plugins_omemo_trust_manager_tag_message_listener_type_id;
}

static GType
dino_plugins_omemo_trust_manager_tag_message_listener_get_type (void)
{
	static volatile gsize dino_plugins_omemo_trust_manager_tag_message_listener_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_trust_manager_tag_message_listener_type_id__once)) {
		GType dino_plugins_omemo_trust_manager_tag_message_listener_type_id;
		dino_plugins_omemo_trust_manager_tag_message_listener_type_id = dino_plugins_omemo_trust_manager_tag_message_listener_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_trust_manager_tag_message_listener_type_id__once, dino_plugins_omemo_trust_manager_tag_message_listener_type_id);
	}
	return dino_plugins_omemo_trust_manager_tag_message_listener_type_id__once;
}

static void
_vala_dino_plugins_omemo_trust_manager_tag_message_listener_get_property (GObject * object,
                                                                          guint property_id,
                                                                          GValue * value,
                                                                          GParamSpec * pspec)
{
	DinoPluginsOmemoTrustManagerTagMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_PLUGINS_OMEMO_TRUST_MANAGER_TYPE_TAG_MESSAGE_LISTENER, DinoPluginsOmemoTrustManagerTagMessageListener);
	switch (property_id) {
		case DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY:
		g_value_set_string (value, xmpp_ordered_listener_get_action_group ((XmppOrderedListener*) self));
		break;
		case DINO_PLUGINS_OMEMO_TRUST_MANAGER_TAG_MESSAGE_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 void
dino_plugins_omemo_value_trust_manager_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

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

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

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

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

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

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

void
dino_plugins_omemo_value_set_trust_manager (GValue* value,
                                            gpointer v_object)
{
	DinoPluginsOmemoTrustManager * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_PLUGINS_OMEMO_TYPE_TRUST_MANAGER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_PLUGINS_OMEMO_TYPE_TRUST_MANAGER));
		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;
		dino_plugins_omemo_trust_manager_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_plugins_omemo_trust_manager_unref (old);
	}
}

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

static void
dino_plugins_omemo_trust_manager_class_init (DinoPluginsOmemoTrustManagerClass * klass,
                                             gpointer klass_data)
{
	dino_plugins_omemo_trust_manager_parent_class = g_type_class_peek_parent (klass);
	((DinoPluginsOmemoTrustManagerClass *) klass)->finalize = dino_plugins_omemo_trust_manager_finalize;
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoTrustManager_private_offset);
	dino_plugins_omemo_trust_manager_signals[DINO_PLUGINS_OMEMO_TRUST_MANAGER_BAD_MESSAGE_STATE_UPDATED_SIGNAL] = g_signal_new ("bad-message-state-updated", DINO_PLUGINS_OMEMO_TYPE_TRUST_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_INT, G_TYPE_NONE, 3, DINO_ENTITIES_TYPE_ACCOUNT, XMPP_TYPE_JID, G_TYPE_INT);
}

static void
dino_plugins_omemo_trust_manager_instance_init (DinoPluginsOmemoTrustManager * self,
                                                gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dino_plugins_omemo_trust_manager_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_MESSAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_INT, NULL, NULL, _dino_entities_message_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_message_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->message_device_id_map = _tmp0_;
	self->ref_count = 1;
}

static void
dino_plugins_omemo_trust_manager_finalize (DinoPluginsOmemoTrustManager * obj)
{
	DinoPluginsOmemoTrustManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_TRUST_MANAGER, DinoPluginsOmemoTrustManager);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->tag_message_listener);
	_g_object_unref0 (self->message_device_id_map);
}

static GType
dino_plugins_omemo_trust_manager_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_plugins_omemo_value_trust_manager_init, dino_plugins_omemo_value_trust_manager_free_value, dino_plugins_omemo_value_trust_manager_copy_value, dino_plugins_omemo_value_trust_manager_peek_pointer, "p", dino_plugins_omemo_value_trust_manager_collect_value, "p", dino_plugins_omemo_value_trust_manager_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoTrustManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_trust_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoTrustManager), 0, (GInstanceInitFunc) dino_plugins_omemo_trust_manager_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 dino_plugins_omemo_trust_manager_type_id;
	dino_plugins_omemo_trust_manager_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoPluginsOmemoTrustManager", &g_define_type_info, &g_define_type_fundamental_info, 0);
	DinoPluginsOmemoTrustManager_private_offset = g_type_add_instance_private (dino_plugins_omemo_trust_manager_type_id, sizeof (DinoPluginsOmemoTrustManagerPrivate));
	return dino_plugins_omemo_trust_manager_type_id;
}

GType
dino_plugins_omemo_trust_manager_get_type (void)
{
	static volatile gsize dino_plugins_omemo_trust_manager_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_trust_manager_type_id__once)) {
		GType dino_plugins_omemo_trust_manager_type_id;
		dino_plugins_omemo_trust_manager_type_id = dino_plugins_omemo_trust_manager_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_trust_manager_type_id__once, dino_plugins_omemo_trust_manager_type_id);
	}
	return dino_plugins_omemo_trust_manager_type_id__once;
}

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

void
dino_plugins_omemo_trust_manager_unref (gpointer instance)
{
	DinoPluginsOmemoTrustManager * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_PLUGINS_OMEMO_TRUST_MANAGER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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

