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

#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.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_ENTITY_CAPABILITIES_STORAGE_0_PROPERTY,
	DINO_ENTITY_CAPABILITIES_STORAGE_NUM_PROPERTIES
};
static GParamSpec* dino_entity_capabilities_storage_properties[DINO_ENTITY_CAPABILITIES_STORAGE_NUM_PROPERTIES];
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_xep_service_discovery_identity_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_service_discovery_identity_unref (var), NULL)))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
#define _qlite_row_iterator_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_iterator_unref (var), NULL)))
#define _qlite_row_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))

struct _DinoEntityCapabilitiesStoragePrivate {
	DinoDatabase* db;
	GeeHashMap* features_cache;
	GeeHashMap* identity_cache;
};

static gint DinoEntityCapabilitiesStorage_private_offset;
static gpointer dino_entity_capabilities_storage_parent_class = NULL;
static XmppXepEntityCapabilitiesStorageIface * dino_entity_capabilities_storage_xmpp_xep_entity_capabilities_storage_parent_iface = NULL;

static void dino_entity_capabilities_storage_real_store_features (XmppXepEntityCapabilitiesStorage* base,
                                                           const gchar* entity,
                                                           GeeList* features);
static void dino_entity_capabilities_storage_real_store_identities (XmppXepEntityCapabilitiesStorage* base,
                                                             const gchar* entity,
                                                             GeeSet* identities);
static GeeList* dino_entity_capabilities_storage_real_get_features (XmppXepEntityCapabilitiesStorage* base,
                                                             const gchar* entity);
static XmppXepServiceDiscoveryIdentity* dino_entity_capabilities_storage_real_get_identities (XmppXepEntityCapabilitiesStorage* base,
                                                                                       const gchar* entity);
static void dino_entity_capabilities_storage_finalize (GObject * obj);
static GType dino_entity_capabilities_storage_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_entity_capabilities_storage_get_instance_private (DinoEntityCapabilitiesStorage* self)
{
	return G_STRUCT_MEMBER_P (self, DinoEntityCapabilitiesStorage_private_offset);
}

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

DinoEntityCapabilitiesStorage*
dino_entity_capabilities_storage_construct (GType object_type,
                                            DinoDatabase* db)
{
	DinoEntityCapabilitiesStorage * self = NULL;
	DinoDatabase* _tmp0_;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoEntityCapabilitiesStorage*) g_object_new (object_type, NULL);
	_tmp0_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp0_;
	return self;
}

DinoEntityCapabilitiesStorage*
dino_entity_capabilities_storage_new (DinoDatabase* db)
{
	return dino_entity_capabilities_storage_construct (DINO_TYPE_ENTITY_CAPABILITIES_STORAGE, db);
}

static void
dino_entity_capabilities_storage_real_store_features (XmppXepEntityCapabilitiesStorage* base,
                                                      const gchar* entity,
                                                      GeeList* features)
{
	DinoEntityCapabilitiesStorage * self;
	GeeHashMap* _tmp0_;
	self = (DinoEntityCapabilitiesStorage*) base;
	g_return_if_fail (entity != NULL);
	g_return_if_fail (features != NULL);
	_tmp0_ = self->priv->features_cache;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, entity)) {
		return;
	}
	{
		GeeList* _feature_list = NULL;
		gint _feature_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _feature_index = 0;
		_feature_list = features;
		_tmp1_ = _feature_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_feature_size = _tmp3_;
		_feature_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			gchar* feature = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			DinoDatabase* _tmp8_;
			DinoDatabaseEntityFeatureTable* _tmp9_;
			DinoDatabaseEntityFeatureTable* _tmp10_;
			QliteInsertBuilder* _tmp11_;
			QliteInsertBuilder* _tmp12_;
			DinoDatabase* _tmp13_;
			DinoDatabaseEntityFeatureTable* _tmp14_;
			DinoDatabaseEntityFeatureTable* _tmp15_;
			QliteColumn* _tmp16_;
			QliteInsertBuilder* _tmp17_;
			QliteInsertBuilder* _tmp18_;
			DinoDatabase* _tmp19_;
			DinoDatabaseEntityFeatureTable* _tmp20_;
			DinoDatabaseEntityFeatureTable* _tmp21_;
			QliteColumn* _tmp22_;
			const gchar* _tmp23_;
			QliteInsertBuilder* _tmp24_;
			QliteInsertBuilder* _tmp25_;
			_feature_index = _feature_index + 1;
			_tmp4_ = _feature_index;
			_tmp5_ = _feature_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _feature_list;
			_tmp7_ = gee_list_get (_tmp6_, _feature_index);
			feature = (gchar*) _tmp7_;
			_tmp8_ = self->priv->db;
			_tmp9_ = dino_database_get_entity_feature (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = qlite_table_insert ((QliteTable*) _tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = self->priv->db;
			_tmp14_ = dino_database_get_entity_feature (_tmp13_);
			_tmp15_ = _tmp14_;
			_tmp16_ = _tmp15_->entity;
			_tmp17_ = qlite_insert_builder_value (_tmp12_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp16_, entity);
			_tmp18_ = _tmp17_;
			_tmp19_ = self->priv->db;
			_tmp20_ = dino_database_get_entity_feature (_tmp19_);
			_tmp21_ = _tmp20_;
			_tmp22_ = _tmp21_->feature;
			_tmp23_ = feature;
			_tmp24_ = qlite_insert_builder_value (_tmp18_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp22_, _tmp23_);
			_tmp25_ = _tmp24_;
			qlite_insert_builder_perform (_tmp25_);
			_qlite_statement_builder_unref0 (_tmp25_);
			_qlite_statement_builder_unref0 (_tmp18_);
			_qlite_statement_builder_unref0 (_tmp12_);
			_g_free0 (feature);
		}
	}
}

static void
dino_entity_capabilities_storage_real_store_identities (XmppXepEntityCapabilitiesStorage* base,
                                                        const gchar* entity,
                                                        GeeSet* identities)
{
	DinoEntityCapabilitiesStorage * self;
	self = (DinoEntityCapabilitiesStorage*) base;
	g_return_if_fail (entity != NULL);
	g_return_if_fail (identities != NULL);
	{
		GeeIterator* _identity_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator ((GeeIterable*) identities);
		_identity_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			XmppXepServiceDiscoveryIdentity* identity = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			XmppXepServiceDiscoveryIdentity* _tmp4_;
			const gchar* _tmp5_;
			const gchar* _tmp6_;
			_tmp1_ = _identity_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _identity_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			identity = (XmppXepServiceDiscoveryIdentity*) _tmp3_;
			_tmp4_ = identity;
			_tmp5_ = xmpp_xep_service_discovery_identity_get_category (_tmp4_);
			_tmp6_ = _tmp5_;
			if (g_strcmp0 (_tmp6_, XMPP_XEP_SERVICE_DISCOVERY_IDENTITY_CATEGORY_CLIENT) == 0) {
				DinoDatabase* _tmp7_;
				DinoDatabaseEntityIdentityTable* _tmp8_;
				DinoDatabaseEntityIdentityTable* _tmp9_;
				QliteInsertBuilder* _tmp10_;
				QliteInsertBuilder* _tmp11_;
				DinoDatabase* _tmp12_;
				DinoDatabaseEntityIdentityTable* _tmp13_;
				DinoDatabaseEntityIdentityTable* _tmp14_;
				QliteColumn* _tmp15_;
				QliteInsertBuilder* _tmp16_;
				QliteInsertBuilder* _tmp17_;
				DinoDatabase* _tmp18_;
				DinoDatabaseEntityIdentityTable* _tmp19_;
				DinoDatabaseEntityIdentityTable* _tmp20_;
				QliteColumn* _tmp21_;
				XmppXepServiceDiscoveryIdentity* _tmp22_;
				const gchar* _tmp23_;
				const gchar* _tmp24_;
				QliteInsertBuilder* _tmp25_;
				QliteInsertBuilder* _tmp26_;
				DinoDatabase* _tmp27_;
				DinoDatabaseEntityIdentityTable* _tmp28_;
				DinoDatabaseEntityIdentityTable* _tmp29_;
				QliteColumn* _tmp30_;
				XmppXepServiceDiscoveryIdentity* _tmp31_;
				const gchar* _tmp32_;
				const gchar* _tmp33_;
				QliteInsertBuilder* _tmp34_;
				QliteInsertBuilder* _tmp35_;
				DinoDatabase* _tmp36_;
				DinoDatabaseEntityIdentityTable* _tmp37_;
				DinoDatabaseEntityIdentityTable* _tmp38_;
				QliteColumn* _tmp39_;
				XmppXepServiceDiscoveryIdentity* _tmp40_;
				const gchar* _tmp41_;
				const gchar* _tmp42_;
				QliteInsertBuilder* _tmp43_;
				QliteInsertBuilder* _tmp44_;
				_tmp7_ = self->priv->db;
				_tmp8_ = dino_database_get_entity_identity (_tmp7_);
				_tmp9_ = _tmp8_;
				_tmp10_ = qlite_table_insert ((QliteTable*) _tmp9_);
				_tmp11_ = _tmp10_;
				_tmp12_ = self->priv->db;
				_tmp13_ = dino_database_get_entity_identity (_tmp12_);
				_tmp14_ = _tmp13_;
				_tmp15_ = _tmp14_->entity;
				_tmp16_ = qlite_insert_builder_value (_tmp11_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp15_, entity);
				_tmp17_ = _tmp16_;
				_tmp18_ = self->priv->db;
				_tmp19_ = dino_database_get_entity_identity (_tmp18_);
				_tmp20_ = _tmp19_;
				_tmp21_ = _tmp20_->category;
				_tmp22_ = identity;
				_tmp23_ = xmpp_xep_service_discovery_identity_get_category (_tmp22_);
				_tmp24_ = _tmp23_;
				_tmp25_ = qlite_insert_builder_value (_tmp17_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp21_, _tmp24_);
				_tmp26_ = _tmp25_;
				_tmp27_ = self->priv->db;
				_tmp28_ = dino_database_get_entity_identity (_tmp27_);
				_tmp29_ = _tmp28_;
				_tmp30_ = _tmp29_->type;
				_tmp31_ = identity;
				_tmp32_ = xmpp_xep_service_discovery_identity_get_type_ (_tmp31_);
				_tmp33_ = _tmp32_;
				_tmp34_ = qlite_insert_builder_value (_tmp26_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp30_, _tmp33_);
				_tmp35_ = _tmp34_;
				_tmp36_ = self->priv->db;
				_tmp37_ = dino_database_get_entity_identity (_tmp36_);
				_tmp38_ = _tmp37_;
				_tmp39_ = _tmp38_->entity_name;
				_tmp40_ = identity;
				_tmp41_ = xmpp_xep_service_discovery_identity_get_name (_tmp40_);
				_tmp42_ = _tmp41_;
				_tmp43_ = qlite_insert_builder_value (_tmp35_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp39_, _tmp42_);
				_tmp44_ = _tmp43_;
				qlite_insert_builder_perform (_tmp44_);
				_qlite_statement_builder_unref0 (_tmp44_);
				_qlite_statement_builder_unref0 (_tmp35_);
				_qlite_statement_builder_unref0 (_tmp26_);
				_qlite_statement_builder_unref0 (_tmp17_);
				_qlite_statement_builder_unref0 (_tmp11_);
				_xmpp_xep_service_discovery_identity_unref0 (identity);
				_g_object_unref0 (_identity_it);
				return;
			}
			_xmpp_xep_service_discovery_identity_unref0 (identity);
		}
		_g_object_unref0 (_identity_it);
	}
}

static gpointer
_qlite_column_ref0 (gpointer self)
{
	return self ? qlite_column_ref (self) : NULL;
}

static GeeList*
dino_entity_capabilities_storage_real_get_features (XmppXepEntityCapabilitiesStorage* base,
                                                    const gchar* entity)
{
	DinoEntityCapabilitiesStorage * self;
	GeeList* features = NULL;
	GeeHashMap* _tmp0_;
	gpointer _tmp1_;
	GeeList* _tmp2_;
	GeeArrayList* _tmp3_;
	GeeHashMap* _tmp35_;
	GeeList* _tmp36_;
	GeeList* result;
	self = (DinoEntityCapabilitiesStorage*) base;
	g_return_val_if_fail (entity != NULL, NULL);
	_tmp0_ = self->priv->features_cache;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, entity);
	features = (GeeList*) _tmp1_;
	_tmp2_ = features;
	if (_tmp2_ != NULL) {
		result = features;
		return result;
	}
	_tmp3_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	_g_object_unref0 (features);
	features = (GeeList*) _tmp3_;
	{
		QliteRowIterator* _row_it = NULL;
		DinoDatabase* _tmp4_;
		DinoDatabaseEntityFeatureTable* _tmp5_;
		DinoDatabaseEntityFeatureTable* _tmp6_;
		DinoDatabase* _tmp7_;
		DinoDatabaseEntityFeatureTable* _tmp8_;
		DinoDatabaseEntityFeatureTable* _tmp9_;
		QliteColumn* _tmp10_;
		QliteColumn* _tmp11_;
		QliteColumn** _tmp12_;
		QliteColumn** _tmp13_;
		gint _tmp13__length1;
		QliteQueryBuilder* _tmp14_;
		QliteQueryBuilder* _tmp15_;
		DinoDatabase* _tmp16_;
		DinoDatabaseEntityFeatureTable* _tmp17_;
		DinoDatabaseEntityFeatureTable* _tmp18_;
		QliteColumn* _tmp19_;
		QliteQueryBuilder* _tmp20_;
		QliteQueryBuilder* _tmp21_;
		QliteRowIterator* _tmp22_;
		QliteRowIterator* _tmp23_;
		_tmp4_ = self->priv->db;
		_tmp5_ = dino_database_get_entity_feature (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = self->priv->db;
		_tmp8_ = dino_database_get_entity_feature (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_->feature;
		_tmp11_ = _qlite_column_ref0 (_tmp10_);
		_tmp12_ = g_new0 (QliteColumn*, 1 + 1);
		_tmp12_[0] = _tmp11_;
		_tmp13_ = _tmp12_;
		_tmp13__length1 = 1;
		_tmp14_ = qlite_table_select ((QliteTable*) _tmp6_, _tmp13_, (gint) 1);
		_tmp15_ = _tmp14_;
		_tmp16_ = self->priv->db;
		_tmp17_ = dino_database_get_entity_feature (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = _tmp18_->entity;
		_tmp20_ = qlite_query_builder_with (_tmp15_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp19_, "=", entity);
		_tmp21_ = _tmp20_;
		_tmp22_ = qlite_query_builder_iterator (_tmp21_);
		_tmp23_ = _tmp22_;
		_qlite_statement_builder_unref0 (_tmp21_);
		_qlite_statement_builder_unref0 (_tmp15_);
		_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) qlite_column_unref), NULL);
		_row_it = _tmp23_;
		while (TRUE) {
			QliteRowIterator* _tmp24_;
			QliteRow* row = NULL;
			QliteRowIterator* _tmp25_;
			QliteRow* _tmp26_;
			GeeList* _tmp27_;
			QliteRow* _tmp28_;
			DinoDatabase* _tmp29_;
			DinoDatabaseEntityFeatureTable* _tmp30_;
			DinoDatabaseEntityFeatureTable* _tmp31_;
			QliteColumn* _tmp32_;
			gpointer _tmp33_;
			gchar* _tmp34_;
			_tmp24_ = _row_it;
			if (!qlite_row_iterator_next (_tmp24_)) {
				break;
			}
			_tmp25_ = _row_it;
			_tmp26_ = qlite_row_iterator_get (_tmp25_);
			row = _tmp26_;
			_tmp27_ = features;
			_tmp28_ = row;
			_tmp29_ = self->priv->db;
			_tmp30_ = dino_database_get_entity_feature (_tmp29_);
			_tmp31_ = _tmp30_;
			_tmp32_ = _tmp31_->feature;
			_tmp33_ = qlite_row_get (_tmp28_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp32_);
			_tmp34_ = (gchar*) _tmp33_;
			gee_collection_add ((GeeCollection*) _tmp27_, _tmp34_);
			_g_free0 (_tmp34_);
			_qlite_row_unref0 (row);
		}
		_qlite_row_iterator_unref0 (_row_it);
	}
	_tmp35_ = self->priv->features_cache;
	_tmp36_ = features;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp35_, entity, _tmp36_);
	result = features;
	return result;
}

static XmppXepServiceDiscoveryIdentity*
dino_entity_capabilities_storage_real_get_identities (XmppXepEntityCapabilitiesStorage* base,
                                                      const gchar* entity)
{
	DinoEntityCapabilitiesStorage * self;
	XmppXepServiceDiscoveryIdentity* identity = NULL;
	GeeHashMap* _tmp0_;
	gpointer _tmp1_;
	XmppXepServiceDiscoveryIdentity* _tmp2_;
	QliteRowOption* row = NULL;
	DinoDatabase* _tmp3_;
	DinoDatabaseEntityIdentityTable* _tmp4_;
	DinoDatabaseEntityIdentityTable* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	DinoDatabase* _tmp8_;
	DinoDatabaseEntityIdentityTable* _tmp9_;
	DinoDatabaseEntityIdentityTable* _tmp10_;
	QliteColumn* _tmp11_;
	QliteQueryBuilder* _tmp12_;
	QliteQueryBuilder* _tmp13_;
	QliteQueryBuilder* _tmp14_;
	QliteQueryBuilder* _tmp15_;
	QliteRowOption* _tmp16_;
	QliteRowOption* _tmp17_;
	QliteRowOption* _tmp18_;
	GeeHashMap* _tmp41_;
	XmppXepServiceDiscoveryIdentity* _tmp42_;
	XmppXepServiceDiscoveryIdentity* result;
	self = (DinoEntityCapabilitiesStorage*) base;
	g_return_val_if_fail (entity != NULL, NULL);
	_tmp0_ = self->priv->identity_cache;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, entity);
	identity = (XmppXepServiceDiscoveryIdentity*) _tmp1_;
	_tmp2_ = identity;
	if (_tmp2_ != NULL) {
		result = identity;
		return result;
	}
	_tmp3_ = self->priv->db;
	_tmp4_ = dino_database_get_entity_identity (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = qlite_table_select ((QliteTable*) _tmp5_, NULL, (gint) 0);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->db;
	_tmp9_ = dino_database_get_entity_identity (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_->entity;
	_tmp12_ = qlite_query_builder_with (_tmp7_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp11_, "=", entity);
	_tmp13_ = _tmp12_;
	_tmp14_ = qlite_query_builder_single (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = qlite_query_builder_row (_tmp15_);
	_tmp17_ = _tmp16_;
	_qlite_statement_builder_unref0 (_tmp15_);
	_qlite_statement_builder_unref0 (_tmp13_);
	_qlite_statement_builder_unref0 (_tmp7_);
	row = _tmp17_;
	_tmp18_ = row;
	if (qlite_row_option_is_present (_tmp18_)) {
		QliteRowOption* _tmp19_;
		DinoDatabase* _tmp20_;
		DinoDatabaseEntityIdentityTable* _tmp21_;
		DinoDatabaseEntityIdentityTable* _tmp22_;
		QliteColumn* _tmp23_;
		gpointer _tmp24_;
		gchar* _tmp25_;
		QliteRowOption* _tmp26_;
		DinoDatabase* _tmp27_;
		DinoDatabaseEntityIdentityTable* _tmp28_;
		DinoDatabaseEntityIdentityTable* _tmp29_;
		QliteColumn* _tmp30_;
		gpointer _tmp31_;
		gchar* _tmp32_;
		QliteRowOption* _tmp33_;
		DinoDatabase* _tmp34_;
		DinoDatabaseEntityIdentityTable* _tmp35_;
		DinoDatabaseEntityIdentityTable* _tmp36_;
		QliteColumn* _tmp37_;
		gpointer _tmp38_;
		gchar* _tmp39_;
		XmppXepServiceDiscoveryIdentity* _tmp40_;
		_tmp19_ = row;
		_tmp20_ = self->priv->db;
		_tmp21_ = dino_database_get_entity_identity (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = _tmp22_->category;
		_tmp24_ = qlite_row_option_get (_tmp19_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp23_, NULL);
		_tmp25_ = (gchar*) _tmp24_;
		_tmp26_ = row;
		_tmp27_ = self->priv->db;
		_tmp28_ = dino_database_get_entity_identity (_tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = _tmp29_->type;
		_tmp31_ = qlite_row_option_get (_tmp26_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp30_, NULL);
		_tmp32_ = (gchar*) _tmp31_;
		_tmp33_ = row;
		_tmp34_ = self->priv->db;
		_tmp35_ = dino_database_get_entity_identity (_tmp34_);
		_tmp36_ = _tmp35_;
		_tmp37_ = _tmp36_->entity_name;
		_tmp38_ = qlite_row_option_get (_tmp33_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp37_, NULL);
		_tmp39_ = (gchar*) _tmp38_;
		_tmp40_ = xmpp_xep_service_discovery_identity_new (_tmp25_, _tmp32_, _tmp39_);
		_xmpp_xep_service_discovery_identity_unref0 (identity);
		identity = _tmp40_;
		_g_free0 (_tmp39_);
		_g_free0 (_tmp32_);
		_g_free0 (_tmp25_);
	}
	_tmp41_ = self->priv->identity_cache;
	_tmp42_ = identity;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp41_, entity, _tmp42_);
	result = identity;
	_qlite_row_option_unref0 (row);
	return result;
}

static void
dino_entity_capabilities_storage_class_init (DinoEntityCapabilitiesStorageClass * klass,
                                             gpointer klass_data)
{
	dino_entity_capabilities_storage_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoEntityCapabilitiesStorage_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_entity_capabilities_storage_finalize;
}

static void
dino_entity_capabilities_storage_xmpp_xep_entity_capabilities_storage_interface_init (XmppXepEntityCapabilitiesStorageIface * iface,
                                                                                      gpointer iface_data)
{
	dino_entity_capabilities_storage_xmpp_xep_entity_capabilities_storage_parent_iface = g_type_interface_peek_parent (iface);
	iface->store_features = (void (*) (XmppXepEntityCapabilitiesStorage*, const gchar*, GeeList*)) dino_entity_capabilities_storage_real_store_features;
	iface->store_identities = (void (*) (XmppXepEntityCapabilitiesStorage*, const gchar*, GeeSet*)) dino_entity_capabilities_storage_real_store_identities;
	iface->get_features = (GeeList* (*) (XmppXepEntityCapabilitiesStorage*, const gchar*)) dino_entity_capabilities_storage_real_get_features;
	iface->get_identities = (XmppXepServiceDiscoveryIdentity* (*) (XmppXepEntityCapabilitiesStorage*, const gchar*)) dino_entity_capabilities_storage_real_get_identities;
}

static void
dino_entity_capabilities_storage_instance_init (DinoEntityCapabilitiesStorage * self,
                                                gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	self->priv = dino_entity_capabilities_storage_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->features_cache = _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, XMPP_XEP_SERVICE_DISCOVERY_TYPE_IDENTITY, (GBoxedCopyFunc) xmpp_xep_service_discovery_identity_ref, (GDestroyNotify) xmpp_xep_service_discovery_identity_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->identity_cache = _tmp1_;
}

static void
dino_entity_capabilities_storage_finalize (GObject * obj)
{
	DinoEntityCapabilitiesStorage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_ENTITY_CAPABILITIES_STORAGE, DinoEntityCapabilitiesStorage);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->features_cache);
	_g_object_unref0 (self->priv->identity_cache);
	G_OBJECT_CLASS (dino_entity_capabilities_storage_parent_class)->finalize (obj);
}

static GType
dino_entity_capabilities_storage_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoEntityCapabilitiesStorageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_entity_capabilities_storage_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoEntityCapabilitiesStorage), 0, (GInstanceInitFunc) dino_entity_capabilities_storage_instance_init, NULL };
	static const GInterfaceInfo xmpp_xep_entity_capabilities_storage_info = { (GInterfaceInitFunc) dino_entity_capabilities_storage_xmpp_xep_entity_capabilities_storage_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_entity_capabilities_storage_type_id;
	dino_entity_capabilities_storage_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoEntityCapabilitiesStorage", &g_define_type_info, 0);
	g_type_add_interface_static (dino_entity_capabilities_storage_type_id, XMPP_XEP_ENTITY_CAPABILITIES_TYPE_STORAGE, &xmpp_xep_entity_capabilities_storage_info);
	DinoEntityCapabilitiesStorage_private_offset = g_type_add_instance_private (dino_entity_capabilities_storage_type_id, sizeof (DinoEntityCapabilitiesStoragePrivate));
	return dino_entity_capabilities_storage_type_id;
}

GType
dino_entity_capabilities_storage_get_type (void)
{
	static volatile gsize dino_entity_capabilities_storage_type_id__once = 0;
	if (g_once_init_enter (&dino_entity_capabilities_storage_type_id__once)) {
		GType dino_entity_capabilities_storage_type_id;
		dino_entity_capabilities_storage_type_id = dino_entity_capabilities_storage_get_type_once ();
		g_once_init_leave (&dino_entity_capabilities_storage_type_id__once, dino_entity_capabilities_storage_type_id);
	}
	return dino_entity_capabilities_storage_type_id__once;
}

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

