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

#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib/gstdio.h>
#include <gobject/gvaluecollector.h>

#define DC_LINK_PREVIEW_MAX_HTML_BYTES (1024 * 1024)
#define DC_LINK_PREVIEW_MAX_IMAGE_BYTES ((gint64) ((8 * 1024) * 1024))
#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_LINK_PREVIEW_FETCHER (dc_link_preview_fetcher_get_type ())
#define DC_LINK_PREVIEW_FETCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_LINK_PREVIEW_FETCHER, DcLinkPreviewFetcher))
#define DC_LINK_PREVIEW_FETCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_LINK_PREVIEW_FETCHER, DcLinkPreviewFetcherClass))
#define DC_IS_LINK_PREVIEW_FETCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_LINK_PREVIEW_FETCHER))
#define DC_IS_LINK_PREVIEW_FETCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_LINK_PREVIEW_FETCHER))
#define DC_LINK_PREVIEW_FETCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_LINK_PREVIEW_FETCHER, DcLinkPreviewFetcherClass))

typedef struct _DcLinkPreviewFetcher DcLinkPreviewFetcher;
typedef struct _DcLinkPreviewFetcherClass DcLinkPreviewFetcherClass;
typedef struct _DcLinkPreviewFetcherPrivate DcLinkPreviewFetcherPrivate;

#define DC_TYPE_RPC_CLIENT (dc_rpc_client_get_type ())
#define DC_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_RPC_CLIENT, DcRpcClient))
#define DC_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_RPC_CLIENT, DcRpcClientClass))
#define DC_IS_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_RPC_CLIENT))
#define DC_IS_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_RPC_CLIENT))
#define DC_RPC_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_RPC_CLIENT, DcRpcClientClass))

typedef struct _DcRpcClient DcRpcClient;
typedef struct _DcRpcClientClass DcRpcClientClass;
enum  {
	DC_LINK_PREVIEW_FETCHER_0_PROPERTY,
	DC_LINK_PREVIEW_FETCHER_NUM_PROPERTIES
};
static GParamSpec* dc_link_preview_fetcher_properties[DC_LINK_PREVIEW_FETCHER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _dc_link_preview_fetcher_result_unref0(var) ((var == NULL) ? NULL : (var = (dc_link_preview_fetcher_result_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define DC_LINK_PREVIEW_FETCHER_TYPE_RESULT (dc_link_preview_fetcher_result_get_type ())
#define DC_LINK_PREVIEW_FETCHER_RESULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_LINK_PREVIEW_FETCHER_TYPE_RESULT, DcLinkPreviewFetcherResult))
#define DC_LINK_PREVIEW_FETCHER_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_LINK_PREVIEW_FETCHER_TYPE_RESULT, DcLinkPreviewFetcherResultClass))
#define DC_LINK_PREVIEW_FETCHER_IS_RESULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_LINK_PREVIEW_FETCHER_TYPE_RESULT))
#define DC_LINK_PREVIEW_FETCHER_IS_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_LINK_PREVIEW_FETCHER_TYPE_RESULT))
#define DC_LINK_PREVIEW_FETCHER_RESULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_LINK_PREVIEW_FETCHER_TYPE_RESULT, DcLinkPreviewFetcherResultClass))

typedef struct _DcLinkPreviewFetcherResult DcLinkPreviewFetcherResult;
typedef struct _DcLinkPreviewFetcherResultClass DcLinkPreviewFetcherResultClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define DC_LINK_PREVIEW_TYPE_METADATA (dc_link_preview_metadata_get_type ())
#define DC_LINK_PREVIEW_METADATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_LINK_PREVIEW_TYPE_METADATA, DcLinkPreviewMetadata))
#define DC_LINK_PREVIEW_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_LINK_PREVIEW_TYPE_METADATA, DcLinkPreviewMetadataClass))
#define DC_LINK_PREVIEW_IS_METADATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_LINK_PREVIEW_TYPE_METADATA))
#define DC_LINK_PREVIEW_IS_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_LINK_PREVIEW_TYPE_METADATA))
#define DC_LINK_PREVIEW_METADATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_LINK_PREVIEW_TYPE_METADATA, DcLinkPreviewMetadataClass))

typedef struct _DcLinkPreviewMetadata DcLinkPreviewMetadata;
typedef struct _DcLinkPreviewMetadataClass DcLinkPreviewMetadataClass;
#define _dc_link_preview_metadata_unref0(var) ((var == NULL) ? NULL : (var = (dc_link_preview_metadata_unref (var), NULL)))
typedef struct _DcLinkPreviewMetadataPrivate DcLinkPreviewMetadataPrivate;
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
typedef struct _DcLinkPreviewFetcherResultPrivate DcLinkPreviewFetcherResultPrivate;
typedef struct _DcLinkPreviewFetcherFetchData DcLinkPreviewFetcherFetchData;
#define _g_uri_unref0(var) ((var == NULL) ? NULL : (var = (g_uri_unref (var), NULL)))
typedef struct _DcLinkPreviewFetcherParamSpecResult DcLinkPreviewFetcherParamSpecResult;

struct _DcLinkPreviewFetcher {
	GObject parent_instance;
	DcLinkPreviewFetcherPrivate * priv;
};

struct _DcLinkPreviewFetcherClass {
	GObjectClass parent_class;
};

struct _DcLinkPreviewFetcherPrivate {
	DcRpcClient* rpc;
};

struct _DcLinkPreviewMetadata {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcLinkPreviewMetadataPrivate * priv;
	gchar* title;
	gchar* description;
	gchar* image_url;
};

struct _DcLinkPreviewMetadataClass {
	GTypeClass parent_class;
	void (*finalize) (DcLinkPreviewMetadata *self);
};

struct _DcLinkPreviewFetcherResult {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcLinkPreviewFetcherResultPrivate * priv;
	gchar* url;
	gchar* image_path;
	gchar* file_name;
	gchar* title;
	gchar* description;
};

struct _DcLinkPreviewFetcherResultClass {
	GTypeClass parent_class;
	void (*finalize) (DcLinkPreviewFetcherResult *self);
};

struct _DcLinkPreviewFetcherFetchData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcLinkPreviewFetcher* self;
	gchar* url;
	gboolean clean_image_urls;
	DcLinkPreviewFetcherResult* result;
	gboolean _tmp0_;
	gchar* mimetype;
	guint8* body;
	gint body_length1;
	gint _body_size_;
	guint8* _tmp1_;
	DcRpcClient* _tmp2_;
	gchar* _tmp3_;
	gint _tmp4_;
	guint8* _tmp5_;
	gint _tmp1__length1;
	gint __tmp1__size_;
	guint8* _tmp6_;
	gint _tmp6__length1;
	GError* e;
	GError* _tmp7_;
	const gchar* _tmp8_;
	DcLinkPreviewMetadata* meta;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* mt;
	gchar* _tmp11_;
	const gchar* _tmp12_;
	DcLinkPreviewMetadata* _tmp13_;
	DcLinkPreviewMetadata* _tmp14_;
	gchar* _tmp15_;
	gboolean _tmp16_;
	gboolean _tmp17_;
	const gchar* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	gint len;
	guint8* _tmp23_;
	gint _tmp23__length1;
	GString* sb;
	GString* _tmp24_;
	GString* _tmp25_;
	guint8* _tmp26_;
	gint _tmp26__length1;
	GString* _tmp27_;
	const gchar* _tmp28_;
	DcLinkPreviewMetadata* _tmp29_;
	gboolean _tmp30_;
	DcLinkPreviewMetadata* _tmp31_;
	DcLinkPreviewMetadata* _tmp32_;
	const gchar* _tmp33_;
	gchar* image_url;
	DcLinkPreviewMetadata* _tmp34_;
	const gchar* _tmp35_;
	gchar* _tmp36_;
	guint8* image;
	guint8* _tmp37_;
	gint image_length1;
	gint _image_size_;
	gchar* image_mime;
	gchar* fetched_from;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	gboolean ok;
	gchar* first;
	const gchar* _tmp40_;
	gchar* _tmp41_;
	gchar** _tmp42_;
	gint _tmp42__length1;
	gint __tmp42__size_;
	const gchar* _tmp43_;
	const gchar* _tmp44_;
	const gchar* _tmp45_;
	gchar* _tmp46_;
	gchar** _tmp47_;
	const gchar* _tmp48_;
	gchar* _tmp49_;
	const gchar* _tmp50_;
	gchar* _tmp51_;
	gchar** _tmp52_;
	gchar** candidates;
	gchar** _tmp53_;
	gint _tmp53__length1;
	gint candidates_length1;
	gint _candidates_size_;
	gchar** _tmp54_;
	gint _tmp54__length1;
	gchar** candidate_collection;
	gint candidate_collection_length1;
	gint _candidate_collection_size_;
	gint candidate_it;
	gchar* _tmp55_;
	gchar* candidate;
	gboolean _tmp56_;
	const gchar* _tmp57_;
	const gchar* _tmp58_;
	guint8* _tmp59_;
	gint _tmp59__length1;
	guint8* _tmp60_;
	gint _tmp60__length1;
	const gchar* _tmp61_;
	gchar* _tmp62_;
	guint8* _tmp63_;
	DcRpcClient* _tmp64_;
	const gchar* _tmp65_;
	gchar* _tmp66_;
	gint _tmp67_;
	guint8* _tmp68_;
	gint _tmp63__length1;
	gint __tmp63__size_;
	guint8* _tmp69_;
	gint _tmp69__length1;
	gboolean _tmp70_;
	guint8* _tmp71_;
	gint _tmp71__length1;
	guint8* _tmp72_;
	gint _tmp72__length1;
	const gchar* _tmp73_;
	gchar* _tmp74_;
	GError* _vala1_e;
	const gchar* _tmp75_;
	GError* _tmp76_;
	const gchar* _tmp77_;
	gchar* ext;
	const gchar* _tmp78_;
	const gchar* _tmp79_;
	gchar* _tmp80_;
	const gchar* _tmp81_;
	gchar* path;
	GFileIOStream* stream;
	GFile* tmp;
	const gchar* _tmp82_;
	gchar* _tmp83_;
	gchar* _tmp84_;
	GFileIOStream* _tmp85_;
	GFile* _tmp86_;
	GFile* _tmp87_;
	GFile* _tmp88_;
	gchar* _tmp89_;
	gsize written;
	GFileIOStream* _tmp90_;
	GOutputStream* _tmp91_;
	GOutputStream* _tmp92_;
	guint8* _tmp93_;
	gint _tmp93__length1;
	gsize _tmp94_;
	GFileIOStream* _tmp95_;
	GdkPixbuf* pixbuf;
	const gchar* _tmp96_;
	GdkPixbuf* _tmp97_;
	gboolean _tmp98_;
	GdkPixbuf* _tmp99_;
	gint _tmp100_;
	gint _tmp101_;
	GdkPixbuf* _tmp102_;
	gint _tmp103_;
	gint _tmp104_;
	GError* _tmp105_;
	GError* _vala2_e;
	GError* _tmp106_;
	const gchar* _tmp107_;
	const gchar* _tmp108_;
	const gchar* _tmp109_;
	DcLinkPreviewFetcherResult* r;
	DcLinkPreviewFetcherResult* _tmp110_;
	DcLinkPreviewFetcherResult* _tmp111_;
	gchar* _tmp112_;
	DcLinkPreviewFetcherResult* _tmp113_;
	const gchar* _tmp114_;
	gchar* _tmp115_;
	const gchar* _tmp116_;
	const gchar* _tmp117_;
	const gchar* _tmp118_;
	DcLinkPreviewFetcherResult* _tmp119_;
	gchar* _tmp120_;
	gchar* _tmp121_;
	gchar* _tmp122_;
	DcLinkPreviewFetcherResult* _tmp123_;
	DcLinkPreviewMetadata* _tmp124_;
	const gchar* _tmp125_;
	gchar* _tmp126_;
	DcLinkPreviewFetcherResult* _tmp127_;
	DcLinkPreviewMetadata* _tmp128_;
	const gchar* _tmp129_;
	gchar* _tmp130_;
	GError* _inner_error0_;
};

struct _DcLinkPreviewFetcherParamSpecResult {
	GParamSpec parent_instance;
};

static gint DcLinkPreviewFetcher_private_offset;
static gpointer dc_link_preview_fetcher_parent_class = NULL;
static gpointer dc_link_preview_fetcher_result_parent_class = NULL;

VALA_EXTERN GType dc_link_preview_fetcher_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcLinkPreviewFetcher, g_object_unref)
VALA_EXTERN GType dc_rpc_client_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRpcClient, g_object_unref)
VALA_EXTERN DcLinkPreviewFetcher* dc_link_preview_fetcher_new (DcRpcClient* rpc);
VALA_EXTERN DcLinkPreviewFetcher* dc_link_preview_fetcher_construct (GType object_type,
                                                         DcRpcClient* rpc);
static void dc_link_preview_fetcher_fetch_data_free (gpointer _data);
VALA_EXTERN gpointer dc_link_preview_fetcher_result_ref (gpointer instance);
VALA_EXTERN void dc_link_preview_fetcher_result_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_link_preview_fetcher_param_spec_result (const gchar* name,
                                                       const gchar* nick,
                                                       const gchar* blurb,
                                                       GType object_type,
                                                       GParamFlags flags);
VALA_EXTERN void dc_link_preview_fetcher_value_set_result (GValue* value,
                                               gpointer v_object);
VALA_EXTERN void dc_link_preview_fetcher_value_take_result (GValue* value,
                                                gpointer v_object);
VALA_EXTERN gpointer dc_link_preview_fetcher_value_get_result (const GValue* value);
VALA_EXTERN GType dc_link_preview_fetcher_result_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcLinkPreviewFetcherResult, dc_link_preview_fetcher_result_unref)
VALA_EXTERN void dc_link_preview_fetcher_fetch (DcLinkPreviewFetcher* self,
                                    const gchar* url,
                                    gboolean clean_image_urls,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
VALA_EXTERN DcLinkPreviewFetcherResult* dc_link_preview_fetcher_fetch_finish (DcLinkPreviewFetcher* self,
                                                                  GAsyncResult* _res_);
static gboolean dc_link_preview_fetcher_fetch_co (DcLinkPreviewFetcherFetchData* _data_);
VALA_EXTERN void dc_rpc_client_get_http_response (DcRpcClient* self,
                                      const gchar* url,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
VALA_EXTERN guint8* dc_rpc_client_get_http_response_finish (DcRpcClient* self,
                                                GAsyncResult* _res_,
                                                gchar** mimetype,
                                                gint* result_length1,
                                                GError** error);
static void dc_link_preview_fetcher_fetch_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
VALA_EXTERN gpointer dc_link_preview_metadata_ref (gpointer instance);
VALA_EXTERN void dc_link_preview_metadata_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_link_preview_param_spec_metadata (const gchar* name,
                                                 const gchar* nick,
                                                 const gchar* blurb,
                                                 GType object_type,
                                                 GParamFlags flags);
VALA_EXTERN void dc_link_preview_value_set_metadata (GValue* value,
                                         gpointer v_object);
VALA_EXTERN void dc_link_preview_value_take_metadata (GValue* value,
                                          gpointer v_object);
VALA_EXTERN gpointer dc_link_preview_value_get_metadata (const GValue* value);
VALA_EXTERN GType dc_link_preview_metadata_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcLinkPreviewMetadata, dc_link_preview_metadata_unref)
VALA_EXTERN DcLinkPreviewMetadata* dc_link_preview_metadata_new (void);
VALA_EXTERN DcLinkPreviewMetadata* dc_link_preview_metadata_construct (GType object_type);
VALA_EXTERN DcLinkPreviewMetadata* dc_link_preview_parse_html (const gchar* html,
                                                   const gchar* base_url);
VALA_EXTERN gchar* dc_link_preview_image_fetch_url (const gchar* url,
                                        gboolean clean);
static guint8* _vala_array_dup13 (guint8* self,
                           gssize length);
VALA_EXTERN gchar* dc_link_preview_image_extension (const gchar* mimetype,
                                        const gchar* url);
VALA_EXTERN DcLinkPreviewFetcherResult* dc_link_preview_fetcher_result_new (void);
VALA_EXTERN DcLinkPreviewFetcherResult* dc_link_preview_fetcher_result_construct (GType object_type);
static gchar* dc_link_preview_fetcher_file_stem (const gchar* url);
static void dc_link_preview_fetcher_result_finalize (DcLinkPreviewFetcherResult * obj);
static GType dc_link_preview_fetcher_result_get_type_once (void);
static void dc_link_preview_fetcher_finalize (GObject * obj);
static GType dc_link_preview_fetcher_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_link_preview_fetcher_get_instance_private (DcLinkPreviewFetcher* self)
{
	return G_STRUCT_MEMBER_P (self, DcLinkPreviewFetcher_private_offset);
}

DcLinkPreviewFetcher*
dc_link_preview_fetcher_construct (GType object_type,
                                   DcRpcClient* rpc)
{
	DcLinkPreviewFetcher * self = NULL;
	g_return_val_if_fail (rpc != NULL, NULL);
	self = (DcLinkPreviewFetcher*) g_object_new (object_type, NULL);
	self->priv->rpc = rpc;
	return self;
}

DcLinkPreviewFetcher*
dc_link_preview_fetcher_new (DcRpcClient* rpc)
{
	return dc_link_preview_fetcher_construct (DC_TYPE_LINK_PREVIEW_FETCHER, rpc);
}

static void
dc_link_preview_fetcher_fetch_data_free (gpointer _data)
{
	DcLinkPreviewFetcherFetchData* _data_;
	_data_ = _data;
	_g_free0 (_data_->url);
	_dc_link_preview_fetcher_result_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcLinkPreviewFetcherFetchData, _data_);
}

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

void
dc_link_preview_fetcher_fetch (DcLinkPreviewFetcher* self,
                               const gchar* url,
                               gboolean clean_image_urls,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	DcLinkPreviewFetcherFetchData* _data_;
	DcLinkPreviewFetcher* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (url != NULL);
	_data_ = g_slice_new0 (DcLinkPreviewFetcherFetchData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_link_preview_fetcher_fetch_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (url);
	_g_free0 (_data_->url);
	_data_->url = _tmp1_;
	_data_->clean_image_urls = clean_image_urls;
	dc_link_preview_fetcher_fetch_co (_data_);
}

DcLinkPreviewFetcherResult*
dc_link_preview_fetcher_fetch_finish (DcLinkPreviewFetcher* self,
                                      GAsyncResult* _res_)
{
	DcLinkPreviewFetcherResult* result;
	DcLinkPreviewFetcherFetchData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/** Returns null when the page has no usable image; the caller
            owns the returned temp file. */
static void
dc_link_preview_fetcher_fetch_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	DcLinkPreviewFetcherFetchData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_link_preview_fetcher_fetch_co (_data_);
}

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

static gboolean
dc_link_preview_fetcher_fetch_co (DcLinkPreviewFetcherFetchData* _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;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (!g_str_has_prefix (_data_->url, "https://")) {
		_data_->_tmp0_ = !g_str_has_prefix (_data_->url, "http://");
	} else {
		_data_->_tmp0_ = FALSE;
	}
	if (_data_->_tmp0_) {
		_data_->result = NULL;
		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_->body_length1 = 0;
	_data_->_body_size_ = 0;
	{
		_data_->_tmp2_ = _data_->self->priv->rpc;
		_data_->_tmp3_ = NULL;
		_data_->_tmp4_ = 0;
		_data_->_state_ = 1;
		dc_rpc_client_get_http_response (_data_->_tmp2_, _data_->url, dc_link_preview_fetcher_fetch_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp5_ = dc_rpc_client_get_http_response_finish (_data_->_tmp2_, _data_->_res_, &_data_->_tmp3_, &_data_->_tmp4_, &_data_->_inner_error0_);
		_g_free0 (_data_->mimetype);
		_data_->mimetype = _data_->_tmp3_;
		_data_->_tmp1_ = _data_->_tmp5_;
		_data_->_tmp1__length1 = _data_->_tmp4_;
		_data_->__tmp1__size_ = _data_->_tmp1__length1;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp6_ = _data_->_tmp1_;
		_data_->_tmp6__length1 = _data_->_tmp1__length1;
		_data_->_tmp1_ = NULL;
		_data_->_tmp1__length1 = 0;
		_data_->body = (g_free (_data_->body), NULL);
		_data_->body = _data_->_tmp6_;
		_data_->body_length1 = _data_->_tmp6__length1;
		_data_->_body_size_ = _data_->body_length1;
		_data_->_tmp1_ = (g_free (_data_->_tmp1_), NULL);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp7_ = _data_->e;
		_data_->_tmp8_ = _data_->_tmp7_->message;
		g_debug ("link_preview_fetcher.vala:35: link preview: %s: %s", _data_->url, _data_->_tmp8_);
		_data_->result = NULL;
		_g_error_free0 (_data_->e);
		_data_->body = (g_free (_data_->body), NULL);
		_g_free0 (_data_->mimetype);
		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:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_data_->body = (g_free (_data_->body), NULL);
		_g_free0 (_data_->mimetype);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->meta = NULL;
	_data_->_tmp10_ = _data_->mimetype;
	_data_->_tmp9_ = _data_->_tmp10_;
	if (_data_->_tmp9_ == NULL) {
		_data_->_tmp9_ = "";
	}
	_data_->_tmp11_ = g_utf8_strdown (_data_->_tmp9_, (gssize) -1);
	_data_->mt = _data_->_tmp11_;
	_data_->_tmp12_ = _data_->mt;
	if (g_str_has_prefix (_data_->_tmp12_, "image/")) {
		_data_->_tmp13_ = dc_link_preview_metadata_new ();
		_dc_link_preview_metadata_unref0 (_data_->meta);
		_data_->meta = _data_->_tmp13_;
		_data_->_tmp14_ = _data_->meta;
		_data_->_tmp15_ = g_strdup (_data_->url);
		_g_free0 (_data_->_tmp14_->image_url);
		_data_->_tmp14_->image_url = _data_->_tmp15_;
	} else {
		_data_->_tmp18_ = _data_->mt;
		_data_->_tmp19_ = strlen (_data_->_tmp18_);
		_data_->_tmp20_ = _data_->_tmp19_;
		if (_data_->_tmp20_ == 0) {
			_data_->_tmp17_ = TRUE;
		} else {
			_data_->_tmp21_ = _data_->mt;
			_data_->_tmp17_ = g_str_has_prefix (_data_->_tmp21_, "text/html");
		}
		if (_data_->_tmp17_) {
			_data_->_tmp16_ = TRUE;
		} else {
			_data_->_tmp22_ = _data_->mt;
			_data_->_tmp16_ = g_str_has_prefix (_data_->_tmp22_, "application/xhtml");
		}
		if (_data_->_tmp16_) {
			_data_->_tmp23_ = _data_->body;
			_data_->_tmp23__length1 = _data_->body_length1;
			_data_->len = MIN (_data_->_tmp23__length1, DC_LINK_PREVIEW_MAX_HTML_BYTES);
			_data_->_tmp24_ = g_string_sized_new ((gsize) (_data_->len + 1));
			_data_->sb = _data_->_tmp24_;
			_data_->_tmp25_ = _data_->sb;
			_data_->_tmp26_ = _data_->body;
			_data_->_tmp26__length1 = _data_->body_length1;
			g_string_append_len (_data_->_tmp25_, (const gchar*) _data_->_tmp26_, (gssize) _data_->len);
			_data_->_tmp27_ = _data_->sb;
			_data_->_tmp28_ = _data_->_tmp27_->str;
			_data_->_tmp29_ = dc_link_preview_parse_html (_data_->_tmp28_, _data_->url);
			_dc_link_preview_metadata_unref0 (_data_->meta);
			_data_->meta = _data_->_tmp29_;
			_g_string_free0 (_data_->sb);
		}
	}
	_data_->_tmp31_ = _data_->meta;
	if (_data_->_tmp31_ == NULL) {
		_data_->_tmp30_ = TRUE;
	} else {
		_data_->_tmp32_ = _data_->meta;
		_data_->_tmp33_ = _data_->_tmp32_->image_url;
		_data_->_tmp30_ = _data_->_tmp33_ == NULL;
	}
	if (_data_->_tmp30_) {
		_data_->result = NULL;
		_g_free0 (_data_->mt);
		_dc_link_preview_metadata_unref0 (_data_->meta);
		_data_->body = (g_free (_data_->body), NULL);
		_g_free0 (_data_->mimetype);
		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_->_tmp34_ = _data_->meta;
	_data_->_tmp35_ = _data_->_tmp34_->image_url;
	_data_->_tmp36_ = g_strdup (_data_->_tmp35_);
	_data_->image_url = _data_->_tmp36_;
	_data_->_tmp37_ = g_new0 (guint8, 0);
	_data_->image = _data_->_tmp37_;
	_data_->image_length1 = 0;
	_data_->_image_size_ = _data_->image_length1;
	_data_->image_mime = NULL;
	_data_->_tmp38_ = _data_->image_url;
	_data_->_tmp39_ = g_strdup (_data_->_tmp38_);
	_data_->fetched_from = _data_->_tmp39_;
	_data_->ok = FALSE;
	_data_->_tmp40_ = _data_->image_url;
	_data_->_tmp41_ = dc_link_preview_image_fetch_url (_data_->_tmp40_, _data_->clean_image_urls);
	_data_->first = _data_->_tmp41_;
	_data_->_tmp42__length1 = 0;
	_data_->__tmp42__size_ = 0;
	_data_->_tmp43_ = _data_->first;
	_data_->_tmp44_ = _data_->image_url;
	if (g_strcmp0 (_data_->_tmp43_, _data_->_tmp44_) == 0) {
		_data_->_tmp45_ = _data_->image_url;
		_data_->_tmp46_ = g_strdup (_data_->_tmp45_);
		_data_->_tmp47_ = g_new0 (gchar*, 1 + 1);
		_data_->_tmp47_[0] = _data_->_tmp46_;
		_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp42_ = _data_->_tmp47_;
		_data_->_tmp42__length1 = 1;
		_data_->__tmp42__size_ = _data_->_tmp42__length1;
	} else {
		_data_->_tmp48_ = _data_->first;
		_data_->_tmp49_ = g_strdup (_data_->_tmp48_);
		_data_->_tmp50_ = _data_->image_url;
		_data_->_tmp51_ = g_strdup (_data_->_tmp50_);
		_data_->_tmp52_ = g_new0 (gchar*, 2 + 1);
		_data_->_tmp52_[0] = _data_->_tmp49_;
		_data_->_tmp52_[1] = _data_->_tmp51_;
		_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp42_ = _data_->_tmp52_;
		_data_->_tmp42__length1 = 2;
		_data_->__tmp42__size_ = _data_->_tmp42__length1;
	}
	_data_->_tmp53_ = _data_->_tmp42_;
	_data_->_tmp53__length1 = _data_->_tmp42__length1;
	_data_->_tmp42_ = NULL;
	_data_->_tmp42__length1 = 0;
	_data_->candidates = _data_->_tmp53_;
	_data_->candidates_length1 = _data_->_tmp53__length1;
	_data_->_candidates_size_ = _data_->candidates_length1;
	_data_->_tmp54_ = _data_->candidates;
	_data_->_tmp54__length1 = _data_->candidates_length1;
	{
		_data_->candidate_collection_length1 = 0;
		_data_->_candidate_collection_size_ = 0;
		_data_->candidate_collection = _data_->_tmp54_;
		_data_->candidate_collection_length1 = _data_->_tmp54__length1;
		for (_data_->candidate_it = 0; _data_->candidate_it < _data_->candidate_collection_length1; _data_->candidate_it = _data_->candidate_it + 1) {
			_data_->_tmp55_ = g_strdup (_data_->candidate_collection[_data_->candidate_it]);
			_data_->candidate = _data_->_tmp55_;
			{
				_data_->_tmp57_ = _data_->mt;
				if (g_str_has_prefix (_data_->_tmp57_, "image/")) {
					_data_->_tmp58_ = _data_->candidate;
					_data_->_tmp56_ = g_strcmp0 (_data_->_tmp58_, _data_->url) == 0;
				} else {
					_data_->_tmp56_ = FALSE;
				}
				if (_data_->_tmp56_) {
					_data_->_tmp59_ = _data_->body;
					_data_->_tmp59__length1 = _data_->body_length1;
					_data_->_tmp60_ = (_data_->_tmp59_ != NULL) ? _vala_array_dup13 (_data_->_tmp59_, _data_->_tmp59__length1) : _data_->_tmp59_;
					_data_->_tmp60__length1 = _data_->_tmp59__length1;
					_data_->image = (g_free (_data_->image), NULL);
					_data_->image = _data_->_tmp60_;
					_data_->image_length1 = _data_->_tmp60__length1;
					_data_->_image_size_ = _data_->image_length1;
					_data_->_tmp61_ = _data_->mimetype;
					_data_->_tmp62_ = g_strdup (_data_->_tmp61_);
					_g_free0 (_data_->image_mime);
					_data_->image_mime = _data_->_tmp62_;
					_data_->ok = TRUE;
					_g_free0 (_data_->candidate);
					break;
				}
				{
					_data_->_tmp64_ = _data_->self->priv->rpc;
					_data_->_tmp65_ = _data_->candidate;
					_data_->_tmp66_ = NULL;
					_data_->_tmp67_ = 0;
					_data_->_state_ = 2;
					dc_rpc_client_get_http_response (_data_->_tmp64_, _data_->_tmp65_, dc_link_preview_fetcher_fetch_ready, _data_);
					return FALSE;
					_state_2:
					_data_->_tmp68_ = dc_rpc_client_get_http_response_finish (_data_->_tmp64_, _data_->_res_, &_data_->_tmp66_, &_data_->_tmp67_, &_data_->_inner_error0_);
					_g_free0 (_data_->image_mime);
					_data_->image_mime = _data_->_tmp66_;
					_data_->_tmp63_ = _data_->_tmp68_;
					_data_->_tmp63__length1 = _data_->_tmp67_;
					_data_->__tmp63__size_ = _data_->_tmp63__length1;
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						goto __catch1_g_error;
					}
					_data_->_tmp69_ = _data_->_tmp63_;
					_data_->_tmp69__length1 = _data_->_tmp63__length1;
					_data_->_tmp63_ = NULL;
					_data_->_tmp63__length1 = 0;
					_data_->image = (g_free (_data_->image), NULL);
					_data_->image = _data_->_tmp69_;
					_data_->image_length1 = _data_->_tmp69__length1;
					_data_->_image_size_ = _data_->image_length1;
					_data_->_tmp71_ = _data_->image;
					_data_->_tmp71__length1 = _data_->image_length1;
					if (_data_->_tmp71__length1 > 0) {
						_data_->_tmp72_ = _data_->image;
						_data_->_tmp72__length1 = _data_->image_length1;
						_data_->_tmp70_ = ((gint64) _data_->_tmp72__length1) <= DC_LINK_PREVIEW_MAX_IMAGE_BYTES;
					} else {
						_data_->_tmp70_ = FALSE;
					}
					if (_data_->_tmp70_) {
						_data_->ok = TRUE;
						_data_->_tmp73_ = _data_->candidate;
						_data_->_tmp74_ = g_strdup (_data_->_tmp73_);
						_g_free0 (_data_->fetched_from);
						_data_->fetched_from = _data_->_tmp74_;
						_data_->_tmp63_ = (g_free (_data_->_tmp63_), NULL);
						_g_free0 (_data_->candidate);
						break;
					}
					_data_->_tmp63_ = (g_free (_data_->_tmp63_), NULL);
				}
				goto __finally1;
				__catch1_g_error:
				{
					_data_->_vala1_e = _data_->_inner_error0_;
					_data_->_inner_error0_ = NULL;
					_data_->_tmp75_ = _data_->candidate;
					_data_->_tmp76_ = _data_->_vala1_e;
					_data_->_tmp77_ = _data_->_tmp76_->message;
					g_debug ("link_preview_fetcher.vala:77: link preview image: %s: %s", _data_->_tmp75_, _data_->_tmp77_);
					_g_error_free0 (_data_->_vala1_e);
				}
				__finally1:
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_free0 (_data_->candidate);
					_data_->candidates = (_vala_array_free (_data_->candidates, _data_->candidates_length1, (GDestroyNotify) g_free), NULL);
					_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_data_->first);
					_g_free0 (_data_->fetched_from);
					_g_free0 (_data_->image_mime);
					_data_->image = (g_free (_data_->image), NULL);
					_g_free0 (_data_->image_url);
					_g_free0 (_data_->mt);
					_dc_link_preview_metadata_unref0 (_data_->meta);
					_data_->body = (g_free (_data_->body), NULL);
					_g_free0 (_data_->mimetype);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
					g_clear_error (&_data_->_inner_error0_);
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_g_free0 (_data_->candidate);
			}
		}
	}
	if (!_data_->ok) {
		_data_->result = NULL;
		_data_->candidates = (_vala_array_free (_data_->candidates, _data_->candidates_length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->first);
		_g_free0 (_data_->fetched_from);
		_g_free0 (_data_->image_mime);
		_data_->image = (g_free (_data_->image), NULL);
		_g_free0 (_data_->image_url);
		_g_free0 (_data_->mt);
		_dc_link_preview_metadata_unref0 (_data_->meta);
		_data_->body = (g_free (_data_->body), NULL);
		_g_free0 (_data_->mimetype);
		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_->_tmp78_ = _data_->image_mime;
	_data_->_tmp79_ = _data_->fetched_from;
	_data_->_tmp80_ = dc_link_preview_image_extension (_data_->_tmp78_, _data_->_tmp79_);
	_data_->ext = _data_->_tmp80_;
	_data_->_tmp81_ = _data_->ext;
	if (_data_->_tmp81_ == NULL) {
		_data_->result = NULL;
		_g_free0 (_data_->ext);
		_data_->candidates = (_vala_array_free (_data_->candidates, _data_->candidates_length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->first);
		_g_free0 (_data_->fetched_from);
		_g_free0 (_data_->image_mime);
		_data_->image = (g_free (_data_->image), NULL);
		_g_free0 (_data_->image_url);
		_g_free0 (_data_->mt);
		_dc_link_preview_metadata_unref0 (_data_->meta);
		_data_->body = (g_free (_data_->body), NULL);
		_g_free0 (_data_->mimetype);
		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_->path = NULL;
	{
		_data_->_tmp82_ = _data_->ext;
		_data_->_tmp83_ = g_strconcat ("parla-preview-XXXXXX.", _data_->_tmp82_, NULL);
		_data_->_tmp84_ = _data_->_tmp83_;
		_data_->_tmp85_ = NULL;
		_data_->_tmp86_ = g_file_new_tmp (_data_->_tmp84_, &_data_->_tmp85_, &_data_->_inner_error0_);
		_g_object_unref0 (_data_->stream);
		_data_->stream = _data_->_tmp85_;
		_data_->_tmp87_ = _data_->_tmp86_;
		_g_free0 (_data_->_tmp84_);
		_data_->tmp = _data_->_tmp87_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->stream);
			goto __catch2_g_error;
		}
		_data_->_tmp88_ = _data_->tmp;
		_data_->_tmp89_ = g_file_get_path (_data_->_tmp88_);
		_g_free0 (_data_->path);
		_data_->path = _data_->_tmp89_;
		_data_->_tmp90_ = _data_->stream;
		_data_->_tmp91_ = g_io_stream_get_output_stream ((GIOStream*) _data_->_tmp90_);
		_data_->_tmp92_ = _data_->_tmp91_;
		_data_->_tmp93_ = _data_->image;
		_data_->_tmp93__length1 = _data_->image_length1;
		_data_->_tmp94_ = 0UL;
		_data_->_state_ = 3;
		g_output_stream_write_all_async (_data_->_tmp92_, _data_->_tmp93_, (gsize) _data_->_tmp93__length1, G_PRIORITY_DEFAULT, NULL, dc_link_preview_fetcher_fetch_ready, _data_);
		return FALSE;
		_state_3:
		g_output_stream_write_all_finish (_data_->_tmp92_, _data_->_res_, &_data_->_tmp94_, &_data_->_inner_error0_);
		_data_->written = _data_->_tmp94_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->tmp);
			_g_object_unref0 (_data_->stream);
			goto __catch2_g_error;
		}
		_data_->_tmp95_ = _data_->stream;
		_data_->_state_ = 4;
		g_io_stream_close_async ((GIOStream*) _data_->_tmp95_, G_PRIORITY_DEFAULT, NULL, dc_link_preview_fetcher_fetch_ready, _data_);
		return FALSE;
		_state_4:
		g_io_stream_close_finish ((GIOStream*) _data_->_tmp95_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->tmp);
			_g_object_unref0 (_data_->stream);
			goto __catch2_g_error;
		}
		_data_->_tmp96_ = _data_->path;
		_data_->_tmp97_ = gdk_pixbuf_new_from_file (_data_->_tmp96_, &_data_->_inner_error0_);
		_data_->pixbuf = _data_->_tmp97_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->tmp);
			_g_object_unref0 (_data_->stream);
			goto __catch2_g_error;
		}
		_data_->_tmp99_ = _data_->pixbuf;
		_data_->_tmp100_ = gdk_pixbuf_get_width (_data_->_tmp99_);
		_data_->_tmp101_ = _data_->_tmp100_;
		if (_data_->_tmp101_ < 2) {
			_data_->_tmp98_ = TRUE;
		} else {
			_data_->_tmp102_ = _data_->pixbuf;
			_data_->_tmp103_ = gdk_pixbuf_get_height (_data_->_tmp102_);
			_data_->_tmp104_ = _data_->_tmp103_;
			_data_->_tmp98_ = _data_->_tmp104_ < 2;
		}
		if (_data_->_tmp98_) {
			_data_->_tmp105_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "empty image");
			_data_->_inner_error0_ = _data_->_tmp105_;
			_g_object_unref0 (_data_->pixbuf);
			_g_object_unref0 (_data_->tmp);
			_g_object_unref0 (_data_->stream);
			goto __catch2_g_error;
		}
		_g_object_unref0 (_data_->pixbuf);
		_g_object_unref0 (_data_->tmp);
		_g_object_unref0 (_data_->stream);
	}
	goto __finally2;
	__catch2_g_error:
	{
		_data_->_vala2_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp106_ = _data_->_vala2_e;
		_data_->_tmp107_ = _data_->_tmp106_->message;
		g_debug ("link_preview_fetcher.vala:100: link preview image unusable: %s", _data_->_tmp107_);
		_data_->_tmp108_ = _data_->path;
		if (_data_->_tmp108_ != NULL) {
			_data_->_tmp109_ = _data_->path;
			g_unlink (_data_->_tmp109_);
		}
		_data_->result = NULL;
		_g_error_free0 (_data_->_vala2_e);
		_g_free0 (_data_->path);
		_g_free0 (_data_->ext);
		_data_->candidates = (_vala_array_free (_data_->candidates, _data_->candidates_length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->first);
		_g_free0 (_data_->fetched_from);
		_g_free0 (_data_->image_mime);
		_data_->image = (g_free (_data_->image), NULL);
		_g_free0 (_data_->image_url);
		_g_free0 (_data_->mt);
		_dc_link_preview_metadata_unref0 (_data_->meta);
		_data_->body = (g_free (_data_->body), NULL);
		_g_free0 (_data_->mimetype);
		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;
	}
	__finally2:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_free0 (_data_->path);
		_g_free0 (_data_->ext);
		_data_->candidates = (_vala_array_free (_data_->candidates, _data_->candidates_length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->first);
		_g_free0 (_data_->fetched_from);
		_g_free0 (_data_->image_mime);
		_data_->image = (g_free (_data_->image), NULL);
		_g_free0 (_data_->image_url);
		_g_free0 (_data_->mt);
		_dc_link_preview_metadata_unref0 (_data_->meta);
		_data_->body = (g_free (_data_->body), NULL);
		_g_free0 (_data_->mimetype);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp110_ = dc_link_preview_fetcher_result_new ();
	_data_->r = _data_->_tmp110_;
	_data_->_tmp111_ = _data_->r;
	_data_->_tmp112_ = g_strdup (_data_->url);
	_g_free0 (_data_->_tmp111_->url);
	_data_->_tmp111_->url = _data_->_tmp112_;
	_data_->_tmp113_ = _data_->r;
	_data_->_tmp114_ = _data_->path;
	_data_->_tmp115_ = g_strdup (_data_->_tmp114_);
	_g_free0 (_data_->_tmp113_->image_path);
	_data_->_tmp113_->image_path = _data_->_tmp115_;
	_data_->_tmp117_ = _data_->ext;
	if (g_strcmp0 (_data_->_tmp117_, "img") == 0) {
		_data_->_tmp116_ = "jpg";
	} else {
		_data_->_tmp118_ = _data_->ext;
		_data_->_tmp116_ = _data_->_tmp118_;
	}
	_data_->_tmp119_ = _data_->r;
	_data_->_tmp120_ = dc_link_preview_fetcher_file_stem (_data_->url);
	_data_->_tmp121_ = _data_->_tmp120_;
	_data_->_tmp122_ = g_strdup_printf ("%s.%s", _data_->_tmp121_, _data_->_tmp116_);
	_g_free0 (_data_->_tmp119_->file_name);
	_data_->_tmp119_->file_name = _data_->_tmp122_;
	_g_free0 (_data_->_tmp121_);
	_data_->_tmp123_ = _data_->r;
	_data_->_tmp124_ = _data_->meta;
	_data_->_tmp125_ = _data_->_tmp124_->title;
	_data_->_tmp126_ = g_strdup (_data_->_tmp125_);
	_g_free0 (_data_->_tmp123_->title);
	_data_->_tmp123_->title = _data_->_tmp126_;
	_data_->_tmp127_ = _data_->r;
	_data_->_tmp128_ = _data_->meta;
	_data_->_tmp129_ = _data_->_tmp128_->description;
	_data_->_tmp130_ = g_strdup (_data_->_tmp129_);
	_g_free0 (_data_->_tmp127_->description);
	_data_->_tmp127_->description = _data_->_tmp130_;
	_data_->result = _data_->r;
	_g_free0 (_data_->path);
	_g_free0 (_data_->ext);
	_data_->candidates = (_vala_array_free (_data_->candidates, _data_->candidates_length1, (GDestroyNotify) g_free), NULL);
	_data_->_tmp42_ = (_vala_array_free (_data_->_tmp42_, _data_->_tmp42__length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (_data_->first);
	_g_free0 (_data_->fetched_from);
	_g_free0 (_data_->image_mime);
	_data_->image = (g_free (_data_->image), NULL);
	_g_free0 (_data_->image_url);
	_g_free0 (_data_->mt);
	_dc_link_preview_metadata_unref0 (_data_->meta);
	_data_->body = (g_free (_data_->body), NULL);
	_g_free0 (_data_->mimetype);
	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 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 gchar*
dc_link_preview_fetcher_file_stem (const gchar* url)
{
	gchar* _tmp12_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (url != NULL, NULL);
	{
		GUri* uri = NULL;
		GUri* _tmp0_;
		gchar* host = NULL;
		GUri* _tmp1_;
		const gchar* _tmp2_;
		gchar* _tmp3_;
		gboolean _tmp4_ = FALSE;
		const gchar* _tmp5_;
		_tmp0_ = g_uri_parse (url, G_URI_FLAGS_PARSE_RELAXED, &_inner_error0_);
		uri = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp1_ = uri;
		_tmp2_ = g_uri_get_host (_tmp1_);
		_tmp3_ = g_strdup (_tmp2_);
		host = _tmp3_;
		_tmp5_ = host;
		if (_tmp5_ != NULL) {
			const gchar* _tmp6_;
			gint _tmp7_;
			gint _tmp8_;
			_tmp6_ = host;
			_tmp7_ = strlen (_tmp6_);
			_tmp8_ = _tmp7_;
			_tmp4_ = _tmp8_ > 0;
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			const gchar* _tmp9_;
			_tmp9_ = host;
			if (g_str_has_prefix (_tmp9_, "www.")) {
				const gchar* _tmp10_;
				gchar* _tmp11_;
				_tmp10_ = host;
				_tmp11_ = string_substring (_tmp10_, (glong) 4, (glong) -1);
				_g_free0 (host);
				host = _tmp11_;
			}
			result = host;
			_g_uri_unref0 (uri);
			return result;
		}
		_g_free0 (host);
		_g_uri_unref0 (uri);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	_tmp12_ = g_strdup ("link-preview");
	result = _tmp12_;
	return result;
}

DcLinkPreviewFetcherResult*
dc_link_preview_fetcher_result_construct (GType object_type)
{
	DcLinkPreviewFetcherResult* self = NULL;
	self = (DcLinkPreviewFetcherResult*) g_type_create_instance (object_type);
	return self;
}

DcLinkPreviewFetcherResult*
dc_link_preview_fetcher_result_new (void)
{
	return dc_link_preview_fetcher_result_construct (DC_LINK_PREVIEW_FETCHER_TYPE_RESULT);
}

static void
dc_link_preview_fetcher_value_result_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dc_link_preview_fetcher_value_result_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dc_link_preview_fetcher_result_unref (value->data[0].v_pointer);
	}
}

static void
dc_link_preview_fetcher_value_result_copy_value (const GValue* src_value,
                                                 GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dc_link_preview_fetcher_result_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dc_link_preview_fetcher_value_result_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dc_link_preview_fetcher_value_result_collect_value (GValue* value,
                                                    guint n_collect_values,
                                                    GTypeCValue* collect_values,
                                                    guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DcLinkPreviewFetcherResult * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dc_link_preview_fetcher_result_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dc_link_preview_fetcher_value_result_lcopy_value (const GValue* value,
                                                  guint n_collect_values,
                                                  GTypeCValue* collect_values,
                                                  guint collect_flags)
{
	DcLinkPreviewFetcherResult ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dc_link_preview_fetcher_result_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dc_link_preview_fetcher_param_spec_result (const gchar* name,
                                           const gchar* nick,
                                           const gchar* blurb,
                                           GType object_type,
                                           GParamFlags flags)
{
	DcLinkPreviewFetcherParamSpecResult* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DC_LINK_PREVIEW_FETCHER_TYPE_RESULT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dc_link_preview_fetcher_value_get_result (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_LINK_PREVIEW_FETCHER_TYPE_RESULT), NULL);
	return value->data[0].v_pointer;
}

void
dc_link_preview_fetcher_value_set_result (GValue* value,
                                          gpointer v_object)
{
	DcLinkPreviewFetcherResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_LINK_PREVIEW_FETCHER_TYPE_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_LINK_PREVIEW_FETCHER_TYPE_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dc_link_preview_fetcher_result_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_link_preview_fetcher_result_unref (old);
	}
}

void
dc_link_preview_fetcher_value_take_result (GValue* value,
                                           gpointer v_object)
{
	DcLinkPreviewFetcherResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_LINK_PREVIEW_FETCHER_TYPE_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_LINK_PREVIEW_FETCHER_TYPE_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_link_preview_fetcher_result_unref (old);
	}
}

static void
dc_link_preview_fetcher_result_class_init (DcLinkPreviewFetcherResultClass * klass,
                                           gpointer klass_data)
{
	dc_link_preview_fetcher_result_parent_class = g_type_class_peek_parent (klass);
	((DcLinkPreviewFetcherResultClass *) klass)->finalize = dc_link_preview_fetcher_result_finalize;
}

static void
dc_link_preview_fetcher_result_instance_init (DcLinkPreviewFetcherResult * self,
                                              gpointer klass)
{
	self->ref_count = 1;
}

static void
dc_link_preview_fetcher_result_finalize (DcLinkPreviewFetcherResult * obj)
{
	DcLinkPreviewFetcherResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_LINK_PREVIEW_FETCHER_TYPE_RESULT, DcLinkPreviewFetcherResult);
	g_signal_handlers_destroy (self);
	_g_free0 (self->url);
	_g_free0 (self->image_path);
	_g_free0 (self->file_name);
	_g_free0 (self->title);
	_g_free0 (self->description);
}

static GType
dc_link_preview_fetcher_result_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dc_link_preview_fetcher_value_result_init, dc_link_preview_fetcher_value_result_free_value, dc_link_preview_fetcher_value_result_copy_value, dc_link_preview_fetcher_value_result_peek_pointer, "p", dc_link_preview_fetcher_value_result_collect_value, "p", dc_link_preview_fetcher_value_result_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DcLinkPreviewFetcherResultClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_link_preview_fetcher_result_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcLinkPreviewFetcherResult), 0, (GInstanceInitFunc) dc_link_preview_fetcher_result_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dc_link_preview_fetcher_result_type_id;
	dc_link_preview_fetcher_result_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DcLinkPreviewFetcherResult", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dc_link_preview_fetcher_result_type_id;
}

GType
dc_link_preview_fetcher_result_get_type (void)
{
	static volatile gsize dc_link_preview_fetcher_result_type_id__once = 0;
	if (g_once_init_enter (&dc_link_preview_fetcher_result_type_id__once)) {
		GType dc_link_preview_fetcher_result_type_id;
		dc_link_preview_fetcher_result_type_id = dc_link_preview_fetcher_result_get_type_once ();
		g_once_init_leave (&dc_link_preview_fetcher_result_type_id__once, dc_link_preview_fetcher_result_type_id);
	}
	return dc_link_preview_fetcher_result_type_id__once;
}

gpointer
dc_link_preview_fetcher_result_ref (gpointer instance)
{
	DcLinkPreviewFetcherResult * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dc_link_preview_fetcher_result_unref (gpointer instance)
{
	DcLinkPreviewFetcherResult * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DC_LINK_PREVIEW_FETCHER_RESULT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
dc_link_preview_fetcher_class_init (DcLinkPreviewFetcherClass * klass,
                                    gpointer klass_data)
{
	dc_link_preview_fetcher_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcLinkPreviewFetcher_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dc_link_preview_fetcher_finalize;
}

static void
dc_link_preview_fetcher_instance_init (DcLinkPreviewFetcher * self,
                                       gpointer klass)
{
	self->priv = dc_link_preview_fetcher_get_instance_private (self);
}

static void
dc_link_preview_fetcher_finalize (GObject * obj)
{
	DcLinkPreviewFetcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_LINK_PREVIEW_FETCHER, DcLinkPreviewFetcher);
	G_OBJECT_CLASS (dc_link_preview_fetcher_parent_class)->finalize (obj);
}

/**
     * Network half of link previews: fetches a pasted page and its
     * Open Graph image through core's get_http_response (so the account's
     * proxy applies and core's HTTP cache is reused) and writes the image
     * to a temp file for the composer to attach.
     */
static GType
dc_link_preview_fetcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcLinkPreviewFetcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_link_preview_fetcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcLinkPreviewFetcher), 0, (GInstanceInitFunc) dc_link_preview_fetcher_instance_init, NULL };
	GType dc_link_preview_fetcher_type_id;
	dc_link_preview_fetcher_type_id = g_type_register_static (G_TYPE_OBJECT, "DcLinkPreviewFetcher", &g_define_type_info, 0);
	DcLinkPreviewFetcher_private_offset = g_type_add_instance_private (dc_link_preview_fetcher_type_id, sizeof (DcLinkPreviewFetcherPrivate));
	return dc_link_preview_fetcher_type_id;
}

GType
dc_link_preview_fetcher_get_type (void)
{
	static volatile gsize dc_link_preview_fetcher_type_id__once = 0;
	if (g_once_init_enter (&dc_link_preview_fetcher_type_id__once)) {
		GType dc_link_preview_fetcher_type_id;
		dc_link_preview_fetcher_type_id = dc_link_preview_fetcher_get_type_once ();
		g_once_init_leave (&dc_link_preview_fetcher_type_id__once, dc_link_preview_fetcher_type_id);
	}
	return dc_link_preview_fetcher_type_id__once;
}

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

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

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

