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

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib/gstdio.h>

#define DC_RPC_INSTALLER_RPC_BIN "deltachat-rpc-server"
#define DC_RPC_INSTALLER_MAX_REDIRECTS 5
#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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_RPC_INSTALLER (dc_rpc_installer_get_type ())
#define DC_RPC_INSTALLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_RPC_INSTALLER, DcRpcInstaller))
#define DC_RPC_INSTALLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_RPC_INSTALLER, DcRpcInstallerClass))
#define DC_IS_RPC_INSTALLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_RPC_INSTALLER))
#define DC_IS_RPC_INSTALLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_RPC_INSTALLER))
#define DC_RPC_INSTALLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_RPC_INSTALLER, DcRpcInstallerClass))

typedef struct _DcRpcInstaller DcRpcInstaller;
typedef struct _DcRpcInstallerClass DcRpcInstallerClass;
typedef struct _DcRpcInstallerPrivate DcRpcInstallerPrivate;
enum  {
	DC_RPC_INSTALLER_0_PROPERTY,
	DC_RPC_INSTALLER_NUM_PROPERTIES
};
static GParamSpec* dc_rpc_installer_properties[DC_RPC_INSTALLER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _DcRpcInstallerInstalledVersionData DcRpcInstallerInstalledVersionData;
typedef struct _DcRpcInstallerFetchLatestTagData DcRpcInstallerFetchLatestTagData;
typedef struct _DcRpcInstallerDownloadLatestData DcRpcInstallerDownloadLatestData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcRpcInstallerDownloadReleaseAssetData DcRpcInstallerDownloadReleaseAssetData;
typedef struct _DcRpcInstallerFetchLatestTagWithCurlData DcRpcInstallerFetchLatestTagWithCurlData;
typedef struct _DcRpcInstallerCurlGetToFileData DcRpcInstallerCurlGetToFileData;
#define _g_uri_unref0(var) ((var == NULL) ? NULL : (var = (g_uri_unref (var), NULL)))
typedef struct _DcRpcInstallerHttpsGetToFileData DcRpcInstallerHttpsGetToFileData;
enum  {
	DC_RPC_INSTALLER_PROGRESS_SIGNAL,
	DC_RPC_INSTALLER_NUM_SIGNALS
};
static guint dc_rpc_installer_signals[DC_RPC_INSTALLER_NUM_SIGNALS] = {0};

struct _DcRpcInstaller {
	GObject parent_instance;
	DcRpcInstallerPrivate * priv;
};

struct _DcRpcInstallerClass {
	GObjectClass parent_class;
};

struct _DcRpcInstallerInstalledVersionData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* result;
	gchar* path;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* stdout_buf;
	gchar* stderr_buf;
	gboolean successful;
	GSubprocess* process;
	const gchar* _tmp2_;
	GSubprocess* _tmp3_;
	GSubprocess* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GSubprocess* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	gboolean _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	const gchar* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* version;
	gchar* _tmp22_;
	const gchar* _tmp23_;
	gboolean _tmp24_;
	const gchar* _tmp25_;
	gint _tmp26_;
	gint _tmp27_;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	GError* _inner_error0_;
};

struct _DcRpcInstallerFetchLatestTagData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* result;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GSocketClient* client;
	GSocketClient* _tmp3_;
	GSocketClient* _tmp4_;
	GSocketConnection* tcp;
	GSocketClient* _tmp5_;
	GSocketConnection* _tmp6_;
	GNetworkAddress* identity;
	GNetworkAddress* _tmp7_;
	GTlsClientConnection* tls;
	GSocketConnection* _tmp8_;
	GNetworkAddress* _tmp9_;
	GTlsClientConnection* _tmp10_;
	GTlsClientConnection* _tmp11_;
	GError* _tmp12_;
	GTlsClientConnection* _tmp13_;
	gchar* request;
	gchar* _tmp14_;
	gsize written;
	GTlsClientConnection* _tmp15_;
	GOutputStream* _tmp16_;
	GOutputStream* _tmp17_;
	const gchar* _tmp18_;
	guint8* _tmp19_;
	gint _tmp19__length1;
	gint _tmp20_;
	guint8* _tmp21_;
	gint _tmp21__length1;
	gsize _tmp22_;
	GDataInputStream* reader;
	GTlsClientConnection* _tmp23_;
	GInputStream* _tmp24_;
	GInputStream* _tmp25_;
	GDataInputStream* _tmp26_;
	GDataInputStream* _tmp27_;
	gsize len;
	gchar* status_line;
	GDataInputStream* _tmp28_;
	gsize _tmp29_;
	gchar* _tmp30_;
	const gchar* _tmp31_;
	const gchar* _tmp32_;
	gint status;
	gchar* location;
	gchar* line;
	gchar* _tmp33_;
	GDataInputStream* _tmp34_;
	gsize _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	const gchar* _tmp38_;
	gchar* stripped;
	const gchar* _tmp39_;
	gchar* _tmp40_;
	const gchar* _tmp41_;
	gint _tmp42_;
	gint _tmp43_;
	const gchar* _tmp44_;
	gchar* _tmp45_;
	gchar* _tmp46_;
	gboolean _tmp47_;
	const gchar* _tmp48_;
	gint _tmp49_;
	gint _tmp50_;
	gchar* _tmp51_;
	gchar* _tmp52_;
	gchar* _tmp53_;
	GTlsClientConnection* _tmp54_;
	gboolean _tmp55_;
	gboolean _tmp56_;
	const gchar* _tmp57_;
	gchar* _tmp58_;
	gchar* _tmp59_;
	GError* _tmp60_;
	GError* _tmp61_;
	gchar* tag;
	const gchar* _tmp62_;
	gchar* _tmp63_;
	const gchar* _tmp64_;
	GError* _tmp65_;
	GError* _inner_error0_;
};

struct _DcRpcInstallerDownloadLatestData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcInstaller* self;
	gchar* result;
	gchar* asset;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _tmp6_;
	GError* _inner_error0_;
};

struct _DcRpcInstallerDownloadReleaseAssetData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcInstaller* self;
	gchar* asset;
	gchar* result;
	gchar* dir;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* tag;
	gchar* _tmp2_;
	gchar* url;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* tmp;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	gchar* final_path;
	gchar* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	GError* _tmp20_;
	const gchar* _tmp21_;
	GError* e;
	const gchar* _tmp22_;
	GError* _tmp23_;
	GError* _tmp24_;
	GError* _inner_error0_;
};

struct _DcRpcInstallerFetchLatestTagWithCurlData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* result;
	gchar* curl;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	GError* _tmp2_;
	gchar** argv;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar** _tmp13_;
	gint argv_length1;
	gint _argv_size_;
	gchar* stdout_buf;
	gchar* stderr_buf;
	gboolean successful;
	GSubprocess* process;
	gchar** _tmp14_;
	gint _tmp14__length1;
	GSubprocess* _tmp15_;
	GSubprocess* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	GSubprocess* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	GError* _tmp23_;
	GError* _tmp24_;
	gchar* location;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	gchar** _tmp27_;
	gchar** _tmp28_;
	gchar** line_collection;
	gint line_collection_length1;
	gint _line_collection_size_;
	gint line_it;
	gchar* _tmp29_;
	gchar* line;
	gchar* stripped;
	const gchar* _tmp30_;
	gchar* _tmp31_;
	const gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	gboolean _tmp35_;
	const gchar* _tmp36_;
	gint _tmp37_;
	gint _tmp38_;
	gchar* _tmp39_;
	gchar* _tmp40_;
	gchar* _tmp41_;
	const gchar* _tmp42_;
	GError* _tmp43_;
	gchar* tag;
	const gchar* _tmp44_;
	gchar* _tmp45_;
	const gchar* _tmp46_;
	GError* _tmp47_;
	GError* _inner_error0_;
};

struct _DcRpcInstallerCurlGetToFileData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcInstaller* self;
	gchar* url;
	gchar* dest;
	gchar* curl;
	gchar* _tmp0_;
	GError* _tmp1_;
	gchar** argv;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar** _tmp16_;
	gint argv_length1;
	gint _argv_size_;
	gchar* stderr_buf;
	gboolean successful;
	GSubprocess* process;
	gchar** _tmp17_;
	gint _tmp17__length1;
	GSubprocess* _tmp18_;
	gchar* stdout_buf;
	GSubprocess* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	GSubprocess* _tmp22_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	GError* _tmp26_;
	GError* _tmp27_;
	GFileInfo* info;
	GFile* _tmp28_;
	GFile* _tmp29_;
	GFileInfo* _tmp30_;
	GFileInfo* _tmp31_;
	gint64 size;
	GFileInfo* _tmp32_;
	GError* _inner_error0_;
};

struct _DcRpcInstallerHttpsGetToFileData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcInstaller* self;
	gchar* url;
	gchar* dest;
	gint depth;
	GError* _tmp0_;
	GUri* uri;
	GUri* _tmp1_;
	gchar* host;
	GUri* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gint port;
	GUri* _tmp5_;
	gchar* path;
	GUri* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	gchar* _tmp12_;
	gchar* query;
	GUri* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gboolean _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	const gchar* _tmp22_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	const gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* target;
	gchar* _tmp27_;
	GSocketClient* client;
	GSocketClient* _tmp28_;
	GSocketClient* _tmp29_;
	GSocketConnection* tcp;
	GSocketClient* _tmp30_;
	const gchar* _tmp31_;
	GSocketConnection* _tmp32_;
	GNetworkAddress* identity;
	const gchar* _tmp33_;
	GNetworkAddress* _tmp34_;
	GTlsClientConnection* tls;
	GSocketConnection* _tmp35_;
	GNetworkAddress* _tmp36_;
	GTlsClientConnection* _tmp37_;
	GTlsClientConnection* _tmp38_;
	GError* _tmp39_;
	GTlsClientConnection* _tmp40_;
	gchar* request;
	const gchar* _tmp41_;
	gchar* _tmp42_;
	gchar* _tmp43_;
	const gchar* _tmp44_;
	gchar* _tmp45_;
	gchar* _tmp46_;
	gchar* _tmp47_;
	gchar* _tmp48_;
	gchar* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	gchar* _tmp52_;
	gchar* _tmp53_;
	gchar* _tmp54_;
	gsize written;
	GTlsClientConnection* _tmp55_;
	GOutputStream* _tmp56_;
	GOutputStream* _tmp57_;
	const gchar* _tmp58_;
	guint8* _tmp59_;
	gint _tmp59__length1;
	gint _tmp60_;
	guint8* _tmp61_;
	gint _tmp61__length1;
	gsize _tmp62_;
	GDataInputStream* reader;
	GTlsClientConnection* _tmp63_;
	GInputStream* _tmp64_;
	GInputStream* _tmp65_;
	GDataInputStream* _tmp66_;
	GDataInputStream* _tmp67_;
	GDataInputStream* _tmp68_;
	gsize len;
	gchar* status_line;
	GDataInputStream* _tmp69_;
	gsize _tmp70_;
	gchar* _tmp71_;
	const gchar* _tmp72_;
	const gchar* _tmp73_;
	gint status;
	gchar* location;
	gint64 content_length;
	gchar* line;
	gchar* _tmp74_;
	GDataInputStream* _tmp75_;
	gsize _tmp76_;
	gchar* _tmp77_;
	gchar* _tmp78_;
	const gchar* _tmp79_;
	gchar* stripped;
	const gchar* _tmp80_;
	gchar* _tmp81_;
	const gchar* _tmp82_;
	gint _tmp83_;
	gint _tmp84_;
	gchar* lower;
	const gchar* _tmp85_;
	gchar* _tmp86_;
	const gchar* _tmp87_;
	const gchar* _tmp88_;
	gint _tmp89_;
	gint _tmp90_;
	gchar* _tmp91_;
	gchar* _tmp92_;
	gchar* _tmp93_;
	const gchar* _tmp94_;
	const gchar* _tmp95_;
	gint _tmp96_;
	gint _tmp97_;
	gchar* _tmp98_;
	gchar* _tmp99_;
	gchar* _tmp100_;
	gchar* _tmp101_;
	gboolean _tmp102_;
	GTlsClientConnection* _tmp103_;
	const gchar* _tmp104_;
	gchar* _tmp105_;
	gchar* _tmp106_;
	GError* _tmp107_;
	GError* _tmp108_;
	const gchar* _tmp109_;
	gboolean _tmp110_;
	GTlsClientConnection* _tmp111_;
	gchar* _tmp112_;
	gchar* _tmp113_;
	GError* _tmp114_;
	GError* _tmp115_;
	GFileOutputStream* fos;
	GFile* _tmp116_;
	GFile* _tmp117_;
	GFileOutputStream* _tmp118_;
	GFileOutputStream* _tmp119_;
	guint8* buf;
	guint8* _tmp120_;
	gint buf_length1;
	gint _buf_size_;
	gint64 received;
	gssize n;
	GDataInputStream* _tmp121_;
	guint8* _tmp122_;
	gint _tmp122__length1;
	gsize bw;
	GFileOutputStream* _tmp123_;
	guint8* _tmp124_;
	gint _tmp124__length1;
	gsize _tmp125_;
	GFileOutputStream* _tmp126_;
	GTlsClientConnection* _tmp127_;
	gboolean _tmp128_;
	gchar* _tmp129_;
	gchar* _tmp130_;
	gchar* _tmp131_;
	gchar* _tmp132_;
	gchar* _tmp133_;
	gchar* _tmp134_;
	GError* _tmp135_;
	GError* _tmp136_;
	GError* _inner_error0_;
};

static gpointer dc_rpc_installer_parent_class = NULL;

VALA_EXTERN GType dc_rpc_installer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRpcInstaller, g_object_unref)
VALA_EXTERN gchar* dc_rpc_installer_managed_dir (void);
VALA_EXTERN gchar* dc_account_finder_get_parla_data_dir (void);
VALA_EXTERN gchar* dc_rpc_installer_managed_bin_path (void);
VALA_EXTERN gchar* dc_account_finder_get_managed_rpc_path (void);
VALA_EXTERN gboolean dc_rpc_installer_can_auto_install (void);
VALA_EXTERN gchar* dc_rpc_installer_detect_asset_name (void);
static gchar* dc_rpc_installer_detect_os (void);
static gchar* dc_rpc_installer_detect_arch (void);
static gchar* dc_rpc_installer_arch_from_uname (void);
static gchar* dc_rpc_installer_arch_from_self_elf (void);
static void dc_rpc_installer_installed_version_data_free (gpointer _data);
VALA_EXTERN void dc_rpc_installer_installed_version (GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_installer_installed_version_finish (GAsyncResult* _res_);
static gboolean dc_rpc_installer_installed_version_co (DcRpcInstallerInstalledVersionData* _data_);
static void dc_rpc_installer_installed_version_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static gboolean dc_rpc_installer_use_curl (void);
VALA_EXTERN gboolean dc_platform_is_macos (void);
static void dc_rpc_installer_fetch_latest_tag_data_free (gpointer _data);
VALA_EXTERN void dc_rpc_installer_fetch_latest_tag (GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_installer_fetch_latest_tag_finish (GAsyncResult* _res_,
                                                 GError** error);
static gboolean dc_rpc_installer_fetch_latest_tag_co (DcRpcInstallerFetchLatestTagData* _data_);
static void dc_rpc_installer_fetch_latest_tag_with_curl (GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static gchar* dc_rpc_installer_fetch_latest_tag_with_curl_finish (GAsyncResult* _res_,
                                                           GError** error);
static void dc_rpc_installer_fetch_latest_tag_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static gint dc_rpc_installer_parse_http_status (const gchar* status_line);
static gchar* dc_rpc_installer_extract_release_tag (const gchar* location);
static void dc_rpc_installer_download_latest_data_free (gpointer _data);
VALA_EXTERN void dc_rpc_installer_download_latest (DcRpcInstaller* self,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_installer_download_latest_finish (DcRpcInstaller* self,
                                                GAsyncResult* _res_,
                                                GError** error);
static gboolean dc_rpc_installer_download_latest_co (DcRpcInstallerDownloadLatestData* _data_);
static void dc_rpc_installer_download_release_asset (DcRpcInstaller* self,
                                              const gchar* asset,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_);
static gchar* dc_rpc_installer_download_release_asset_finish (DcRpcInstaller* self,
                                                       GAsyncResult* _res_,
                                                       GError** error);
static void dc_rpc_installer_download_latest_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
static void dc_rpc_installer_download_release_asset_data_free (gpointer _data);
static gboolean dc_rpc_installer_download_release_asset_co (DcRpcInstallerDownloadReleaseAssetData* _data_);
static void dc_rpc_installer_download_release_asset_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void dc_rpc_installer_curl_get_to_file (DcRpcInstaller* self,
                                        const gchar* url,
                                        const gchar* dest,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
static void dc_rpc_installer_curl_get_to_file_finish (DcRpcInstaller* self,
                                               GAsyncResult* _res_,
                                               GError** error);
static void dc_rpc_installer_https_get_to_file (DcRpcInstaller* self,
                                         const gchar* url,
                                         const gchar* dest,
                                         gint depth,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
static void dc_rpc_installer_https_get_to_file_finish (DcRpcInstaller* self,
                                                GAsyncResult* _res_,
                                                GError** error);
static void dc_rpc_installer_ensure_executable (const gchar* path,
                                         GError** error);
static gchar* dc_rpc_installer_curl_path (void);
static gchar* dc_rpc_installer_curl_failure_message (const gchar* stderr_buf);
static void dc_rpc_installer_fetch_latest_tag_with_curl_data_free (gpointer _data);
static gboolean dc_rpc_installer_fetch_latest_tag_with_curl_co (DcRpcInstallerFetchLatestTagWithCurlData* _data_);
static void dc_rpc_installer_fetch_latest_tag_with_curl_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void dc_rpc_installer_curl_get_to_file_data_free (gpointer _data);
static gboolean dc_rpc_installer_curl_get_to_file_co (DcRpcInstallerCurlGetToFileData* _data_);
static void dc_rpc_installer_curl_get_to_file_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void dc_rpc_installer_https_get_to_file_data_free (gpointer _data);
static gboolean dc_rpc_installer_https_get_to_file_co (DcRpcInstallerHttpsGetToFileData* _data_);
static void dc_rpc_installer_https_get_to_file_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_installer_extract_version (const gchar* text);
VALA_EXTERN DcRpcInstaller* dc_rpc_installer_new (void);
VALA_EXTERN DcRpcInstaller* dc_rpc_installer_construct (GType object_type);
static void g_cclosure_user_marshal_VOID__INT64_INT64 (GClosure * closure,
                                                GValue * return_value,
                                                guint n_param_values,
                                                const GValue * param_values,
                                                gpointer invocation_hint,
                                                gpointer marshal_data);
static GType dc_rpc_installer_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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/** Directory Parla owns for the downloaded server, created on demand. */
gchar*
dc_rpc_installer_managed_dir (void)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	_tmp0_ = dc_account_finder_get_parla_data_dir ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_build_filename (_tmp1_, "bin", NULL);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	result = _tmp3_;
	return result;
}

/** Absolute path to the Parla-managed server binary. */
gchar*
dc_rpc_installer_managed_bin_path (void)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = dc_account_finder_get_managed_rpc_path ();
	result = _tmp0_;
	return result;
}

/**
         * True when Parla can install a managed server for this host with one
         * click. The package source differs by OS, but the UX is the same.
         */
gboolean
dc_rpc_installer_can_auto_install (void)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	_tmp0_ = dc_rpc_installer_detect_asset_name ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_free0 (_tmp1_);
	result = _tmp2_;
	return result;
}

/**
         * Name of the GitHub release asset matching the host OS/architecture,
         * or null when no prebuilt binary is published for this machine.
         */
gchar*
dc_rpc_installer_detect_asset_name (void)
{
	gchar* os = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_;
	gchar* arch = NULL;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	GQuark _tmp9_ = 0U;
	static GQuark _tmp8_label0 = 0;
	static GQuark _tmp8_label1 = 0;
	static GQuark _tmp8_label2 = 0;
	static GQuark _tmp8_label3 = 0;
	static GQuark _tmp8_label4 = 0;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	GQuark _tmp13_ = 0U;
	static GQuark _tmp12_label0 = 0;
	static GQuark _tmp12_label1 = 0;
	gchar* result;
	_tmp0_ = dc_rpc_installer_detect_os ();
	os = _tmp0_;
	_tmp2_ = os;
	if (g_strcmp0 (_tmp2_, "Linux") == 0) {
		gchar* _tmp3_;
		_tmp3_ = dc_rpc_installer_detect_arch ();
		_g_free0 (_tmp1_);
		_tmp1_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = dc_rpc_installer_arch_from_uname ();
		_g_free0 (_tmp1_);
		_tmp1_ = _tmp4_;
	}
	_tmp5_ = _tmp1_;
	_tmp1_ = NULL;
	arch = _tmp5_;
	_tmp6_ = arch;
	_tmp7_ = _tmp6_;
	_tmp9_ = (NULL == _tmp7_) ? 0 : g_quark_from_string (_tmp7_);
	if (((((_tmp9_ == ((0 != _tmp8_label0) ? _tmp8_label0 : (_tmp8_label0 = g_quark_from_static_string ("x86_64")))) || (_tmp9_ == ((0 != _tmp8_label1) ? _tmp8_label1 : (_tmp8_label1 = g_quark_from_static_string ("aarch64"))))) || (_tmp9_ == ((0 != _tmp8_label2) ? _tmp8_label2 : (_tmp8_label2 = g_quark_from_static_string ("armv7l"))))) || (_tmp9_ == ((0 != _tmp8_label3) ? _tmp8_label3 : (_tmp8_label3 = g_quark_from_static_string ("armv6l"))))) || (_tmp9_ == ((0 != _tmp8_label4) ? _tmp8_label4 : (_tmp8_label4 = g_quark_from_static_string ("i686"))))) {
		switch (0) {
			default:
			{
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = NULL;
				_g_free0 (arch);
				_g_free0 (_tmp1_);
				_g_free0 (os);
				return result;
			}
		}
	}
	_tmp10_ = os;
	_tmp11_ = _tmp10_;
	_tmp13_ = (NULL == _tmp11_) ? 0 : g_quark_from_string (_tmp11_);
	if (_tmp13_ == ((0 != _tmp12_label0) ? _tmp12_label0 : (_tmp12_label0 = g_quark_from_static_string ("Linux")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp14_;
				gchar* _tmp15_;
				_tmp14_ = arch;
				_tmp15_ = g_strdup_printf ("%s-%s-linux", DC_RPC_INSTALLER_RPC_BIN, _tmp14_);
				result = _tmp15_;
				_g_free0 (arch);
				_g_free0 (_tmp1_);
				_g_free0 (os);
				return result;
			}
		}
	} else if (_tmp13_ == ((0 != _tmp12_label1) ? _tmp12_label1 : (_tmp12_label1 = g_quark_from_static_string ("Darwin")))) {
		switch (0) {
			default:
			{
				gboolean _tmp16_ = FALSE;
				const gchar* _tmp17_;
				const gchar* _tmp19_;
				gchar* _tmp20_;
				_tmp17_ = arch;
				if (g_strcmp0 (_tmp17_, "x86_64") != 0) {
					const gchar* _tmp18_;
					_tmp18_ = arch;
					_tmp16_ = g_strcmp0 (_tmp18_, "aarch64") != 0;
				} else {
					_tmp16_ = FALSE;
				}
				if (_tmp16_) {
					result = NULL;
					_g_free0 (arch);
					_g_free0 (_tmp1_);
					_g_free0 (os);
					return result;
				}
				_tmp19_ = arch;
				_tmp20_ = g_strdup_printf ("%s-%s-macos", DC_RPC_INSTALLER_RPC_BIN, _tmp19_);
				result = _tmp20_;
				_g_free0 (arch);
				_g_free0 (_tmp1_);
				_g_free0 (os);
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = NULL;
				_g_free0 (arch);
				_g_free0 (_tmp1_);
				_g_free0 (os);
				return result;
			}
		}
	}
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gchar*
dc_rpc_installer_detect_os (void)
{
	GError* _inner_error0_ = NULL;
	gchar* result;
	{
		gchar* output = NULL;
		gchar* _tmp0_ = NULL;
		gchar* os = NULL;
		gchar* _tmp1_;
		const gchar* _tmp2_ = NULL;
		const gchar* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gchar* _tmp7_;
		g_spawn_command_line_sync ("uname -s", &_tmp0_, NULL, NULL, &_inner_error0_);
		_g_free0 (output);
		output = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (output);
			if (_inner_error0_->domain == G_SPAWN_ERROR) {
				goto __catch0_g_spawn_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp1_ = string_strip (output);
		os = _tmp1_;
		_tmp3_ = os;
		_tmp4_ = strlen (_tmp3_);
		_tmp5_ = _tmp4_;
		if (_tmp5_ > 0) {
			const gchar* _tmp6_;
			_tmp6_ = os;
			_tmp2_ = _tmp6_;
		} else {
			_tmp2_ = NULL;
		}
		_tmp7_ = g_strdup (_tmp2_);
		result = _tmp7_;
		_g_free0 (os);
		_g_free0 (output);
		return result;
	}
	goto __finally0;
	__catch0_g_spawn_error:
	{
		g_clear_error (&_inner_error0_);
		result = NULL;
		return result;
	}
	__finally0:
	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;
}

/**
         * Detect the host architecture, mapped to upstream asset naming. We read
         * the ELF e_machine field of our own executable first (no subprocess),
         * and fall back to `uname -m`.
         */
static gchar*
dc_rpc_installer_detect_arch (void)
{
	gchar* from_elf = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	_tmp0_ = dc_rpc_installer_arch_from_self_elf ();
	from_elf = _tmp0_;
	_tmp1_ = from_elf;
	if (_tmp1_ != NULL) {
		result = from_elf;
		return result;
	}
	_tmp2_ = dc_rpc_installer_arch_from_uname ();
	result = _tmp2_;
	_g_free0 (from_elf);
	return result;
}

static gchar*
dc_rpc_installer_arch_from_self_elf (void)
{
	GError* _inner_error0_ = NULL;
	gchar* result;
	{
		guint8* header = NULL;
		guint8* _tmp0_;
		gint header_length1;
		gint _header_size_;
		GFileInputStream* stream = NULL;
		GFile* _tmp1_;
		GFile* _tmp2_;
		GFileInputStream* _tmp3_;
		GFileInputStream* _tmp4_;
		gsize got = 0UL;
		GFileInputStream* _tmp5_;
		guint8* _tmp6_;
		gint _tmp6__length1;
		gsize _tmp7_ = 0UL;
		GFileInputStream* _tmp8_;
		gboolean _tmp9_ = FALSE;
		gboolean _tmp10_ = FALSE;
		gboolean _tmp11_ = FALSE;
		guint8* _tmp12_;
		gint _tmp12__length1;
		guint8 _tmp13_;
		gint machine = 0;
		guint8* _tmp20_;
		gint _tmp20__length1;
		guint8 _tmp21_;
		guint8* _tmp22_;
		gint _tmp22__length1;
		guint8 _tmp23_;
		_tmp0_ = g_new0 (guint8, 20);
		header = _tmp0_;
		header_length1 = 20;
		_header_size_ = header_length1;
		_tmp1_ = g_file_new_for_path ("/proc/self/exe");
		_tmp2_ = _tmp1_;
		_tmp3_ = g_file_read (_tmp2_, NULL, &_inner_error0_);
		_tmp4_ = _tmp3_;
		_g_object_unref0 (_tmp2_);
		stream = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			header = (g_free (header), NULL);
			goto __catch0_g_error;
		}
		_tmp5_ = stream;
		_tmp6_ = header;
		_tmp6__length1 = header_length1;
		g_input_stream_read_all ((GInputStream*) _tmp5_, _tmp6_, (gsize) _tmp6__length1, &_tmp7_, NULL, &_inner_error0_);
		got = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (stream);
			header = (g_free (header), NULL);
			goto __catch0_g_error;
		}
		_tmp8_ = stream;
		g_input_stream_close ((GInputStream*) _tmp8_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (stream);
			header = (g_free (header), NULL);
			goto __catch0_g_error;
		}
		if (got < ((gsize) 20)) {
			result = NULL;
			_g_object_unref0 (stream);
			header = (g_free (header), NULL);
			return result;
		}
		_tmp12_ = header;
		_tmp12__length1 = header_length1;
		_tmp13_ = _tmp12_[0];
		if (((gint) _tmp13_) != 0x7f) {
			_tmp11_ = TRUE;
		} else {
			guint8* _tmp14_;
			gint _tmp14__length1;
			guint8 _tmp15_;
			_tmp14_ = header;
			_tmp14__length1 = header_length1;
			_tmp15_ = _tmp14_[1];
			_tmp11_ = _tmp15_ != ((guint8) 'E');
		}
		if (_tmp11_) {
			_tmp10_ = TRUE;
		} else {
			guint8* _tmp16_;
			gint _tmp16__length1;
			guint8 _tmp17_;
			_tmp16_ = header;
			_tmp16__length1 = header_length1;
			_tmp17_ = _tmp16_[2];
			_tmp10_ = _tmp17_ != ((guint8) 'L');
		}
		if (_tmp10_) {
			_tmp9_ = TRUE;
		} else {
			guint8* _tmp18_;
			gint _tmp18__length1;
			guint8 _tmp19_;
			_tmp18_ = header;
			_tmp18__length1 = header_length1;
			_tmp19_ = _tmp18_[3];
			_tmp9_ = _tmp19_ != ((guint8) 'F');
		}
		if (_tmp9_) {
			result = NULL;
			_g_object_unref0 (stream);
			header = (g_free (header), NULL);
			return result;
		}
		_tmp20_ = header;
		_tmp20__length1 = header_length1;
		_tmp21_ = _tmp20_[18];
		_tmp22_ = header;
		_tmp22__length1 = header_length1;
		_tmp23_ = _tmp22_[19];
		machine = (gint) (_tmp21_ | (_tmp23_ << 8));
		switch (machine) {
			case 0x3e:
			{
				gchar* _tmp24_;
				_tmp24_ = g_strdup ("x86_64");
				result = _tmp24_;
				_g_object_unref0 (stream);
				header = (g_free (header), NULL);
				return result;
			}
			case 0xb7:
			{
				gchar* _tmp25_;
				_tmp25_ = g_strdup ("aarch64");
				result = _tmp25_;
				_g_object_unref0 (stream);
				header = (g_free (header), NULL);
				return result;
			}
			case 0x28:
			{
				gchar* _tmp26_;
				_tmp26_ = g_strdup ("armv7l");
				result = _tmp26_;
				_g_object_unref0 (stream);
				header = (g_free (header), NULL);
				return result;
			}
			case 0x03:
			{
				gchar* _tmp27_;
				_tmp27_ = g_strdup ("i686");
				result = _tmp27_;
				_g_object_unref0 (stream);
				header = (g_free (header), NULL);
				return result;
			}
			default:
			{
				result = NULL;
				_g_object_unref0 (stream);
				header = (g_free (header), NULL);
				return result;
			}
		}
		_g_object_unref0 (stream);
		header = (g_free (header), NULL);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		result = NULL;
		return result;
	}
	__finally0:
	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;
}

static gchar*
dc_rpc_installer_arch_from_uname (void)
{
	GError* _inner_error0_ = NULL;
	gchar* result;
	{
		gchar* output = NULL;
		gchar* _tmp0_ = NULL;
		gchar* m = NULL;
		const gchar* _tmp1_;
		gchar* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		GQuark _tmp6_ = 0U;
		static GQuark _tmp5_label0 = 0;
		static GQuark _tmp5_label1 = 0;
		static GQuark _tmp5_label2 = 0;
		static GQuark _tmp5_label3 = 0;
		static GQuark _tmp5_label4 = 0;
		static GQuark _tmp5_label5 = 0;
		static GQuark _tmp5_label6 = 0;
		g_spawn_command_line_sync ("uname -m", &_tmp0_, NULL, NULL, &_inner_error0_);
		_g_free0 (output);
		output = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (output);
			if (_inner_error0_->domain == G_SPAWN_ERROR) {
				goto __catch0_g_spawn_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp1_ = output;
		_tmp2_ = string_strip (_tmp1_);
		m = _tmp2_;
		_tmp3_ = m;
		_tmp4_ = _tmp3_;
		_tmp6_ = (NULL == _tmp4_) ? 0 : g_quark_from_string (_tmp4_);
		if (_tmp6_ == ((0 != _tmp5_label0) ? _tmp5_label0 : (_tmp5_label0 = g_quark_from_static_string ("x86_64")))) {
			switch (0) {
				default:
				{
					gchar* _tmp7_;
					_tmp7_ = g_strdup ("x86_64");
					result = _tmp7_;
					_g_free0 (m);
					_g_free0 (output);
					return result;
				}
			}
		} else if ((_tmp6_ == ((0 != _tmp5_label1) ? _tmp5_label1 : (_tmp5_label1 = g_quark_from_static_string ("aarch64")))) || (_tmp6_ == ((0 != _tmp5_label2) ? _tmp5_label2 : (_tmp5_label2 = g_quark_from_static_string ("arm64"))))) {
			switch (0) {
				default:
				{
					gchar* _tmp8_;
					_tmp8_ = g_strdup ("aarch64");
					result = _tmp8_;
					_g_free0 (m);
					_g_free0 (output);
					return result;
				}
			}
		} else if (_tmp6_ == ((0 != _tmp5_label3) ? _tmp5_label3 : (_tmp5_label3 = g_quark_from_static_string ("armv7l")))) {
			switch (0) {
				default:
				{
					gchar* _tmp9_;
					_tmp9_ = g_strdup ("armv7l");
					result = _tmp9_;
					_g_free0 (m);
					_g_free0 (output);
					return result;
				}
			}
		} else if (_tmp6_ == ((0 != _tmp5_label4) ? _tmp5_label4 : (_tmp5_label4 = g_quark_from_static_string ("armv6l")))) {
			switch (0) {
				default:
				{
					gchar* _tmp10_;
					_tmp10_ = g_strdup ("armv6l");
					result = _tmp10_;
					_g_free0 (m);
					_g_free0 (output);
					return result;
				}
			}
		} else if ((_tmp6_ == ((0 != _tmp5_label5) ? _tmp5_label5 : (_tmp5_label5 = g_quark_from_static_string ("i686")))) || (_tmp6_ == ((0 != _tmp5_label6) ? _tmp5_label6 : (_tmp5_label6 = g_quark_from_static_string ("i386"))))) {
			switch (0) {
				default:
				{
					gchar* _tmp11_;
					_tmp11_ = g_strdup ("i686");
					result = _tmp11_;
					_g_free0 (m);
					_g_free0 (output);
					return result;
				}
			}
		} else {
			switch (0) {
				default:
				{
					result = NULL;
					_g_free0 (m);
					_g_free0 (output);
					return result;
				}
			}
		}
		_g_free0 (m);
		_g_free0 (output);
	}
	goto __finally0;
	__catch0_g_spawn_error:
	{
		g_clear_error (&_inner_error0_);
		result = NULL;
		return result;
	}
	__finally0:
	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;
}

static void
dc_rpc_installer_installed_version_data_free (gpointer _data)
{
	DcRpcInstallerInstalledVersionData* _data_;
	_data_ = _data;
	_g_free0 (_data_->result);
	g_slice_free (DcRpcInstallerInstalledVersionData, _data_);
}

void
dc_rpc_installer_installed_version (GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	DcRpcInstallerInstalledVersionData* _data_;
	_data_ = g_slice_new0 (DcRpcInstallerInstalledVersionData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_installer_installed_version_data_free);
	dc_rpc_installer_installed_version_co (_data_);
}

gchar*
dc_rpc_installer_installed_version_finish (GAsyncResult* _res_)
{
	gchar* result;
	DcRpcInstallerInstalledVersionData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/** Read the installed managed binary's --version string, or null. */
static void
dc_rpc_installer_installed_version_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	DcRpcInstallerInstalledVersionData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_installer_installed_version_co (_data_);
}

static gboolean
dc_rpc_installer_installed_version_co (DcRpcInstallerInstalledVersionData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dc_rpc_installer_managed_bin_path ();
	_data_->path = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->path;
	if (!g_file_test (_data_->_tmp1_, G_FILE_TEST_IS_EXECUTABLE)) {
		_data_->result = NULL;
		_g_free0 (_data_->path);
		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_->_tmp2_ = _data_->path;
		_data_->_tmp3_ = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &_data_->_inner_error0_, _data_->_tmp2_, "--version", NULL);
		_data_->process = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->stderr_buf);
			_g_free0 (_data_->stdout_buf);
			goto __catch0_g_error;
		}
		_data_->_tmp4_ = _data_->process;
		_data_->_tmp5_ = NULL;
		_data_->_tmp6_ = NULL;
		_data_->_state_ = 1;
		g_subprocess_communicate_utf8_async (_data_->_tmp4_, NULL, NULL, dc_rpc_installer_installed_version_ready, _data_);
		return FALSE;
		_state_1:
		g_subprocess_communicate_utf8_finish (_data_->_tmp4_, _data_->_res_, &_data_->_tmp5_, &_data_->_tmp6_, &_data_->_inner_error0_);
		_g_free0 (_data_->stdout_buf);
		_data_->stdout_buf = _data_->_tmp5_;
		_g_free0 (_data_->stderr_buf);
		_data_->stderr_buf = _data_->_tmp6_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->process);
			_g_free0 (_data_->stderr_buf);
			_g_free0 (_data_->stdout_buf);
			goto __catch0_g_error;
		}
		_data_->_tmp7_ = _data_->process;
		_data_->successful = g_subprocess_get_successful (_data_->_tmp7_);
		_data_->_tmp10_ = _data_->stdout_buf;
		_data_->_tmp9_ = _data_->_tmp10_;
		if (_data_->_tmp9_ == NULL) {
			_data_->_tmp9_ = "";
		}
		_data_->_tmp11_ = string_strip (_data_->_tmp9_);
		_data_->_tmp12_ = _data_->_tmp11_;
		_data_->_tmp13_ = strlen (_data_->_tmp12_);
		_data_->_tmp14_ = _data_->_tmp13_;
		_data_->_tmp15_ = _data_->_tmp14_ > 0;
		_g_free0 (_data_->_tmp12_);
		if (_data_->_tmp15_) {
			_data_->_tmp17_ = _data_->stdout_buf;
			_data_->_tmp16_ = _data_->_tmp17_;
			if (_data_->_tmp16_ == NULL) {
				_data_->_tmp16_ = "";
			}
			_data_->_tmp18_ = string_strip (_data_->_tmp16_);
			_g_free0 (_data_->_tmp8_);
			_data_->_tmp8_ = _data_->_tmp18_;
		} else {
			_data_->_tmp20_ = _data_->stderr_buf;
			_data_->_tmp19_ = _data_->_tmp20_;
			if (_data_->_tmp19_ == NULL) {
				_data_->_tmp19_ = "";
			}
			_data_->_tmp21_ = string_strip (_data_->_tmp19_);
			_g_free0 (_data_->_tmp8_);
			_data_->_tmp8_ = _data_->_tmp21_;
		}
		_data_->_tmp22_ = _data_->_tmp8_;
		_data_->_tmp8_ = NULL;
		_data_->version = _data_->_tmp22_;
		if (_data_->successful) {
			_data_->_tmp25_ = _data_->version;
			_data_->_tmp26_ = strlen (_data_->_tmp25_);
			_data_->_tmp27_ = _data_->_tmp26_;
			_data_->_tmp24_ = _data_->_tmp27_ > 0;
		} else {
			_data_->_tmp24_ = FALSE;
		}
		if (_data_->_tmp24_) {
			_data_->_tmp28_ = _data_->version;
			_data_->_tmp23_ = _data_->_tmp28_;
		} else {
			_data_->_tmp23_ = NULL;
		}
		_data_->_tmp29_ = g_strdup (_data_->_tmp23_);
		_data_->result = _data_->_tmp29_;
		_g_free0 (_data_->version);
		_g_free0 (_data_->_tmp8_);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_g_free0 (_data_->stdout_buf);
		_g_free0 (_data_->path);
		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:
	{
		g_clear_error (&_data_->_inner_error0_);
		_data_->result = NULL;
		_g_free0 (_data_->path);
		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_free0 (_data_->path);
	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;
}

/**
         * Resolve the latest upstream release tag (e.g. "v2.51.0") by following
         * the redirect from the GitHub "latest" release URL.
         */
static gboolean
dc_rpc_installer_use_curl (void)
{
	gboolean result;
	result = dc_platform_is_macos ();
	return result;
}

static void
dc_rpc_installer_fetch_latest_tag_data_free (gpointer _data)
{
	DcRpcInstallerFetchLatestTagData* _data_;
	_data_ = _data;
	_g_free0 (_data_->result);
	g_slice_free (DcRpcInstallerFetchLatestTagData, _data_);
}

void
dc_rpc_installer_fetch_latest_tag (GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	DcRpcInstallerFetchLatestTagData* _data_;
	_data_ = g_slice_new0 (DcRpcInstallerFetchLatestTagData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_installer_fetch_latest_tag_data_free);
	dc_rpc_installer_fetch_latest_tag_co (_data_);
}

gchar*
dc_rpc_installer_fetch_latest_tag_finish (GAsyncResult* _res_,
                                          GError** error)
{
	gchar* result;
	DcRpcInstallerFetchLatestTagData* _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
dc_rpc_installer_fetch_latest_tag_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	DcRpcInstallerFetchLatestTagData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_installer_fetch_latest_tag_co (_data_);
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

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 gboolean
dc_rpc_installer_fetch_latest_tag_co (DcRpcInstallerFetchLatestTagData* _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;
		case 6:
		goto _state_6;
		case 7:
		goto _state_7;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (dc_rpc_installer_use_curl ()) {
		_data_->_state_ = 1;
		dc_rpc_installer_fetch_latest_tag_with_curl (dc_rpc_installer_fetch_latest_tag_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp1_ = dc_rpc_installer_fetch_latest_tag_with_curl_finish (_data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp0_ = _data_->_tmp1_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp2_ = _data_->_tmp0_;
		_data_->_tmp0_ = NULL;
		_data_->result = _data_->_tmp2_;
		_g_free0 (_data_->_tmp0_);
		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_->_tmp3_ = g_socket_client_new ();
	_data_->client = _data_->_tmp3_;
	_data_->_tmp4_ = _data_->client;
	g_socket_client_set_timeout (_data_->_tmp4_, (guint) 15);
	_data_->_tmp5_ = _data_->client;
	_data_->_state_ = 2;
	g_socket_client_connect_to_host_async (_data_->_tmp5_, "github.com", (guint16) 443, NULL, dc_rpc_installer_fetch_latest_tag_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp6_ = g_socket_client_connect_to_host_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
	_data_->tcp = _data_->_tmp6_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp7_ = (GNetworkAddress*) g_network_address_new ("github.com", (guint16) 443);
	_data_->identity = _data_->_tmp7_;
	_data_->_tmp8_ = _data_->tcp;
	_data_->_tmp9_ = _data_->identity;
	_data_->_tmp10_ = g_tls_client_connection_new ((GIOStream*) _data_->_tmp8_, (GSocketConnectable*) _data_->_tmp9_, &_data_->_inner_error0_);
	_data_->tls = _data_->_tmp10_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->tls;
	if (_data_->_tmp11_ == NULL) {
		_data_->_tmp12_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to create TLS connection");
		_data_->_inner_error0_ = _data_->_tmp12_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp13_ = _data_->tls;
	_data_->_state_ = 3;
	g_tls_connection_handshake_async ((GTlsConnection*) _data_->_tmp13_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_fetch_latest_tag_ready, _data_);
	return FALSE;
	_state_3:
	g_tls_connection_handshake_finish ((GTlsConnection*) _data_->_tmp13_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp14_ = g_strdup ("HEAD /chatmail/core/releases/latest HTTP/1.1\r\n" "Host: github.com\r\n" "User-Agent: Parla\r\n" "Accept: */*\r\n" "Connection: close\r\n\r\n");
	_data_->request = _data_->_tmp14_;
	_data_->_tmp15_ = _data_->tls;
	_data_->_tmp16_ = g_io_stream_get_output_stream ((GIOStream*) _data_->_tmp15_);
	_data_->_tmp17_ = _data_->_tmp16_;
	_data_->_tmp18_ = _data_->request;
	_data_->_tmp20_ = 0;
	_data_->_tmp19_ = string_get_data (_data_->_tmp18_, &_data_->_tmp20_);
	_data_->_tmp19__length1 = _data_->_tmp20_;
	_data_->_tmp21_ = _data_->_tmp19_;
	_data_->_tmp21__length1 = _data_->_tmp19__length1;
	_data_->_tmp22_ = 0UL;
	_data_->_state_ = 4;
	g_output_stream_write_all_async (_data_->_tmp17_, _data_->_tmp21_, (gsize) _data_->_tmp21__length1, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_fetch_latest_tag_ready, _data_);
	return FALSE;
	_state_4:
	g_output_stream_write_all_finish (_data_->_tmp17_, _data_->_res_, &_data_->_tmp22_, &_data_->_inner_error0_);
	_data_->written = _data_->_tmp22_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp23_ = _data_->tls;
	_data_->_tmp24_ = g_io_stream_get_input_stream ((GIOStream*) _data_->_tmp23_);
	_data_->_tmp25_ = _data_->_tmp24_;
	_data_->_tmp26_ = g_data_input_stream_new (_data_->_tmp25_);
	_data_->reader = _data_->_tmp26_;
	_data_->_tmp27_ = _data_->reader;
	g_data_input_stream_set_newline_type (_data_->_tmp27_, G_DATA_STREAM_NEWLINE_TYPE_LF);
	_data_->_tmp28_ = _data_->reader;
	_data_->_tmp29_ = 0UL;
	_data_->_state_ = 5;
	g_data_input_stream_read_line_async (_data_->_tmp28_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_fetch_latest_tag_ready, _data_);
	return FALSE;
	_state_5:
	_data_->_tmp30_ = g_data_input_stream_read_line_finish_utf8 (_data_->_tmp28_, _data_->_res_, &_data_->_tmp29_, &_data_->_inner_error0_);
	_data_->len = _data_->_tmp29_;
	_data_->status_line = _data_->_tmp30_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp32_ = _data_->status_line;
	_data_->_tmp31_ = _data_->_tmp32_;
	if (_data_->_tmp31_ == NULL) {
		_data_->_tmp31_ = "";
	}
	_data_->status = dc_rpc_installer_parse_http_status (_data_->_tmp31_);
	_data_->location = NULL;
	while (TRUE) {
		_data_->_tmp34_ = _data_->reader;
		_data_->_tmp35_ = 0UL;
		_data_->_state_ = 6;
		g_data_input_stream_read_line_async (_data_->_tmp34_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_fetch_latest_tag_ready, _data_);
		return FALSE;
		_state_6:
		_data_->_tmp36_ = g_data_input_stream_read_line_finish_utf8 (_data_->_tmp34_, _data_->_res_, &_data_->_tmp35_, &_data_->_inner_error0_);
		_data_->len = _data_->_tmp35_;
		_data_->_tmp33_ = _data_->_tmp36_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp37_ = _data_->_tmp33_;
		_data_->_tmp33_ = NULL;
		_g_free0 (_data_->line);
		_data_->line = _data_->_tmp37_;
		_data_->_tmp38_ = _data_->line;
		if (!(_data_->_tmp38_ != NULL)) {
			_g_free0 (_data_->_tmp33_);
			break;
		}
		_data_->_tmp39_ = _data_->line;
		_data_->_tmp40_ = string_strip (_data_->_tmp39_);
		_data_->stripped = _data_->_tmp40_;
		_data_->_tmp41_ = _data_->stripped;
		_data_->_tmp42_ = strlen (_data_->_tmp41_);
		_data_->_tmp43_ = _data_->_tmp42_;
		if (_data_->_tmp43_ == 0) {
			_g_free0 (_data_->stripped);
			_g_free0 (_data_->_tmp33_);
			break;
		}
		_data_->_tmp44_ = _data_->stripped;
		_data_->_tmp45_ = g_utf8_strdown (_data_->_tmp44_, (gssize) -1);
		_data_->_tmp46_ = _data_->_tmp45_;
		_data_->_tmp47_ = g_str_has_prefix (_data_->_tmp46_, "location:");
		_g_free0 (_data_->_tmp46_);
		if (_data_->_tmp47_) {
			_data_->_tmp48_ = _data_->stripped;
			_data_->_tmp49_ = strlen ("location:");
			_data_->_tmp50_ = _data_->_tmp49_;
			_data_->_tmp51_ = string_substring (_data_->_tmp48_, (glong) _data_->_tmp50_, (glong) -1);
			_data_->_tmp52_ = _data_->_tmp51_;
			_data_->_tmp53_ = string_strip (_data_->_tmp52_);
			_g_free0 (_data_->location);
			_data_->location = _data_->_tmp53_;
			_g_free0 (_data_->_tmp52_);
		}
		_g_free0 (_data_->stripped);
		_g_free0 (_data_->_tmp33_);
	}
	{
		_data_->_tmp54_ = _data_->tls;
		_data_->_state_ = 7;
		g_io_stream_close_async ((GIOStream*) _data_->_tmp54_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_fetch_latest_tag_ready, _data_);
		return FALSE;
		_state_7:
		g_io_stream_close_finish ((GIOStream*) _data_->_tmp54_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->status < 300) {
		_data_->_tmp56_ = TRUE;
	} else {
		_data_->_tmp56_ = _data_->status >= 400;
	}
	if (_data_->_tmp56_) {
		_data_->_tmp55_ = TRUE;
	} else {
		_data_->_tmp57_ = _data_->location;
		_data_->_tmp55_ = _data_->_tmp57_ == NULL;
	}
	if (_data_->_tmp55_) {
		_data_->_tmp58_ = g_strdup_printf ("GitHub returned HTTP status %d", _data_->status);
		_data_->_tmp59_ = _data_->_tmp58_;
		_data_->_tmp60_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp59_);
		_data_->_tmp61_ = _data_->_tmp60_;
		_g_free0 (_data_->_tmp59_);
		_data_->_inner_error0_ = _data_->_tmp61_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp62_ = _data_->location;
	_data_->_tmp63_ = dc_rpc_installer_extract_release_tag (_data_->_tmp62_);
	_data_->tag = _data_->_tmp63_;
	_data_->_tmp64_ = _data_->tag;
	if (_data_->_tmp64_ == NULL) {
		_data_->_tmp65_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "GitHub response did not include a release tag");
		_data_->_inner_error0_ = _data_->_tmp65_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->tag);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->tag;
	_g_free0 (_data_->line);
	_g_free0 (_data_->location);
	_g_free0 (_data_->status_line);
	_g_object_unref0 (_data_->reader);
	_g_free0 (_data_->request);
	_g_object_unref0 (_data_->tls);
	_g_object_unref0 (_data_->identity);
	_g_object_unref0 (_data_->tcp);
	_g_object_unref0 (_data_->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
dc_rpc_installer_download_latest_data_free (gpointer _data)
{
	DcRpcInstallerDownloadLatestData* _data_;
	_data_ = _data;
	_g_free0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcInstallerDownloadLatestData, _data_);
}

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

void
dc_rpc_installer_download_latest (DcRpcInstaller* self,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	DcRpcInstallerDownloadLatestData* _data_;
	DcRpcInstaller* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcRpcInstallerDownloadLatestData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_installer_download_latest_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_rpc_installer_download_latest_co (_data_);
}

gchar*
dc_rpc_installer_download_latest_finish (DcRpcInstaller* self,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	gchar* result;
	DcRpcInstallerDownloadLatestData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
         * Download the latest matching server release into the managed
         * directory and atomically install it. Returns the installed path.
         */
static void
dc_rpc_installer_download_latest_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	DcRpcInstallerDownloadLatestData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_installer_download_latest_co (_data_);
}

static gboolean
dc_rpc_installer_download_latest_co (DcRpcInstallerDownloadLatestData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dc_rpc_installer_detect_asset_name ();
	_data_->asset = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->asset;
	if (_data_->_tmp1_ != NULL) {
		_data_->_tmp3_ = _data_->asset;
		_data_->_state_ = 1;
		dc_rpc_installer_download_release_asset (_data_->self, _data_->_tmp3_, dc_rpc_installer_download_latest_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp4_ = dc_rpc_installer_download_release_asset_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp2_ = _data_->_tmp4_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->asset);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp5_ = _data_->_tmp2_;
		_data_->_tmp2_ = NULL;
		_data_->result = _data_->_tmp5_;
		_g_free0 (_data_->_tmp2_);
		_g_free0 (_data_->asset);
		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_->_tmp6_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "No prebuilt deltachat-rpc-server is published for this platform");
	_data_->_inner_error0_ = _data_->_tmp6_;
	g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
	_g_free0 (_data_->asset);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dc_rpc_installer_download_release_asset_data_free (gpointer _data)
{
	DcRpcInstallerDownloadReleaseAssetData* _data_;
	_data_ = _data;
	_g_free0 (_data_->asset);
	_g_free0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcInstallerDownloadReleaseAssetData, _data_);
}

static void
dc_rpc_installer_download_release_asset (DcRpcInstaller* self,
                                         const gchar* asset,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	DcRpcInstallerDownloadReleaseAssetData* _data_;
	DcRpcInstaller* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (asset != NULL);
	_data_ = g_slice_new0 (DcRpcInstallerDownloadReleaseAssetData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_installer_download_release_asset_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (asset);
	_g_free0 (_data_->asset);
	_data_->asset = _tmp1_;
	dc_rpc_installer_download_release_asset_co (_data_);
}

static gchar*
dc_rpc_installer_download_release_asset_finish (DcRpcInstaller* self,
                                                GAsyncResult* _res_,
                                                GError** error)
{
	gchar* result;
	DcRpcInstallerDownloadReleaseAssetData* _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
dc_rpc_installer_download_release_asset_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	DcRpcInstallerDownloadReleaseAssetData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_installer_download_release_asset_co (_data_);
}

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

static gboolean
dc_rpc_installer_download_release_asset_co (DcRpcInstallerDownloadReleaseAssetData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dc_rpc_installer_managed_dir ();
	_data_->dir = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->dir;
	g_mkdir_with_parents (_data_->_tmp1_, 0700);
	_data_->_state_ = 1;
	dc_rpc_installer_fetch_latest_tag (dc_rpc_installer_download_release_asset_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp2_ = dc_rpc_installer_fetch_latest_tag_finish (_data_->_res_, &_data_->_inner_error0_);
	_data_->tag = _data_->_tmp2_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->dir);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->tag;
	_data_->_tmp4_ = g_strdup_printf ("https://github.com/chatmail/core/releases/download/%s/%s", _data_->_tmp3_, _data_->asset);
	_data_->url = _data_->_tmp4_;
	_data_->_tmp5_ = _data_->dir;
	_data_->_tmp6_ = g_strdup_printf (".%s.download", DC_RPC_INSTALLER_RPC_BIN);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = g_build_filename (_data_->_tmp5_, _data_->_tmp7_, NULL);
	_data_->_tmp9_ = _data_->_tmp8_;
	_g_free0 (_data_->_tmp7_);
	_data_->tmp = _data_->_tmp9_;
	_data_->_tmp10_ = _data_->tmp;
	g_unlink (_data_->_tmp10_);
	{
		if (dc_rpc_installer_use_curl ()) {
			_data_->_tmp11_ = _data_->url;
			_data_->_tmp12_ = _data_->tmp;
			_data_->_state_ = 2;
			dc_rpc_installer_curl_get_to_file (_data_->self, _data_->_tmp11_, _data_->_tmp12_, dc_rpc_installer_download_release_asset_ready, _data_);
			return FALSE;
			_state_2:
			dc_rpc_installer_curl_get_to_file_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		} else {
			_data_->_tmp13_ = _data_->url;
			_data_->_tmp14_ = _data_->tmp;
			_data_->_state_ = 3;
			dc_rpc_installer_https_get_to_file (_data_->self, _data_->_tmp13_, _data_->_tmp14_, 0, dc_rpc_installer_download_release_asset_ready, _data_);
			return FALSE;
			_state_3:
			dc_rpc_installer_https_get_to_file_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		_data_->_tmp15_ = _data_->tmp;
		dc_rpc_installer_ensure_executable (_data_->_tmp15_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp16_ = dc_rpc_installer_managed_bin_path ();
		_data_->final_path = _data_->_tmp16_;
		_data_->_tmp17_ = _data_->final_path;
		g_unlink (_data_->_tmp17_);
		_data_->_tmp18_ = _data_->tmp;
		_data_->_tmp19_ = _data_->final_path;
		if (g_rename (_data_->_tmp18_, _data_->_tmp19_) != 0) {
			_data_->_tmp20_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Could not install the server binary");
			_data_->_inner_error0_ = _data_->_tmp20_;
			_g_free0 (_data_->final_path);
			goto __catch0_g_error;
		}
		_data_->_tmp21_ = _data_->final_path;
		dc_rpc_installer_ensure_executable (_data_->_tmp21_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->final_path);
			goto __catch0_g_error;
		}
		_data_->result = _data_->final_path;
		_g_free0 (_data_->tmp);
		_g_free0 (_data_->url);
		_g_free0 (_data_->tag);
		_g_free0 (_data_->dir);
		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_->_tmp22_ = _data_->tmp;
		g_unlink (_data_->_tmp22_);
		_data_->_tmp23_ = _data_->e;
		_data_->_tmp24_ = _g_error_copy0 (_data_->_tmp23_);
		_data_->_inner_error0_ = _data_->_tmp24_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
	_g_free0 (_data_->tmp);
	_g_free0 (_data_->url);
	_g_free0 (_data_->tag);
	_g_free0 (_data_->dir);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
dc_rpc_installer_curl_path (void)
{
	gchar* _tmp1_;
	gchar* result;
	if (g_file_test ("/usr/bin/curl", G_FILE_TEST_IS_EXECUTABLE)) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("/usr/bin/curl");
		result = _tmp0_;
		return result;
	}
	_tmp1_ = g_find_program_in_path ("curl");
	result = _tmp1_;
	return result;
}

static gchar*
dc_rpc_installer_curl_failure_message (const gchar* stderr_buf)
{
	const gchar* _tmp0_ = NULL;
	gchar* msg = NULL;
	gchar* _tmp1_;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gchar* _tmp7_;
	gchar* result;
	_tmp0_ = stderr_buf;
	if (_tmp0_ == NULL) {
		_tmp0_ = "";
	}
	_tmp1_ = string_strip (_tmp0_);
	msg = _tmp1_;
	_tmp3_ = msg;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ > 0) {
		const gchar* _tmp6_;
		_tmp6_ = msg;
		_tmp2_ = _tmp6_;
	} else {
		_tmp2_ = "curl exited unsuccessfully";
	}
	_tmp7_ = g_strdup (_tmp2_);
	result = _tmp7_;
	_g_free0 (msg);
	return result;
}

static void
dc_rpc_installer_fetch_latest_tag_with_curl_data_free (gpointer _data)
{
	DcRpcInstallerFetchLatestTagWithCurlData* _data_;
	_data_ = _data;
	_g_free0 (_data_->result);
	g_slice_free (DcRpcInstallerFetchLatestTagWithCurlData, _data_);
}

static void
dc_rpc_installer_fetch_latest_tag_with_curl (GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	DcRpcInstallerFetchLatestTagWithCurlData* _data_;
	_data_ = g_slice_new0 (DcRpcInstallerFetchLatestTagWithCurlData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_installer_fetch_latest_tag_with_curl_data_free);
	dc_rpc_installer_fetch_latest_tag_with_curl_co (_data_);
}

static gchar*
dc_rpc_installer_fetch_latest_tag_with_curl_finish (GAsyncResult* _res_,
                                                    GError** error)
{
	gchar* result;
	DcRpcInstallerFetchLatestTagWithCurlData* _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
dc_rpc_installer_fetch_latest_tag_with_curl_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	DcRpcInstallerFetchLatestTagWithCurlData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_installer_fetch_latest_tag_with_curl_co (_data_);
}

static gboolean
dc_rpc_installer_fetch_latest_tag_with_curl_co (DcRpcInstallerFetchLatestTagWithCurlData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dc_rpc_installer_curl_path ();
	_data_->curl = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->curl;
	if (_data_->_tmp1_ == NULL) {
		_data_->_tmp2_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "curl is required to download");
		_data_->_inner_error0_ = _data_->_tmp2_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->curl;
	_data_->_tmp4_ = g_strdup (_data_->_tmp3_);
	_data_->_tmp5_ = g_strdup ("--head");
	_data_->_tmp6_ = g_strdup ("--silent");
	_data_->_tmp7_ = g_strdup ("--show-error");
	_data_->_tmp8_ = g_strdup ("--max-time");
	_data_->_tmp9_ = g_strdup ("15");
	_data_->_tmp10_ = g_strdup ("--user-agent");
	_data_->_tmp11_ = g_strdup ("Parla");
	_data_->_tmp12_ = g_strdup ("https://github.com/chatmail/core/releases/latest");
	_data_->_tmp13_ = g_new0 (gchar*, 9 + 1);
	_data_->_tmp13_[0] = _data_->_tmp4_;
	_data_->_tmp13_[1] = _data_->_tmp5_;
	_data_->_tmp13_[2] = _data_->_tmp6_;
	_data_->_tmp13_[3] = _data_->_tmp7_;
	_data_->_tmp13_[4] = _data_->_tmp8_;
	_data_->_tmp13_[5] = _data_->_tmp9_;
	_data_->_tmp13_[6] = _data_->_tmp10_;
	_data_->_tmp13_[7] = _data_->_tmp11_;
	_data_->_tmp13_[8] = _data_->_tmp12_;
	_data_->argv = _data_->_tmp13_;
	_data_->argv_length1 = 9;
	_data_->_argv_size_ = _data_->argv_length1;
	_data_->_tmp14_ = _data_->argv;
	_data_->_tmp14__length1 = _data_->argv_length1;
	_data_->_tmp15_ = g_subprocess_newv (_data_->_tmp14_, G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &_data_->_inner_error0_);
	_data_->process = _data_->_tmp15_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->stderr_buf);
		_g_free0 (_data_->stdout_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp16_ = _data_->process;
	_data_->_tmp17_ = NULL;
	_data_->_tmp18_ = NULL;
	_data_->_state_ = 1;
	g_subprocess_communicate_utf8_async (_data_->_tmp16_, NULL, NULL, dc_rpc_installer_fetch_latest_tag_with_curl_ready, _data_);
	return FALSE;
	_state_1:
	g_subprocess_communicate_utf8_finish (_data_->_tmp16_, _data_->_res_, &_data_->_tmp17_, &_data_->_tmp18_, &_data_->_inner_error0_);
	_g_free0 (_data_->stdout_buf);
	_data_->stdout_buf = _data_->_tmp17_;
	_g_free0 (_data_->stderr_buf);
	_data_->stderr_buf = _data_->_tmp18_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_g_free0 (_data_->stdout_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp19_ = _data_->process;
	_data_->successful = g_subprocess_get_successful (_data_->_tmp19_);
	if (!_data_->successful) {
		_data_->_tmp20_ = _data_->stderr_buf;
		_data_->_tmp21_ = dc_rpc_installer_curl_failure_message (_data_->_tmp20_);
		_data_->_tmp22_ = _data_->_tmp21_;
		_data_->_tmp23_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp22_);
		_data_->_tmp24_ = _data_->_tmp23_;
		_g_free0 (_data_->_tmp22_);
		_data_->_inner_error0_ = _data_->_tmp24_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_g_free0 (_data_->stdout_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->location = NULL;
	_data_->_tmp26_ = _data_->stdout_buf;
	_data_->_tmp25_ = _data_->_tmp26_;
	if (_data_->_tmp25_ == NULL) {
		_data_->_tmp25_ = "";
	}
	_data_->_tmp28_ = _data_->_tmp27_ = g_strsplit (_data_->_tmp25_, "\n", 0);
	{
		_data_->line_collection_length1 = 0;
		_data_->_line_collection_size_ = 0;
		_data_->line_collection = _data_->_tmp28_;
		_data_->line_collection_length1 = _vala_array_length (_data_->_tmp27_);
		for (_data_->line_it = 0; _data_->line_it < _data_->line_collection_length1; _data_->line_it = _data_->line_it + 1) {
			_data_->_tmp29_ = g_strdup (_data_->line_collection[_data_->line_it]);
			_data_->line = _data_->_tmp29_;
			{
				_data_->_tmp30_ = _data_->line;
				_data_->_tmp31_ = string_strip (_data_->_tmp30_);
				_data_->stripped = _data_->_tmp31_;
				_data_->_tmp32_ = _data_->stripped;
				_data_->_tmp33_ = g_utf8_strdown (_data_->_tmp32_, (gssize) -1);
				_data_->_tmp34_ = _data_->_tmp33_;
				_data_->_tmp35_ = g_str_has_prefix (_data_->_tmp34_, "location:");
				_g_free0 (_data_->_tmp34_);
				if (_data_->_tmp35_) {
					_data_->_tmp36_ = _data_->stripped;
					_data_->_tmp37_ = strlen ("location:");
					_data_->_tmp38_ = _data_->_tmp37_;
					_data_->_tmp39_ = string_substring (_data_->_tmp36_, (glong) _data_->_tmp38_, (glong) -1);
					_data_->_tmp40_ = _data_->_tmp39_;
					_data_->_tmp41_ = string_strip (_data_->_tmp40_);
					_g_free0 (_data_->location);
					_data_->location = _data_->_tmp41_;
					_g_free0 (_data_->_tmp40_);
					_g_free0 (_data_->stripped);
					_g_free0 (_data_->line);
					break;
				}
				_g_free0 (_data_->stripped);
				_g_free0 (_data_->line);
			}
		}
		_data_->line_collection = (_vala_array_free (_data_->line_collection, _data_->line_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_data_->_tmp42_ = _data_->location;
	if (_data_->_tmp42_ == NULL) {
		_data_->_tmp43_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "GitHub response did not include a release redirect");
		_data_->_inner_error0_ = _data_->_tmp43_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->location);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_g_free0 (_data_->stdout_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp44_ = _data_->location;
	_data_->_tmp45_ = dc_rpc_installer_extract_release_tag (_data_->_tmp44_);
	_data_->tag = _data_->_tmp45_;
	_data_->_tmp46_ = _data_->tag;
	if (_data_->_tmp46_ == NULL) {
		_data_->_tmp47_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "GitHub response did not include a release tag");
		_data_->_inner_error0_ = _data_->_tmp47_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->tag);
		_g_free0 (_data_->location);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_g_free0 (_data_->stdout_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->tag;
	_g_free0 (_data_->location);
	_g_object_unref0 (_data_->process);
	_g_free0 (_data_->stderr_buf);
	_g_free0 (_data_->stdout_buf);
	_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (_data_->curl);
	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
dc_rpc_installer_curl_get_to_file_data_free (gpointer _data)
{
	DcRpcInstallerCurlGetToFileData* _data_;
	_data_ = _data;
	_g_free0 (_data_->url);
	_g_free0 (_data_->dest);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcInstallerCurlGetToFileData, _data_);
}

static void
dc_rpc_installer_curl_get_to_file (DcRpcInstaller* self,
                                   const gchar* url,
                                   const gchar* dest,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	DcRpcInstallerCurlGetToFileData* _data_;
	DcRpcInstaller* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (url != NULL);
	g_return_if_fail (dest != NULL);
	_data_ = g_slice_new0 (DcRpcInstallerCurlGetToFileData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_installer_curl_get_to_file_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (url);
	_g_free0 (_data_->url);
	_data_->url = _tmp1_;
	_tmp2_ = g_strdup (dest);
	_g_free0 (_data_->dest);
	_data_->dest = _tmp2_;
	dc_rpc_installer_curl_get_to_file_co (_data_);
}

static void
dc_rpc_installer_curl_get_to_file_finish (DcRpcInstaller* self,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	DcRpcInstallerCurlGetToFileData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
dc_rpc_installer_curl_get_to_file_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	DcRpcInstallerCurlGetToFileData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_installer_curl_get_to_file_co (_data_);
}

static gboolean
dc_rpc_installer_curl_get_to_file_co (DcRpcInstallerCurlGetToFileData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dc_rpc_installer_curl_path ();
	_data_->curl = _data_->_tmp0_;
	if (_data_->curl == NULL) {
		_data_->_tmp1_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "curl is required to download");
		_data_->_inner_error0_ = _data_->_tmp1_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_signal_emit (_data_->self, dc_rpc_installer_signals[DC_RPC_INSTALLER_PROGRESS_SIGNAL], 0, (gint64) 0, (gint64) -1);
	_data_->_tmp2_ = g_strdup (_data_->curl);
	_data_->_tmp3_ = g_strdup ("--location");
	_data_->_tmp4_ = g_strdup ("--fail");
	_data_->_tmp5_ = g_strdup ("--silent");
	_data_->_tmp6_ = g_strdup ("--show-error");
	_data_->_tmp7_ = g_strdup ("--connect-timeout");
	_data_->_tmp8_ = g_strdup ("15");
	_data_->_tmp9_ = g_strdup ("--max-time");
	_data_->_tmp10_ = g_strdup ("300");
	_data_->_tmp11_ = g_strdup ("--user-agent");
	_data_->_tmp12_ = g_strdup ("Parla");
	_data_->_tmp13_ = g_strdup ("--output");
	_data_->_tmp14_ = g_strdup (_data_->dest);
	_data_->_tmp15_ = g_strdup (_data_->url);
	_data_->_tmp16_ = g_new0 (gchar*, 14 + 1);
	_data_->_tmp16_[0] = _data_->_tmp2_;
	_data_->_tmp16_[1] = _data_->_tmp3_;
	_data_->_tmp16_[2] = _data_->_tmp4_;
	_data_->_tmp16_[3] = _data_->_tmp5_;
	_data_->_tmp16_[4] = _data_->_tmp6_;
	_data_->_tmp16_[5] = _data_->_tmp7_;
	_data_->_tmp16_[6] = _data_->_tmp8_;
	_data_->_tmp16_[7] = _data_->_tmp9_;
	_data_->_tmp16_[8] = _data_->_tmp10_;
	_data_->_tmp16_[9] = _data_->_tmp11_;
	_data_->_tmp16_[10] = _data_->_tmp12_;
	_data_->_tmp16_[11] = _data_->_tmp13_;
	_data_->_tmp16_[12] = _data_->_tmp14_;
	_data_->_tmp16_[13] = _data_->_tmp15_;
	_data_->argv = _data_->_tmp16_;
	_data_->argv_length1 = 14;
	_data_->_argv_size_ = _data_->argv_length1;
	_data_->_tmp17_ = _data_->argv;
	_data_->_tmp17__length1 = _data_->argv_length1;
	_data_->_tmp18_ = g_subprocess_newv (_data_->_tmp17_, G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &_data_->_inner_error0_);
	_data_->process = _data_->_tmp18_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->stderr_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp19_ = _data_->process;
	_data_->_tmp20_ = NULL;
	_data_->_tmp21_ = NULL;
	_data_->_state_ = 1;
	g_subprocess_communicate_utf8_async (_data_->_tmp19_, NULL, NULL, dc_rpc_installer_curl_get_to_file_ready, _data_);
	return FALSE;
	_state_1:
	g_subprocess_communicate_utf8_finish (_data_->_tmp19_, _data_->_res_, &_data_->_tmp20_, &_data_->_tmp21_, &_data_->_inner_error0_);
	_g_free0 (_data_->stdout_buf);
	_data_->stdout_buf = _data_->_tmp20_;
	_g_free0 (_data_->stderr_buf);
	_data_->stderr_buf = _data_->_tmp21_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->stdout_buf);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp22_ = _data_->process;
	_data_->successful = g_subprocess_get_successful (_data_->_tmp22_);
	if (!_data_->successful) {
		_data_->_tmp23_ = _data_->stderr_buf;
		_data_->_tmp24_ = dc_rpc_installer_curl_failure_message (_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_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->stdout_buf);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp28_ = g_file_new_for_path (_data_->dest);
		_data_->_tmp29_ = _data_->_tmp28_;
		_data_->_tmp30_ = g_file_query_info (_data_->_tmp29_, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &_data_->_inner_error0_);
		_data_->_tmp31_ = _data_->_tmp30_;
		_g_object_unref0 (_data_->_tmp29_);
		_data_->info = _data_->_tmp31_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp32_ = _data_->info;
		_data_->size = g_file_info_get_size (_data_->_tmp32_);
		g_signal_emit (_data_->self, dc_rpc_installer_signals[DC_RPC_INSTALLER_PROGRESS_SIGNAL], 0, _data_->size, _data_->size);
		_g_object_unref0 (_data_->info);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
		g_signal_emit (_data_->self, dc_rpc_installer_signals[DC_RPC_INSTALLER_PROGRESS_SIGNAL], 0, (gint64) 0, (gint64) -1);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->stdout_buf);
		_g_object_unref0 (_data_->process);
		_g_free0 (_data_->stderr_buf);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->curl);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_free0 (_data_->stdout_buf);
	_g_object_unref0 (_data_->process);
	_g_free0 (_data_->stderr_buf);
	_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (_data_->curl);
	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
dc_rpc_installer_ensure_executable (const gchar* path,
                                    GError** error)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (path != NULL);
	if (g_chmod (path, 0755) != 0) {
		gchar* _tmp0_;
		gchar* _tmp1_;
		GError* _tmp2_;
		GError* _tmp3_;
		_tmp0_ = g_strdup_printf ("Could not make the server executable: %s", path);
		_tmp1_ = _tmp0_;
		_tmp2_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _tmp1_);
		_tmp3_ = _tmp2_;
		_g_free0 (_tmp1_);
		_inner_error0_ = _tmp3_;
		g_propagate_error (error, _inner_error0_);
		return;
	}
	if (!g_file_test (path, G_FILE_TEST_IS_EXECUTABLE)) {
		gchar* _tmp4_;
		gchar* _tmp5_;
		GError* _tmp6_;
		GError* _tmp7_;
		_tmp4_ = g_strdup_printf ("Installed server is not executable: %s", path);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _tmp5_);
		_tmp7_ = _tmp6_;
		_g_free0 (_tmp5_);
		_inner_error0_ = _tmp7_;
		g_propagate_error (error, _inner_error0_);
		return;
	}
}

static void
dc_rpc_installer_https_get_to_file_data_free (gpointer _data)
{
	DcRpcInstallerHttpsGetToFileData* _data_;
	_data_ = _data;
	_g_free0 (_data_->url);
	_g_free0 (_data_->dest);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcInstallerHttpsGetToFileData, _data_);
}

static void
dc_rpc_installer_https_get_to_file (DcRpcInstaller* self,
                                    const gchar* url,
                                    const gchar* dest,
                                    gint depth,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	DcRpcInstallerHttpsGetToFileData* _data_;
	DcRpcInstaller* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (url != NULL);
	g_return_if_fail (dest != NULL);
	_data_ = g_slice_new0 (DcRpcInstallerHttpsGetToFileData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_installer_https_get_to_file_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (url);
	_g_free0 (_data_->url);
	_data_->url = _tmp1_;
	_tmp2_ = g_strdup (dest);
	_g_free0 (_data_->dest);
	_data_->dest = _tmp2_;
	_data_->depth = depth;
	dc_rpc_installer_https_get_to_file_co (_data_);
}

static void
dc_rpc_installer_https_get_to_file_finish (DcRpcInstaller* self,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	DcRpcInstallerHttpsGetToFileData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

/**
         * Stream an HTTPS GET to a file, following redirects across hosts.
         */
static void
dc_rpc_installer_https_get_to_file_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	DcRpcInstallerHttpsGetToFileData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_installer_https_get_to_file_co (_data_);
}

static gint64
int64_parse (const gchar* str,
             guint _base)
{
	gint64 result;
	g_return_val_if_fail (str != NULL, -1LL);
	result = g_ascii_strtoll (str, NULL, _base);
	return result;
}

static gboolean
dc_rpc_installer_https_get_to_file_co (DcRpcInstallerHttpsGetToFileData* _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;
		case 6:
		goto _state_6;
		case 7:
		goto _state_7;
		case 8:
		goto _state_8;
		case 9:
		goto _state_9;
		case 10:
		goto _state_10;
		case 11:
		goto _state_11;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->depth > DC_RPC_INSTALLER_MAX_REDIRECTS) {
		_data_->_tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Too many HTTP redirects");
		_data_->_inner_error0_ = _data_->_tmp0_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = g_uri_parse (_data_->url, G_URI_FLAGS_ENCODED, &_data_->_inner_error0_);
	_data_->uri = _data_->_tmp1_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->uri;
	_data_->_tmp3_ = g_uri_get_host (_data_->_tmp2_);
	_data_->_tmp4_ = g_strdup (_data_->_tmp3_);
	_data_->host = _data_->_tmp4_;
	_data_->_tmp5_ = _data_->uri;
	_data_->port = g_uri_get_port (_data_->_tmp5_);
	if (_data_->port <= 0) {
		_data_->port = 443;
	}
	_data_->_tmp6_ = _data_->uri;
	_data_->_tmp7_ = g_uri_get_path (_data_->_tmp6_);
	_data_->_tmp8_ = g_strdup (_data_->_tmp7_);
	_data_->path = _data_->_tmp8_;
	_data_->_tmp9_ = _data_->path;
	_data_->_tmp10_ = strlen (_data_->_tmp9_);
	_data_->_tmp11_ = _data_->_tmp10_;
	if (_data_->_tmp11_ == 0) {
		_data_->_tmp12_ = g_strdup ("/");
		_g_free0 (_data_->path);
		_data_->path = _data_->_tmp12_;
	}
	_data_->_tmp13_ = _data_->uri;
	_data_->_tmp14_ = g_uri_get_query (_data_->_tmp13_);
	_data_->_tmp15_ = g_strdup (_data_->_tmp14_);
	_data_->query = _data_->_tmp15_;
	_data_->_tmp18_ = _data_->query;
	if (_data_->_tmp18_ != NULL) {
		_data_->_tmp19_ = _data_->query;
		_data_->_tmp20_ = strlen (_data_->_tmp19_);
		_data_->_tmp21_ = _data_->_tmp20_;
		_data_->_tmp17_ = _data_->_tmp21_ > 0;
	} else {
		_data_->_tmp17_ = FALSE;
	}
	if (_data_->_tmp17_) {
		_data_->_tmp22_ = _data_->path;
		_data_->_tmp23_ = _data_->query;
		_data_->_tmp24_ = g_strdup_printf ("%s?%s", _data_->_tmp22_, _data_->_tmp23_);
		_g_free0 (_data_->_tmp16_);
		_data_->_tmp16_ = _data_->_tmp24_;
	} else {
		_data_->_tmp25_ = _data_->path;
		_data_->_tmp26_ = g_strdup (_data_->_tmp25_);
		_g_free0 (_data_->_tmp16_);
		_data_->_tmp16_ = _data_->_tmp26_;
	}
	_data_->_tmp27_ = _data_->_tmp16_;
	_data_->_tmp16_ = NULL;
	_data_->target = _data_->_tmp27_;
	_data_->_tmp28_ = g_socket_client_new ();
	_data_->client = _data_->_tmp28_;
	_data_->_tmp29_ = _data_->client;
	g_socket_client_set_timeout (_data_->_tmp29_, (guint) 60);
	_data_->_tmp30_ = _data_->client;
	_data_->_tmp31_ = _data_->host;
	_data_->_state_ = 1;
	g_socket_client_connect_to_host_async (_data_->_tmp30_, _data_->_tmp31_, (guint16) _data_->port, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp32_ = g_socket_client_connect_to_host_finish (_data_->_tmp30_, _data_->_res_, &_data_->_inner_error0_);
	_data_->tcp = _data_->_tmp32_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp33_ = _data_->host;
	_data_->_tmp34_ = (GNetworkAddress*) g_network_address_new (_data_->_tmp33_, (guint16) _data_->port);
	_data_->identity = _data_->_tmp34_;
	_data_->_tmp35_ = _data_->tcp;
	_data_->_tmp36_ = _data_->identity;
	_data_->_tmp37_ = g_tls_client_connection_new ((GIOStream*) _data_->_tmp35_, (GSocketConnectable*) _data_->_tmp36_, &_data_->_inner_error0_);
	_data_->tls = _data_->_tmp37_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp38_ = _data_->tls;
	if (_data_->_tmp38_ == NULL) {
		_data_->_tmp39_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to create TLS connection");
		_data_->_inner_error0_ = _data_->_tmp39_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp40_ = _data_->tls;
	_data_->_state_ = 2;
	g_tls_connection_handshake_async ((GTlsConnection*) _data_->_tmp40_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
	return FALSE;
	_state_2:
	g_tls_connection_handshake_finish ((GTlsConnection*) _data_->_tmp40_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp41_ = _data_->target;
	_data_->_tmp42_ = g_strdup_printf ("GET %s HTTP/1.1\r\n", _data_->_tmp41_);
	_data_->_tmp43_ = _data_->_tmp42_;
	_data_->_tmp44_ = _data_->host;
	_data_->_tmp45_ = g_strdup_printf ("Host: %s\r\n", _data_->_tmp44_);
	_data_->_tmp46_ = _data_->_tmp45_;
	_data_->_tmp47_ = g_strconcat (_data_->_tmp43_, _data_->_tmp46_, NULL);
	_data_->_tmp48_ = _data_->_tmp47_;
	_data_->_tmp49_ = g_strconcat (_data_->_tmp48_, "User-Agent: Parla\r\n", NULL);
	_data_->_tmp50_ = _data_->_tmp49_;
	_data_->_tmp51_ = g_strconcat (_data_->_tmp50_, "Accept: */*\r\n", NULL);
	_data_->_tmp52_ = _data_->_tmp51_;
	_data_->_tmp53_ = g_strconcat (_data_->_tmp52_, "Connection: close\r\n\r\n", NULL);
	_data_->_tmp54_ = _data_->_tmp53_;
	_g_free0 (_data_->_tmp52_);
	_g_free0 (_data_->_tmp50_);
	_g_free0 (_data_->_tmp48_);
	_g_free0 (_data_->_tmp46_);
	_g_free0 (_data_->_tmp43_);
	_data_->request = _data_->_tmp54_;
	_data_->_tmp55_ = _data_->tls;
	_data_->_tmp56_ = g_io_stream_get_output_stream ((GIOStream*) _data_->_tmp55_);
	_data_->_tmp57_ = _data_->_tmp56_;
	_data_->_tmp58_ = _data_->request;
	_data_->_tmp60_ = 0;
	_data_->_tmp59_ = string_get_data (_data_->_tmp58_, &_data_->_tmp60_);
	_data_->_tmp59__length1 = _data_->_tmp60_;
	_data_->_tmp61_ = _data_->_tmp59_;
	_data_->_tmp61__length1 = _data_->_tmp59__length1;
	_data_->_tmp62_ = 0UL;
	_data_->_state_ = 3;
	g_output_stream_write_all_async (_data_->_tmp57_, _data_->_tmp61_, (gsize) _data_->_tmp61__length1, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
	return FALSE;
	_state_3:
	g_output_stream_write_all_finish (_data_->_tmp57_, _data_->_res_, &_data_->_tmp62_, &_data_->_inner_error0_);
	_data_->written = _data_->_tmp62_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp63_ = _data_->tls;
	_data_->_tmp64_ = g_io_stream_get_input_stream ((GIOStream*) _data_->_tmp63_);
	_data_->_tmp65_ = _data_->_tmp64_;
	_data_->_tmp66_ = g_data_input_stream_new (_data_->_tmp65_);
	_data_->reader = _data_->_tmp66_;
	_data_->_tmp67_ = _data_->reader;
	g_data_input_stream_set_newline_type (_data_->_tmp67_, G_DATA_STREAM_NEWLINE_TYPE_LF);
	_data_->_tmp68_ = _data_->reader;
	g_buffered_input_stream_set_buffer_size ((GBufferedInputStream*) _data_->_tmp68_, (gsize) 65536);
	_data_->_tmp69_ = _data_->reader;
	_data_->_tmp70_ = 0UL;
	_data_->_state_ = 4;
	g_data_input_stream_read_line_async (_data_->_tmp69_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
	return FALSE;
	_state_4:
	_data_->_tmp71_ = g_data_input_stream_read_line_finish_utf8 (_data_->_tmp69_, _data_->_res_, &_data_->_tmp70_, &_data_->_inner_error0_);
	_data_->len = _data_->_tmp70_;
	_data_->status_line = _data_->_tmp71_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp73_ = _data_->status_line;
	_data_->_tmp72_ = _data_->_tmp73_;
	if (_data_->_tmp72_ == NULL) {
		_data_->_tmp72_ = "";
	}
	_data_->status = dc_rpc_installer_parse_http_status (_data_->_tmp72_);
	_data_->location = NULL;
	_data_->content_length = (gint64) -1;
	while (TRUE) {
		_data_->_tmp75_ = _data_->reader;
		_data_->_tmp76_ = 0UL;
		_data_->_state_ = 5;
		g_data_input_stream_read_line_async (_data_->_tmp75_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
		return FALSE;
		_state_5:
		_data_->_tmp77_ = g_data_input_stream_read_line_finish_utf8 (_data_->_tmp75_, _data_->_res_, &_data_->_tmp76_, &_data_->_inner_error0_);
		_data_->len = _data_->_tmp76_;
		_data_->_tmp74_ = _data_->_tmp77_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			_g_free0 (_data_->target);
			_g_free0 (_data_->_tmp16_);
			_g_free0 (_data_->query);
			_g_free0 (_data_->path);
			_g_free0 (_data_->host);
			_g_uri_unref0 (_data_->uri);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp78_ = _data_->_tmp74_;
		_data_->_tmp74_ = NULL;
		_g_free0 (_data_->line);
		_data_->line = _data_->_tmp78_;
		_data_->_tmp79_ = _data_->line;
		if (!(_data_->_tmp79_ != NULL)) {
			_g_free0 (_data_->_tmp74_);
			break;
		}
		_data_->_tmp80_ = _data_->line;
		_data_->_tmp81_ = string_strip (_data_->_tmp80_);
		_data_->stripped = _data_->_tmp81_;
		_data_->_tmp82_ = _data_->stripped;
		_data_->_tmp83_ = strlen (_data_->_tmp82_);
		_data_->_tmp84_ = _data_->_tmp83_;
		if (_data_->_tmp84_ == 0) {
			_g_free0 (_data_->stripped);
			_g_free0 (_data_->_tmp74_);
			break;
		}
		_data_->_tmp85_ = _data_->stripped;
		_data_->_tmp86_ = g_utf8_strdown (_data_->_tmp85_, (gssize) -1);
		_data_->lower = _data_->_tmp86_;
		_data_->_tmp87_ = _data_->lower;
		if (g_str_has_prefix (_data_->_tmp87_, "location:")) {
			_data_->_tmp88_ = _data_->stripped;
			_data_->_tmp89_ = strlen ("location:");
			_data_->_tmp90_ = _data_->_tmp89_;
			_data_->_tmp91_ = string_substring (_data_->_tmp88_, (glong) _data_->_tmp90_, (glong) -1);
			_data_->_tmp92_ = _data_->_tmp91_;
			_data_->_tmp93_ = string_strip (_data_->_tmp92_);
			_g_free0 (_data_->location);
			_data_->location = _data_->_tmp93_;
			_g_free0 (_data_->_tmp92_);
		} else {
			_data_->_tmp94_ = _data_->lower;
			if (g_str_has_prefix (_data_->_tmp94_, "content-length:")) {
				_data_->_tmp95_ = _data_->stripped;
				_data_->_tmp96_ = strlen ("content-length:");
				_data_->_tmp97_ = _data_->_tmp96_;
				_data_->_tmp98_ = string_substring (_data_->_tmp95_, (glong) _data_->_tmp97_, (glong) -1);
				_data_->_tmp99_ = _data_->_tmp98_;
				_data_->_tmp100_ = string_strip (_data_->_tmp99_);
				_data_->_tmp101_ = _data_->_tmp100_;
				_data_->content_length = int64_parse (_data_->_tmp101_, (guint) 0);
				_g_free0 (_data_->_tmp101_);
				_g_free0 (_data_->_tmp99_);
			}
		}
		_g_free0 (_data_->lower);
		_g_free0 (_data_->stripped);
		_g_free0 (_data_->_tmp74_);
	}
	if (_data_->status >= 300) {
		_data_->_tmp102_ = _data_->status < 400;
	} else {
		_data_->_tmp102_ = FALSE;
	}
	if (_data_->_tmp102_) {
		{
			_data_->_tmp103_ = _data_->tls;
			_data_->_state_ = 6;
			g_io_stream_close_async ((GIOStream*) _data_->_tmp103_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
			return FALSE;
			_state_6:
			g_io_stream_close_finish ((GIOStream*) _data_->_tmp103_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			g_clear_error (&_data_->_inner_error0_);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			_g_free0 (_data_->target);
			_g_free0 (_data_->_tmp16_);
			_g_free0 (_data_->query);
			_g_free0 (_data_->path);
			_g_free0 (_data_->host);
			_g_uri_unref0 (_data_->uri);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp104_ = _data_->location;
		if (_data_->_tmp104_ == NULL) {
			_data_->_tmp105_ = g_strdup_printf ("Redirect (%d) without a Location header", _data_->status);
			_data_->_tmp106_ = _data_->_tmp105_;
			_data_->_tmp107_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp106_);
			_data_->_tmp108_ = _data_->_tmp107_;
			_g_free0 (_data_->_tmp106_);
			_data_->_inner_error0_ = _data_->_tmp108_;
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			_g_free0 (_data_->target);
			_g_free0 (_data_->_tmp16_);
			_g_free0 (_data_->query);
			_g_free0 (_data_->path);
			_g_free0 (_data_->host);
			_g_uri_unref0 (_data_->uri);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp109_ = _data_->location;
		_data_->_state_ = 7;
		dc_rpc_installer_https_get_to_file (_data_->self, _data_->_tmp109_, _data_->dest, _data_->depth + 1, dc_rpc_installer_https_get_to_file_ready, _data_);
		return FALSE;
		_state_7:
		dc_rpc_installer_https_get_to_file_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			_g_free0 (_data_->target);
			_g_free0 (_data_->_tmp16_);
			_g_free0 (_data_->query);
			_g_free0 (_data_->path);
			_g_free0 (_data_->host);
			_g_uri_unref0 (_data_->uri);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		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;
	}
	if (_data_->status < 200) {
		_data_->_tmp110_ = TRUE;
	} else {
		_data_->_tmp110_ = _data_->status >= 300;
	}
	if (_data_->_tmp110_) {
		{
			_data_->_tmp111_ = _data_->tls;
			_data_->_state_ = 8;
			g_io_stream_close_async ((GIOStream*) _data_->_tmp111_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
			return FALSE;
			_state_8:
			g_io_stream_close_finish ((GIOStream*) _data_->_tmp111_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
		}
		goto __finally1;
		__catch1_g_error:
		{
			g_clear_error (&_data_->_inner_error0_);
		}
		__finally1:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			_g_free0 (_data_->target);
			_g_free0 (_data_->_tmp16_);
			_g_free0 (_data_->query);
			_g_free0 (_data_->path);
			_g_free0 (_data_->host);
			_g_uri_unref0 (_data_->uri);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp112_ = g_strdup_printf ("Download failed with HTTP status %d", _data_->status);
		_data_->_tmp113_ = _data_->_tmp112_;
		_data_->_tmp114_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _data_->_tmp113_);
		_data_->_tmp115_ = _data_->_tmp114_;
		_g_free0 (_data_->_tmp113_);
		_data_->_inner_error0_ = _data_->_tmp115_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp116_ = g_file_new_for_path (_data_->dest);
	_data_->_tmp117_ = _data_->_tmp116_;
	_data_->_tmp118_ = g_file_replace (_data_->_tmp117_, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &_data_->_inner_error0_);
	_data_->_tmp119_ = _data_->_tmp118_;
	_g_object_unref0 (_data_->_tmp117_);
	_data_->fos = _data_->_tmp119_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp120_ = g_new0 (guint8, 65536);
	_data_->buf = _data_->_tmp120_;
	_data_->buf_length1 = 65536;
	_data_->_buf_size_ = _data_->buf_length1;
	_data_->received = (gint64) 0;
	g_signal_emit (_data_->self, dc_rpc_installer_signals[DC_RPC_INSTALLER_PROGRESS_SIGNAL], 0, (gint64) 0, _data_->content_length);
	while (TRUE) {
		_data_->_tmp121_ = _data_->reader;
		_data_->_tmp122_ = _data_->buf;
		_data_->_tmp122__length1 = _data_->buf_length1;
		_data_->_state_ = 9;
		g_input_stream_read_async ((GInputStream*) _data_->_tmp121_, _data_->_tmp122_, (gsize) _data_->_tmp122__length1, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
		return FALSE;
		_state_9:
		_data_->n = g_input_stream_read_finish ((GInputStream*) _data_->_tmp121_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_data_->buf = (g_free (_data_->buf), NULL);
			_g_object_unref0 (_data_->fos);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			_g_free0 (_data_->target);
			_g_free0 (_data_->_tmp16_);
			_g_free0 (_data_->query);
			_g_free0 (_data_->path);
			_g_free0 (_data_->host);
			_g_uri_unref0 (_data_->uri);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		if (_data_->n <= ((gssize) 0)) {
			break;
		}
		_data_->_tmp123_ = _data_->fos;
		_data_->_tmp124_ = _data_->buf;
		_data_->_tmp124__length1 = _data_->buf_length1;
		_data_->_tmp125_ = 0UL;
		g_output_stream_write_all ((GOutputStream*) _data_->_tmp123_, _data_->_tmp124_ + 0, (gsize) (((gint) _data_->n) - 0), &_data_->_tmp125_, NULL, &_data_->_inner_error0_);
		_data_->bw = _data_->_tmp125_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_data_->buf = (g_free (_data_->buf), NULL);
			_g_object_unref0 (_data_->fos);
			_g_free0 (_data_->line);
			_g_free0 (_data_->location);
			_g_free0 (_data_->status_line);
			_g_object_unref0 (_data_->reader);
			_g_free0 (_data_->request);
			_g_object_unref0 (_data_->tls);
			_g_object_unref0 (_data_->identity);
			_g_object_unref0 (_data_->tcp);
			_g_object_unref0 (_data_->client);
			_g_free0 (_data_->target);
			_g_free0 (_data_->_tmp16_);
			_g_free0 (_data_->query);
			_g_free0 (_data_->path);
			_g_free0 (_data_->host);
			_g_uri_unref0 (_data_->uri);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->received += (gint64) _data_->n;
		g_signal_emit (_data_->self, dc_rpc_installer_signals[DC_RPC_INSTALLER_PROGRESS_SIGNAL], 0, _data_->received, _data_->content_length);
	}
	_data_->_tmp126_ = _data_->fos;
	_data_->_state_ = 10;
	g_output_stream_close_async ((GOutputStream*) _data_->_tmp126_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
	return FALSE;
	_state_10:
	g_output_stream_close_finish ((GOutputStream*) _data_->_tmp126_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_data_->buf = (g_free (_data_->buf), NULL);
		_g_object_unref0 (_data_->fos);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp127_ = _data_->tls;
		_data_->_state_ = 11;
		g_io_stream_close_async ((GIOStream*) _data_->_tmp127_, G_PRIORITY_DEFAULT, NULL, dc_rpc_installer_https_get_to_file_ready, _data_);
		return FALSE;
		_state_11:
		g_io_stream_close_finish ((GIOStream*) _data_->_tmp127_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch2_g_error;
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally2:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_data_->buf = (g_free (_data_->buf), NULL);
		_g_object_unref0 (_data_->fos);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->content_length > ((gint64) 0)) {
		_data_->_tmp128_ = _data_->received < _data_->content_length;
	} else {
		_data_->_tmp128_ = FALSE;
	}
	if (_data_->_tmp128_) {
		_data_->_tmp129_ = g_strdup_printf ("%" G_GINT64_FORMAT, _data_->received);
		_data_->_tmp130_ = _data_->_tmp129_;
		_data_->_tmp131_ = g_strdup_printf ("%" G_GINT64_FORMAT, _data_->content_length);
		_data_->_tmp132_ = _data_->_tmp131_;
		_data_->_tmp133_ = g_strdup_printf ("Download truncated (%s of %s bytes)", _data_->_tmp130_, _data_->_tmp132_);
		_data_->_tmp134_ = _data_->_tmp133_;
		_data_->_tmp135_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT, _data_->_tmp134_);
		_data_->_tmp136_ = _data_->_tmp135_;
		_g_free0 (_data_->_tmp134_);
		_g_free0 (_data_->_tmp132_);
		_g_free0 (_data_->_tmp130_);
		_data_->_inner_error0_ = _data_->_tmp136_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_data_->buf = (g_free (_data_->buf), NULL);
		_g_object_unref0 (_data_->fos);
		_g_free0 (_data_->line);
		_g_free0 (_data_->location);
		_g_free0 (_data_->status_line);
		_g_object_unref0 (_data_->reader);
		_g_free0 (_data_->request);
		_g_object_unref0 (_data_->tls);
		_g_object_unref0 (_data_->identity);
		_g_object_unref0 (_data_->tcp);
		_g_object_unref0 (_data_->client);
		_g_free0 (_data_->target);
		_g_free0 (_data_->_tmp16_);
		_g_free0 (_data_->query);
		_g_free0 (_data_->path);
		_g_free0 (_data_->host);
		_g_uri_unref0 (_data_->uri);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->buf = (g_free (_data_->buf), NULL);
	_g_object_unref0 (_data_->fos);
	_g_free0 (_data_->line);
	_g_free0 (_data_->location);
	_g_free0 (_data_->status_line);
	_g_object_unref0 (_data_->reader);
	_g_free0 (_data_->request);
	_g_object_unref0 (_data_->tls);
	_g_object_unref0 (_data_->identity);
	_g_object_unref0 (_data_->tcp);
	_g_object_unref0 (_data_->client);
	_g_free0 (_data_->target);
	_g_free0 (_data_->_tmp16_);
	_g_free0 (_data_->query);
	_g_free0 (_data_->path);
	_g_free0 (_data_->host);
	_g_uri_unref0 (_data_->uri);
	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 gint
dc_rpc_installer_parse_http_status (const gchar* status_line)
{
	gchar** parts = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gint parts_length1;
	gint _parts_size_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar** _tmp3_;
	gint _tmp3__length1;
	const gchar* _tmp4_;
	gint result;
	g_return_val_if_fail (status_line != NULL, -1);
	_tmp1_ = _tmp0_ = g_strsplit (status_line, " ", 0);
	parts = _tmp1_;
	parts_length1 = _vala_array_length (_tmp0_);
	_parts_size_ = parts_length1;
	_tmp2_ = parts;
	_tmp2__length1 = parts_length1;
	if (_tmp2__length1 < 2) {
		result = 0;
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		return result;
	}
	_tmp3_ = parts;
	_tmp3__length1 = parts_length1;
	_tmp4_ = _tmp3_[1];
	result = atoi (_tmp4_);
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

/** Extract a dotted numeric version (e.g. "2.51.0") from arbitrary text. */
static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

gchar*
dc_rpc_installer_extract_version (const gchar* text)
{
	gint start = 0;
	gint end = 0;
	gboolean _tmp7_ = FALSE;
	gchar* version = NULL;
	gchar* _tmp8_;
	const gchar* _tmp15_ = NULL;
	const gchar* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	gchar* _tmp20_;
	gchar* result;
	g_return_val_if_fail (text != NULL, NULL);
	start = -1;
	end = -1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				gint _tmp2_;
				gint _tmp3_;
				gchar c = '\0';
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = strlen (text);
				_tmp3_ = _tmp2_;
				if (!(i < _tmp3_)) {
					break;
				}
				c = string_get (text, (glong) i);
				if (start < 0) {
					gboolean _tmp4_ = FALSE;
					if (c >= '0') {
						_tmp4_ = c <= '9';
					} else {
						_tmp4_ = FALSE;
					}
					if (_tmp4_) {
						start = i;
						end = i + 1;
					}
				} else {
					gboolean _tmp5_ = FALSE;
					gboolean _tmp6_ = FALSE;
					if (c >= '0') {
						_tmp6_ = c <= '9';
					} else {
						_tmp6_ = FALSE;
					}
					if (_tmp6_) {
						_tmp5_ = TRUE;
					} else {
						_tmp5_ = c == '.';
					}
					if (_tmp5_) {
						end = i + 1;
					} else {
						break;
					}
				}
			}
		}
	}
	if (start < 0) {
		_tmp7_ = TRUE;
	} else {
		_tmp7_ = end <= start;
	}
	if (_tmp7_) {
		result = NULL;
		return result;
	}
	_tmp8_ = string_substring (text, (glong) start, (glong) (end - start));
	version = _tmp8_;
	while (TRUE) {
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gchar* _tmp14_;
		_tmp9_ = version;
		if (!g_str_has_suffix (_tmp9_, ".")) {
			break;
		}
		_tmp10_ = version;
		_tmp11_ = version;
		_tmp12_ = strlen (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = string_substring (_tmp10_, (glong) 0, (glong) (_tmp13_ - 1));
		_g_free0 (version);
		version = _tmp14_;
	}
	_tmp16_ = version;
	_tmp17_ = strlen (_tmp16_);
	_tmp18_ = _tmp17_;
	if (_tmp18_ > 0) {
		const gchar* _tmp19_;
		_tmp19_ = version;
		_tmp15_ = _tmp19_;
	} else {
		_tmp15_ = NULL;
	}
	_tmp20_ = g_strdup (_tmp15_);
	result = _tmp20_;
	_g_free0 (version);
	return result;
}

static gint
string_last_index_of (const gchar* self,
                      const gchar* needle,
                      gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = g_strrstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gchar*
dc_rpc_installer_extract_release_tag (const gchar* location)
{
	gint idx = 0;
	gchar* tag = NULL;
	gint _tmp0_;
	gint _tmp1_;
	gchar* _tmp2_;
	gint q = 0;
	const gchar* _tmp3_;
	gint hash = 0;
	const gchar* _tmp6_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_ = NULL;
	const gchar* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	gchar* _tmp16_;
	gchar* result;
	g_return_val_if_fail (location != NULL, NULL);
	idx = string_last_index_of (location, "/tag/", 0);
	if (idx < 0) {
		result = NULL;
		return result;
	}
	_tmp0_ = strlen ("/tag/");
	_tmp1_ = _tmp0_;
	_tmp2_ = string_substring (location, (glong) (idx + _tmp1_), (glong) -1);
	tag = _tmp2_;
	_tmp3_ = tag;
	q = string_index_of (_tmp3_, "?", 0);
	if (q >= 0) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = tag;
		_tmp5_ = string_substring (_tmp4_, (glong) 0, (glong) q);
		_g_free0 (tag);
		tag = _tmp5_;
	}
	_tmp6_ = tag;
	hash = string_index_of (_tmp6_, "#", 0);
	if (hash >= 0) {
		const gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp7_ = tag;
		_tmp8_ = string_substring (_tmp7_, (glong) 0, (glong) hash);
		_g_free0 (tag);
		tag = _tmp8_;
	}
	_tmp9_ = tag;
	_tmp10_ = string_strip (_tmp9_);
	_g_free0 (tag);
	tag = _tmp10_;
	_tmp12_ = tag;
	_tmp13_ = strlen (_tmp12_);
	_tmp14_ = _tmp13_;
	if (_tmp14_ > 0) {
		const gchar* _tmp15_;
		_tmp15_ = tag;
		_tmp11_ = _tmp15_;
	} else {
		_tmp11_ = NULL;
	}
	_tmp16_ = g_strdup (_tmp11_);
	result = _tmp16_;
	_g_free0 (tag);
	return result;
}

DcRpcInstaller*
dc_rpc_installer_construct (GType object_type)
{
	DcRpcInstaller * self = NULL;
	self = (DcRpcInstaller*) g_object_new (object_type, NULL);
	return self;
}

DcRpcInstaller*
dc_rpc_installer_new (void)
{
	return dc_rpc_installer_construct (DC_TYPE_RPC_INSTALLER);
}

static void
g_cclosure_user_marshal_VOID__INT64_INT64 (GClosure * closure,
                                           GValue * return_value,
                                           guint n_param_values,
                                           const GValue * param_values,
                                           gpointer invocation_hint,
                                           gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT64_INT64) (gpointer data1, gint64 arg_1, gint64 arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT64_INT64 callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	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__INT64_INT64) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int64 (param_values + 1), g_value_get_int64 (param_values + 2), data2);
}

static void
dc_rpc_installer_class_init (DcRpcInstallerClass * klass,
                             gpointer klass_data)
{
	dc_rpc_installer_parent_class = g_type_class_peek_parent (klass);
	/** Emitted while downloading. `total` is -1 when the size is unknown. */
	dc_rpc_installer_signals[DC_RPC_INSTALLER_PROGRESS_SIGNAL] = g_signal_new ("progress", DC_TYPE_RPC_INSTALLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT64_INT64, G_TYPE_NONE, 2, G_TYPE_INT64, G_TYPE_INT64);
}

static void
dc_rpc_installer_instance_init (DcRpcInstaller * self,
                                gpointer klass)
{
}

/**
     * Downloads and installs a Parla-owned `deltachat-rpc-server` binary into
     * Parla's private data directory (~/.local/share/parla/bin). This is a
     * last-resort fallback for source/unpackaged installs: distro, Flatpak and
     * system binaries always take precedence (see AccountFinder). The managed
     * binary is fetched from the upstream chatmail/core GitHub releases.
     *
     * The HTTP/TLS plumbing is intentionally dependency-free (GIO sockets +
     * TlsClientConnection) to keep Parla self-contained.
     */
static GType
dc_rpc_installer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcRpcInstallerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_rpc_installer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcRpcInstaller), 0, (GInstanceInitFunc) dc_rpc_installer_instance_init, NULL };
	GType dc_rpc_installer_type_id;
	dc_rpc_installer_type_id = g_type_register_static (G_TYPE_OBJECT, "DcRpcInstaller", &g_define_type_info, 0);
	return dc_rpc_installer_type_id;
}

GType
dc_rpc_installer_get_type (void)
{
	static volatile gsize dc_rpc_installer_type_id__once = 0;
	if (g_once_init_enter (&dc_rpc_installer_type_id__once)) {
		GType dc_rpc_installer_type_id;
		dc_rpc_installer_type_id = dc_rpc_installer_get_type_once ();
		g_once_init_leave (&dc_rpc_installer_type_id__once, dc_rpc_installer_type_id);
	}
	return dc_rpc_installer_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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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

