mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-03-15 19:42:53 +03:00
rationalise the usage of the file scheme
svn path=/trunk/netsurf/; revision=10221
This commit is contained in:
parent
9f575c590b
commit
95e4a737de
@ -76,9 +76,9 @@ char *url_to_path(const char *url)
|
||||
|
||||
char *path_to_url(const char *path)
|
||||
{
|
||||
char *r = malloc(strlen(path) + 8 + 1);
|
||||
char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
|
||||
|
||||
strcpy(r, "file:///");
|
||||
strcpy(r, FILE_SCHEME_PREFIX);
|
||||
strcat(r, path);
|
||||
|
||||
return r;
|
||||
|
@ -1151,9 +1151,9 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len,
|
||||
|
||||
char *path_to_url(const char *path)
|
||||
{
|
||||
char *r = (char *)malloc(strlen(path) + 7 + 1);
|
||||
char *r = (char *)malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
|
||||
|
||||
strcpy(r, "file://");
|
||||
strcpy(r, FILE_SCHEME_PREFIX);
|
||||
strcat(r, path);
|
||||
|
||||
return r;
|
||||
@ -1161,7 +1161,7 @@ char *path_to_url(const char *path)
|
||||
|
||||
char *url_to_path(const char *url)
|
||||
{
|
||||
return strdup(url + 5);
|
||||
return strdup(url + FILE_SCHEME_PREFIX_LEN);
|
||||
}
|
||||
|
||||
bool cookies_update(const char *domain, const struct cookie_data *data)
|
||||
|
@ -1098,7 +1098,6 @@ size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
|
||||
#undef SKIP_ST
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the status code and content type and inform the caller.
|
||||
*
|
||||
@ -1154,10 +1153,12 @@ bool fetch_curl_process_headers(struct curl_fetch_info *f)
|
||||
}
|
||||
|
||||
/* find MIME type from filetype for local files */
|
||||
if (strncmp(f->url, "file:///", 8) == 0) {
|
||||
if (strncmp(f->url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN) == 0) {
|
||||
struct stat s;
|
||||
char *url_path = curl_unescape(f->url + 7,
|
||||
(int) strlen(f->url + 7));
|
||||
char *url_path = curl_unescape(f->url + FILE_SCHEME_PREFIX_LEN,
|
||||
(int) strlen(f->url + FILE_SCHEME_PREFIX_LEN));
|
||||
|
||||
LOG(("Obtaining mime type for file %s", url_path));
|
||||
|
||||
if (url_path != NULL && stat(url_path, &s) == 0) {
|
||||
/* file: URL and file exists */
|
||||
|
@ -24,14 +24,15 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "utils/log.h"
|
||||
#include "utils/url.h"
|
||||
|
||||
#include "framebuffer/findfile.h"
|
||||
|
||||
char *path_to_url(const char *path)
|
||||
{
|
||||
char *r = malloc(strlen(path) + 7 + 1);
|
||||
char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
|
||||
|
||||
strcpy(r, "file://");
|
||||
strcpy(r, FILE_SCHEME_PREFIX);
|
||||
strcat(r, path);
|
||||
|
||||
return r;
|
||||
|
@ -19,8 +19,6 @@
|
||||
#ifndef NETSURF_FB_FINDFILE_H
|
||||
#define NETSURF_FB_FINDFILE_H
|
||||
|
||||
char *path_to_url(const char *path);
|
||||
|
||||
extern char *fb_find_resource(char *buf, const char *filename, const char *def);
|
||||
|
||||
#endif /* NETSURF_FB_FINDFILE_H */
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/options.h"
|
||||
#include "utils/log.h"
|
||||
#include "utils/url.h"
|
||||
#include "utils/messages.h"
|
||||
#include "utils/utils.h"
|
||||
#include "desktop/textinput.h"
|
||||
|
137
gtk/gtk_gui.c
137
gtk/gtk_gui.c
@ -97,8 +97,6 @@ static struct browser_window *select_menu_bw;
|
||||
static struct form_control *select_menu_control;
|
||||
|
||||
static void nsgtk_init_glade(void);
|
||||
static char *nsgtk_find_resource(char *buf, const char *filename,
|
||||
const char *def);
|
||||
static void nsgtk_check_homedir(void);
|
||||
static void *nsgtk_hubbub_realloc(void *ptr, size_t len, void *pw);
|
||||
static bool nsgtk_throbber_init(int framec);
|
||||
@ -114,6 +112,71 @@ static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data);
|
||||
#define THROBBER_FRAMES 9
|
||||
|
||||
|
||||
/**
|
||||
* Locate a shared resource file by searching known places in order.
|
||||
*
|
||||
* \param buf buffer to write to. must be at least PATH_MAX chars. May be NULL and routine will allocate string which must be freed by caller.
|
||||
* \param filename file to look for
|
||||
* \param def default to return if file not found
|
||||
* \return buf
|
||||
*
|
||||
* Search order is: ~/.netsurf/, $NETSURFRES/ (where NETSURFRES is an
|
||||
* environment variable), and finally the path specified by the define
|
||||
* GTK_RESPATH.
|
||||
*/
|
||||
static char *
|
||||
nsgtk_find_resource(char *buf, const char *filename, const char *def)
|
||||
{
|
||||
char *cdir = getenv("HOME");
|
||||
char t[PATH_MAX];
|
||||
|
||||
if (buf == NULL) {
|
||||
buf = malloc(PATH_MAX);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cdir != NULL) {
|
||||
strcpy(t, cdir);
|
||||
strcat(t, "/.netsurf/");
|
||||
strcat(t, filename);
|
||||
if (realpath(t, buf) != NULL) {
|
||||
if (access(buf, R_OK) == 0)
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
cdir = getenv("NETSURFRES");
|
||||
|
||||
if (cdir != NULL) {
|
||||
if (realpath(cdir, buf) != NULL) {
|
||||
strcat(buf, "/");
|
||||
strcat(buf, filename);
|
||||
if (access(buf, R_OK) == 0)
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(t, GTK_RESPATH);
|
||||
strcat(t, filename);
|
||||
if (realpath(t, buf) != NULL) {
|
||||
if (access(buf, R_OK) == 0)
|
||||
return buf;
|
||||
}
|
||||
|
||||
if (def[0] == '~') {
|
||||
snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1);
|
||||
if (realpath(t, buf) == NULL) {
|
||||
strcpy(buf, t);
|
||||
}
|
||||
} else {
|
||||
if (realpath(def, buf) == NULL) {
|
||||
strcpy(buf, def);
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -421,70 +484,6 @@ void gui_quit(void)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Locate a shared resource file by searching known places in order.
|
||||
*
|
||||
* \param buf buffer to write to. must be at least PATH_MAX chars. May be NULL and routine will allocate string which must be freed by caller.
|
||||
* \param filename file to look for
|
||||
* \param def default to return if file not found
|
||||
* \return buf
|
||||
*
|
||||
* Search order is: ~/.netsurf/, $NETSURFRES/ (where NETSURFRES is an
|
||||
* environment variable), and finally the path specified by the define
|
||||
* GTK_RESPATH.
|
||||
*/
|
||||
char *nsgtk_find_resource(char *buf, const char *filename, const char *def)
|
||||
{
|
||||
char *cdir = getenv("HOME");
|
||||
char t[PATH_MAX];
|
||||
|
||||
if (buf == NULL) {
|
||||
buf = malloc(PATH_MAX);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cdir != NULL) {
|
||||
strcpy(t, cdir);
|
||||
strcat(t, "/.netsurf/");
|
||||
strcat(t, filename);
|
||||
if (realpath(t, buf) != NULL) {
|
||||
if (access(buf, R_OK) == 0)
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
cdir = getenv("NETSURFRES");
|
||||
|
||||
if (cdir != NULL) {
|
||||
if (realpath(cdir, buf) != NULL) {
|
||||
strcat(buf, "/");
|
||||
strcat(buf, filename);
|
||||
if (access(buf, R_OK) == 0)
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(t, GTK_RESPATH);
|
||||
strcat(t, filename);
|
||||
if (realpath(t, buf) != NULL) {
|
||||
if (access(buf, R_OK) == 0)
|
||||
return buf;
|
||||
}
|
||||
|
||||
if (def[0] == '~') {
|
||||
snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1);
|
||||
if (realpath(t, buf) == NULL) {
|
||||
strcpy(buf, t);
|
||||
}
|
||||
} else {
|
||||
if (realpath(def, buf) == NULL) {
|
||||
strcpy(buf, def);
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -729,9 +728,9 @@ 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) + SLEN("file://") + 1);
|
||||
char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
|
||||
|
||||
strcpy(r, "file://");
|
||||
strcpy(r, FILE_SCHEME_PREFIX);
|
||||
strcat(r, path);
|
||||
|
||||
return r;
|
||||
@ -740,7 +739,7 @@ char *path_to_url(const char *path)
|
||||
|
||||
char *url_to_path(const char *url)
|
||||
{
|
||||
return strdup(url + 5);
|
||||
return strdup(url + FILE_SCHEME_PREFIX_LEN);
|
||||
}
|
||||
|
||||
|
||||
|
@ -390,9 +390,9 @@ void nsgtk_openfile_open(const char *filename)
|
||||
{
|
||||
struct browser_window *bw = gui_window_get_browser_window(
|
||||
current_model->top_level);
|
||||
char url[strlen(filename) + SLEN("file://") + 1];
|
||||
char url[strlen(filename) + FILE_SCHEME_PREFIX_LEN + 1];
|
||||
|
||||
sprintf(url, "file://%s", filename);
|
||||
sprintf(url, FILE_SCHEME_PREFIX"%s", filename);
|
||||
|
||||
browser_window_go(bw, url, 0, true);
|
||||
|
||||
|
10
riscos/gui.c
10
riscos/gui.c
@ -2074,10 +2074,10 @@ char *path_to_url(const char *path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(url, "file://", SLEN("file://"));
|
||||
memcpy(url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN);
|
||||
if (__unixify(buffer, __RISCOSIFY_NO_REVERSE_SUFFIX,
|
||||
url + SLEN("file://"),
|
||||
1 - spare + 10 - SLEN("file://"),
|
||||
url + FILE_SCHEME_PREFIX_LEN,
|
||||
1 - spare + 10 - FILE_SCHEME_PREFIX_LEN,
|
||||
0) == NULL) {
|
||||
LOG(("__unixify failed: %s", buffer));
|
||||
free(buffer);
|
||||
@ -2087,7 +2087,7 @@ char *path_to_url(const char *path)
|
||||
free(buffer); buffer = NULL;
|
||||
|
||||
/* We don't want '/' to be escaped. */
|
||||
url_err = url_escape(url, SLEN("file://"), false, "/", &escurl);
|
||||
url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl);
|
||||
free(url); url = NULL;
|
||||
if (url_err != URL_FUNC_OK) {
|
||||
LOG(("url_escape failed: %s", url));
|
||||
@ -2110,7 +2110,7 @@ char *url_to_path(const char *url)
|
||||
char *temp_name, *r;
|
||||
char *filename;
|
||||
|
||||
if (strncmp(url, "file:///", 8))
|
||||
if (strncmp(url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN))
|
||||
return NULL;
|
||||
|
||||
temp_name = curl_unescape(url + 7, strlen(url) - 7);
|
||||
|
@ -24,6 +24,10 @@
|
||||
#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 */
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils/url.h"
|
||||
#include "utils/log.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
@ -37,12 +38,19 @@ static char *realpath(const char *path, char *resolved_path)
|
||||
|
||||
char *path_to_url(const char *path)
|
||||
{
|
||||
char *r = malloc(strlen(path) + 7 + 1);
|
||||
char *url = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
|
||||
char *sidx;
|
||||
|
||||
strcpy(r, "file://");
|
||||
strcat(r, path);
|
||||
strcpy(url, FILE_SCHEME_PREFIX);
|
||||
strcat(url, path);
|
||||
|
||||
return r;
|
||||
sidx = strrchr(url, '\\');
|
||||
while (sidx != NULL) {
|
||||
*sidx = '/';
|
||||
sidx = strrchr(url, '\\');
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
#define NETSURF_WINDOWS_RESPATH "C:"
|
||||
|
||||
char *path_to_url(const char *path);
|
||||
|
||||
extern char *nsws_find_resource(char *buf, const char *filename,
|
||||
const char *def);
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "desktop/selection.h"
|
||||
#include "desktop/textinput.h"
|
||||
#include "render/html.h"
|
||||
#include "utils/url.h"
|
||||
#include "utils/log.h"
|
||||
#include "utils/messages.h"
|
||||
#include "utils/utils.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user