/* 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>

#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 _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

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

struct _DcLinkCleanerClass {
	GObjectClass parent_class;
};

static gpointer dc_link_cleaner_parent_class = NULL;

VALA_EXTERN GType dc_link_cleaner_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcLinkCleaner, g_object_unref)
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);
static gchar* dc_link_cleaner_host_of (const gchar* url);
static gboolean dc_link_cleaner_host_is_brand (const gchar* host,
                                        const gchar* brand);
static gchar* dc_link_cleaner_strip_amazon_ref_path (const gchar* base_part);
static void dc_link_cleaner_rules_for_host (const gchar* host,
                                     gchar*** params,
                                     gint* params_length1,
                                     gchar*** prefixes,
                                     gint* prefixes_length1);
static gboolean dc_link_cleaner_is_tracking_param (const gchar* name,
                                            gchar** site_params,
                                            gint site_params_length1,
                                            gchar** site_prefixes,
                                            gint site_prefixes_length1);
static gboolean dc_link_cleaner_contains (gchar** haystack,
                                   gint haystack_length1,
                                   const gchar* needle);
static gboolean dc_link_cleaner_has_any_prefix (const gchar* name,
                                         gchar** prefixes,
                                         gint prefixes_length1);
static gchar** _vala_array_dup9 (gchar** self,
                          gssize length);
static gchar** _vala_array_dup10 (gchar** self,
                           gssize length);
static gboolean dc_link_cleaner_host_is (const gchar* host,
                                  const gchar* domain);
static gchar** _vala_array_dup11 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup12 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup13 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup14 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup15 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup16 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup17 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup18 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup19 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup20 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup21 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup22 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup23 (gchar** self,
                           gssize length);
static gchar** _vala_array_dup24 (gchar** self,
                           gssize length);
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 const gchar* DC_LINK_CLEANER_GLOBAL_PARAMS[23] = {"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"};
static const gchar* DC_LINK_CLEANER_GLOBAL_PREFIXES[5] = {"utm_", "pk_", "mtm_", "piwik_", "hsa_"};
static const gchar* DC_LINK_CLEANER_YOUTUBE_PARAMS[6] = {"si", "feature", "pp", "ab_channel", "embeds_referring_euri", "source_ve_path"};
static const gchar* DC_LINK_CLEANER_X_PARAMS[4] = {"s", "t", "ref_src", "ref_url"};
static const gchar* DC_LINK_CLEANER_INSTAGRAM_PARAMS[4] = {"igsh", "ig_rid", "ig_mid", "xmt"};
static const gchar* DC_LINK_CLEANER_FACEBOOK_PARAMS[14] = {"mibextid", "rdid", "share_url", "refid", "ref", "fref", "hc_ref", "sfnsn", "wtsid", "paipv", "eav", "comment_tracking", "notif_id", "notif_t"};
static const gchar* DC_LINK_CLEANER_FACEBOOK_PREFIXES[1] = {"__"};
static const gchar* DC_LINK_CLEANER_LINKEDIN_PARAMS[11] = {"trk", "trackingid", "lipi", "midtoken", "midsig", "trkemail", "ebp", "refid", "otptoken", "original_referer", "rcm"};
static const gchar* DC_LINK_CLEANER_TIKTOK_PARAMS[14] = {"_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"};
static const gchar* DC_LINK_CLEANER_REDDIT_PARAMS[5] = {"share_id", "ref", "ref_source", "rdt", "correlation_id"};
static const gchar* DC_LINK_CLEANER_SPOTIFY_PARAMS[4] = {"si", "nd", "_branch_match_id", "_branch_referrer"};
static const gchar* DC_LINK_CLEANER_AMAZON_PARAMS[17] = {"tag", "ref", "ref_", "ascsubtag", "linkcode", "linkid", "camp", "creative", "creativeasin", "qid", "sr", "sprefix", "crid", "dib", "dib_tag", "content-id", "social_share"};
static const gchar* DC_LINK_CLEANER_AMAZON_PREFIXES[2] = {"pf_rd_", "pd_rd_"};
static const gchar* DC_LINK_CLEANER_EBAY_PARAMS[12] = {"mkcid", "mkevt", "mkrid", "ssspo", "sssrc", "ssuid", "campid", "toolid", "customid", "mkpid", "ul_noapp", "amdata"};
static const gchar* DC_LINK_CLEANER_ALIEXPRESS_PARAMS[12] = {"spm", "scm", "aff_platform", "aff_trace_key", "aff_fcid", "aff_fsk", "terminal_id", "pdp_npi", "gatewayadapt", "algo_pvid", "algo_exp_id", "utparam-url"};
static const gchar* DC_LINK_CLEANER_TWITCH_PARAMS[2] = {"tt_content", "tt_medium"};
static const gchar* DC_LINK_CLEANER_EMPTY[0] = {};

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

/** Strips tracking query parameters (and Amazon's /ref= path
            suffix) from a single URL. */
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)
{
	gchar* host = NULL;
	gchar* _tmp0_;
	gint frag_start = 0;
	gint query_start = 0;
	gboolean _tmp1_ = FALSE;
	gint _tmp2_ = 0;
	gint base_end = 0;
	gchar* base_part = NULL;
	gchar* _tmp6_;
	gchar* _tmp7_ = NULL;
	gchar* fragment = NULL;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	gint _tmp17_ = 0;
	gint query_end = 0;
	gchar* query = NULL;
	gchar* _tmp20_;
	gchar** site_params = NULL;
	gint site_params_length1 = 0;
	gint _site_params_size_ = 0;
	gchar** site_prefixes = NULL;
	gint site_prefixes_length1 = 0;
	gint _site_prefixes_size_ = 0;
	const gchar* _tmp21_;
	gchar** _tmp22_ = NULL;
	gint _tmp23_ = 0;
	gchar** _tmp24_ = NULL;
	gint _tmp25_ = 0;
	GString* kept = NULL;
	GString* _tmp26_;
	const gchar* _tmp27_;
	gchar** _tmp28_;
	gchar** _tmp29_;
	gchar* _tmp48_ = NULL;
	GString* _tmp49_;
	gchar* cleaned = NULL;
	gchar* _tmp58_;
	const gchar* _tmp59_;
	const gchar* _tmp60_;
	gchar* _tmp61_;
	gchar* result;
	g_return_val_if_fail (url != NULL, NULL);
	_tmp0_ = dc_link_cleaner_host_of (url);
	host = _tmp0_;
	frag_start = string_index_of_char (url, (gunichar) '#', 0);
	query_start = string_index_of_char (url, (gunichar) '?', 0);
	if (frag_start >= 0) {
		_tmp1_ = query_start > frag_start;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		query_start = -1;
	}
	if (query_start >= 0) {
		_tmp2_ = query_start;
	} else {
		gint _tmp3_ = 0;
		if (frag_start >= 0) {
			_tmp3_ = frag_start;
		} else {
			gint _tmp4_;
			gint _tmp5_;
			_tmp4_ = strlen (url);
			_tmp5_ = _tmp4_;
			_tmp3_ = _tmp5_;
		}
		_tmp2_ = _tmp3_;
	}
	base_end = _tmp2_;
	_tmp6_ = string_slice (url, (glong) 0, (glong) base_end);
	base_part = _tmp6_;
	if (frag_start >= 0) {
		gchar* _tmp8_;
		_tmp8_ = string_substring (url, (glong) frag_start, (glong) -1);
		_g_free0 (_tmp7_);
		_tmp7_ = _tmp8_;
	} else {
		gchar* _tmp9_;
		_tmp9_ = g_strdup ("");
		_g_free0 (_tmp7_);
		_tmp7_ = _tmp9_;
	}
	_tmp10_ = _tmp7_;
	_tmp7_ = NULL;
	fragment = _tmp10_;
	_tmp11_ = host;
	if (dc_link_cleaner_host_is_brand (_tmp11_, "amazon")) {
		const gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp12_ = base_part;
		_tmp13_ = dc_link_cleaner_strip_amazon_ref_path (_tmp12_);
		_g_free0 (base_part);
		base_part = _tmp13_;
	}
	if (query_start < 0) {
		const gchar* _tmp14_;
		const gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp14_ = base_part;
		_tmp15_ = fragment;
		_tmp16_ = g_strconcat (_tmp14_, _tmp15_, NULL);
		result = _tmp16_;
		_g_free0 (fragment);
		_g_free0 (_tmp7_);
		_g_free0 (base_part);
		_g_free0 (host);
		return result;
	}
	if (frag_start >= 0) {
		_tmp17_ = frag_start;
	} else {
		gint _tmp18_;
		gint _tmp19_;
		_tmp18_ = strlen (url);
		_tmp19_ = _tmp18_;
		_tmp17_ = _tmp19_;
	}
	query_end = _tmp17_;
	_tmp20_ = string_slice (url, (glong) (query_start + 1), (glong) query_end);
	query = _tmp20_;
	_tmp21_ = host;
	dc_link_cleaner_rules_for_host (_tmp21_, &_tmp22_, &_tmp23_, &_tmp24_, &_tmp25_);
	site_params = (_vala_array_free (site_params, site_params_length1, (GDestroyNotify) g_free), NULL);
	site_params = _tmp22_;
	site_params_length1 = _tmp23_;
	_site_params_size_ = site_params_length1;
	site_prefixes = (_vala_array_free (site_prefixes, site_prefixes_length1, (GDestroyNotify) g_free), NULL);
	site_prefixes = _tmp24_;
	site_prefixes_length1 = _tmp25_;
	_site_prefixes_size_ = site_prefixes_length1;
	_tmp26_ = g_string_new ("");
	kept = _tmp26_;
	_tmp27_ = query;
	_tmp29_ = _tmp28_ = g_strsplit (_tmp27_, "&", 0);
	{
		gchar** param_collection = NULL;
		gint param_collection_length1 = 0;
		gint _param_collection_size_ = 0;
		gint param_it = 0;
		param_collection = _tmp29_;
		param_collection_length1 = _vala_array_length (_tmp28_);
		for (param_it = 0; param_it < param_collection_length1; param_it = param_it + 1) {
			gchar* _tmp30_;
			gchar* param = NULL;
			_tmp30_ = g_strdup (param_collection[param_it]);
			param = _tmp30_;
			{
				const gchar* _tmp31_;
				gint _tmp32_;
				gint _tmp33_;
				gint eq = 0;
				const gchar* _tmp34_;
				gchar* _tmp35_ = NULL;
				gchar* name = NULL;
				gchar* _tmp40_;
				const gchar* _tmp41_;
				gchar** _tmp42_;
				gint _tmp42__length1;
				gchar** _tmp43_;
				gint _tmp43__length1;
				GString* _tmp44_;
				GString* _tmp46_;
				const gchar* _tmp47_;
				_tmp31_ = param;
				_tmp32_ = strlen (_tmp31_);
				_tmp33_ = _tmp32_;
				if (_tmp33_ == 0) {
					_g_free0 (param);
					continue;
				}
				_tmp34_ = param;
				eq = string_index_of_char (_tmp34_, (gunichar) '=', 0);
				if (eq >= 0) {
					const gchar* _tmp36_;
					gchar* _tmp37_;
					_tmp36_ = param;
					_tmp37_ = string_slice (_tmp36_, (glong) 0, (glong) eq);
					_g_free0 (_tmp35_);
					_tmp35_ = _tmp37_;
				} else {
					const gchar* _tmp38_;
					gchar* _tmp39_;
					_tmp38_ = param;
					_tmp39_ = g_strdup (_tmp38_);
					_g_free0 (_tmp35_);
					_tmp35_ = _tmp39_;
				}
				_tmp40_ = g_utf8_strdown (_tmp35_, (gssize) -1);
				name = _tmp40_;
				_tmp41_ = name;
				_tmp42_ = site_params;
				_tmp42__length1 = site_params_length1;
				_tmp43_ = site_prefixes;
				_tmp43__length1 = site_prefixes_length1;
				if (dc_link_cleaner_is_tracking_param (_tmp41_, _tmp42_, (gint) _tmp42__length1, _tmp43_, (gint) _tmp43__length1)) {
					_g_free0 (name);
					_g_free0 (_tmp35_);
					_g_free0 (param);
					continue;
				}
				_tmp44_ = kept;
				if (_tmp44_->len > ((gssize) 0)) {
					GString* _tmp45_;
					_tmp45_ = kept;
					g_string_append_c (_tmp45_, '&');
				}
				_tmp46_ = kept;
				_tmp47_ = param;
				g_string_append (_tmp46_, _tmp47_);
				_g_free0 (name);
				_g_free0 (_tmp35_);
				_g_free0 (param);
			}
		}
		param_collection = (_vala_array_free (param_collection, param_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp49_ = kept;
	if (_tmp49_->len > ((gssize) 0)) {
		const gchar* _tmp50_;
		gchar* _tmp51_;
		gchar* _tmp52_;
		GString* _tmp53_;
		const gchar* _tmp54_;
		gchar* _tmp55_;
		_tmp50_ = base_part;
		_tmp51_ = g_strconcat (_tmp50_, "?", NULL);
		_tmp52_ = _tmp51_;
		_tmp53_ = kept;
		_tmp54_ = _tmp53_->str;
		_tmp55_ = g_strconcat (_tmp52_, _tmp54_, NULL);
		_g_free0 (_tmp48_);
		_tmp48_ = _tmp55_;
		_g_free0 (_tmp52_);
	} else {
		const gchar* _tmp56_;
		gchar* _tmp57_;
		_tmp56_ = base_part;
		_tmp57_ = g_strdup (_tmp56_);
		_g_free0 (_tmp48_);
		_tmp48_ = _tmp57_;
	}
	_tmp58_ = _tmp48_;
	_tmp48_ = NULL;
	cleaned = _tmp58_;
	_tmp59_ = cleaned;
	_tmp60_ = fragment;
	_tmp61_ = g_strconcat (_tmp59_, _tmp60_, NULL);
	result = _tmp61_;
	_g_free0 (cleaned);
	_g_free0 (_tmp48_);
	_g_string_free0 (kept);
	site_prefixes = (_vala_array_free (site_prefixes, site_prefixes_length1, (GDestroyNotify) g_free), NULL);
	site_params = (_vala_array_free (site_params, site_params_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (query);
	_g_free0 (fragment);
	_g_free0 (_tmp7_);
	_g_free0 (base_part);
	_g_free0 (host);
	return result;
}

static gboolean
dc_link_cleaner_is_tracking_param (const gchar* name,
                                   gchar** site_params,
                                   gint site_params_length1,
                                   gchar** site_prefixes,
                                   gint site_prefixes_length1)
{
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	if (dc_link_cleaner_contains (DC_LINK_CLEANER_GLOBAL_PARAMS, (gint) G_N_ELEMENTS (DC_LINK_CLEANER_GLOBAL_PARAMS), name)) {
		result = TRUE;
		return result;
	}
	if (dc_link_cleaner_has_any_prefix (name, DC_LINK_CLEANER_GLOBAL_PREFIXES, (gint) G_N_ELEMENTS (DC_LINK_CLEANER_GLOBAL_PREFIXES))) {
		result = TRUE;
		return result;
	}
	if (dc_link_cleaner_contains (site_params, (gint) site_params_length1, name)) {
		result = TRUE;
		return result;
	}
	result = dc_link_cleaner_has_any_prefix (name, site_prefixes, (gint) site_prefixes_length1);
	return result;
}

static gchar**
_vala_array_dup9 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup10 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup11 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup12 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup13 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup14 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup15 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup16 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup17 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup18 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup19 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup20 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup21 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup22 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup23 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup24 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static void
dc_link_cleaner_rules_for_host (const gchar* host,
                                gchar*** params,
                                gint* params_length1,
                                gchar*** prefixes,
                                gint* prefixes_length1)
{
	gchar** _vala_params = NULL;
	gint _vala_params_length1 = 0;
	gchar** _vala_prefixes = NULL;
	gint _vala_prefixes_length1 = 0;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (host != NULL);
	_tmp0_ = _vala_array_dup9 (DC_LINK_CLEANER_EMPTY, G_N_ELEMENTS (DC_LINK_CLEANER_EMPTY));
	_tmp0__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_EMPTY);
	_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
	_vala_params = _tmp0_;
	_vala_params_length1 = _tmp0__length1;
	_tmp1_ = _vala_array_dup10 (DC_LINK_CLEANER_EMPTY, G_N_ELEMENTS (DC_LINK_CLEANER_EMPTY));
	_tmp1__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_EMPTY);
	_vala_prefixes = (_vala_array_free (_vala_prefixes, _vala_prefixes_length1, (GDestroyNotify) g_free), NULL);
	_vala_prefixes = _tmp1_;
	_vala_prefixes_length1 = _tmp1__length1;
	if (dc_link_cleaner_host_is (host, "youtube.com")) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = dc_link_cleaner_host_is (host, "youtu.be");
	}
	if (_tmp2_) {
		gchar** _tmp3_;
		gint _tmp3__length1;
		_tmp3_ = _vala_array_dup11 (DC_LINK_CLEANER_YOUTUBE_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_YOUTUBE_PARAMS));
		_tmp3__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_YOUTUBE_PARAMS);
		_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
		_vala_params = _tmp3_;
		_vala_params_length1 = _tmp3__length1;
	} else {
		gboolean _tmp4_ = FALSE;
		if (dc_link_cleaner_host_is (host, "x.com")) {
			_tmp4_ = TRUE;
		} else {
			_tmp4_ = dc_link_cleaner_host_is (host, "twitter.com");
		}
		if (_tmp4_) {
			gchar** _tmp5_;
			gint _tmp5__length1;
			_tmp5_ = _vala_array_dup12 (DC_LINK_CLEANER_X_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_X_PARAMS));
			_tmp5__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_X_PARAMS);
			_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
			_vala_params = _tmp5_;
			_vala_params_length1 = _tmp5__length1;
		} else {
			gboolean _tmp6_ = FALSE;
			gboolean _tmp7_ = FALSE;
			if (dc_link_cleaner_host_is (host, "instagram.com")) {
				_tmp7_ = TRUE;
			} else {
				_tmp7_ = dc_link_cleaner_host_is (host, "threads.net");
			}
			if (_tmp7_) {
				_tmp6_ = TRUE;
			} else {
				_tmp6_ = dc_link_cleaner_host_is (host, "threads.com");
			}
			if (_tmp6_) {
				gchar** _tmp8_;
				gint _tmp8__length1;
				_tmp8_ = _vala_array_dup13 (DC_LINK_CLEANER_INSTAGRAM_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_INSTAGRAM_PARAMS));
				_tmp8__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_INSTAGRAM_PARAMS);
				_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
				_vala_params = _tmp8_;
				_vala_params_length1 = _tmp8__length1;
			} else {
				gboolean _tmp9_ = FALSE;
				gboolean _tmp10_ = FALSE;
				gboolean _tmp11_ = FALSE;
				gboolean _tmp12_ = FALSE;
				if (dc_link_cleaner_host_is (host, "facebook.com")) {
					_tmp12_ = TRUE;
				} else {
					_tmp12_ = dc_link_cleaner_host_is (host, "fb.com");
				}
				if (_tmp12_) {
					_tmp11_ = TRUE;
				} else {
					_tmp11_ = dc_link_cleaner_host_is (host, "fb.watch");
				}
				if (_tmp11_) {
					_tmp10_ = TRUE;
				} else {
					_tmp10_ = dc_link_cleaner_host_is (host, "fb.me");
				}
				if (_tmp10_) {
					_tmp9_ = TRUE;
				} else {
					_tmp9_ = dc_link_cleaner_host_is (host, "messenger.com");
				}
				if (_tmp9_) {
					gchar** _tmp13_;
					gint _tmp13__length1;
					gchar** _tmp14_;
					gint _tmp14__length1;
					_tmp13_ = _vala_array_dup14 (DC_LINK_CLEANER_FACEBOOK_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_FACEBOOK_PARAMS));
					_tmp13__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_FACEBOOK_PARAMS);
					_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
					_vala_params = _tmp13_;
					_vala_params_length1 = _tmp13__length1;
					_tmp14_ = _vala_array_dup15 (DC_LINK_CLEANER_FACEBOOK_PREFIXES, G_N_ELEMENTS (DC_LINK_CLEANER_FACEBOOK_PREFIXES));
					_tmp14__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_FACEBOOK_PREFIXES);
					_vala_prefixes = (_vala_array_free (_vala_prefixes, _vala_prefixes_length1, (GDestroyNotify) g_free), NULL);
					_vala_prefixes = _tmp14_;
					_vala_prefixes_length1 = _tmp14__length1;
				} else {
					gboolean _tmp15_ = FALSE;
					if (dc_link_cleaner_host_is (host, "linkedin.com")) {
						_tmp15_ = TRUE;
					} else {
						_tmp15_ = dc_link_cleaner_host_is (host, "lnkd.in");
					}
					if (_tmp15_) {
						gchar** _tmp16_;
						gint _tmp16__length1;
						_tmp16_ = _vala_array_dup16 (DC_LINK_CLEANER_LINKEDIN_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_LINKEDIN_PARAMS));
						_tmp16__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_LINKEDIN_PARAMS);
						_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
						_vala_params = _tmp16_;
						_vala_params_length1 = _tmp16__length1;
					} else {
						if (dc_link_cleaner_host_is (host, "tiktok.com")) {
							gchar** _tmp17_;
							gint _tmp17__length1;
							_tmp17_ = _vala_array_dup17 (DC_LINK_CLEANER_TIKTOK_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_TIKTOK_PARAMS));
							_tmp17__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_TIKTOK_PARAMS);
							_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
							_vala_params = _tmp17_;
							_vala_params_length1 = _tmp17__length1;
						} else {
							gboolean _tmp18_ = FALSE;
							if (dc_link_cleaner_host_is (host, "reddit.com")) {
								_tmp18_ = TRUE;
							} else {
								_tmp18_ = dc_link_cleaner_host_is (host, "redd.it");
							}
							if (_tmp18_) {
								gchar** _tmp19_;
								gint _tmp19__length1;
								_tmp19_ = _vala_array_dup18 (DC_LINK_CLEANER_REDDIT_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_REDDIT_PARAMS));
								_tmp19__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_REDDIT_PARAMS);
								_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
								_vala_params = _tmp19_;
								_vala_params_length1 = _tmp19__length1;
							} else {
								if (dc_link_cleaner_host_is (host, "spotify.com")) {
									gchar** _tmp20_;
									gint _tmp20__length1;
									_tmp20_ = _vala_array_dup19 (DC_LINK_CLEANER_SPOTIFY_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_SPOTIFY_PARAMS));
									_tmp20__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_SPOTIFY_PARAMS);
									_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
									_vala_params = _tmp20_;
									_vala_params_length1 = _tmp20__length1;
								} else {
									if (dc_link_cleaner_host_is (host, "twitch.tv")) {
										gchar** _tmp21_;
										gint _tmp21__length1;
										_tmp21_ = _vala_array_dup20 (DC_LINK_CLEANER_TWITCH_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_TWITCH_PARAMS));
										_tmp21__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_TWITCH_PARAMS);
										_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
										_vala_params = _tmp21_;
										_vala_params_length1 = _tmp21__length1;
									} else {
										if (dc_link_cleaner_host_is_brand (host, "amazon")) {
											gchar** _tmp22_;
											gint _tmp22__length1;
											gchar** _tmp23_;
											gint _tmp23__length1;
											_tmp22_ = _vala_array_dup21 (DC_LINK_CLEANER_AMAZON_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_AMAZON_PARAMS));
											_tmp22__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_AMAZON_PARAMS);
											_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
											_vala_params = _tmp22_;
											_vala_params_length1 = _tmp22__length1;
											_tmp23_ = _vala_array_dup22 (DC_LINK_CLEANER_AMAZON_PREFIXES, G_N_ELEMENTS (DC_LINK_CLEANER_AMAZON_PREFIXES));
											_tmp23__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_AMAZON_PREFIXES);
											_vala_prefixes = (_vala_array_free (_vala_prefixes, _vala_prefixes_length1, (GDestroyNotify) g_free), NULL);
											_vala_prefixes = _tmp23_;
											_vala_prefixes_length1 = _tmp23__length1;
										} else {
											if (dc_link_cleaner_host_is_brand (host, "ebay")) {
												gchar** _tmp24_;
												gint _tmp24__length1;
												_tmp24_ = _vala_array_dup23 (DC_LINK_CLEANER_EBAY_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_EBAY_PARAMS));
												_tmp24__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_EBAY_PARAMS);
												_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
												_vala_params = _tmp24_;
												_vala_params_length1 = _tmp24__length1;
											} else {
												if (dc_link_cleaner_host_is_brand (host, "aliexpress")) {
													gchar** _tmp25_;
													gint _tmp25__length1;
													_tmp25_ = _vala_array_dup24 (DC_LINK_CLEANER_ALIEXPRESS_PARAMS, G_N_ELEMENTS (DC_LINK_CLEANER_ALIEXPRESS_PARAMS));
													_tmp25__length1 = G_N_ELEMENTS (DC_LINK_CLEANER_ALIEXPRESS_PARAMS);
													_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
													_vala_params = _tmp25_;
													_vala_params_length1 = _tmp25__length1;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	if (params) {
		*params = _vala_params;
	} else {
		_vala_params = (_vala_array_free (_vala_params, _vala_params_length1, (GDestroyNotify) g_free), NULL);
	}
	if (params_length1) {
		*params_length1 = _vala_params_length1;
	}
	if (prefixes) {
		*prefixes = _vala_prefixes;
	} else {
		_vala_prefixes = (_vala_array_free (_vala_prefixes, _vala_prefixes_length1, (GDestroyNotify) g_free), NULL);
	}
	if (prefixes_length1) {
		*prefixes_length1 = _vala_prefixes_length1;
	}
}

/** 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_is (const gchar* host,
                         const gchar* domain)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (host != NULL, FALSE);
	g_return_val_if_fail (domain != NULL, FALSE);
	if (g_strcmp0 (host, domain) == 0) {
		_tmp0_ = TRUE;
	} else {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = g_strconcat (".", domain, NULL);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_str_has_suffix (host, _tmp2_);
		_g_free0 (_tmp2_);
	}
	result = _tmp0_;
	return result;
}

static gboolean
dc_link_cleaner_host_is_brand (const gchar* host,
                               const gchar* brand)
{
	gint idx = 0;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean result;
	g_return_val_if_fail (host != NULL, FALSE);
	g_return_val_if_fail (brand != NULL, FALSE);
	_tmp0_ = g_strconcat (brand, ".", NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_index_of (host, _tmp1_, 0);
	_g_free0 (_tmp1_);
	idx = _tmp2_;
	if (idx == 0) {
		_tmp3_ = TRUE;
	} else {
		gboolean _tmp4_ = FALSE;
		if (idx > 0) {
			_tmp4_ = string_get (host, (glong) (idx - 1)) == '.';
		} else {
			_tmp4_ = FALSE;
		}
		_tmp3_ = _tmp4_;
	}
	result = _tmp3_;
	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
dc_link_cleaner_contains (gchar** haystack,
                          gint haystack_length1,
                          const gchar* needle)
{
	gboolean result;
	g_return_val_if_fail (needle != NULL, FALSE);
	{
		gchar** s_collection = NULL;
		gint s_collection_length1 = 0;
		gint _s_collection_size_ = 0;
		gint s_it = 0;
		s_collection = haystack;
		s_collection_length1 = haystack_length1;
		for (s_it = 0; s_it < s_collection_length1; s_it = s_it + 1) {
			gchar* _tmp0_;
			gchar* s = NULL;
			_tmp0_ = g_strdup (s_collection[s_it]);
			s = _tmp0_;
			{
				const gchar* _tmp1_;
				_tmp1_ = s;
				if (g_strcmp0 (_tmp1_, needle) == 0) {
					result = TRUE;
					_g_free0 (s);
					return result;
				}
				_g_free0 (s);
			}
		}
	}
	result = FALSE;
	return result;
}

static gboolean
dc_link_cleaner_has_any_prefix (const gchar* name,
                                gchar** prefixes,
                                gint prefixes_length1)
{
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	{
		gchar** prefix_collection = NULL;
		gint prefix_collection_length1 = 0;
		gint _prefix_collection_size_ = 0;
		gint prefix_it = 0;
		prefix_collection = prefixes;
		prefix_collection_length1 = prefixes_length1;
		for (prefix_it = 0; prefix_it < prefix_collection_length1; prefix_it = prefix_it + 1) {
			gchar* _tmp0_;
			gchar* prefix = NULL;
			_tmp0_ = g_strdup (prefix_collection[prefix_it]);
			prefix = _tmp0_;
			{
				const gchar* _tmp1_;
				_tmp1_ = prefix;
				if (g_str_has_prefix (name, _tmp1_)) {
					result = TRUE;
					_g_free0 (prefix);
					return result;
				}
				_g_free0 (prefix);
			}
		}
	}
	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 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;
}

