epiphany-extensions r1817 - in trunk: . extensions/adblock



Author: xan
Date: Sat Feb 21 11:44:21 2009
New Revision: 1817
URL: http://svn.gnome.org/viewvc/epiphany-extensions?rev=1817&view=rev

Log:
adblock: port to GRegex.

Bug #402273

Modified:
   trunk/configure.ac
   trunk/extensions/adblock/Makefile.am
   trunk/extensions/adblock/ad-uri-tester.c
   trunk/extensions/adblock/adblock-pattern.c
   trunk/extensions/adblock/adblock-ui.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sat Feb 21 11:44:21 2009
@@ -259,7 +259,7 @@
 # PCRE
 # ****
 
-if echo "$EXTENSIONS" | egrep '(^| )(adblock|greasemonkey)($| )' > /dev/null; then
+if echo "$EXTENSIONS" | egrep '(^| )(greasemonkey)($| )' > /dev/null; then
 	AC_PATH_PROG([PCRE_CONFIG], [pcre-config], [no])
 
 	if test "x$PCRE_CONFIG" = "xno"; then

Modified: trunk/extensions/adblock/Makefile.am
==============================================================================
--- trunk/extensions/adblock/Makefile.am	(original)
+++ trunk/extensions/adblock/Makefile.am	Sat Feb 21 11:44:21 2009
@@ -23,12 +23,8 @@
 
 libadblockextension_la_CFLAGS = \
 	$(EPIPHANY_DEPENDENCY_CFLAGS)	\
-	$(PCRE_CFLAGS)			\
 	$(AM_CFLAGS)
 
-libadblockextension_la_LIBADD = \
-	$(PCRE_LIBS)
-
 libadblockextension_la_LDFLAGS = \
 	-module -avoid-version \
 	-export-symbols $(top_srcdir)/ephy-extension.symbols \

Modified: trunk/extensions/adblock/ad-uri-tester.c
==============================================================================
--- trunk/extensions/adblock/ad-uri-tester.c	(original)
+++ trunk/extensions/adblock/ad-uri-tester.c	Sat Feb 21 11:44:21 2009
@@ -15,7 +15,6 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- *  $Id$
  */
 
 #include "config.h"
@@ -23,8 +22,6 @@
 #include "ad-uri-tester.h"
 #include "adblock-pattern.h"
 
-#include <pcre.h>
-
 #include "ephy-file-helpers.h"
 #include "ephy-debug.h"
 
@@ -97,15 +94,14 @@
 
 static gboolean
 match_uri (const char *pattern,
-	   const pcre *preg,
+	   const GRegex *regex,
 	   const UriWithLen *uri_with_len)
 {
-	int ret;
+	gboolean match;
 
-	ret = pcre_exec (preg, NULL, uri_with_len->uri, uri_with_len->len,
-			 0, PCRE_NO_UTF8_CHECK, NULL, 0);
+	match = g_regex_match (regex, uri_with_len->uri, 0, NULL);
 
-	if (ret >= 0)
+	if (match)
 	{
 		LOG ("Blocking '%s' with pattern '%s'",
 		     uri_with_len->uri, pattern);

Modified: trunk/extensions/adblock/adblock-pattern.c
==============================================================================
--- trunk/extensions/adblock/adblock-pattern.c	(original)
+++ trunk/extensions/adblock/adblock-pattern.c	Sat Feb 21 11:44:21 2009
@@ -1,6 +1,7 @@
 /*
  *  Copyright  2004 Adam Hooper
  *  Copyright  2005, 2006 Jean-FranÃois Rameau
+ *  Copyright  2009 Xan Lopez <xan gnome org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -16,14 +17,12 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- *  $Id$
  */
 
 #include "config.h"
 
 #include "adblock-pattern.h"
 
-#include <pcre.h>
 #include <string.h>
 #include <gio/gio.h>
 
@@ -50,9 +49,8 @@
 	char **lines;
 	char **t;
 	char *line;
-	pcre *preg;
-	const char *err;
-	int erroffset;
+	GRegex *regex;
+	GError *error = NULL;
 
 	if (!g_file_get_contents (filename, &contents, NULL, NULL))
 	{
@@ -73,17 +71,18 @@
 
 		if (*line == '\0') continue; /* empty line */
 
-		preg = pcre_compile (line, PCRE_UTF8, &err, &erroffset, NULL);
+		regex = g_regex_new (line, G_REGEX_OPTIMIZE, 0, &error);
 
-		if (preg == NULL)
+		if (regex == NULL)
 		{
 			g_warning ("Could not compile expression \"%s\"\n"
-				   "Error at column %d: %s",
-				   line, erroffset, err);
+				   "Error: %s",
+				   line, error->message);
+			g_error_free (error);
 			continue;
 		}
 
-		g_hash_table_insert (patterns, g_strdup (line), preg);
+		g_hash_table_insert (patterns, g_strdup (line), regex);
 	}
 
 	g_strfreev (lines);
@@ -160,24 +159,26 @@
 {
 	char **lines, **t;
 	char *line;
-	pcre *preg1, *preg2;
-	const char *err;
-	int erroffset, ret;
+	GRegex *regex1, *regex2;
+	GError *error = NULL;
+	gboolean match;
 	GSList *patterns = NULL;
 
-	/* We don't care about some specifi rules */
-	preg1 = pcre_compile ("^\\[Adblock\\]", PCRE_UTF8, &err, &erroffset, NULL);
-	if (preg1 == NULL)
-	{
-		g_warning ("Could not compile expression ^\\[Adblock]\n" "Error at column %d: %s",
-			   erroffset, err);
+	/* We don't care about some specific rules */
+	regex1 = g_regex_new ("^\\[Adblock\\]", 0, 0, &error);
+	if (regex1 == NULL)
+	{
+		g_warning ("Could not compile expression ^\\[Adblock]\n" "Error: %s",
+			   error->message);
+		g_error_free (error);
 		return;
 	}
-	preg2 = pcre_compile ("^\\!Filterset", PCRE_UTF8, &err, &erroffset, NULL);
-	if (preg1 == NULL)
+	regex2 = g_regex_new ("^\\!Filterset", 0, 0, &error);
+	if (regex2 == NULL)
 	{
-		g_warning ("Could not compile expression ^\\!Filterset\n" "Error at column %d: %s",
-			   erroffset, err);
+		g_warning ("Could not compile expression ^\\!Filterset\n" "Error: %s",
+			   error->message);
+		g_error_free (error);
 		return;
 	}
 
@@ -194,15 +195,13 @@
 
 		if (*line == '\0') continue; /* empty line */
 
-		ret = pcre_exec (preg1, NULL, line, strlen (line),
-				0, PCRE_NO_UTF8_CHECK, NULL, 0);
+		match = g_regex_match (regex1, line, 0, NULL);
 
-		if (ret >= 0) continue;
+		if (match) continue;
 
-		ret = pcre_exec (preg2, NULL, line, strlen (line),
-				0, PCRE_NO_UTF8_CHECK, NULL, 0);
+		match = g_regex_match (regex2, line, 0, NULL);
 
-		if (ret >= 0) continue;
+		if (match) continue;
 
 		if (*line == '/')
 		{
@@ -217,6 +216,8 @@
 	}
 
 	g_strfreev (lines);
+	g_regex_unref (regex1);
+	g_regex_unref (regex2);
 
 	adblock_pattern_save (patterns, PATTERN_DEFAULT_BLACKLIST);
 

Modified: trunk/extensions/adblock/adblock-ui.c
==============================================================================
--- trunk/extensions/adblock/adblock-ui.c	(original)
+++ trunk/extensions/adblock/adblock-ui.c	Sat Feb 21 11:44:21 2009
@@ -336,8 +336,8 @@
 
 	patterns = g_hash_table_new_full (g_str_hash,
 					  g_str_equal,
-					  g_free,
-					  g_free);
+					  (GDestroyNotify)g_free,
+					  (GDestroyNotify)g_regex_unref);
 
 	adblock_pattern_load (patterns, type);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]