From e4f163447c33db4341f01317013e8e1a47b10301 Mon Sep 17 00:00:00 2001 From: Alexander Butenko Date: Tue, 13 Oct 2009 02:37:52 +0200 Subject: [PATCH] Don't prefetch IP addresses and bail out if the soup URI is invalid --- extensions/dnsprefetch.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/extensions/dnsprefetch.c b/extensions/dnsprefetch.c index 4a00be3f..83b52e99 100644 --- a/extensions/dnsprefetch.c +++ b/extensions/dnsprefetch.c @@ -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 (WebKitWebView* web_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)) { -- 2.39.5