]> spindle.queued.net Git - midori/commitdiff
Don't prefetch IP addresses and bail out if the soup URI is invalid
authorAlexander Butenko <a.butenka@gmail.com>
Tue, 13 Oct 2009 00:37:52 +0000 (02:37 +0200)
committerChristian Dywan <christian@twotoasts.de>
Tue, 13 Oct 2009 00:37:52 +0000 (02:37 +0200)
extensions/dnsprefetch.c

index 4a00be3fad7e5f0c7dabf9fa337963d303d86b84..83b52e9912bb0eb0c12dd70185d5b5cd16720baf 100644 (file)
@@ -21,18 +21,34 @@ static gchar* hosts = NULL;
 static int host_count;
 
 static void
-dnsprefetch_do_prefetch (WebKitWebView *web_view,
-                         gchar         *title,
-                         gchar         *uri,
+dnsprefetch_do_prefetch (WebKitWebViewweb_view,
+                         const gchar*   title,
+                         const char*    uri,
                          gpointer       user_data)
 {
-    SoupURI* s_uri;
+     SoupURI* s_uri;
 
-     /* FIXME: Ignore IP addresses */
-     if (!(uri && g_str_has_prefix (uri, "http")))
+     if (!uri)
+        return;
+     s_uri = soup_uri_new (uri);
+     if (!s_uri)
          return;
 
-     s_uri = soup_uri_new (uri);
+     #if GLIB_CHECK_VERSION (2, 22, 0)
+     if (g_hostname_is_ip_address (s_uri->host))
+     #else
+     if (g_ascii_isdigit (s_uri->host[0]) && g_strstr_len (s_uri->host, 4, "."))
+     #endif
+     {
+         soup_uri_free (s_uri);
+         return;
+     }
+     if (!g_str_has_prefix (uri, "http"))
+     {
+         soup_uri_free (s_uri);
+         return;
+     }
+
      if (!g_regex_match_simple (s_uri->host, hosts,
                                 G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY))
      {