~ubuntu-branches/ubuntu/hardy/epiphany-extensions/hardy-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-02-11 12:07:10 UTC
  • mfrom: (1.1.25 upstream)
  • Revision ID: james.westby@ubuntu.com-20080211120710-mene00j2jh4ddwnz
Tags: 2.20.1svn20080211-0ubuntu1
* New SVN snapshot:
  - work with the hardy epiphany-browser version (lp: #178117)
* debian/control.in:
  - build using xulrunner
  - updated epiphany-browser requirement
* debian/patches/ephy-extensions.xul.1.9.patch:
  - patch from Alexander Sack to build using xulrunner1.9
* debian/patches/delicious.diff:
  - dropped, the change is in the svn version
* debian/rules:
  - build using libxul
  - updated installation directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 *  along with this program; if not, write to the Free Software
17
17
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
18
 *
19
 
 *  $Id: adblock-pattern.c 1538 2007-07-08 09:32:03Z jframeau $
 
19
 *  $Id: adblock-pattern.c 1627 2007-11-03 23:46:07Z cyrilbois $
20
20
 */
21
21
 
22
22
#include "config.h"
32
32
#include <libgnomevfs/gnome-vfs-utils.h>
33
33
 
34
34
#define DEFAULT_BLACKLIST_FILENAME      "adblock-patterns"
35
 
#define BLACKLIST_FILENAME              "blacklist"
 
35
#define BLACKLIST_FILENAME              "blacklist"
36
36
#define WHITELIST_FILENAME              "whitelist"
37
37
 
38
38
typedef enum
45
45
 
46
46
static void
47
47
adblock_pattern_load_from_file (GHashTable *patterns,
48
 
                                const char *filename)
 
48
                                const char *filename)
49
49
{
50
50
        char *contents;
51
51
        char **lines;
93
93
 
94
94
static char *
95
95
adblock_pattern_filename (AdblockPatternType type, OpType op)
96
 
               
97
96
{
98
97
        char *filename = NULL;
99
98
 
101
100
        {
102
101
                case PATTERN_BLACKLIST:
103
102
                        filename = g_build_filename (ephy_dot_dir (), "extensions", "data",
104
 
                                                     "adblock", BLACKLIST_FILENAME,
105
 
                                                     NULL);
 
103
                                                     "adblock", BLACKLIST_FILENAME,
 
104
                                                     NULL);
106
105
                        break;
107
106
                case PATTERN_WHITELIST:
108
107
                        filename = g_build_filename (ephy_dot_dir (), "extensions", "data",
109
 
                                                     "adblock", WHITELIST_FILENAME,
110
 
                                                     NULL);
 
108
                                                     "adblock", WHITELIST_FILENAME,
 
109
                                                     NULL);
111
110
                        break;
112
111
                case PATTERN_DEFAULT_BLACKLIST:
113
112
                        /* We first try the user's one */
114
113
                        filename = g_build_filename (ephy_dot_dir (), "extensions", "data",
115
 
                                                     "adblock", DEFAULT_BLACKLIST_FILENAME,
116
 
                                                     NULL);
 
114
                                                     "adblock", DEFAULT_BLACKLIST_FILENAME,
 
115
                                                     NULL);
117
116
                        if (op == OP_LOAD && !g_file_test (filename, G_FILE_TEST_IS_REGULAR))
118
117
                        {
119
118
                                g_free (filename);
130
129
 
131
130
static gboolean
132
131
adblock_pattern_foreach_save (const char *pattern,
133
 
                              GIOChannel *channel)
 
132
                              GIOChannel *channel)
134
133
{
135
134
        GIOStatus status;
136
 
        gsize bytes_written;
 
135
        gsize bytes_written;
137
136
 
138
137
        status = g_io_channel_write_chars (channel, pattern, -1, &bytes_written, NULL);
139
138
        status = g_io_channel_write_chars (channel, "\n", -1, &bytes_written, NULL);
171
170
        preg1 = pcre_compile ("^\\[Adblock\\]", PCRE_UTF8, &err, &erroffset, NULL);
172
171
        if (preg1 == NULL)
173
172
        {
174
 
                g_warning ("Could not compile expression ^\\[Adblock]\n" "Error at column %d: %s", 
 
173
                g_warning ("Could not compile expression ^\\[Adblock]\n" "Error at column %d: %s",
175
174
                           erroffset, err);
176
175
                return;
177
176
        }
178
177
        preg2 = pcre_compile ("^\\!Filterset", PCRE_UTF8, &err, &erroffset, NULL);
179
178
        if (preg1 == NULL)
180
179
        {
181
 
                g_warning ("Could not compile expression ^\\!Filterset\n" "Error at column %d: %s", 
 
180
                g_warning ("Could not compile expression ^\\!Filterset\n" "Error at column %d: %s",
182
181
                           erroffset, err);
183
182
                return;
184
183
        }
221
220
        g_strfreev (lines);
222
221
 
223
222
        adblock_pattern_save (patterns, PATTERN_DEFAULT_BLACKLIST);
224
 
        
 
223
 
225
224
        g_slist_foreach (patterns, (GFunc)g_free, NULL);
226
225
}
227
226
 
268
267
 
269
268
/* Public */
270
269
 
271
 
void 
272
 
adblock_pattern_load (GHashTable *patterns, 
273
 
                      AdblockPatternType type)
274
 
               
 
270
void
 
271
adblock_pattern_load (GHashTable *patterns,
 
272
                      AdblockPatternType type)
275
273
{
276
274
        char *filename = NULL;
277
275
 
287
285
}
288
286
 
289
287
 
290
 
void 
 
288
void
291
289
adblock_pattern_save (GSList *patterns, AdblockPatternType type)
292
290
{
293
291
        GError *error = NULL;
297
295
 
298
296
        GIOChannel *channel = g_io_channel_new_file (filename, "w", NULL);
299
297
 
300
 
        g_slist_foreach (patterns,      
301
 
                         (GFunc)adblock_pattern_foreach_save, 
 
298
        g_slist_foreach (patterns,
 
299
                         (GFunc)adblock_pattern_foreach_save,
302
300
                         channel);
303
301
 
304
302
        g_io_channel_shutdown (channel, TRUE, &error);
305
303
}
306
304
 
307
 
void 
 
305
void
308
306
adblock_pattern_get_filtersetg_patterns (void)
309
307
{
310
308
        char *date, *patterns;
314
312
        {
315
313
                g_warning ("Could not get the last update");
316
314
                return;
317
 
        }       
 
315
        }
318
316
 
319
317
        patterns = adblock_pattern_get_filterg_patterns (date);
320
318
        if (patterns == NULL)
322
320
                g_warning ("Could not get content from last update");
323
321
                return;
324
322
        }
325
 
        
 
323
 
326
324
        adblock_pattern_rewrite_patterns (patterns);
327
325
 
328
326
        g_free (date);