diff options
-rw-r--r-- | utils/nsurl.c | 45 | ||||
-rw-r--r-- | utils/nsurl.h | 24 |
2 files changed, 69 insertions, 0 deletions
diff --git a/utils/nsurl.c b/utils/nsurl.c index 392d98346..e2b48a888 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -1183,6 +1183,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) { assert(url != NULL); diff --git a/utils/nsurl.h b/utils/nsurl.h index 23dd3f251..90fb5decb 100644 --- a/utils/nsurl.h +++ b/utils/nsurl.h @@ -23,6 +23,7 @@ #ifndef _NETSURF_UTILS_NSURL_H_ #define _NETSURF_UTILS_NSURL_H_ +#include <libwapcaplet/libwapcaplet.h> #include "utils/errors.h" @@ -124,6 +125,29 @@ nserror nsurl_get(const nsurl *url, nsurl_component parts, /** + * 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 * * \param url NetSurf URL object |