Use Midori.URI API in sokoke_prefetch_uri

This commit is contained in:
Christian Dywan 2011-10-29 00:43:03 +02:00
parent cebf09e804
commit d39b62c73e

View file

@ -1546,38 +1546,28 @@ sokoke_prefetch_uri (MidoriWebSettings* settings,
#define MAXHOSTS 50 #define MAXHOSTS 50
static gchar* hosts = NULL; static gchar* hosts = NULL;
static gint host_count = G_MAXINT; static gint host_count = G_MAXINT;
gchar* hostname;
SoupURI* s_uri;
if (!uri)
return FALSE;
if (settings && !katze_object_get_boolean (settings, "enable-dns-prefetching")) if (settings && !katze_object_get_boolean (settings, "enable-dns-prefetching"))
return FALSE; return FALSE;
s_uri = soup_uri_new (uri); if (!(hostname = midori_uri_parse (uri, NULL))
if (!s_uri || !s_uri->host) || !strcmp (hostname, uri)
return FALSE; || g_hostname_is_ip_address (hostname)
|| !midori_uri_is_http (uri))
if (g_hostname_is_ip_address (s_uri->host))
{ {
soup_uri_free (s_uri); g_free (hostname);
return FALSE;
}
if (!g_str_has_prefix (uri, "http"))
{
soup_uri_free (s_uri);
return FALSE; return FALSE;
} }
if (!hosts || if (!hosts ||
!g_regex_match_simple (s_uri->host, hosts, !g_regex_match_simple (hostname, hosts,
G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY)) G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY))
{ {
SoupAddress* address; SoupAddress* address;
gchar* new_hosts; gchar* new_hosts;
address = soup_address_new (s_uri->host, SOUP_ADDRESS_ANY_PORT); address = soup_address_new (hostname, SOUP_ADDRESS_ANY_PORT);
soup_address_resolve_async (address, 0, 0, callback, user_data); soup_address_resolve_async (address, 0, 0, callback, user_data);
g_object_unref (address); g_object_unref (address);
@ -1587,12 +1577,12 @@ sokoke_prefetch_uri (MidoriWebSettings* settings,
host_count = 0; host_count = 0;
} }
host_count++; host_count++;
new_hosts = g_strdup_printf ("%s|%s", hosts, s_uri->host); new_hosts = g_strdup_printf ("%s|%s", hosts, hostname);
katze_assign (hosts, new_hosts); katze_assign (hosts, new_hosts);
} }
else if (callback) else if (callback)
callback (NULL, SOUP_STATUS_OK, user_data); callback (NULL, SOUP_STATUS_OK, user_data);
soup_uri_free (s_uri); g_free (hostname);
return TRUE; return TRUE;
} }