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

/*
 Copyright (C) 2009-2014 Christian Dywan <christian@twotoasts.de>
 Copyright (C) 2009-2012 Alexander Butenko <a.butenka@gmail.com>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 See the file COPYING for the full license text.
*/

#include <glib.h>
#include <glib-object.h>
#include "toolbar-editor.h"
#include <stdlib.h>
#include <string.h>

#define __g_list_free__g_regex_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_regex_unref0_ (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

struct _AdblockKeysPrivate {
	GList* blacklist;
};


static gpointer adblock_keys_parent_class = NULL;

#define ADBLOCK_KEYS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ADBLOCK_TYPE_KEYS, AdblockKeysPrivate))
enum  {
	ADBLOCK_KEYS_DUMMY_PROPERTY
};
static void _g_regex_unref0_ (gpointer var);
static void _g_list_free__g_regex_unref0_ (GList* self);
static void adblock_keys_real_clear (AdblockFeature* base);
static AdblockDirective* adblock_keys_real_match (AdblockFeature* base, const gchar* request_uri, const gchar* page_uri, GError** error);
gchar* adblock_fixup_regex (const gchar* prefix, const gchar* src);
static AdblockDirective* _adblock_directive_dup (AdblockDirective* self);
static void adblock_keys_finalize (GObject* obj);


static void _g_regex_unref0_ (gpointer var) {
#line 15 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	(var == NULL) ? NULL : (var = (g_regex_unref (var), NULL));
#line 50 "keys.c"
}


static void _g_list_free__g_regex_unref0_ (GList* self) {
#line 15 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	g_list_foreach (self, (GFunc) _g_regex_unref0_, NULL);
#line 15 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	g_list_free (self);
#line 59 "keys.c"
}


AdblockKeys* adblock_keys_construct (GType object_type, AdblockOptions* options) {
	AdblockKeys * self = NULL;
	AdblockOptions* _tmp0_ = NULL;
#line 17 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	g_return_val_if_fail (options != NULL, NULL);
#line 18 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_tmp0_ = options;
#line 18 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	self = (AdblockKeys*) adblock_filter_construct (object_type, _tmp0_);
#line 17 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	return self;
#line 74 "keys.c"
}


AdblockKeys* adblock_keys_new (AdblockOptions* options) {
#line 17 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	return adblock_keys_construct (ADBLOCK_TYPE_KEYS, options);
#line 81 "keys.c"
}


static void adblock_keys_real_clear (AdblockFeature* base) {
	AdblockKeys * self;
#line 21 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	self = (AdblockKeys*) base;
#line 22 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	ADBLOCK_FEATURE_CLASS (adblock_keys_parent_class)->clear ((AdblockFeature*) G_TYPE_CHECK_INSTANCE_CAST (self, ADBLOCK_TYPE_FILTER, AdblockFilter));
#line 23 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	__g_list_free__g_regex_unref0_0 (self->priv->blacklist);
#line 23 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	self->priv->blacklist = NULL;
#line 95 "keys.c"
}


static const gchar* string_offset (const gchar* self, glong offset) {
	const gchar* result = NULL;
	glong _tmp0_ = 0L;
#line 1035 "/usr/share/vala-0.26/vapi/glib-2.0.vapi"
	g_return_val_if_fail (self != NULL, NULL);
#line 1036 "/usr/share/vala-0.26/vapi/glib-2.0.vapi"
	_tmp0_ = offset;
#line 1036 "/usr/share/vala-0.26/vapi/glib-2.0.vapi"
	result = (const gchar*) (((gchar*) self) + _tmp0_);
#line 1036 "/usr/share/vala-0.26/vapi/glib-2.0.vapi"
	return result;
#line 110 "keys.c"
}


static gpointer _g_regex_ref0 (gpointer self) {
#line 35 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	return self ? g_regex_ref (self) : NULL;
#line 117 "keys.c"
}


static AdblockDirective* _adblock_directive_dup (AdblockDirective* self) {
	AdblockDirective* dup;
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	dup = g_new0 (AdblockDirective, 1);
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	memcpy (dup, self, sizeof (AdblockDirective));
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	return dup;
#line 129 "keys.c"
}


static gpointer __adblock_directive_dup0 (gpointer self) {
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	return self ? _adblock_directive_dup (self) : NULL;
#line 136 "keys.c"
}


static AdblockDirective* adblock_keys_real_match (AdblockFeature* base, const gchar* request_uri, const gchar* page_uri, GError** error) {
	AdblockKeys * self;
	AdblockDirective* result = NULL;
	gchar* uri = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gint signature_size = 0;
	gint pos = 0;
	gint l = 0;
	const gchar* _tmp3_ = NULL;
	gint _tmp4_ = 0;
	gint _tmp5_ = 0;
	GError * _inner_error_ = NULL;
#line 26 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	self = (AdblockKeys*) base;
#line 26 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	g_return_val_if_fail (request_uri != NULL, NULL);
#line 26 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	g_return_val_if_fail (page_uri != NULL, NULL);
#line 27 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_tmp0_ = request_uri;
#line 27 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_tmp1_ = adblock_fixup_regex ("", _tmp0_);
#line 27 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	uri = _tmp1_;
#line 28 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_tmp2_ = uri;
#line 28 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	if (_tmp2_ == NULL) {
#line 29 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		result = NULL;
#line 29 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		_g_free0 (uri);
#line 29 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		return result;
#line 176 "keys.c"
	}
#line 31 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	signature_size = 8;
#line 32 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_tmp3_ = uri;
#line 32 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_tmp4_ = strlen (_tmp3_);
#line 32 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_tmp5_ = _tmp4_;
#line 32 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	l = _tmp5_;
#line 188 "keys.c"
	{
		gint _tmp6_ = 0;
		gint _tmp7_ = 0;
		gboolean _tmp8_ = FALSE;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		_tmp6_ = l;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		_tmp7_ = signature_size;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		pos = _tmp6_ - _tmp7_;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		_tmp8_ = TRUE;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
		while (TRUE) {
#line 203 "keys.c"
			gint _tmp10_ = 0;
			gchar* signature = NULL;
			const gchar* _tmp11_ = NULL;
			gint _tmp12_ = 0;
			const gchar* _tmp13_ = NULL;
			gint _tmp14_ = 0;
			gchar* _tmp15_ = NULL;
			GRegex* regex = NULL;
			GHashTable* _tmp16_ = NULL;
			const gchar* _tmp17_ = NULL;
			gconstpointer _tmp18_ = NULL;
			GRegex* _tmp19_ = NULL;
			gboolean _tmp20_ = FALSE;
			GRegex* _tmp21_ = NULL;
			gboolean _tmp25_ = FALSE;
			GRegex* _tmp26_ = NULL;
			const gchar* _tmp27_ = NULL;
			const gchar* _tmp28_ = NULL;
			const gchar* _tmp29_ = NULL;
			gboolean _tmp30_ = FALSE;
			GRegex* _tmp33_ = NULL;
			GRegex* _tmp34_ = NULL;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			if (!_tmp8_) {
#line 228 "keys.c"
				gint _tmp9_ = 0;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp9_ = pos;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				pos = _tmp9_ - 1;
#line 234 "keys.c"
			}
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp8_ = FALSE;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp10_ = pos;
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			if (!(_tmp10_ >= 0)) {
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				break;
#line 244 "keys.c"
			}
#line 34 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp11_ = uri;
#line 34 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp12_ = pos;
#line 34 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp13_ = string_offset (_tmp11_, (glong) _tmp12_);
#line 34 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp14_ = signature_size;
#line 34 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp15_ = g_strndup (_tmp13_, (gsize) _tmp14_);
#line 34 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			signature = _tmp15_;
#line 35 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp16_ = ((AdblockFilter*) self)->rules;
#line 35 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp17_ = signature;
#line 35 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp18_ = g_hash_table_lookup (_tmp16_, _tmp17_);
#line 35 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp19_ = _g_regex_ref0 ((GRegex*) _tmp18_);
#line 35 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			regex = _tmp19_;
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp21_ = regex;
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			if (_tmp21_ == NULL) {
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp20_ = TRUE;
#line 274 "keys.c"
			} else {
				GList* _tmp22_ = NULL;
				GRegex* _tmp23_ = NULL;
				GList* _tmp24_ = NULL;
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp22_ = self->priv->blacklist;
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp23_ = regex;
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp24_ = g_list_find (_tmp22_, _tmp23_);
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp20_ = _tmp24_ != NULL;
#line 287 "keys.c"
			}
#line 36 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			if (_tmp20_) {
#line 37 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_regex_unref0 (regex);
#line 37 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_free0 (signature);
#line 37 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				continue;
#line 297 "keys.c"
			}
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp26_ = regex;
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp27_ = uri;
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp28_ = request_uri;
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp29_ = page_uri;
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp30_ = adblock_filter_check_rule ((AdblockFilter*) self, _tmp26_, _tmp27_, _tmp28_, _tmp29_, &_inner_error_);
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp25_ = _tmp30_;
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				g_propagate_error (error, _inner_error_);
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_regex_unref0 (regex);
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_free0 (signature);
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_free0 (uri);
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				return NULL;
#line 323 "keys.c"
			}
#line 39 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			if (_tmp25_) {
#line 327 "keys.c"
				AdblockDirective _tmp31_ = 0;
				AdblockDirective* _tmp32_ = NULL;
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp31_ = ADBLOCK_DIRECTIVE_BLOCK;
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_tmp32_ = __adblock_directive_dup0 (&_tmp31_);
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				result = _tmp32_;
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_regex_unref0 (regex);
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_free0 (signature);
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				_g_free0 (uri);
#line 40 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
				return result;
#line 344 "keys.c"
			}
#line 41 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp33_ = regex;
#line 41 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_tmp34_ = _g_regex_ref0 (_tmp33_);
#line 41 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			self->priv->blacklist = g_list_prepend (self->priv->blacklist, _tmp34_);
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_g_regex_unref0 (regex);
#line 33 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
			_g_free0 (signature);
#line 356 "keys.c"
		}
	}
#line 44 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	result = NULL;
#line 44 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	_g_free0 (uri);
#line 44 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	return result;
#line 365 "keys.c"
}


static void adblock_keys_class_init (AdblockKeysClass * klass) {
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	adblock_keys_parent_class = g_type_class_peek_parent (klass);
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	g_type_class_add_private (klass, sizeof (AdblockKeysPrivate));
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	((AdblockFeatureClass *) klass)->clear = adblock_keys_real_clear;
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	((AdblockFeatureClass *) klass)->match = adblock_keys_real_match;
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	G_OBJECT_CLASS (klass)->finalize = adblock_keys_finalize;
#line 380 "keys.c"
}


static void adblock_keys_instance_init (AdblockKeys * self) {
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	self->priv = ADBLOCK_KEYS_GET_PRIVATE (self);
#line 387 "keys.c"
}


static void adblock_keys_finalize (GObject* obj) {
	AdblockKeys * self;
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ADBLOCK_TYPE_KEYS, AdblockKeys);
#line 15 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	__g_list_free__g_regex_unref0_0 (self->priv->blacklist);
#line 14 "/usr/src/ports/midori/midori-0.5.10-1.i686/src/extensions/adblock/keys.vala"
	G_OBJECT_CLASS (adblock_keys_parent_class)->finalize (obj);
#line 399 "keys.c"
}


GType adblock_keys_get_type (void) {
	static volatile gsize adblock_keys_type_id__volatile = 0;
	if (g_once_init_enter (&adblock_keys_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (AdblockKeysClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) adblock_keys_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AdblockKeys), 0, (GInstanceInitFunc) adblock_keys_instance_init, NULL };
		GType adblock_keys_type_id;
		adblock_keys_type_id = g_type_register_static (ADBLOCK_TYPE_FILTER, "AdblockKeys", &g_define_type_info, 0);
		g_once_init_leave (&adblock_keys_type_id__volatile, adblock_keys_type_id);
	}
	return adblock_keys_type_id__volatile;
}



