Don't cache local adblock filters, and remove disabled filter files

This commit is contained in:
Alexander Butenko 2010-02-03 18:26:44 +01:00 committed by Christian Dywan
parent bee4615d10
commit de7818b7aa

View file

@ -97,12 +97,37 @@ adblock_download_notify_status_cb (WebKitDownload* download,
/* g_object_unref (download); */ /* g_object_unref (download); */
} }
static gchar*
adblock_get_filename_for_uri (const gchar* uri)
{
gchar* filename;
gchar* folder;
gchar* path;
if (strchr (uri + 4,'-'))
return NULL;
if (!strncmp (uri, "file", 4))
return g_strndup (uri + 7, strlen (uri) - 7);
folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
"adblock", NULL);
katze_mkdir_with_parents (folder, 0700);
filename = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
path = g_build_filename (folder, filename, NULL);
g_free (filename);
g_free (folder);
return path;
}
static void static void
adblock_reload_rules (MidoriExtension* extension, adblock_reload_rules (MidoriExtension* extension,
gboolean custom_only) gboolean custom_only)
{ {
gchar* path;
gchar* custom_list; gchar* custom_list;
gchar* folder;
gchar** filters; gchar** filters;
guint i = 0; guint i = 0;
@ -116,21 +141,22 @@ adblock_reload_rules (MidoriExtension* extension,
filters = midori_extension_get_string_list (extension, "filters", NULL); filters = midori_extension_get_string_list (extension, "filters", NULL);
if (!custom_only && filters && *filters) if (!custom_only && filters && *filters)
{ {
folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, while (filters[i] != NULL)
"adblock", NULL);
katze_mkdir_with_parents (folder, 0700);
while (filters[i++] != NULL)
{ {
gchar* filename = g_compute_checksum_for_string (G_CHECKSUM_MD5, path = adblock_get_filename_for_uri (filters[i]);
filters[i - 1], -1); if (!path)
gchar* path = g_build_filename (folder, filename, NULL); {
i++;
continue;
}
if (!adblock_parse_file (path)) if (!adblock_parse_file (path))
{ {
WebKitNetworkRequest* request; WebKitNetworkRequest* request;
WebKitDownload* download; WebKitDownload* download;
gchar* destination = g_filename_to_uri (path, NULL, NULL); gchar* destination = g_filename_to_uri (path, NULL, NULL);
request = webkit_network_request_new (filters[i -1]); request = webkit_network_request_new (filters[i]);
download = webkit_download_new (request); download = webkit_download_new (request);
g_object_unref (request); g_object_unref (request);
webkit_download_set_destination_uri (download, destination); webkit_download_set_destination_uri (download, destination);
@ -141,9 +167,8 @@ adblock_reload_rules (MidoriExtension* extension,
} }
else else
g_free (path); g_free (path);
g_free (filename); i++;
} }
g_free (folder);
} }
g_strfreev (filters); g_strfreev (filters);
@ -186,9 +211,9 @@ adblock_preferences_renderer_text_edited_cb (GtkCellRenderer* renderer,
} }
static void static void
adblock_preferences_renderer_toggle_toggled_cb (GtkTreeViewColumn* column, adblock_preferences_renderer_toggle_toggled_cb (GtkCellRendererToggle* renderer,
const gchar* path, const gchar* path,
GtkTreeModel* model) GtkTreeModel* model)
{ {
GtkTreeIter iter; GtkTreeIter iter;
@ -200,7 +225,17 @@ adblock_preferences_renderer_toggle_toggled_cb (GtkTreeViewColumn* column,
if (ADBLOCK_FILTER_VALID (filter)) if (ADBLOCK_FILTER_VALID (filter))
{ {
filter[4] = filter[4] != '-' ? '-' : ':'; filter[4] = ':';
if (gtk_cell_renderer_toggle_get_active (renderer))
{
if (!strncmp (filter, "http", 4))
{
gchar* filename = adblock_get_filename_for_uri (filter);
g_unlink (filename);
g_free (filename);
}
filter[4] = '-';
}
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, filter, -1); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, filter, -1);