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

#include "openpgp.h"
#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gpgme.h>
#include <gpgme_fix.h>
#include <gio/gio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER (dino_plugins_open_pgp_manager_received_message_listener_get_type ())
#define DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER, DinoPluginsOpenPgpManagerReceivedMessageListener))
#define DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER, DinoPluginsOpenPgpManagerReceivedMessageListenerClass))
#define DINO_PLUGINS_OPEN_PGP_MANAGER_IS_RECEIVED_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER))
#define DINO_PLUGINS_OPEN_PGP_MANAGER_IS_RECEIVED_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER))
#define DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER, DinoPluginsOpenPgpManagerReceivedMessageListenerClass))

typedef struct _DinoPluginsOpenPgpManagerReceivedMessageListener DinoPluginsOpenPgpManagerReceivedMessageListener;
typedef struct _DinoPluginsOpenPgpManagerReceivedMessageListenerClass DinoPluginsOpenPgpManagerReceivedMessageListenerClass;
enum  {
	DINO_PLUGINS_OPEN_PGP_MANAGER_0_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_MANAGER_ID_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_MANAGER_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_open_pgp_manager_properties[DINO_PLUGINS_OPEN_PGP_MANAGER_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 _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _gpgme_key_unref_vapi0(var) ((var == NULL) ? NULL : (var = (gpgme_key_unref_vapi (var), NULL)))
typedef struct _Block3Data Block3Data;
typedef struct _DinoPluginsOpenPgpManagerReceivedMessageListenerPrivate DinoPluginsOpenPgpManagerReceivedMessageListenerPrivate;
enum  {
	DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_0_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_open_pgp_manager_received_message_listener_properties[DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_NUM_PROPERTIES];
typedef struct _DinoPluginsOpenPgpManagerReceivedMessageListenerRunData DinoPluginsOpenPgpManagerReceivedMessageListenerRunData;

struct _DinoPluginsOpenPgpManagerPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoPluginsOpenPgpDatabase* db;
	GeeHashMap* pgp_key_ids;
	GRecMutex __lock_pgp_key_ids;
	DinoPluginsOpenPgpManagerReceivedMessageListener* received_message_listener;
};

struct _Block3Data {
	int _ref_count_;
	DinoPluginsOpenPgpManager* self;
	DinoEntitiesAccount* account;
};

struct _DinoPluginsOpenPgpManagerReceivedMessageListener {
	DinoMessageListener parent_instance;
	DinoPluginsOpenPgpManagerReceivedMessageListenerPrivate * priv;
	gchar** after_actions_const;
	gint after_actions_const_length1;
	gint _after_actions_const_size_;
};

struct _DinoPluginsOpenPgpManagerReceivedMessageListenerClass {
	DinoMessageListenerClass parent_class;
};

struct _DinoPluginsOpenPgpManagerReceivedMessageListenerRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoPluginsOpenPgpManagerReceivedMessageListener* self;
	DinoEntitiesMessage* message;
	XmppMessageStanza* stanza;
	DinoEntitiesConversation* conversation;
	gboolean result;
	gboolean _tmp0_;
	DinoPluginsOpenPgpMessageFlag* _tmp1_;
	DinoPluginsOpenPgpMessageFlag* _tmp2_;
	gboolean _tmp3_;
	DinoPluginsOpenPgpMessageFlag* _tmp4_;
	DinoPluginsOpenPgpMessageFlag* _tmp5_;
};

static gint DinoPluginsOpenPgpManager_private_offset;
static gpointer dino_plugins_open_pgp_manager_parent_class = NULL;
DinoModuleIdentity* dino_plugins_open_pgp_manager_IDENTITY = NULL;
static gpointer dino_plugins_open_pgp_manager_received_message_listener_parent_class = NULL;
static DinoStreamInteractionModuleIface * dino_plugins_open_pgp_manager_dino_stream_interaction_module_parent_iface = NULL;

static GType dino_plugins_open_pgp_manager_received_message_listener_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static guint _xmpp_jid_hash_bare_func_gee_hash_data_func (gconstpointer v,
                                                   gpointer self);
static gboolean _xmpp_jid_equals_bare_func_gee_equal_data_func (gconstpointer a,
                                                         gconstpointer b,
                                                         gpointer self);
static DinoPluginsOpenPgpManagerReceivedMessageListener* dino_plugins_open_pgp_manager_received_message_listener_new (void);
static DinoPluginsOpenPgpManagerReceivedMessageListener* dino_plugins_open_pgp_manager_received_message_listener_construct (GType object_type);
static DinoPluginsOpenPgpManager* dino_plugins_open_pgp_manager_new (DinoStreamInteractor* stream_interactor,
                                                              DinoPluginsOpenPgpDatabase* db);
static DinoPluginsOpenPgpManager* dino_plugins_open_pgp_manager_construct (GType object_type,
                                                                    DinoStreamInteractor* stream_interactor,
                                                                    DinoPluginsOpenPgpDatabase* db);
static void dino_plugins_open_pgp_manager_on_account_added (DinoPluginsOpenPgpManager* self,
                                                     DinoEntitiesAccount* account);
static void _dino_plugins_open_pgp_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                           DinoEntitiesAccount* account,
                                                                                           gpointer self);
static void dino_plugins_open_pgp_manager_check_encypt (DinoPluginsOpenPgpManager* self,
                                                 DinoEntitiesMessage* message,
                                                 XmppMessageStanza* message_stanza,
                                                 DinoEntitiesConversation* conversation);
static void _dino_plugins_open_pgp_manager_check_encypt_dino_message_processor_pre_message_send (DinoMessageProcessor* _sender,
                                                                                          DinoEntitiesMessage* message,
                                                                                          XmppMessageStanza* message_stanza,
                                                                                          DinoEntitiesConversation* conversation,
                                                                                          gpointer self);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda7_ (Block3Data* _data3_,
                 XmppXmppStream* stream,
                 XmppJid* jid,
                 const gchar* key_id);
static void dino_plugins_open_pgp_manager_on_jid_key_received (DinoPluginsOpenPgpManager* self,
                                                        DinoEntitiesAccount* account,
                                                        XmppJid* jid,
                                                        const gchar* key_id);
static void ___lambda7__dino_plugins_open_pgp_module_received_jid_key_id (DinoPluginsOpenPgpModule* _sender,
                                                                   XmppXmppStream* stream,
                                                                   XmppJid* jid,
                                                                   const gchar* key_id,
                                                                   gpointer self);
static void dino_plugins_open_pgp_manager_received_message_listener_real_run_data_free (gpointer _data);
static void dino_plugins_open_pgp_manager_received_message_listener_real_run (DinoMessageListener* base,
                                                                       DinoEntitiesMessage* message,
                                                                       XmppMessageStanza* stanza,
                                                                       DinoEntitiesConversation* conversation,
                                                                       GAsyncReadyCallback _callback_,
                                                                       gpointer _user_data_);
static gboolean dino_plugins_open_pgp_manager_received_message_listener_real_run_co (DinoPluginsOpenPgpManagerReceivedMessageListenerRunData* _data_);
static void dino_plugins_open_pgp_manager_received_message_listener_finalize (GObject * obj);
static GType dino_plugins_open_pgp_manager_received_message_listener_get_type_once (void);
static void _vala_dino_plugins_open_pgp_manager_received_message_listener_get_property (GObject * object,
                                                                                 guint property_id,
                                                                                 GValue * value,
                                                                                 GParamSpec * pspec);
static void dino_plugins_open_pgp_manager_finalize (GObject * obj);
static GType dino_plugins_open_pgp_manager_get_type_once (void);
static void _vala_dino_plugins_open_pgp_manager_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_plugins_open_pgp_manager_get_instance_private (DinoPluginsOpenPgpManager* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOpenPgpManager_private_offset);
}

static guint
_xmpp_jid_hash_bare_func_gee_hash_data_func (gconstpointer v,
                                             gpointer self)
{
	guint result;
	result = xmpp_jid_hash_bare_func ((XmppJid*) v);
	return result;
}

static gboolean
_xmpp_jid_equals_bare_func_gee_equal_data_func (gconstpointer a,
                                                gconstpointer b,
                                                gpointer self)
{
	gboolean result;
	result = xmpp_jid_equals_bare_func ((XmppJid*) a, (XmppJid*) b);
	return result;
}

void
dino_plugins_open_pgp_manager_start (DinoStreamInteractor* stream_interactor,
                                     DinoPluginsOpenPgpDatabase* db)
{
	DinoPluginsOpenPgpManager* m = NULL;
	DinoPluginsOpenPgpManager* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_plugins_open_pgp_manager_new (stream_interactor, db);
	m = _tmp0_;
	dino_stream_interactor_add_module (stream_interactor, (DinoStreamInteractionModule*) m);
	_g_object_unref0 (m);
}

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

static void
_dino_plugins_open_pgp_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                      DinoEntitiesAccount* account,
                                                                                      gpointer self)
{
	dino_plugins_open_pgp_manager_on_account_added ((DinoPluginsOpenPgpManager*) self, account);
}

static void
_dino_plugins_open_pgp_manager_check_encypt_dino_message_processor_pre_message_send (DinoMessageProcessor* _sender,
                                                                                     DinoEntitiesMessage* message,
                                                                                     XmppMessageStanza* message_stanza,
                                                                                     DinoEntitiesConversation* conversation,
                                                                                     gpointer self)
{
	dino_plugins_open_pgp_manager_check_encypt ((DinoPluginsOpenPgpManager*) self, message, message_stanza, conversation);
}

static DinoPluginsOpenPgpManager*
dino_plugins_open_pgp_manager_construct (GType object_type,
                                         DinoStreamInteractor* stream_interactor,
                                         DinoPluginsOpenPgpDatabase* db)
{
	DinoPluginsOpenPgpManager * self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoPluginsOpenPgpDatabase* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoMessageProcessor* _tmp4_;
	DinoMessageListenerHolder* _tmp5_;
	DinoPluginsOpenPgpManagerReceivedMessageListener* _tmp6_;
	DinoModuleIdentity* _tmp7_;
	gpointer _tmp8_;
	DinoMessageProcessor* _tmp9_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOpenPgpManager*) g_object_new (object_type, NULL);
	_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_;
	g_signal_connect_object (stream_interactor, "account-added", (GCallback) _dino_plugins_open_pgp_manager_on_account_added_dino_stream_interactor_account_added, self, 0);
	_tmp2_ = dino_message_processor_IDENTITY;
	_tmp3_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
	_tmp4_ = (DinoMessageProcessor*) _tmp3_;
	_tmp5_ = _tmp4_->received_pipeline;
	_tmp6_ = self->priv->received_message_listener;
	xmpp_listener_holder_connect ((XmppListenerHolder*) _tmp5_, (XmppOrderedListener*) _tmp6_);
	_g_object_unref0 (_tmp4_);
	_tmp7_ = dino_message_processor_IDENTITY;
	_tmp8_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp7_);
	_tmp9_ = (DinoMessageProcessor*) _tmp8_;
	g_signal_connect_object (_tmp9_, "pre-message-send", (GCallback) _dino_plugins_open_pgp_manager_check_encypt_dino_message_processor_pre_message_send, self, 0);
	_g_object_unref0 (_tmp9_);
	return self;
}

static DinoPluginsOpenPgpManager*
dino_plugins_open_pgp_manager_new (DinoStreamInteractor* stream_interactor,
                                   DinoPluginsOpenPgpDatabase* db)
{
	return dino_plugins_open_pgp_manager_construct (DINO_PLUGINS_OPEN_PGP_TYPE_MANAGER, stream_interactor, db);
}

static gpointer
_gpgme_key_ref_vapi0 (gpointer self)
{
	return self ? gpgme_key_ref_vapi (self) : NULL;
}

struct _gpgme_key**
dino_plugins_open_pgp_manager_get_key_fprs (DinoPluginsOpenPgpManager* self,
                                            DinoEntitiesConversation* conversation,
                                            gint* result_length1,
                                            GError** error)
{
	GeeList* keys = NULL;
	GeeArrayList* _tmp0_;
	GeeList* _tmp1_;
	DinoPluginsOpenPgpDatabase* _tmp2_;
	DinoEntitiesAccount* _tmp3_;
	DinoEntitiesAccount* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	DinoEntitiesConversationType _tmp7_;
	DinoEntitiesConversationType _tmp8_;
	struct _gpgme_key** gpgkeys = NULL;
	GeeList* _tmp73_;
	gint _tmp74_;
	gint _tmp75_;
	struct _gpgme_key** _tmp76_;
	gint gpgkeys_length1;
	gint _gpgkeys_size_;
	struct _gpgme_key** _tmp91_;
	gint _tmp91__length1;
	GError* _inner_error0_ = NULL;
	struct _gpgme_key** result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	keys = (GeeList*) _tmp0_;
	_tmp1_ = keys;
	_tmp2_ = self->priv->db;
	_tmp3_ = dino_entities_conversation_get_account (conversation);
	_tmp4_ = _tmp3_;
	_tmp5_ = dino_plugins_open_pgp_database_get_account_key (_tmp2_, _tmp4_);
	_tmp6_ = _tmp5_;
	gee_collection_add ((GeeCollection*) _tmp1_, _tmp6_);
	_g_free0 (_tmp6_);
	_tmp7_ = dino_entities_conversation_get_type_ (conversation);
	_tmp8_ = _tmp7_;
	if (_tmp8_ == DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT) {
		GeeList* muc_jids = NULL;
		GeeArrayList* _tmp9_;
		GeeList* occupants = NULL;
		DinoStreamInteractor* _tmp10_;
		DinoModuleIdentity* _tmp11_;
		gpointer _tmp12_;
		DinoMucManager* _tmp13_;
		XmppJid* _tmp14_;
		XmppJid* _tmp15_;
		DinoEntitiesAccount* _tmp16_;
		DinoEntitiesAccount* _tmp17_;
		GeeList* _tmp18_;
		GeeList* _tmp19_;
		GeeList* _tmp20_;
		GeeList* offline_members = NULL;
		DinoStreamInteractor* _tmp23_;
		DinoModuleIdentity* _tmp24_;
		gpointer _tmp25_;
		DinoMucManager* _tmp26_;
		XmppJid* _tmp27_;
		XmppJid* _tmp28_;
		DinoEntitiesAccount* _tmp29_;
		DinoEntitiesAccount* _tmp30_;
		GeeList* _tmp31_;
		GeeList* _tmp32_;
		GeeList* _tmp33_;
		_tmp9_ = gee_array_list_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, NULL, NULL, NULL);
		muc_jids = (GeeList*) _tmp9_;
		_tmp10_ = self->priv->stream_interactor;
		_tmp11_ = dino_muc_manager_IDENTITY;
		_tmp12_ = dino_stream_interactor_get_module (_tmp10_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp11_);
		_tmp13_ = (DinoMucManager*) _tmp12_;
		_tmp14_ = dino_entities_conversation_get_counterpart (conversation);
		_tmp15_ = _tmp14_;
		_tmp16_ = dino_entities_conversation_get_account (conversation);
		_tmp17_ = _tmp16_;
		_tmp18_ = dino_muc_manager_get_occupants (_tmp13_, _tmp15_, _tmp17_);
		_tmp19_ = _tmp18_;
		_g_object_unref0 (_tmp13_);
		occupants = _tmp19_;
		_tmp20_ = occupants;
		if (_tmp20_ != NULL) {
			GeeList* _tmp21_;
			GeeList* _tmp22_;
			_tmp21_ = muc_jids;
			_tmp22_ = occupants;
			gee_collection_add_all ((GeeCollection*) _tmp21_, (GeeCollection*) _tmp22_);
		}
		_tmp23_ = self->priv->stream_interactor;
		_tmp24_ = dino_muc_manager_IDENTITY;
		_tmp25_ = dino_stream_interactor_get_module (_tmp23_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp24_);
		_tmp26_ = (DinoMucManager*) _tmp25_;
		_tmp27_ = dino_entities_conversation_get_counterpart (conversation);
		_tmp28_ = _tmp27_;
		_tmp29_ = dino_entities_conversation_get_account (conversation);
		_tmp30_ = _tmp29_;
		_tmp31_ = dino_muc_manager_get_offline_members (_tmp26_, _tmp28_, _tmp30_);
		_tmp32_ = _tmp31_;
		_g_object_unref0 (_tmp26_);
		offline_members = _tmp32_;
		_tmp33_ = occupants;
		if (_tmp33_ != NULL) {
			GeeList* _tmp34_;
			GeeList* _tmp35_;
			_tmp34_ = muc_jids;
			_tmp35_ = offline_members;
			gee_collection_add_all ((GeeCollection*) _tmp34_, (GeeCollection*) _tmp35_);
		}
		{
			GeeList* _jid_list = NULL;
			GeeList* _tmp36_;
			gint _jid_size = 0;
			GeeList* _tmp37_;
			gint _tmp38_;
			gint _tmp39_;
			gint _jid_index = 0;
			_tmp36_ = muc_jids;
			_jid_list = _tmp36_;
			_tmp37_ = _jid_list;
			_tmp38_ = gee_collection_get_size ((GeeCollection*) _tmp37_);
			_tmp39_ = _tmp38_;
			_jid_size = _tmp39_;
			_jid_index = -1;
			while (TRUE) {
				gint _tmp40_;
				gint _tmp41_;
				XmppJid* jid = NULL;
				GeeList* _tmp42_;
				gpointer _tmp43_;
				gchar* key_id = NULL;
				DinoStreamInteractor* _tmp44_;
				DinoModuleIdentity* _tmp45_;
				gpointer _tmp46_;
				DinoPluginsOpenPgpManager* _tmp47_;
				DinoEntitiesAccount* _tmp48_;
				DinoEntitiesAccount* _tmp49_;
				XmppJid* _tmp50_;
				gchar* _tmp51_;
				gchar* _tmp52_;
				gboolean _tmp53_ = FALSE;
				gboolean _tmp54_ = FALSE;
				const gchar* _tmp55_;
				_jid_index = _jid_index + 1;
				_tmp40_ = _jid_index;
				_tmp41_ = _jid_size;
				if (!(_tmp40_ < _tmp41_)) {
					break;
				}
				_tmp42_ = _jid_list;
				_tmp43_ = gee_list_get (_tmp42_, _jid_index);
				jid = (XmppJid*) _tmp43_;
				_tmp44_ = self->priv->stream_interactor;
				_tmp45_ = dino_plugins_open_pgp_manager_IDENTITY;
				_tmp46_ = dino_stream_interactor_get_module (_tmp44_, DINO_PLUGINS_OPEN_PGP_TYPE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp45_);
				_tmp47_ = (DinoPluginsOpenPgpManager*) _tmp46_;
				_tmp48_ = dino_entities_conversation_get_account (conversation);
				_tmp49_ = _tmp48_;
				_tmp50_ = jid;
				_tmp51_ = dino_plugins_open_pgp_manager_get_key_id (_tmp47_, _tmp49_, _tmp50_);
				_tmp52_ = _tmp51_;
				_g_object_unref0 (_tmp47_);
				key_id = _tmp52_;
				_tmp55_ = key_id;
				if (_tmp55_ != NULL) {
					GeeList* _tmp56_ = NULL;
					const gchar* _tmp57_;
					GeeList* _tmp58_;
					gint _tmp59_;
					gint _tmp60_;
					_tmp57_ = key_id;
					_tmp58_ = gpg_helper_get_keylist (_tmp57_, FALSE, &_inner_error0_);
					_tmp56_ = _tmp58_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						g_propagate_error (error, _inner_error0_);
						_g_free0 (key_id);
						_xmpp_jid_unref0 (jid);
						_g_object_unref0 (offline_members);
						_g_object_unref0 (occupants);
						_g_object_unref0 (muc_jids);
						_g_object_unref0 (keys);
						return NULL;
					}
					_tmp59_ = gee_collection_get_size ((GeeCollection*) _tmp56_);
					_tmp60_ = _tmp59_;
					_tmp54_ = _tmp60_ > 0;
					_g_object_unref0 (_tmp56_);
				} else {
					_tmp54_ = FALSE;
				}
				if (_tmp54_) {
					GeeList* _tmp61_;
					const gchar* _tmp62_;
					_tmp61_ = keys;
					_tmp62_ = key_id;
					_tmp53_ = !gee_collection_contains ((GeeCollection*) _tmp61_, _tmp62_);
				} else {
					_tmp53_ = FALSE;
				}
				if (_tmp53_) {
					GeeList* _tmp63_;
					const gchar* _tmp64_;
					_tmp63_ = keys;
					_tmp64_ = key_id;
					gee_collection_add ((GeeCollection*) _tmp63_, _tmp64_);
				}
				_g_free0 (key_id);
				_xmpp_jid_unref0 (jid);
			}
		}
		_g_object_unref0 (offline_members);
		_g_object_unref0 (occupants);
		_g_object_unref0 (muc_jids);
	} else {
		gchar* key_id = NULL;
		DinoEntitiesAccount* _tmp65_;
		DinoEntitiesAccount* _tmp66_;
		XmppJid* _tmp67_;
		XmppJid* _tmp68_;
		gchar* _tmp69_;
		const gchar* _tmp70_;
		_tmp65_ = dino_entities_conversation_get_account (conversation);
		_tmp66_ = _tmp65_;
		_tmp67_ = dino_entities_conversation_get_counterpart (conversation);
		_tmp68_ = _tmp67_;
		_tmp69_ = dino_plugins_open_pgp_manager_get_key_id (self, _tmp66_, _tmp68_);
		key_id = _tmp69_;
		_tmp70_ = key_id;
		if (_tmp70_ != NULL) {
			GeeList* _tmp71_;
			const gchar* _tmp72_;
			_tmp71_ = keys;
			_tmp72_ = key_id;
			gee_collection_add ((GeeCollection*) _tmp71_, _tmp72_);
		}
		_g_free0 (key_id);
	}
	_tmp73_ = keys;
	_tmp74_ = gee_collection_get_size ((GeeCollection*) _tmp73_);
	_tmp75_ = _tmp74_;
	_tmp76_ = g_new0 (struct _gpgme_key*, _tmp75_ + 1);
	gpgkeys = _tmp76_;
	gpgkeys_length1 = _tmp75_;
	_gpgkeys_size_ = gpgkeys_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp77_ = FALSE;
			_tmp77_ = TRUE;
			while (TRUE) {
				GeeList* _tmp79_;
				gint _tmp80_;
				gint _tmp81_;
				if (!_tmp77_) {
					gint _tmp78_;
					_tmp78_ = i;
					i = _tmp78_ + 1;
				}
				_tmp77_ = FALSE;
				_tmp79_ = keys;
				_tmp80_ = gee_collection_get_size ((GeeCollection*) _tmp79_);
				_tmp81_ = _tmp80_;
				if (!(i < _tmp81_)) {
					break;
				}
				{
					struct _gpgme_key* key = NULL;
					GeeList* _tmp82_;
					gpointer _tmp83_;
					gchar* _tmp84_;
					struct _gpgme_key* _tmp85_;
					struct _gpgme_key* _tmp86_;
					struct _gpgme_key* _tmp87_;
					_tmp82_ = keys;
					_tmp83_ = gee_list_get (_tmp82_, i);
					_tmp84_ = (gchar*) _tmp83_;
					_tmp85_ = gpg_helper_get_public_key (_tmp84_, &_inner_error0_);
					_tmp86_ = _tmp85_;
					_g_free0 (_tmp84_);
					key = _tmp86_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch0_g_error;
					}
					_tmp87_ = key;
					if (_tmp87_ != NULL) {
						struct _gpgme_key** _tmp88_;
						gint _tmp88__length1;
						struct _gpgme_key* _tmp89_;
						struct _gpgme_key* _tmp90_;
						_tmp88_ = gpgkeys;
						_tmp88__length1 = gpgkeys_length1;
						_tmp89_ = key;
						_tmp90_ = _gpgme_key_ref_vapi0 (_tmp89_);
						_gpgme_key_unref_vapi0 (_tmp88_[i]);
						_tmp88_[i] = _tmp90_;
					}
					_gpgme_key_unref_vapi0 (key);
				}
				goto __finally0;
				__catch0_g_error:
				{
					g_clear_error (&_inner_error0_);
				}
				__finally0:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					gpgkeys = (_vala_array_free (gpgkeys, gpgkeys_length1, (GDestroyNotify) gpgme_key_unref_vapi), NULL);
					_g_object_unref0 (keys);
					return NULL;
				}
			}
		}
	}
	_tmp91_ = gpgkeys;
	_tmp91__length1 = gpgkeys_length1;
	if (result_length1) {
		*result_length1 = _tmp91__length1;
	}
	result = _tmp91_;
	_g_object_unref0 (keys);
	return result;
}

static void
dino_plugins_open_pgp_manager_check_encypt (DinoPluginsOpenPgpManager* self,
                                            DinoEntitiesMessage* message,
                                            XmppMessageStanza* message_stanza,
                                            DinoEntitiesConversation* conversation)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	g_return_if_fail (message_stanza != NULL);
	g_return_if_fail (conversation != NULL);
	{
		DinoEntitiesEncryption _tmp0_;
		DinoEntitiesEncryption _tmp1_;
		_tmp0_ = dino_entities_message_get_encryption (message);
		_tmp1_ = _tmp0_;
		if (_tmp1_ == DINO_ENTITIES_ENCRYPTION_PGP) {
			struct _gpgme_key** keys = NULL;
			gint _tmp2_ = 0;
			struct _gpgme_key** _tmp3_;
			gint keys_length1;
			gint _keys_size_;
			XmppXmppStream* stream = NULL;
			DinoStreamInteractor* _tmp4_;
			DinoEntitiesAccount* _tmp5_;
			DinoEntitiesAccount* _tmp6_;
			XmppXmppStream* _tmp7_;
			XmppXmppStream* _tmp8_;
			_tmp3_ = dino_plugins_open_pgp_manager_get_key_fprs (self, conversation, &_tmp2_, &_inner_error0_);
			keys = _tmp3_;
			keys_length1 = _tmp2_;
			_keys_size_ = keys_length1;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp4_ = self->priv->stream_interactor;
			_tmp5_ = dino_entities_conversation_get_account (conversation);
			_tmp6_ = _tmp5_;
			_tmp7_ = dino_stream_interactor_get_stream (_tmp4_, _tmp6_);
			stream = _tmp7_;
			_tmp8_ = stream;
			if (_tmp8_ != NULL) {
				gboolean encrypted = FALSE;
				XmppXmppStream* _tmp9_;
				XmppModuleIdentity* _tmp10_;
				gpointer _tmp11_;
				DinoPluginsOpenPgpModule* _tmp12_;
				struct _gpgme_key** _tmp13_;
				gint _tmp13__length1;
				gboolean _tmp14_;
				_tmp9_ = stream;
				_tmp10_ = dino_plugins_open_pgp_module_IDENTITY;
				_tmp11_ = xmpp_xmpp_stream_get_module (_tmp9_, DINO_PLUGINS_OPEN_PGP_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp10_);
				_tmp12_ = (DinoPluginsOpenPgpModule*) _tmp11_;
				_tmp13_ = keys;
				_tmp13__length1 = keys_length1;
				_tmp14_ = dino_plugins_open_pgp_module_encrypt (_tmp12_, message_stanza, _tmp13_, (gint) _tmp13__length1);
				_g_object_unref0 (_tmp12_);
				encrypted = _tmp14_;
				if (!encrypted) {
					dino_entities_message_set_marked (message, DINO_ENTITIES_MESSAGE_MARKED_WONTSEND);
				}
			}
			_g_object_unref0 (stream);
			keys = (_vala_array_free (keys, keys_length1, (GDestroyNotify) gpgme_key_unref_vapi), NULL);
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		dino_entities_message_set_marked (message, DINO_ENTITIES_MESSAGE_MARKED_WONTSEND);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

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

gchar*
dino_plugins_open_pgp_manager_get_key_id (DinoPluginsOpenPgpManager* self,
                                          DinoEntitiesAccount* account,
                                          XmppJid* jid)
{
	XmppJid* _tmp0_ = NULL;
	DinoStreamInteractor* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoMucManager* _tmp4_;
	gboolean _tmp5_;
	XmppJid* search_jid = NULL;
	XmppJid* _tmp9_;
	DinoPluginsOpenPgpDatabase* _tmp10_;
	gchar* _tmp11_;
	gchar* 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);
	_tmp1_ = self->priv->stream_interactor;
	_tmp2_ = dino_muc_manager_IDENTITY;
	_tmp3_ = dino_stream_interactor_get_module (_tmp1_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
	_tmp4_ = (DinoMucManager*) _tmp3_;
	_tmp5_ = dino_muc_manager_is_groupchat_occupant (_tmp4_, jid, account);
	_g_object_unref0 (_tmp4_);
	if (_tmp5_) {
		XmppJid* _tmp6_;
		_tmp6_ = _xmpp_jid_ref0 (jid);
		_xmpp_jid_unref0 (_tmp0_);
		_tmp0_ = _tmp6_;
	} else {
		XmppJid* _tmp7_;
		XmppJid* _tmp8_;
		_tmp7_ = xmpp_jid_get_bare_jid (jid);
		_tmp8_ = _tmp7_;
		_xmpp_jid_unref0 (_tmp0_);
		_tmp0_ = _tmp8_;
	}
	_tmp9_ = _tmp0_;
	_tmp0_ = NULL;
	search_jid = _tmp9_;
	_tmp10_ = self->priv->db;
	_tmp11_ = dino_plugins_open_pgp_database_get_contact_key (_tmp10_, search_jid);
	result = _tmp11_;
	_xmpp_jid_unref0 (search_jid);
	_xmpp_jid_unref0 (_tmp0_);
	return result;
}

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		DinoPluginsOpenPgpManager* self;
		self = _data3_->self;
		_g_object_unref0 (_data3_->account);
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}

static void
__lambda7_ (Block3Data* _data3_,
            XmppXmppStream* stream,
            XmppJid* jid,
            const gchar* key_id)
{
	DinoPluginsOpenPgpManager* self;
	self = _data3_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (key_id != NULL);
	dino_plugins_open_pgp_manager_on_jid_key_received (self, _data3_->account, jid, key_id);
}

static void
___lambda7__dino_plugins_open_pgp_module_received_jid_key_id (DinoPluginsOpenPgpModule* _sender,
                                                              XmppXmppStream* stream,
                                                              XmppJid* jid,
                                                              const gchar* key_id,
                                                              gpointer self)
{
	__lambda7_ (self, stream, jid, key_id);
}

static void
dino_plugins_open_pgp_manager_on_account_added (DinoPluginsOpenPgpManager* self,
                                                DinoEntitiesAccount* account)
{
	Block3Data* _data3_;
	DinoEntitiesAccount* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoModuleManager* _tmp2_;
	XmppModuleIdentity* _tmp3_;
	gpointer _tmp4_;
	DinoPluginsOpenPgpModule* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_data3_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (_data3_->account);
	_data3_->account = _tmp0_;
	_tmp1_ = self->priv->stream_interactor;
	_tmp2_ = _tmp1_->module_manager;
	_tmp3_ = dino_plugins_open_pgp_module_IDENTITY;
	_tmp4_ = dino_module_manager_get_module (_tmp2_, DINO_PLUGINS_OPEN_PGP_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data3_->account, _tmp3_);
	_tmp5_ = (DinoPluginsOpenPgpModule*) _tmp4_;
	g_signal_connect_data (_tmp5_, "received-jid-key-id", (GCallback) ___lambda7__dino_plugins_open_pgp_module_received_jid_key_id, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	_g_object_unref0 (_tmp5_);
	block3_data_unref (_data3_);
	_data3_ = NULL;
}

static void
dino_plugins_open_pgp_manager_on_jid_key_received (DinoPluginsOpenPgpManager* self,
                                                   DinoEntitiesAccount* account,
                                                   XmppJid* jid,
                                                   const gchar* key_id)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (key_id != NULL);
	{
		GeeHashMap* _tmp0_;
		_tmp0_ = self->priv->pgp_key_ids;
		g_rec_mutex_lock (&self->priv->__lock_pgp_key_ids);
		{
			gboolean _tmp1_ = FALSE;
			GeeHashMap* _tmp2_;
			GeeHashMap* _tmp18_;
			_tmp2_ = self->priv->pgp_key_ids;
			if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp2_, jid)) {
				_tmp1_ = TRUE;
			} else {
				GeeHashMap* _tmp3_;
				gpointer _tmp4_;
				gchar* _tmp5_;
				_tmp3_ = self->priv->pgp_key_ids;
				_tmp4_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp3_, jid);
				_tmp5_ = (gchar*) _tmp4_;
				_tmp1_ = g_strcmp0 (_tmp5_, key_id) != 0;
				_g_free0 (_tmp5_);
			}
			if (_tmp1_) {
				XmppJid* _tmp6_ = NULL;
				DinoStreamInteractor* _tmp7_;
				DinoModuleIdentity* _tmp8_;
				gpointer _tmp9_;
				DinoMucManager* _tmp10_;
				gboolean _tmp11_;
				XmppJid* set_jid = NULL;
				XmppJid* _tmp15_;
				DinoPluginsOpenPgpDatabase* _tmp16_;
				XmppJid* _tmp17_;
				_tmp7_ = self->priv->stream_interactor;
				_tmp8_ = dino_muc_manager_IDENTITY;
				_tmp9_ = dino_stream_interactor_get_module (_tmp7_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp8_);
				_tmp10_ = (DinoMucManager*) _tmp9_;
				_tmp11_ = dino_muc_manager_is_groupchat_occupant (_tmp10_, jid, account);
				_g_object_unref0 (_tmp10_);
				if (_tmp11_) {
					XmppJid* _tmp12_;
					_tmp12_ = _xmpp_jid_ref0 (jid);
					_xmpp_jid_unref0 (_tmp6_);
					_tmp6_ = _tmp12_;
				} else {
					XmppJid* _tmp13_;
					XmppJid* _tmp14_;
					_tmp13_ = xmpp_jid_get_bare_jid (jid);
					_tmp14_ = _tmp13_;
					_xmpp_jid_unref0 (_tmp6_);
					_tmp6_ = _tmp14_;
				}
				_tmp15_ = _tmp6_;
				_tmp6_ = NULL;
				set_jid = _tmp15_;
				_tmp16_ = self->priv->db;
				_tmp17_ = set_jid;
				dino_plugins_open_pgp_database_set_contact_key (_tmp16_, _tmp17_, key_id);
				_xmpp_jid_unref0 (set_jid);
				_xmpp_jid_unref0 (_tmp6_);
			}
			_tmp18_ = self->priv->pgp_key_ids;
			gee_abstract_map_set ((GeeAbstractMap*) _tmp18_, jid, key_id);
		}
		__finally0:
		{
			GeeHashMap* _tmp19_;
			_tmp19_ = self->priv->pgp_key_ids;
			g_rec_mutex_unlock (&self->priv->__lock_pgp_key_ids);
		}
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			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;
		}
	}
}

static const gchar*
dino_plugins_open_pgp_manager_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoPluginsOpenPgpManager* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoPluginsOpenPgpManager*) base;
	_tmp0_ = dino_plugins_open_pgp_manager_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
dino_plugins_open_pgp_manager_received_message_listener_real_run_data_free (gpointer _data)
{
	DinoPluginsOpenPgpManagerReceivedMessageListenerRunData* _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 (DinoPluginsOpenPgpManagerReceivedMessageListenerRunData, _data_);
}

static void
dino_plugins_open_pgp_manager_received_message_listener_real_run (DinoMessageListener* base,
                                                                  DinoEntitiesMessage* message,
                                                                  XmppMessageStanza* stanza,
                                                                  DinoEntitiesConversation* conversation,
                                                                  GAsyncReadyCallback _callback_,
                                                                  gpointer _user_data_)
{
	DinoPluginsOpenPgpManagerReceivedMessageListener * self;
	DinoPluginsOpenPgpManagerReceivedMessageListenerRunData* _data_;
	DinoPluginsOpenPgpManagerReceivedMessageListener* _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 = (DinoPluginsOpenPgpManagerReceivedMessageListener*) base;
	_data_ = g_slice_new0 (DinoPluginsOpenPgpManagerReceivedMessageListenerRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_plugins_open_pgp_manager_received_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_open_pgp_manager_received_message_listener_real_run_co (_data_);
}

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

static gboolean
dino_plugins_open_pgp_manager_received_message_listener_real_run_co (DinoPluginsOpenPgpManagerReceivedMessageListenerRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = dino_plugins_open_pgp_message_flag_get_flag (_data_->stanza);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = _data_->_tmp2_ != NULL;
	_g_object_unref0 (_data_->_tmp2_);
	if (_data_->_tmp3_) {
		_data_->_tmp4_ = dino_plugins_open_pgp_message_flag_get_flag (_data_->stanza);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp0_ = _data_->_tmp5_->decrypted;
		_g_object_unref0 (_data_->_tmp5_);
	} else {
		_data_->_tmp0_ = FALSE;
	}
	if (_data_->_tmp0_) {
		dino_entities_message_set_encryption (_data_->message, DINO_ENTITIES_ENCRYPTION_PGP);
	}
	_data_->result = FALSE;
	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 DinoPluginsOpenPgpManagerReceivedMessageListener*
dino_plugins_open_pgp_manager_received_message_listener_construct (GType object_type)
{
	DinoPluginsOpenPgpManagerReceivedMessageListener * self = NULL;
	self = (DinoPluginsOpenPgpManagerReceivedMessageListener*) dino_message_listener_construct (object_type);
	return self;
}

static DinoPluginsOpenPgpManagerReceivedMessageListener*
dino_plugins_open_pgp_manager_received_message_listener_new (void)
{
	return dino_plugins_open_pgp_manager_received_message_listener_construct (DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER);
}

static const gchar*
dino_plugins_open_pgp_manager_received_message_listener_real_get_action_group (XmppOrderedListener* base)
{
	const gchar* result;
	DinoPluginsOpenPgpManagerReceivedMessageListener* self;
	self = (DinoPluginsOpenPgpManagerReceivedMessageListener*) base;
	result = "DECRYPT";
	return result;
}

static gchar**
dino_plugins_open_pgp_manager_received_message_listener_real_get_after_actions (XmppOrderedListener* base,
                                                                                gint* result_length1)
{
	gchar** result;
	DinoPluginsOpenPgpManagerReceivedMessageListener* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	self = (DinoPluginsOpenPgpManagerReceivedMessageListener*) 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_open_pgp_manager_received_message_listener_class_init (DinoPluginsOpenPgpManagerReceivedMessageListenerClass * klass,
                                                                    gpointer klass_data)
{
	dino_plugins_open_pgp_manager_received_message_listener_parent_class = g_type_class_peek_parent (klass);
	((DinoMessageListenerClass *) klass)->run = (void (*) (DinoMessageListener*, DinoEntitiesMessage*, XmppMessageStanza*, DinoEntitiesConversation*, GAsyncReadyCallback, gpointer)) dino_plugins_open_pgp_manager_received_message_listener_real_run;
	((DinoMessageListenerClass *) klass)->run_finish = (gboolean (*) (DinoMessageListener*, GAsyncResult*)) dino_plugins_open_pgp_manager_received_message_listener_run_finish;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_action_group = (const gchar* (*) (XmppOrderedListener*)) dino_plugins_open_pgp_manager_received_message_listener_real_get_action_group;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_after_actions = (gchar** (*) (XmppOrderedListener*, gint*)) dino_plugins_open_pgp_manager_received_message_listener_real_get_after_actions;
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_plugins_open_pgp_manager_received_message_listener_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_open_pgp_manager_received_message_listener_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY, dino_plugins_open_pgp_manager_received_message_listener_properties[DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_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_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY, dino_plugins_open_pgp_manager_received_message_listener_properties[DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_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_open_pgp_manager_received_message_listener_instance_init (DinoPluginsOpenPgpManagerReceivedMessageListener * self,
                                                                       gpointer klass)
{
	gchar** _tmp0_;
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	self->after_actions_const = _tmp0_;
	self->after_actions_const_length1 = 0;
	self->_after_actions_const_size_ = self->after_actions_const_length1;
}

static void
dino_plugins_open_pgp_manager_received_message_listener_finalize (GObject * obj)
{
	DinoPluginsOpenPgpManagerReceivedMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER, DinoPluginsOpenPgpManagerReceivedMessageListener);
	self->after_actions_const = (_vala_array_free (self->after_actions_const, self->after_actions_const_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (dino_plugins_open_pgp_manager_received_message_listener_parent_class)->finalize (obj);
}

static GType
dino_plugins_open_pgp_manager_received_message_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOpenPgpManagerReceivedMessageListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_open_pgp_manager_received_message_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOpenPgpManagerReceivedMessageListener), 0, (GInstanceInitFunc) dino_plugins_open_pgp_manager_received_message_listener_instance_init, NULL };
	GType dino_plugins_open_pgp_manager_received_message_listener_type_id;
	dino_plugins_open_pgp_manager_received_message_listener_type_id = g_type_register_static (DINO_TYPE_MESSAGE_LISTENER, "DinoPluginsOpenPgpManagerReceivedMessageListener", &g_define_type_info, 0);
	return dino_plugins_open_pgp_manager_received_message_listener_type_id;
}

static GType
dino_plugins_open_pgp_manager_received_message_listener_get_type (void)
{
	static volatile gsize dino_plugins_open_pgp_manager_received_message_listener_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_open_pgp_manager_received_message_listener_type_id__once)) {
		GType dino_plugins_open_pgp_manager_received_message_listener_type_id;
		dino_plugins_open_pgp_manager_received_message_listener_type_id = dino_plugins_open_pgp_manager_received_message_listener_get_type_once ();
		g_once_init_leave (&dino_plugins_open_pgp_manager_received_message_listener_type_id__once, dino_plugins_open_pgp_manager_received_message_listener_type_id);
	}
	return dino_plugins_open_pgp_manager_received_message_listener_type_id__once;
}

static void
_vala_dino_plugins_open_pgp_manager_received_message_listener_get_property (GObject * object,
                                                                            guint property_id,
                                                                            GValue * value,
                                                                            GParamSpec * pspec)
{
	DinoPluginsOpenPgpManagerReceivedMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_PLUGINS_OPEN_PGP_MANAGER_TYPE_RECEIVED_MESSAGE_LISTENER, DinoPluginsOpenPgpManagerReceivedMessageListener);
	switch (property_id) {
		case DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY:
		g_value_set_string (value, xmpp_ordered_listener_get_action_group ((XmppOrderedListener*) self));
		break;
		case DINO_PLUGINS_OPEN_PGP_MANAGER_RECEIVED_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_open_pgp_manager_class_init (DinoPluginsOpenPgpManagerClass * klass,
                                          gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_plugins_open_pgp_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOpenPgpManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_plugins_open_pgp_manager_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_open_pgp_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OPEN_PGP_MANAGER_ID_PROPERTY, dino_plugins_open_pgp_manager_properties[DINO_PLUGINS_OPEN_PGP_MANAGER_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	_tmp0_ = dino_module_identity_new (DINO_PLUGINS_OPEN_PGP_TYPE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "pgp_manager");
	dino_plugins_open_pgp_manager_IDENTITY = _tmp0_;
}

static void
dino_plugins_open_pgp_manager_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                             gpointer iface_data)
{
	dino_plugins_open_pgp_manager_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_plugins_open_pgp_manager_real_get_id;
}

static void
dino_plugins_open_pgp_manager_instance_init (DinoPluginsOpenPgpManager * self,
                                             gpointer klass)
{
	GeeHashMap* _tmp0_;
	DinoPluginsOpenPgpManagerReceivedMessageListener* _tmp1_;
	self->priv = dino_plugins_open_pgp_manager_get_instance_private (self);
	g_rec_mutex_init (&self->priv->__lock_pgp_key_ids);
	_tmp0_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _xmpp_jid_hash_bare_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_bare_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->pgp_key_ids = _tmp0_;
	_tmp1_ = dino_plugins_open_pgp_manager_received_message_listener_new ();
	self->priv->received_message_listener = _tmp1_;
}

static void
dino_plugins_open_pgp_manager_finalize (GObject * obj)
{
	DinoPluginsOpenPgpManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OPEN_PGP_TYPE_MANAGER, DinoPluginsOpenPgpManager);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	g_rec_mutex_clear (&self->priv->__lock_pgp_key_ids);
	_g_object_unref0 (self->priv->pgp_key_ids);
	_g_object_unref0 (self->priv->received_message_listener);
	G_OBJECT_CLASS (dino_plugins_open_pgp_manager_parent_class)->finalize (obj);
}

static GType
dino_plugins_open_pgp_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOpenPgpManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_open_pgp_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOpenPgpManager), 0, (GInstanceInitFunc) dino_plugins_open_pgp_manager_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_plugins_open_pgp_manager_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_open_pgp_manager_type_id;
	dino_plugins_open_pgp_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOpenPgpManager", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_open_pgp_manager_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoPluginsOpenPgpManager_private_offset = g_type_add_instance_private (dino_plugins_open_pgp_manager_type_id, sizeof (DinoPluginsOpenPgpManagerPrivate));
	return dino_plugins_open_pgp_manager_type_id;
}

GType
dino_plugins_open_pgp_manager_get_type (void)
{
	static volatile gsize dino_plugins_open_pgp_manager_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_open_pgp_manager_type_id__once)) {
		GType dino_plugins_open_pgp_manager_type_id;
		dino_plugins_open_pgp_manager_type_id = dino_plugins_open_pgp_manager_get_type_once ();
		g_once_init_leave (&dino_plugins_open_pgp_manager_type_id__once, dino_plugins_open_pgp_manager_type_id);
	}
	return dino_plugins_open_pgp_manager_type_id__once;
}

static void
_vala_dino_plugins_open_pgp_manager_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	DinoPluginsOpenPgpManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_PLUGINS_OPEN_PGP_TYPE_MANAGER, DinoPluginsOpenPgpManager);
	switch (property_id) {
		case DINO_PLUGINS_OPEN_PGP_MANAGER_ID_PROPERTY:
		g_value_set_string (value, dino_stream_interaction_module_get_id ((DinoStreamInteractionModule*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

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

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

