From 00b6cfc57e27f8146d9b41ba8e63038a4f9df70e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 26 May 2014 23:43:36 +0100 Subject: rework path to url mapping functions to convert from and to nsurl --- framebuffer/fetch.c | 62 ++--------------------------------------------------- 1 file changed, 2 insertions(+), 60 deletions(-) (limited to 'framebuffer/fetch.c') diff --git a/framebuffer/fetch.c b/framebuffer/fetch.c index 6d97cfda7..b32a95168 100644 --- a/framebuffer/fetch.c +++ b/framebuffer/fetch.c @@ -26,66 +26,15 @@ #include #include "utils/nsurl.h" -#include "utils/url.h" #include "utils/log.h" #include "utils/filepath.h" +#include "utils/file.h" #include "desktop/gui.h" #include "framebuffer/findfile.h" #include "framebuffer/fetch.h" -/** - * Convert a pathname to a file: URL. - * - * \param path pathname - * \return URL, allocated on heap, or NULL on failure - */ -static char *path_to_url(const char *path) -{ - int urllen; - char *url; - - if (path == NULL) - return NULL; - - urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; - url = malloc(urllen); - - if (*path == '/') { - path++; /* file: paths are already absolute */ - } - - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); - - return url; -} - -/** - * Convert a file: URL to a pathname. - * - * \param url a file: URL - * \return pathname, allocated on heap, or NULL on failure - */ -static char *url_to_path(const char *url) -{ - char *path; - char *respath; - nserror res; /* result from url routines */ - - res = url_path(url, &path); - if (res != NSERROR_OK) { - return NULL; - } - - res = url_unescape(path, &respath); - free(path); - if (res != NSERROR_OK) { - return NULL; - } - - return respath; -} /** * Translate resource to full url. @@ -101,17 +50,12 @@ static char *url_to_path(const char *url) static nsurl *get_resource_url(const char *path) { char buf[PATH_MAX]; - char *raw; nsurl *url = NULL; if (strcmp(path, "favicon.ico") == 0) path = "favicon.png"; - raw = path_to_url(filepath_sfind(respaths, buf, path)); - if (raw != NULL) { - nsurl_create(raw, &url); - free(raw); - } + netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url); return url; } @@ -148,8 +92,6 @@ static const char *fetch_filetype(const char *unix_path) /* table for fetch operations */ static struct gui_fetch_table fetch_table = { .filetype = fetch_filetype, - .path_to_url = path_to_url, - .url_to_path = url_to_path, .get_resource_url = get_resource_url, }; -- cgit v1.2.3