summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--amiga/gui.c1
-rwxr-xr-xamiga/launch.c2
-rwxr-xr-xamiga/misc.c2
-rwxr-xr-xatari/misc.c1
-rw-r--r--beos/login.cpp1
-rw-r--r--desktop/download.c2
-rw-r--r--desktop/searchweb.c5
-rw-r--r--framebuffer/fetch.c6
-rw-r--r--gtk/dialogs/source.c4
-rw-r--r--gtk/download.c2
-rw-r--r--gtk/fetch.c6
-rw-r--r--gtk/scaffolding.c15
-rw-r--r--monkey/fetch.c6
-rw-r--r--render/form.c10
-rw-r--r--riscos/download.c10
-rw-r--r--riscos/gui.c10
-rw-r--r--riscos/save.c2
-rw-r--r--utils/url.c199
-rw-r--r--utils/url.h120
-rw-r--r--utils/utsname.h5
-rw-r--r--windows/download.c4
21 files changed, 213 insertions, 200 deletions
diff --git a/amiga/gui.c b/amiga/gui.c
index 5055f93f0..e254687ed 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -245,7 +245,6 @@ static nserror amiga_vmkpath(char **str, size_t *size, size_t nelm, va_list ap)
size_t elm_idx;
char *fname;
size_t fname_len = 0;
- char *curp;
/* check the parameters are all sensible */
if ((nelm == 0) || (nelm > 16)) {
diff --git a/amiga/launch.c b/amiga/launch.c
index 1ccc52026..84d362fa1 100755
--- a/amiga/launch.c
+++ b/amiga/launch.c
@@ -49,7 +49,7 @@ struct ami_protocol *ami_openurl_add_protocol(const char *url)
struct ami_protocol *ami_p =
(struct ami_protocol *)AllocVecTagList(sizeof(struct ami_protocol), NULL);
- if(url_scheme(url, &ami_p->protocol) != URL_FUNC_OK)
+ if(url_scheme(url, &ami_p->protocol) != NSERROR_OK)
{
FreeVec(ami_p);
return NULL;
diff --git a/amiga/misc.c b/amiga/misc.c
index 3f6983476..3b4363ff5 100755
--- a/amiga/misc.c
+++ b/amiga/misc.c
@@ -141,7 +141,7 @@ char *url_to_path(const char *url)
}
}
- if(url_unescape(url2,&unesc) == URL_FUNC_OK)
+ if(url_unescape(url2,&unesc) == NSERROR_OK)
return unesc;
return (char *)url2;
diff --git a/atari/misc.c b/atari/misc.c
index 4d1365fa6..8f58f7fa9 100755
--- a/atari/misc.c
+++ b/atari/misc.c
@@ -213,7 +213,6 @@ hlcache_handle *load_icon(const char *name, hlcache_handle_callback cb,
{
char *url = NULL;
const char *icon_url = NULL;
- int len;
hlcache_handle *c;
nserror err;
nsurl *icon_nsurl;
diff --git a/beos/login.cpp b/beos/login.cpp
index 5cd7a3c83..a82fd54a3 100644
--- a/beos/login.cpp
+++ b/beos/login.cpp
@@ -166,7 +166,6 @@ extern "C" void gui_401login_open(nsurl *url, const char *realm,
nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
lwc_string *host;
- url_func_result res;
host = nsurl_get_component(url, NSURL_HOST);
diff --git a/desktop/download.c b/desktop/download.c
index b458f577c..cad04779f 100644
--- a/desktop/download.c
+++ b/desktop/download.c
@@ -75,7 +75,7 @@ static char *download_default_filename(const char *url)
{
char *nice;
- if (url_nice(url, &nice, false) == URL_FUNC_OK)
+ if (url_nice(url, &nice, false) == NSERROR_OK)
return nice;
return NULL;
diff --git a/desktop/searchweb.c b/desktop/searchweb.c
index 368ad051a..71c872b75 100644
--- a/desktop/searchweb.c
+++ b/desktop/searchweb.c
@@ -63,7 +63,7 @@ bool search_web_new_window(struct browser_window *bw, const char *searchterm)
nsurl *url;
nserror error;
- if (url_escape(searchterm,0, true, NULL, &encsearchterm) != URL_FUNC_OK)
+ if (url_escape(searchterm,0, true, NULL, &encsearchterm) != NSERROR_OK)
return false;
urltxt = search_web_get_url(encsearchterm);
@@ -146,8 +146,7 @@ void search_web_provider_details(int reference)
char *search_web_from_term(const char *searchterm)
{
char *encsearchterm, *url;
- if (url_escape(searchterm, 0, true, NULL, &encsearchterm)
- != URL_FUNC_OK)
+ if (url_escape(searchterm, 0, true, NULL, &encsearchterm) != NSERROR_OK)
return strdup(searchterm);
url = search_web_get_url(encsearchterm);
free(encsearchterm);
diff --git a/framebuffer/fetch.c b/framebuffer/fetch.c
index 7c8dcc589..6d97cfda7 100644
--- a/framebuffer/fetch.c
+++ b/framebuffer/fetch.c
@@ -71,16 +71,16 @@ static char *url_to_path(const char *url)
{
char *path;
char *respath;
- url_func_result res; /* result from url routines */
+ nserror res; /* result from url routines */
res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
return NULL;
}
res = url_unescape(path, &respath);
free(path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
return NULL;
}
diff --git a/gtk/dialogs/source.c b/gtk/dialogs/source.c
index 326e3fbc9..c53c67fe4 100644
--- a/gtk/dialogs/source.c
+++ b/gtk/dialogs/source.c
@@ -369,10 +369,10 @@ gboolean nsgtk_on_source_save_as_activate(GtkMenuItem *widget, gpointer g)
GTK_RESPONSE_ACCEPT,
NULL);
char *filename;
- url_func_result res;
+ nserror res;
res = url_nice(nsg->url, &filename, false);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
filename = strdup(messages_get("SaveSource"));
if (filename == NULL) {
warn_user("NoMemory", 0);
diff --git a/gtk/download.c b/gtk/download.c
index e49e66ef3..2f7250b5f 100644
--- a/gtk/download.c
+++ b/gtk/download.c
@@ -733,7 +733,7 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
if (download == NULL)
return NULL;
- if (url_host(url, &domain) != URL_FUNC_OK) {
+ if (url_host(url, &domain) != NSERROR_OK) {
domain = g_strdup(messages_get("gtkUnknownHost"));
if (domain == NULL) {
free(download);
diff --git a/gtk/fetch.c b/gtk/fetch.c
index a76ad9f4d..c1857ab48 100644
--- a/gtk/fetch.c
+++ b/gtk/fetch.c
@@ -256,16 +256,16 @@ static char *url_to_path(const char *url)
{
char *path;
char *respath;
- url_func_result res; /* result from url routines */
+ nserror res; /* result from url routines */
res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
return NULL;
}
res = url_unescape(path, &respath);
free(path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
return NULL;
}
diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c
index fde195657..7ae61dac0 100644
--- a/gtk/scaffolding.c
+++ b/gtk/scaffolding.c
@@ -672,7 +672,7 @@ MULTIHANDLER(savepage)
NULL);
DIR *d;
char *path;
- url_func_result res;
+ nserror res;
GtkFileFilter *filter = gtk_file_filter_new();
gtk_file_filter_set_name(filter, "Directories");
gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME,
@@ -682,7 +682,7 @@ MULTIHANDLER(savepage)
res = url_nice(nsurl_access(browser_window_get_url(
nsgtk_get_browser_window(g->top_level))), &path, false);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
path = strdup(messages_get("SaveText"));
if (path == NULL) {
warn_user("NoMemory", 0);
@@ -736,15 +736,14 @@ MULTIHANDLER(pdf)
char filename[PATH_MAX];
char dirname[PATH_MAX];
char *url_name;
- url_func_result res;
+ nserror res;
LOG(("Print preview (generating PDF) started."));
res = url_nice(nsurl_access(browser_window_get_url(bw)),
&url_name, true);
- if (res != URL_FUNC_OK) {
- warn_user(messages_get(res == URL_FUNC_NOMEM ? "NoMemory"
- : "URIError"), 0);
+ if (res != NSERROR_OK) {
+ warn_user(messages_get_errorcode(res), 0);
return TRUE;
}
@@ -812,12 +811,12 @@ MULTIHANDLER(plaintext)
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
char *filename;
- url_func_result res;
+ nserror res;
res = url_nice(nsurl_access(browser_window_get_url(
nsgtk_get_browser_window(g->top_level))),
&filename, false);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
filename = strdup(messages_get("SaveText"));
if (filename == NULL) {
warn_user("NoMemory", 0);
diff --git a/monkey/fetch.c b/monkey/fetch.c
index e2530e710..01258bb06 100644
--- a/monkey/fetch.c
+++ b/monkey/fetch.c
@@ -62,16 +62,16 @@ static char *url_to_path(const char *url)
{
char *path;
char *respath;
- url_func_result res; /* result from url routines */
+ nserror res; /* result from url routines */
res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
return NULL;
}
res = url_unescape(path, &respath);
free(path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
return NULL;
}
diff --git a/render/form.c b/render/form.c
index 518d2f626..76a67ba5c 100644
--- a/render/form.c
+++ b/render/form.c
@@ -857,7 +857,7 @@ static char *form_url_encode(struct form *form,
char *name, *value;
char *s, *s2;
unsigned int len, len1, len_init;
- url_func_result url_err;
+ nserror url_err;
if (query_string)
s = malloc(2);
@@ -878,21 +878,21 @@ static char *form_url_encode(struct form *form,
for (; control; control = control->next) {
url_err = url_escape(control->name, 0, true, NULL, &name);
- if (url_err == URL_FUNC_NOMEM) {
+ if (url_err == NSERROR_NOMEM) {
free(s);
return NULL;
}
- assert(url_err == URL_FUNC_OK);
+ assert(url_err == NSERROR_OK);
url_err = url_escape(control->value, 0, true, NULL, &value);
- if (url_err == URL_FUNC_NOMEM) {
+ if (url_err == NSERROR_NOMEM) {
free(name);
free(s);
return NULL;
}
- assert(url_err == URL_FUNC_OK);
+ assert(url_err == NSERROR_OK);
len1 = len + strlen(name) + strlen(value) + 2;
s2 = realloc(s, len1 + 1);
diff --git a/riscos/download.c b/riscos/download.c
index 6cba17ef0..05a2e9ec9 100644
--- a/riscos/download.c
+++ b/riscos/download.c
@@ -230,7 +230,7 @@ static struct gui_download_window *gui_download_window_create(download_context *
struct gui_download_window *dw;
bool space_warning = false;
os_error *error;
- url_func_result res;
+ nserror res;
char *local_path;
nserror err;
size_t i, last_dot;
@@ -260,22 +260,22 @@ static struct gui_download_window *gui_download_window_create(download_context *
/* Get scheme from URL */
res = url_scheme(url, &scheme);
- if (res == URL_FUNC_NOMEM) {
+ if (res == NSERROR_NOMEM) {
warn_user("NoMemory", 0);
free(dw);
return 0;
- } else if (res == URL_FUNC_OK) {
+ } else if (res == NSERROR_OK) {
/* If we have a scheme and it's "file", then
* attempt to use the local filetype directly */
if (strcasecmp(scheme, "file") == 0) {
char *path = NULL;
res = url_path(url, &path);
- if (res == URL_FUNC_NOMEM) {
+ if (res == NSERROR_NOMEM) {
warn_user("NoMemory", 0);
free(scheme);
free(dw);
return 0;
- } else if (res == URL_FUNC_OK) {
+ } else if (res == NSERROR_OK) {
char *raw_path = curl_unescape(path,
strlen(path));
if (raw_path == NULL) {
diff --git a/riscos/gui.c b/riscos/gui.c
index 6447e4d90..7a505cb5a 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -736,7 +736,7 @@ static char *path_to_url(const char *path)
char *unix_path; /* unix path */
char *escurl;
os_error *error;
- url_func_result url_err;
+ nserror url_err;
int urllen;
char *url; /* resulting url */
@@ -795,7 +795,7 @@ static char *path_to_url(const char *path)
/* We don't want '/' to be escaped. */
url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl);
free(url); url = NULL;
- if (url_err != URL_FUNC_OK) {
+ if (url_err != NSERROR_OK) {
LOG(("url_escape failed: %s", url));
return NULL;
}
@@ -816,18 +816,18 @@ char *url_to_path(const char *url)
char *path;
char *filename;
char *respath;
- url_func_result res; /* result from url routines */
+ nserror res; /* result from url routines */
char *r;
res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
warn_user("NoMemory", 0);
return NULL;
}
res = url_unescape(path, &respath);
free(path);
- if (res != URL_FUNC_OK) {
+ if (res != NSERROR_OK) {
return NULL;
}
diff --git a/riscos/save.c b/riscos/save.c
index fa638d37d..749cc5991 100644
--- a/riscos/save.c
+++ b/riscos/save.c
@@ -1251,7 +1251,7 @@ void ro_gui_save_set_state(hlcache_handle *h, gui_save_type save_type,
/* leafname */
if (url && url_nice(url, &nice, nsoption_bool(strip_extensions)) ==
- URL_FUNC_OK) {
+ NSERROR_OK) {
for (i = 0; nice[i]; i++) {
if (nice[i] == '.')
nice[i] = '/';
diff --git a/utils/url.c b/utils/url.c
index ba492f333..b0e23d7f0 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -19,7 +19,7 @@
*/
/** \file
- * URL parsing and joining (implementation).
+ * \brief Implementation of URL parsing and joining operations.
*/
#include <ctype.h>
@@ -43,12 +43,7 @@ struct url_components_internal {
regex_t url_re, url_up_re;
-/**
- * Initialise URL routines.
- *
- * Compiles regular expressions required by the url_ functions.
- */
-
+/* exported interface documented in utils/url.h */
void url_init(void)
{
/* regex from RFC 2396 */
@@ -70,16 +65,7 @@ void url_init(void)
REG_EXTENDED);
}
-
-/**
- * Check whether a host string is an IP address. It should support and
- * detect IPv4 addresses (all of dotted-quad or subsets, decimal or
- * hexadecimal notations) and IPv6 addresses (including those containing
- * embedded IPv4 addresses.)
- *
- * \param host a hostname terminated by '\0'
- * \return true if the hostname is an IP address, false otherwise
- */
+/* exported interface documented in utils/url.h */
bool url_host_is_ip_address(const char *host)
{
struct in_addr ipv4;
@@ -90,7 +76,7 @@ bool url_host_is_ip_address(const char *host)
struct in6_addr ipv6;
char ipv6_addr[64];
#endif
- /* FIXME TODO: Some parts of urldb.c (and perhaps other parts of
+ /** @todo FIXME Some parts of urldb.c (and perhaps other parts of
* NetSurf) make confusions between hosts and "prefixes", we can
* sometimes be erroneously passed more than just a host. Sometimes
* we may be passed trailing slashes, or even whole path segments.
@@ -170,13 +156,12 @@ out_true:
*
* See RFC 3986 for reference.
*
- * \param url a valid absolute or relative URL
- * \param result pointer to buffer to hold components
- * \return URL_FUNC_OK on success
+ * \param url A valid absolute or relative URL.
+ * \param result Pointer to buffer to hold components.
+ * \return NSERROR_OK on success
*/
-
-static url_func_result url_get_components(const char *url,
- struct url_components *result)
+static nserror
+url_get_components(const char *url, struct url_components *result)
{
int storage_length;
char *storage_end;
@@ -197,7 +182,7 @@ static url_func_result url_get_components(const char *url,
storage_length = strlen(url) + 8;
internal->buffer = malloc(storage_length);
if (!internal->buffer)
- return URL_FUNC_NOMEM;
+ return NSERROR_NOMEM;
storage_end = internal->buffer;
/* look for a valid scheme */
@@ -275,7 +260,7 @@ static url_func_result url_get_components(const char *url,
}
assert((result->buffer + storage_length) >= storage_end);
- return URL_FUNC_OK;
+ return NSERROR_OK;
}
@@ -284,10 +269,9 @@ static url_func_result url_get_components(const char *url,
*
* See RFC 3986 for reference.
*
- * \param components the components to reform into a URL
- * \return a new URL allocated on the heap, or NULL on failure
+ * \param components The components to reform into a URL.
+ * \return A new URL allocated on the heap, or NULL on failure
*/
-
static char *url_reform_components(const struct url_components *components)
{
int scheme_len = 0, authority_len = 0, path_len = 0, query_len = 0,
@@ -353,19 +337,10 @@ static void url_destroy_components(const struct url_components *components)
free(internal->buffer);
}
-
-/**
- * Resolve a relative URL to absolute form.
- *
- * \param rel relative URL
- * \param base base URL, must be absolute and cleaned as by nsurl_create()
- * \param result pointer to pointer to buffer to hold absolute url
- * \return URL_FUNC_OK on success
- */
-
-url_func_result url_join(const char *rel, const char *base, char **result)
+/* exported interface documented in utils/url.h */
+nserror url_join(const char *rel, const char *base, char **result)
{
- url_func_result status = URL_FUNC_NOMEM;
+ nserror status = NSERROR_NOMEM;
struct url_components_internal base_components = {0,0,0,0,0,0};
struct url_components_internal *base_ptr = &base_components;
struct url_components_internal rel_components = {0,0,0,0,0,0};
@@ -384,9 +359,9 @@ url_func_result url_join(const char *rel, const char *base, char **result)
/* break down the relative URL (not cached, corruptable) */
status = url_get_components(rel, (struct url_components *) rel_ptr);
- if (status != URL_FUNC_OK) {
+ if (status != NSERROR_OK) {
LOG(("relative url '%s' failed to get components", rel));
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
}
/* [1] relative URL is absolute, use it entirely */
@@ -396,10 +371,10 @@ url_func_result url_join(const char *rel, const char *base, char **result)
/* break down the base URL (possibly cached, not corruptable) */
status = url_get_components(base, (struct url_components *) base_ptr);
- if (status != URL_FUNC_OK) {
+ if (status != NSERROR_OK) {
url_destroy_components((struct url_components *) rel_ptr);
LOG(("base url '%s' failed to get components", base));
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
}
/* [2] relative authority takes presidence */
@@ -542,7 +517,7 @@ url_join_reform_url:
goto url_join_no_mem;
/* return success */
- status = URL_FUNC_OK;
+ status = NSERROR_OK;
url_join_no_mem:
free(start);
@@ -553,27 +528,20 @@ url_join_no_mem:
}
-/**
- * Return the host name from an URL.
- *
- * \param url an absolute URL
- * \param result pointer to pointer to buffer to hold host name
- * \return URL_FUNC_OK on success
- */
-
-url_func_result url_host(const char *url, char **result)
+/* exported interface documented in utils/url.h */
+nserror url_host(const char *url, char **result)
{
- url_func_result status;
+ nserror status;
struct url_components components;
const char *host_start, *host_end;
assert(url);
status = url_get_components(url, &components);
- if (status == URL_FUNC_OK) {
+ if (status == NSERROR_OK) {
if (!components.authority) {
url_destroy_components(&components);
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
}
host_start = strchr(components.authority, '@');
host_start = host_start ? host_start + 1 : components.authority;
@@ -592,7 +560,7 @@ url_func_result url_host(const char *url, char **result)
*result = malloc(host_end - host_start + 1);
if (!(*result)) {
url_destroy_components(&components);
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
}
memcpy((*result), host_start, host_end - host_start);
(*result)[host_end - host_start] = '\0';
@@ -602,31 +570,22 @@ url_func_result url_host(const char *url, char **result)
}
-/**
- * Return the scheme name from an URL.
- *
- * See RFC 3986, 3.1 for reference.
- *
- * \param url an absolute URL
- * \param result pointer to pointer to buffer to hold scheme name
- * \return URL_FUNC_OK on success
- */
-
-url_func_result url_scheme(const char *url, char **result)
+/* exported interface documented in utils/url.h */
+nserror url_scheme(const char *url, char **result)
{
- url_func_result status;
+ nserror status;
struct url_components components;
assert(url);
status = url_get_components(url, &components);
- if (status == URL_FUNC_OK) {
+ if (status == NSERROR_OK) {
if (!components.scheme) {
- status = URL_FUNC_FAILED;
+ status = NSERROR_NOT_FOUND;
} else {
*result = strdup(components.scheme);
if (!(*result))
- status = URL_FUNC_NOMEM;
+ status = NSERROR_NOMEM;
}
}
url_destroy_components(&components);
@@ -634,45 +593,31 @@ url_func_result url_scheme(const char *url, char **result)
}
-/**
- * Extract path segment from an URL
- *
- * \param url an absolute URL
- * \param result pointer to pointer to buffer to hold result
- * \return URL_FUNC_OK on success
- */
-
-url_func_result url_path(const char *url, char **result)
+/* exported interface documented in utils/url.h */
+nserror url_path(const char *url, char **result)
{
- url_func_result status;
+ nserror status;
struct url_components components;
assert(url);
status = url_get_components(url, &components);
- if (status == URL_FUNC_OK) {
+ if (status == NSERROR_OK) {
if (!components.path) {
- status = URL_FUNC_FAILED;
+ status = NSERROR_NOT_FOUND;
} else {
*result = strdup(components.path);
if (!(*result))
- status = URL_FUNC_NOMEM;
+ status = NSERROR_NOMEM;
}
}
url_destroy_components(&components);
return status;
}
-/**
- * Attempt to find a nice filename for a URL.
- *
- * \param url an absolute URL
- * \param result pointer to pointer to buffer to hold filename
- * \param remove_extensions remove any extensions from the filename
- * \return URL_FUNC_OK on success
- */
-url_func_result url_nice(const char *url, char **result,
+/* exported interface documented in utils/url.h */
+nserror url_nice(const char *url, char **result,
bool remove_extensions)
{
int m;
@@ -686,7 +631,7 @@ url_func_result url_nice(const char *url, char **result,
m = regexec(&url_re, url, 10, match, 0);
if (m) {
LOG(("url '%s' failed to match regex", url));
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
}
/* extract the last component of the path, if possible */
@@ -732,7 +677,7 @@ url_func_result url_nice(const char *url, char **result,
*result = malloc(end - start + 1);
if (!*result) {
LOG(("malloc failed"));
- return URL_FUNC_NOMEM;
+ return NSERROR_NOMEM;
}
strncpy(*result, url + start, end - start);
(*result)[end - start] = 0;
@@ -743,7 +688,7 @@ url_func_result url_nice(const char *url, char **result,
*dot = 0;
}
- return URL_FUNC_OK;
+ return NSERROR_OK;
no_path:
@@ -755,7 +700,7 @@ no_path:
match[URL_RE_AUTHORITY].rm_so + 1);
if (!*result) {
LOG(("malloc failed"));
- return URL_FUNC_NOMEM;
+ return NSERROR_NOMEM;
}
strncpy(*result, url + match[URL_RE_AUTHORITY].rm_so,
match[URL_RE_AUTHORITY].rm_eo -
@@ -767,50 +712,38 @@ no_path:
if ((*result)[i] == '.')
(*result)[i] = '_';
- return URL_FUNC_OK;
+ return NSERROR_OK;
}
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
}
-/**
- * Convert an escaped string to plain.
- * \param result unescaped string owned by caller must be freed with free()
- * \return URL_FUNC_OK on success
- */
-url_func_result url_unescape(const char *str, char **result)
+
+/* exported interface documented in utils/url.h */
+nserror url_unescape(const char *str, char **result)
{
char *curlstr;
char *retstr;
curlstr = curl_unescape(str, 0);
if (curlstr == NULL) {
- return URL_FUNC_NOMEM;
+ return NSERROR_NOMEM;
}
retstr = strdup(curlstr);
curl_free(curlstr);
if (retstr == NULL) {
- return URL_FUNC_NOMEM;
+ return NSERROR_NOMEM;
}
*result = retstr;
- return URL_FUNC_OK;
+ return NSERROR_OK;
}
-/**
- * Escape a string suitable for inclusion in an URL.
- *
- * \param unescaped the unescaped string
- * \param toskip number of bytes to skip in unescaped string
- * \param sptoplus true iff spaces should be converted to +
- * \param escexceptions NULL or a string of characters excluded to be escaped
- * \param result pointer to pointer to buffer to hold escaped string
- * \return URL_FUNC_OK on success
- */
-url_func_result url_escape(const char *unescaped, size_t toskip,
+/* exported interface documented in utils/url.h */
+nserror url_escape(const char *unescaped, size_t toskip,
bool sptoplus, const char *escexceptions, char **result)
{
size_t len;
@@ -818,18 +751,18 @@ url_func_result url_escape(const char *unescaped, size_t toskip,
const char *c;
if (!unescaped || !result)
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
*result = NULL;
len = strlen(unescaped);
if (len < toskip)
- return URL_FUNC_FAILED;
+ return NSERROR_NOT_FOUND;
len -= toskip;
escaped = malloc(len * 3 + 1);
if (!escaped)
- return URL_FUNC_NOMEM;
+ return NSERROR_NOMEM;
for (c = unescaped + toskip, d = escaped; *c; c++) {
/* Check if we should escape this byte.
@@ -859,7 +792,7 @@ url_func_result url_escape(const char *unescaped, size_t toskip,
tmpres = malloc(d - escaped + toskip);
if (!tmpres) {
free(escaped);
- return URL_FUNC_NOMEM;
+ return NSERROR_NOMEM;
}
memcpy(tmpres, unescaped, toskip);
@@ -868,7 +801,7 @@ url_func_result url_escape(const char *unescaped, size_t toskip,
free(escaped);
- return URL_FUNC_OK;
+ return NSERROR_OK;
}
@@ -877,25 +810,25 @@ url_func_result url_escape(const char *unescaped, size_t toskip,
int main(int argc, char *argv[])
{
int i;
- url_func_result res;
+ nserror res;
char *s;
url_init();
for (i = 1; i != argc; i++) {
/* printf("==> '%s'\n", argv[i]);
res = url_normalize(argv[i], &s);
- if (res == URL_FUNC_OK) {
+ if (res == NSERROR_OK) {
printf("<== '%s'\n", s);
free(s);
}*/
/* printf("==> '%s'\n", argv[i]);
res = url_host(argv[i], &s);
- if (res == URL_FUNC_OK) {
+ if (res == NSERROR_OK) {
printf("<== '%s'\n", s);
free(s);
}*/
if (1 != i) {
res = url_join(argv[i], argv[1], &s);
- if (res == URL_FUNC_OK) {
+ if (res == NSERROR_OK) {
printf("'%s' + '%s' \t= '%s'\n", argv[1],
argv[i], s);
free(s);
@@ -903,14 +836,14 @@ int main(int argc, char *argv[])
}
/* printf("'%s' => ", argv[i]);
res = url_nice(argv[i], &s, true);
- if (res == URL_FUNC_OK) {
+ if (res == NSERROR_OK) {
printf("'%s', ", s);
free(s);
} else {
printf("failed %u, ", res);
}
res = url_nice(argv[i], &s, false);
- if (res == URL_FUNC_OK) {
+ if (res == NSERROR_OK) {
printf("'%s', ", s);
free(s);
} else {
diff --git a/utils/url.h b/utils/url.h
index 621e62f0d..00cd1bc5f 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -17,26 +17,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/**
+/**
* \file utils/url.h
- * \brief URL parsing and joining (interface).
+ * \brief Interface to URL parsing and joining operations.
*/
#ifndef _NETSURF_UTILS_URL_H_
#define _NETSURF_UTILS_URL_H_
-/** File url prefix */
+#include "utils/errors.h"
+
+/** File url prefix. */
#define FILE_SCHEME_PREFIX "file:///"
-/** File url prefix length */
-#define FILE_SCHEME_PREFIX_LEN 8
-/** URL utility function return codes */
-typedef enum {
- URL_FUNC_OK, /**< No error */
- URL_FUNC_NOMEM, /**< Insufficient memory */
- URL_FUNC_FAILED /**< Non fatal error (eg failed to match regex) */
-} url_func_result;
+/** File url prefix length. */
+#define FILE_SCHEME_PREFIX_LEN 8
+/** Split out components of a url. */
struct url_components {
const char *buffer;
const char *scheme;
@@ -46,16 +43,99 @@ struct url_components {
const char *fragment;
};
+
+/**
+ * Initialise URL routines.
+ *
+ * Compiles regular expressions required by the url_ functions.
+ */
void url_init(void);
+
+
+/**
+ * Check whether a host string is an IP address.
+ *
+ * This call detects IPv4 addresses (all of dotted-quad or subsets,
+ * decimal or hexadecimal notations) and IPv6 addresses (including
+ * those containing embedded IPv4 addresses.)
+ *
+ * \param host a hostname terminated by '\0'
+ * \return true if the hostname is an IP address, false otherwise
+ */
bool url_host_is_ip_address(const char *host);
-url_func_result url_join(const char *rel, const char *base, char **result);
-url_func_result url_host(const char *url, char **result);
-url_func_result url_scheme(const char *url, char **result);
-url_func_result url_nice(const char *url, char **result,
- bool remove_extensions);
-url_func_result url_escape(const char *unescaped, size_t toskip,
- bool sptoplus, const char *escexceptions, char **result);
-url_func_result url_unescape(const char *str, char **result);
-url_func_result url_path(const char *url, char **result);
+
+
+/**
+ * Resolve a relative URL to absolute form.
+ *
+ * \param rel relative URL
+ * \param base base URL, must be absolute and cleaned as by nsurl_create()
+ * \param result pointer to pointer to buffer to hold absolute url
+ * \return NSERROR_OK on success
+ */
+nserror url_join(const char *rel, const char *base, char **result);
+
+
+/**
+ * Return the host name from an URL.
+ *
+ * \param url an absolute URL
+ * \param result pointer to pointer to buffer to hold host name
+ * \return NSERROR_OK on success
+ */
+nserror url_host(const char *url, char **result);
+
+
+/**
+ * Return the scheme name from an URL.
+ *
+ * See RFC 3986, 3.1 for reference.
+ *
+ * \param url an absolute URL
+ * \param result pointer to pointer to buffer to hold scheme name
+ * \return NSERROR_OK on success
+ */
+nserror url_scheme(const char *url, char **result);
+
+
+/**
+ * Attempt to find a nice filename for a URL.
+ *
+ * \param url an absolute URL
+ * \param result pointer to pointer to buffer to hold filename
+ * \param remove_extensions remove any extensions from the filename
+ * \return NSERROR_OK on success
+ */
+nserror url_nice(const char *url, char **result, bool remove_extensions);
+
+/**
+ * Escape a string suitable for inclusion in an URL.
+ *
+ * \param unescaped the unescaped string
+ * \param toskip number of bytes to skip in unescaped string
+ * \param sptoplus true iff spaces should be converted to +
+ * \param escexceptions NULL or a string of characters excluded to be escaped
+ * \param result pointer to pointer to buffer to hold escaped string
+ * \return NSERROR_OK on success
+ */
+nserror url_escape(const char *unescaped, size_t toskip, bool sptoplus, const char *escexceptions, char **result);
+
+
+/**
+ * Convert an escaped string to plain.
+ * \param result unescaped string owned by caller must be freed with free()
+ * \return NSERROR_OK on success
+ */
+nserror url_unescape(const char *str, char **result);
+
+
+/**
+ * Extract path segment from an URL
+ *
+ * \param url an absolute URL
+ * \param result pointer to pointer to buffer to hold result
+ * \return NSERROR_OK on success
+ */
+nserror url_path(const char *url, char **result);
#endif
diff --git a/utils/utsname.h b/utils/utsname.h
index cc267c6d3..cef183670 100644
--- a/utils/utsname.h
+++ b/utils/utsname.h
@@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file utils/utsname.h
+ * \brief Interface to uts API to get name and information about current kernel.
+ */
+
#ifndef _NETSURF_UTILS_UTSNAME_H_
#define _NETSURF_UTILS_UTSNAME_H_
diff --git a/windows/download.c b/windows/download.c
index fe2a09237..b721d1fdc 100644
--- a/windows/download.c
+++ b/windows/download.c
@@ -70,14 +70,14 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
messages_get("UnknownSize") :
human_friendly_bytesize(total_size);
- if (url_nice(url, &filename, false) != URL_FUNC_OK)
+ if (url_nice(url, &filename, false) != NSERROR_OK)
filename = strdup(messages_get("UnknownFile"));
if (filename == NULL) {
warn_user(messages_get("NoMemory"), 0);
free(w);
return NULL;
}
- if (url_host(url, &domain) != URL_FUNC_OK)
+ if (url_host(url, &domain) != NSERROR_OK)
domain = strdup(messages_get("UnknownHost"));
if (domain == NULL) {
warn_user(messages_get("NoMemory"), 0);