~l3on/ubuntu/precise/epiphany-extensions/new-release

« back to all changes in this revision

Viewing changes to extensions/adblock/adblock-pattern.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-09-18 14:08:05 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20090918140805-fa8kka5uo6u5l5io
Tags: 2.27.92-0ubuntu1
* new upstream 2.27.92 ships ships epiphany-webkit extensions only
  - update debian/control - move from epiphany-browser to -webkit
  - update debian/rules - drop link creation that tried to support -browser
    and -webkit parts and run dh_pysupport on epiphany-webkit dir
  - update debian/rules - use really-all extensions
  - add debian/patches/02_greasemonkey_web_view.patch - fix greasemonkey
    extension being broken by bad web_view lookup - bgo 595814

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  Copyright © 2004 Adam Hooper
3
3
 *  Copyright © 2005, 2006 Jean-François Rameau
 
4
 *  Copyright © 2009 Xan Lopez <xan@gnome.org>
4
5
 *
5
6
 *  This program is free software; you can redistribute it and/or modify
6
7
 *  it under the terms of the GNU General Public License as published by
16
17
 *  along with this program; if not, write to the Free Software
17
18
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19
 *
19
 
 *  $Id$
20
20
 */
21
21
 
22
22
#include "config.h"
23
23
 
24
24
#include "adblock-pattern.h"
25
25
 
26
 
#include <pcre.h>
27
26
#include <string.h>
28
27
#include <gio/gio.h>
29
28
 
50
49
        char **lines;
51
50
        char **t;
52
51
        char *line;
53
 
        pcre *preg;
54
 
        const char *err;
55
 
        int erroffset;
 
52
        GRegex *regex;
 
53
        GError *error = NULL;
56
54
 
57
55
        if (!g_file_get_contents (filename, &contents, NULL, NULL))
58
56
        {
73
71
 
74
72
                if (*line == '\0') continue; /* empty line */
75
73
 
76
 
                preg = pcre_compile (line, PCRE_UTF8, &err, &erroffset, NULL);
 
74
                regex = g_regex_new (line, G_REGEX_OPTIMIZE, 0, &error);
77
75
 
78
 
                if (preg == NULL)
 
76
                if (regex == NULL)
79
77
                {
80
78
                        g_warning ("Could not compile expression \"%s\"\n"
81
 
                                   "Error at column %d: %s",
82
 
                                   line, erroffset, err);
 
79
                                   "Error: %s",
 
80
                                   line, error->message);
 
81
                        g_error_free (error);
83
82
                        continue;
84
83
                }
85
84
 
86
 
                g_hash_table_insert (patterns, g_strdup (line), preg);
 
85
                g_hash_table_insert (patterns, g_strdup (line), regex);
87
86
        }
88
87
 
89
88
        g_strfreev (lines);
160
159
{
161
160
        char **lines, **t;
162
161
        char *line;
163
 
        pcre *preg1, *preg2;
164
 
        const char *err;
165
 
        int erroffset, ret;
 
162
        GRegex *regex1, *regex2;
 
163
        GError *error = NULL;
 
164
        gboolean match;
166
165
        GSList *patterns = NULL;
167
166
 
168
 
        /* We don't care about some specifi rules */
169
 
        preg1 = pcre_compile ("^\\[Adblock\\]", PCRE_UTF8, &err, &erroffset, NULL);
170
 
        if (preg1 == NULL)
 
167
        /* We don't care about some specific rules */
 
168
        regex1 = g_regex_new ("^\\[Adblock\\]", 0, 0, &error);
 
169
        if (regex1 == NULL)
171
170
        {
172
 
                g_warning ("Could not compile expression ^\\[Adblock]\n" "Error at column %d: %s",
173
 
                           erroffset, err);
 
171
                g_warning ("Could not compile expression ^\\[Adblock]\n" "Error: %s",
 
172
                           error->message);
 
173
                g_error_free (error);
174
174
                return;
175
175
        }
176
 
        preg2 = pcre_compile ("^\\!Filterset", PCRE_UTF8, &err, &erroffset, NULL);
177
 
        if (preg1 == NULL)
 
176
        regex2 = g_regex_new ("^\\!Filterset", 0, 0, &error);
 
177
        if (regex2 == NULL)
178
178
        {
179
 
                g_warning ("Could not compile expression ^\\!Filterset\n" "Error at column %d: %s",
180
 
                           erroffset, err);
 
179
                g_warning ("Could not compile expression ^\\!Filterset\n" "Error: %s",
 
180
                           error->message);
 
181
                g_error_free (error);
181
182
                return;
182
183
        }
183
184
 
194
195
 
195
196
                if (*line == '\0') continue; /* empty line */
196
197
 
197
 
                ret = pcre_exec (preg1, NULL, line, strlen (line),
198
 
                                0, PCRE_NO_UTF8_CHECK, NULL, 0);
199
 
 
200
 
                if (ret >= 0) continue;
201
 
 
202
 
                ret = pcre_exec (preg2, NULL, line, strlen (line),
203
 
                                0, PCRE_NO_UTF8_CHECK, NULL, 0);
204
 
 
205
 
                if (ret >= 0) continue;
 
198
                match = g_regex_match (regex1, line, 0, NULL);
 
199
 
 
200
                if (match) continue;
 
201
 
 
202
                match = g_regex_match (regex2, line, 0, NULL);
 
203
 
 
204
                if (match) continue;
206
205
 
207
206
                if (*line == '/')
208
207
                {
217
216
        }
218
217
 
219
218
        g_strfreev (lines);
 
219
        g_regex_unref (regex1);
 
220
        g_regex_unref (regex2);
220
221
 
221
222
        adblock_pattern_save (patterns, PATTERN_DEFAULT_BLACKLIST);
222
223