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

#include "omemo.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <omemo/signal_protocol.h>
#include <native/helper.h>
#include <omemo/signal_protocol_types.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  {
	OMEMO_SIMPLE_SESSION_STORE_0_PROPERTY,
	OMEMO_SIMPLE_SESSION_STORE_NUM_PROPERTIES
};
static GParamSpec* omemo_simple_session_store_properties[OMEMO_SIMPLE_SESSION_STORE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _omemo_session_store_session_unref0(var) ((var == NULL) ? NULL : (var = (omemo_session_store_session_unref (var), NULL)))

struct _OmemoSimpleSessionStorePrivate {
	GeeMap* session_map;
};

static gint OmemoSimpleSessionStore_private_offset;
static gpointer omemo_simple_session_store_parent_class = NULL;

static guint8* omemo_simple_session_store_real_load_session (OmemoSessionStore* base,
                                                      signal_protocol_address* address,
                                                      gint* result_length1,
                                                      GError** error);
static guint8* _vala_array_dup32 (guint8* self,
                           gssize length);
static signal_int_list* omemo_simple_session_store_real_get_sub_device_sessions (OmemoSessionStore* base,
                                                                          const gchar* name,
                                                                          GError** error);
static void omemo_simple_session_store_real_store_session (OmemoSessionStore* base,
                                                    signal_protocol_address* address,
                                                    guint8* record,
                                                    gint record_length1,
                                                    GError** error);
static guint8* _vala_array_dup33 (guint8* self,
                           gssize length);
static gboolean omemo_simple_session_store_real_contains_session (OmemoSessionStore* base,
                                                           signal_protocol_address* address,
                                                           GError** error);
static void omemo_simple_session_store_real_delete_session (OmemoSessionStore* base,
                                                     signal_protocol_address* address,
                                                     GError** error);
static const char* _omemo_error_code_to_string (int value);
static void omemo_simple_session_store_real_delete_all_sessions (OmemoSessionStore* base,
                                                          const gchar* name,
                                                          GError** error);
static void omemo_simple_session_store_finalize (GObject * obj);
static GType omemo_simple_session_store_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
omemo_simple_session_store_get_instance_private (OmemoSimpleSessionStore* self)
{
	return G_STRUCT_MEMBER_P (self, OmemoSimpleSessionStore_private_offset);
}

static guint8*
_vala_array_dup32 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
omemo_simple_session_store_real_load_session (OmemoSessionStore* base,
                                              signal_protocol_address* address,
                                              gint* result_length1,
                                              GError** error)
{
	OmemoSimpleSessionStore * self;
	GeeMap* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_;
	guint8* _tmp25_;
	gint _tmp25__length1;
	guint8* result;
	self = (OmemoSimpleSessionStore*) base;
	g_return_val_if_fail (address != NULL, NULL);
	_tmp0_ = self->priv->session_map;
	_tmp1_ = signal_protocol_address_get_name (address);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = gee_map_has_key (_tmp0_, _tmp3_);
	_g_free0 (_tmp3_);
	if (_tmp4_) {
		{
			GeeArrayList* _session_list = NULL;
			GeeMap* _tmp5_;
			gchar* _tmp6_;
			gchar* _tmp7_;
			gchar* _tmp8_;
			gpointer _tmp9_;
			GeeArrayList* _tmp10_;
			gint _session_size = 0;
			GeeArrayList* _tmp11_;
			gint _tmp12_;
			gint _tmp13_;
			gint _session_index = 0;
			_tmp5_ = self->priv->session_map;
			_tmp6_ = signal_protocol_address_get_name (address);
			_tmp7_ = _tmp6_;
			_tmp8_ = _tmp7_;
			_tmp9_ = gee_map_get (_tmp5_, _tmp8_);
			_tmp10_ = (GeeArrayList*) _tmp9_;
			_g_free0 (_tmp8_);
			_session_list = _tmp10_;
			_tmp11_ = _session_list;
			_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
			_tmp13_ = _tmp12_;
			_session_size = _tmp13_;
			_session_index = -1;
			while (TRUE) {
				gint _tmp14_;
				gint _tmp15_;
				OmemoSessionStoreSession* session = NULL;
				GeeArrayList* _tmp16_;
				gpointer _tmp17_;
				OmemoSessionStoreSession* _tmp18_;
				gint32 _tmp19_;
				gint32 _tmp20_;
				_session_index = _session_index + 1;
				_tmp14_ = _session_index;
				_tmp15_ = _session_size;
				if (!(_tmp14_ < _tmp15_)) {
					break;
				}
				_tmp16_ = _session_list;
				_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _session_index);
				session = (OmemoSessionStoreSession*) _tmp17_;
				_tmp18_ = session;
				_tmp19_ = signal_protocol_address_get_device_id (address);
				_tmp20_ = _tmp19_;
				if (_tmp18_->device_id == ((gint) _tmp20_)) {
					OmemoSessionStoreSession* _tmp21_;
					guint8* _tmp22_;
					gint _tmp22__length1;
					guint8* _tmp23_;
					gint _tmp23__length1;
					guint8* _tmp24_;
					gint _tmp24__length1;
					_tmp21_ = session;
					_tmp22_ = _tmp21_->record;
					_tmp22__length1 = _tmp21_->record_length1;
					_tmp23_ = (_tmp22_ != NULL) ? _vala_array_dup32 (_tmp22_, _tmp22__length1) : _tmp22_;
					_tmp23__length1 = _tmp22__length1;
					_tmp24_ = _tmp23_;
					_tmp24__length1 = _tmp23__length1;
					if (result_length1) {
						*result_length1 = _tmp24__length1;
					}
					result = _tmp24_;
					_omemo_session_store_session_unref0 (session);
					_g_object_unref0 (_session_list);
					return result;
				}
				_omemo_session_store_session_unref0 (session);
			}
			_g_object_unref0 (_session_list);
		}
	}
	_tmp25_ = NULL;
	_tmp25__length1 = 0;
	if (result_length1) {
		*result_length1 = _tmp25__length1;
	}
	result = _tmp25_;
	return result;
}

static signal_int_list*
omemo_simple_session_store_real_get_sub_device_sessions (OmemoSessionStore* base,
                                                         const gchar* name,
                                                         GError** error)
{
	OmemoSimpleSessionStore * self;
	signal_int_list* res = NULL;
	signal_int_list* _tmp0_;
	GeeMap* _tmp1_;
	signal_int_list* result;
	self = (OmemoSimpleSessionStore*) base;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = signal_int_list_alloc ();
	res = _tmp0_;
	_tmp1_ = self->priv->session_map;
	if (gee_map_has_key (_tmp1_, name)) {
		{
			GeeArrayList* _session_list = NULL;
			GeeMap* _tmp2_;
			gpointer _tmp3_;
			gint _session_size = 0;
			GeeArrayList* _tmp4_;
			gint _tmp5_;
			gint _tmp6_;
			gint _session_index = 0;
			_tmp2_ = self->priv->session_map;
			_tmp3_ = gee_map_get (_tmp2_, name);
			_session_list = (GeeArrayList*) _tmp3_;
			_tmp4_ = _session_list;
			_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
			_tmp6_ = _tmp5_;
			_session_size = _tmp6_;
			_session_index = -1;
			while (TRUE) {
				gint _tmp7_;
				gint _tmp8_;
				OmemoSessionStoreSession* session = NULL;
				GeeArrayList* _tmp9_;
				gpointer _tmp10_;
				signal_int_list* _tmp11_;
				OmemoSessionStoreSession* _tmp12_;
				_session_index = _session_index + 1;
				_tmp7_ = _session_index;
				_tmp8_ = _session_size;
				if (!(_tmp7_ < _tmp8_)) {
					break;
				}
				_tmp9_ = _session_list;
				_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _session_index);
				session = (OmemoSessionStoreSession*) _tmp10_;
				_tmp11_ = res;
				_tmp12_ = session;
				signal_int_list_push_back (_tmp11_, _tmp12_->device_id);
				_omemo_session_store_session_unref0 (session);
			}
			_g_object_unref0 (_session_list);
		}
	}
	result = res;
	return result;
}

static guint8*
_vala_array_dup33 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static void
omemo_simple_session_store_real_store_session (OmemoSessionStore* base,
                                               signal_protocol_address* address,
                                               guint8* record,
                                               gint record_length1,
                                               GError** error)
{
	OmemoSimpleSessionStore * self;
	gboolean _tmp0_ = FALSE;
	GeeMap* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gboolean _tmp5_;
	OmemoSessionStoreSession* session = NULL;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gint32 _tmp14_;
	gint32 _tmp15_;
	guint8* _tmp16_;
	gint _tmp16__length1;
	OmemoSessionStoreSession* _tmp17_ = NULL;
	GeeMap* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gpointer _tmp22_;
	GeeArrayList* _tmp23_;
	OmemoSessionStoreSession* _tmp24_;
	OmemoSessionStoreSession* _tmp25_;
	GError* _inner_error0_ = NULL;
	self = (OmemoSimpleSessionStore*) base;
	g_return_if_fail (address != NULL);
	_tmp0_ = omemo_session_store_contains_session ((OmemoSessionStore*) self, address, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	if (_tmp0_) {
		omemo_session_store_delete_session ((OmemoSessionStore*) self, address, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
	}
	_tmp1_ = self->priv->session_map;
	_tmp2_ = signal_protocol_address_get_name (address);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp5_ = !gee_map_has_key (_tmp1_, _tmp4_);
	_g_free0 (_tmp4_);
	if (_tmp5_) {
		GeeMap* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		GeeArrayList* _tmp10_;
		GeeArrayList* _tmp11_;
		_tmp6_ = self->priv->session_map;
		_tmp7_ = signal_protocol_address_get_name (address);
		_tmp8_ = _tmp7_;
		_tmp9_ = _tmp8_;
		_tmp10_ = gee_array_list_new (OMEMO_SESSION_STORE_TYPE_SESSION, (GBoxedCopyFunc) omemo_session_store_session_ref, (GDestroyNotify) omemo_session_store_session_unref, NULL, NULL, NULL);
		_tmp11_ = _tmp10_;
		gee_map_set (_tmp6_, _tmp9_, _tmp11_);
		_g_object_unref0 (_tmp11_);
		_g_free0 (_tmp9_);
	}
	_tmp12_ = signal_protocol_address_get_name (address);
	_tmp13_ = _tmp12_;
	_tmp14_ = signal_protocol_address_get_device_id (address);
	_tmp15_ = _tmp14_;
	_tmp16_ = (record != NULL) ? _vala_array_dup33 (record, record_length1) : record;
	_tmp16__length1 = record_length1;
	_tmp17_ = omemo_session_store_session_new ();
	_g_free0 (_tmp17_->name);
	_tmp17_->name = _tmp13_;
	_tmp17_->device_id = (gint) _tmp15_;
	_tmp17_->record = (g_free (_tmp17_->record), NULL);
	_tmp17_->record = _tmp16_;
	_tmp17_->record_length1 = _tmp16__length1;
	session = _tmp17_;
	_tmp18_ = self->priv->session_map;
	_tmp19_ = signal_protocol_address_get_name (address);
	_tmp20_ = _tmp19_;
	_tmp21_ = _tmp20_;
	_tmp22_ = gee_map_get (_tmp18_, _tmp21_);
	_tmp23_ = (GeeArrayList*) _tmp22_;
	_tmp24_ = session;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp23_, _tmp24_);
	_g_object_unref0 (_tmp23_);
	_g_free0 (_tmp21_);
	_tmp25_ = session;
	g_signal_emit_by_name ((OmemoSessionStore*) self, "session-stored", _tmp25_);
	_omemo_session_store_session_unref0 (session);
}

static gboolean
omemo_simple_session_store_real_contains_session (OmemoSessionStore* base,
                                                  signal_protocol_address* address,
                                                  GError** error)
{
	OmemoSimpleSessionStore * self;
	GeeMap* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	self = (OmemoSimpleSessionStore*) base;
	g_return_val_if_fail (address != NULL, FALSE);
	_tmp0_ = self->priv->session_map;
	_tmp1_ = signal_protocol_address_get_name (address);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = !gee_map_has_key (_tmp0_, _tmp3_);
	_g_free0 (_tmp3_);
	if (_tmp4_) {
		result = FALSE;
		return result;
	}
	{
		GeeArrayList* _session_list = NULL;
		GeeMap* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gpointer _tmp9_;
		GeeArrayList* _tmp10_;
		gint _session_size = 0;
		GeeArrayList* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gint _session_index = 0;
		_tmp5_ = self->priv->session_map;
		_tmp6_ = signal_protocol_address_get_name (address);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_;
		_tmp9_ = gee_map_get (_tmp5_, _tmp8_);
		_tmp10_ = (GeeArrayList*) _tmp9_;
		_g_free0 (_tmp8_);
		_session_list = _tmp10_;
		_tmp11_ = _session_list;
		_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
		_tmp13_ = _tmp12_;
		_session_size = _tmp13_;
		_session_index = -1;
		while (TRUE) {
			gint _tmp14_;
			gint _tmp15_;
			OmemoSessionStoreSession* session = NULL;
			GeeArrayList* _tmp16_;
			gpointer _tmp17_;
			OmemoSessionStoreSession* _tmp18_;
			gint32 _tmp19_;
			gint32 _tmp20_;
			_session_index = _session_index + 1;
			_tmp14_ = _session_index;
			_tmp15_ = _session_size;
			if (!(_tmp14_ < _tmp15_)) {
				break;
			}
			_tmp16_ = _session_list;
			_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _session_index);
			session = (OmemoSessionStoreSession*) _tmp17_;
			_tmp18_ = session;
			_tmp19_ = signal_protocol_address_get_device_id (address);
			_tmp20_ = _tmp19_;
			if (_tmp18_->device_id == ((gint) _tmp20_)) {
				result = TRUE;
				_omemo_session_store_session_unref0 (session);
				_g_object_unref0 (_session_list);
				return result;
			}
			_omemo_session_store_session_unref0 (session);
		}
		_g_object_unref0 (_session_list);
	}
	result = FALSE;
	return result;
}

static const char*
_omemo_error_code_to_string (int value)
{
	switch (value) {
		case SG_SUCCESS:
		return "SG_SUCCESS";
		case SG_ERR_NOMEM:
		return "SG_ERR_NOMEM";
		case SG_ERR_INVAL:
		return "SG_ERR_INVAL";
		case SG_ERR_UNKNOWN:
		return "SG_ERR_UNKNOWN";
		case SG_ERR_DUPLICATE_MESSAGE:
		return "SG_ERR_DUPLICATE_MESSAGE";
		case SG_ERR_INVALID_KEY:
		return "SG_ERR_INVALID_KEY";
		case SG_ERR_INVALID_KEY_ID:
		return "SG_ERR_INVALID_KEY_ID";
		case SG_ERR_INVALID_MAC:
		return "SG_ERR_INVALID_MAC";
		case SG_ERR_INVALID_MESSAGE:
		return "SG_ERR_INVALID_MESSAGE";
		case SG_ERR_INVALID_VERSION:
		return "SG_ERR_INVALID_VERSION";
		case SG_ERR_LEGACY_MESSAGE:
		return "SG_ERR_LEGACY_MESSAGE";
		case SG_ERR_NO_SESSION:
		return "SG_ERR_NO_SESSION";
		case SG_ERR_STALE_KEY_EXCHANGE:
		return "SG_ERR_STALE_KEY_EXCHANGE";
		case SG_ERR_UNTRUSTED_IDENTITY:
		return "SG_ERR_UNTRUSTED_IDENTITY";
		case SG_ERR_VRF_SIG_VERIF_FAILED:
		return "SG_ERR_VRF_SIG_VERIF_FAILED";
		case SG_ERR_INVALID_PROTO_BUF:
		return "SG_ERR_INVALID_PROTO_BUF";
		case SG_ERR_FP_VERSION_MISMATCH:
		return "SG_ERR_FP_VERSION_MISMATCH";
		case SG_ERR_FP_IDENT_MISMATCH:
		return "SG_ERR_FP_IDENT_MISMATCH";
	}
	return NULL;
}

static gint
signal_throw_gerror_by_code_ (gint code,
                              const gchar* message,
                              GError** error)
{
	gboolean _tmp0_ = FALSE;
	GError* _inner_error0_ = NULL;
	gint result;
	if (code < 0) {
		_tmp0_ = code > SG_ERR_MINIMUM;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		const gchar* _tmp1_ = NULL;
		const gchar* _tmp2_;
		GError* _tmp3_;
		gint _tmp4_ = -1;
		_tmp1_ = message;
		if (_tmp1_ == NULL) {
			_tmp1_ = "libomemo-c error";
		}
		_tmp2_ = _omemo_error_code_to_string ((int) code);
		_tmp3_ = g_error_new ((GQuark) -1, code, "%s: %s", _tmp1_, _tmp2_);
		_inner_error0_ = _tmp3_;
		g_propagate_error (error, _inner_error0_);
		return _tmp4_;
	}
	result = code;
	return result;
}

static void
omemo_simple_session_store_real_delete_session (OmemoSessionStore* base,
                                                signal_protocol_address* address,
                                                GError** error)
{
	OmemoSimpleSessionStore * self;
	GeeMap* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_;
	GError* _inner_error0_ = NULL;
	self = (OmemoSimpleSessionStore*) base;
	g_return_if_fail (address != NULL);
	_tmp0_ = self->priv->session_map;
	_tmp1_ = signal_protocol_address_get_name (address);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = !gee_map_has_key (_tmp0_, _tmp3_);
	_g_free0 (_tmp3_);
	if (_tmp4_) {
		signal_throw_gerror_by_code_ ((gint) SG_ERR_UNKNOWN, "No session found", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
	}
	{
		GeeArrayList* _session_list = NULL;
		GeeMap* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gpointer _tmp9_;
		GeeArrayList* _tmp10_;
		gint _session_size = 0;
		GeeArrayList* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gint _session_index = 0;
		_tmp5_ = self->priv->session_map;
		_tmp6_ = signal_protocol_address_get_name (address);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_;
		_tmp9_ = gee_map_get (_tmp5_, _tmp8_);
		_tmp10_ = (GeeArrayList*) _tmp9_;
		_g_free0 (_tmp8_);
		_session_list = _tmp10_;
		_tmp11_ = _session_list;
		_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
		_tmp13_ = _tmp12_;
		_session_size = _tmp13_;
		_session_index = -1;
		while (TRUE) {
			gint _tmp14_;
			gint _tmp15_;
			OmemoSessionStoreSession* session = NULL;
			GeeArrayList* _tmp16_;
			gpointer _tmp17_;
			OmemoSessionStoreSession* _tmp18_;
			gint32 _tmp19_;
			gint32 _tmp20_;
			_session_index = _session_index + 1;
			_tmp14_ = _session_index;
			_tmp15_ = _session_size;
			if (!(_tmp14_ < _tmp15_)) {
				break;
			}
			_tmp16_ = _session_list;
			_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _session_index);
			session = (OmemoSessionStoreSession*) _tmp17_;
			_tmp18_ = session;
			_tmp19_ = signal_protocol_address_get_device_id (address);
			_tmp20_ = _tmp19_;
			if (_tmp18_->device_id == ((gint) _tmp20_)) {
				GeeMap* _tmp21_;
				gchar* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				gpointer _tmp25_;
				GeeArrayList* _tmp26_;
				OmemoSessionStoreSession* _tmp27_;
				GeeMap* _tmp28_;
				gchar* _tmp29_;
				gchar* _tmp30_;
				gchar* _tmp31_;
				gpointer _tmp32_;
				GeeArrayList* _tmp33_;
				gint _tmp34_;
				gint _tmp35_;
				gboolean _tmp36_;
				OmemoSessionStoreSession* _tmp41_;
				_tmp21_ = self->priv->session_map;
				_tmp22_ = signal_protocol_address_get_name (address);
				_tmp23_ = _tmp22_;
				_tmp24_ = _tmp23_;
				_tmp25_ = gee_map_get (_tmp21_, _tmp24_);
				_tmp26_ = (GeeArrayList*) _tmp25_;
				_tmp27_ = session;
				gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp26_, _tmp27_);
				_g_object_unref0 (_tmp26_);
				_g_free0 (_tmp24_);
				_tmp28_ = self->priv->session_map;
				_tmp29_ = signal_protocol_address_get_name (address);
				_tmp30_ = _tmp29_;
				_tmp31_ = _tmp30_;
				_tmp32_ = gee_map_get (_tmp28_, _tmp31_);
				_tmp33_ = (GeeArrayList*) _tmp32_;
				_tmp34_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp33_);
				_tmp35_ = _tmp34_;
				_tmp36_ = _tmp35_ == 0;
				_g_object_unref0 (_tmp33_);
				_g_free0 (_tmp31_);
				if (_tmp36_) {
					GeeMap* _tmp37_;
					gchar* _tmp38_;
					gchar* _tmp39_;
					gchar* _tmp40_;
					_tmp37_ = self->priv->session_map;
					_tmp38_ = signal_protocol_address_get_name (address);
					_tmp39_ = _tmp38_;
					_tmp40_ = _tmp39_;
					gee_map_unset (_tmp37_, _tmp40_, NULL);
					_g_free0 (_tmp40_);
				}
				_tmp41_ = session;
				g_signal_emit_by_name ((OmemoSessionStore*) self, "session-removed", _tmp41_);
				_omemo_session_store_session_unref0 (session);
				_g_object_unref0 (_session_list);
				return;
			}
			_omemo_session_store_session_unref0 (session);
		}
		_g_object_unref0 (_session_list);
	}
}

static void
omemo_simple_session_store_real_delete_all_sessions (OmemoSessionStore* base,
                                                     const gchar* name,
                                                     GError** error)
{
	OmemoSimpleSessionStore * self;
	GeeMap* _tmp0_;
	self = (OmemoSimpleSessionStore*) base;
	g_return_if_fail (name != NULL);
	_tmp0_ = self->priv->session_map;
	if (gee_map_has_key (_tmp0_, name)) {
		{
			GeeArrayList* _session_list = NULL;
			GeeMap* _tmp1_;
			gpointer _tmp2_;
			gint _session_size = 0;
			GeeArrayList* _tmp3_;
			gint _tmp4_;
			gint _tmp5_;
			gint _session_index = 0;
			_tmp1_ = self->priv->session_map;
			_tmp2_ = gee_map_get (_tmp1_, name);
			_session_list = (GeeArrayList*) _tmp2_;
			_tmp3_ = _session_list;
			_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
			_tmp5_ = _tmp4_;
			_session_size = _tmp5_;
			_session_index = -1;
			while (TRUE) {
				gint _tmp6_;
				gint _tmp7_;
				OmemoSessionStoreSession* session = NULL;
				GeeArrayList* _tmp8_;
				gpointer _tmp9_;
				GeeMap* _tmp10_;
				gpointer _tmp11_;
				GeeArrayList* _tmp12_;
				OmemoSessionStoreSession* _tmp13_;
				GeeMap* _tmp14_;
				gpointer _tmp15_;
				GeeArrayList* _tmp16_;
				gint _tmp17_;
				gint _tmp18_;
				gboolean _tmp19_;
				OmemoSessionStoreSession* _tmp21_;
				_session_index = _session_index + 1;
				_tmp6_ = _session_index;
				_tmp7_ = _session_size;
				if (!(_tmp6_ < _tmp7_)) {
					break;
				}
				_tmp8_ = _session_list;
				_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _session_index);
				session = (OmemoSessionStoreSession*) _tmp9_;
				_tmp10_ = self->priv->session_map;
				_tmp11_ = gee_map_get (_tmp10_, name);
				_tmp12_ = (GeeArrayList*) _tmp11_;
				_tmp13_ = session;
				gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp12_, _tmp13_);
				_g_object_unref0 (_tmp12_);
				_tmp14_ = self->priv->session_map;
				_tmp15_ = gee_map_get (_tmp14_, name);
				_tmp16_ = (GeeArrayList*) _tmp15_;
				_tmp17_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp16_);
				_tmp18_ = _tmp17_;
				_tmp19_ = _tmp18_ == 0;
				_g_object_unref0 (_tmp16_);
				if (_tmp19_) {
					GeeMap* _tmp20_;
					_tmp20_ = self->priv->session_map;
					gee_map_unset (_tmp20_, name, NULL);
				}
				_tmp21_ = session;
				g_signal_emit_by_name ((OmemoSessionStore*) self, "session-removed", _tmp21_);
				_omemo_session_store_session_unref0 (session);
			}
			_g_object_unref0 (_session_list);
		}
	}
}

OmemoSimpleSessionStore*
omemo_simple_session_store_construct (GType object_type)
{
	OmemoSimpleSessionStore * self = NULL;
	self = (OmemoSimpleSessionStore*) omemo_session_store_construct (object_type);
	return self;
}

OmemoSimpleSessionStore*
omemo_simple_session_store_new (void)
{
	return omemo_simple_session_store_construct (OMEMO_TYPE_SIMPLE_SESSION_STORE);
}

static void
omemo_simple_session_store_class_init (OmemoSimpleSessionStoreClass * klass,
                                       gpointer klass_data)
{
	omemo_simple_session_store_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &OmemoSimpleSessionStore_private_offset);
	((OmemoSessionStoreClass *) klass)->load_session = (guint8* (*) (OmemoSessionStore*, signal_protocol_address*, gint*, GError**)) omemo_simple_session_store_real_load_session;
	((OmemoSessionStoreClass *) klass)->get_sub_device_sessions = (signal_int_list* (*) (OmemoSessionStore*, const gchar*, GError**)) omemo_simple_session_store_real_get_sub_device_sessions;
	((OmemoSessionStoreClass *) klass)->store_session = (void (*) (OmemoSessionStore*, signal_protocol_address*, guint8*, gint, GError**)) omemo_simple_session_store_real_store_session;
	((OmemoSessionStoreClass *) klass)->contains_session = (gboolean (*) (OmemoSessionStore*, signal_protocol_address*, GError**)) omemo_simple_session_store_real_contains_session;
	((OmemoSessionStoreClass *) klass)->delete_session = (void (*) (OmemoSessionStore*, signal_protocol_address*, GError**)) omemo_simple_session_store_real_delete_session;
	((OmemoSessionStoreClass *) klass)->delete_all_sessions = (void (*) (OmemoSessionStore*, const gchar*, GError**)) omemo_simple_session_store_real_delete_all_sessions;
	G_OBJECT_CLASS (klass)->finalize = omemo_simple_session_store_finalize;
}

static void
omemo_simple_session_store_instance_init (OmemoSimpleSessionStore * self,
                                          gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = omemo_simple_session_store_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->session_map = (GeeMap*) _tmp0_;
}

static void
omemo_simple_session_store_finalize (GObject * obj)
{
	OmemoSimpleSessionStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, OMEMO_TYPE_SIMPLE_SESSION_STORE, OmemoSimpleSessionStore);
	_g_object_unref0 (self->priv->session_map);
	G_OBJECT_CLASS (omemo_simple_session_store_parent_class)->finalize (obj);
}

static GType
omemo_simple_session_store_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (OmemoSimpleSessionStoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) omemo_simple_session_store_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (OmemoSimpleSessionStore), 0, (GInstanceInitFunc) omemo_simple_session_store_instance_init, NULL };
	GType omemo_simple_session_store_type_id;
	omemo_simple_session_store_type_id = g_type_register_static (OMEMO_TYPE_SESSION_STORE, "OmemoSimpleSessionStore", &g_define_type_info, 0);
	OmemoSimpleSessionStore_private_offset = g_type_add_instance_private (omemo_simple_session_store_type_id, sizeof (OmemoSimpleSessionStorePrivate));
	return omemo_simple_session_store_type_id;
}

GType
omemo_simple_session_store_get_type (void)
{
	static volatile gsize omemo_simple_session_store_type_id__once = 0;
	if (g_once_init_enter (&omemo_simple_session_store_type_id__once)) {
		GType omemo_simple_session_store_type_id;
		omemo_simple_session_store_type_id = omemo_simple_session_store_get_type_once ();
		g_once_init_leave (&omemo_simple_session_store_type_id__once, omemo_simple_session_store_type_id);
	}
	return omemo_simple_session_store_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;
}

