netsurf: branch master updated. release/3.0-1004-g27fdcb9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/27fdcb90f2b9ecaeea39f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/27fdcb90f2b9ecaeea39f1c...
...tree http://git.netsurf-browser.org/netsurf.git/tree/27fdcb90f2b9ecaeea39f1c67...
The branch, master has been updated
via 27fdcb90f2b9ecaeea39f1c673d7978deaeb1d53 (commit)
via cdc4041942be67ee8b70206e7a1bf6f72514e532 (commit)
via def97156d3c0cbeacf2996859f16f727d44eb4e8 (commit)
via 89992958d251cbb1cbd634a0dd89d1161de35041 (commit)
via 0ab5fe7c02ccbbd9a898c483219a9317b19834d0 (commit)
from dc074042e9f4bcd7d3ccf09fcd81f9b11a0517d0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
resources/FatMessages | 5 +++
riscos/dialog.c | 76 +++++++++++++++++++++++++++++++++++++++++++------
riscos/gui.h | 4 ++
riscos/gui/url_bar.c | 68 ++++++++++++++++++++++++++++++++++++--------
riscos/templates/de | 2 +-
riscos/templates/en | 2 +-
riscos/templates/fr | 2 +-
riscos/templates/nl | 2 +-
8 files changed, 136 insertions(+), 25 deletions(-)
diff --git a/resources/FatMessages b/resources/FatMessages
index 50b39dd..ff5a761 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -2916,6 +2916,11 @@ de.all.NoMemory:Zu wenig Speicher. Bitte mehr Speicher zur Verfügung stellen un
fr.all.NoMemory:NetSurf a besoin de plus de mémoire. Veuillez libérer de la mémoire et réessayer.
it.all.NoMemory:Memoria insufficiente per l'esecuzione di NetSurf. Per favore liberane un pò e riprova nuovamente.
nl.all.NoMemory:NetSurf krijgt gebrek aan geheugen. Maak wat geheugen vrij en probeer het dan nog eens.
+en.ro.LongURL:The URL for this page is too long for NetSurf to display.
+de.ro.LongURL:The URL for this page is too long for NetSurf to display.
+fr.ro.LongURL:The URL for this page is too long for NetSurf to display.
+it.ro.LongURL:The URL for this page is too long for NetSurf to display.
+nl.ro.LongURL:The URL for this page is too long for NetSurf to display.
en.ro.FontBadInst:An error occurred when initialising fonts due to the presence of obsolete copies of the ROM fonts on disc. NetSurf will exit and launch a program which will attempt to fix this.
de.ro.FontBadInst:Font-Initialisierung fehlerhaft. Obsolete Kopien von ROM Fonts auf dem lokalem Speichermedium. Fehlerbehebung startet.
fr.ro.FontBadInst:Une erreur s'est produite lors de l'initialisation des fontes à cause de la présence de copies obsolètes de fontes ROM sur disque. NetSurf va sortir et lancer un programme qui va tenter de réparer cela.
diff --git a/riscos/dialog.c b/riscos/dialog.c
index 147dce9..4347023 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -5,6 +5,7 @@
* Copyright 2005 Richard Wilson <info(a)tinct.net>
* Copyright 2004 Andrew Timmins <atimmins(a)blueyonder.co.uk>
* Copyright 2005 Adrian Lees <adrianl(a)users.sourceforge.net>
+ * Copyright 2014 Stephen Fryatt <stevef(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -85,6 +86,7 @@ static struct {
} persistent_dialog[MAX_PERSISTENT];
+static bool ro_gui_dialog_open_url_init(void);
static bool ro_gui_dialog_openurl_apply(wimp_w w);
static bool ro_gui_dialog_open_url_menu_prepare(wimp_w w, wimp_i i,
wimp_menu *menu, wimp_pointer *pointer);
@@ -161,15 +163,7 @@ void ro_gui_dialog_init(void)
ro_gui_wimp_event_set_help_prefix(dialog_url_complete, "HelpAutoURL");
/* open URL */
- dialog_openurl = ro_gui_dialog_create("open_url");
- ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
- ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
- ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
- ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
- ro_gui_dialog_openurl_apply);
- ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
- ro_gui_dialog_open_url_menu_prepare);
- ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
+ ro_gui_dialog_open_url_init();
/* scale view */
dialog_zoom = ro_gui_dialog_create("zoom");
@@ -702,6 +696,70 @@ void ro_gui_dialog_update_zoom(struct gui_window *g) {
}
+/**
+ * Create the Open URL dialogue, allocating storage for the URL field icon
+ * as we go.
+ *
+ * \return true on success; false on failure (although errors with
+ * the templates or memory allocation will exit via die()).
+ */
+
+static bool ro_gui_dialog_open_url_init(void)
+{
+ wimp_window *definition;
+ char *buffer;
+ os_error *error;
+
+ definition = ro_gui_dialog_load_template("open_url");
+
+ /* _load_template() should die on any error, so we trust its data. */
+
+ assert(definition != NULL);
+
+ /* Create the dialogue, with modifications. */
+
+ if ((definition->icons[ICON_OPENURL_URL].flags & wimp_ICON_INDIRECTED)
+ == 0) {
+ LOG(("open_url URL icon not indirected"));
+ xwimp_close_template();
+ die("Template");
+ }
+
+ buffer = malloc(RO_GUI_MAX_URL_SIZE);
+ if (buffer == NULL) {
+ xwimp_close_template();
+ die("NoMemory");
+ }
+
+ definition->icons[ICON_OPENURL_URL].data.indirected_text.text = buffer;
+ definition->icons[ICON_OPENURL_URL].data.indirected_text.size =
+ RO_GUI_MAX_URL_SIZE;
+ definition->sprite_area = gui_sprites;
+
+ error = xwimp_create_window(definition, &dialog_openurl);
+ if (error != NULL) {
+ LOG(("xwimp_create_window: 0x%x: %s",
+ error->errnum, error->errmess));
+ xwimp_close_template();
+ die(error->errmess);
+ }
+
+ free(definition);
+
+ ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
+ ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
+ ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
+ ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
+ ro_gui_dialog_openurl_apply);
+ ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
+ ro_gui_dialog_open_url_menu_prepare);
+ ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
+
+ return true;
+}
+
+
+
bool ro_gui_dialog_openurl_apply(wimp_w w) {
const char *urltxt;
char *url2;
diff --git a/riscos/gui.h b/riscos/gui.h
index 32710b4..051834a 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -35,6 +35,10 @@
#define THUMBNAIL_WIDTH 100
#define THUMBNAIL_HEIGHT 86
+/* The maximum size for user-editable URLs in the RISC OS GUI. */
+
+#define RO_GUI_MAX_URL_SIZE 2048
+
extern int os_version;
extern const char * NETSURF_DIR;
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 4993093..d764740 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -1,6 +1,6 @@
/*
* Copyright 2004, 2005 Richard Wilson <info(a)tinct.net>
- * Copyright 2011-2013 Stephen Fryatt <stevef(a)netsurf-browser.org>
+ * Copyright 2011-2014 Stephen Fryatt <stevef(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -30,6 +30,7 @@
#include "oslib/os.h"
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
+#include "riscos/gui.h"
#include "riscos/hotlist.h"
#include "riscos/gui/url_bar.h"
#include "riscos/theme.h"
@@ -39,6 +40,7 @@
#include "riscos/window.h"
#include "utils/log.h"
#include "utils/messages.h"
+#include "utils/utf8.h"
#include "utils/utils.h"
#define URLBAR_HEIGHT 52
@@ -49,8 +51,6 @@
#define URLBAR_MIN_WIDTH 52
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
-#define URLBAR_INITIAL_LENGTH 256
-#define URLBAR_EXTEND_LENGTH 128
struct url_bar {
/** The applied theme (or NULL to use the default) */
@@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
url_bar->hotlist.extent.x1 = 0;
url_bar->hotlist.extent.y1 = 0;
- url_bar->text_size = URLBAR_INITIAL_LENGTH;
+ url_bar->text_size = RO_GUI_MAX_URL_SIZE;
url_bar->text_buffer = malloc(url_bar->text_size);
strncpy(url_bar->text_buffer, "", url_bar->text_size);
@@ -942,24 +942,68 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
{
wimp_caret caret;
os_error *error;
- const char *set_url;
+ char *local_text = NULL;
+ const char *set_url, *local_url;
nsurl *n;
- if (url_bar == NULL || url_bar->text_buffer == NULL)
+ if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL)
return;
- if (nsurl_create(url, &n) == NSERROR_OK) {
+ /* Before we do anything with the URL, get it into local encoding so
+ * that behaviour is consistant with the rest of the URL Bar module
+ * (which will act on the icon's text buffer, which is always in local
+ * encoding).
+ */
+
+ if (is_utf8) {
+ utf8_convert_ret err;
+
+ err = utf8_to_local_encoding(url, 0, &local_text);
+ if (err != UTF8_CONVERT_OK) {
+ /* A bad encoding should never happen, so assert this */
+ assert(err != UTF8_CONVERT_BADENC);
+ LOG(("utf8_to_enc failed"));
+ /* Paranoia */
+ local_text = NULL;
+ }
+ local_url = (local_text != NULL) ? local_text : url;
+ } else {
+ local_url = url;
+ }
+
+ /* Copy the text into the icon buffer. If the text is too long, blank
+ * the buffer and warn the user.
+ */
+
+ if (strlen(local_url) >= url_bar->text_size) {
+ strncpy(url_bar->text_buffer, "", url_bar->text_size - 1);
+ url_bar->text_buffer[url_bar->text_size - 1] = '\0';
+ warn_user("LongURL", NULL);
+ LOG(("Long URL (%d chars): %s", strlen(url), url));
+ } else {
+ strncpy(url_bar->text_buffer, local_url,
+ url_bar->text_size - 1);
+ url_bar->text_buffer[url_bar->text_size - 1] = '\0';
+ }
+
+ if (local_text != NULL)
+ free(local_text);
+
+ /* Set the hotlist flag. */
+
+ if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) {
ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
nsurl_unref(n);
}
- if (url_bar->text_icon == -1) {
- strncpy(url_bar->text_buffer, url, url_bar->text_size);
+ /* If there's no icon, then there's nothing else to do... */
+
+ if (url_bar->text_icon == -1)
return;
- }
- ro_gui_set_icon_string(url_bar->window, url_bar->text_icon,
- url, is_utf8);
+ /* ...if there is, redraw the icon and fix the caret's position. */
+
+ ro_gui_redraw_icon(url_bar->window, url_bar->text_icon);
error = xwimp_get_caret_position(&caret);
if (error) {
diff --git a/riscos/templates/de b/riscos/templates/de
index 905d57e..190d38a 100644
--- a/riscos/templates/de
+++ b/riscos/templates/de
@@ -1683,7 +1683,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/en b/riscos/templates/en
index a943b1e..fed72b3 100644
--- a/riscos/templates/en
+++ b/riscos/templates/en
@@ -1891,7 +1891,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/fr b/riscos/templates/fr
index 30bcbfa..2acc578 100644
--- a/riscos/templates/fr
+++ b/riscos/templates/fr
@@ -1695,7 +1695,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/nl b/riscos/templates/nl
index dcc8af5..8e7725f 100644
--- a/riscos/templates/nl
+++ b/riscos/templates/nl
@@ -1895,7 +1895,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
--
NetSurf Browser
9 years
netsurf: branch stevef/urlsize updated. release/3.0-1004-g27fdcb9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/27fdcb90f2b9ecaeea39f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/27fdcb90f2b9ecaeea39f1c...
...tree http://git.netsurf-browser.org/netsurf.git/tree/27fdcb90f2b9ecaeea39f1c67...
The branch, stevef/urlsize has been updated
via 27fdcb90f2b9ecaeea39f1c673d7978deaeb1d53 (commit)
from cdc4041942be67ee8b70206e7a1bf6f72514e532 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=27fdcb90f2b9ecaeea3...
commit 27fdcb90f2b9ecaeea39f1c673d7978deaeb1d53
Author: Steve Fryatt <stevef(a)netsurf-browser.org>
Commit: Steve Fryatt <stevef(a)netsurf-browser.org>
Update copyright dates in modified files.
diff --git a/riscos/dialog.c b/riscos/dialog.c
index 5fe1d27..4347023 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -5,6 +5,7 @@
* Copyright 2005 Richard Wilson <info(a)tinct.net>
* Copyright 2004 Andrew Timmins <atimmins(a)blueyonder.co.uk>
* Copyright 2005 Adrian Lees <adrianl(a)users.sourceforge.net>
+ * Copyright 2014 Stephen Fryatt <stevef(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index f77c6e7..d764740 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -1,6 +1,6 @@
/*
* Copyright 2004, 2005 Richard Wilson <info(a)tinct.net>
- * Copyright 2011-2013 Stephen Fryatt <stevef(a)netsurf-browser.org>
+ * Copyright 2011-2014 Stephen Fryatt <stevef(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
-----------------------------------------------------------------------
Summary of changes:
riscos/dialog.c | 1 +
riscos/gui/url_bar.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/riscos/dialog.c b/riscos/dialog.c
index 5fe1d27..4347023 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -5,6 +5,7 @@
* Copyright 2005 Richard Wilson <info(a)tinct.net>
* Copyright 2004 Andrew Timmins <atimmins(a)blueyonder.co.uk>
* Copyright 2005 Adrian Lees <adrianl(a)users.sourceforge.net>
+ * Copyright 2014 Stephen Fryatt <stevef(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index f77c6e7..d764740 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -1,6 +1,6 @@
/*
* Copyright 2004, 2005 Richard Wilson <info(a)tinct.net>
- * Copyright 2011-2013 Stephen Fryatt <stevef(a)netsurf-browser.org>
+ * Copyright 2011-2014 Stephen Fryatt <stevef(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
--
NetSurf Browser
9 years
netsurf: branch stevef/urlsize updated. release/3.0-1003-gcdc4041
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/cdc4041942be67ee8b702...
...commit http://git.netsurf-browser.org/netsurf.git/commit/cdc4041942be67ee8b70206...
...tree http://git.netsurf-browser.org/netsurf.git/tree/cdc4041942be67ee8b70206e7...
The branch, stevef/urlsize has been updated
via cdc4041942be67ee8b70206e7a1bf6f72514e532 (commit)
from def97156d3c0cbeacf2996859f16f727d44eb4e8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=cdc4041942be67ee8b7...
commit cdc4041942be67ee8b70206e7a1bf6f72514e532
Author: Steve Fryatt <stevef(a)netsurf-browser.org>
Commit: Steve Fryatt <stevef(a)netsurf-browser.org>
Add belt and braces to ensure that URL Bar content is always cleanly terminated.
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 829419d..f77c6e7 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -976,11 +976,14 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
*/
if (strlen(local_url) >= url_bar->text_size) {
- strncpy(url_bar->text_buffer, "", url_bar->text_size);
+ strncpy(url_bar->text_buffer, "", url_bar->text_size - 1);
+ url_bar->text_buffer[url_bar->text_size - 1] = '\0';
warn_user("LongURL", NULL);
LOG(("Long URL (%d chars): %s", strlen(url), url));
} else {
- strncpy(url_bar->text_buffer, local_url, url_bar->text_size);
+ strncpy(url_bar->text_buffer, local_url,
+ url_bar->text_size - 1);
+ url_bar->text_buffer[url_bar->text_size - 1] = '\0';
}
if (local_text != NULL)
-----------------------------------------------------------------------
Summary of changes:
riscos/gui/url_bar.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 829419d..f77c6e7 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -976,11 +976,14 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
*/
if (strlen(local_url) >= url_bar->text_size) {
- strncpy(url_bar->text_buffer, "", url_bar->text_size);
+ strncpy(url_bar->text_buffer, "", url_bar->text_size - 1);
+ url_bar->text_buffer[url_bar->text_size - 1] = '\0';
warn_user("LongURL", NULL);
LOG(("Long URL (%d chars): %s", strlen(url), url));
} else {
- strncpy(url_bar->text_buffer, local_url, url_bar->text_size);
+ strncpy(url_bar->text_buffer, local_url,
+ url_bar->text_size - 1);
+ url_bar->text_buffer[url_bar->text_size - 1] = '\0';
}
if (local_text != NULL)
--
NetSurf Browser
9 years
netsurf: branch stevef/urlsize updated. release/3.0-1002-gdef9715
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/def97156d3c0cbeacf299...
...commit http://git.netsurf-browser.org/netsurf.git/commit/def97156d3c0cbeacf29968...
...tree http://git.netsurf-browser.org/netsurf.git/tree/def97156d3c0cbeacf2996859...
The branch, stevef/urlsize has been updated
via def97156d3c0cbeacf2996859f16f727d44eb4e8 (commit)
from 89992958d251cbb1cbd634a0dd89d1161de35041 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=def97156d3c0cbeacf2...
commit def97156d3c0cbeacf2996859f16f727d44eb4e8
Author: Steve Fryatt <stevef(a)netsurf-browser.org>
Commit: Steve Fryatt <stevef(a)netsurf-browser.org>
Make Open URL dialogue allocate memory for the URL field.
Add global constant for URL length, to manage both URL Bar and Open URL.
diff --git a/riscos/dialog.c b/riscos/dialog.c
index 147dce9..5fe1d27 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -85,6 +85,7 @@ static struct {
} persistent_dialog[MAX_PERSISTENT];
+static bool ro_gui_dialog_open_url_init(void);
static bool ro_gui_dialog_openurl_apply(wimp_w w);
static bool ro_gui_dialog_open_url_menu_prepare(wimp_w w, wimp_i i,
wimp_menu *menu, wimp_pointer *pointer);
@@ -161,15 +162,7 @@ void ro_gui_dialog_init(void)
ro_gui_wimp_event_set_help_prefix(dialog_url_complete, "HelpAutoURL");
/* open URL */
- dialog_openurl = ro_gui_dialog_create("open_url");
- ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
- ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
- ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
- ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
- ro_gui_dialog_openurl_apply);
- ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
- ro_gui_dialog_open_url_menu_prepare);
- ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
+ ro_gui_dialog_open_url_init();
/* scale view */
dialog_zoom = ro_gui_dialog_create("zoom");
@@ -702,6 +695,70 @@ void ro_gui_dialog_update_zoom(struct gui_window *g) {
}
+/**
+ * Create the Open URL dialogue, allocating storage for the URL field icon
+ * as we go.
+ *
+ * \return true on success; false on failure (although errors with
+ * the templates or memory allocation will exit via die()).
+ */
+
+static bool ro_gui_dialog_open_url_init(void)
+{
+ wimp_window *definition;
+ char *buffer;
+ os_error *error;
+
+ definition = ro_gui_dialog_load_template("open_url");
+
+ /* _load_template() should die on any error, so we trust its data. */
+
+ assert(definition != NULL);
+
+ /* Create the dialogue, with modifications. */
+
+ if ((definition->icons[ICON_OPENURL_URL].flags & wimp_ICON_INDIRECTED)
+ == 0) {
+ LOG(("open_url URL icon not indirected"));
+ xwimp_close_template();
+ die("Template");
+ }
+
+ buffer = malloc(RO_GUI_MAX_URL_SIZE);
+ if (buffer == NULL) {
+ xwimp_close_template();
+ die("NoMemory");
+ }
+
+ definition->icons[ICON_OPENURL_URL].data.indirected_text.text = buffer;
+ definition->icons[ICON_OPENURL_URL].data.indirected_text.size =
+ RO_GUI_MAX_URL_SIZE;
+ definition->sprite_area = gui_sprites;
+
+ error = xwimp_create_window(definition, &dialog_openurl);
+ if (error != NULL) {
+ LOG(("xwimp_create_window: 0x%x: %s",
+ error->errnum, error->errmess));
+ xwimp_close_template();
+ die(error->errmess);
+ }
+
+ free(definition);
+
+ ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
+ ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
+ ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
+ ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
+ ro_gui_dialog_openurl_apply);
+ ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
+ ro_gui_dialog_open_url_menu_prepare);
+ ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
+
+ return true;
+}
+
+
+
bool ro_gui_dialog_openurl_apply(wimp_w w) {
const char *urltxt;
char *url2;
diff --git a/riscos/gui.h b/riscos/gui.h
index 32710b4..051834a 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -35,6 +35,10 @@
#define THUMBNAIL_WIDTH 100
#define THUMBNAIL_HEIGHT 86
+/* The maximum size for user-editable URLs in the RISC OS GUI. */
+
+#define RO_GUI_MAX_URL_SIZE 2048
+
extern int os_version;
extern const char * NETSURF_DIR;
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index b66b2af..829419d 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -30,6 +30,7 @@
#include "oslib/os.h"
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
+#include "riscos/gui.h"
#include "riscos/hotlist.h"
#include "riscos/gui/url_bar.h"
#include "riscos/theme.h"
@@ -50,7 +51,6 @@
#define URLBAR_MIN_WIDTH 52
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
-#define URLBAR_URL_LENGTH 2048
struct url_bar {
/** The applied theme (or NULL to use the default) */
@@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
url_bar->hotlist.extent.x1 = 0;
url_bar->hotlist.extent.y1 = 0;
- url_bar->text_size = URLBAR_URL_LENGTH;
+ url_bar->text_size = RO_GUI_MAX_URL_SIZE;
url_bar->text_buffer = malloc(url_bar->text_size);
strncpy(url_bar->text_buffer, "", url_bar->text_size);
diff --git a/riscos/templates/de b/riscos/templates/de
index 905d57e..190d38a 100644
--- a/riscos/templates/de
+++ b/riscos/templates/de
@@ -1683,7 +1683,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/en b/riscos/templates/en
index a943b1e..fed72b3 100644
--- a/riscos/templates/en
+++ b/riscos/templates/en
@@ -1891,7 +1891,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/fr b/riscos/templates/fr
index 30bcbfa..2acc578 100644
--- a/riscos/templates/fr
+++ b/riscos/templates/fr
@@ -1695,7 +1695,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/nl b/riscos/templates/nl
index dcc8af5..8e7725f 100644
--- a/riscos/templates/nl
+++ b/riscos/templates/nl
@@ -1895,7 +1895,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
-----------------------------------------------------------------------
Summary of changes:
riscos/dialog.c | 75 ++++++++++++++++++++++++++++++++++++++++++++------
riscos/gui.h | 4 ++
riscos/gui/url_bar.c | 4 +-
riscos/templates/de | 2 +-
riscos/templates/en | 2 +-
riscos/templates/fr | 2 +-
riscos/templates/nl | 2 +-
7 files changed, 76 insertions(+), 15 deletions(-)
diff --git a/riscos/dialog.c b/riscos/dialog.c
index 147dce9..5fe1d27 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -85,6 +85,7 @@ static struct {
} persistent_dialog[MAX_PERSISTENT];
+static bool ro_gui_dialog_open_url_init(void);
static bool ro_gui_dialog_openurl_apply(wimp_w w);
static bool ro_gui_dialog_open_url_menu_prepare(wimp_w w, wimp_i i,
wimp_menu *menu, wimp_pointer *pointer);
@@ -161,15 +162,7 @@ void ro_gui_dialog_init(void)
ro_gui_wimp_event_set_help_prefix(dialog_url_complete, "HelpAutoURL");
/* open URL */
- dialog_openurl = ro_gui_dialog_create("open_url");
- ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
- ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
- ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
- ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
- ro_gui_dialog_openurl_apply);
- ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
- ro_gui_dialog_open_url_menu_prepare);
- ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
+ ro_gui_dialog_open_url_init();
/* scale view */
dialog_zoom = ro_gui_dialog_create("zoom");
@@ -702,6 +695,70 @@ void ro_gui_dialog_update_zoom(struct gui_window *g) {
}
+/**
+ * Create the Open URL dialogue, allocating storage for the URL field icon
+ * as we go.
+ *
+ * \return true on success; false on failure (although errors with
+ * the templates or memory allocation will exit via die()).
+ */
+
+static bool ro_gui_dialog_open_url_init(void)
+{
+ wimp_window *definition;
+ char *buffer;
+ os_error *error;
+
+ definition = ro_gui_dialog_load_template("open_url");
+
+ /* _load_template() should die on any error, so we trust its data. */
+
+ assert(definition != NULL);
+
+ /* Create the dialogue, with modifications. */
+
+ if ((definition->icons[ICON_OPENURL_URL].flags & wimp_ICON_INDIRECTED)
+ == 0) {
+ LOG(("open_url URL icon not indirected"));
+ xwimp_close_template();
+ die("Template");
+ }
+
+ buffer = malloc(RO_GUI_MAX_URL_SIZE);
+ if (buffer == NULL) {
+ xwimp_close_template();
+ die("NoMemory");
+ }
+
+ definition->icons[ICON_OPENURL_URL].data.indirected_text.text = buffer;
+ definition->icons[ICON_OPENURL_URL].data.indirected_text.size =
+ RO_GUI_MAX_URL_SIZE;
+ definition->sprite_area = gui_sprites;
+
+ error = xwimp_create_window(definition, &dialog_openurl);
+ if (error != NULL) {
+ LOG(("xwimp_create_window: 0x%x: %s",
+ error->errnum, error->errmess));
+ xwimp_close_template();
+ die(error->errmess);
+ }
+
+ free(definition);
+
+ ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
+ ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
+ ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
+ ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
+ ro_gui_dialog_openurl_apply);
+ ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
+ ro_gui_dialog_open_url_menu_prepare);
+ ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
+
+ return true;
+}
+
+
+
bool ro_gui_dialog_openurl_apply(wimp_w w) {
const char *urltxt;
char *url2;
diff --git a/riscos/gui.h b/riscos/gui.h
index 32710b4..051834a 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -35,6 +35,10 @@
#define THUMBNAIL_WIDTH 100
#define THUMBNAIL_HEIGHT 86
+/* The maximum size for user-editable URLs in the RISC OS GUI. */
+
+#define RO_GUI_MAX_URL_SIZE 2048
+
extern int os_version;
extern const char * NETSURF_DIR;
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index b66b2af..829419d 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -30,6 +30,7 @@
#include "oslib/os.h"
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
+#include "riscos/gui.h"
#include "riscos/hotlist.h"
#include "riscos/gui/url_bar.h"
#include "riscos/theme.h"
@@ -50,7 +51,6 @@
#define URLBAR_MIN_WIDTH 52
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
-#define URLBAR_URL_LENGTH 2048
struct url_bar {
/** The applied theme (or NULL to use the default) */
@@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
url_bar->hotlist.extent.x1 = 0;
url_bar->hotlist.extent.y1 = 0;
- url_bar->text_size = URLBAR_URL_LENGTH;
+ url_bar->text_size = RO_GUI_MAX_URL_SIZE;
url_bar->text_buffer = malloc(url_bar->text_size);
strncpy(url_bar->text_buffer, "", url_bar->text_size);
diff --git a/riscos/templates/de b/riscos/templates/de
index 905d57e..190d38a 100644
--- a/riscos/templates/de
+++ b/riscos/templates/de
@@ -1683,7 +1683,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/en b/riscos/templates/en
index a943b1e..fed72b3 100644
--- a/riscos/templates/en
+++ b/riscos/templates/en
@@ -1891,7 +1891,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/fr b/riscos/templates/fr
index 30bcbfa..2acc578 100644
--- a/riscos/templates/fr
+++ b/riscos/templates/fr
@@ -1695,7 +1695,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
diff --git a/riscos/templates/nl b/riscos/templates/nl
index dcc8af5..8e7725f 100644
--- a/riscos/templates/nl
+++ b/riscos/templates/nl
@@ -1895,7 +1895,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
- text.size:128
+ text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {
--
NetSurf Browser
9 years
netsurf: branch stevef/urlsize updated. release/3.0-1001-g8999295
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/89992958d251cbb1cbd63...
...commit http://git.netsurf-browser.org/netsurf.git/commit/89992958d251cbb1cbd634a...
...tree http://git.netsurf-browser.org/netsurf.git/tree/89992958d251cbb1cbd634a0d...
The branch, stevef/urlsize has been updated
via 89992958d251cbb1cbd634a0dd89d1161de35041 (commit)
via 0ab5fe7c02ccbbd9a898c483219a9317b19834d0 (commit)
from dc074042e9f4bcd7d3ccf09fcd81f9b11a0517d0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=89992958d251cbb1cbd...
commit 89992958d251cbb1cbd634a0dd89d1161de35041
Author: Steve Fryatt <stevef(a)netsurf-browser.org>
Commit: Steve Fryatt <stevef(a)netsurf-browser.org>
Increase maximum size of a URL in the URL Bar to 2047 characters plus terminator.
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 0b6bd1c..b66b2af 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -50,7 +50,7 @@
#define URLBAR_MIN_WIDTH 52
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
-#define URLBAR_INITIAL_LENGTH 256
+#define URLBAR_URL_LENGTH 2048
struct url_bar {
/** The applied theme (or NULL to use the default) */
@@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
url_bar->hotlist.extent.x1 = 0;
url_bar->hotlist.extent.y1 = 0;
- url_bar->text_size = URLBAR_INITIAL_LENGTH;
+ url_bar->text_size = URLBAR_URL_LENGTH;
url_bar->text_buffer = malloc(url_bar->text_size);
strncpy(url_bar->text_buffer, "", url_bar->text_size);
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=0ab5fe7c02ccbbd9a89...
commit 0ab5fe7c02ccbbd9a898c483219a9317b19834d0
Author: Steve Fryatt <stevef(a)netsurf-browser.org>
Commit: Steve Fryatt <stevef(a)netsurf-browser.org>
Improve URL handling in URL Bar.
Rationalise handling of UTF8, so that URLs are always converted into local encoding even if there is no URL icon present.
In addition, make preliminary hotlist test in set_url() use local encoding, in line with all subsequent checks.
Make handling of over-length URLs more sensible: warn user and completely blank the URL bar.
diff --git a/resources/FatMessages b/resources/FatMessages
index 50b39dd..ff5a761 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -2916,6 +2916,11 @@ de.all.NoMemory:Zu wenig Speicher. Bitte mehr Speicher zur Verfügung stellen un
fr.all.NoMemory:NetSurf a besoin de plus de mémoire. Veuillez libérer de la mémoire et réessayer.
it.all.NoMemory:Memoria insufficiente per l'esecuzione di NetSurf. Per favore liberane un pò e riprova nuovamente.
nl.all.NoMemory:NetSurf krijgt gebrek aan geheugen. Maak wat geheugen vrij en probeer het dan nog eens.
+en.ro.LongURL:The URL for this page is too long for NetSurf to display.
+de.ro.LongURL:The URL for this page is too long for NetSurf to display.
+fr.ro.LongURL:The URL for this page is too long for NetSurf to display.
+it.ro.LongURL:The URL for this page is too long for NetSurf to display.
+nl.ro.LongURL:The URL for this page is too long for NetSurf to display.
en.ro.FontBadInst:An error occurred when initialising fonts due to the presence of obsolete copies of the ROM fonts on disc. NetSurf will exit and launch a program which will attempt to fix this.
de.ro.FontBadInst:Font-Initialisierung fehlerhaft. Obsolete Kopien von ROM Fonts auf dem lokalem Speichermedium. Fehlerbehebung startet.
fr.ro.FontBadInst:Une erreur s'est produite lors de l'initialisation des fontes à cause de la présence de copies obsolètes de fontes ROM sur disque. NetSurf va sortir et lancer un programme qui va tenter de réparer cela.
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 4993093..0b6bd1c 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -39,6 +39,7 @@
#include "riscos/window.h"
#include "utils/log.h"
#include "utils/messages.h"
+#include "utils/utf8.h"
#include "utils/utils.h"
#define URLBAR_HEIGHT 52
@@ -50,7 +51,6 @@
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
#define URLBAR_INITIAL_LENGTH 256
-#define URLBAR_EXTEND_LENGTH 128
struct url_bar {
/** The applied theme (or NULL to use the default) */
@@ -942,24 +942,65 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
{
wimp_caret caret;
os_error *error;
- const char *set_url;
+ char *local_text = NULL;
+ const char *set_url, *local_url;
nsurl *n;
- if (url_bar == NULL || url_bar->text_buffer == NULL)
+ if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL)
return;
- if (nsurl_create(url, &n) == NSERROR_OK) {
+ /* Before we do anything with the URL, get it into local encoding so
+ * that behaviour is consistant with the rest of the URL Bar module
+ * (which will act on the icon's text buffer, which is always in local
+ * encoding).
+ */
+
+ if (is_utf8) {
+ utf8_convert_ret err;
+
+ err = utf8_to_local_encoding(url, 0, &local_text);
+ if (err != UTF8_CONVERT_OK) {
+ /* A bad encoding should never happen, so assert this */
+ assert(err != UTF8_CONVERT_BADENC);
+ LOG(("utf8_to_enc failed"));
+ /* Paranoia */
+ local_text = NULL;
+ }
+ local_url = (local_text != NULL) ? local_text : url;
+ } else {
+ local_url = url;
+ }
+
+ /* Copy the text into the icon buffer. If the text is too long, blank
+ * the buffer and warn the user.
+ */
+
+ if (strlen(local_url) >= url_bar->text_size) {
+ strncpy(url_bar->text_buffer, "", url_bar->text_size);
+ warn_user("LongURL", NULL);
+ LOG(("Long URL (%d chars): %s", strlen(url), url));
+ } else {
+ strncpy(url_bar->text_buffer, local_url, url_bar->text_size);
+ }
+
+ if (local_text != NULL)
+ free(local_text);
+
+ /* Set the hotlist flag. */
+
+ if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) {
ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
nsurl_unref(n);
}
- if (url_bar->text_icon == -1) {
- strncpy(url_bar->text_buffer, url, url_bar->text_size);
+ /* If there's no icon, then there's nothing else to do... */
+
+ if (url_bar->text_icon == -1)
return;
- }
- ro_gui_set_icon_string(url_bar->window, url_bar->text_icon,
- url, is_utf8);
+ /* ...if there is, redraw the icon and fix the caret's position. */
+
+ ro_gui_redraw_icon(url_bar->window, url_bar->text_icon);
error = xwimp_get_caret_position(&caret);
if (error) {
-----------------------------------------------------------------------
Summary of changes:
resources/FatMessages | 5 ++++
riscos/gui/url_bar.c | 63 ++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/resources/FatMessages b/resources/FatMessages
index 50b39dd..ff5a761 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -2916,6 +2916,11 @@ de.all.NoMemory:Zu wenig Speicher. Bitte mehr Speicher zur Verfügung stellen un
fr.all.NoMemory:NetSurf a besoin de plus de mémoire. Veuillez libérer de la mémoire et réessayer.
it.all.NoMemory:Memoria insufficiente per l'esecuzione di NetSurf. Per favore liberane un pò e riprova nuovamente.
nl.all.NoMemory:NetSurf krijgt gebrek aan geheugen. Maak wat geheugen vrij en probeer het dan nog eens.
+en.ro.LongURL:The URL for this page is too long for NetSurf to display.
+de.ro.LongURL:The URL for this page is too long for NetSurf to display.
+fr.ro.LongURL:The URL for this page is too long for NetSurf to display.
+it.ro.LongURL:The URL for this page is too long for NetSurf to display.
+nl.ro.LongURL:The URL for this page is too long for NetSurf to display.
en.ro.FontBadInst:An error occurred when initialising fonts due to the presence of obsolete copies of the ROM fonts on disc. NetSurf will exit and launch a program which will attempt to fix this.
de.ro.FontBadInst:Font-Initialisierung fehlerhaft. Obsolete Kopien von ROM Fonts auf dem lokalem Speichermedium. Fehlerbehebung startet.
fr.ro.FontBadInst:Une erreur s'est produite lors de l'initialisation des fontes à cause de la présence de copies obsolètes de fontes ROM sur disque. NetSurf va sortir et lancer un programme qui va tenter de réparer cela.
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 4993093..b66b2af 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -39,6 +39,7 @@
#include "riscos/window.h"
#include "utils/log.h"
#include "utils/messages.h"
+#include "utils/utf8.h"
#include "utils/utils.h"
#define URLBAR_HEIGHT 52
@@ -49,8 +50,7 @@
#define URLBAR_MIN_WIDTH 52
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
-#define URLBAR_INITIAL_LENGTH 256
-#define URLBAR_EXTEND_LENGTH 128
+#define URLBAR_URL_LENGTH 2048
struct url_bar {
/** The applied theme (or NULL to use the default) */
@@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
url_bar->hotlist.extent.x1 = 0;
url_bar->hotlist.extent.y1 = 0;
- url_bar->text_size = URLBAR_INITIAL_LENGTH;
+ url_bar->text_size = URLBAR_URL_LENGTH;
url_bar->text_buffer = malloc(url_bar->text_size);
strncpy(url_bar->text_buffer, "", url_bar->text_size);
@@ -942,24 +942,65 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
{
wimp_caret caret;
os_error *error;
- const char *set_url;
+ char *local_text = NULL;
+ const char *set_url, *local_url;
nsurl *n;
- if (url_bar == NULL || url_bar->text_buffer == NULL)
+ if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL)
return;
- if (nsurl_create(url, &n) == NSERROR_OK) {
+ /* Before we do anything with the URL, get it into local encoding so
+ * that behaviour is consistant with the rest of the URL Bar module
+ * (which will act on the icon's text buffer, which is always in local
+ * encoding).
+ */
+
+ if (is_utf8) {
+ utf8_convert_ret err;
+
+ err = utf8_to_local_encoding(url, 0, &local_text);
+ if (err != UTF8_CONVERT_OK) {
+ /* A bad encoding should never happen, so assert this */
+ assert(err != UTF8_CONVERT_BADENC);
+ LOG(("utf8_to_enc failed"));
+ /* Paranoia */
+ local_text = NULL;
+ }
+ local_url = (local_text != NULL) ? local_text : url;
+ } else {
+ local_url = url;
+ }
+
+ /* Copy the text into the icon buffer. If the text is too long, blank
+ * the buffer and warn the user.
+ */
+
+ if (strlen(local_url) >= url_bar->text_size) {
+ strncpy(url_bar->text_buffer, "", url_bar->text_size);
+ warn_user("LongURL", NULL);
+ LOG(("Long URL (%d chars): %s", strlen(url), url));
+ } else {
+ strncpy(url_bar->text_buffer, local_url, url_bar->text_size);
+ }
+
+ if (local_text != NULL)
+ free(local_text);
+
+ /* Set the hotlist flag. */
+
+ if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) {
ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
nsurl_unref(n);
}
- if (url_bar->text_icon == -1) {
- strncpy(url_bar->text_buffer, url, url_bar->text_size);
+ /* If there's no icon, then there's nothing else to do... */
+
+ if (url_bar->text_icon == -1)
return;
- }
- ro_gui_set_icon_string(url_bar->window, url_bar->text_icon,
- url, is_utf8);
+ /* ...if there is, redraw the icon and fix the caret's position. */
+
+ ro_gui_redraw_icon(url_bar->window, url_bar->text_icon);
error = xwimp_get_caret_position(&caret);
if (error) {
--
NetSurf Browser
9 years
netsurf: branch master updated. release/3.0-999-gdc07404
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/dc074042e9f4bcd7d3ccf...
...commit http://git.netsurf-browser.org/netsurf.git/commit/dc074042e9f4bcd7d3ccf09...
...tree http://git.netsurf-browser.org/netsurf.git/tree/dc074042e9f4bcd7d3ccf09fc...
The branch, master has been updated
via dc074042e9f4bcd7d3ccf09fcd81f9b11a0517d0 (commit)
from 8ce0a10670e655d9e3a4f31fedd34baf1a3189b9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=dc074042e9f4bcd7d3c...
commit dc074042e9f4bcd7d3ccf09fcd81f9b11a0517d0
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
fix errors in url_to_path tfetch table changes
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 32ad8f1..5c35911 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -22,6 +22,7 @@
#import "cocoa/plotter.h"
#import "cocoa/DownloadWindowController.h"
#import "cocoa/selection.h"
+#import "cocoa/fetch.h"
#import "desktop/gui.h"
#import "content/urldb.h"
diff --git a/riscos/gui.c b/riscos/gui.c
index 43e2f3a..69d5b29 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -808,7 +808,7 @@ static char *path_to_url(const char *path)
* \return RISC OS pathname, allocated on heap, or 0 on failure
*/
-static char *url_to_path(const char *url)
+char *url_to_path(const char *url)
{
char *path;
char *filename;
diff --git a/riscos/gui.h b/riscos/gui.h
index 3eeb562..32710b4 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -119,6 +119,7 @@ void ro_gui_drag_box_start(wimp_pointer *pointer);
bool ro_gui_prequit(void);
const char *ro_gui_default_language(void);
void gui_poll(bool active); /* exported for riscos/wimp_event.c:722 */
+char *url_to_path(const char *url);
/* in download.c */
void ro_gui_download_init(void);
-----------------------------------------------------------------------
Summary of changes:
cocoa/NetsurfApp.m | 1 +
riscos/gui.c | 2 +-
riscos/gui.h | 1 +
3 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 32ad8f1..5c35911 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -22,6 +22,7 @@
#import "cocoa/plotter.h"
#import "cocoa/DownloadWindowController.h"
#import "cocoa/selection.h"
+#import "cocoa/fetch.h"
#import "desktop/gui.h"
#import "content/urldb.h"
diff --git a/riscos/gui.c b/riscos/gui.c
index 43e2f3a..69d5b29 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -808,7 +808,7 @@ static char *path_to_url(const char *path)
* \return RISC OS pathname, allocated on heap, or 0 on failure
*/
-static char *url_to_path(const char *url)
+char *url_to_path(const char *url)
{
char *path;
char *filename;
diff --git a/riscos/gui.h b/riscos/gui.h
index 3eeb562..32710b4 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -119,6 +119,7 @@ void ro_gui_drag_box_start(wimp_pointer *pointer);
bool ro_gui_prequit(void);
const char *ro_gui_default_language(void);
void gui_poll(bool active); /* exported for riscos/wimp_event.c:722 */
+char *url_to_path(const char *url);
/* in download.c */
void ro_gui_download_init(void);
--
NetSurf Browser
9 years
netsurf: branch master updated. release/3.0-998-g8ce0a10
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/8ce0a10670e655d9e3a4f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/8ce0a10670e655d9e3a4f31...
...tree http://git.netsurf-browser.org/netsurf.git/tree/8ce0a10670e655d9e3a4f31fe...
The branch, master has been updated
via 8ce0a10670e655d9e3a4f31fedd34baf1a3189b9 (commit)
from 46b8fbaeac4dd1e35945ae1338056156e5b3b86b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=8ce0a10670e655d9e3a...
commit 8ce0a10670e655d9e3a4f31fedd34baf1a3189b9
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
move path_to_url and url_to_path to fetch operation table
diff --git a/amiga/gui.c b/amiga/gui.c
index a9c72c9..074dfaf 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -5189,6 +5189,8 @@ static struct gui_fetch_table amiga_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = gui_get_resource_url,
};
diff --git a/amiga/misc.h b/amiga/misc.h
index 34a85fa..60f249c 100644
--- a/amiga/misc.h
+++ b/amiga/misc.h
@@ -18,6 +18,10 @@
#ifndef AMIGA_MISC_H
#define AMIGA_MISC_H
+
char *translate_escape_chars(const char *s);
int32 ami_warn_user_multi(const char *body, const char *opt1, const char *opt2, struct Window *win);
+char *url_to_path(const char *url);
+char *path_to_url(const char *path);
+
#endif
diff --git a/atari/findfile.h b/atari/findfile.h
index e87f7cf..cced009 100755
--- a/atari/findfile.h
+++ b/atari/findfile.h
@@ -21,6 +21,9 @@
#define NS_ATARI_FINDFILE_H
extern char *atari_find_resource(char *buf, const char *filename, const char *def);
-char * local_file_to_url( const char * filename );
+char *local_file_to_url(const char *filename);
+
+char *path_to_url(const char *path_in);
+char *url_to_path(const char *url);
#endif /* NETSURF_ATARI_FINDFILE_H */
diff --git a/atari/gui.c b/atari/gui.c
index 0267148..f1f557e 100644
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -1077,6 +1077,8 @@ static struct gui_fetch_table atari_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = gui_get_resource_url,
.mimetype = fetch_mimetype,
diff --git a/beos/gui.cpp b/beos/gui.cpp
index ca176c8..05e0637 100644
--- a/beos/gui.cpp
+++ b/beos/gui.cpp
@@ -786,6 +786,17 @@ static void gui_quit(void)
fetch_rsrc_unregister();
}
+static 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;
+}
/**
* Send the source of a content to a text editor.
@@ -983,7 +994,7 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len,
return UTF8_CONVERT_OK;
}
-char *path_to_url(const char *path)
+static char *path_to_url(const char *path)
{
int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
char *url = (char *)malloc(urllen);
@@ -1001,17 +1012,6 @@ char *path_to_url(const char *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;
-}
static void *myrealloc(void *ptr, size_t len, void *pw)
{
@@ -1071,6 +1071,8 @@ static struct gui_fetch_table beos_fetch_table = {
filename_from_path,
path_add_part,
fetch_filetype,
+ path_to_url,
+ url_to_path,
gui_get_resource_url,
NULL //fetch_mimetype
};
diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m
index 77ee57b..956654a 100644
--- a/cocoa/BrowserViewController.m
+++ b/cocoa/BrowserViewController.m
@@ -19,6 +19,7 @@
#import "cocoa/BrowserViewController.h"
#import "cocoa/BrowserView.h"
#import "cocoa/BrowserWindowController.h"
+#import "cocoa/fetch.h"
#import "desktop/browser_private.h"
#import "desktop/local_history.h"
diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target
index 8bd13c2..49f67f0 100644
--- a/cocoa/Makefile.target
+++ b/cocoa/Makefile.target
@@ -95,7 +95,6 @@ S_COCOA := \
schedule.m \
selection.m \
thumbnail.m \
- url.m \
utf8.m \
utils.m \
ArrowBox.m \
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 5643efd..32ad8f1 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -25,7 +25,6 @@
#import "desktop/gui.h"
#import "content/urldb.h"
-#import "content/fetch.h"
#import "css/utils.h"
#import "desktop/gui.h"
#import "desktop/local_history.h"
diff --git a/cocoa/fetch.h b/cocoa/fetch.h
index 4a50b6e..5d2e928 100644
--- a/cocoa/fetch.h
+++ b/cocoa/fetch.h
@@ -16,4 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-const char *fetch_filetype(const char *unix_path);
+extern struct gui_fetch_table *cocoa_fetch_table;
+
+char *url_to_path(const char *url);
diff --git a/cocoa/fetch.m b/cocoa/fetch.m
index b1c7aea..7bf00e0 100644
--- a/cocoa/fetch.m
+++ b/cocoa/fetch.m
@@ -19,7 +19,7 @@
#import <Cocoa/Cocoa.h>
#import "utils/log.h"
-#import "content/fetch.h"
+#import "desktop/gui.h"
#import "cocoa/fetch.h"
@@ -42,9 +42,9 @@ static const struct mimemap_s {
};
-const char *fetch_filetype(const char *unix_path)
+static const char *fetch_filetype(const char *unix_path)
{
- NSString *uti;
+ NSString *uti;
NSString *mimeType = nil;
NSError *utiError = nil;
@@ -58,7 +58,7 @@ const char *fetch_filetype(const char *unix_path)
LOG(("uti call failed"));
- strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype));
+ strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype));
return cocoafiletype;
}
@@ -83,13 +83,60 @@ const char *fetch_filetype(const char *unix_path)
eidx++;
}
- strncpy(cocoafiletype,
- cocoamimemap[eidx].mimetype,
+ strncpy(cocoafiletype,
+ cocoamimemap[eidx].mimetype,
sizeof(cocoafiletype));
}
}
LOG(( "\tMIME type for '%s' is '%s'", unix_path, cocoafiletype ));
-
+
return cocoafiletype;
}
+
+char *url_to_path(const char *url)
+{
+ NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]];
+ return strdup([[nsurl path] UTF8String]);
+}
+
+static char *path_to_url(const char *path)
+{
+ return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]]
+ absoluteString] UTF8String] );
+}
+
+static char *filename_from_path(char *path)
+{
+ return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
+}
+
+static bool path_add_part(char *path, int length, const char *newpart)
+{
+ NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
+
+ strncpy( path, [newPath UTF8String], length );
+
+ return true;
+}
+
+static nsurl *gui_get_resource_url(const char *path)
+{
+ nsurl *url = NULL;
+ NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""];
+ if (nspath == nil) return NULL;
+ nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url);
+ return url;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filename_from_path = filename_from_path,
+ .path_add_part = path_add_part,
+ .filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
+
+ .get_resource_url = gui_get_resource_url,
+};
+
+struct gui_fetch_table *cocoa_fetch_table = &fetch_table;
diff --git a/cocoa/gui.h b/cocoa/gui.h
index 55b6907..7571400 100644
--- a/cocoa/gui.h
+++ b/cocoa/gui.h
@@ -20,7 +20,6 @@
extern struct gui_window_table *cocoa_window_table;
extern struct gui_clipboard_table *cocoa_clipboard_table;
-extern struct gui_fetch_table *cocoa_fetch_table;
extern struct gui_browser_table *cocoa_browser_table;
extern NSString * const kCookiesFileOption;
diff --git a/cocoa/gui.m b/cocoa/gui.m
index 2a97df3..750d9fc 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -46,15 +46,6 @@ NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs";
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
-static nsurl *gui_get_resource_url(const char *path)
-{
- nsurl *url = NULL;
- NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""];
- if (nspath == nil) return NULL;
- nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url);
- return url;
-}
-
static void gui_poll(bool active)
{
cocoa_autorelease();
@@ -273,20 +264,6 @@ static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
cb( false, cbpw );
}
-static char *filename_from_path(char *path)
-{
- return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
-}
-
-static bool path_add_part(char *path, int length, const char *newpart)
-{
- NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
-
- strncpy( path, [newPath UTF8String], length );
-
- return true;
-}
-
static struct gui_window_table window_table = {
.create = gui_window_create,
@@ -312,15 +289,6 @@ static struct gui_window_table window_table = {
struct gui_window_table *cocoa_window_table = &window_table;
-static struct gui_fetch_table fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
- .filetype = fetch_filetype,
-
- .get_resource_url = gui_get_resource_url,
-};
-
-struct gui_fetch_table *cocoa_fetch_table = &fetch_table;
static struct gui_browser_table browser_table = {
.poll = gui_poll,
diff --git a/cocoa/url.m b/cocoa/url.m
deleted file mode 100644
index 931f459..0000000
--- a/cocoa/url.m
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2011 Sven Weidauer <sven.weidauer(a)gmail.com>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#import <Cocoa/Cocoa.h>
-
-#import "utils/url.h"
-
-
-char *url_to_path(const char *url)
-{
- NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]];
- return strdup([[nsurl path] UTF8String]);
-}
-
-char *path_to_url(const char *path)
-{
- return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]]
- absoluteString] UTF8String] );
-}
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index 7b93ab1..00d5cc5 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -142,7 +142,7 @@ fetch_file_setup(struct fetch *fetchh,
if (ctx == NULL)
return NULL;
- ctx->path = url_to_path(nsurl_access(url));
+ ctx->path = guit->fetch->url_to_path(nsurl_access(url));
if (ctx->path == NULL) {
free(ctx);
return NULL;
@@ -600,7 +600,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
}
}
- if((path = path_to_url(urlpath)) == NULL)
+ if((path = guit->fetch->path_to_url(urlpath)) == NULL)
continue;
if (S_ISREG(ent_stat.st_mode)) {
diff --git a/desktop/gui.h b/desktop/gui.h
index 724355d..da609b1 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -319,6 +319,22 @@ struct gui_fetch_table {
*/
const char *(*filetype)(const char *unix_path);
+ /**
+ * Convert a pathname to a file: URL.
+ *
+ * \param path pathname
+ * \return URL, allocated on heap, or NULL on failure
+ */
+ char *(*path_to_url)(const char *path);
+
+ /**
+ * Convert a file: URL to a pathname.
+ *
+ * \param url a file: URL
+ * \return pathname, allocated on heap, or NULL on failure
+ */
+ char *(*url_to_path)(const char *url);
+
/* Optional entries */
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 06b5383..dfe7755 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -317,6 +317,12 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft)
if (gft->filetype == NULL) {
return NSERROR_BAD_PARAMETER;
}
+ if (gft->path_to_url == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+ if (gft->url_to_path == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
/* fill in the optional entries with defaults */
diff --git a/desktop/searchweb.c b/desktop/searchweb.c
index d42919d..b3f6162 100644
--- a/desktop/searchweb.c
+++ b/desktop/searchweb.c
@@ -236,7 +236,7 @@ void search_web_retrieve_ico(bool localdefault)
if (localdefault) {
if (search_default_ico_location == NULL)
return;
- url = path_to_url(search_default_ico_location);
+ url = guit->fetch->path_to_url(search_default_ico_location);
} else {
url = search_web_ico_name();
}
diff --git a/framebuffer/fetch.c b/framebuffer/fetch.c
index 2e304c2..0c9b90f 100644
--- a/framebuffer/fetch.c
+++ b/framebuffer/fetch.c
@@ -68,7 +68,13 @@ static bool path_add_part(char *path, int length, const char *newpart)
return true;
}
-char *path_to_url(const char *path)
+/**
+ * Convert a pathname to a file: URL.
+ *
+ * \param path pathname
+ * \return URL, allocated on heap, or NULL on failure
+ */
+static char *path_to_url(const char *path)
{
int urllen;
char *url;
@@ -88,8 +94,13 @@ char *path_to_url(const char *path)
return url;
}
-
-char *url_to_path(const char *url)
+/**
+ * Convert a file: URL to a pathname.
+ *
+ * \param url a file: URL
+ * \return pathname, allocated on heap, or NULL on failure
+ */
+static char *url_to_path(const char *url)
{
char *path;
char *respath;
@@ -178,6 +189,8 @@ static struct gui_fetch_table fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = get_resource_url,
.mimetype = fetch_mimetype,
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index 426c4af..ec19d1b 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -108,7 +108,7 @@ $(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(
# S_GTK are sources purely for the GTK build
S_GTK := font_pango.c bitmap.c gui.c schedule.c thumbnail.c plotters.c \
treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
- selection.c history.c window.c filetype.c download.c menu.c \
+ selection.c history.c window.c fetch.c download.c menu.c \
print.c search.c tabs.c theme.c toolbar.c gettext.c \
compat.c cookies.c hotlist.c \
$(addprefix dialogs/,preferences.c about.c source.c)
diff --git a/gtk/dialogs/source.c b/gtk/dialogs/source.c
index 5306bdc..a7c9815 100644
--- a/gtk/dialogs/source.c
+++ b/gtk/dialogs/source.c
@@ -23,13 +23,6 @@
#include <unistd.h>
#include <gtk/gtk.h>
-#include "gtk/compat.h"
-#include "gtk/dialogs/source.h"
-#include "gtk/dialogs/about.h"
-#include "gtk/window.h"
-#include "gtk/gui.h"
-#include "gtk/print.h"
-#include "gtk/selection.h"
#include "desktop/browser_private.h"
#include "desktop/netsurf.h"
#include "desktop/print.h"
@@ -42,9 +35,17 @@
#include "render/font.h"
#include "content/content.h"
#include "content/content_type.h"
-
#include "utils/log.h"
+#include "gtk/compat.h"
+#include "gtk/dialogs/source.h"
+#include "gtk/dialogs/about.h"
+#include "gtk/window.h"
+#include "gtk/gui.h"
+#include "gtk/print.h"
+#include "gtk/selection.h"
+#include "gtk/fetch.h"
+
struct nsgtk_source_window {
gchar *url;
char *data;
diff --git a/gtk/fetch.c b/gtk/fetch.c
new file mode 100644
index 0000000..f4a42b5
--- /dev/null
+++ b/gtk/fetch.c
@@ -0,0 +1,347 @@
+/*
+ * Copyright 2014 vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "utils/hashtable.h"
+#include "utils/url.h"
+#include "utils/log.h"
+#include "utils/filepath.h"
+#include "desktop/gui.h"
+
+#include "gtk/gui.h"
+#include "gtk/fetch.h"
+
+static struct hash_table *mime_hash = NULL;
+
+void gtk_fetch_filetype_init(const char *mimefile)
+{
+ struct stat statbuf;
+ FILE *fh = NULL;
+
+ mime_hash = hash_create(117);
+
+ /* first, check to see if /etc/mime.types in preference */
+
+ if ((stat("/etc/mime.types", &statbuf) == 0) &&
+ S_ISREG(statbuf.st_mode)) {
+ mimefile = "/etc/mime.types";
+ }
+
+ fh = fopen(mimefile, "r");
+
+ /* Some OSes (mentioning no Solarises) have a worthlessly tiny
+ * /etc/mime.types that don't include essential things, so we
+ * pre-seed our hash with the essentials. These will get
+ * over-ridden if they are mentioned in the mime.types file.
+ */
+
+ hash_add(mime_hash, "css", "text/css");
+ hash_add(mime_hash, "htm", "text/html");
+ hash_add(mime_hash, "html", "text/html");
+ hash_add(mime_hash, "jpg", "image/jpeg");
+ hash_add(mime_hash, "jpeg", "image/jpeg");
+ hash_add(mime_hash, "gif", "image/gif");
+ hash_add(mime_hash, "png", "image/png");
+ hash_add(mime_hash, "jng", "image/jng");
+ hash_add(mime_hash, "mng", "image/mng");
+ hash_add(mime_hash, "webp", "image/webp");
+ hash_add(mime_hash, "spr", "image/x-riscos-sprite");
+
+ if (fh == NULL) {
+ LOG(("Unable to open a mime.types file, so using a minimal one for you."));
+ return;
+ }
+
+ while (!feof(fh)) {
+ char line[256], *ptr, *type, *ext;
+
+ if (fgets(line, 256, fh) == NULL)
+ break;
+
+ if (!feof(fh) && line[0] != '#') {
+ ptr = line;
+
+ /* search for the first non-whitespace character */
+ while (isspace(*ptr)) {
+ ptr++;
+ }
+
+ /* is this line empty other than leading whitespace? */
+ if (*ptr == '\n' || *ptr == '\0') {
+ continue;
+ }
+
+ type = ptr;
+
+ /* search for the first non-whitespace char or NUL or
+ * NL */
+ while (*ptr && (!isspace(*ptr)) && *ptr != '\n') {
+ ptr++;
+ }
+
+ if (*ptr == '\0' || *ptr == '\n') {
+ /* this mimetype has no extensions - read next
+ * line.
+ */
+ continue;
+ }
+
+ *ptr++ = '\0';
+
+ /* search for the first non-whitespace character which
+ * will be the first filename extenion */
+ while (isspace(*ptr)) {
+ ptr++;
+ }
+
+ while(true) {
+ ext = ptr;
+
+ /* search for the first whitespace char or
+ * NUL or NL which is the end of the ext.
+ */
+ while (*ptr &&
+ (!isspace(*ptr)) &&
+ *ptr != '\n') {
+ ptr++;
+ }
+
+ if (*ptr == '\0' || *ptr == '\n') {
+ /* special case for last extension on
+ * the line
+ */
+ *ptr = '\0';
+ hash_add(mime_hash, ext, type);
+ break;
+ }
+
+ *ptr++ = '\0';
+ hash_add(mime_hash, ext, type);
+
+ /* search for the first non-whitespace char or
+ * NUL or NL, to find start of next ext.
+ */
+ while (*ptr &&
+ (isspace(*ptr)) &&
+ *ptr != '\n') {
+ ptr++;
+ }
+ }
+ }
+ }
+
+ fclose(fh);
+}
+
+void gtk_fetch_filetype_fin(void)
+{
+ hash_destroy(mime_hash);
+}
+
+const char *fetch_filetype(const char *unix_path)
+{
+ struct stat statbuf;
+ char *ext;
+ const char *ptr;
+ char *lowerchar;
+ const char *type;
+ int l;
+
+ if (stat(unix_path, &statbuf) != 0) {
+ /* stat failed */
+ return "text/plain";
+ }
+
+ if (S_ISDIR(statbuf.st_mode)) {
+ return "application/x-netsurf-directory";
+ }
+
+ l = strlen(unix_path);
+
+ /* Hacky RISC OS compatibility */
+ if ((3 < l) && (strcasecmp(unix_path + l - 4, ",f79") == 0)) {
+ return "text/css";
+ } else if ((3 < l) && (strcasecmp(unix_path + l - 4, ",faf") == 0)) {
+ return "text/html";
+ } else if ((3 < l) && (strcasecmp(unix_path + l - 4, ",b60") == 0)) {
+ return "image/png";
+ } else if ((3 < l) && (strcasecmp(unix_path + l - 4, ",ff9") == 0)) {
+ return "image/x-riscos-sprite";
+ }
+
+ if (strchr(unix_path, '.') == NULL) {
+ /* no extension anywhere! */
+ return "text/plain";
+ }
+
+ ptr = unix_path + strlen(unix_path);
+ while (*ptr != '.' && *ptr != '/') {
+ ptr--;
+ }
+
+ if (*ptr != '.') {
+ return "text/plain";
+ }
+
+ ext = strdup(ptr + 1); /* skip the . */
+
+ /* the hash table only contains lower-case versions - make sure this
+ * copy is lower case too.
+ */
+ lowerchar = ext;
+ while (*lowerchar) {
+ *lowerchar = tolower(*lowerchar);
+ lowerchar++;
+ }
+
+ type = hash_get(mime_hash, ext);
+ free(ext);
+
+ if (type == NULL) {
+ type = "text/plain";
+ }
+
+ return type;
+}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+static char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '/');
+ if (!leafname) {
+ leafname = path;
+ } else {
+ leafname += 1;
+ }
+
+ return strdup(leafname);
+}
+
+/**
+ * Add a path component/filename to an existing path
+ *
+ * \param path buffer containing path + free space
+ * \param length length of buffer "path"
+ * \param newpart string containing path component to add to path
+ * \return true on success
+ */
+static bool path_add_part(char *path, int length, const char *newpart)
+{
+ if (path[strlen(path) - 1] != '/') {
+ strncat(path, "/", length);
+ }
+
+ strncat(path, newpart, length);
+
+ return true;
+}
+
+char *path_to_url(const char *path)
+{
+ int urllen;
+ char *url;
+
+ if (path == NULL) {
+ return NULL;
+ }
+
+ urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
+
+ url = malloc(urllen);
+ if (url == NULL) {
+ return NULL;
+ }
+
+ if (*path == '/') {
+ path++; /* file: paths are already absolute */
+ }
+
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
+
+ return url;
+}
+
+
+static char *url_to_path(const char *url)
+{
+ char *path;
+ char *respath;
+ url_func_result res; /* result from url routines */
+
+ res = url_path(url, &path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ res = url_unescape(path, &respath);
+ free(path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ return respath;
+}
+
+static nsurl *gui_get_resource_url(const char *path)
+{
+ char buf[PATH_MAX];
+ char *raw;
+ nsurl *url = NULL;
+
+ /* default.css -> gtkdefault.css */
+ if (strcmp(path, "default.css") == 0) {
+ path = "gtkdefault.css";
+ }
+
+ /* favicon.ico -> favicon.png */
+ if (strcmp(path, "favicon.ico") == 0) {
+ path = "favicon.png";
+ }
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filename_from_path = filename_from_path,
+ .path_add_part = path_add_part,
+ .filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
+
+ .get_resource_url = gui_get_resource_url,
+
+};
+
+struct gui_fetch_table *nsgtk_fetch_table = &fetch_table;
diff --git a/gtk/fetch.h b/gtk/fetch.h
new file mode 100644
index 0000000..400a06a
--- /dev/null
+++ b/gtk/fetch.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_GTK_FETCH_H
+#define NETSURF_GTK_FETCH_H
+
+struct gui_fetch_table *nsgtk_fetch_table;
+
+void gtk_fetch_filetype_init(const char *mimefile);
+void gtk_fetch_filetype_fin(void);
+const char *fetch_filetype(const char *unix_path);
+
+char *path_to_url(const char *path);
+
+#endif
diff --git a/gtk/filetype.c b/gtk/filetype.c
deleted file mode 100644
index a949b14..0000000
--- a/gtk/filetype.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright 2007 Rob Kendrick <rjek(a)netsurf-browser.org>
- * Copyright 2007 Vincent Sanders <vince(a)debian.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "gtk/filetype.h"
-#include "content/fetch.h"
-#include "utils/log.h"
-#include "utils/hashtable.h"
-
-static struct hash_table *mime_hash = NULL;
-
-void gtk_fetch_filetype_init(const char *mimefile)
-{
- struct stat statbuf;
- FILE *fh = NULL;
-
- mime_hash = hash_create(117);
-
- /* first, check to see if /etc/mime.types in preference */
-
- if ((stat("/etc/mime.types", &statbuf) == 0) &&
- S_ISREG(statbuf.st_mode)) {
- mimefile = "/etc/mime.types";
-
- }
-
- fh = fopen(mimefile, "r");
-
- /* Some OSes (mentioning no Solarises) have a worthlessly tiny
- * /etc/mime.types that don't include essential things, so we
- * pre-seed our hash with the essentials. These will get
- * over-ridden if they are mentioned in the mime.types file.
- */
-
- hash_add(mime_hash, "css", "text/css");
- hash_add(mime_hash, "htm", "text/html");
- hash_add(mime_hash, "html", "text/html");
- hash_add(mime_hash, "jpg", "image/jpeg");
- hash_add(mime_hash, "jpeg", "image/jpeg");
- hash_add(mime_hash, "gif", "image/gif");
- hash_add(mime_hash, "png", "image/png");
- hash_add(mime_hash, "jng", "image/jng");
- hash_add(mime_hash, "mng", "image/mng");
- hash_add(mime_hash, "webp", "image/webp");
- hash_add(mime_hash, "spr", "image/x-riscos-sprite");
-
- if (fh == NULL) {
- LOG(("Unable to open a mime.types file, so using a minimal one for you."));
- return;
- }
-
- while (!feof(fh)) {
- char line[256], *ptr, *type, *ext;
- if (fgets(line, 256, fh) == NULL)
- break;
- if (!feof(fh) && line[0] != '#') {
- ptr = line;
-
- /* search for the first non-whitespace character */
- while (isspace(*ptr))
- ptr++;
-
- /* is this line empty other than leading whitespace? */
- if (*ptr == '\n' || *ptr == '\0')
- continue;
-
- type = ptr;
-
- /* search for the first non-whitespace char or NUL or
- * NL */
- while (*ptr && (!isspace(*ptr)) && *ptr != '\n')
- ptr++;
-
- if (*ptr == '\0' || *ptr == '\n') {
- /* this mimetype has no extensions - read next
- * line.
- */
- continue;
- }
-
- *ptr++ = '\0';
-
- /* search for the first non-whitespace character which
- * will be the first filename extenion */
- while (isspace(*ptr))
- ptr++;
-
- while(true) {
- ext = ptr;
-
- /* search for the first whitespace char or
- * NUL or NL which is the end of the ext.
- */
- while (*ptr && (!isspace(*ptr)) &&
- *ptr != '\n')
- ptr++;
-
- if (*ptr == '\0' || *ptr == '\n') {
- /* special case for last extension on
- * the line
- */
- *ptr = '\0';
- hash_add(mime_hash, ext, type);
- break;
- }
-
- *ptr++ = '\0';
- hash_add(mime_hash, ext, type);
-
- /* search for the first non-whitespace char or
- * NUL or NL, to find start of next ext.
- */
- while (*ptr && (isspace(*ptr)) && *ptr != '\n')
- ptr++;
- }
- }
- }
-
- fclose(fh);
-}
-
-void gtk_fetch_filetype_fin(void)
-{
- hash_destroy(mime_hash);
-}
-
-const char *fetch_filetype(const char *unix_path)
-{
- struct stat statbuf;
- char *ext;
- const char *ptr;
- char *lowerchar;
- const char *type;
- int l;
-
- if (stat(unix_path, &statbuf) != 0) {
- /* stat failed */
- return "text/plain";
- }
-
- if (S_ISDIR(statbuf.st_mode))
- return "application/x-netsurf-directory";
-
- l = strlen(unix_path);
-
- /* Hacky RISC OS compatibility */
- if ((3 < l) && (strcasecmp(unix_path + l - 4, ",f79") == 0)) {
- return "text/css";
- } else if ((3 < l) && (strcasecmp(unix_path + l - 4, ",faf") == 0)) {
- return "text/html";
- } else if ((3 < l) && (strcasecmp(unix_path + l - 4, ",b60") == 0)) {
- return "image/png";
- } else if ((3 < l) && (strcasecmp(unix_path + l - 4, ",ff9") == 0)) {
- return "image/x-riscos-sprite";
- }
-
- if (strchr(unix_path, '.') == NULL) {
- /* no extension anywhere! */
- return "text/plain";
- }
-
- ptr = unix_path + strlen(unix_path);
- while (*ptr != '.' && *ptr != '/')
- ptr--;
-
- if (*ptr != '.')
- return "text/plain";
-
- ext = strdup(ptr + 1); /* skip the . */
-
- /* the hash table only contains lower-case versions - make sure this
- * copy is lower case too.
- */
- lowerchar = ext;
- while(*lowerchar) {
- *lowerchar = tolower(*lowerchar);
- lowerchar++;
- }
-
- type = hash_get(mime_hash, ext);
- free(ext);
-
- return type != NULL ? type : "text/plain";
-}
-
-#ifdef TEST_RIG
-
-int main(int argc, char *argv[])
-{
- unsigned int c1, *c2;
- const char *key;
-
- gtk_fetch_filetype_init("./mime.types");
-
- c1 = 0; c2 = 0;
-
- while ( (key = hash_iterate(mime_hash, &c1, &c2)) != NULL) {
- printf("%s ", key);
- }
-
- printf("\n");
-
- if (argc > 1) {
- printf("%s maps to %s\n", argv[1], fetch_filetype(argv[1]));
- }
-
- gtk_fetch_filetype_fin();
-}
-
-#endif
diff --git a/gtk/filetype.h b/gtk/filetype.h
deleted file mode 100644
index 68bb9c0..0000000
--- a/gtk/filetype.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2007 Rob Kendrick <rjek(a)netsurf-browser.org>
- * Copyright 2007 Vincent Sanders <vince(a)debian.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-void gtk_fetch_filetype_init(const char *mimefile);
-void gtk_fetch_filetype_fin(void);
-const char *fetch_filetype(const char *unix_path);
diff --git a/gtk/gui.c b/gtk/gui.c
index d6d3502..ad80e89 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -60,7 +60,7 @@
#include "gtk/completion.h"
#include "gtk/cookies.h"
#include "gtk/download.h"
-#include "gtk/filetype.h"
+#include "gtk/fetch.h"
#include "gtk/gui.h"
#include "gtk/history.h"
#include "gtk/hotlist.h"
@@ -109,7 +109,7 @@ static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data);
#define THROBBER_FRAMES 9
-static char **respaths; /** resource search path vector */
+char **respaths; /** resource search path vector */
/** Create an array of valid paths to search for resources.
*
@@ -324,28 +324,6 @@ static void check_options(char **respath)
}
-static nsurl *gui_get_resource_url(const char *path)
-{
- char buf[PATH_MAX];
- char *raw;
- nsurl *url = NULL;
-
- /* default.css -> gtkdefault.css */
- if (strcmp(path, "default.css") == 0)
- path = "gtkdefault.css";
-
- /* favicon.ico -> favicon.png */
- if (strcmp(path, "favicon.ico") == 0)
- path = "favicon.png";
-
- raw = path_to_url(filepath_sfind(respaths, buf, path));
- if (raw != NULL) {
- nsurl_create(raw, &url);
- free(raw);
- }
-
- return url;
-}
/**
@@ -842,51 +820,6 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len,
}
-char *path_to_url(const char *path)
-{
- int urllen;
- char *url;
-
- if (path == NULL) {
- return NULL;
- }
-
- urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
-
- url = malloc(urllen);
- if (url == NULL) {
- return NULL;
- }
-
- 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 *path;
- char *respath;
- url_func_result res; /* result from url routines */
-
- res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- res = url_unescape(path, &respath);
- free(path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- return respath;
-}
#ifdef WITH_PDF_EXPORT
@@ -1089,59 +1022,12 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key)
}
}
-/**
- * Return the filename part of a full path
- *
- * \param path full path and filename
- * \return filename (will be freed with free())
- */
-
-static char *filename_from_path(char *path)
-{
- char *leafname;
-
- leafname = strrchr(path, '/');
- if (!leafname)
- leafname = path;
- else
- leafname += 1;
-
- return strdup(leafname);
-}
-
-/**
- * Add a path component/filename to an existing path
- *
- * \param path buffer containing path + free space
- * \param length length of buffer "path"
- * \param newpart string containing path component to add to path
- * \return true on success
- */
-
-static bool path_add_part(char *path, int length, const char *newpart)
-{
- if(path[strlen(path) - 1] != '/')
- strncat(path, "/", length);
-
- strncat(path, newpart, length);
-
- return true;
-}
static struct gui_clipboard_table nsgtk_clipboard_table = {
.get = gui_get_clipboard,
.set = gui_set_clipboard,
};
-static struct gui_fetch_table nsgtk_fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
- .filetype = fetch_filetype,
-
- .get_resource_url = gui_get_resource_url,
-
-};
-
static struct gui_browser_table nsgtk_browser_table = {
.poll = gui_poll,
@@ -1166,7 +1052,7 @@ int main(int argc, char** argv)
.window = nsgtk_window_table,
.clipboard = &nsgtk_clipboard_table,
.download = nsgtk_download_table,
- .fetch = &nsgtk_fetch_table,
+ .fetch = nsgtk_fetch_table,
};
/* check home directory is available */
diff --git a/gtk/gui.h b/gtk/gui.h
index 65a6e07..dc1f2b3 100644
--- a/gtk/gui.h
+++ b/gtk/gui.h
@@ -59,6 +59,8 @@ extern char *themelist_file_location;
extern GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */
+extern char **respaths; /** resource search path vector */
+
uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *);
extern void gui_401login_open(nsurl *url, const char *realm,
diff --git a/monkey/Makefile.target b/monkey/Makefile.target
index 5240754..7c0f167 100644
--- a/monkey/Makefile.target
+++ b/monkey/Makefile.target
@@ -68,7 +68,7 @@ endif
# S_MONKEY are sources purely for the MONKEY build
S_MONKEY := main.c utils.c filetype.c schedule.c \
bitmap.c plot.c browser.c download.c thumbnail.c \
- 401login.c cert.c font.c poll.c dispatch.c
+ 401login.c cert.c font.c poll.c dispatch.c fetch.c
S_MONKEY := $(addprefix monkey/,$(S_MONKEY))
diff --git a/monkey/fetch.c b/monkey/fetch.c
new file mode 100644
index 0000000..668ad0e
--- /dev/null
+++ b/monkey/fetch.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <limits.h>
+
+#include "desktop/gui.h"
+#include "utils/url.h"
+#include "utils/nsurl.h"
+#include "utils/filepath.h"
+
+#include "monkey/filetype.h"
+#include "monkey/fetch.h"
+
+extern char **respaths;
+
+
+static char *path_to_url(const char *path)
+{
+ int urllen;
+ char *url;
+
+ if (path == NULL) {
+ return NULL;
+ }
+
+ urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
+
+ url = malloc(urllen);
+ if (url == NULL) {
+ return NULL;
+ }
+
+ if (*path == '/') {
+ path++; /* file: paths are already absolute */
+ }
+
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
+
+ return url;
+}
+
+static char *url_to_path(const char *url)
+{
+ char *path;
+ char *respath;
+ url_func_result res; /* result from url routines */
+
+ res = url_path(url, &path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ res = url_unescape(path, &respath);
+ free(path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ return respath;
+}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+static char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '/');
+ if (!leafname)
+ leafname = path;
+ else
+ leafname += 1;
+
+ return strdup(leafname);
+}
+
+/**
+ * Add a path component/filename to an existing path
+ *
+ * \param path buffer containing path + free space
+ * \param length length of buffer "path"
+ * \param newpart string containing path component to add to path
+ * \return true on success
+ */
+
+static bool path_add_part(char *path, int length, const char *newpart)
+{
+ if(path[strlen(path) - 1] != '/')
+ strncat(path, "/", length);
+
+ strncat(path, newpart, length);
+
+ return true;
+}
+
+static nsurl *gui_get_resource_url(const char *path)
+{
+ char buf[PATH_MAX];
+ char *raw;
+ nsurl *url = NULL;
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filename_from_path = filename_from_path,
+ .path_add_part = path_add_part,
+ .filetype = monkey_fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
+
+ .get_resource_url = gui_get_resource_url,
+};
+
+struct gui_fetch_table *monkey_fetch_table = &fetch_table;
diff --git a/monkey/fetch.h b/monkey/fetch.h
new file mode 100644
index 0000000..59e8696
--- /dev/null
+++ b/monkey/fetch.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+struct gui_fetch_table *monkey_fetch_table;
diff --git a/monkey/main.c b/monkey/main.c
index 1135f0e..07ce7ee 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -20,13 +20,14 @@
#include <stdio.h>
#include <stdlib.h>
-#include "monkey/filetype.h"
#include "utils/nsoption.h"
#include "monkey/poll.h"
#include "monkey/dispatch.h"
#include "monkey/browser.h"
#include "monkey/cert.h"
#include "monkey/401login.h"
+#include "monkey/filetype.h"
+#include "monkey/fetch.h"
#include "content/urldb.h"
#include "content/fetchers/resource.h"
@@ -36,49 +37,34 @@
#include "utils/filepath.h"
#include "utils/url.h"
-static char **respaths; /** resource search path vector */
+char **respaths; /** resource search path vector */
/* Stolen from gtk/gui.c */
static char **
nsmonkey_init_resource(const char *resource_path)
{
- const gchar * const *langv;
- char **pathv; /* resource path string vector */
- char **respath; /* resource paths vector */
+ const gchar * const *langv;
+ char **pathv; /* resource path string vector */
+ char **respath; /* resource paths vector */
- pathv = filepath_path_to_strvec(resource_path);
+ pathv = filepath_path_to_strvec(resource_path);
- langv = g_get_language_names();
+ langv = g_get_language_names();
- respath = filepath_generate(pathv, langv);
+ respath = filepath_generate(pathv, langv);
- filepath_free_strvec(pathv);
+ filepath_free_strvec(pathv);
- return respath;
+ return respath;
}
static void monkey_quit(void)
{
- urldb_save_cookies(nsoption_charp(cookie_jar));
- urldb_save(nsoption_charp(url_file));
- free(nsoption_charp(cookie_file));
- free(nsoption_charp(cookie_jar));
- monkey_fetch_filetype_fin();
-}
-
-static nsurl *gui_get_resource_url(const char *path)
-{
- char buf[PATH_MAX];
- char *raw;
- nsurl *url = NULL;
-
- raw = path_to_url(filepath_sfind(respaths, buf, path));
- if (raw != NULL) {
- nsurl_create(raw, &url);
- free(raw);
- }
-
- return url;
+ urldb_save_cookies(nsoption_charp(cookie_jar));
+ urldb_save(nsoption_charp(url_file));
+ free(nsoption_charp(cookie_file));
+ free(nsoption_charp(cookie_jar));
+ monkey_fetch_filetype_fin();
}
static void
@@ -115,53 +101,6 @@ static bool nslog_stream_configure(FILE *fptr)
return true;
}
-/**
- * Return the filename part of a full path
- *
- * \param path full path and filename
- * \return filename (will be freed with free())
- */
-
-static char *filename_from_path(char *path)
-{
- char *leafname;
-
- leafname = strrchr(path, '/');
- if (!leafname)
- leafname = path;
- else
- leafname += 1;
-
- return strdup(leafname);
-}
-
-/**
- * Add a path component/filename to an existing path
- *
- * \param path buffer containing path + free space
- * \param length length of buffer "path"
- * \param newpart string containing path component to add to path
- * \return true on success
- */
-
-static bool path_add_part(char *path, int length, const char *newpart)
-{
- if(path[strlen(path) - 1] != '/')
- strncat(path, "/", length);
-
- strncat(path, newpart, length);
-
- return true;
-}
-
-static struct gui_fetch_table monkey_fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
- .filetype = monkey_fetch_filetype,
-
- .get_resource_url = gui_get_resource_url,
-};
-
static struct gui_browser_table monkey_browser_table = {
.poll = monkey_poll,
@@ -182,14 +121,14 @@ main(int argc, char **argv)
.browser = &monkey_browser_table,
.window = monkey_window_table,
.download = monkey_download_table,
- .fetch = &monkey_fetch_table,
+ .fetch = monkey_fetch_table,
};
/* Unbuffer stdin/out/err */
setbuf(stdin, NULL);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
-
+
/* Prep the search paths */
respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./monkey/res");
@@ -215,22 +154,22 @@ main(int argc, char **argv)
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
-
+
filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
monkey_fetch_filetype_init(buf);
-
+
urldb_load(nsoption_charp(url_file));
urldb_load_cookies(nsoption_charp(cookie_file));
-
+
monkey_prepare_input();
monkey_register_handler("QUIT", quit_handler);
monkey_register_handler("WINDOW", monkey_window_handle_command);
-
+
fprintf(stdout, "GENERIC STARTED\n");
netsurf_main_loop();
fprintf(stdout, "GENERIC CLOSING_DOWN\n");
monkey_kill_browser_windows();
-
+
netsurf_exit();
fprintf(stdout, "GENERIC FINISHED\n");
diff --git a/monkey/utils.c b/monkey/utils.c
index aa72455..88776a9 100644
--- a/monkey/utils.c
+++ b/monkey/utils.c
@@ -25,50 +25,6 @@
#include "utils/url.h"
#include "utils/utf8.h"
-char *path_to_url(const char *path)
-{
- int urllen;
- char *url;
-
- if (path == NULL) {
- return NULL;
- }
-
- urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
-
- url = malloc(urllen);
- if (url == NULL) {
- return NULL;
- }
-
- 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 *path;
- char *respath;
- url_func_result res; /* result from url routines */
-
- res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- res = url_unescape(path, &respath);
- free(path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- return respath;
-}
void warn_user(const char *warning, const char *detail)
diff --git a/riscos/gui.c b/riscos/gui.c
index 8495dd6..43e2f3a 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -719,6 +719,135 @@ void ro_gui_check_resolvers(void)
}
}
+/**
+ * Convert a RISC OS pathname to a file: URL.
+ *
+ * \param path RISC OS pathname
+ * \return URL, allocated on heap, or 0 on failure
+ */
+
+static char *path_to_url(const char *path)
+{
+ int spare;
+ 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",
+ error->errnum, error->errmess));
+ warn_user("PathToURL", error->errmess);
+ return NULL;
+ }
+
+ canonical_path = malloc(1 - spare);
+ if (canonical_path == NULL) {
+ LOG(("malloc failed"));
+ warn_user("NoMemory", 0);
+ free(canonical_path);
+ return NULL;
+ }
+
+ 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(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);
+
+ /* 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);
+ free(url); url = NULL;
+ if (url_err != URL_FUNC_OK) {
+ LOG(("url_escape failed: %s", url));
+ return NULL;
+ }
+
+ return escurl;
+}
+
+
+/**
+ * Convert a file: URL to a RISC OS pathname.
+ *
+ * \param url a file: URL
+ * \return RISC OS pathname, allocated on heap, or 0 on failure
+ */
+
+static char *url_to_path(const char *url)
+{
+ char *path;
+ char *filename;
+ char *respath;
+ url_func_result res; /* result from url routines */
+ char *r;
+
+ res = url_path(url, &path);
+ if (res != URL_FUNC_OK) {
+ warn_user("NoMemory", 0);
+ return NULL;
+ }
+
+ res = url_unescape(path, &respath);
+ free(path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ /* RISC OS path should not be more than 100 characters longer */
+ filename = malloc(strlen(respath) + 100);
+ if (!filename) {
+ free(respath);
+ warn_user("NoMemory", 0);
+ return NULL;
+ }
+
+ r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX,
+ filename, strlen(respath) + 100, 0);
+
+ free(respath);
+ if (r == 0) {
+ free(filename);
+ LOG(("__riscosify failed"));
+ return NULL;
+ }
+
+ return filename;
+}
/**
* Last-minute gui init, after all other modules have initialised.
@@ -838,7 +967,6 @@ static bool nslog_stream_configure(FILE *fptr)
}
-
/**
* Close down the gui (RISC OS).
*/
@@ -1873,135 +2001,6 @@ void ro_msg_window_info(wimp_message *message)
}
-/**
- * Convert a RISC OS pathname to a file: URL.
- *
- * \param path RISC OS pathname
- * \return URL, allocated on heap, or 0 on failure
- */
-
-char *path_to_url(const char *path)
-{
- int spare;
- 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",
- error->errnum, error->errmess));
- warn_user("PathToURL", error->errmess);
- return NULL;
- }
-
- canonical_path = malloc(1 - spare);
- if (canonical_path == NULL) {
- LOG(("malloc failed"));
- warn_user("NoMemory", 0);
- free(canonical_path);
- return NULL;
- }
-
- 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(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);
-
- /* 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);
- free(url); url = NULL;
- if (url_err != URL_FUNC_OK) {
- LOG(("url_escape failed: %s", url));
- return NULL;
- }
-
- return escurl;
-}
-
-
-/**
- * Convert a file: URL to a RISC OS pathname.
- *
- * \param url a file: URL
- * \return RISC OS pathname, allocated on heap, or 0 on failure
- */
-
-char *url_to_path(const char *url)
-{
- char *path;
- char *filename;
- char *respath;
- url_func_result res; /* result from url routines */
- char *r;
-
- res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
- warn_user("NoMemory", 0);
- return NULL;
- }
-
- res = url_unescape(path, &respath);
- free(path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- /* RISC OS path should not be more than 100 characters longer */
- filename = malloc(strlen(respath) + 100);
- if (!filename) {
- free(respath);
- warn_user("NoMemory", 0);
- return NULL;
- }
-
- r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX,
- filename, strlen(respath) + 100, 0);
-
- free(respath);
- if (r == 0) {
- free(filename);
- LOG(("__riscosify failed"));
- return NULL;
- }
-
- return filename;
-}
/**
@@ -2357,6 +2356,8 @@ static struct gui_fetch_table riscos_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = gui_get_resource_url,
.mimetype = fetch_mimetype,
diff --git a/utils/url.h b/utils/url.h
index 7c716d7..621e62f 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -58,7 +58,4 @@ url_func_result url_escape(const char *unescaped, size_t toskip,
url_func_result url_unescape(const char *str, char **result);
url_func_result url_path(const char *url, char **result);
-char *path_to_url(const char *path);
-char *url_to_path(const char *url);
-
#endif
diff --git a/windows/findfile.h b/windows/findfile.h
index 5f8c729..8a3e719 100644
--- a/windows/findfile.h
+++ b/windows/findfile.h
@@ -23,5 +23,8 @@ extern char *nsws_find_resource(char *buf, const char *filename, const char *def
char **nsws_init_resource(const char *resource_path);
+char *path_to_url(const char *path);
+char *url_to_path(const char *url);
+
#endif /* _NETSURF_WINDOWS_FINDFILE_H_ */
diff --git a/windows/gui.c b/windows/gui.c
index a6b2fac..6ac4f61 100644
--- a/windows/gui.c
+++ b/windows/gui.c
@@ -1882,6 +1882,8 @@ static struct gui_fetch_table fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.mimetype = fetch_mimetype,
};
-----------------------------------------------------------------------
Summary of changes:
amiga/gui.c | 2 +
amiga/misc.h | 4 +
atari/findfile.h | 5 +-
atari/gui.c | 2 +
beos/gui.cpp | 26 ++--
cocoa/BrowserViewController.m | 1 +
cocoa/Makefile.target | 1 -
cocoa/NetsurfApp.m | 1 -
cocoa/fetch.h | 4 +-
cocoa/fetch.m | 61 ++++++++-
cocoa/gui.h | 1 -
cocoa/gui.m | 32 -----
cocoa/url.m | 34 -----
content/fetchers/file.c | 4 +-
desktop/gui.h | 16 +++
desktop/gui_factory.c | 6 +
desktop/searchweb.c | 2 +-
framebuffer/fetch.c | 19 +++-
gtk/Makefile.target | 2 +-
gtk/dialogs/source.c | 17 ++--
gtk/{filetype.c => fetch.c} | 187 ++++++++++++++++++++++------
gtk/{filetype.h => fetch.h} | 12 ++-
gtk/gui.c | 120 +-----------------
gtk/gui.h | 2 +
monkey/Makefile.target | 2 +-
monkey/fetch.c | 145 ++++++++++++++++++++++
{framebuffer => monkey}/fetch.h | 8 +-
monkey/main.c | 107 ++++-------------
monkey/utils.c | 44 -------
riscos/gui.c | 261 ++++++++++++++++++++-------------------
utils/url.h | 3 -
windows/findfile.h | 3 +
windows/gui.c | 2 +
33 files changed, 606 insertions(+), 530 deletions(-)
delete mode 100644 cocoa/url.m
rename gtk/{filetype.c => fetch.c} (59%)
rename gtk/{filetype.h => fetch.h} (79%)
create mode 100644 monkey/fetch.c
copy {framebuffer => monkey}/fetch.h (86%)
diff --git a/amiga/gui.c b/amiga/gui.c
index a9c72c9..074dfaf 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -5189,6 +5189,8 @@ static struct gui_fetch_table amiga_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = gui_get_resource_url,
};
diff --git a/amiga/misc.h b/amiga/misc.h
index 34a85fa..60f249c 100644
--- a/amiga/misc.h
+++ b/amiga/misc.h
@@ -18,6 +18,10 @@
#ifndef AMIGA_MISC_H
#define AMIGA_MISC_H
+
char *translate_escape_chars(const char *s);
int32 ami_warn_user_multi(const char *body, const char *opt1, const char *opt2, struct Window *win);
+char *url_to_path(const char *url);
+char *path_to_url(const char *path);
+
#endif
diff --git a/atari/findfile.h b/atari/findfile.h
index e87f7cf..cced009 100755
--- a/atari/findfile.h
+++ b/atari/findfile.h
@@ -21,6 +21,9 @@
#define NS_ATARI_FINDFILE_H
extern char *atari_find_resource(char *buf, const char *filename, const char *def);
-char * local_file_to_url( const char * filename );
+char *local_file_to_url(const char *filename);
+
+char *path_to_url(const char *path_in);
+char *url_to_path(const char *url);
#endif /* NETSURF_ATARI_FINDFILE_H */
diff --git a/atari/gui.c b/atari/gui.c
index 0267148..f1f557e 100644
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -1077,6 +1077,8 @@ static struct gui_fetch_table atari_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = gui_get_resource_url,
.mimetype = fetch_mimetype,
diff --git a/beos/gui.cpp b/beos/gui.cpp
index ca176c8..05e0637 100644
--- a/beos/gui.cpp
+++ b/beos/gui.cpp
@@ -786,6 +786,17 @@ static void gui_quit(void)
fetch_rsrc_unregister();
}
+static 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;
+}
/**
* Send the source of a content to a text editor.
@@ -983,7 +994,7 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len,
return UTF8_CONVERT_OK;
}
-char *path_to_url(const char *path)
+static char *path_to_url(const char *path)
{
int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
char *url = (char *)malloc(urllen);
@@ -1001,17 +1012,6 @@ char *path_to_url(const char *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;
-}
static void *myrealloc(void *ptr, size_t len, void *pw)
{
@@ -1071,6 +1071,8 @@ static struct gui_fetch_table beos_fetch_table = {
filename_from_path,
path_add_part,
fetch_filetype,
+ path_to_url,
+ url_to_path,
gui_get_resource_url,
NULL //fetch_mimetype
};
diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m
index 77ee57b..956654a 100644
--- a/cocoa/BrowserViewController.m
+++ b/cocoa/BrowserViewController.m
@@ -19,6 +19,7 @@
#import "cocoa/BrowserViewController.h"
#import "cocoa/BrowserView.h"
#import "cocoa/BrowserWindowController.h"
+#import "cocoa/fetch.h"
#import "desktop/browser_private.h"
#import "desktop/local_history.h"
diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target
index 8bd13c2..49f67f0 100644
--- a/cocoa/Makefile.target
+++ b/cocoa/Makefile.target
@@ -95,7 +95,6 @@ S_COCOA := \
schedule.m \
selection.m \
thumbnail.m \
- url.m \
utf8.m \
utils.m \
ArrowBox.m \
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 5643efd..32ad8f1 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -25,7 +25,6 @@
#import "desktop/gui.h"
#import "content/urldb.h"
-#import "content/fetch.h"
#import "css/utils.h"
#import "desktop/gui.h"
#import "desktop/local_history.h"
diff --git a/cocoa/fetch.h b/cocoa/fetch.h
index 4a50b6e..5d2e928 100644
--- a/cocoa/fetch.h
+++ b/cocoa/fetch.h
@@ -16,4 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-const char *fetch_filetype(const char *unix_path);
+extern struct gui_fetch_table *cocoa_fetch_table;
+
+char *url_to_path(const char *url);
diff --git a/cocoa/fetch.m b/cocoa/fetch.m
index b1c7aea..7bf00e0 100644
--- a/cocoa/fetch.m
+++ b/cocoa/fetch.m
@@ -19,7 +19,7 @@
#import <Cocoa/Cocoa.h>
#import "utils/log.h"
-#import "content/fetch.h"
+#import "desktop/gui.h"
#import "cocoa/fetch.h"
@@ -42,9 +42,9 @@ static const struct mimemap_s {
};
-const char *fetch_filetype(const char *unix_path)
+static const char *fetch_filetype(const char *unix_path)
{
- NSString *uti;
+ NSString *uti;
NSString *mimeType = nil;
NSError *utiError = nil;
@@ -58,7 +58,7 @@ const char *fetch_filetype(const char *unix_path)
LOG(("uti call failed"));
- strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype));
+ strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype));
return cocoafiletype;
}
@@ -83,13 +83,60 @@ const char *fetch_filetype(const char *unix_path)
eidx++;
}
- strncpy(cocoafiletype,
- cocoamimemap[eidx].mimetype,
+ strncpy(cocoafiletype,
+ cocoamimemap[eidx].mimetype,
sizeof(cocoafiletype));
}
}
LOG(( "\tMIME type for '%s' is '%s'", unix_path, cocoafiletype ));
-
+
return cocoafiletype;
}
+
+char *url_to_path(const char *url)
+{
+ NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]];
+ return strdup([[nsurl path] UTF8String]);
+}
+
+static char *path_to_url(const char *path)
+{
+ return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]]
+ absoluteString] UTF8String] );
+}
+
+static char *filename_from_path(char *path)
+{
+ return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
+}
+
+static bool path_add_part(char *path, int length, const char *newpart)
+{
+ NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
+
+ strncpy( path, [newPath UTF8String], length );
+
+ return true;
+}
+
+static nsurl *gui_get_resource_url(const char *path)
+{
+ nsurl *url = NULL;
+ NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""];
+ if (nspath == nil) return NULL;
+ nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url);
+ return url;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filename_from_path = filename_from_path,
+ .path_add_part = path_add_part,
+ .filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
+
+ .get_resource_url = gui_get_resource_url,
+};
+
+struct gui_fetch_table *cocoa_fetch_table = &fetch_table;
diff --git a/cocoa/gui.h b/cocoa/gui.h
index 55b6907..7571400 100644
--- a/cocoa/gui.h
+++ b/cocoa/gui.h
@@ -20,7 +20,6 @@
extern struct gui_window_table *cocoa_window_table;
extern struct gui_clipboard_table *cocoa_clipboard_table;
-extern struct gui_fetch_table *cocoa_fetch_table;
extern struct gui_browser_table *cocoa_browser_table;
extern NSString * const kCookiesFileOption;
diff --git a/cocoa/gui.m b/cocoa/gui.m
index 2a97df3..750d9fc 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -46,15 +46,6 @@ NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs";
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
-static nsurl *gui_get_resource_url(const char *path)
-{
- nsurl *url = NULL;
- NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""];
- if (nspath == nil) return NULL;
- nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url);
- return url;
-}
-
static void gui_poll(bool active)
{
cocoa_autorelease();
@@ -273,20 +264,6 @@ static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
cb( false, cbpw );
}
-static char *filename_from_path(char *path)
-{
- return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
-}
-
-static bool path_add_part(char *path, int length, const char *newpart)
-{
- NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
-
- strncpy( path, [newPath UTF8String], length );
-
- return true;
-}
-
static struct gui_window_table window_table = {
.create = gui_window_create,
@@ -312,15 +289,6 @@ static struct gui_window_table window_table = {
struct gui_window_table *cocoa_window_table = &window_table;
-static struct gui_fetch_table fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
- .filetype = fetch_filetype,
-
- .get_resource_url = gui_get_resource_url,
-};
-
-struct gui_fetch_table *cocoa_fetch_table = &fetch_table;
static struct gui_browser_table browser_table = {
.poll = gui_poll,
diff --git a/cocoa/url.m b/cocoa/url.m
deleted file mode 100644
index 931f459..0000000
--- a/cocoa/url.m
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2011 Sven Weidauer <sven.weidauer(a)gmail.com>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#import <Cocoa/Cocoa.h>
-
-#import "utils/url.h"
-
-
-char *url_to_path(const char *url)
-{
- NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]];
- return strdup([[nsurl path] UTF8String]);
-}
-
-char *path_to_url(const char *path)
-{
- return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]]
- absoluteString] UTF8String] );
-}
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index 7b93ab1..00d5cc5 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -142,7 +142,7 @@ fetch_file_setup(struct fetch *fetchh,
if (ctx == NULL)
return NULL;
- ctx->path = url_to_path(nsurl_access(url));
+ ctx->path = guit->fetch->url_to_path(nsurl_access(url));
if (ctx->path == NULL) {
free(ctx);
return NULL;
@@ -600,7 +600,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
}
}
- if((path = path_to_url(urlpath)) == NULL)
+ if((path = guit->fetch->path_to_url(urlpath)) == NULL)
continue;
if (S_ISREG(ent_stat.st_mode)) {
diff --git a/desktop/gui.h b/desktop/gui.h
index 724355d..da609b1 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -319,6 +319,22 @@ struct gui_fetch_table {
*/
const char *(*filetype)(const char *unix_path);
+ /**
+ * Convert a pathname to a file: URL.
+ *
+ * \param path pathname
+ * \return URL, allocated on heap, or NULL on failure
+ */
+ char *(*path_to_url)(const char *path);
+
+ /**
+ * Convert a file: URL to a pathname.
+ *
+ * \param url a file: URL
+ * \return pathname, allocated on heap, or NULL on failure
+ */
+ char *(*url_to_path)(const char *url);
+
/* Optional entries */
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 06b5383..dfe7755 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -317,6 +317,12 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft)
if (gft->filetype == NULL) {
return NSERROR_BAD_PARAMETER;
}
+ if (gft->path_to_url == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+ if (gft->url_to_path == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
/* fill in the optional entries with defaults */
diff --git a/desktop/searchweb.c b/desktop/searchweb.c
index d42919d..b3f6162 100644
--- a/desktop/searchweb.c
+++ b/desktop/searchweb.c
@@ -236,7 +236,7 @@ void search_web_retrieve_ico(bool localdefault)
if (localdefault) {
if (search_default_ico_location == NULL)
return;
- url = path_to_url(search_default_ico_location);
+ url = guit->fetch->path_to_url(search_default_ico_location);
} else {
url = search_web_ico_name();
}
diff --git a/framebuffer/fetch.c b/framebuffer/fetch.c
index 2e304c2..0c9b90f 100644
--- a/framebuffer/fetch.c
+++ b/framebuffer/fetch.c
@@ -68,7 +68,13 @@ static bool path_add_part(char *path, int length, const char *newpart)
return true;
}
-char *path_to_url(const char *path)
+/**
+ * Convert a pathname to a file: URL.
+ *
+ * \param path pathname
+ * \return URL, allocated on heap, or NULL on failure
+ */
+static char *path_to_url(const char *path)
{
int urllen;
char *url;
@@ -88,8 +94,13 @@ char *path_to_url(const char *path)
return url;
}
-
-char *url_to_path(const char *url)
+/**
+ * Convert a file: URL to a pathname.
+ *
+ * \param url a file: URL
+ * \return pathname, allocated on heap, or NULL on failure
+ */
+static char *url_to_path(const char *url)
{
char *path;
char *respath;
@@ -178,6 +189,8 @@ static struct gui_fetch_table fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = get_resource_url,
.mimetype = fetch_mimetype,
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index 426c4af..ec19d1b 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -108,7 +108,7 @@ $(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(
# S_GTK are sources purely for the GTK build
S_GTK := font_pango.c bitmap.c gui.c schedule.c thumbnail.c plotters.c \
treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
- selection.c history.c window.c filetype.c download.c menu.c \
+ selection.c history.c window.c fetch.c download.c menu.c \
print.c search.c tabs.c theme.c toolbar.c gettext.c \
compat.c cookies.c hotlist.c \
$(addprefix dialogs/,preferences.c about.c source.c)
diff --git a/gtk/dialogs/source.c b/gtk/dialogs/source.c
index 5306bdc..a7c9815 100644
--- a/gtk/dialogs/source.c
+++ b/gtk/dialogs/source.c
@@ -23,13 +23,6 @@
#include <unistd.h>
#include <gtk/gtk.h>
-#include "gtk/compat.h"
-#include "gtk/dialogs/source.h"
-#include "gtk/dialogs/about.h"
-#include "gtk/window.h"
-#include "gtk/gui.h"
-#include "gtk/print.h"
-#include "gtk/selection.h"
#include "desktop/browser_private.h"
#include "desktop/netsurf.h"
#include "desktop/print.h"
@@ -42,9 +35,17 @@
#include "render/font.h"
#include "content/content.h"
#include "content/content_type.h"
-
#include "utils/log.h"
+#include "gtk/compat.h"
+#include "gtk/dialogs/source.h"
+#include "gtk/dialogs/about.h"
+#include "gtk/window.h"
+#include "gtk/gui.h"
+#include "gtk/print.h"
+#include "gtk/selection.h"
+#include "gtk/fetch.h"
+
struct nsgtk_source_window {
gchar *url;
char *data;
diff --git a/gtk/filetype.c b/gtk/fetch.c
similarity index 59%
rename from gtk/filetype.c
rename to gtk/fetch.c
index a949b14..f4a42b5 100644
--- a/gtk/filetype.c
+++ b/gtk/fetch.c
@@ -1,6 +1,5 @@
/*
- * Copyright 2007 Rob Kendrick <rjek(a)netsurf-browser.org>
- * Copyright 2007 Vincent Sanders <vince(a)debian.org>
+ * Copyright 2014 vincent Sanders <vince(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -18,18 +17,18 @@
*/
#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#include "gtk/filetype.h"
-#include "content/fetch.h"
-#include "utils/log.h"
#include "utils/hashtable.h"
+#include "utils/url.h"
+#include "utils/log.h"
+#include "utils/filepath.h"
+#include "desktop/gui.h"
+
+#include "gtk/gui.h"
+#include "gtk/fetch.h"
static struct hash_table *mime_hash = NULL;
@@ -43,9 +42,8 @@ void gtk_fetch_filetype_init(const char *mimefile)
/* first, check to see if /etc/mime.types in preference */
if ((stat("/etc/mime.types", &statbuf) == 0) &&
- S_ISREG(statbuf.st_mode)) {
+ S_ISREG(statbuf.st_mode)) {
mimefile = "/etc/mime.types";
-
}
fh = fopen(mimefile, "r");
@@ -75,25 +73,30 @@ void gtk_fetch_filetype_init(const char *mimefile)
while (!feof(fh)) {
char line[256], *ptr, *type, *ext;
+
if (fgets(line, 256, fh) == NULL)
- break;
+ break;
+
if (!feof(fh) && line[0] != '#') {
ptr = line;
/* search for the first non-whitespace character */
- while (isspace(*ptr))
+ while (isspace(*ptr)) {
ptr++;
+ }
/* is this line empty other than leading whitespace? */
- if (*ptr == '\n' || *ptr == '\0')
+ if (*ptr == '\n' || *ptr == '\0') {
continue;
+ }
type = ptr;
/* search for the first non-whitespace char or NUL or
* NL */
- while (*ptr && (!isspace(*ptr)) && *ptr != '\n')
+ while (*ptr && (!isspace(*ptr)) && *ptr != '\n') {
ptr++;
+ }
if (*ptr == '\0' || *ptr == '\n') {
/* this mimetype has no extensions - read next
@@ -106,8 +109,9 @@ void gtk_fetch_filetype_init(const char *mimefile)
/* search for the first non-whitespace character which
* will be the first filename extenion */
- while (isspace(*ptr))
+ while (isspace(*ptr)) {
ptr++;
+ }
while(true) {
ext = ptr;
@@ -115,9 +119,11 @@ void gtk_fetch_filetype_init(const char *mimefile)
/* search for the first whitespace char or
* NUL or NL which is the end of the ext.
*/
- while (*ptr && (!isspace(*ptr)) &&
- *ptr != '\n')
+ while (*ptr &&
+ (!isspace(*ptr)) &&
+ *ptr != '\n') {
ptr++;
+ }
if (*ptr == '\0' || *ptr == '\n') {
/* special case for last extension on
@@ -134,8 +140,11 @@ void gtk_fetch_filetype_init(const char *mimefile)
/* search for the first non-whitespace char or
* NUL or NL, to find start of next ext.
*/
- while (*ptr && (isspace(*ptr)) && *ptr != '\n')
+ while (*ptr &&
+ (isspace(*ptr)) &&
+ *ptr != '\n') {
ptr++;
+ }
}
}
}
@@ -162,8 +171,9 @@ const char *fetch_filetype(const char *unix_path)
return "text/plain";
}
- if (S_ISDIR(statbuf.st_mode))
+ if (S_ISDIR(statbuf.st_mode)) {
return "application/x-netsurf-directory";
+ }
l = strlen(unix_path);
@@ -184,11 +194,13 @@ const char *fetch_filetype(const char *unix_path)
}
ptr = unix_path + strlen(unix_path);
- while (*ptr != '.' && *ptr != '/')
+ while (*ptr != '.' && *ptr != '/') {
ptr--;
+ }
- if (*ptr != '.')
+ if (*ptr != '.') {
return "text/plain";
+ }
ext = strdup(ptr + 1); /* skip the . */
@@ -196,7 +208,7 @@ const char *fetch_filetype(const char *unix_path)
* copy is lower case too.
*/
lowerchar = ext;
- while(*lowerchar) {
+ while (*lowerchar) {
*lowerchar = tolower(*lowerchar);
lowerchar++;
}
@@ -204,31 +216,132 @@ const char *fetch_filetype(const char *unix_path)
type = hash_get(mime_hash, ext);
free(ext);
- return type != NULL ? type : "text/plain";
+ if (type == NULL) {
+ type = "text/plain";
+ }
+
+ return type;
}
-#ifdef TEST_RIG
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+static char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '/');
+ if (!leafname) {
+ leafname = path;
+ } else {
+ leafname += 1;
+ }
+
+ return strdup(leafname);
+}
-int main(int argc, char *argv[])
+/**
+ * Add a path component/filename to an existing path
+ *
+ * \param path buffer containing path + free space
+ * \param length length of buffer "path"
+ * \param newpart string containing path component to add to path
+ * \return true on success
+ */
+static bool path_add_part(char *path, int length, const char *newpart)
{
- unsigned int c1, *c2;
- const char *key;
+ if (path[strlen(path) - 1] != '/') {
+ strncat(path, "/", length);
+ }
- gtk_fetch_filetype_init("./mime.types");
+ strncat(path, newpart, length);
- c1 = 0; c2 = 0;
+ return true;
+}
- while ( (key = hash_iterate(mime_hash, &c1, &c2)) != NULL) {
- printf("%s ", key);
+char *path_to_url(const char *path)
+{
+ int urllen;
+ char *url;
+
+ if (path == NULL) {
+ return NULL;
+ }
+
+ urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
+
+ url = malloc(urllen);
+ if (url == NULL) {
+ return NULL;
+ }
+
+ if (*path == '/') {
+ path++; /* file: paths are already absolute */
}
- printf("\n");
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
+
+ return url;
+}
+
+
+static char *url_to_path(const char *url)
+{
+ char *path;
+ char *respath;
+ url_func_result res; /* result from url routines */
+
+ res = url_path(url, &path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
- if (argc > 1) {
- printf("%s maps to %s\n", argv[1], fetch_filetype(argv[1]));
+ res = url_unescape(path, &respath);
+ free(path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
}
- gtk_fetch_filetype_fin();
+ return respath;
}
-#endif
+static nsurl *gui_get_resource_url(const char *path)
+{
+ char buf[PATH_MAX];
+ char *raw;
+ nsurl *url = NULL;
+
+ /* default.css -> gtkdefault.css */
+ if (strcmp(path, "default.css") == 0) {
+ path = "gtkdefault.css";
+ }
+
+ /* favicon.ico -> favicon.png */
+ if (strcmp(path, "favicon.ico") == 0) {
+ path = "favicon.png";
+ }
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filename_from_path = filename_from_path,
+ .path_add_part = path_add_part,
+ .filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
+
+ .get_resource_url = gui_get_resource_url,
+
+};
+
+struct gui_fetch_table *nsgtk_fetch_table = &fetch_table;
diff --git a/gtk/filetype.h b/gtk/fetch.h
similarity index 79%
rename from gtk/filetype.h
rename to gtk/fetch.h
index 68bb9c0..400a06a 100644
--- a/gtk/filetype.h
+++ b/gtk/fetch.h
@@ -1,6 +1,5 @@
/*
- * Copyright 2007 Rob Kendrick <rjek(a)netsurf-browser.org>
- * Copyright 2007 Vincent Sanders <vince(a)debian.org>
+ * Copyright 2014 Vincent Sanders <vince(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -17,6 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef NETSURF_GTK_FETCH_H
+#define NETSURF_GTK_FETCH_H
+
+struct gui_fetch_table *nsgtk_fetch_table;
+
void gtk_fetch_filetype_init(const char *mimefile);
void gtk_fetch_filetype_fin(void);
const char *fetch_filetype(const char *unix_path);
+
+char *path_to_url(const char *path);
+
+#endif
diff --git a/gtk/gui.c b/gtk/gui.c
index d6d3502..ad80e89 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -60,7 +60,7 @@
#include "gtk/completion.h"
#include "gtk/cookies.h"
#include "gtk/download.h"
-#include "gtk/filetype.h"
+#include "gtk/fetch.h"
#include "gtk/gui.h"
#include "gtk/history.h"
#include "gtk/hotlist.h"
@@ -109,7 +109,7 @@ static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data);
#define THROBBER_FRAMES 9
-static char **respaths; /** resource search path vector */
+char **respaths; /** resource search path vector */
/** Create an array of valid paths to search for resources.
*
@@ -324,28 +324,6 @@ static void check_options(char **respath)
}
-static nsurl *gui_get_resource_url(const char *path)
-{
- char buf[PATH_MAX];
- char *raw;
- nsurl *url = NULL;
-
- /* default.css -> gtkdefault.css */
- if (strcmp(path, "default.css") == 0)
- path = "gtkdefault.css";
-
- /* favicon.ico -> favicon.png */
- if (strcmp(path, "favicon.ico") == 0)
- path = "favicon.png";
-
- raw = path_to_url(filepath_sfind(respaths, buf, path));
- if (raw != NULL) {
- nsurl_create(raw, &url);
- free(raw);
- }
-
- return url;
-}
/**
@@ -842,51 +820,6 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len,
}
-char *path_to_url(const char *path)
-{
- int urllen;
- char *url;
-
- if (path == NULL) {
- return NULL;
- }
-
- urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
-
- url = malloc(urllen);
- if (url == NULL) {
- return NULL;
- }
-
- 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 *path;
- char *respath;
- url_func_result res; /* result from url routines */
-
- res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- res = url_unescape(path, &respath);
- free(path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- return respath;
-}
#ifdef WITH_PDF_EXPORT
@@ -1089,59 +1022,12 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key)
}
}
-/**
- * Return the filename part of a full path
- *
- * \param path full path and filename
- * \return filename (will be freed with free())
- */
-
-static char *filename_from_path(char *path)
-{
- char *leafname;
-
- leafname = strrchr(path, '/');
- if (!leafname)
- leafname = path;
- else
- leafname += 1;
-
- return strdup(leafname);
-}
-
-/**
- * Add a path component/filename to an existing path
- *
- * \param path buffer containing path + free space
- * \param length length of buffer "path"
- * \param newpart string containing path component to add to path
- * \return true on success
- */
-
-static bool path_add_part(char *path, int length, const char *newpart)
-{
- if(path[strlen(path) - 1] != '/')
- strncat(path, "/", length);
-
- strncat(path, newpart, length);
-
- return true;
-}
static struct gui_clipboard_table nsgtk_clipboard_table = {
.get = gui_get_clipboard,
.set = gui_set_clipboard,
};
-static struct gui_fetch_table nsgtk_fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
- .filetype = fetch_filetype,
-
- .get_resource_url = gui_get_resource_url,
-
-};
-
static struct gui_browser_table nsgtk_browser_table = {
.poll = gui_poll,
@@ -1166,7 +1052,7 @@ int main(int argc, char** argv)
.window = nsgtk_window_table,
.clipboard = &nsgtk_clipboard_table,
.download = nsgtk_download_table,
- .fetch = &nsgtk_fetch_table,
+ .fetch = nsgtk_fetch_table,
};
/* check home directory is available */
diff --git a/gtk/gui.h b/gtk/gui.h
index 65a6e07..dc1f2b3 100644
--- a/gtk/gui.h
+++ b/gtk/gui.h
@@ -59,6 +59,8 @@ extern char *themelist_file_location;
extern GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */
+extern char **respaths; /** resource search path vector */
+
uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *);
extern void gui_401login_open(nsurl *url, const char *realm,
diff --git a/monkey/Makefile.target b/monkey/Makefile.target
index 5240754..7c0f167 100644
--- a/monkey/Makefile.target
+++ b/monkey/Makefile.target
@@ -68,7 +68,7 @@ endif
# S_MONKEY are sources purely for the MONKEY build
S_MONKEY := main.c utils.c filetype.c schedule.c \
bitmap.c plot.c browser.c download.c thumbnail.c \
- 401login.c cert.c font.c poll.c dispatch.c
+ 401login.c cert.c font.c poll.c dispatch.c fetch.c
S_MONKEY := $(addprefix monkey/,$(S_MONKEY))
diff --git a/monkey/fetch.c b/monkey/fetch.c
new file mode 100644
index 0000000..668ad0e
--- /dev/null
+++ b/monkey/fetch.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <limits.h>
+
+#include "desktop/gui.h"
+#include "utils/url.h"
+#include "utils/nsurl.h"
+#include "utils/filepath.h"
+
+#include "monkey/filetype.h"
+#include "monkey/fetch.h"
+
+extern char **respaths;
+
+
+static char *path_to_url(const char *path)
+{
+ int urllen;
+ char *url;
+
+ if (path == NULL) {
+ return NULL;
+ }
+
+ urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
+
+ url = malloc(urllen);
+ if (url == NULL) {
+ return NULL;
+ }
+
+ if (*path == '/') {
+ path++; /* file: paths are already absolute */
+ }
+
+ snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path);
+
+ return url;
+}
+
+static char *url_to_path(const char *url)
+{
+ char *path;
+ char *respath;
+ url_func_result res; /* result from url routines */
+
+ res = url_path(url, &path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ res = url_unescape(path, &respath);
+ free(path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ return respath;
+}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+static char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '/');
+ if (!leafname)
+ leafname = path;
+ else
+ leafname += 1;
+
+ return strdup(leafname);
+}
+
+/**
+ * Add a path component/filename to an existing path
+ *
+ * \param path buffer containing path + free space
+ * \param length length of buffer "path"
+ * \param newpart string containing path component to add to path
+ * \return true on success
+ */
+
+static bool path_add_part(char *path, int length, const char *newpart)
+{
+ if(path[strlen(path) - 1] != '/')
+ strncat(path, "/", length);
+
+ strncat(path, newpart, length);
+
+ return true;
+}
+
+static nsurl *gui_get_resource_url(const char *path)
+{
+ char buf[PATH_MAX];
+ char *raw;
+ nsurl *url = NULL;
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
+}
+
+static struct gui_fetch_table fetch_table = {
+ .filename_from_path = filename_from_path,
+ .path_add_part = path_add_part,
+ .filetype = monkey_fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
+
+ .get_resource_url = gui_get_resource_url,
+};
+
+struct gui_fetch_table *monkey_fetch_table = &fetch_table;
diff --git a/framebuffer/fetch.h b/monkey/fetch.h
similarity index 86%
copy from framebuffer/fetch.h
copy to monkey/fetch.h
index 718b083..59e8696 100644
--- a/framebuffer/fetch.h
+++ b/monkey/fetch.h
@@ -16,10 +16,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#ifndef NETSURF_FB_FETCH_H
-#define NETSURF_FB_FETCH_H
-
-struct gui_fetch_table *framebuffer_fetch_table;
-
-#endif
+struct gui_fetch_table *monkey_fetch_table;
diff --git a/monkey/main.c b/monkey/main.c
index 1135f0e..07ce7ee 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -20,13 +20,14 @@
#include <stdio.h>
#include <stdlib.h>
-#include "monkey/filetype.h"
#include "utils/nsoption.h"
#include "monkey/poll.h"
#include "monkey/dispatch.h"
#include "monkey/browser.h"
#include "monkey/cert.h"
#include "monkey/401login.h"
+#include "monkey/filetype.h"
+#include "monkey/fetch.h"
#include "content/urldb.h"
#include "content/fetchers/resource.h"
@@ -36,49 +37,34 @@
#include "utils/filepath.h"
#include "utils/url.h"
-static char **respaths; /** resource search path vector */
+char **respaths; /** resource search path vector */
/* Stolen from gtk/gui.c */
static char **
nsmonkey_init_resource(const char *resource_path)
{
- const gchar * const *langv;
- char **pathv; /* resource path string vector */
- char **respath; /* resource paths vector */
+ const gchar * const *langv;
+ char **pathv; /* resource path string vector */
+ char **respath; /* resource paths vector */
- pathv = filepath_path_to_strvec(resource_path);
+ pathv = filepath_path_to_strvec(resource_path);
- langv = g_get_language_names();
+ langv = g_get_language_names();
- respath = filepath_generate(pathv, langv);
+ respath = filepath_generate(pathv, langv);
- filepath_free_strvec(pathv);
+ filepath_free_strvec(pathv);
- return respath;
+ return respath;
}
static void monkey_quit(void)
{
- urldb_save_cookies(nsoption_charp(cookie_jar));
- urldb_save(nsoption_charp(url_file));
- free(nsoption_charp(cookie_file));
- free(nsoption_charp(cookie_jar));
- monkey_fetch_filetype_fin();
-}
-
-static nsurl *gui_get_resource_url(const char *path)
-{
- char buf[PATH_MAX];
- char *raw;
- nsurl *url = NULL;
-
- raw = path_to_url(filepath_sfind(respaths, buf, path));
- if (raw != NULL) {
- nsurl_create(raw, &url);
- free(raw);
- }
-
- return url;
+ urldb_save_cookies(nsoption_charp(cookie_jar));
+ urldb_save(nsoption_charp(url_file));
+ free(nsoption_charp(cookie_file));
+ free(nsoption_charp(cookie_jar));
+ monkey_fetch_filetype_fin();
}
static void
@@ -115,53 +101,6 @@ static bool nslog_stream_configure(FILE *fptr)
return true;
}
-/**
- * Return the filename part of a full path
- *
- * \param path full path and filename
- * \return filename (will be freed with free())
- */
-
-static char *filename_from_path(char *path)
-{
- char *leafname;
-
- leafname = strrchr(path, '/');
- if (!leafname)
- leafname = path;
- else
- leafname += 1;
-
- return strdup(leafname);
-}
-
-/**
- * Add a path component/filename to an existing path
- *
- * \param path buffer containing path + free space
- * \param length length of buffer "path"
- * \param newpart string containing path component to add to path
- * \return true on success
- */
-
-static bool path_add_part(char *path, int length, const char *newpart)
-{
- if(path[strlen(path) - 1] != '/')
- strncat(path, "/", length);
-
- strncat(path, newpart, length);
-
- return true;
-}
-
-static struct gui_fetch_table monkey_fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
- .filetype = monkey_fetch_filetype,
-
- .get_resource_url = gui_get_resource_url,
-};
-
static struct gui_browser_table monkey_browser_table = {
.poll = monkey_poll,
@@ -182,14 +121,14 @@ main(int argc, char **argv)
.browser = &monkey_browser_table,
.window = monkey_window_table,
.download = monkey_download_table,
- .fetch = &monkey_fetch_table,
+ .fetch = monkey_fetch_table,
};
/* Unbuffer stdin/out/err */
setbuf(stdin, NULL);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
-
+
/* Prep the search paths */
respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./monkey/res");
@@ -215,22 +154,22 @@ main(int argc, char **argv)
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
-
+
filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
monkey_fetch_filetype_init(buf);
-
+
urldb_load(nsoption_charp(url_file));
urldb_load_cookies(nsoption_charp(cookie_file));
-
+
monkey_prepare_input();
monkey_register_handler("QUIT", quit_handler);
monkey_register_handler("WINDOW", monkey_window_handle_command);
-
+
fprintf(stdout, "GENERIC STARTED\n");
netsurf_main_loop();
fprintf(stdout, "GENERIC CLOSING_DOWN\n");
monkey_kill_browser_windows();
-
+
netsurf_exit();
fprintf(stdout, "GENERIC FINISHED\n");
diff --git a/monkey/utils.c b/monkey/utils.c
index aa72455..88776a9 100644
--- a/monkey/utils.c
+++ b/monkey/utils.c
@@ -25,50 +25,6 @@
#include "utils/url.h"
#include "utils/utf8.h"
-char *path_to_url(const char *path)
-{
- int urllen;
- char *url;
-
- if (path == NULL) {
- return NULL;
- }
-
- urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
-
- url = malloc(urllen);
- if (url == NULL) {
- return NULL;
- }
-
- 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 *path;
- char *respath;
- url_func_result res; /* result from url routines */
-
- res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- res = url_unescape(path, &respath);
- free(path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- return respath;
-}
void warn_user(const char *warning, const char *detail)
diff --git a/riscos/gui.c b/riscos/gui.c
index 8495dd6..43e2f3a 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -719,6 +719,135 @@ void ro_gui_check_resolvers(void)
}
}
+/**
+ * Convert a RISC OS pathname to a file: URL.
+ *
+ * \param path RISC OS pathname
+ * \return URL, allocated on heap, or 0 on failure
+ */
+
+static char *path_to_url(const char *path)
+{
+ int spare;
+ 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",
+ error->errnum, error->errmess));
+ warn_user("PathToURL", error->errmess);
+ return NULL;
+ }
+
+ canonical_path = malloc(1 - spare);
+ if (canonical_path == NULL) {
+ LOG(("malloc failed"));
+ warn_user("NoMemory", 0);
+ free(canonical_path);
+ return NULL;
+ }
+
+ 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(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);
+
+ /* 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);
+ free(url); url = NULL;
+ if (url_err != URL_FUNC_OK) {
+ LOG(("url_escape failed: %s", url));
+ return NULL;
+ }
+
+ return escurl;
+}
+
+
+/**
+ * Convert a file: URL to a RISC OS pathname.
+ *
+ * \param url a file: URL
+ * \return RISC OS pathname, allocated on heap, or 0 on failure
+ */
+
+static char *url_to_path(const char *url)
+{
+ char *path;
+ char *filename;
+ char *respath;
+ url_func_result res; /* result from url routines */
+ char *r;
+
+ res = url_path(url, &path);
+ if (res != URL_FUNC_OK) {
+ warn_user("NoMemory", 0);
+ return NULL;
+ }
+
+ res = url_unescape(path, &respath);
+ free(path);
+ if (res != URL_FUNC_OK) {
+ return NULL;
+ }
+
+ /* RISC OS path should not be more than 100 characters longer */
+ filename = malloc(strlen(respath) + 100);
+ if (!filename) {
+ free(respath);
+ warn_user("NoMemory", 0);
+ return NULL;
+ }
+
+ r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX,
+ filename, strlen(respath) + 100, 0);
+
+ free(respath);
+ if (r == 0) {
+ free(filename);
+ LOG(("__riscosify failed"));
+ return NULL;
+ }
+
+ return filename;
+}
/**
* Last-minute gui init, after all other modules have initialised.
@@ -838,7 +967,6 @@ static bool nslog_stream_configure(FILE *fptr)
}
-
/**
* Close down the gui (RISC OS).
*/
@@ -1873,135 +2001,6 @@ void ro_msg_window_info(wimp_message *message)
}
-/**
- * Convert a RISC OS pathname to a file: URL.
- *
- * \param path RISC OS pathname
- * \return URL, allocated on heap, or 0 on failure
- */
-
-char *path_to_url(const char *path)
-{
- int spare;
- 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",
- error->errnum, error->errmess));
- warn_user("PathToURL", error->errmess);
- return NULL;
- }
-
- canonical_path = malloc(1 - spare);
- if (canonical_path == NULL) {
- LOG(("malloc failed"));
- warn_user("NoMemory", 0);
- free(canonical_path);
- return NULL;
- }
-
- 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(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);
-
- /* 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);
- free(url); url = NULL;
- if (url_err != URL_FUNC_OK) {
- LOG(("url_escape failed: %s", url));
- return NULL;
- }
-
- return escurl;
-}
-
-
-/**
- * Convert a file: URL to a RISC OS pathname.
- *
- * \param url a file: URL
- * \return RISC OS pathname, allocated on heap, or 0 on failure
- */
-
-char *url_to_path(const char *url)
-{
- char *path;
- char *filename;
- char *respath;
- url_func_result res; /* result from url routines */
- char *r;
-
- res = url_path(url, &path);
- if (res != URL_FUNC_OK) {
- warn_user("NoMemory", 0);
- return NULL;
- }
-
- res = url_unescape(path, &respath);
- free(path);
- if (res != URL_FUNC_OK) {
- return NULL;
- }
-
- /* RISC OS path should not be more than 100 characters longer */
- filename = malloc(strlen(respath) + 100);
- if (!filename) {
- free(respath);
- warn_user("NoMemory", 0);
- return NULL;
- }
-
- r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX,
- filename, strlen(respath) + 100, 0);
-
- free(respath);
- if (r == 0) {
- free(filename);
- LOG(("__riscosify failed"));
- return NULL;
- }
-
- return filename;
-}
/**
@@ -2357,6 +2356,8 @@ static struct gui_fetch_table riscos_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.get_resource_url = gui_get_resource_url,
.mimetype = fetch_mimetype,
diff --git a/utils/url.h b/utils/url.h
index 7c716d7..621e62f 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -58,7 +58,4 @@ url_func_result url_escape(const char *unescaped, size_t toskip,
url_func_result url_unescape(const char *str, char **result);
url_func_result url_path(const char *url, char **result);
-char *path_to_url(const char *path);
-char *url_to_path(const char *url);
-
#endif
diff --git a/windows/findfile.h b/windows/findfile.h
index 5f8c729..8a3e719 100644
--- a/windows/findfile.h
+++ b/windows/findfile.h
@@ -23,5 +23,8 @@ extern char *nsws_find_resource(char *buf, const char *filename, const char *def
char **nsws_init_resource(const char *resource_path);
+char *path_to_url(const char *path);
+char *url_to_path(const char *url);
+
#endif /* _NETSURF_WINDOWS_FINDFILE_H_ */
diff --git a/windows/gui.c b/windows/gui.c
index a6b2fac..6ac4f61 100644
--- a/windows/gui.c
+++ b/windows/gui.c
@@ -1882,6 +1882,8 @@ static struct gui_fetch_table fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
+ .path_to_url = path_to_url,
+ .url_to_path = url_to_path,
.mimetype = fetch_mimetype,
};
--
NetSurf Browser
9 years
netsurf: branch master updated. release/3.0-997-g46b8fba
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/46b8fbaeac4dd1e35945a...
...commit http://git.netsurf-browser.org/netsurf.git/commit/46b8fbaeac4dd1e35945ae1...
...tree http://git.netsurf-browser.org/netsurf.git/tree/46b8fbaeac4dd1e35945ae133...
The branch, master has been updated
via 46b8fbaeac4dd1e35945ae1338056156e5b3b86b (commit)
from 96e5368d34d960dd1aa71dcac81079f331adfab6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=46b8fbaeac4dd1e3594...
commit 46b8fbaeac4dd1e35945ae1338056156e5b3b86b
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Use corestring.
diff --git a/render/textplain.c b/render/textplain.c
index 892e03e..5254e6a 100644
--- a/render/textplain.c
+++ b/render/textplain.c
@@ -46,6 +46,7 @@
#include "render/textplain.h"
#include "render/html.h"
#include "render/search.h"
+#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
@@ -159,7 +160,6 @@ static const content_handler textplain_content_handler = {
.no_share = true,
};
-static lwc_string *textplain_charset;
static lwc_string *textplain_default_charset;
/**
@@ -170,16 +170,9 @@ nserror textplain_init(void)
lwc_error lerror;
nserror error;
- lerror = lwc_intern_string("charset", SLEN("charset"),
- &textplain_charset);
- if (lerror != lwc_error_ok) {
- return NSERROR_NOMEM;
- }
-
lerror = lwc_intern_string("Windows-1252", SLEN("Windows-1252"),
&textplain_default_charset);
if (lerror != lwc_error_ok) {
- lwc_string_unref(textplain_charset);
return NSERROR_NOMEM;
}
@@ -187,7 +180,6 @@ nserror textplain_init(void)
&textplain_content_handler);
if (error != NSERROR_OK) {
lwc_string_unref(textplain_default_charset);
- lwc_string_unref(textplain_charset);
}
return error;
@@ -202,11 +194,6 @@ void textplain_fini(void)
lwc_string_unref(textplain_default_charset);
textplain_default_charset = NULL;
}
-
- if (textplain_charset != NULL) {
- lwc_string_unref(textplain_charset);
- textplain_charset = NULL;
- }
}
/**
@@ -233,7 +220,7 @@ nserror textplain_create(const content_handler *handler,
return error;
}
- error = http_parameter_list_find_item(params, textplain_charset,
+ error = http_parameter_list_find_item(params, corestring_lwc_charset,
&encoding);
if (error != NSERROR_OK) {
encoding = lwc_string_ref(textplain_default_charset);
-----------------------------------------------------------------------
Summary of changes:
render/textplain.c | 17 ++---------------
1 files changed, 2 insertions(+), 15 deletions(-)
diff --git a/render/textplain.c b/render/textplain.c
index 892e03e..5254e6a 100644
--- a/render/textplain.c
+++ b/render/textplain.c
@@ -46,6 +46,7 @@
#include "render/textplain.h"
#include "render/html.h"
#include "render/search.h"
+#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
@@ -159,7 +160,6 @@ static const content_handler textplain_content_handler = {
.no_share = true,
};
-static lwc_string *textplain_charset;
static lwc_string *textplain_default_charset;
/**
@@ -170,16 +170,9 @@ nserror textplain_init(void)
lwc_error lerror;
nserror error;
- lerror = lwc_intern_string("charset", SLEN("charset"),
- &textplain_charset);
- if (lerror != lwc_error_ok) {
- return NSERROR_NOMEM;
- }
-
lerror = lwc_intern_string("Windows-1252", SLEN("Windows-1252"),
&textplain_default_charset);
if (lerror != lwc_error_ok) {
- lwc_string_unref(textplain_charset);
return NSERROR_NOMEM;
}
@@ -187,7 +180,6 @@ nserror textplain_init(void)
&textplain_content_handler);
if (error != NSERROR_OK) {
lwc_string_unref(textplain_default_charset);
- lwc_string_unref(textplain_charset);
}
return error;
@@ -202,11 +194,6 @@ void textplain_fini(void)
lwc_string_unref(textplain_default_charset);
textplain_default_charset = NULL;
}
-
- if (textplain_charset != NULL) {
- lwc_string_unref(textplain_charset);
- textplain_charset = NULL;
- }
}
/**
@@ -233,7 +220,7 @@ nserror textplain_create(const content_handler *handler,
return error;
}
- error = http_parameter_list_find_item(params, textplain_charset,
+ error = http_parameter_list_find_item(params, corestring_lwc_charset,
&encoding);
if (error != NSERROR_OK) {
encoding = lwc_string_ref(textplain_default_charset);
--
NetSurf Browser
9 years
netsurf: branch master updated. release/3.0-996-g96e5368
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/96e5368d34d960dd1aa71...
...commit http://git.netsurf-browser.org/netsurf.git/commit/96e5368d34d960dd1aa71dc...
...tree http://git.netsurf-browser.org/netsurf.git/tree/96e5368d34d960dd1aa71dcac...
The branch, master has been updated
via 96e5368d34d960dd1aa71dcac81079f331adfab6 (commit)
from ae6874d3088a46a3d02c64ec7e466baaf03a991f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=96e5368d34d960dd1aa...
commit 96e5368d34d960dd1aa71dcac81079f331adfab6
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Use corestring.
diff --git a/desktop/download.c b/desktop/download.c
index 14390c7..b5427b4 100644
--- a/desktop/download.c
+++ b/desktop/download.c
@@ -28,6 +28,7 @@
#include "desktop/download.h"
#include "desktop/gui.h"
#include "desktop/gui_factory.h"
+#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/url.h"
#include "utils/utils.h"
@@ -114,26 +115,18 @@ static nserror download_context_process_headers(download_context *ctx)
http_header = llcache_handle_get_header(ctx->llcache,
"Content-Disposition");
if (http_header != NULL) {
- lwc_string *filename;
lwc_string *filename_value;
http_content_disposition *disposition;
- if (lwc_intern_string("filename", SLEN("filename"),
- &filename) != lwc_error_ok) {
- http_content_type_destroy(content_type);
- return NSERROR_NOMEM;
- }
-
error = http_parse_content_disposition(http_header,
&disposition);
if (error != NSERROR_OK) {
- lwc_string_unref(filename);
http_content_type_destroy(content_type);
return error;
}
error = http_parameter_list_find_item(disposition->parameters,
- filename, &filename_value);
+ corestring_lwc_filename, &filename_value);
if (error == NSERROR_OK) {
ctx->filename = download_parse_filename(
lwc_string_data(filename_value));
@@ -141,7 +134,6 @@ static nserror download_context_process_headers(download_context *ctx)
}
http_content_disposition_destroy(disposition);
- lwc_string_unref(filename);
}
ctx->mime_type = lwc_string_ref(content_type->media_type);
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 47279c3..c51a38f 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -48,6 +48,7 @@ lwc_string *corestring_lwc_default;
lwc_string *corestring_lwc_div;
lwc_string *corestring_lwc_embed;
lwc_string *corestring_lwc_file;
+lwc_string *corestring_lwc_filename;
lwc_string *corestring_lwc_font;
lwc_string *corestring_lwc_frame;
lwc_string *corestring_lwc_frameset;
@@ -302,6 +303,7 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(div);
CSS_LWC_STRING_UNREF(embed);
CSS_LWC_STRING_UNREF(file);
+ CSS_LWC_STRING_UNREF(filename);
CSS_LWC_STRING_UNREF(font);
CSS_LWC_STRING_UNREF(frame);
CSS_LWC_STRING_UNREF(frameset);
@@ -580,6 +582,7 @@ nserror corestrings_init(void)
CSS_LWC_STRING_INTERN(div);
CSS_LWC_STRING_INTERN(embed);
CSS_LWC_STRING_INTERN(file);
+ CSS_LWC_STRING_INTERN(filename);
CSS_LWC_STRING_INTERN(font);
CSS_LWC_STRING_INTERN(frame);
CSS_LWC_STRING_INTERN(frameset);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 78fcd15..1f34ada 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -52,6 +52,7 @@ extern lwc_string *corestring_lwc_default;
extern lwc_string *corestring_lwc_div;
extern lwc_string *corestring_lwc_embed;
extern lwc_string *corestring_lwc_file;
+extern lwc_string *corestring_lwc_filename;
extern lwc_string *corestring_lwc_font;
extern lwc_string *corestring_lwc_frame;
extern lwc_string *corestring_lwc_frameset;
-----------------------------------------------------------------------
Summary of changes:
desktop/download.c | 12 ++----------
utils/corestrings.c | 3 +++
utils/corestrings.h | 1 +
3 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/desktop/download.c b/desktop/download.c
index 14390c7..b5427b4 100644
--- a/desktop/download.c
+++ b/desktop/download.c
@@ -28,6 +28,7 @@
#include "desktop/download.h"
#include "desktop/gui.h"
#include "desktop/gui_factory.h"
+#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/url.h"
#include "utils/utils.h"
@@ -114,26 +115,18 @@ static nserror download_context_process_headers(download_context *ctx)
http_header = llcache_handle_get_header(ctx->llcache,
"Content-Disposition");
if (http_header != NULL) {
- lwc_string *filename;
lwc_string *filename_value;
http_content_disposition *disposition;
- if (lwc_intern_string("filename", SLEN("filename"),
- &filename) != lwc_error_ok) {
- http_content_type_destroy(content_type);
- return NSERROR_NOMEM;
- }
-
error = http_parse_content_disposition(http_header,
&disposition);
if (error != NSERROR_OK) {
- lwc_string_unref(filename);
http_content_type_destroy(content_type);
return error;
}
error = http_parameter_list_find_item(disposition->parameters,
- filename, &filename_value);
+ corestring_lwc_filename, &filename_value);
if (error == NSERROR_OK) {
ctx->filename = download_parse_filename(
lwc_string_data(filename_value));
@@ -141,7 +134,6 @@ static nserror download_context_process_headers(download_context *ctx)
}
http_content_disposition_destroy(disposition);
- lwc_string_unref(filename);
}
ctx->mime_type = lwc_string_ref(content_type->media_type);
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 47279c3..c51a38f 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -48,6 +48,7 @@ lwc_string *corestring_lwc_default;
lwc_string *corestring_lwc_div;
lwc_string *corestring_lwc_embed;
lwc_string *corestring_lwc_file;
+lwc_string *corestring_lwc_filename;
lwc_string *corestring_lwc_font;
lwc_string *corestring_lwc_frame;
lwc_string *corestring_lwc_frameset;
@@ -302,6 +303,7 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(div);
CSS_LWC_STRING_UNREF(embed);
CSS_LWC_STRING_UNREF(file);
+ CSS_LWC_STRING_UNREF(filename);
CSS_LWC_STRING_UNREF(font);
CSS_LWC_STRING_UNREF(frame);
CSS_LWC_STRING_UNREF(frameset);
@@ -580,6 +582,7 @@ nserror corestrings_init(void)
CSS_LWC_STRING_INTERN(div);
CSS_LWC_STRING_INTERN(embed);
CSS_LWC_STRING_INTERN(file);
+ CSS_LWC_STRING_INTERN(filename);
CSS_LWC_STRING_INTERN(font);
CSS_LWC_STRING_INTERN(frame);
CSS_LWC_STRING_INTERN(frameset);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 78fcd15..1f34ada 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -52,6 +52,7 @@ extern lwc_string *corestring_lwc_default;
extern lwc_string *corestring_lwc_div;
extern lwc_string *corestring_lwc_embed;
extern lwc_string *corestring_lwc_file;
+extern lwc_string *corestring_lwc_filename;
extern lwc_string *corestring_lwc_font;
extern lwc_string *corestring_lwc_frame;
extern lwc_string *corestring_lwc_frameset;
--
NetSurf Browser
9 years