[Xfce4-commits] <midori:master> Don't test file existence in adblock, katze_mkdir and check download status

Christian Dywan noreply at xfce.org
Tue Dec 22 00:20:06 CET 2009


Updating branch refs/heads/master
         to 1c424106f10f7bf8783bc3e4889654b43d5509b6 (commit)
       from 61266c26ecda1d5e61dc93b080339f04b2febcae (commit)

commit 1c424106f10f7bf8783bc3e4889654b43d5509b6
Author: Alexander Butenko <a.butenka at gmail.com>
Date:   Mon Dec 21 23:57:31 2009 +0100

    Don't test file existence in adblock, katze_mkdir and check download status
    
    It is enough to see if g_fopen fails, thus we don't need g_access
    to test file existence additionally.
    
    katze_mkdir_with_parents is optimized for existing folders.
    
    We need to check the status, to see if file downloads are finished.
    
    For Windows, we need to use g_strndup instead of strndup.

 extensions/adblock.c |   47 +++++++++++++++++++++--------------------------
 1 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index 18bd1b0..f1c36c2 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -34,7 +34,7 @@ static gchar* blockcss = NULL;
 static gchar* blockcssprivate = NULL;
 static gchar* blockscript = NULL;
 
-static void
+static gboolean
 adblock_parse_file (gchar* path);
 
 static gchar*
@@ -90,8 +90,9 @@ adblock_download_notify_status_cb (WebKitDownload* download,
                                    GParamSpec*     pspec,
                                    gchar*          path)
 {
-    if (g_access (path, F_OK) != 0)
-       return;
+    if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_FINISHED)
+        return;
+
     adblock_parse_file (path);
     g_free (path);
     /* g_object_unref (download); */
@@ -104,13 +105,14 @@ adblock_reload_rules (MidoriExtension* extension)
     gchar* folder;
     guint i = 0;
     filters = midori_extension_get_string_list (extension, "filters", NULL);
-    folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
-                               "adblock", NULL);
-    g_mkdir_with_parents (folder, 0700);
 
     if (!filters)
         return;
 
+    folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
+                               "adblock", NULL);
+    katze_mkdir_with_parents (folder, 0700);
+
     adblock_init_db ();
 
     while (filters[i++] != NULL)
@@ -118,7 +120,7 @@ adblock_reload_rules (MidoriExtension* extension)
         gchar* filename = g_compute_checksum_for_string (G_CHECKSUM_MD5,
                                                          filters[i - 1], -1);
         gchar* path = g_build_filename (folder, filename, NULL);
-        if (g_access (path, F_OK) != 0)
+        if (!adblock_parse_file (path))
         {
             WebKitNetworkRequest* request;
             WebKitDownload* download;
@@ -133,10 +135,7 @@ adblock_reload_rules (MidoriExtension* extension)
             webkit_download_start (download);
         }
         else
-        {
-            adblock_parse_file (path);
             g_free (path);
-        }
         g_free (filename);
     }
     katze_assign (blockscript, adblock_build_js (blockcss, blockcssprivate));
@@ -573,24 +572,23 @@ adblock_is_matched_by_key (const gchar*  opts,
                            const gchar*  req_uri,
                            const gchar*  page_uri)
 {
-    int pos = 0;
-    gchar *sig = NULL;
-    GRegex* regex;
     gchar* uri;
+    gint len;
+    int pos = 0;
 
     uri = adblock_fixup_regexp ((gchar*)req_uri);
-
-    int len = strlen (uri);
-    for (pos = len - SIGNATURE_SIZE; pos >= 0; pos--) {
-        sig = strndup (uri+pos, SIGNATURE_SIZE);
-        regex = g_hash_table_lookup (keys, sig);
+    len = strlen (uri);
+    for (pos = len - SIGNATURE_SIZE; pos >= 0; pos--)
+    {
+        gchar* sig = g_strndup (uri + pos, SIGNATURE_SIZE);
+        GRegex* regex = g_hash_table_lookup (keys, sig);
         if (regex)
         {
             if (g_regex_match_full (regex, req_uri, -1, 0, 0, NULL, NULL))
             {
                 g_free (uri);
                 g_free (sig);
-                if (opts && adblock_check_filter_options (regex, opts, req_uri, page_uri) == TRUE)
+                if (opts && adblock_check_filter_options (regex, opts, req_uri, page_uri))
                     return FALSE;
                 else
                 {
@@ -1001,23 +999,20 @@ adblock_parse_line (gchar* line)
     return adblock_add_url_pattern ("%s", "uri", line);
 }
 
-static void
+static gboolean
 adblock_parse_file (gchar* path)
 {
     FILE* file;
     gchar line[500];
-    gchar *out;
 
     if ((file = g_fopen (path, "r")))
     {
         while (fgets (line, 500, file))
-        {
-            out = adblock_parse_line (line);
-            if (out)
-                g_free (out);
-        }
+            g_free (adblock_parse_line (line));
         fclose (file);
+        return TRUE;
     }
+    return FALSE;
 }
 
 static void



More information about the Xfce4-commits mailing list