From fbf7c11f928a6f8aafb12601f211d54250b91a11 Mon Sep 17 00:00:00 2001 From: Diego Escalante Urrelo Date: Wed, 10 Feb 2010 11:59:07 -0500 Subject: Use SoupURI to get host name in ephy-string Bug #582035 --- lib/ephy-string.c | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) (limited to 'lib') diff --git a/lib/ephy-string.c b/lib/ephy-string.c index 7f7ec8481..0b07dc794 100644 --- a/lib/ephy-string.c +++ b/lib/ephy-string.c @@ -27,6 +27,7 @@ #include #include #include +#include #define ELLIPSIS "\xe2\x80\xa6" @@ -448,47 +449,18 @@ ephy_string_canonicalize_pathname (const char *cpath) char * ephy_string_get_host_name (const char *url) { - const char *start; - const char *p; + SoupURI *uri; + char *ret; if (url == NULL || g_str_has_prefix (url, "file://")) return NULL; - - start = strstr (url, "//"); - if (start == NULL || start == '\0') - { - /* Not an URL */ - return NULL; - } - if (strlen (start) > 2) - { - /* Go past the protocol part */ - start = start + 2; - } - else - { - /* Not an URL again */ - return NULL; - } - p = strchr (start, '@'); - if (p != NULL) - { - /* We have a username:password@hostname scheme, skip it. */ - if (strlen (p) > 1) start = ++p; - } - p = strchr (start, ':'); - if (p != NULL) - { - /* hostname:port, skip port */ - return g_strndup (start, (p - start)); - } - p = strchr (start, '/'); - if (p == NULL) - { - /* No more slashes in the url, we assume it's a host name */ - return g_strdup (start); - } - return g_strndup (start, (p - start)); + uri = soup_uri_new (url); + if (uri == NULL) return NULL; + + ret = g_strdup (uri->host); + soup_uri_free (uri); + + return ret; } char * -- cgit