summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2010-04-16 23:56:53 +0000
committerVincent Sanders <vince@netsurf-browser.org>2010-04-16 23:56:53 +0000
commit448b0275ae4d62b31f64e3c6399d4fb5a045315c (patch)
treed42cf1938d8ef3497381b7a8858651044f58ea7c
parent01eb197f56ae69b0e4dba5d3475585d9cdda599c (diff)
downloadnetsurf-448b0275ae4d62b31f64e3c6399d4fb5a045315c.tar.gz
netsurf-448b0275ae4d62b31f64e3c6399d4fb5a045315c.tar.bz2
Fix file: handling on risc os, gtk, windows and framebuffer frontends
svn path=/trunk/netsurf/; revision=10419
-rw-r--r--content/fetchers/fetch_curl.c5
-rw-r--r--framebuffer/findfile.c27
-rw-r--r--framebuffer/misc.c5
-rw-r--r--gtk/gtk_gui.c21
-rw-r--r--riscos/gui.c53
-rw-r--r--windows/findfile.c6
6 files changed, 80 insertions, 37 deletions
diff --git a/content/fetchers/fetch_curl.c b/content/fetchers/fetch_curl.c
index e3f3d492b..aad0b603c 100644
--- a/content/fetchers/fetch_curl.c
+++ b/content/fetchers/fetch_curl.c
@@ -1155,8 +1155,7 @@ bool fetch_curl_process_headers(struct curl_fetch_info *f)
/* find MIME type from filetype for local files */
if (strncmp(f->url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN) == 0) {
struct stat s;
- char *url_path = curl_unescape(f->url + FILE_SCHEME_PREFIX_LEN,
- (int) strlen(f->url + FILE_SCHEME_PREFIX_LEN));
+ char *url_path = url_to_path(f->url);
LOG(("Obtaining mime type for file %s", url_path));
@@ -1209,7 +1208,7 @@ bool fetch_curl_process_headers(struct curl_fetch_info *f)
}
if (url_path != NULL)
- curl_free(url_path);
+ free(url_path);
}
if (f->abort)
diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c
index 64d96fcb4..a00f0f835 100644
--- a/framebuffer/findfile.c
+++ b/framebuffer/findfile.c
@@ -23,6 +23,8 @@
#include <stdlib.h>
#include <string.h>
+#include <curl/curl.h>
+
#include "utils/log.h"
#include "utils/url.h"
@@ -30,12 +32,29 @@
char *path_to_url(const char *path)
{
- char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+ int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
+ char *url = malloc(urllen);
+
+ if (*path == '/') {
+ path++; /* file: paths are already absolute */
+ }
+
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
+
+ return url;
+}
+
+
+char *url_to_path(const char *url)
+{
+ char *url_path = curl_unescape(url, 0);
+ char *path;
- strcpy(r, FILE_SCHEME_PREFIX);
- strcat(r, path);
+ /* return the absolute path including leading / */
+ path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
+ curl_free(url_path);
- return r;
+ return path;
}
/**
diff --git a/framebuffer/misc.c b/framebuffer/misc.c
index c5f367019..5e351f517 100644
--- a/framebuffer/misc.c
+++ b/framebuffer/misc.c
@@ -40,10 +40,6 @@ bool cookies_update(const char *domain, const struct cookie_data *data)
return true;
}
-char *url_to_path(const char *url)
-{
- return strdup(url + 5);
-}
/**
* Return the filename part of a full path
@@ -51,7 +47,6 @@ char *url_to_path(const char *url)
* \param path full path and filename
* \return filename (will be freed with free())
*/
-
char *filename_from_path(char *path)
{
char *leafname;
diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c
index 9d0c04bbb..8f5ccf3f9 100644
--- a/gtk/gtk_gui.c
+++ b/gtk/gtk_gui.c
@@ -757,18 +757,29 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len,
char *path_to_url(const char *path)
{
- char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+ int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
+ char *url = malloc(urllen);
- strcpy(r, FILE_SCHEME_PREFIX);
- strcat(r, path);
+ if (*path == '/') {
+ path++; /* file: paths are already absolute */
+ }
- return r;
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
+
+ return url;
}
char *url_to_path(const char *url)
{
- return strdup(url + FILE_SCHEME_PREFIX_LEN);
+ char *url_path = curl_unescape(url, 0);
+ char *path;
+
+ /* return the absolute path including leading / */
+ path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
+ curl_free(url_path);
+
+ return path;
}
diff --git a/riscos/gui.c b/riscos/gui.c
index be0ef6844..edfe778c6 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -2037,10 +2037,15 @@ void ro_msg_window_info(wimp_message *message)
char *path_to_url(const char *path)
{
int spare;
- char *buffer, *url, *escurl;
+ char *canonical_path; /* canonicalised RISC OS path */
+ char *unix_path; /* unix path */
+ char *escurl;
os_error *error;
url_func_result url_err;
+ int urllen;
+ char *url; /* resulting url */
+ /* calculate the canonical risc os path */
error = xosfscontrol_canonicalise_path(path, 0, 0, 0, 0, &spare);
if (error) {
LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s",
@@ -2049,38 +2054,48 @@ char *path_to_url(const char *path)
return NULL;
}
- buffer = malloc(1 - spare);
- url = malloc(1 - spare + 10);
- if (!buffer || !url) {
+ canonical_path = malloc(1 - spare);
+ if (canonical_path == NULL) {
LOG(("malloc failed"));
warn_user("NoMemory", 0);
- free(buffer);
- free(url);
+ free(canonical_path);
return NULL;
}
- error = xosfscontrol_canonicalise_path(path, buffer, 0, 0, 1 - spare,
- 0);
+ error = xosfscontrol_canonicalise_path(path, canonical_path, 0, 0, 1 - spare, 0);
if (error) {
LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s",
error->errnum, error->errmess));
warn_user("PathToURL", error->errmess);
- free(buffer);
- free(url);
+ free(canonical_path);
+ return NULL;
+ }
+
+ /* create a unix path from teh cananocal risc os one */
+ unix_path = __unixify(canonical_path, __RISCOSIFY_NO_REVERSE_SUFFIX, NULL, 0, 0);
+
+ if (unix_path == NULL)
+ LOG(("__unixify failed: %s", canonical_path));
+ free(canonical_path);
return NULL;
}
+ free(canonical_path);
- memcpy(url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN);
- if (__unixify(buffer, __RISCOSIFY_NO_REVERSE_SUFFIX,
- url + FILE_SCHEME_PREFIX_LEN,
- 1 - spare + 10 - FILE_SCHEME_PREFIX_LEN,
- 0) == NULL) {
- LOG(("__unixify failed: %s", buffer));
- free(buffer);
- free(url);
+ /* convert the unix path into a url */
+ urllen = strlen(unix_path) + FILE_SCHEME_PREFIX_LEN + 1;
+ url = malloc(urllen);
+ if (url == NULL) {
+ LOG(("Unable to allocate url"));
+ free(unix_path);
return NULL;
}
- free(buffer); buffer = NULL;
+
+ if (*unix_path == '/') {
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path + 1);
+ } else {
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path);
+ }
+ free(unix_path);
/* We don't want '/' to be escaped. */
url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl);
diff --git a/windows/findfile.c b/windows/findfile.c
index c3e613d3a..f4f5e4557 100644
--- a/windows/findfile.c
+++ b/windows/findfile.c
@@ -38,10 +38,14 @@ static char *realpath(const char *path, char *resolved_path)
char *path_to_url(const char *path)
{
- char *url = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+ char *url = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 3);
char *sidx;
strcpy(url, FILE_SCHEME_PREFIX);
+ if (*path == '/') {
+ /* unix style path start, so try wine Z: */
+ strcat(url, "Z:");
+ }
strcat(url, path);
sidx = strrchr(url, '\\');