Fix file: handling on risc os, gtk, windows and framebuffer frontends

svn path=/trunk/netsurf/; revision=10419
This commit is contained in:
Vincent Sanders 2010-04-16 23:56:53 +00:00
parent 01eb197f56
commit 448b0275ae
6 changed files with 80 additions and 37 deletions

View File

@ -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)

View File

@ -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);
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)
{
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;
}
/**

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
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);
/* 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(buffer); buffer = NULL;
free(canonical_path);
/* 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;
}
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);

View File

@ -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, '\\');