[Xfce4-commits] <midori:master> Adblock: check if file contains any metadata first

Christian Dywan noreply at xfce.org
Tue Sep 11 00:46:02 CEST 2012


Updating branch refs/heads/master
         to 82242a8c2e74c788e5cae9085c64d1ed31e3078b (commit)
       from 8de05bc07dca842cb3b5bb1105c7a1fbdf0dda04 (commit)

commit 82242a8c2e74c788e5cae9085c64d1ed31e3078b
Author: Paweł Forysiuk <tuxator at o2.pl>
Date:   Wed Sep 5 23:58:21 2012 +0200

    Adblock: check if file contains any metadata first

 extensions/adblock.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index 2dbd409..91855da 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -1539,14 +1539,16 @@ static gboolean
 adblock_file_is_up_to_date (gchar* path)
 {
     FILE* file;
-    guint days_to_expire = 0;
-    gchar* timestamp = NULL;
     gchar line[2000];
 
     /* Check a chunk of header for update info */
     if ((file = g_fopen (path, "r")))
     {
+        guint days_to_expire = 0;
+        gchar* timestamp = NULL;
         guint i;
+        gboolean found_meta = FALSE;
+
         for (i = 0; i <= 10; i++)
         {
             fgets (line, 2000, file);
@@ -1555,6 +1557,7 @@ adblock_file_is_up_to_date (gchar* path)
                 gchar** parts = g_strsplit (line, " ", 4);
                 days_to_expire = atoi (parts[2]);
                 g_strfreev (parts);
+                found_meta = TRUE;
             }
             if (strncmp ("! This list expires after", line, 25) == 0)
             {
@@ -1566,6 +1569,7 @@ adblock_file_is_up_to_date (gchar* path)
                     days_to_expire = (atoi (parts[5])) / 24;
 
                 g_strfreev (parts);
+                found_meta = TRUE;
             }
 
             if (strncmp ("! Last modified", line, 15) == 0
@@ -1575,9 +1579,16 @@ adblock_file_is_up_to_date (gchar* path)
                 timestamp = g_strdup (parts[1] + 1);
                 g_strchomp (timestamp);
                 g_strfreev (parts);
+                found_meta = TRUE;
             }
         }
 
+        if (!found_meta)
+        {
+            g_print ("Adblock: no metadata found in %s (broken download?)\n", path);
+            return FALSE;
+        }
+
         if (days_to_expire && timestamp != NULL)
         {
             guint days_elapsed = 0;


More information about the Xfce4-commits mailing list