Add nsurl_get_lwc function.

svn path=/trunk/netsurf/; revision=12894
This commit is contained in:
Michael Drake 2011-09-26 21:50:16 +00:00
parent ad3af34742
commit e90f794706
2 changed files with 69 additions and 0 deletions

View File

@ -1182,6 +1182,51 @@ nserror nsurl_get(const nsurl *url, nsurl_component parts,
}
/* exported interface, documented in nsurl.h */
lwc_string *nsurl_get_lwc(const nsurl *url, nsurl_component part)
{
assert(url != NULL);
switch (part) {
case NSURL_SCHEME:
return (url->scheme != NULL) ?
lwc_string_ref(url->scheme) : NULL;
case NSURL_USERNAME:
return (url->username != NULL) ?
lwc_string_ref(url->username) : NULL;
case NSURL_PASSWORD:
return (url->password != NULL) ?
lwc_string_ref(url->password) : NULL;
case NSURL_HOST:
return (url->host != NULL) ?
lwc_string_ref(url->host) : NULL;
case NSURL_PORT:
return (url->port != NULL) ?
lwc_string_ref(url->port) : NULL;
case NSURL_PATH:
return (url->path != NULL) ?
lwc_string_ref(url->path) : NULL;
case NSURL_QUERY:
return (url->query != NULL) ?
lwc_string_ref(url->query) : NULL;
case NSURL_FRAGMENT:
return (url->fragment != NULL) ?
lwc_string_ref(url->fragment) : NULL;
default:
LOG(("Unsupported value passed to part param."));
assert(0);
}
}
/* exported interface, documented in nsurl.h */
bool nsurl_enquire(const nsurl *url, nsurl_component part)
{

View File

@ -23,6 +23,7 @@
#ifndef _NETSURF_UTILS_NSURL_H_
#define _NETSURF_UTILS_NSURL_H_
#include <libwapcaplet/libwapcaplet.h>
#include "utils/errors.h"
@ -123,6 +124,29 @@ nserror nsurl_get(const nsurl *url, nsurl_component parts,
char **url_s, size_t *url_l);
/**
* Get part of a URL as a lwc_string, from a NetSurf URL object
*
* \param url NetSurf URL object
* \param part The URL component required
* \return the required component as an lwc_string, or NULL
*
* The caller owns the returned lwc_string and should call lwc_string_unref
* when they are done with it.
*
* The valid values for the part parameter are:
* NSURL_SCHEME
* NSURL_USERNAME
* NSURL_PASSWORD
* NSURL_HOST
* NSURL_PORT
* NSURL_PATH
* NSURL_QUERY
* NSURL_FRAGMENT
*/
lwc_string *nsurl_get_lwc(const nsurl *url, nsurl_component part);
/**
* Enquire about the existence of componenets in a given URL
*