From d4c519cc05536486c202a399826633b1b025c22a Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 11 Jul 2010 20:42:06 +0000 Subject: Amiga file: URIs now translate the : in device names to / (and back), which conforms better to the spec (: will still work for compatibility, but may have problems). This fixes a problem with directory browsing. Directory parent link now uses the full parent path returned by url_parent instead of one relative to the current directory. svn path=/trunk/netsurf/; revision=10629 --- amiga/misc.c | 44 ++++++++++++++++++++++++++++++++++++++------ render/directory.c | 4 +++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/amiga/misc.c b/amiga/misc.c index e07f9ecbd..04e38469a 100755 --- a/amiga/misc.c +++ b/amiga/misc.c @@ -59,7 +59,7 @@ void die(const char *error) char *url_to_path(const char *url) { - char *tmps, *unesc; + char *tmps, *unesc, *slash, *colon, *url2; CURL *curl; if (strncmp(url, "file://", SLEN("file://")) != 0) @@ -72,25 +72,57 @@ char *url_to_path(const char *url) url += SLEN("/"); + url2 = malloc(strlen(url) + 2); + strcpy(url2, url); + + colon = strchr(url2, ':'); + if(colon == NULL) + { + if(slash = strchr(url2, '/')) + { + *slash = ':'; + } + else + { + int len = strlen(url2); + url2[len] = ':'; + url2[len + 1] = '\0'; + } + } + if(curl = curl_easy_init()) { - unesc = curl_easy_unescape(curl,url,0,NULL); + unesc = curl_easy_unescape(curl,url2,0,NULL); tmps = strdup(unesc); + free(url2); curl_free(unesc); curl_easy_cleanup(curl); return tmps; } - return strdup((char *)url); + return (char *)url2; } char *path_to_url(const char *path) { - char *r = malloc(strlen(path) + SLEN("file:///") + 1); + char *colon = NULL; + char *r = NULL; + char newpath[1024 + strlen(path)]; + BPTR lock = 0; - strcpy(r, "file:///"); - strcat(r, path); + if(lock = Lock(path, MODE_OLDFILE)) + { + DevNameFromLock(lock, newpath, sizeof newpath, DN_FULLPATH); + UnLock(lock); + } + r = malloc(strlen(newpath) + SLEN("file:///") + 1); + + if(colon = strchr(newpath, ':')) *colon = '/'; + + strcpy(r, "file:///"); + strcat(r, newpath); +printf("ptu %s => %s\n",path, r); return r; } diff --git a/render/directory.c b/render/directory.c index 193941ecf..4cb9c8af4 100644 --- a/render/directory.c +++ b/render/directory.c @@ -100,11 +100,13 @@ bool directory_convert(struct content *c) { (uint8_t *) buffer, strlen(buffer)); res = url_parent(content__get_url(c), &up); + if (res == URL_FUNC_OK) { res = url_compare(content__get_url(c), up, false, &compare); if ((res == URL_FUNC_OK) && !compare) { + if(up[strlen(up) - 1] == '/') up[strlen(up) - 1] = '\0'; snprintf(buffer, sizeof(buffer), - "[..]\n"); + "[..]\n", up); binding_parse_chunk(c->data.html.parser_binding, (uint8_t *) buffer, strlen(buffer)); -- cgit v1.2.3