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

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#define DC_LINK_CLEANER_GLOBAL_PARAMS "fbclid gclid gclsrc dclid wbraid gbraid msclkid yclid twclid " "ttclid li_fat_id mc_cid mc_eid igshid srsltid s_cid _hsenc " "_hsmi _openstat vero_conv vero_id oly_anon_id oly_enc_id"
#define DC_LINK_CLEANER_GLOBAL_PREFIXES "utm_ pk_ mtm_ piwik_ hsa_"
#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_CLEANER (dc_link_cleaner_get_type ())
#define DC_LINK_CLEANER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_LINK_CLEANER, DcLinkCleaner))
#define DC_LINK_CLEANER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_LINK_CLEANER, DcLinkCleanerClass))
#define DC_IS_LINK_CLEANER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_LINK_CLEANER))
#define DC_IS_LINK_CLEANER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_LINK_CLEANER))
#define DC_LINK_CLEANER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_LINK_CLEANER, DcLinkCleanerClass))

typedef struct _DcLinkCleaner DcLinkCleaner;
typedef struct _DcLinkCleanerClass DcLinkCleanerClass;
typedef struct _DcLinkCleanerPrivate DcLinkCleanerPrivate;
enum  {
	DC_LINK_CLEANER_0_PROPERTY,
	DC_LINK_CLEANER_NUM_PROPERTIES
};
static GParamSpec* dc_link_cleaner_properties[DC_LINK_CLEANER_NUM_PROPERTIES];

#define DC_LINK_CLEANER_TYPE_SITE_RULE (dc_link_cleaner_site_rule_get_type ())
typedef struct _DcLinkCleanerSiteRule DcLinkCleanerSiteRule;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

#define DC_TYPE_REMOVE_PARAM_FILTER (dc_remove_param_filter_get_type ())
#define DC_REMOVE_PARAM_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_REMOVE_PARAM_FILTER, DcRemoveParamFilter))
#define DC_REMOVE_PARAM_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_REMOVE_PARAM_FILTER, DcRemoveParamFilterClass))
#define DC_IS_REMOVE_PARAM_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_REMOVE_PARAM_FILTER))
#define DC_IS_REMOVE_PARAM_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_REMOVE_PARAM_FILTER))
#define DC_REMOVE_PARAM_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_REMOVE_PARAM_FILTER, DcRemoveParamFilterClass))

typedef struct _DcRemoveParamFilter DcRemoveParamFilter;
typedef struct _DcRemoveParamFilterClass DcRemoveParamFilterClass;

struct _DcLinkCleaner {
	GObject parent_instance;
	DcLinkCleanerPrivate * priv;
};

struct _DcLinkCleanerClass {
	GObjectClass parent_class;
};

struct _DcLinkCleanerSiteRule {
	const gchar* hosts;
	const gchar* params;
	const gchar* prefixes;
};

static gpointer dc_link_cleaner_parent_class = NULL;
VALA_EXTERN DcRemoveParamFilter* dc_remove_param_filter_active;

VALA_EXTERN GType dc_link_cleaner_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcLinkCleaner, g_object_unref)
static GType dc_link_cleaner_site_rule_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static DcLinkCleanerSiteRule* dc_link_cleaner_site_rule_dup (const DcLinkCleanerSiteRule* self);
static void dc_link_cleaner_site_rule_free (DcLinkCleanerSiteRule* self);
VALA_EXTERN gchar* dc_link_cleaner_clean_text (const gchar* text);
static gint dc_link_cleaner_find_url_start (const gchar* text,
                                     gint pos);
static gint dc_link_cleaner_find_url_end (const gchar* text,
                                   gint start);
VALA_EXTERN gchar* dc_link_cleaner_clean_url (const gchar* url);
VALA_EXTERN gchar** dc_link_cleaner_find_urls (const gchar* text,
                                   gint* result_length1);
static void _vala_array_add25 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
VALA_EXTERN GType dc_remove_param_filter_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRemoveParamFilter, g_object_unref)
VALA_EXTERN gchar* dc_remove_param_filter_clean_url (DcRemoveParamFilter* self,
                                         const gchar* url);
static gchar* dc_link_cleaner_host_of (const gchar* url);
static gboolean dc_link_cleaner_host_matches (const gchar* host,
                                       const gchar* pattern);
static gchar* dc_link_cleaner_strip_amazon_ref_path (const gchar* base_part);
static gint dc_link_cleaner_site_rule_for (const gchar* host);
static gboolean dc_link_cleaner_is_tracking_param (const gchar* name,
                                            gint site);
static gboolean dc_link_cleaner_has_word (const gchar* words,
                                   const gchar* word);
static gboolean dc_link_cleaner_has_prefix_in (const gchar* prefixes,
                                        const gchar* name);
static gboolean dc_link_cleaner_is_balanced (const gchar* text,
                                      gint start,
                                      gint end,
                                      gchar open,
                                      gchar close);
VALA_EXTERN DcLinkCleaner* dc_link_cleaner_new (void);
VALA_EXTERN DcLinkCleaner* dc_link_cleaner_construct (GType object_type);
static GType dc_link_cleaner_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);

static const DcLinkCleanerSiteRule DC_LINK_CLEANER_SITE_RULES[13] = {{"youtube.com youtu.be", "si feature pp ab_channel embeds_referring_euri source_ve_path", ""}, {"x.com twitter.com", "s t ref_src ref_url", ""}, {"instagram.com threads.net threads.com", "igsh ig_rid ig_mid xmt", ""}, {"facebook.com fb.com fb.watch fb.me messenger.com", "mibextid rdid share_url refid ref fref hc_ref sfnsn wtsid paipv " "eav comment_tracking notif_id notif_t", "__"}, {"linkedin.com lnkd.in", "trk trackingid lipi midtoken midsig trkemail ebp refid otptoken " "original_referer rcm", ""}, {"tiktok.com", "_t _r is_from_webapp sender_device sender_web_id web_id u_code " "tt_from is_copy_url share_app_id share_link_id share_iid ug_btm " "checksum", ""}, {"reddit.com redd.it", "share_id ref ref_source rdt correlation_id", ""}, {"spotify.com", "si nd _branch_match_id _branch_referrer", ""}, {"twitch.tv", "tt_content tt_medium", ""}, {"ytimg.com", "sqp rs usqp", ""}, {"amazon.*", "tag ref ref_ ascsubtag linkcode linkid camp creative creativeasin " "qid sr sprefix crid dib dib_tag content-id social_share", "pf_rd_ pd_rd_"}, {"ebay.*", "mkcid mkevt mkrid ssspo sssrc ssuid campid toolid customid mkpid " "ul_noapp amdata", ""}, {"aliexpress.*", "spm scm aff_platform aff_trace_key aff_fcid aff_fsk terminal_id " "pdp_npi gatewayadapt algo_pvid algo_exp_id utparam-url", ""}};

/** Rewrites every http(s) URL found in the text; anything that is
            not a URL passes through unchanged. */
static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	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;
}

gchar*
dc_link_cleaner_clean_text (const gchar* text)
{
	GString* _result_ = NULL;
	GString* _tmp0_;
	gint pos = 0;
	GString* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GString* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* result;
	g_return_val_if_fail (text != NULL, NULL);
	_tmp0_ = g_string_new ("");
	_result_ = _tmp0_;
	pos = 0;
	while (TRUE) {
		gint start = 0;
		gint end = 0;
		GString* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		GString* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		start = dc_link_cleaner_find_url_start (text, pos);
		if (start < 0) {
			break;
		}
		end = dc_link_cleaner_find_url_end (text, start);
		_tmp1_ = _result_;
		_tmp2_ = string_slice (text, (glong) pos, (glong) start);
		_tmp3_ = _tmp2_;
		g_string_append (_tmp1_, _tmp3_);
		_g_free0 (_tmp3_);
		_tmp4_ = _result_;
		_tmp5_ = string_slice (text, (glong) start, (glong) end);
		_tmp6_ = _tmp5_;
		_tmp7_ = dc_link_cleaner_clean_url (_tmp6_);
		_tmp8_ = _tmp7_;
		g_string_append (_tmp4_, _tmp8_);
		_g_free0 (_tmp8_);
		_g_free0 (_tmp6_);
		pos = end;
	}
	_tmp9_ = _result_;
	_tmp10_ = string_substring (text, (glong) pos, (glong) -1);
	_tmp11_ = _tmp10_;
	g_string_append (_tmp9_, _tmp11_);
	_g_free0 (_tmp11_);
	_tmp12_ = _result_;
	_tmp13_ = _tmp12_->str;
	_tmp14_ = g_strdup (_tmp13_);
	result = _tmp14_;
	_g_string_free0 (_result_);
	return result;
}

/** Every http(s) URL found in the text, in order, duplicates
            included. */
static void
_vala_array_add25 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

gchar**
dc_link_cleaner_find_urls (const gchar* text,
                           gint* result_length1)
{
	gchar** urls = NULL;
	gchar** _tmp0_;
	gint urls_length1;
	gint _urls_size_;
	gint pos = 0;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar** result;
	g_return_val_if_fail (text != NULL, NULL);
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	urls = _tmp0_;
	urls_length1 = 0;
	_urls_size_ = urls_length1;
	pos = 0;
	while (TRUE) {
		gint start = 0;
		gint end = 0;
		gchar* _tmp1_;
		start = dc_link_cleaner_find_url_start (text, pos);
		if (start < 0) {
			break;
		}
		end = dc_link_cleaner_find_url_end (text, start);
		_tmp1_ = string_slice (text, (glong) start, (glong) end);
		_vala_array_add25 (&urls, &urls_length1, &_urls_size_, _tmp1_);
		pos = end;
	}
	_tmp2_ = urls;
	_tmp2__length1 = urls_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

/** Strips tracking query parameters (and Amazon's /ref= path
            suffix) from a single URL. When a removeparam filter list is
            active (Settings → Links) it replaces the built-in rules. */
static gint
string_index_of_char (const gchar* self,
                      gunichar c,
                      gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_strchr (((gchar*) self) + start_index, (gssize) -1, c);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

gchar*
dc_link_cleaner_clean_url (const gchar* url)
{
	DcRemoveParamFilter* _tmp0_;
	gchar* host = NULL;
	gchar* _tmp3_;
	gint frag_start = 0;
	gint query_start = 0;
	gboolean _tmp4_ = FALSE;
	gint _tmp5_ = 0;
	gint base_end = 0;
	gchar* base_part = NULL;
	gchar* _tmp9_;
	gchar* _tmp10_ = NULL;
	gchar* fragment = NULL;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	gint _tmp20_ = 0;
	gint query_end = 0;
	gchar* query = NULL;
	gchar* _tmp23_;
	gint site = 0;
	const gchar* _tmp24_;
	GString* kept = NULL;
	GString* _tmp25_;
	const gchar* _tmp26_;
	gchar** _tmp27_;
	gchar** _tmp28_;
	gchar* _tmp45_ = NULL;
	GString* _tmp46_;
	gchar* cleaned = NULL;
	gchar* _tmp55_;
	const gchar* _tmp56_;
	const gchar* _tmp57_;
	gchar* _tmp58_;
	gchar* result;
	g_return_val_if_fail (url != NULL, NULL);
	_tmp0_ = dc_remove_param_filter_active;
	if (_tmp0_ != NULL) {
		DcRemoveParamFilter* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = dc_remove_param_filter_active;
		_tmp2_ = dc_remove_param_filter_clean_url (_tmp1_, url);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = dc_link_cleaner_host_of (url);
	host = _tmp3_;
	frag_start = string_index_of_char (url, (gunichar) '#', 0);
	query_start = string_index_of_char (url, (gunichar) '?', 0);
	if (frag_start >= 0) {
		_tmp4_ = query_start > frag_start;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		query_start = -1;
	}
	if (query_start >= 0) {
		_tmp5_ = query_start;
	} else {
		gint _tmp6_ = 0;
		if (frag_start >= 0) {
			_tmp6_ = frag_start;
		} else {
			gint _tmp7_;
			gint _tmp8_;
			_tmp7_ = strlen (url);
			_tmp8_ = _tmp7_;
			_tmp6_ = _tmp8_;
		}
		_tmp5_ = _tmp6_;
	}
	base_end = _tmp5_;
	_tmp9_ = string_slice (url, (glong) 0, (glong) base_end);
	base_part = _tmp9_;
	if (frag_start >= 0) {
		gchar* _tmp11_;
		_tmp11_ = string_substring (url, (glong) frag_start, (glong) -1);
		_g_free0 (_tmp10_);
		_tmp10_ = _tmp11_;
	} else {
		gchar* _tmp12_;
		_tmp12_ = g_strdup ("");
		_g_free0 (_tmp10_);
		_tmp10_ = _tmp12_;
	}
	_tmp13_ = _tmp10_;
	_tmp10_ = NULL;
	fragment = _tmp13_;
	_tmp14_ = host;
	if (dc_link_cleaner_host_matches (_tmp14_, "amazon.*")) {
		const gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp15_ = base_part;
		_tmp16_ = dc_link_cleaner_strip_amazon_ref_path (_tmp15_);
		_g_free0 (base_part);
		base_part = _tmp16_;
	}
	if (query_start < 0) {
		const gchar* _tmp17_;
		const gchar* _tmp18_;
		gchar* _tmp19_;
		_tmp17_ = base_part;
		_tmp18_ = fragment;
		_tmp19_ = g_strconcat (_tmp17_, _tmp18_, NULL);
		result = _tmp19_;
		_g_free0 (fragment);
		_g_free0 (_tmp10_);
		_g_free0 (base_part);
		_g_free0 (host);
		return result;
	}
	if (frag_start >= 0) {
		_tmp20_ = frag_start;
	} else {
		gint _tmp21_;
		gint _tmp22_;
		_tmp21_ = strlen (url);
		_tmp22_ = _tmp21_;
		_tmp20_ = _tmp22_;
	}
	query_end = _tmp20_;
	_tmp23_ = string_slice (url, (glong) (query_start + 1), (glong) query_end);
	query = _tmp23_;
	_tmp24_ = host;
	site = dc_link_cleaner_site_rule_for (_tmp24_);
	_tmp25_ = g_string_new ("");
	kept = _tmp25_;
	_tmp26_ = query;
	_tmp28_ = _tmp27_ = g_strsplit (_tmp26_, "&", 0);
	{
		gchar** param_collection = NULL;
		gint param_collection_length1 = 0;
		gint _param_collection_size_ = 0;
		gint param_it = 0;
		param_collection = _tmp28_;
		param_collection_length1 = _vala_array_length (_tmp27_);
		for (param_it = 0; param_it < param_collection_length1; param_it = param_it + 1) {
			gchar* _tmp29_;
			gchar* param = NULL;
			_tmp29_ = g_strdup (param_collection[param_it]);
			param = _tmp29_;
			{
				const gchar* _tmp30_;
				gint _tmp31_;
				gint _tmp32_;
				gint eq = 0;
				const gchar* _tmp33_;
				gchar* _tmp34_ = NULL;
				gchar* name = NULL;
				gchar* _tmp39_;
				const gchar* _tmp40_;
				GString* _tmp41_;
				GString* _tmp43_;
				const gchar* _tmp44_;
				_tmp30_ = param;
				_tmp31_ = strlen (_tmp30_);
				_tmp32_ = _tmp31_;
				if (_tmp32_ == 0) {
					_g_free0 (param);
					continue;
				}
				_tmp33_ = param;
				eq = string_index_of_char (_tmp33_, (gunichar) '=', 0);
				if (eq >= 0) {
					const gchar* _tmp35_;
					gchar* _tmp36_;
					_tmp35_ = param;
					_tmp36_ = string_slice (_tmp35_, (glong) 0, (glong) eq);
					_g_free0 (_tmp34_);
					_tmp34_ = _tmp36_;
				} else {
					const gchar* _tmp37_;
					gchar* _tmp38_;
					_tmp37_ = param;
					_tmp38_ = g_strdup (_tmp37_);
					_g_free0 (_tmp34_);
					_tmp34_ = _tmp38_;
				}
				_tmp39_ = g_utf8_strdown (_tmp34_, (gssize) -1);
				name = _tmp39_;
				_tmp40_ = name;
				if (dc_link_cleaner_is_tracking_param (_tmp40_, site)) {
					_g_free0 (name);
					_g_free0 (_tmp34_);
					_g_free0 (param);
					continue;
				}
				_tmp41_ = kept;
				if (_tmp41_->len > ((gssize) 0)) {
					GString* _tmp42_;
					_tmp42_ = kept;
					g_string_append_c (_tmp42_, '&');
				}
				_tmp43_ = kept;
				_tmp44_ = param;
				g_string_append (_tmp43_, _tmp44_);
				_g_free0 (name);
				_g_free0 (_tmp34_);
				_g_free0 (param);
			}
		}
		param_collection = (_vala_array_free (param_collection, param_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp46_ = kept;
	if (_tmp46_->len > ((gssize) 0)) {
		const gchar* _tmp47_;
		gchar* _tmp48_;
		gchar* _tmp49_;
		GString* _tmp50_;
		const gchar* _tmp51_;
		gchar* _tmp52_;
		_tmp47_ = base_part;
		_tmp48_ = g_strconcat (_tmp47_, "?", NULL);
		_tmp49_ = _tmp48_;
		_tmp50_ = kept;
		_tmp51_ = _tmp50_->str;
		_tmp52_ = g_strconcat (_tmp49_, _tmp51_, NULL);
		_g_free0 (_tmp45_);
		_tmp45_ = _tmp52_;
		_g_free0 (_tmp49_);
	} else {
		const gchar* _tmp53_;
		gchar* _tmp54_;
		_tmp53_ = base_part;
		_tmp54_ = g_strdup (_tmp53_);
		_g_free0 (_tmp45_);
		_tmp45_ = _tmp54_;
	}
	_tmp55_ = _tmp45_;
	_tmp45_ = NULL;
	cleaned = _tmp55_;
	_tmp56_ = cleaned;
	_tmp57_ = fragment;
	_tmp58_ = g_strconcat (_tmp56_, _tmp57_, NULL);
	result = _tmp58_;
	_g_free0 (cleaned);
	_g_free0 (_tmp45_);
	_g_string_free0 (kept);
	_g_free0 (query);
	_g_free0 (fragment);
	_g_free0 (_tmp10_);
	_g_free0 (base_part);
	_g_free0 (host);
	return result;
}

static gboolean
dc_link_cleaner_is_tracking_param (const gchar* name,
                                   gint site)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	if (dc_link_cleaner_has_word (DC_LINK_CLEANER_GLOBAL_PARAMS, name)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = dc_link_cleaner_has_prefix_in (DC_LINK_CLEANER_GLOBAL_PREFIXES, name);
	}
	if (_tmp0_) {
		result = TRUE;
		return result;
	}
	if (site >= 0) {
		gboolean _tmp2_ = FALSE;
		DcLinkCleanerSiteRule _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = DC_LINK_CLEANER_SITE_RULES[site];
		_tmp4_ = _tmp3_.params;
		if (dc_link_cleaner_has_word (_tmp4_, name)) {
			_tmp2_ = TRUE;
		} else {
			DcLinkCleanerSiteRule _tmp5_;
			const gchar* _tmp6_;
			_tmp5_ = DC_LINK_CLEANER_SITE_RULES[site];
			_tmp6_ = _tmp5_.prefixes;
			_tmp2_ = dc_link_cleaner_has_prefix_in (_tmp6_, name);
		}
		_tmp1_ = _tmp2_;
	} else {
		_tmp1_ = FALSE;
	}
	result = _tmp1_;
	return result;
}

static gint
dc_link_cleaner_site_rule_for (const gchar* host)
{
	gint result;
	g_return_val_if_fail (host != NULL, -1);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				DcLinkCleanerSiteRule _tmp2_;
				const gchar* _tmp3_;
				gchar** _tmp4_;
				gchar** _tmp5_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < G_N_ELEMENTS (DC_LINK_CLEANER_SITE_RULES))) {
					break;
				}
				_tmp2_ = DC_LINK_CLEANER_SITE_RULES[i];
				_tmp3_ = _tmp2_.hosts;
				_tmp5_ = _tmp4_ = g_strsplit (_tmp3_, " ", 0);
				{
					gchar** pattern_collection = NULL;
					gint pattern_collection_length1 = 0;
					gint _pattern_collection_size_ = 0;
					gint pattern_it = 0;
					pattern_collection = _tmp5_;
					pattern_collection_length1 = _vala_array_length (_tmp4_);
					for (pattern_it = 0; pattern_it < pattern_collection_length1; pattern_it = pattern_it + 1) {
						gchar* _tmp6_;
						gchar* pattern = NULL;
						_tmp6_ = g_strdup (pattern_collection[pattern_it]);
						pattern = _tmp6_;
						{
							const gchar* _tmp7_;
							_tmp7_ = pattern;
							if (dc_link_cleaner_host_matches (host, _tmp7_)) {
								result = i;
								_g_free0 (pattern);
								pattern_collection = (_vala_array_free (pattern_collection, pattern_collection_length1, (GDestroyNotify) g_free), NULL);
								return result;
							}
							_g_free0 (pattern);
						}
					}
					pattern_collection = (_vala_array_free (pattern_collection, pattern_collection_length1, (GDestroyNotify) g_free), NULL);
				}
			}
		}
	}
	result = -1;
	return result;
}

/** Lowercased host without userinfo, port, or a leading www./m. */
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
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;
}

static gint
string_last_index_of_char (const gchar* self,
                           gunichar c,
                           gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_strrchr (((gchar*) self) + start_index, (gssize) -1, c);
	_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_link_cleaner_host_of (const gchar* url)
{
	gint scheme_end = 0;
	gint start = 0;
	gint end = 0;
	gchar* host = NULL;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gint at = 0;
	const gchar* _tmp10_;
	gint colon = 0;
	const gchar* _tmp13_;
	const gchar* _tmp16_;
	gchar* result;
	g_return_val_if_fail (url != NULL, NULL);
	scheme_end = string_index_of (url, "://", 0);
	if (scheme_end < 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("");
		result = _tmp0_;
		return result;
	}
	start = scheme_end + 3;
	end = start;
	while (TRUE) {
		gint _tmp1_;
		gint _tmp2_;
		gchar c = '\0';
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		gint _tmp5_;
		_tmp1_ = strlen (url);
		_tmp2_ = _tmp1_;
		if (!(end < _tmp2_)) {
			break;
		}
		c = string_get (url, (glong) end);
		if (c == '/') {
			_tmp4_ = TRUE;
		} else {
			_tmp4_ = c == '?';
		}
		if (_tmp4_) {
			_tmp3_ = TRUE;
		} else {
			_tmp3_ = c == '#';
		}
		if (_tmp3_) {
			break;
		}
		_tmp5_ = end;
		end = _tmp5_ + 1;
	}
	_tmp6_ = string_slice (url, (glong) start, (glong) end);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_utf8_strdown (_tmp7_, (gssize) -1);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	host = _tmp9_;
	_tmp10_ = host;
	at = string_last_index_of_char (_tmp10_, (gunichar) '@', 0);
	if (at >= 0) {
		const gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp11_ = host;
		_tmp12_ = string_substring (_tmp11_, (glong) (at + 1), (glong) -1);
		_g_free0 (host);
		host = _tmp12_;
	}
	_tmp13_ = host;
	colon = string_index_of_char (_tmp13_, (gunichar) ':', 0);
	if (colon >= 0) {
		const gchar* _tmp14_;
		gchar* _tmp15_;
		_tmp14_ = host;
		_tmp15_ = string_slice (_tmp14_, (glong) 0, (glong) colon);
		_g_free0 (host);
		host = _tmp15_;
	}
	_tmp16_ = host;
	if (g_str_has_prefix (_tmp16_, "www.")) {
		const gchar* _tmp17_;
		gchar* _tmp18_;
		_tmp17_ = host;
		_tmp18_ = string_substring (_tmp17_, (glong) 4, (glong) -1);
		_g_free0 (host);
		host = _tmp18_;
	} else {
		const gchar* _tmp19_;
		_tmp19_ = host;
		if (g_str_has_prefix (_tmp19_, "m.")) {
			const gchar* _tmp20_;
			gchar* _tmp21_;
			_tmp20_ = host;
			_tmp21_ = string_substring (_tmp20_, (glong) 2, (glong) -1);
			_g_free0 (host);
			host = _tmp21_;
		}
	}
	result = host;
	return result;
}

static gboolean
dc_link_cleaner_host_matches (const gchar* host,
                              const gchar* pattern)
{
	gboolean _tmp7_ = FALSE;
	gboolean result;
	g_return_val_if_fail (host != NULL, FALSE);
	g_return_val_if_fail (pattern != NULL, FALSE);
	if (g_str_has_suffix (pattern, ".*")) {
		gint idx = 0;
		gint _tmp0_;
		gint _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gint _tmp4_;
		gboolean _tmp5_ = FALSE;
		_tmp0_ = strlen (pattern);
		_tmp1_ = _tmp0_;
		_tmp2_ = string_slice (pattern, (glong) 0, (glong) (_tmp1_ - 1));
		_tmp3_ = _tmp2_;
		_tmp4_ = string_index_of (host, _tmp3_, 0);
		_g_free0 (_tmp3_);
		idx = _tmp4_;
		if (idx == 0) {
			_tmp5_ = TRUE;
		} else {
			gboolean _tmp6_ = FALSE;
			if (idx > 0) {
				_tmp6_ = string_get (host, (glong) (idx - 1)) == '.';
			} else {
				_tmp6_ = FALSE;
			}
			_tmp5_ = _tmp6_;
		}
		result = _tmp5_;
		return result;
	}
	if (g_strcmp0 (host, pattern) == 0) {
		_tmp7_ = TRUE;
	} else {
		gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp8_ = g_strconcat (".", pattern, NULL);
		_tmp9_ = _tmp8_;
		_tmp7_ = g_str_has_suffix (host, _tmp9_);
		_g_free0 (_tmp9_);
	}
	result = _tmp7_;
	return result;
}

static gchar*
dc_link_cleaner_strip_amazon_ref_path (const gchar* base_part)
{
	gint idx = 0;
	gchar* _tmp0_ = NULL;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (base_part != NULL, NULL);
	idx = string_index_of (base_part, "/ref=", 0);
	if (idx >= 0) {
		gchar* _tmp1_;
		_tmp1_ = string_slice (base_part, (glong) 0, (glong) idx);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp1_;
	} else {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (base_part);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp3_;
	_g_free0 (_tmp0_);
	return result;
}

static gint
dc_link_cleaner_find_url_start (const gchar* text,
                                gint pos)
{
	gint idx = 0;
	gint result;
	g_return_val_if_fail (text != NULL, -1);
	idx = string_index_of (text, "http", pos);
	while (TRUE) {
		gchar* rest = NULL;
		gchar* _tmp0_;
		gboolean _tmp1_ = FALSE;
		const gchar* _tmp2_;
		if (!(idx >= 0)) {
			break;
		}
		_tmp0_ = string_substring (text, (glong) idx, (glong) -1);
		rest = _tmp0_;
		_tmp2_ = rest;
		if (g_str_has_prefix (_tmp2_, "http://")) {
			_tmp1_ = TRUE;
		} else {
			const gchar* _tmp3_;
			_tmp3_ = rest;
			_tmp1_ = g_str_has_prefix (_tmp3_, "https://");
		}
		if (_tmp1_) {
			result = idx;
			_g_free0 (rest);
			return result;
		}
		idx = string_index_of (text, "http", idx + 4);
		_g_free0 (rest);
	}
	result = -1;
	return result;
}

static gint
dc_link_cleaner_find_url_end (const gchar* text,
                              gint start)
{
	gint end = 0;
	gint result;
	g_return_val_if_fail (text != NULL, -1);
	end = start;
	while (TRUE) {
		gint _tmp0_;
		gint _tmp1_;
		gchar c = '\0';
		gboolean _tmp2_ = FALSE;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		gboolean _tmp7_ = FALSE;
		gboolean _tmp8_ = FALSE;
		gint _tmp9_;
		_tmp0_ = strlen (text);
		_tmp1_ = _tmp0_;
		if (!(end < _tmp1_)) {
			break;
		}
		c = string_get (text, (glong) end);
		if (c == ' ') {
			_tmp8_ = TRUE;
		} else {
			_tmp8_ = c == '\t';
		}
		if (_tmp8_) {
			_tmp7_ = TRUE;
		} else {
			_tmp7_ = c == '\n';
		}
		if (_tmp7_) {
			_tmp6_ = TRUE;
		} else {
			_tmp6_ = c == '\r';
		}
		if (_tmp6_) {
			_tmp5_ = TRUE;
		} else {
			_tmp5_ = c == '<';
		}
		if (_tmp5_) {
			_tmp4_ = TRUE;
		} else {
			_tmp4_ = c == '>';
		}
		if (_tmp4_) {
			_tmp3_ = TRUE;
		} else {
			_tmp3_ = c == '"';
		}
		if (_tmp3_) {
			_tmp2_ = TRUE;
		} else {
			_tmp2_ = c == '\'';
		}
		if (_tmp2_) {
			break;
		}
		_tmp9_ = end;
		end = _tmp9_ + 1;
	}
	while (TRUE) {
		gchar c = '\0';
		gboolean _tmp10_ = FALSE;
		gboolean _tmp11_ = FALSE;
		gboolean _tmp12_ = FALSE;
		gboolean _tmp13_ = FALSE;
		gboolean _tmp14_ = FALSE;
		if (!(end > start)) {
			break;
		}
		c = string_get (text, (glong) (end - 1));
		if (c == '.') {
			_tmp14_ = TRUE;
		} else {
			_tmp14_ = c == ',';
		}
		if (_tmp14_) {
			_tmp13_ = TRUE;
		} else {
			_tmp13_ = c == ';';
		}
		if (_tmp13_) {
			_tmp12_ = TRUE;
		} else {
			_tmp12_ = c == ':';
		}
		if (_tmp12_) {
			_tmp11_ = TRUE;
		} else {
			_tmp11_ = c == '!';
		}
		if (_tmp11_) {
			_tmp10_ = TRUE;
		} else {
			_tmp10_ = c == '?';
		}
		if (_tmp10_) {
			gint _tmp15_;
			_tmp15_ = end;
			end = _tmp15_ - 1;
		} else {
			gboolean _tmp16_ = FALSE;
			gboolean _tmp17_ = FALSE;
			if (c == ')') {
				_tmp17_ = !dc_link_cleaner_is_balanced (text, start, end, '(', ')');
			} else {
				_tmp17_ = FALSE;
			}
			if (_tmp17_) {
				_tmp16_ = TRUE;
			} else {
				gboolean _tmp18_ = FALSE;
				if (c == ']') {
					_tmp18_ = !dc_link_cleaner_is_balanced (text, start, end, '[', ']');
				} else {
					_tmp18_ = FALSE;
				}
				_tmp16_ = _tmp18_;
			}
			if (_tmp16_) {
				gint _tmp19_;
				_tmp19_ = end;
				end = _tmp19_ - 1;
			} else {
				break;
			}
		}
	}
	result = end;
	return result;
}

static gboolean
dc_link_cleaner_is_balanced (const gchar* text,
                             gint start,
                             gint end,
                             gchar open,
                             gchar close)
{
	gint depth = 0;
	gboolean result;
	g_return_val_if_fail (text != NULL, FALSE);
	depth = 0;
	{
		gint i = 0;
		i = start;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < end)) {
					break;
				}
				if (string_get (text, (glong) i) == open) {
					gint _tmp2_;
					_tmp2_ = depth;
					depth = _tmp2_ + 1;
				} else {
					if (string_get (text, (glong) i) == close) {
						gint _tmp3_;
						_tmp3_ = depth;
						depth = _tmp3_ - 1;
					}
				}
			}
		}
	}
	result = depth >= 0;
	return result;
}

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

static gboolean
dc_link_cleaner_has_word (const gchar* words,
                          const gchar* word)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gboolean _tmp8_;
	gboolean result;
	g_return_val_if_fail (words != NULL, FALSE);
	g_return_val_if_fail (word != NULL, FALSE);
	_tmp0_ = g_strconcat (" ", words, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, " ", NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (" ", word, NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp5_, " ", NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = string_contains (_tmp3_, _tmp7_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp8_;
	return result;
}

static gboolean
dc_link_cleaner_has_prefix_in (const gchar* prefixes,
                               const gchar* name)
{
	gchar** _tmp0_;
	gchar** _tmp1_;
	gboolean result;
	g_return_val_if_fail (prefixes != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp1_ = _tmp0_ = g_strsplit (prefixes, " ", 0);
	{
		gchar** prefix_collection = NULL;
		gint prefix_collection_length1 = 0;
		gint _prefix_collection_size_ = 0;
		gint prefix_it = 0;
		prefix_collection = _tmp1_;
		prefix_collection_length1 = _vala_array_length (_tmp0_);
		for (prefix_it = 0; prefix_it < prefix_collection_length1; prefix_it = prefix_it + 1) {
			gchar* _tmp2_;
			gchar* prefix = NULL;
			_tmp2_ = g_strdup (prefix_collection[prefix_it]);
			prefix = _tmp2_;
			{
				gboolean _tmp3_ = FALSE;
				const gchar* _tmp4_;
				gint _tmp5_;
				gint _tmp6_;
				_tmp4_ = prefix;
				_tmp5_ = strlen (_tmp4_);
				_tmp6_ = _tmp5_;
				if (_tmp6_ > 0) {
					const gchar* _tmp7_;
					_tmp7_ = prefix;
					_tmp3_ = g_str_has_prefix (name, _tmp7_);
				} else {
					_tmp3_ = FALSE;
				}
				if (_tmp3_) {
					result = TRUE;
					_g_free0 (prefix);
					prefix_collection = (_vala_array_free (prefix_collection, prefix_collection_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_g_free0 (prefix);
			}
		}
		prefix_collection = (_vala_array_free (prefix_collection, prefix_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = FALSE;
	return result;
}

DcLinkCleaner*
dc_link_cleaner_construct (GType object_type)
{
	DcLinkCleaner * self = NULL;
	self = (DcLinkCleaner*) g_object_new (object_type, NULL);
	return self;
}

DcLinkCleaner*
dc_link_cleaner_new (void)
{
	return dc_link_cleaner_construct (DC_TYPE_LINK_CLEANER);
}

static DcLinkCleanerSiteRule*
dc_link_cleaner_site_rule_dup (const DcLinkCleanerSiteRule* self)
{
	DcLinkCleanerSiteRule* dup;
	dup = g_new0 (DcLinkCleanerSiteRule, 1);
	memcpy (dup, self, sizeof (DcLinkCleanerSiteRule));
	return dup;
}

static void
dc_link_cleaner_site_rule_free (DcLinkCleanerSiteRule* self)
{
	g_free (self);
}

static GType
dc_link_cleaner_site_rule_get_type_once (void)
{
	GType dc_link_cleaner_site_rule_type_id;
	dc_link_cleaner_site_rule_type_id = g_boxed_type_register_static ("DcLinkCleanerSiteRule", (GBoxedCopyFunc) dc_link_cleaner_site_rule_dup, (GBoxedFreeFunc) dc_link_cleaner_site_rule_free);
	return dc_link_cleaner_site_rule_type_id;
}

static GType
dc_link_cleaner_site_rule_get_type (void)
{
	static volatile gsize dc_link_cleaner_site_rule_type_id__once = 0;
	if (g_once_init_enter (&dc_link_cleaner_site_rule_type_id__once)) {
		GType dc_link_cleaner_site_rule_type_id;
		dc_link_cleaner_site_rule_type_id = dc_link_cleaner_site_rule_get_type_once ();
		g_once_init_leave (&dc_link_cleaner_site_rule_type_id__once, dc_link_cleaner_site_rule_type_id);
	}
	return dc_link_cleaner_site_rule_type_id__once;
}

static void
dc_link_cleaner_class_init (DcLinkCleanerClass * klass,
                            gpointer klass_data)
{
	dc_link_cleaner_parent_class = g_type_class_peek_parent (klass);
}

static void
dc_link_cleaner_instance_init (DcLinkCleaner * self,
                               gpointer klass)
{
}

/**
     * Strips well-known tracking parameters from http(s) URLs found in
     * text pasted into the compose bar. Parameters that carry content
     * (video id, timestamp, playlist, search terms) are preserved;
     * everything else is left byte-for-byte untouched.
     */
static GType
dc_link_cleaner_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcLinkCleanerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_link_cleaner_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcLinkCleaner), 0, (GInstanceInitFunc) dc_link_cleaner_instance_init, NULL };
	GType dc_link_cleaner_type_id;
	dc_link_cleaner_type_id = g_type_register_static (G_TYPE_OBJECT, "DcLinkCleaner", &g_define_type_info, 0);
	return dc_link_cleaner_type_id;
}

GType
dc_link_cleaner_get_type (void)
{
	static volatile gsize dc_link_cleaner_type_id__once = 0;
	if (g_once_init_enter (&dc_link_cleaner_type_id__once)) {
		GType dc_link_cleaner_type_id;
		dc_link_cleaner_type_id = dc_link_cleaner_get_type_once ();
		g_once_init_leave (&dc_link_cleaner_type_id__once, dc_link_cleaner_type_id);
	}
	return dc_link_cleaner_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;
}

