Precis:

In theory, this patch fixes handling of file: URIs.
It behaves correctly with the RISC OS, GTK, and framebuffer frontends.
It needs testing with Amiga, BeOS, and Windows frontends.


Added files




Changed files


 amiga/misc.c                  |   29 ++++++++++++++++-------------
 beos/beos_gui.cpp             |    8 +++++---
 content/fetchers/fetch_curl.c |   12 +++++-------
 framebuffer/findfile.c        |    6 ++++--
 framebuffer/misc.c            |    3 ++-
 gtk/gtk_gui.c                 |    8 +++++---
 gtk/gtk_scaffolding.c         |    5 +++--
 riscos/gui.c                  |   13 +++++++------
 utils/url.h                   |    4 ----
 windows/findfile.c            |    9 +++++----
 windows/misc.c                |    3 ++-
 11 files changed, 54 insertions(+), 46 deletions(-)


Index: framebuffer/findfile.c
===================================================================
--- framebuffer/findfile.c      (revision 10385)
+++ framebuffer/findfile.c      (working copy)
@@ -25,14 +25,16 @@
 
 #include "utils/log.h"
 #include "utils/url.h"
+#include "utils/utils.h"
 
 #include "framebuffer/findfile.h"
 
 char *path_to_url(const char *path)
 {
-       char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+       /* Assumption: we're on a platform that uses unix paths */
+       char *r = malloc(strlen(path) + SLEN("file://") + 1);
 
-       strcpy(r, FILE_SCHEME_PREFIX);
+       strcpy(r, "file://");
        strcat(r, path);
 
        return r;
Index: framebuffer/misc.c
===================================================================
--- framebuffer/misc.c  (revision 10385)
+++ framebuffer/misc.c  (working copy)
@@ -42,7 +42,8 @@
 
 char *url_to_path(const char *url)
 {
-       return strdup(url + 5);
+       /* Assumption: we're on a platform that uses unix paths */
+       return strdup(url + SLEN("file://"));
 }
 
 /**
Index: gtk/gtk_scaffolding.c
===================================================================
--- gtk/gtk_scaffolding.c       (revision 10385)
+++ gtk/gtk_scaffolding.c       (working copy)
@@ -388,9 +388,10 @@
 {
        struct browser_window *bw = gui_window_get_browser_window(
                        current_model->top_level);
-       char url[strlen(filename) + FILE_SCHEME_PREFIX_LEN + 1];
+       /* Assumption: we're on a platform that uses unix paths */
+       char url[strlen(filename) + SLEN("file://") + 1];
 
-       sprintf(url, FILE_SCHEME_PREFIX"%s", filename);
+       sprintf(url, "file://%s", filename);
 
         browser_window_go(bw, url, 0, true);
 
Index: gtk/gtk_gui.c
===================================================================
--- gtk/gtk_gui.c       (revision 10385)
+++ gtk/gtk_gui.c       (working copy)
@@ -738,9 +738,10 @@
 
 char *path_to_url(const char *path)
 {
-       char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+       /* Assumption: we're on a platform that uses unix paths */
+       char *r = malloc(strlen(path) + SLEN("file://") + 1);
 
-       strcpy(r, FILE_SCHEME_PREFIX);
+       strcpy(r, "file://");
        strcat(r, path);
 
        return r;
@@ -749,7 +750,8 @@
 
 char *url_to_path(const char *url)
 {
-       return strdup(url + FILE_SCHEME_PREFIX_LEN);
+       /* Assumption: we're on a platform that uses unix paths */
+       return strdup(url + SLEN("file://"));
 }
 
 
Index: beos/beos_gui.cpp
===================================================================
--- beos/beos_gui.cpp   (revision 10385)
+++ beos/beos_gui.cpp   (working copy)
@@ -1151,9 +1151,10 @@
 
 char *path_to_url(const char *path)
 {
-       char *r = (char *)malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+       /* Assumption: BeOS/Haiku use unix-style paths */
+       char *r = (char *)malloc(strlen(path) + SLEN("file://") + 1);
 
-       strcpy(r, FILE_SCHEME_PREFIX);
+       strcpy(r, "file://");
        strcat(r, path);
 
        return r;
@@ -1161,7 +1162,8 @@
 
 char *url_to_path(const char *url)
 {
-       return strdup(url + FILE_SCHEME_PREFIX_LEN);
+       /* Assumption: BeOS/Haiku use unix-style paths */
+       return strdup(url + SLEN("file://"));
 }
 
 bool cookies_update(const char *domain, const struct cookie_data *data)
Index: windows/findfile.c
===================================================================
--- windows/findfile.c  (revision 10385)
+++ windows/findfile.c  (working copy)
@@ -24,8 +24,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "utils/log.h"
 #include "utils/url.h"
-#include "utils/log.h"
 #include "utils/utils.h"
 
 #include "windows/findfile.h"
@@ -38,16 +38,17 @@
 
 char *path_to_url(const char *path)
 {
-       char *url = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+       /* Assumption: Windows path does not have leading '/' */
+       char *url = malloc(strlen(path) + SLEN("file:///") + 1);
        char *sidx;
 
-       strcpy(url, FILE_SCHEME_PREFIX);
+       strcpy(url, "file:///");
        strcat(url, path);
 
        sidx = strrchr(url, '\\');
        while (sidx != NULL) {
                *sidx = '/';
-               sidx = strrchr(url, '\\');
+               sidx = strrchr(sidx, '\\');
        }
 
        return url;
Index: windows/misc.c
===================================================================
--- windows/misc.c      (revision 10385)
+++ windows/misc.c      (working copy)
@@ -48,7 +48,8 @@
 
 char *url_to_path(const char *url)
 {
-       return strdup(url + 5);
+       /* Assumption: Win32 path does not have leading '/' */
+       return strdup(url + SLEN("file:///"));
 }
 
 /**
Index: utils/url.h
===================================================================
--- utils/url.h (revision 10385)
+++ utils/url.h (working copy)
@@ -24,10 +24,6 @@
 #ifndef _NETSURF_UTILS_URL_H_
 #define _NETSURF_UTILS_URL_H_
 
-/* file url prefix */
-#define FILE_SCHEME_PREFIX "file:///"
-#define FILE_SCHEME_PREFIX_LEN 8
-
 typedef enum {
        URL_FUNC_OK,     /**< No error */
        URL_FUNC_NOMEM,  /**< Insufficient memory */
Index: riscos/gui.c
===================================================================
--- riscos/gui.c        (revision 10385)
+++ riscos/gui.c        (working copy)
@@ -2070,10 +2070,10 @@
                return NULL;
        }
 
-       memcpy(url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN);
+       memcpy(url, "file://", SLEN("file://"));
        if (__unixify(buffer, __RISCOSIFY_NO_REVERSE_SUFFIX,
-                       url + FILE_SCHEME_PREFIX_LEN,
-                       1 - spare + 10 - FILE_SCHEME_PREFIX_LEN,
+                       url + SLEN("file://"),
+                       1 - spare + 10 - SLEN("file://"),
                        0) == NULL) {
                LOG(("__unixify failed: %s", buffer));
                free(buffer);
@@ -2083,7 +2083,7 @@
        free(buffer); buffer = NULL;
 
        /* We don't want '/' to be escaped.  */
-       url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl);
+       url_err = url_escape(url, SLEN("file://"), false, "/", &escurl);
        free(url); url = NULL;
        if (url_err != URL_FUNC_OK) {
                LOG(("url_escape failed: %s", url));
@@ -2106,10 +2106,11 @@
        char *temp_name, *r;
        char *filename;
 
-       if (strncmp(url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN))
+       if (strncmp(url, "file:///", SLEN("file:///")))
                return NULL;
 
-       temp_name = curl_unescape(url + 7, strlen(url) - 7);
+       temp_name = curl_unescape(url + SLEN("file://"), 
+                       strlen(url) - SLEN("file://"));
 
        if (!temp_name) {
                warn_user("NoMemory", 0);
Index: content/fetchers/fetch_curl.c
===================================================================
--- content/fetchers/fetch_curl.c       (revision 10385)
+++ content/fetchers/fetch_curl.c       (working copy)
@@ -1098,6 +1098,7 @@
 #undef SKIP_ST
 }
 
+
 /**
  * Find the status code and content type and inform the caller.
  *
@@ -1153,13 +1154,10 @@
        }
 
        /* find MIME type from filetype for local files */
-       if (strncmp(f->url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN) == 0) {
+       if (strncmp(f->url, "file:///", 8) == 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));
-
                if (url_path != NULL && stat(url_path, &s) == 0) {
                        /* file: URL and file exists */
                        char header[64];
@@ -1203,13 +1201,13 @@
                                fetch_send_callback(FETCH_NOTMODIFIED, 
                                                f->fetch_handle, 0, 0,
                                                FETCH_ERROR_NO_ERROR);
-                               curl_free(url_path);
+                               free(url_path);
                                return true;
                        }
                }
 
                if (url_path != NULL)
-                       curl_free(url_path);
+                       free(url_path);
        }
 
        if (f->abort)
Index: amiga/misc.c
===================================================================
--- amiga/misc.c        (revision 10385)
+++ amiga/misc.c        (working copy)
@@ -59,23 +59,25 @@
 
 char *url_to_path(const char *url)
 {
+       /* Assumption: Amiga path does not start with '/' */
        char *tmps, *unesc;
        CURL *curl;
 
-       tmps = strstr(url, "///localhost/") + 13;
+       if (strncmp(url, "file:///", SLEN("file:///")) != 0)
+               return NULL;
 
-       if(tmps < url) tmps = strstr(url,"///") + 3;
+       url += SLEN("file:///");
 
-       if(tmps >= url)
+       if (strncmp(url, "localhost/", SLEN("localhost/")) == 0)
+               url += SLEN("localhost/");
+
+       if(curl = curl_easy_init())
        {
-               if(curl = curl_easy_init())
-               {
-                       unesc = curl_easy_unescape(curl,tmps,0,NULL);
-                       tmps = strdup(unesc);
-                       curl_free(unesc);
-                       curl_easy_cleanup(curl);
-                       return tmps;
-               }
+               unesc = curl_easy_unescape(curl,url,0,NULL);
+               tmps = strdup(unesc);
+               curl_free(unesc);
+               curl_easy_cleanup(curl);
+               return tmps;
        }
 
        return strdup((char *)url);
@@ -83,9 +85,10 @@
 
 char *path_to_url(const char *path)
 {
-       char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
+       /* Assumption: Amiga path does not start with '/' */
+       char *r = malloc(strlen(path) + SLEN("file:///") + 1);
 
-       strcpy(r, FILE_SCHEME_PREFIX);
+       strcpy(r, "file:///");
        strcat(r, path);
 
        return r;


Conflicted files




Removed files



Reply via email to