diff options
author | James Bursa <james@netsurf-browser.org> | 2003-12-26 16:21:46 +0000 |
---|---|---|
committer | James Bursa <james@netsurf-browser.org> | 2003-12-26 16:21:46 +0000 |
commit | 20a6f739dc48afdf902eb92e0c8422ebcf0d47a4 (patch) | |
tree | 7d0f603c19989963dcf0467fe75cd91013a31d9e | |
parent | 894703b53b27a25d58d9a6fa77e99d967e9588f6 (diff) | |
download | netsurf-20a6f739dc48afdf902eb92e0c8422ebcf0d47a4.tar.gz netsurf-20a6f739dc48afdf902eb92e0c8422ebcf0d47a4.tar.bz2 |
[project @ 2003-12-26 16:21:46 by bursa]
Rewrite get_host_from_url() to use uri library.
svn path=/import/netsurf/; revision=444
-rw-r--r-- | desktop/loginlist.c | 4 | ||||
-rw-r--r-- | riscos/401login.c | 1 | ||||
-rw-r--r-- | utils/utils.c | 33 |
3 files changed, 22 insertions, 16 deletions
diff --git a/desktop/loginlist.c b/desktop/loginlist.c index 147b6bed7..090f877f5 100644 --- a/desktop/loginlist.c +++ b/desktop/loginlist.c @@ -30,6 +30,8 @@ void login_list_add(char *host, char* logindets) { char *temp = get_host_from_url(host); char *i; + assert(temp); + /* Go back to the path base ie strip the document name * eg. http://www.blah.com/blah/test.htm becomes * http://www.blah.com/blah/ @@ -77,6 +79,7 @@ struct login *login_list_get(char *host) { return NULL; temphost = get_host_from_url(host); + assert(temphost); temp = xstrdup(host); /* Smallest thing to check for is the scheme + host name + trailing '/' @@ -84,6 +87,7 @@ struct login *login_list_get(char *host) { */ if (strlen(temphost) > strlen(temp)) { temp = get_host_from_url(host); + assert(temp); } /* Work backwards through the path, directory at at time. diff --git a/riscos/401login.c b/riscos/401login.c index 4e428ab3c..82a18df81 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -59,6 +59,7 @@ void gui_401login_open(struct browser_window *bw, struct content *c, char *realm murl = c->url; host = get_host_from_url(murl); + assert(host); bwin = bw; ro_gui_401login_open(host, realm, murl); diff --git a/utils/utils.c b/utils/utils.c index 1487ac1c7..e8a8fbabc 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -217,27 +217,28 @@ fail: return 0; } - - -char *get_host_from_url (char *url) { - char *host = xcalloc(strlen(url)+10, sizeof(char)); - int i; - - i = strspn(url, "abcdefghijklmnopqrstuvwxyz"); - if (url[i] == ':') { - strcpy(host, url); - i += 3; - } +/** + * Extract the host name from a url. + * + * \param url an absolute URL + * \return a new string, or 0 in case of error + */ - for (; host[i] != 0 && host[i] != '/'; i++) - host[i] = tolower(host[i]); +char *get_host_from_url(char *url) +{ + char *host = 0; + uri_t *uri; - host[i] = '/'; - host[i+1] = 0; + uri = uri_alloc(url, strlen(url)); + if (!uri) + return 0; + if (uri->host) + host = xstrdup(uri->host); + uri_free(uri); - return host; + return host; } |