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

#include "omemo.h"
#include <glib.h>
#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "xmpp-vala.h"
#include "qlite.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

enum  {
	DINO_PLUGINS_OMEMO_PLUGIN_0_PROPERTY,
	DINO_PLUGINS_OMEMO_PLUGIN_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_plugin_properties[DINO_PLUGINS_OMEMO_PLUGIN_NUM_PROPERTIES];
#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 _dino_plugins_omemo_own_notifications_unref0(var) ((var == NULL) ? NULL : (var = (dino_plugins_omemo_own_notifications_unref (var), NULL)))
#define _dino_plugins_omemo_trust_manager_unref0(var) ((var == NULL) ? NULL : (var = (dino_plugins_omemo_trust_manager_unref (var), NULL)))
#define _omemo_context_unref0(var) ((var == NULL) ? NULL : (var = (omemo_context_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block5Data Block5Data;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _Block5Data {
	int _ref_count_;
	DinoPluginsOmemoPlugin* self;
	DinoApplication* app;
};

static gpointer dino_plugins_omemo_plugin_parent_class = NULL;
static OmemoContext* dino_plugins_omemo_plugin__context;
static GRecMutex __lock_dino_plugins_omemo_plugin_dino_plugins_omemo_plugin__context = {0};
static OmemoContext* dino_plugins_omemo_plugin__context = NULL;
static DinoPluginsRootInterfaceIface * dino_plugins_omemo_plugin_dino_plugins_root_interface_parent_iface = NULL;

static guint _dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                           gpointer self);
static gboolean _dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
static void dino_plugins_omemo_plugin_real_registered (DinoPluginsRootInterface* base,
                                                DinoApplication* app);
static Block5Data* block5_data_ref (Block5Data* _data5_);
static void block5_data_unref (void * _userdata_);
static void __lambda41_ (Block5Data* _data5_,
                  DinoEntitiesAccount* account,
                  GeeArrayList* list);
static void ___lambda41__dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                                  DinoEntitiesAccount* account,
                                                                  GeeArrayList* modules,
                                                                  gpointer self);
static void dino_plugins_omemo_plugin_real_shutdown (DinoPluginsRootInterface* base);
static void dino_plugins_omemo_plugin_finalize (GObject * obj);
static GType dino_plugins_omemo_plugin_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static guint
_dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                     gpointer self)
{
	guint result;
	result = dino_entities_account_hash_func ((DinoEntitiesAccount*) v);
	return result;
}

static gboolean
_dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                        gconstpointer b,
                                                        gpointer self)
{
	gboolean result;
	result = dino_entities_account_equals_func ((DinoEntitiesAccount*) a, (DinoEntitiesAccount*) b);
	return result;
}

static gpointer
_omemo_context_ref0 (gpointer self)
{
	return self ? omemo_context_ref (self) : NULL;
}

OmemoContext*
dino_plugins_omemo_plugin_get_context (void)
{
	OmemoContext* _tmp0_;
	OmemoContext* _tmp1_;
	OmemoContext* _tmp2_;
	OmemoContext* result;
	_tmp0_ = dino_plugins_omemo_plugin__context;
	_vala_assert (_tmp0_ != NULL, "_context != null");
	_tmp1_ = dino_plugins_omemo_plugin__context;
	_tmp2_ = _omemo_context_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, OMEMO_TYPE_CONTEXT, OmemoContext));
	result = _tmp2_;
	return result;
}

gboolean
dino_plugins_omemo_plugin_ensure_context (void)
{
	GError* _inner_error0_ = NULL;
	gboolean result;
	{
		OmemoContext* _tmp0_;
		gboolean _tmp11_ = FALSE;
		_tmp0_ = dino_plugins_omemo_plugin__context;
		g_rec_mutex_lock (&__lock_dino_plugins_omemo_plugin_dino_plugins_omemo_plugin__context);
		{
			gboolean _tmp9_ = FALSE;
			{
				OmemoContext* _tmp1_;
				_tmp1_ = dino_plugins_omemo_plugin__context;
				if (_tmp1_ == NULL) {
					OmemoContext* _tmp2_ = NULL;
					OmemoContext* _tmp3_;
					OmemoContext* _tmp4_;
					_tmp3_ = omemo_context_new (DINO_PLUGINS_OMEMO_PLUGIN_DEBUG, &_inner_error0_);
					_tmp2_ = _tmp3_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch1_g_error;
					}
					_tmp4_ = _tmp2_;
					_tmp2_ = NULL;
					_omemo_context_unref0 (dino_plugins_omemo_plugin__context);
					dino_plugins_omemo_plugin__context = _tmp4_;
					_omemo_context_unref0 (_tmp2_);
				}
				result = TRUE;
				{
					OmemoContext* _tmp5_;
					_tmp5_ = dino_plugins_omemo_plugin__context;
					g_rec_mutex_unlock (&__lock_dino_plugins_omemo_plugin_dino_plugins_omemo_plugin__context);
				}
				return result;
			}
			goto __finally1;
			__catch1_g_error:
			{
				GError* e = NULL;
				GError* _tmp6_;
				const gchar* _tmp7_;
				e = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp6_ = e;
				_tmp7_ = _tmp6_->message;
				g_warning ("plugin.vala:25: Error initializing libomemo-c Context %s", _tmp7_);
				result = FALSE;
				_g_error_free0 (e);
				{
					OmemoContext* _tmp8_;
					_tmp8_ = dino_plugins_omemo_plugin__context;
					g_rec_mutex_unlock (&__lock_dino_plugins_omemo_plugin_dino_plugins_omemo_plugin__context);
				}
				return result;
			}
			__finally1:
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp9_;
		}
		__finally0:
		{
			OmemoContext* _tmp10_;
			_tmp10_ = dino_plugins_omemo_plugin__context;
			g_rec_mutex_unlock (&__lock_dino_plugins_omemo_plugin_dino_plugins_omemo_plugin__context);
		}
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp11_;
	}
}

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

static Block5Data*
block5_data_ref (Block5Data* _data5_)
{
	g_atomic_int_inc (&_data5_->_ref_count_);
	return _data5_;
}

static void
block5_data_unref (void * _userdata_)
{
	Block5Data* _data5_;
	_data5_ = (Block5Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data5_->_ref_count_)) {
		DinoPluginsOmemoPlugin* self;
		self = _data5_->self;
		_g_object_unref0 (_data5_->app);
		_g_object_unref0 (self);
		g_slice_free (Block5Data, _data5_);
	}
}

static void
__lambda41_ (Block5Data* _data5_,
             DinoEntitiesAccount* account,
             GeeArrayList* list)
{
	DinoPluginsOmemoPlugin* self;
	OmemoStore* store = NULL;
	OmemoContext* _tmp0_;
	OmemoContext* _tmp1_;
	OmemoStore* _tmp2_;
	OmemoStore* _tmp3_;
	DinoPluginsOmemoStreamModule* _tmp4_;
	DinoPluginsOmemoStreamModule* _tmp5_;
	GeeHashMap* _tmp6_;
	DinoStreamInteractor* _tmp7_;
	DinoStreamInteractor* _tmp8_;
	DinoPluginsOmemoTrustManager* _tmp9_;
	DinoPluginsOmemoDatabase* _tmp10_;
	DinoPluginsOmemoOmemoDecryptor* _tmp11_;
	DinoPluginsOmemoOmemoDecryptor* _tmp12_;
	GeeHashMap* _tmp13_;
	gpointer _tmp14_;
	DinoPluginsOmemoOmemoDecryptor* _tmp15_;
	GeeHashMap* _tmp16_;
	DinoPluginsOmemoTrustManager* _tmp17_;
	DinoPluginsOmemoOmemoEncryptor* _tmp18_;
	DinoPluginsOmemoOmemoEncryptor* _tmp19_;
	GeeHashMap* _tmp20_;
	gpointer _tmp21_;
	DinoPluginsOmemoOmemoEncryptor* _tmp22_;
	DinoPluginsJetOmemoModule* _tmp23_;
	DinoPluginsJetOmemoModule* _tmp24_;
	DinoPluginsOmemoDtlsSrtpVerificationDraftStreamModule* _tmp25_;
	DinoPluginsOmemoDtlsSrtpVerificationDraftStreamModule* _tmp26_;
	DinoApplication* _tmp27_;
	DinoStreamInteractor* _tmp28_;
	DinoStreamInteractor* _tmp29_;
	DinoPluginsOmemoOwnNotifications* _tmp30_;
	self = _data5_->self;
	g_return_if_fail (account != NULL);
	g_return_if_fail (list != NULL);
	_tmp0_ = dino_plugins_omemo_plugin_get_context ();
	_tmp1_ = _tmp0_;
	_tmp2_ = omemo_context_create_store (_tmp1_);
	_tmp3_ = _tmp2_;
	_omemo_context_unref0 (_tmp1_);
	store = _tmp3_;
	_tmp4_ = dino_plugins_omemo_stream_module_new (store);
	_tmp5_ = _tmp4_;
	gee_abstract_collection_add ((GeeAbstractCollection*) list, (XmppXmppStreamModule*) _tmp5_);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = self->decryptors;
	_tmp7_ = dino_application_get_stream_interactor (_data5_->app);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->trust_manager;
	_tmp10_ = self->db;
	_tmp11_ = dino_plugins_omemo_omemo_decryptor_new (account, _tmp8_, _tmp9_, _tmp10_, store);
	_tmp12_ = _tmp11_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp6_, account, _tmp12_);
	_g_object_unref0 (_tmp12_);
	_tmp13_ = self->decryptors;
	_tmp14_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp13_, account);
	_tmp15_ = (DinoPluginsOmemoOmemoDecryptor*) _tmp14_;
	gee_abstract_collection_add ((GeeAbstractCollection*) list, (XmppXmppStreamModule*) _tmp15_);
	_g_object_unref0 (_tmp15_);
	_tmp16_ = self->encryptors;
	_tmp17_ = self->trust_manager;
	_tmp18_ = dino_plugins_omemo_omemo_encryptor_new (account, _tmp17_, store);
	_tmp19_ = _tmp18_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp16_, account, _tmp19_);
	_g_object_unref0 (_tmp19_);
	_tmp20_ = self->encryptors;
	_tmp21_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp20_, account);
	_tmp22_ = (DinoPluginsOmemoOmemoEncryptor*) _tmp21_;
	gee_abstract_collection_add ((GeeAbstractCollection*) list, (XmppXmppStreamModule*) _tmp22_);
	_g_object_unref0 (_tmp22_);
	_tmp23_ = dino_plugins_jet_omemo_module_new ();
	_tmp24_ = _tmp23_;
	gee_abstract_collection_add ((GeeAbstractCollection*) list, (XmppXmppStreamModule*) _tmp24_);
	_g_object_unref0 (_tmp24_);
	_tmp25_ = dino_plugins_omemo_dtls_srtp_verification_draft_stream_module_new ();
	_tmp26_ = _tmp25_;
	gee_abstract_collection_add ((GeeAbstractCollection*) list, (XmppXmppStreamModule*) _tmp26_);
	_g_object_unref0 (_tmp26_);
	_tmp27_ = self->app;
	_tmp28_ = dino_application_get_stream_interactor (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = dino_plugins_omemo_own_notifications_new (self, _tmp29_, account);
	_dino_plugins_omemo_own_notifications_unref0 (self->own_notifications);
	self->own_notifications = _tmp30_;
	_g_object_unref0 (store);
}

static void
___lambda41__dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                             DinoEntitiesAccount* account,
                                                             GeeArrayList* modules,
                                                             gpointer self)
{
	__lambda41_ (self, account, modules);
}

static void
dino_plugins_omemo_plugin_real_registered (DinoPluginsRootInterface* base,
                                           DinoApplication* app)
{
	DinoPluginsOmemoPlugin * self;
	Block5Data* _data5_;
	DinoApplication* _tmp0_;
	DinoApplication* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	DinoPluginsOmemoDatabase* _tmp6_;
	DinoPluginsOmemoEncryptionListEntry* _tmp7_;
	DinoPluginsOmemoContactDetailsProvider* _tmp8_;
	DinoApplication* _tmp9_;
	DinoStreamInteractor* _tmp10_;
	DinoStreamInteractor* _tmp11_;
	DinoPluginsOmemoDeviceNotificationPopulator* _tmp12_;
	DinoApplication* _tmp13_;
	DinoStreamInteractor* _tmp14_;
	DinoStreamInteractor* _tmp15_;
	DinoPluginsOmemoDatabase* _tmp16_;
	DinoPluginsOmemoTrustManager* _tmp17_;
	DinoApplication* _tmp18_;
	DinoPluginsRegistry* _tmp19_;
	DinoPluginsRegistry* _tmp20_;
	DinoPluginsOmemoEncryptionListEntry* _tmp21_;
	DinoApplication* _tmp22_;
	DinoPluginsRegistry* _tmp23_;
	DinoPluginsRegistry* _tmp24_;
	DinoPluginsOmemoOmemoPreferencesEntry* _tmp25_;
	DinoPluginsOmemoOmemoPreferencesEntry* _tmp26_;
	DinoApplication* _tmp27_;
	DinoPluginsRegistry* _tmp28_;
	DinoPluginsRegistry* _tmp29_;
	DinoPluginsOmemoContactDetailsProvider* _tmp30_;
	DinoApplication* _tmp31_;
	DinoPluginsRegistry* _tmp32_;
	DinoPluginsRegistry* _tmp33_;
	DinoPluginsOmemoDeviceNotificationPopulator* _tmp34_;
	DinoApplication* _tmp35_;
	DinoPluginsRegistry* _tmp36_;
	DinoPluginsRegistry* _tmp37_;
	DinoApplication* _tmp38_;
	DinoStreamInteractor* _tmp39_;
	DinoStreamInteractor* _tmp40_;
	DinoPluginsOmemoBadMessagesPopulator* _tmp41_;
	DinoPluginsOmemoBadMessagesPopulator* _tmp42_;
	DinoApplication* _tmp43_;
	DinoPluginsRegistry* _tmp44_;
	DinoPluginsRegistry* _tmp45_;
	DinoPluginsOmemoDatabase* _tmp46_;
	DinoPluginsOmemoCallEncryptionEntry* _tmp47_;
	DinoPluginsOmemoCallEncryptionEntry* _tmp48_;
	DinoApplication* _tmp49_;
	DinoStreamInteractor* _tmp50_;
	DinoStreamInteractor* _tmp51_;
	DinoModuleManager* _tmp52_;
	DinoStreamInteractor* _tmp53_;
	DinoStreamInteractor* _tmp54_;
	DinoModuleIdentity* _tmp55_;
	gpointer _tmp56_;
	DinoMessageProcessor* _tmp57_;
	DinoMessageListenerHolder* _tmp58_;
	GeeHashMap* _tmp59_;
	DinoPluginsOmemoDecryptMessageListener* _tmp60_;
	DinoPluginsOmemoDecryptMessageListener* _tmp61_;
	DinoStreamInteractor* _tmp62_;
	DinoStreamInteractor* _tmp63_;
	DinoModuleIdentity* _tmp64_;
	gpointer _tmp65_;
	DinoFileManager* _tmp66_;
	DinoPluginsOmemoOmemoFileDecryptor* _tmp67_;
	DinoPluginsOmemoOmemoFileDecryptor* _tmp68_;
	DinoStreamInteractor* _tmp69_;
	DinoStreamInteractor* _tmp70_;
	DinoModuleIdentity* _tmp71_;
	gpointer _tmp72_;
	DinoFileManager* _tmp73_;
	DinoPluginsOmemoOmemoFileEncryptor* _tmp74_;
	DinoPluginsOmemoOmemoFileEncryptor* _tmp75_;
	DinoJingleFileHelperRegistry* _tmp76_;
	DinoJingleFileHelperRegistry* _tmp77_;
	DinoStreamInteractor* _tmp78_;
	DinoStreamInteractor* _tmp79_;
	DinoPluginsJetOmemoEncryptionHelper* _tmp80_;
	DinoPluginsJetOmemoEncryptionHelper* _tmp81_;
	DinoApplication* _tmp82_;
	DinoStreamInteractor* _tmp83_;
	DinoStreamInteractor* _tmp84_;
	DinoPluginsOmemoDatabase* _tmp85_;
	DinoPluginsOmemoTrustManager* _tmp86_;
	GeeHashMap* _tmp87_;
	gchar* locales_dir = NULL;
	DinoSearchPathGenerator* _tmp88_;
	DinoSearchPathGenerator* _tmp89_;
	const gchar* _tmp94_;
	self = (DinoPluginsOmemoPlugin*) base;
	g_return_if_fail (app != NULL);
	_data5_ = g_slice_new0 (Block5Data);
	_data5_->_ref_count_ = 1;
	_data5_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (app);
	_g_object_unref0 (_data5_->app);
	_data5_->app = _tmp0_;
	dino_plugins_omemo_plugin_ensure_context ();
	_tmp1_ = _g_object_ref0 (_data5_->app);
	_g_object_unref0 (self->app);
	self->app = _tmp1_;
	_tmp2_ = dino_application_get_storage_dir ();
	_tmp3_ = _tmp2_;
	_tmp4_ = g_build_filename (_tmp3_, "omemo.db", NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = dino_plugins_omemo_database_new (_tmp5_);
	_qlite_database_unref0 (self->db);
	self->db = _tmp6_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_tmp7_ = dino_plugins_omemo_encryption_list_entry_new (self);
	_g_object_unref0 (self->list_entry);
	self->list_entry = _tmp7_;
	_tmp8_ = dino_plugins_omemo_contact_details_provider_new (self);
	_g_object_unref0 (self->contact_details_provider);
	self->contact_details_provider = _tmp8_;
	_tmp9_ = self->app;
	_tmp10_ = dino_application_get_stream_interactor (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = dino_plugins_omemo_device_notification_populator_new (self, _tmp11_);
	_g_object_unref0 (self->device_notification_populator);
	self->device_notification_populator = _tmp12_;
	_tmp13_ = self->app;
	_tmp14_ = dino_application_get_stream_interactor (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = self->db;
	_tmp17_ = dino_plugins_omemo_trust_manager_new (_tmp15_, _tmp16_);
	_dino_plugins_omemo_trust_manager_unref0 (self->trust_manager);
	self->trust_manager = _tmp17_;
	_tmp18_ = self->app;
	_tmp19_ = dino_application_get_plugin_registry (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = self->list_entry;
	dino_plugins_registry_register_encryption_list_entry (_tmp20_, (DinoPluginsEncryptionListEntry*) _tmp21_);
	_tmp22_ = self->app;
	_tmp23_ = dino_application_get_plugin_registry (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = dino_plugins_omemo_omemo_preferences_entry_new (self);
	_tmp26_ = _tmp25_;
	dino_plugins_registry_register_encryption_preferences_entry (_tmp24_, (DinoPluginsEncryptionPreferencesEntry*) _tmp26_);
	_g_object_unref0 (_tmp26_);
	_tmp27_ = self->app;
	_tmp28_ = dino_application_get_plugin_registry (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = self->contact_details_provider;
	dino_plugins_registry_register_contact_details_entry (_tmp29_, (DinoPluginsContactDetailsProvider*) _tmp30_);
	_tmp31_ = self->app;
	_tmp32_ = dino_application_get_plugin_registry (_tmp31_);
	_tmp33_ = _tmp32_;
	_tmp34_ = self->device_notification_populator;
	dino_plugins_registry_register_notification_populator (_tmp33_, (DinoPluginsNotificationPopulator*) _tmp34_);
	_tmp35_ = self->app;
	_tmp36_ = dino_application_get_plugin_registry (_tmp35_);
	_tmp37_ = _tmp36_;
	_tmp38_ = self->app;
	_tmp39_ = dino_application_get_stream_interactor (_tmp38_);
	_tmp40_ = _tmp39_;
	_tmp41_ = dino_plugins_omemo_bad_messages_populator_new (_tmp40_, self);
	_tmp42_ = _tmp41_;
	dino_plugins_registry_register_conversation_addition_populator (_tmp37_, (DinoPluginsConversationAdditionPopulator*) _tmp42_);
	_g_object_unref0 (_tmp42_);
	_tmp43_ = self->app;
	_tmp44_ = dino_application_get_plugin_registry (_tmp43_);
	_tmp45_ = _tmp44_;
	_tmp46_ = self->db;
	_tmp47_ = dino_plugins_omemo_call_encryption_entry_new (_tmp46_);
	_tmp48_ = _tmp47_;
	dino_plugins_registry_register_call_entryption_entry (_tmp45_, DINO_PLUGINS_OMEMO_DTLS_SRTP_VERIFICATION_DRAFT_NS_URI, (DinoPluginsCallEncryptionEntry*) _tmp48_);
	_g_object_unref0 (_tmp48_);
	_tmp49_ = self->app;
	_tmp50_ = dino_application_get_stream_interactor (_tmp49_);
	_tmp51_ = _tmp50_;
	_tmp52_ = _tmp51_->module_manager;
	g_signal_connect_data (_tmp52_, "initialize-account-modules", (GCallback) ___lambda41__dino_module_manager_initialize_account_modules, block5_data_ref (_data5_), (GClosureNotify) block5_data_unref, 0);
	_tmp53_ = dino_application_get_stream_interactor (_data5_->app);
	_tmp54_ = _tmp53_;
	_tmp55_ = dino_message_processor_IDENTITY;
	_tmp56_ = dino_stream_interactor_get_module (_tmp54_, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp55_);
	_tmp57_ = (DinoMessageProcessor*) _tmp56_;
	_tmp58_ = _tmp57_->received_pipeline;
	_tmp59_ = self->decryptors;
	_tmp60_ = dino_plugins_omemo_decrypt_message_listener_new (_tmp59_);
	_tmp61_ = _tmp60_;
	xmpp_listener_holder_connect ((XmppListenerHolder*) _tmp58_, (XmppOrderedListener*) _tmp61_);
	_g_object_unref0 (_tmp61_);
	_g_object_unref0 (_tmp57_);
	_tmp62_ = dino_application_get_stream_interactor (_data5_->app);
	_tmp63_ = _tmp62_;
	_tmp64_ = dino_file_manager_IDENTITY;
	_tmp65_ = dino_stream_interactor_get_module (_tmp63_, DINO_TYPE_FILE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp64_);
	_tmp66_ = (DinoFileManager*) _tmp65_;
	_tmp67_ = dino_plugins_omemo_omemo_file_decryptor_new ();
	_tmp68_ = _tmp67_;
	dino_file_manager_add_file_decryptor (_tmp66_, (DinoFileDecryptor*) _tmp68_);
	_g_object_unref0 (_tmp68_);
	_g_object_unref0 (_tmp66_);
	_tmp69_ = dino_application_get_stream_interactor (_data5_->app);
	_tmp70_ = _tmp69_;
	_tmp71_ = dino_file_manager_IDENTITY;
	_tmp72_ = dino_stream_interactor_get_module (_tmp70_, DINO_TYPE_FILE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp71_);
	_tmp73_ = (DinoFileManager*) _tmp72_;
	_tmp74_ = dino_plugins_omemo_omemo_file_encryptor_new ();
	_tmp75_ = _tmp74_;
	dino_file_manager_add_file_encryptor (_tmp73_, (DinoFileEncryptor*) _tmp75_);
	_g_object_unref0 (_tmp75_);
	_g_object_unref0 (_tmp73_);
	_tmp76_ = dino_jingle_file_helper_registry_get_instance ();
	_tmp77_ = _tmp76_;
	_tmp78_ = dino_application_get_stream_interactor (_data5_->app);
	_tmp79_ = _tmp78_;
	_tmp80_ = dino_plugins_jet_omemo_encryption_helper_new (_tmp79_);
	_tmp81_ = _tmp80_;
	dino_jingle_file_helper_registry_add_encryption_helper (_tmp77_, DINO_ENTITIES_ENCRYPTION_OMEMO, (DinoJingleFileEncryptionHelper*) _tmp81_);
	_g_object_unref0 (_tmp81_);
	_tmp82_ = self->app;
	_tmp83_ = dino_application_get_stream_interactor (_tmp82_);
	_tmp84_ = _tmp83_;
	_tmp85_ = self->db;
	_tmp86_ = self->trust_manager;
	_tmp87_ = self->encryptors;
	dino_plugins_omemo_manager_start (_tmp84_, _tmp85_, _tmp86_, _tmp87_);
	_tmp88_ = dino_application_get_search_path_generator (_data5_->app);
	_tmp89_ = _tmp88_;
	if (_tmp89_ != NULL) {
		DinoSearchPathGenerator* _tmp90_;
		DinoSearchPathGenerator* _tmp91_;
		gchar* _tmp92_;
		_tmp90_ = dino_application_get_search_path_generator (_data5_->app);
		_tmp91_ = _tmp90_;
		_tmp92_ = dino_search_path_generator_get_locale_path (G_TYPE_CHECK_INSTANCE_CAST (_tmp91_, DINO_TYPE_SEARCH_PATH_GENERATOR, DinoSearchPathGenerator), GETTEXT_PACKAGE, LOCALE_INSTALL_DIR);
		_g_free0 (locales_dir);
		locales_dir = _tmp92_;
	} else {
		gchar* _tmp93_;
		_tmp93_ = g_strdup (LOCALE_INSTALL_DIR);
		_g_free0 (locales_dir);
		locales_dir = _tmp93_;
	}
	_tmp94_ = locales_dir;
	dino_internationalize (GETTEXT_PACKAGE, _tmp94_);
	_g_free0 (locales_dir);
	block5_data_unref (_data5_);
	_data5_ = NULL;
}

static void
dino_plugins_omemo_plugin_real_shutdown (DinoPluginsRootInterface* base)
{
	DinoPluginsOmemoPlugin * self;
	self = (DinoPluginsOmemoPlugin*) base;
}

gboolean
dino_plugins_omemo_plugin_has_new_devices (DinoPluginsOmemoPlugin* 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_;
	XmppJid* _tmp8_;
	XmppJid* _tmp9_;
	XmppJid* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	QliteQueryBuilder* _tmp13_;
	QliteQueryBuilder* _tmp14_;
	gboolean _tmp15_;
	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->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->db;
	_tmp6_ = dino_plugins_omemo_database_get_identity_meta (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = xmpp_jid_get_bare_jid (jid);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	_tmp11_ = xmpp_jid_to_string (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = dino_plugins_omemo_database_identity_meta_table_get_new_devices (_tmp7_, identity_id, _tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = qlite_query_builder_count (_tmp14_) > ((gint64) 0);
	_qlite_statement_builder_unref0 (_tmp14_);
	_g_free0 (_tmp12_);
	_xmpp_jid_unref0 (_tmp10_);
	result = _tmp15_;
	return result;
}

DinoPluginsOmemoPlugin*
dino_plugins_omemo_plugin_construct (GType object_type)
{
	DinoPluginsOmemoPlugin * self = NULL;
	self = (DinoPluginsOmemoPlugin*) g_object_new (object_type, NULL);
	return self;
}

DinoPluginsOmemoPlugin*
dino_plugins_omemo_plugin_new (void)
{
	return dino_plugins_omemo_plugin_construct (DINO_PLUGINS_OMEMO_TYPE_PLUGIN);
}

static void
dino_plugins_omemo_plugin_class_init (DinoPluginsOmemoPluginClass * klass,
                                      gpointer klass_data)
{
	dino_plugins_omemo_plugin_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_omemo_plugin_finalize;
	g_rec_mutex_init (&__lock_dino_plugins_omemo_plugin_dino_plugins_omemo_plugin__context);
}

static void
dino_plugins_omemo_plugin_dino_plugins_root_interface_interface_init (DinoPluginsRootInterfaceIface * iface,
                                                                      gpointer iface_data)
{
	dino_plugins_omemo_plugin_dino_plugins_root_interface_parent_iface = g_type_interface_peek_parent (iface);
	iface->registered = (void (*) (DinoPluginsRootInterface*, DinoApplication*)) dino_plugins_omemo_plugin_real_registered;
	iface->shutdown = (void (*) (DinoPluginsRootInterface*)) dino_plugins_omemo_plugin_real_shutdown;
}

static void
dino_plugins_omemo_plugin_instance_init (DinoPluginsOmemoPlugin * self,
                                         gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, DINO_PLUGINS_OMEMO_TYPE_OMEMO_DECRYPTOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->decryptors = _tmp0_;
	_tmp1_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, DINO_PLUGINS_OMEMO_TYPE_OMEMO_ENCRYPTOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->encryptors = _tmp1_;
}

static void
dino_plugins_omemo_plugin_finalize (GObject * obj)
{
	DinoPluginsOmemoPlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_PLUGIN, DinoPluginsOmemoPlugin);
	_g_object_unref0 (self->app);
	_qlite_database_unref0 (self->db);
	_g_object_unref0 (self->list_entry);
	_g_object_unref0 (self->contact_details_provider);
	_g_object_unref0 (self->device_notification_populator);
	_dino_plugins_omemo_own_notifications_unref0 (self->own_notifications);
	_dino_plugins_omemo_trust_manager_unref0 (self->trust_manager);
	_g_object_unref0 (self->decryptors);
	_g_object_unref0 (self->encryptors);
	G_OBJECT_CLASS (dino_plugins_omemo_plugin_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_plugin_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoPlugin), 0, (GInstanceInitFunc) dino_plugins_omemo_plugin_instance_init, NULL };
	static const GInterfaceInfo dino_plugins_root_interface_info = { (GInterfaceInitFunc) dino_plugins_omemo_plugin_dino_plugins_root_interface_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_omemo_plugin_type_id;
	dino_plugins_omemo_plugin_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOmemoPlugin", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_omemo_plugin_type_id, DINO_PLUGINS_TYPE_ROOT_INTERFACE, &dino_plugins_root_interface_info);
	return dino_plugins_omemo_plugin_type_id;
}

GType
dino_plugins_omemo_plugin_get_type (void)
{
	static volatile gsize dino_plugins_omemo_plugin_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_plugin_type_id__once)) {
		GType dino_plugins_omemo_plugin_type_id;
		dino_plugins_omemo_plugin_type_id = dino_plugins_omemo_plugin_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_plugin_type_id__once, dino_plugins_omemo_plugin_type_id);
	}
	return dino_plugins_omemo_plugin_type_id__once;
}

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

