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

/*
 * Copyright © 2025 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libsoup/soup.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.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  {
	SERVICES_CAL_DAV_CORE_0_PROPERTY,
	SERVICES_CAL_DAV_CORE_NUM_PROPERTIES
};
static GParamSpec* services_cal_dav_core_properties[SERVICES_CAL_DAV_CORE_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 _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
typedef struct _ServicesCalDavCoreResolveWellKnownCaldavData ServicesCalDavCoreResolveWellKnownCaldavData;
typedef struct _ServicesCalDavCoreResolveCalendarHomeData ServicesCalDavCoreResolveCalendarHomeData;
#define _http_response_unref0(var) ((var == NULL) ? NULL : (var = (http_response_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _ServicesCalDavCoreLoginData ServicesCalDavCoreLoginData;
typedef struct _ServicesCalDavCoreAddCaldavAccountData ServicesCalDavCoreAddCaldavAccountData;
typedef struct _ServicesCalDavCoreSyncData ServicesCalDavCoreSyncData;
enum  {
	SERVICES_CAL_DAV_CORE_SYNC_PROGRESS_SIGNAL,
	SERVICES_CAL_DAV_CORE_NUM_SIGNALS
};
static guint services_cal_dav_core_signals[SERVICES_CAL_DAV_CORE_NUM_SIGNALS] = {0};

struct _ServicesCalDAVCorePrivate {
	GeeHashMap* clients;
};

struct _ServicesCalDavCoreResolveWellKnownCaldavData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesCalDAVCore* self;
	SoupSession* session;
	gchar* base_url;
	gboolean ignore_ssl;
	gchar* result;
	ServicesLogService* _tmp0_;
	ServicesLogService* _tmp1_;
	gchar* well_known_url;
	gchar* _tmp2_;
	SoupMessage* msg;
	const gchar* _tmp3_;
	SoupMessage* _tmp4_;
	SoupMessage* _tmp5_;
	SoupMessageHeaders* _tmp6_;
	SoupMessageHeaders* _tmp7_;
	SoupMessage* _tmp8_;
	SoupMessage* _tmp9_;
	SoupMessage* _tmp10_;
	GBytes* _tmp11_;
	GBytes* _tmp12_;
	gboolean _tmp13_;
	gboolean _tmp14_;
	gboolean _tmp15_;
	SoupMessage* _tmp16_;
	guint _tmp17_;
	guint _tmp18_;
	SoupMessage* _tmp19_;
	guint _tmp20_;
	guint _tmp21_;
	SoupMessage* _tmp22_;
	guint _tmp23_;
	guint _tmp24_;
	SoupMessage* _tmp25_;
	guint _tmp26_;
	guint _tmp27_;
	gchar* location;
	SoupMessage* _tmp28_;
	SoupMessageHeaders* _tmp29_;
	SoupMessageHeaders* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	const gchar* _tmp33_;
	const gchar* _tmp34_;
	const gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* base_scheme;
	gchar* _tmp37_;
	gchar* location_scheme;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	gboolean _tmp40_;
	const gchar* _tmp41_;
	const gchar* _tmp42_;
	const gchar* _tmp43_;
	ServicesLogService* _tmp44_;
	ServicesLogService* _tmp45_;
	const gchar* _tmp46_;
	gchar* _tmp47_;
	gchar* _tmp48_;
	gchar* _tmp49_;
	ServicesLogService* _tmp50_;
	ServicesLogService* _tmp51_;
	const gchar* _tmp52_;
	gchar* _tmp53_;
	gchar* _tmp54_;
	gchar* _tmp55_;
	gchar* _tmp56_;
	GError* e;
	GError* _tmp57_;
	GError* _tmp58_;
	GError* _tmp59_;
	ServicesLogService* _tmp60_;
	ServicesLogService* _tmp61_;
	GError* _tmp62_;
	const gchar* _tmp63_;
	gchar* _tmp64_;
	gchar* _tmp65_;
	gchar* _tmp66_;
	GError* _inner_error0_;
};

struct _ServicesCalDavCoreResolveCalendarHomeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesCalDAVCore* self;
	CalDAVType caldav_type;
	gchar* dav_url;
	gchar* username;
	gchar* password;
	GCancellable* cancellable;
	gboolean ignore_ssl;
	gchar* result;
	ServicesLogService* _tmp0_;
	ServicesLogService* _tmp1_;
	ServicesCalDAVCalDAVClient* caldav_client;
	SoupSession* _tmp2_;
	SoupSession* _tmp3_;
	ServicesCalDAVCalDAVClient* _tmp4_;
	ServicesCalDAVCalDAVClient* _tmp5_;
	gchar* principal_url;
	ServicesCalDAVCalDAVClient* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	GError* _tmp9_;
	gchar* calendar_home;
	ServicesCalDAVCalDAVClient* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	GError* e;
	GError* _tmp13_;
	GError* _tmp14_;
	GError* _tmp15_;
	ServicesLogService* _tmp16_;
	ServicesLogService* _tmp17_;
	GError* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	GError* _tmp22_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	GError* _tmp26_;
	GError* _tmp27_;
	GError* _inner_error0_;
};

struct _ServicesCalDavCoreLoginData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesCalDAVCore* self;
	CalDAVType caldav_type;
	gchar* dav_url;
	gchar* username;
	gchar* password;
	gchar* calendar_home;
	GCancellable* cancellable;
	gboolean ignore_ssl;
	HttpResponse* result;
	ServicesLogService* _tmp0_;
	ServicesLogService* _tmp1_;
	HttpResponse* response;
	HttpResponse* _tmp2_;
	ServicesStore* _tmp3_;
	ServicesLogService* _tmp4_;
	ServicesLogService* _tmp5_;
	HttpResponse* _tmp6_;
	HttpResponse* _tmp7_;
	ServicesCalDAVCalDAVClient* caldav_client;
	SoupSession* _tmp8_;
	SoupSession* _tmp9_;
	ServicesCalDAVCalDAVClient* _tmp10_;
	ServicesCalDAVCalDAVClient* _tmp11_;
	gchar* principal_url;
	ServicesCalDAVCalDAVClient* _tmp12_;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	HttpResponse* _tmp15_;
	HttpResponse* _tmp16_;
	ObjectsSource* source;
	ObjectsSource* _tmp17_;
	ObjectsSource* _tmp18_;
	Util* _tmp19_;
	Util* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	ObjectsSource* _tmp23_;
	ObjectsSource* _tmp24_;
	GDateTime* _tmp25_;
	GDateTime* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	ObjectsSource* _tmp29_;
	ObjectsSourceCalDAVData* caldav_data;
	ObjectsSourceCalDAVData* _tmp30_;
	ObjectsSourceCalDAVData* _tmp31_;
	ObjectsSourceCalDAVData* _tmp32_;
	ObjectsSourceCalDAVData* _tmp33_;
	ObjectsSourceCalDAVData* _tmp34_;
	ObjectsSourceCalDAVData* _tmp35_;
	ObjectsSourceCalDAVData* _tmp36_;
	ObjectsSource* _tmp37_;
	ObjectsSourceCalDAVData* _tmp38_;
	GValue _data_object;
	GValue _tmp39_;
	ObjectsSource* _tmp40_;
	HttpResponse* _tmp41_;
	GValue _tmp42_;
	GValue _tmp43_;
	HttpResponse* _tmp44_;
	GeeHashMap* _tmp45_;
	ObjectsSource* _tmp46_;
	const gchar* _tmp47_;
	const gchar* _tmp48_;
	ServicesCalDAVCalDAVClient* _tmp49_;
	ServicesLogService* _tmp50_;
	ServicesLogService* _tmp51_;
	GError* e;
	ServicesLogService* _tmp52_;
	ServicesLogService* _tmp53_;
	GError* _tmp54_;
	const gchar* _tmp55_;
	gchar* _tmp56_;
	gchar* _tmp57_;
	HttpResponse* _tmp58_;
	GError* _tmp59_;
	HttpResponse* _tmp60_;
	GError* _tmp61_;
	const gchar* _tmp62_;
	GError* _inner_error0_;
};

struct _ServicesCalDavCoreAddCaldavAccountData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesCalDAVCore* self;
	ObjectsSource* source;
	GCancellable* cancellable;
	HttpResponse* result;
	ServicesLogService* _tmp0_;
	ServicesLogService* _tmp1_;
	HttpResponse* response;
	HttpResponse* _tmp2_;
	ServicesCalDAVCalDAVClient* caldav_client;
	ServicesCalDAVCalDAVClient* _tmp3_;
	gchar* principal_url;
	ServicesCalDAVCalDAVClient* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	HttpResponse* _tmp7_;
	HttpResponse* _tmp8_;
	ServicesCalDAVCalDAVClient* _tmp9_;
	const gchar* _tmp10_;
	GeeArrayList* projects;
	ServicesCalDAVCalDAVClient* _tmp11_;
	GeeArrayList* _tmp12_;
	GeeArrayList* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	gint processed;
	gint i;
	gboolean _tmp16_;
	GeeArrayList* _tmp17_;
	gint _tmp18_;
	gint _tmp19_;
	gint batch_end;
	GeeArrayList* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	gint j;
	gboolean _tmp23_;
	gint _tmp24_;
	ServicesStore* _tmp25_;
	GeeArrayList* _tmp26_;
	gpointer _tmp27_;
	ObjectsProject* _tmp28_;
	gint _vala1_j;
	gboolean _tmp29_;
	gint _tmp30_;
	GeeArrayList* _tmp31_;
	gint _tmp32_;
	gint _tmp33_;
	GeeArrayList* _tmp34_;
	gpointer _tmp35_;
	ObjectsProject* _tmp36_;
	const gchar* _tmp37_;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	gchar* _tmp40_;
	ServicesCalDAVCalDAVClient* _tmp41_;
	GeeArrayList* _tmp42_;
	gpointer _tmp43_;
	ObjectsProject* _tmp44_;
	gint _tmp45_;
	ServicesStore* _tmp46_;
	GeeArrayList* _tmp47_;
	gint _tmp48_;
	gint _tmp49_;
	GeeArrayList* _tmp50_;
	gint _tmp51_;
	gint _tmp52_;
	ServicesLogService* _tmp53_;
	ServicesLogService* _tmp54_;
	GeeArrayList* _tmp55_;
	gint _tmp56_;
	gint _tmp57_;
	gchar* _tmp58_;
	gchar* _tmp59_;
	HttpResponse* _tmp60_;
	GError* e;
	HttpResponse* _tmp61_;
	GError* _tmp62_;
	HttpResponse* _tmp63_;
	GError* _tmp64_;
	const gchar* _tmp65_;
	ServicesLogService* _tmp66_;
	ServicesLogService* _tmp67_;
	GError* _tmp68_;
	const gchar* _tmp69_;
	gchar* _tmp70_;
	gchar* _tmp71_;
	GError* _inner_error0_;
};

struct _ServicesCalDavCoreSyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesCalDAVCore* self;
	ObjectsSource* source;
	ServicesLogService* _tmp0_;
	ServicesLogService* _tmp1_;
	ServicesCalDAVCalDAVClient* caldav_client;
	ServicesCalDAVCalDAVClient* _tmp2_;
	GCancellable* cancellable;
	GCancellable* _tmp3_;
	ServicesCalDAVCalDAVClient* _tmp4_;
	GCancellable* _tmp5_;
	GeeArrayList* projects;
	ServicesStore* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	GeeArrayList* _tmp9_;
	ServicesLogService* _tmp10_;
	ServicesLogService* _tmp11_;
	GeeArrayList* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	GeeArrayList* _project_list;
	GeeArrayList* _tmp17_;
	gint _project_size;
	GeeArrayList* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	gint _project_index;
	gint _tmp21_;
	gint _tmp22_;
	ObjectsProject* project;
	GeeArrayList* _tmp23_;
	gpointer _tmp24_;
	const gchar* _tmp25_;
	ObjectsProject* _tmp26_;
	const gchar* _tmp27_;
	const gchar* _tmp28_;
	const gchar* _tmp29_;
	ObjectsProject* _tmp30_;
	const gchar* _tmp31_;
	const gchar* _tmp32_;
	ServicesLogService* _tmp33_;
	ServicesLogService* _tmp34_;
	ObjectsProject* _tmp35_;
	const gchar* _tmp36_;
	const gchar* _tmp37_;
	gchar* _tmp38_;
	gchar* _tmp39_;
	ServicesCalDAVCalDAVClient* _tmp40_;
	ObjectsProject* _tmp41_;
	GCancellable* _tmp42_;
	GDateTime* _tmp43_;
	GDateTime* _tmp44_;
	gchar* _tmp45_;
	gchar* _tmp46_;
	ServicesLogService* _tmp47_;
	ServicesLogService* _tmp48_;
	GError* e;
	ServicesLogService* _tmp49_;
	ServicesLogService* _tmp50_;
	const gchar* _tmp51_;
	const gchar* _tmp52_;
	GError* _tmp53_;
	const gchar* _tmp54_;
	gchar* _tmp55_;
	gchar* _tmp56_;
	gboolean _tmp57_;
	GError* _tmp58_;
	const gchar* _tmp59_;
	GError* _tmp60_;
	const gchar* _tmp61_;
	ServicesLogService* _tmp62_;
	ServicesLogService* _tmp63_;
	SyncStatus* _tmp64_;
	SyncStatus* _tmp65_;
	SyncStatus* _tmp66_;
	SyncStatus* _tmp67_;
	gboolean _tmp68_;
	GError* _tmp69_;
	const gchar* _tmp70_;
	GError* _tmp71_;
	const gchar* _tmp72_;
	ServicesLogService* _tmp73_;
	ServicesLogService* _tmp74_;
	SyncStatus* _tmp75_;
	SyncStatus* _tmp76_;
	SyncStatus* _tmp77_;
	SyncStatus* _tmp78_;
	GError* _inner_error0_;
};

static gint ServicesCalDAVCore_private_offset;
static gpointer services_cal_dav_core_parent_class = NULL;
static ServicesCalDAVCore* services_cal_dav_core__instance;
static ServicesCalDAVCore* services_cal_dav_core__instance = NULL;

static gchar* services_cal_dav_core_make_absolute_url (ServicesCalDAVCore* self,
                                                const gchar* base_url,
                                                const gchar* href);
static void services_cal_dav_core_resolve_well_known_caldav_data_free (gpointer _data);
static gboolean services_cal_dav_core_resolve_well_known_caldav_co (ServicesCalDavCoreResolveWellKnownCaldavData* _data_);
static gboolean ___lambda35_ (ServicesCalDAVCore* self);
static gboolean ____lambda35__soup_message_accept_certificate (SoupMessage* _sender,
                                                        GTlsCertificate* tls_peer_certificate,
                                                        GTlsCertificateFlags tls_peer_errors,
                                                        gpointer self);
static void services_cal_dav_core_resolve_well_known_caldav_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_);
static void services_cal_dav_core_resolve_calendar_home_data_free (gpointer _data);
static gboolean services_cal_dav_core_resolve_calendar_home_co (ServicesCalDavCoreResolveCalendarHomeData* _data_);
static void services_cal_dav_core_resolve_calendar_home_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void services_cal_dav_core_login_data_free (gpointer _data);
static gboolean services_cal_dav_core_login_co (ServicesCalDavCoreLoginData* _data_);
static void services_cal_dav_core_login_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_);
static void services_cal_dav_core_add_caldav_account_data_free (gpointer _data);
static gboolean services_cal_dav_core_add_caldav_account_co (ServicesCalDavCoreAddCaldavAccountData* _data_);
static void services_cal_dav_core_add_caldav_account_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
static void _________lambda36_ (ServicesCalDAVCore* self,
                         gint current,
                         gint total,
                         const gchar* msg);
static void __________lambda36__services_cal_dav_cal_dav_client_progress_callback (gint current,
                                                                            gint total,
                                                                            const gchar* message,
                                                                            gpointer self);
static void services_cal_dav_core_sync_data_free (gpointer _data);
static gboolean services_cal_dav_core_sync_co (ServicesCalDavCoreSyncData* _data_);
static void services_cal_dav_core_sync_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
static void g_cclosure_user_marshal_VOID__INT_INT_STRING (GClosure * closure,
                                                   GValue * return_value,
                                                   guint n_param_values,
                                                   const GValue * param_values,
                                                   gpointer invocation_hint,
                                                   gpointer marshal_data);
static void services_cal_dav_core_finalize (GObject * obj);
static GType services_cal_dav_core_get_type_once (void);

static inline gpointer
services_cal_dav_core_get_instance_private (ServicesCalDAVCore* self)
{
	return G_STRUCT_MEMBER_P (self, ServicesCalDAVCore_private_offset);
}

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

ServicesCalDAVCore*
services_cal_dav_core_get_default (void)
{
	ServicesCalDAVCore* _tmp0_;
	ServicesCalDAVCore* _tmp2_;
	ServicesCalDAVCore* _tmp3_;
	ServicesCalDAVCore* result;
	_tmp0_ = services_cal_dav_core__instance;
	if (_tmp0_ == NULL) {
		ServicesCalDAVCore* _tmp1_;
		_tmp1_ = services_cal_dav_core_new ();
		_g_object_unref0 (services_cal_dav_core__instance);
		services_cal_dav_core__instance = _tmp1_;
	}
	_tmp2_ = services_cal_dav_core__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

ServicesCalDAVCore*
services_cal_dav_core_construct (GType object_type)
{
	ServicesCalDAVCore * self = NULL;
	GeeHashMap* _tmp0_;
	self = (ServicesCalDAVCore*) g_object_new (object_type, NULL);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, SERVICES_CAL_DAV_TYPE_CAL_DAV_CLIENT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->clients);
	self->priv->clients = _tmp0_;
	return self;
}

ServicesCalDAVCore*
services_cal_dav_core_new (void)
{
	return services_cal_dav_core_construct (SERVICES_CAL_DAV_TYPE_CORE);
}

ServicesCalDAVCalDAVClient*
services_cal_dav_core_get_client (ServicesCalDAVCore* self,
                                  ObjectsSource* source)
{
	GeeHashMap* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GeeHashMap* _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	gpointer _tmp32_;
	ServicesCalDAVCalDAVClient* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (source != NULL, NULL);
	_tmp0_ = self->priv->clients;
	_tmp1_ = objects_base_object_get_id ((ObjectsBaseObject*) source);
	_tmp2_ = _tmp1_;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, _tmp2_)) {
		ServicesLogService* _tmp3_;
		ServicesLogService* _tmp4_;
		ServicesCalDAVCalDAVClient* client = NULL;
		SoupSession* _tmp5_;
		SoupSession* _tmp6_;
		ObjectsSourceCalDAVData* _tmp7_;
		ObjectsSourceCalDAVData* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		ObjectsSourceCalDAVData* _tmp11_;
		ObjectsSourceCalDAVData* _tmp12_;
		const gchar* _tmp13_;
		const gchar* _tmp14_;
		ObjectsSourceCalDAVData* _tmp15_;
		ObjectsSourceCalDAVData* _tmp16_;
		const gchar* _tmp17_;
		const gchar* _tmp18_;
		ObjectsSourceCalDAVData* _tmp19_;
		ObjectsSourceCalDAVData* _tmp20_;
		gboolean _tmp21_;
		gboolean _tmp22_;
		ServicesCalDAVCalDAVClient* _tmp23_;
		ServicesCalDAVCalDAVClient* _tmp24_;
		GeeHashMap* _tmp25_;
		const gchar* _tmp26_;
		const gchar* _tmp27_;
		ServicesCalDAVCalDAVClient* _tmp28_;
		_tmp3_ = services_log_service_get_default ();
		_tmp4_ = _tmp3_;
		services_log_service_info (_tmp4_, "CalDAV.Core", "Creating new client for source");
		_g_object_unref0 (_tmp4_);
		_tmp5_ = soup_session_new ();
		_tmp6_ = _tmp5_;
		_tmp7_ = objects_source_get_caldav_data (source);
		_tmp8_ = _tmp7_;
		_tmp9_ = objects_source_cal_dav_data_get_server_url (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = objects_source_get_caldav_data (source);
		_tmp12_ = _tmp11_;
		_tmp13_ = objects_source_cal_dav_data_get_username (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp15_ = objects_source_get_caldav_data (source);
		_tmp16_ = _tmp15_;
		_tmp17_ = objects_source_cal_dav_data_get_password (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = objects_source_get_caldav_data (source);
		_tmp20_ = _tmp19_;
		_tmp21_ = objects_source_cal_dav_data_get_ignore_ssl (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = services_cal_dav_cal_dav_client_new (_tmp6_, _tmp10_, _tmp14_, _tmp18_, _tmp22_);
		_tmp24_ = _tmp23_;
		_g_object_unref0 (_tmp6_);
		client = _tmp24_;
		_tmp25_ = self->priv->clients;
		_tmp26_ = objects_base_object_get_id ((ObjectsBaseObject*) source);
		_tmp27_ = _tmp26_;
		_tmp28_ = client;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp25_, _tmp27_, _tmp28_);
		_g_object_unref0 (client);
	}
	_tmp29_ = self->priv->clients;
	_tmp30_ = objects_base_object_get_id ((ObjectsBaseObject*) source);
	_tmp31_ = _tmp30_;
	_tmp32_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp29_, _tmp31_);
	result = (ServicesCalDAVCalDAVClient*) _tmp32_;
	return result;
}

ServicesCalDAVCalDAVClient*
services_cal_dav_core_get_client_by_id (ServicesCalDAVCore* self,
                                        const gchar* source_id)
{
	GeeHashMap* _tmp0_;
	ServicesCalDAVCalDAVClient* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (source_id != NULL, NULL);
	_tmp0_ = self->priv->clients;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, source_id)) {
		GeeHashMap* _tmp1_;
		gpointer _tmp2_;
		_tmp1_ = self->priv->clients;
		_tmp2_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp1_, source_id);
		result = (ServicesCalDAVCalDAVClient*) _tmp2_;
		return result;
	}
	result = NULL;
	return result;
}

void
services_cal_dav_core_remove_client (ServicesCalDAVCore* self,
                                     const gchar* source_id)
{
	ServicesLogService* _tmp0_;
	ServicesLogService* _tmp1_;
	GeeHashMap* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source_id != NULL);
	_tmp0_ = services_log_service_get_default ();
	_tmp1_ = _tmp0_;
	services_log_service_info (_tmp1_, "CalDAV.Core", "Removing client");
	_g_object_unref0 (_tmp1_);
	_tmp2_ = self->priv->clients;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp2_, source_id, NULL);
}

void
services_cal_dav_core_clear (ServicesCalDAVCore* self)
{
	GeeHashMap* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->clients;
	gee_abstract_map_clear ((GeeAbstractMap*) _tmp0_);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static gchar*
services_cal_dav_core_make_absolute_url (ServicesCalDAVCore* self,
                                         const gchar* base_url,
                                         const gchar* href)
{
	gchar* abs_url = NULL;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (base_url != NULL, NULL);
	g_return_val_if_fail (href != NULL, NULL);
	abs_url = NULL;
	{
		gchar* _tmp0_ = NULL;
		gchar* _tmp1_;
		const gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp1_ = g_uri_resolve_relative (base_url, href, G_URI_FLAGS_NONE, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = string_to_string (_tmp0_);
		_tmp3_ = g_strdup (_tmp2_);
		_g_free0 (abs_url);
		abs_url = _tmp3_;
		_g_free0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		ServicesLogService* _tmp4_;
		ServicesLogService* _tmp5_;
		GError* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = services_log_service_get_default ();
		_tmp5_ = _tmp4_;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		_tmp8_ = g_strdup_printf ("Failed to resolve relative url: %s", _tmp7_);
		_tmp9_ = _tmp8_;
		services_log_service_error (_tmp5_, "CalDAV.Core", _tmp9_);
		_g_free0 (_tmp9_);
		_g_object_unref0 (_tmp5_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (abs_url);
		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 NULL;
	}
	result = abs_url;
	return result;
}

static void
services_cal_dav_core_resolve_well_known_caldav_data_free (gpointer _data)
{
	ServicesCalDavCoreResolveWellKnownCaldavData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->session);
	_g_free0 (_data_->base_url);
	_g_free0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesCalDavCoreResolveWellKnownCaldavData, _data_);
}

void
services_cal_dav_core_resolve_well_known_caldav (ServicesCalDAVCore* self,
                                                 SoupSession* session,
                                                 const gchar* base_url,
                                                 gboolean ignore_ssl,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	ServicesCalDavCoreResolveWellKnownCaldavData* _data_;
	ServicesCalDAVCore* _tmp0_;
	SoupSession* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	g_return_if_fail (base_url != NULL);
	_data_ = g_slice_new0 (ServicesCalDavCoreResolveWellKnownCaldavData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_cal_dav_core_resolve_well_known_caldav_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (session);
	_g_object_unref0 (_data_->session);
	_data_->session = _tmp1_;
	_tmp2_ = g_strdup (base_url);
	_g_free0 (_data_->base_url);
	_data_->base_url = _tmp2_;
	_data_->ignore_ssl = ignore_ssl;
	services_cal_dav_core_resolve_well_known_caldav_co (_data_);
}

gchar*
services_cal_dav_core_resolve_well_known_caldav_finish (ServicesCalDAVCore* self,
                                                        GAsyncResult* _res_,
                                                        GError** error)
{
	gchar* result;
	ServicesCalDavCoreResolveWellKnownCaldavData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
___lambda35_ (ServicesCalDAVCore* self)
{
	gboolean result;
	result = TRUE;
	return result;
}

static gboolean
____lambda35__soup_message_accept_certificate (SoupMessage* _sender,
                                               GTlsCertificate* tls_peer_certificate,
                                               GTlsCertificateFlags tls_peer_errors,
                                               gpointer self)
{
	gboolean result;
	result = ___lambda35_ ((ServicesCalDAVCore*) self);
	return result;
}

static void
services_cal_dav_core_resolve_well_known_caldav_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_)
{
	ServicesCalDavCoreResolveWellKnownCaldavData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_cal_dav_core_resolve_well_known_caldav_co (_data_);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static gboolean
services_cal_dav_core_resolve_well_known_caldav_co (ServicesCalDavCoreResolveWellKnownCaldavData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = services_log_service_get_default ();
	_data_->_tmp1_ = _data_->_tmp0_;
	services_log_service_info (_data_->_tmp1_, "CalDAV.Core", "Resolving .well-known/caldav");
	_g_object_unref0 (_data_->_tmp1_);
	_data_->_tmp2_ = services_cal_dav_core_make_absolute_url (_data_->self, _data_->base_url, "/.well-known/caldav");
	_data_->well_known_url = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->well_known_url;
	_data_->_tmp4_ = soup_message_new ("GET", _data_->_tmp3_);
	_data_->msg = _data_->_tmp4_;
	_data_->_tmp5_ = _data_->msg;
	_data_->_tmp6_ = soup_message_get_request_headers (_data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	soup_message_headers_append (_data_->_tmp7_, "User-Agent", CONSTANTS_SOUP_USER_AGENT);
	_data_->_tmp8_ = _data_->msg;
	soup_message_set_flags (_data_->_tmp8_, SOUP_MESSAGE_NO_REDIRECT);
	if (_data_->ignore_ssl) {
		_data_->_tmp9_ = _data_->msg;
		g_signal_connect_object (_data_->_tmp9_, "accept-certificate", (GCallback) ____lambda35__soup_message_accept_certificate, _data_->self, 0);
	}
	{
		_data_->_tmp10_ = _data_->msg;
		_data_->_state_ = 1;
		soup_session_send_and_read_async (_data_->session, _data_->_tmp10_, G_PRIORITY_DEFAULT, NULL, services_cal_dav_core_resolve_well_known_caldav_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp11_ = soup_session_send_and_read_finish (_data_->session, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp12_ = _data_->_tmp11_;
		_g_bytes_unref0 (_data_->_tmp12_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp16_ = _data_->msg;
		g_object_get (_data_->_tmp16_, "status-code", &_data_->_tmp17_, NULL);
		_data_->_tmp18_ = _data_->_tmp17_;
		if (_data_->_tmp18_ == ((guint) 301)) {
			_data_->_tmp15_ = TRUE;
		} else {
			_data_->_tmp19_ = _data_->msg;
			g_object_get (_data_->_tmp19_, "status-code", &_data_->_tmp20_, NULL);
			_data_->_tmp21_ = _data_->_tmp20_;
			_data_->_tmp15_ = _data_->_tmp21_ == ((guint) 302);
		}
		if (_data_->_tmp15_) {
			_data_->_tmp14_ = TRUE;
		} else {
			_data_->_tmp22_ = _data_->msg;
			g_object_get (_data_->_tmp22_, "status-code", &_data_->_tmp23_, NULL);
			_data_->_tmp24_ = _data_->_tmp23_;
			_data_->_tmp14_ = _data_->_tmp24_ == ((guint) 307);
		}
		if (_data_->_tmp14_) {
			_data_->_tmp13_ = TRUE;
		} else {
			_data_->_tmp25_ = _data_->msg;
			g_object_get (_data_->_tmp25_, "status-code", &_data_->_tmp26_, NULL);
			_data_->_tmp27_ = _data_->_tmp26_;
			_data_->_tmp13_ = _data_->_tmp27_ == ((guint) 308);
		}
		if (_data_->_tmp13_) {
			_data_->_tmp28_ = _data_->msg;
			_data_->_tmp29_ = soup_message_get_response_headers (_data_->_tmp28_);
			_data_->_tmp30_ = _data_->_tmp29_;
			_data_->_tmp31_ = soup_message_headers_get_one (_data_->_tmp30_, "Location");
			_data_->_tmp32_ = g_strdup (_data_->_tmp31_);
			_data_->location = _data_->_tmp32_;
			_data_->_tmp33_ = _data_->location;
			if (_data_->_tmp33_ != NULL) {
				_data_->_tmp34_ = _data_->location;
				if (g_str_has_prefix (_data_->_tmp34_, "/")) {
					_data_->_tmp35_ = _data_->location;
					_data_->_tmp36_ = services_cal_dav_core_make_absolute_url (_data_->self, _data_->base_url, _data_->_tmp35_);
					_g_free0 (_data_->location);
					_data_->location = _data_->_tmp36_;
				}
				_data_->_tmp37_ = g_uri_parse_scheme (_data_->base_url);
				_data_->base_scheme = _data_->_tmp37_;
				_data_->_tmp38_ = _data_->location;
				_data_->_tmp39_ = g_uri_parse_scheme (_data_->_tmp38_);
				_data_->location_scheme = _data_->_tmp39_;
				_data_->_tmp41_ = _data_->base_scheme;
				if (g_strcmp0 (_data_->_tmp41_, "https") == 0) {
					_data_->_tmp42_ = _data_->location_scheme;
					_data_->_tmp40_ = g_strcmp0 (_data_->_tmp42_, "http") == 0;
				} else {
					_data_->_tmp40_ = FALSE;
				}
				if (_data_->_tmp40_) {
					_data_->_tmp43_ = _data_->location;
					if (g_str_has_prefix (_data_->_tmp43_, "http://")) {
						_data_->_tmp44_ = services_log_service_get_default ();
						_data_->_tmp45_ = _data_->_tmp44_;
						services_log_service_warn (_data_->_tmp45_, "CalDAV.Core", "Resolving .well-known/caldav caused a redirect from https to http. Pre" \
"venting downgrade.");
						_g_object_unref0 (_data_->_tmp45_);
						_data_->_tmp46_ = _data_->location;
						_data_->_tmp47_ = string_substring (_data_->_tmp46_, (glong) 4, (glong) -1);
						_data_->_tmp48_ = _data_->_tmp47_;
						_data_->_tmp49_ = g_strconcat ("https", _data_->_tmp48_, NULL);
						_g_free0 (_data_->location);
						_data_->location = _data_->_tmp49_;
						_g_free0 (_data_->_tmp48_);
					} else {
						_data_->_tmp50_ = services_log_service_get_default ();
						_data_->_tmp51_ = _data_->_tmp50_;
						_data_->_tmp52_ = _data_->location;
						_data_->_tmp53_ = g_strdup_printf ("Redirect location has http scheme but unexpected format: %s", _data_->_tmp52_);
						_data_->_tmp54_ = _data_->_tmp53_;
						services_log_service_warn (_data_->_tmp51_, "CalDAV.Core", _data_->_tmp54_);
						_g_free0 (_data_->_tmp54_);
						_g_object_unref0 (_data_->_tmp51_);
						_data_->_tmp55_ = g_strdup (_data_->base_url);
						_data_->result = _data_->_tmp55_;
						_g_free0 (_data_->location_scheme);
						_g_free0 (_data_->base_scheme);
						_g_free0 (_data_->location);
						_g_object_unref0 (_data_->msg);
						_g_free0 (_data_->well_known_url);
						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;
					}
				}
				_data_->result = _data_->location;
				_g_free0 (_data_->location_scheme);
				_g_free0 (_data_->base_scheme);
				_g_object_unref0 (_data_->msg);
				_g_free0 (_data_->well_known_url);
				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;
			}
			_g_free0 (_data_->location);
		}
		_data_->_tmp56_ = g_strdup (_data_->base_url);
		_data_->result = _data_->_tmp56_;
		_g_object_unref0 (_data_->msg);
		_g_free0 (_data_->well_known_url);
		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;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp57_ = _data_->e;
		if (g_error_matches (_data_->_tmp57_, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
			_data_->_tmp58_ = _data_->e;
			_data_->_tmp59_ = _g_error_copy0 (_data_->_tmp58_);
			_data_->_inner_error0_ = _data_->_tmp59_;
			_g_error_free0 (_data_->e);
			goto __finally0;
		}
		_data_->_tmp60_ = services_log_service_get_default ();
		_data_->_tmp61_ = _data_->_tmp60_;
		_data_->_tmp62_ = _data_->e;
		_data_->_tmp63_ = _data_->_tmp62_->message;
		_data_->_tmp64_ = g_strdup_printf ("Failed to check .well-known/caldav: %s", _data_->_tmp63_);
		_data_->_tmp65_ = _data_->_tmp64_;
		services_log_service_warn (_data_->_tmp61_, "CalDAV.Core", _data_->_tmp65_);
		_g_free0 (_data_->_tmp65_);
		_g_object_unref0 (_data_->_tmp61_);
		_data_->_tmp66_ = g_strdup (_data_->base_url);
		_data_->result = _data_->_tmp66_;
		_g_error_free0 (_data_->e);
		_g_object_unref0 (_data_->msg);
		_g_free0 (_data_->well_known_url);
		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;
	}
	__finally0:
	g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
	_g_object_unref0 (_data_->msg);
	_g_free0 (_data_->well_known_url);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
services_cal_dav_core_resolve_calendar_home_data_free (gpointer _data)
{
	ServicesCalDavCoreResolveCalendarHomeData* _data_;
	_data_ = _data;
	_g_free0 (_data_->dav_url);
	_g_free0 (_data_->username);
	_g_free0 (_data_->password);
	_g_object_unref0 (_data_->cancellable);
	_g_free0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesCalDavCoreResolveCalendarHomeData, _data_);
}

void
services_cal_dav_core_resolve_calendar_home (ServicesCalDAVCore* self,
                                             CalDAVType caldav_type,
                                             const gchar* dav_url,
                                             const gchar* username,
                                             const gchar* password,
                                             GCancellable* cancellable,
                                             gboolean ignore_ssl,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	ServicesCalDavCoreResolveCalendarHomeData* _data_;
	ServicesCalDAVCore* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dav_url != NULL);
	g_return_if_fail (username != NULL);
	g_return_if_fail (password != NULL);
	g_return_if_fail (cancellable != NULL);
	_data_ = g_slice_new0 (ServicesCalDavCoreResolveCalendarHomeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_cal_dav_core_resolve_calendar_home_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->caldav_type = caldav_type;
	_tmp1_ = g_strdup (dav_url);
	_g_free0 (_data_->dav_url);
	_data_->dav_url = _tmp1_;
	_tmp2_ = g_strdup (username);
	_g_free0 (_data_->username);
	_data_->username = _tmp2_;
	_tmp3_ = g_strdup (password);
	_g_free0 (_data_->password);
	_data_->password = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	_data_->ignore_ssl = ignore_ssl;
	services_cal_dav_core_resolve_calendar_home_co (_data_);
}

gchar*
services_cal_dav_core_resolve_calendar_home_finish (ServicesCalDAVCore* self,
                                                    GAsyncResult* _res_,
                                                    GError** error)
{
	gchar* result;
	ServicesCalDavCoreResolveCalendarHomeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
services_cal_dav_core_resolve_calendar_home_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	ServicesCalDavCoreResolveCalendarHomeData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_cal_dav_core_resolve_calendar_home_co (_data_);
}

static gboolean
services_cal_dav_core_resolve_calendar_home_co (ServicesCalDavCoreResolveCalendarHomeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = services_log_service_get_default ();
	_data_->_tmp1_ = _data_->_tmp0_;
	services_log_service_info (_data_->_tmp1_, "CalDAV.Core", "Resolving calendar home");
	_g_object_unref0 (_data_->_tmp1_);
	_data_->_tmp2_ = soup_session_new ();
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = services_cal_dav_cal_dav_client_new (_data_->_tmp3_, _data_->dav_url, _data_->username, _data_->password, _data_->ignore_ssl);
	_data_->_tmp5_ = _data_->_tmp4_;
	_g_object_unref0 (_data_->_tmp3_);
	_data_->caldav_client = _data_->_tmp5_;
	{
		_data_->_tmp6_ = _data_->caldav_client;
		_data_->_state_ = 1;
		services_cal_dav_cal_dav_client_get_principal_url (_data_->_tmp6_, _data_->cancellable, services_cal_dav_core_resolve_calendar_home_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp7_ = services_cal_dav_cal_dav_client_get_principal_url_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
		_data_->principal_url = _data_->_tmp7_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp8_ = _data_->principal_url;
		if (_data_->_tmp8_ == NULL) {
			_data_->_tmp9_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "No principal url received");
			_data_->_inner_error0_ = _data_->_tmp9_;
			_g_free0 (_data_->principal_url);
			goto __catch0_g_error;
		}
		_data_->_tmp10_ = _data_->caldav_client;
		_data_->_tmp11_ = _data_->principal_url;
		_data_->_state_ = 2;
		services_cal_dav_cal_dav_client_get_calendar_home (_data_->_tmp10_, _data_->_tmp11_, _data_->cancellable, services_cal_dav_core_resolve_calendar_home_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp12_ = services_cal_dav_cal_dav_client_get_calendar_home_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
		_data_->calendar_home = _data_->_tmp12_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->principal_url);
			goto __catch0_g_error;
		}
		_data_->result = _data_->calendar_home;
		_g_free0 (_data_->principal_url);
		_g_object_unref0 (_data_->caldav_client);
		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;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp13_ = _data_->e;
		if (g_error_matches (_data_->_tmp13_, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
			_data_->_tmp14_ = _data_->e;
			_data_->_tmp15_ = _g_error_copy0 (_data_->_tmp14_);
			_data_->_inner_error0_ = _data_->_tmp15_;
			_g_error_free0 (_data_->e);
			goto __finally0;
		}
		_data_->_tmp16_ = services_log_service_get_default ();
		_data_->_tmp17_ = _data_->_tmp16_;
		_data_->_tmp18_ = _data_->e;
		_data_->_tmp19_ = _data_->_tmp18_->message;
		_data_->_tmp20_ = g_strdup_printf ("Failed to resolve calendar home: %s", _data_->_tmp19_);
		_data_->_tmp21_ = _data_->_tmp20_;
		services_log_service_error (_data_->_tmp17_, "CalDAV.Core", _data_->_tmp21_);
		_g_free0 (_data_->_tmp21_);
		_g_object_unref0 (_data_->_tmp17_);
		_data_->_tmp22_ = _data_->e;
		_data_->_tmp23_ = _data_->_tmp22_->message;
		_data_->_tmp24_ = g_strdup_printf ("Failed to resolve calendar home: %s", _data_->_tmp23_);
		_data_->_tmp25_ = _data_->_tmp24_;
		_data_->_tmp26_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp25_);
		_data_->_tmp27_ = _data_->_tmp26_;
		_g_free0 (_data_->_tmp25_);
		_data_->_inner_error0_ = _data_->_tmp27_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
	_g_object_unref0 (_data_->caldav_client);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
services_cal_dav_core_login_data_free (gpointer _data)
{
	ServicesCalDavCoreLoginData* _data_;
	_data_ = _data;
	_g_free0 (_data_->dav_url);
	_g_free0 (_data_->username);
	_g_free0 (_data_->password);
	_g_free0 (_data_->calendar_home);
	_g_object_unref0 (_data_->cancellable);
	_http_response_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesCalDavCoreLoginData, _data_);
}

void
services_cal_dav_core_login (ServicesCalDAVCore* self,
                             CalDAVType caldav_type,
                             const gchar* dav_url,
                             const gchar* username,
                             const gchar* password,
                             const gchar* calendar_home,
                             GCancellable* cancellable,
                             gboolean ignore_ssl,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_)
{
	ServicesCalDavCoreLoginData* _data_;
	ServicesCalDAVCore* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GCancellable* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dav_url != NULL);
	g_return_if_fail (username != NULL);
	g_return_if_fail (password != NULL);
	g_return_if_fail (calendar_home != NULL);
	g_return_if_fail (cancellable != NULL);
	_data_ = g_slice_new0 (ServicesCalDavCoreLoginData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_cal_dav_core_login_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->caldav_type = caldav_type;
	_tmp1_ = g_strdup (dav_url);
	_g_free0 (_data_->dav_url);
	_data_->dav_url = _tmp1_;
	_tmp2_ = g_strdup (username);
	_g_free0 (_data_->username);
	_data_->username = _tmp2_;
	_tmp3_ = g_strdup (password);
	_g_free0 (_data_->password);
	_data_->password = _tmp3_;
	_tmp4_ = g_strdup (calendar_home);
	_g_free0 (_data_->calendar_home);
	_data_->calendar_home = _tmp4_;
	_tmp5_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp5_;
	_data_->ignore_ssl = ignore_ssl;
	services_cal_dav_core_login_co (_data_);
}

HttpResponse*
services_cal_dav_core_login_finish (ServicesCalDAVCore* self,
                                    GAsyncResult* _res_)
{
	HttpResponse* result;
	ServicesCalDavCoreLoginData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
services_cal_dav_core_login_ready (GObject* source_object,
                                   GAsyncResult* _res_,
                                   gpointer _user_data_)
{
	ServicesCalDavCoreLoginData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_cal_dav_core_login_co (_data_);
}

static gchar*
g_date_time_to_string (GDateTime* self)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_format (self, "%FT%H:%M:%S%z");
	result = _tmp0_;
	return result;
}

static gboolean
services_cal_dav_core_login_co (ServicesCalDavCoreLoginData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = services_log_service_get_default ();
	_data_->_tmp1_ = _data_->_tmp0_;
	services_log_service_info (_data_->_tmp1_, "CalDAV.Core", "Starting login");
	_g_object_unref0 (_data_->_tmp1_);
	_data_->_tmp2_ = http_response_new ();
	_data_->response = _data_->_tmp2_;
	_data_->_tmp3_ = services_store_instance ();
	if (services_store_source_caldav_exists (_data_->_tmp3_, _data_->dav_url, _data_->username)) {
		_data_->_tmp4_ = services_log_service_get_default ();
		_data_->_tmp5_ = _data_->_tmp4_;
		services_log_service_warn (_data_->_tmp5_, "CalDAV.Core", "Source already exists, aborting login");
		_g_object_unref0 (_data_->_tmp5_);
		_data_->_tmp6_ = _data_->response;
		http_response_set_error_code (_data_->_tmp6_, 409);
		_data_->_tmp7_ = _data_->response;
		http_response_set_error (_data_->_tmp7_, _ ("Source already exists"));
		_data_->result = _data_->response;
		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;
	}
	_data_->_tmp8_ = soup_session_new ();
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_tmp10_ = services_cal_dav_cal_dav_client_new (_data_->_tmp9_, _data_->dav_url, _data_->username, _data_->password, _data_->ignore_ssl);
	_data_->_tmp11_ = _data_->_tmp10_;
	_g_object_unref0 (_data_->_tmp9_);
	_data_->caldav_client = _data_->_tmp11_;
	{
		_data_->_tmp12_ = _data_->caldav_client;
		_data_->_state_ = 1;
		services_cal_dav_cal_dav_client_get_principal_url (_data_->_tmp12_, _data_->cancellable, services_cal_dav_core_login_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp13_ = services_cal_dav_cal_dav_client_get_principal_url_finish (_data_->_tmp12_, _data_->_res_, &_data_->_inner_error0_);
		_data_->principal_url = _data_->_tmp13_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp14_ = _data_->principal_url;
		if (_data_->_tmp14_ == NULL) {
			_data_->_tmp15_ = _data_->response;
			http_response_set_error_code (_data_->_tmp15_, 409);
			_data_->_tmp16_ = _data_->response;
			http_response_set_error (_data_->_tmp16_, _ ("Failed to resolve principal url"));
			_data_->result = _data_->response;
			_g_free0 (_data_->principal_url);
			_g_object_unref0 (_data_->caldav_client);
			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;
		}
		_data_->_tmp17_ = objects_source_new ();
		_data_->source = _data_->_tmp17_;
		_data_->_tmp18_ = _data_->source;
		_data_->_tmp19_ = util_get_default ();
		_data_->_tmp20_ = _data_->_tmp19_;
		_data_->_tmp21_ = util_generate_id (_data_->_tmp20_, NULL);
		_data_->_tmp22_ = _data_->_tmp21_;
		objects_base_object_set_id ((ObjectsBaseObject*) _data_->_tmp18_, _data_->_tmp22_);
		_g_free0 (_data_->_tmp22_);
		_g_object_unref0 (_data_->_tmp20_);
		_data_->_tmp23_ = _data_->source;
		objects_source_set_source_type (_data_->_tmp23_, SOURCE_TYPE_CALDAV);
		_data_->_tmp24_ = _data_->source;
		_data_->_tmp25_ = g_date_time_new_now_local ();
		_data_->_tmp26_ = _data_->_tmp25_;
		_data_->_tmp27_ = g_date_time_to_string (_data_->_tmp26_);
		_data_->_tmp28_ = _data_->_tmp27_;
		objects_source_set_last_sync (_data_->_tmp24_, _data_->_tmp28_);
		_g_free0 (_data_->_tmp28_);
		_g_date_time_unref0 (_data_->_tmp26_);
		_data_->_tmp29_ = _data_->source;
		objects_source_set_sync_server (_data_->_tmp29_, TRUE);
		_data_->_tmp30_ = objects_source_cal_dav_data_new ();
		_data_->caldav_data = _data_->_tmp30_;
		_data_->_tmp31_ = _data_->caldav_data;
		objects_source_cal_dav_data_set_server_url (_data_->_tmp31_, _data_->dav_url);
		_data_->_tmp32_ = _data_->caldav_data;
		objects_source_cal_dav_data_set_calendar_home_url (_data_->_tmp32_, _data_->calendar_home);
		_data_->_tmp33_ = _data_->caldav_data;
		objects_source_cal_dav_data_set_username (_data_->_tmp33_, _data_->username);
		_data_->_tmp34_ = _data_->caldav_data;
		objects_source_cal_dav_data_set_password (_data_->_tmp34_, _data_->password);
		_data_->_tmp35_ = _data_->caldav_data;
		objects_source_cal_dav_data_set_caldav_type (_data_->_tmp35_, _data_->caldav_type);
		_data_->_tmp36_ = _data_->caldav_data;
		objects_source_cal_dav_data_set_ignore_ssl (_data_->_tmp36_, _data_->ignore_ssl);
		_data_->_tmp37_ = _data_->source;
		_data_->_tmp38_ = _data_->caldav_data;
		objects_source_set_data (_data_->_tmp37_, (ObjectsSourceData*) _data_->_tmp38_);
		memset (&_data_->_tmp39_, 0, sizeof (GValue));
		g_value_init (&_data_->_tmp39_, OBJECTS_TYPE_SOURCE);
		_data_->_data_object = _data_->_tmp39_;
		_data_->_tmp40_ = _data_->source;
		g_value_set_object (&_data_->_data_object, (GObject*) _data_->_tmp40_);
		_data_->_tmp41_ = _data_->response;
		_data_->_tmp42_ = _data_->_data_object;
		_data_->_tmp43_ = _data_->_tmp42_;
		http_response_set_data_object (_data_->_tmp41_, &_data_->_tmp43_);
		_data_->_tmp44_ = _data_->response;
		http_response_set_status (_data_->_tmp44_, TRUE);
		_data_->_tmp45_ = _data_->self->priv->clients;
		_data_->_tmp46_ = _data_->source;
		_data_->_tmp47_ = objects_base_object_get_id ((ObjectsBaseObject*) _data_->_tmp46_);
		_data_->_tmp48_ = _data_->_tmp47_;
		_data_->_tmp49_ = _data_->caldav_client;
		gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp45_, _data_->_tmp48_, _data_->_tmp49_);
		_data_->_tmp50_ = services_log_service_get_default ();
		_data_->_tmp51_ = _data_->_tmp50_;
		services_log_service_info (_data_->_tmp51_, "CalDAV.Core", "Login successful");
		_g_object_unref0 (_data_->_tmp51_);
		G_IS_VALUE (&_data_->_data_object) ? (g_value_unset (&_data_->_data_object), NULL) : NULL;
		_g_object_unref0 (_data_->caldav_data);
		_g_object_unref0 (_data_->source);
		_g_free0 (_data_->principal_url);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp52_ = services_log_service_get_default ();
		_data_->_tmp53_ = _data_->_tmp52_;
		_data_->_tmp54_ = _data_->e;
		_data_->_tmp55_ = _data_->_tmp54_->message;
		_data_->_tmp56_ = g_strdup_printf ("Login error: %s", _data_->_tmp55_);
		_data_->_tmp57_ = _data_->_tmp56_;
		services_log_service_error (_data_->_tmp53_, "CalDAV.Core", _data_->_tmp57_);
		_g_free0 (_data_->_tmp57_);
		_g_object_unref0 (_data_->_tmp53_);
		_data_->_tmp58_ = _data_->response;
		_data_->_tmp59_ = _data_->e;
		http_response_set_error_code (_data_->_tmp58_, _data_->_tmp59_->code);
		_data_->_tmp60_ = _data_->response;
		_data_->_tmp61_ = _data_->e;
		_data_->_tmp62_ = _data_->_tmp61_->message;
		http_response_set_error (_data_->_tmp60_, _data_->_tmp62_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->caldav_client);
		_http_response_unref0 (_data_->response);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->response;
	_g_object_unref0 (_data_->caldav_client);
	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 void
services_cal_dav_core_add_caldav_account_data_free (gpointer _data)
{
	ServicesCalDavCoreAddCaldavAccountData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->source);
	_g_object_unref0 (_data_->cancellable);
	_http_response_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesCalDavCoreAddCaldavAccountData, _data_);
}

void
services_cal_dav_core_add_caldav_account (ServicesCalDAVCore* self,
                                          ObjectsSource* source,
                                          GCancellable* cancellable,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	ServicesCalDavCoreAddCaldavAccountData* _data_;
	ServicesCalDAVCore* _tmp0_;
	ObjectsSource* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	g_return_if_fail (cancellable != NULL);
	_data_ = g_slice_new0 (ServicesCalDavCoreAddCaldavAccountData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_cal_dav_core_add_caldav_account_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (source);
	_g_object_unref0 (_data_->source);
	_data_->source = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	services_cal_dav_core_add_caldav_account_co (_data_);
}

HttpResponse*
services_cal_dav_core_add_caldav_account_finish (ServicesCalDAVCore* self,
                                                 GAsyncResult* _res_)
{
	HttpResponse* result;
	ServicesCalDavCoreAddCaldavAccountData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
services_cal_dav_core_add_caldav_account_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	ServicesCalDavCoreAddCaldavAccountData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_cal_dav_core_add_caldav_account_co (_data_);
}

static void
_________lambda36_ (ServicesCalDAVCore* self,
                    gint current,
                    gint total,
                    const gchar* msg)
{
	g_return_if_fail (msg != NULL);
	g_signal_emit (self, services_cal_dav_core_signals[SERVICES_CAL_DAV_CORE_SYNC_PROGRESS_SIGNAL], 0, current, total, msg);
}

static void
__________lambda36__services_cal_dav_cal_dav_client_progress_callback (gint current,
                                                                       gint total,
                                                                       const gchar* message,
                                                                       gpointer self)
{
	_________lambda36_ ((ServicesCalDAVCore*) self, current, total, message);
}

static gboolean
services_cal_dav_core_add_caldav_account_co (ServicesCalDavCoreAddCaldavAccountData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		case 5:
		goto _state_5;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = services_log_service_get_default ();
	_data_->_tmp1_ = _data_->_tmp0_;
	services_log_service_info (_data_->_tmp1_, "CalDAV.Core", "Adding CalDAV account");
	_g_object_unref0 (_data_->_tmp1_);
	_data_->_tmp2_ = http_response_new ();
	_data_->response = _data_->_tmp2_;
	_data_->_tmp3_ = services_cal_dav_core_get_client (_data_->self, _data_->source);
	_data_->caldav_client = _data_->_tmp3_;
	{
		static const gint BATCH_SIZE = 5;
		_data_->_tmp4_ = _data_->caldav_client;
		_data_->_state_ = 1;
		services_cal_dav_cal_dav_client_get_principal_url (_data_->_tmp4_, _data_->cancellable, services_cal_dav_core_add_caldav_account_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp5_ = services_cal_dav_cal_dav_client_get_principal_url_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error0_);
		_data_->principal_url = _data_->_tmp5_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp6_ = _data_->principal_url;
		if (_data_->_tmp6_ == NULL) {
			_data_->_tmp7_ = _data_->response;
			http_response_set_error_code (_data_->_tmp7_, 409);
			_data_->_tmp8_ = _data_->response;
			http_response_set_error (_data_->_tmp8_, _ ("Failed to resolve principal url"));
			_data_->result = _data_->response;
			_g_free0 (_data_->principal_url);
			_g_object_unref0 (_data_->caldav_client);
			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;
		}
		_data_->_tmp9_ = _data_->caldav_client;
		_data_->_tmp10_ = _data_->principal_url;
		_data_->_state_ = 2;
		services_cal_dav_cal_dav_client_update_userdata (_data_->_tmp9_, _data_->_tmp10_, _data_->source, _data_->cancellable, services_cal_dav_core_add_caldav_account_ready, _data_);
		return FALSE;
		_state_2:
		services_cal_dav_cal_dav_client_update_userdata_finish (_data_->_tmp9_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->principal_url);
			goto __catch0_g_error;
		}
		_data_->_tmp11_ = _data_->caldav_client;
		_data_->_state_ = 3;
		services_cal_dav_cal_dav_client_fetch_project_list (_data_->_tmp11_, _data_->source, _data_->cancellable, services_cal_dav_core_add_caldav_account_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp12_ = services_cal_dav_cal_dav_client_fetch_project_list_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
		_data_->projects = _data_->_tmp12_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->principal_url);
			goto __catch0_g_error;
		}
		_data_->_tmp13_ = _data_->projects;
		_data_->_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp13_);
		_data_->_tmp15_ = _data_->_tmp14_;
		g_signal_emit (_data_->self, services_cal_dav_core_signals[SERVICES_CAL_DAV_CORE_SYNC_PROGRESS_SIGNAL], 0, 0, _data_->_tmp15_, _ ("Starting sync…"));
		_data_->processed = 0;
		{
			_data_->i = 0;
			{
				_data_->_tmp16_ = TRUE;
				while (TRUE) {
					if (!_data_->_tmp16_) {
						_data_->i += BATCH_SIZE;
					}
					_data_->_tmp16_ = FALSE;
					_data_->_tmp17_ = _data_->projects;
					_data_->_tmp18_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp17_);
					_data_->_tmp19_ = _data_->_tmp18_;
					if (!(_data_->i < _data_->_tmp19_)) {
						break;
					}
					_data_->_tmp20_ = _data_->projects;
					_data_->_tmp21_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp20_);
					_data_->_tmp22_ = _data_->_tmp21_;
					_data_->batch_end = MIN (_data_->i + BATCH_SIZE, _data_->_tmp22_);
					{
						_data_->j = _data_->i;
						{
							_data_->_tmp23_ = TRUE;
							while (TRUE) {
								if (!_data_->_tmp23_) {
									_data_->_tmp24_ = _data_->j;
									_data_->j = _data_->_tmp24_ + 1;
								}
								_data_->_tmp23_ = FALSE;
								if (!(_data_->j < _data_->batch_end)) {
									break;
								}
								_data_->_tmp25_ = services_store_instance ();
								_data_->_tmp26_ = _data_->projects;
								_data_->_tmp27_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp26_, _data_->j);
								_data_->_tmp28_ = (ObjectsProject*) _data_->_tmp27_;
								services_store_insert_project (_data_->_tmp25_, _data_->_tmp28_);
								_g_object_unref0 (_data_->_tmp28_);
							}
						}
					}
					_data_->_state_ = 4;
					util_nap ((guint) 10, G_PRIORITY_DEFAULT, services_cal_dav_core_add_caldav_account_ready, _data_);
					return FALSE;
					_state_4:
					util_nap_finish (_data_->_res_);
					{
						_data_->_vala1_j = _data_->i;
						{
							_data_->_tmp29_ = TRUE;
							while (TRUE) {
								if (!_data_->_tmp29_) {
									_data_->_tmp30_ = _data_->_vala1_j;
									_data_->_vala1_j = _data_->_tmp30_ + 1;
								}
								_data_->_tmp29_ = FALSE;
								if (!(_data_->_vala1_j < _data_->batch_end)) {
									break;
								}
								_data_->_tmp31_ = _data_->projects;
								_data_->_tmp32_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp31_);
								_data_->_tmp33_ = _data_->_tmp32_;
								_data_->_tmp34_ = _data_->projects;
								_data_->_tmp35_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp34_, _data_->_vala1_j);
								_data_->_tmp36_ = (ObjectsProject*) _data_->_tmp35_;
								_data_->_tmp37_ = objects_base_object_get_name ((ObjectsBaseObject*) _data_->_tmp36_);
								_data_->_tmp38_ = _data_->_tmp37_;
								_data_->_tmp39_ = g_strdup_printf (_ ("Syncing %s…"), _data_->_tmp38_);
								_data_->_tmp40_ = _data_->_tmp39_;
								g_signal_emit (_data_->self, services_cal_dav_core_signals[SERVICES_CAL_DAV_CORE_SYNC_PROGRESS_SIGNAL], 0, _data_->processed + 1, _data_->_tmp33_, _data_->_tmp40_);
								_g_free0 (_data_->_tmp40_);
								_g_object_unref0 (_data_->_tmp36_);
								_data_->_tmp41_ = _data_->caldav_client;
								_data_->_tmp42_ = _data_->projects;
								_data_->_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp42_, _data_->_vala1_j);
								_data_->_tmp44_ = (ObjectsProject*) _data_->_tmp43_;
								_data_->_state_ = 5;
								services_cal_dav_cal_dav_client_fetch_items_for_project (_data_->_tmp41_, _data_->_tmp44_, _data_->cancellable, __________lambda36__services_cal_dav_cal_dav_client_progress_callback, g_object_ref (_data_->self), g_object_unref, services_cal_dav_core_add_caldav_account_ready, _data_);
								return FALSE;
								_state_5:
								services_cal_dav_cal_dav_client_fetch_items_for_project_finish (_data_->_tmp41_, _data_->_res_, &_data_->_inner_error0_);
								_g_object_unref0 (_data_->_tmp44_);
								if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
									_g_object_unref0 (_data_->projects);
									_g_free0 (_data_->principal_url);
									goto __catch0_g_error;
								}
								_data_->_tmp45_ = _data_->processed;
								_data_->processed = _data_->_tmp45_ + 1;
							}
						}
					}
				}
			}
		}
		_data_->_tmp46_ = services_store_instance ();
		services_store_insert_source (_data_->_tmp46_, _data_->source);
		_data_->_tmp47_ = _data_->projects;
		_data_->_tmp48_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp47_);
		_data_->_tmp49_ = _data_->_tmp48_;
		_data_->_tmp50_ = _data_->projects;
		_data_->_tmp51_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp50_);
		_data_->_tmp52_ = _data_->_tmp51_;
		g_signal_emit (_data_->self, services_cal_dav_core_signals[SERVICES_CAL_DAV_CORE_SYNC_PROGRESS_SIGNAL], 0, _data_->_tmp49_, _data_->_tmp52_, _ ("Sync completed"));
		_data_->_tmp53_ = services_log_service_get_default ();
		_data_->_tmp54_ = _data_->_tmp53_;
		_data_->_tmp55_ = _data_->projects;
		_data_->_tmp56_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp55_);
		_data_->_tmp57_ = _data_->_tmp56_;
		_data_->_tmp58_ = g_strdup_printf ("Account added successfully, %d projects synced", _data_->_tmp57_);
		_data_->_tmp59_ = _data_->_tmp58_;
		services_log_service_info (_data_->_tmp54_, "CalDAV.Core", _data_->_tmp59_);
		_g_free0 (_data_->_tmp59_);
		_g_object_unref0 (_data_->_tmp54_);
		_data_->_tmp60_ = _data_->response;
		http_response_set_status (_data_->_tmp60_, TRUE);
		_g_object_unref0 (_data_->projects);
		_g_free0 (_data_->principal_url);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp61_ = _data_->response;
		_data_->_tmp62_ = _data_->e;
		http_response_set_error_code (_data_->_tmp61_, _data_->_tmp62_->code);
		_data_->_tmp63_ = _data_->response;
		_data_->_tmp64_ = _data_->e;
		_data_->_tmp65_ = _data_->_tmp64_->message;
		http_response_set_error (_data_->_tmp63_, _data_->_tmp65_);
		_data_->_tmp66_ = services_log_service_get_default ();
		_data_->_tmp67_ = _data_->_tmp66_;
		_data_->_tmp68_ = _data_->e;
		_data_->_tmp69_ = _data_->_tmp68_->message;
		_data_->_tmp70_ = g_strdup_printf ("Add account error: %s", _data_->_tmp69_);
		_data_->_tmp71_ = _data_->_tmp70_;
		services_log_service_error (_data_->_tmp67_, "CalDAV.Core", _data_->_tmp71_);
		_g_free0 (_data_->_tmp71_);
		_g_object_unref0 (_data_->_tmp67_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->caldav_client);
		_http_response_unref0 (_data_->response);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->response;
	_g_object_unref0 (_data_->caldav_client);
	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 void
services_cal_dav_core_sync_data_free (gpointer _data)
{
	ServicesCalDavCoreSyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->source);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesCalDavCoreSyncData, _data_);
}

void
services_cal_dav_core_sync (ServicesCalDAVCore* self,
                            ObjectsSource* source,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	ServicesCalDavCoreSyncData* _data_;
	ServicesCalDAVCore* _tmp0_;
	ObjectsSource* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_data_ = g_slice_new0 (ServicesCalDavCoreSyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_cal_dav_core_sync_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (source);
	_g_object_unref0 (_data_->source);
	_data_->source = _tmp1_;
	services_cal_dav_core_sync_co (_data_);
}

void
services_cal_dav_core_sync_finish (ServicesCalDAVCore* self,
                                   GAsyncResult* _res_)
{
	ServicesCalDavCoreSyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
services_cal_dav_core_sync_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	ServicesCalDavCoreSyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_cal_dav_core_sync_co (_data_);
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static gboolean
services_cal_dav_core_sync_co (ServicesCalDavCoreSyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = services_log_service_get_default ();
	_data_->_tmp1_ = _data_->_tmp0_;
	services_log_service_info (_data_->_tmp1_, "CalDAV.Core", "Starting sync");
	_g_object_unref0 (_data_->_tmp1_);
	_data_->_tmp2_ = services_cal_dav_core_get_client (_data_->self, _data_->source);
	_data_->caldav_client = _data_->_tmp2_;
	g_signal_emit_by_name (_data_->source, "sync-started");
	{
		_data_->_tmp3_ = g_cancellable_new ();
		_data_->cancellable = _data_->_tmp3_;
		_data_->_tmp4_ = _data_->caldav_client;
		_data_->_tmp5_ = _data_->cancellable;
		_data_->_state_ = 1;
		services_cal_dav_cal_dav_client_sync (_data_->_tmp4_, _data_->source, _data_->_tmp5_, services_cal_dav_core_sync_ready, _data_);
		return FALSE;
		_state_1:
		services_cal_dav_cal_dav_client_sync_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->cancellable);
			goto __catch0_g_error;
		}
		_data_->_tmp6_ = services_store_instance ();
		_data_->_tmp7_ = objects_base_object_get_id ((ObjectsBaseObject*) _data_->source);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_tmp9_ = services_store_get_projects_by_source (_data_->_tmp6_, _data_->_tmp8_);
		_data_->projects = _data_->_tmp9_;
		_data_->_tmp10_ = services_log_service_get_default ();
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = _data_->projects;
		_data_->_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp12_);
		_data_->_tmp14_ = _data_->_tmp13_;
		_data_->_tmp15_ = g_strdup_printf ("Found %d projects to sync", _data_->_tmp14_);
		_data_->_tmp16_ = _data_->_tmp15_;
		services_log_service_debug (_data_->_tmp11_, "CalDAV.Core", _data_->_tmp16_);
		_g_free0 (_data_->_tmp16_);
		_g_object_unref0 (_data_->_tmp11_);
		{
			_data_->_tmp17_ = _data_->projects;
			_data_->_project_list = _data_->_tmp17_;
			_data_->_tmp18_ = _data_->_project_list;
			_data_->_tmp19_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp18_);
			_data_->_tmp20_ = _data_->_tmp19_;
			_data_->_project_size = _data_->_tmp20_;
			_data_->_project_index = -1;
			while (TRUE) {
				_data_->_project_index = _data_->_project_index + 1;
				_data_->_tmp21_ = _data_->_project_index;
				_data_->_tmp22_ = _data_->_project_size;
				if (!(_data_->_tmp21_ < _data_->_tmp22_)) {
					break;
				}
				_data_->_tmp23_ = _data_->_project_list;
				_data_->_tmp24_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp23_, _data_->_project_index);
				_data_->project = (ObjectsProject*) _data_->_tmp24_;
				_data_->_tmp26_ = _data_->project;
				_data_->_tmp27_ = objects_project_get_sync_id (_data_->_tmp26_);
				_data_->_tmp28_ = _data_->_tmp27_;
				_data_->_tmp25_ = _data_->_tmp28_;
				if (_data_->_tmp25_ == NULL) {
					_data_->_tmp25_ = "(null)";
				}
				_data_->_tmp30_ = _data_->project;
				_data_->_tmp31_ = objects_project_get_calendar_url (_data_->_tmp30_);
				_data_->_tmp32_ = _data_->_tmp31_;
				_data_->_tmp29_ = _data_->_tmp32_;
				if (_data_->_tmp29_ == NULL) {
					_data_->_tmp29_ = "(null)";
				}
				_data_->_tmp33_ = services_log_service_get_default ();
				_data_->_tmp34_ = _data_->_tmp33_;
				_data_->_tmp35_ = _data_->project;
				_data_->_tmp36_ = objects_base_object_get_name ((ObjectsBaseObject*) _data_->_tmp35_);
				_data_->_tmp37_ = _data_->_tmp36_;
				_data_->_tmp38_ = g_strdup_printf ("Project: '%s' | sync_id: '%s' | url: '%s'", _data_->_tmp37_, _data_->_tmp25_, _data_->_tmp29_);
				_data_->_tmp39_ = _data_->_tmp38_;
				services_log_service_debug (_data_->_tmp34_, "CalDAV.Core", _data_->_tmp39_);
				_g_free0 (_data_->_tmp39_);
				_g_object_unref0 (_data_->_tmp34_);
				_data_->_tmp40_ = _data_->caldav_client;
				_data_->_tmp41_ = _data_->project;
				_data_->_tmp42_ = _data_->cancellable;
				_data_->_state_ = 2;
				services_cal_dav_cal_dav_client_sync_tasklist (_data_->_tmp40_, _data_->_tmp41_, _data_->_tmp42_, services_cal_dav_core_sync_ready, _data_);
				return FALSE;
				_state_2:
				services_cal_dav_cal_dav_client_sync_tasklist_finish (_data_->_tmp40_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_object_unref0 (_data_->project);
					_g_object_unref0 (_data_->projects);
					_g_object_unref0 (_data_->cancellable);
					goto __catch0_g_error;
				}
				_g_object_unref0 (_data_->project);
			}
		}
		g_signal_emit_by_name (_data_->source, "sync-finished");
		objects_source_set_sync_status (_data_->source, NULL);
		_data_->_tmp43_ = g_date_time_new_now_local ();
		_data_->_tmp44_ = _data_->_tmp43_;
		_data_->_tmp45_ = g_date_time_to_string (_data_->_tmp44_);
		_data_->_tmp46_ = _data_->_tmp45_;
		objects_source_set_last_sync (_data_->source, _data_->_tmp46_);
		_g_free0 (_data_->_tmp46_);
		_g_date_time_unref0 (_data_->_tmp44_);
		_data_->_tmp47_ = services_log_service_get_default ();
		_data_->_tmp48_ = _data_->_tmp47_;
		services_log_service_info (_data_->_tmp48_, "CalDAV.Core", "Sync completed successfully");
		_g_object_unref0 (_data_->_tmp48_);
		_g_object_unref0 (_data_->projects);
		_g_object_unref0 (_data_->cancellable);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp49_ = services_log_service_get_default ();
		_data_->_tmp50_ = _data_->_tmp49_;
		_data_->_tmp51_ = objects_source_get_display_name (_data_->source);
		_data_->_tmp52_ = _data_->_tmp51_;
		_data_->_tmp53_ = _data_->e;
		_data_->_tmp54_ = _data_->_tmp53_->message;
		_data_->_tmp55_ = g_strdup_printf ("Failed to sync source '%s': %s", _data_->_tmp52_, _data_->_tmp54_);
		_data_->_tmp56_ = _data_->_tmp55_;
		services_log_service_error (_data_->_tmp50_, "CalDAV.Core", _data_->_tmp56_);
		_g_free0 (_data_->_tmp56_);
		_g_object_unref0 (_data_->_tmp50_);
		_data_->_tmp58_ = _data_->e;
		_data_->_tmp59_ = _data_->_tmp58_->message;
		if (string_contains (_data_->_tmp59_, "HTTP 401")) {
			_data_->_tmp57_ = TRUE;
		} else {
			_data_->_tmp60_ = _data_->e;
			_data_->_tmp61_ = _data_->_tmp60_->message;
			_data_->_tmp57_ = string_contains (_data_->_tmp61_, "Authentication failed");
		}
		if (_data_->_tmp57_) {
			_data_->_tmp62_ = services_log_service_get_default ();
			_data_->_tmp63_ = _data_->_tmp62_;
			services_log_service_warn (_data_->_tmp63_, "CalDAV.Core", "Authentication expired, re-login required");
			_g_object_unref0 (_data_->_tmp63_);
			_data_->_tmp64_ = sync_status_new (SYNC_ERROR_TYPE_AUTH_EXPIRED, _ ("Authentication Expired"), _ ("Your session has expired. Please remove and re-add your account in Pre" \
"ferences."));
			_data_->_tmp65_ = _data_->_tmp64_;
			objects_source_set_sync_status (_data_->source, _data_->_tmp65_);
			_g_object_unref0 (_data_->_tmp65_);
			_data_->_tmp66_ = objects_source_get_sync_status (_data_->source);
			_data_->_tmp67_ = _data_->_tmp66_;
			g_signal_emit_by_name (_data_->source, "sync-failed", _data_->_tmp67_);
		} else {
			_data_->_tmp69_ = _data_->e;
			_data_->_tmp70_ = _data_->_tmp69_->message;
			if (string_contains (_data_->_tmp70_, "HTTP 429")) {
				_data_->_tmp68_ = TRUE;
			} else {
				_data_->_tmp71_ = _data_->e;
				_data_->_tmp72_ = _data_->_tmp71_->message;
				_data_->_tmp68_ = string_contains (_data_->_tmp72_, "Too Many Requests");
			}
			if (_data_->_tmp68_) {
				_data_->_tmp73_ = services_log_service_get_default ();
				_data_->_tmp74_ = _data_->_tmp73_;
				services_log_service_warn (_data_->_tmp74_, "CalDAV.Core", "Rate limited by server, try again later");
				_g_object_unref0 (_data_->_tmp74_);
				_data_->_tmp75_ = sync_status_new (SYNC_ERROR_TYPE_SERVER_ERROR, _ ("Too Many Requests"), _ ("The server is rate limiting requests. Please wait a few minutes and tr" \
"y again."));
				_data_->_tmp76_ = _data_->_tmp75_;
				objects_source_set_sync_status (_data_->source, _data_->_tmp76_);
				_g_object_unref0 (_data_->_tmp76_);
				_data_->_tmp77_ = objects_source_get_sync_status (_data_->source);
				_data_->_tmp78_ = _data_->_tmp77_;
				g_signal_emit_by_name (_data_->source, "sync-failed", _data_->_tmp78_);
			} else {
				objects_source_set_sync_status (_data_->source, NULL);
				g_signal_emit_by_name (_data_->source, "sync-failed", NULL);
			}
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->caldav_client);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->caldav_client);
	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 void
g_cclosure_user_marshal_VOID__INT_INT_STRING (GClosure * closure,
                                              GValue * return_value,
                                              guint n_param_values,
                                              const GValue * param_values,
                                              gpointer invocation_hint,
                                              gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_INT_STRING) (gpointer data1, gint arg_1, gint arg_2, const char* arg_3, gpointer data2);
	register GMarshalFunc_VOID__INT_INT_STRING callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT_STRING) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), g_value_get_string (param_values + 3), data2);
}

static void
services_cal_dav_core_class_init (ServicesCalDAVCoreClass * klass,
                                  gpointer klass_data)
{
	services_cal_dav_core_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ServicesCalDAVCore_private_offset);
	G_OBJECT_CLASS (klass)->finalize = services_cal_dav_core_finalize;
	services_cal_dav_core_signals[SERVICES_CAL_DAV_CORE_SYNC_PROGRESS_SIGNAL] = g_signal_new ("sync-progress", SERVICES_CAL_DAV_TYPE_CORE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT_STRING, G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
}

static void
services_cal_dav_core_instance_init (ServicesCalDAVCore * self,
                                     gpointer klass)
{
	self->priv = services_cal_dav_core_get_instance_private (self);
}

static void
services_cal_dav_core_finalize (GObject * obj)
{
	ServicesCalDAVCore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SERVICES_CAL_DAV_TYPE_CORE, ServicesCalDAVCore);
	_g_object_unref0 (self->priv->clients);
	G_OBJECT_CLASS (services_cal_dav_core_parent_class)->finalize (obj);
}

static GType
services_cal_dav_core_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ServicesCalDAVCoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) services_cal_dav_core_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ServicesCalDAVCore), 0, (GInstanceInitFunc) services_cal_dav_core_instance_init, NULL };
	GType services_cal_dav_core_type_id;
	services_cal_dav_core_type_id = g_type_register_static (G_TYPE_OBJECT, "ServicesCalDAVCore", &g_define_type_info, 0);
	ServicesCalDAVCore_private_offset = g_type_add_instance_private (services_cal_dav_core_type_id, sizeof (ServicesCalDAVCorePrivate));
	return services_cal_dav_core_type_id;
}

GType
services_cal_dav_core_get_type (void)
{
	static volatile gsize services_cal_dav_core_type_id__once = 0;
	if (g_once_init_enter (&services_cal_dav_core_type_id__once)) {
		GType services_cal_dav_core_type_id;
		services_cal_dav_core_type_id = services_cal_dav_core_get_type_once ();
		g_once_init_leave (&services_cal_dav_core_type_id__once, services_cal_dav_core_type_id);
	}
	return services_cal_dav_core_type_id__once;
}

