summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/gui.h33
-rw-r--r--desktop/gui_factory.c35
-rw-r--r--desktop/save_complete.c78
3 files changed, 81 insertions, 65 deletions
diff --git a/desktop/gui.h b/desktop/gui.h
index 5f4ba1cdb..0d4135a93 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -68,6 +68,7 @@ struct ssl_cert_info;
struct hlcache_handle;
struct download_context;
struct nsurl;
+struct gui_file_table;
typedef struct nsnsclipboard_styles {
size_t start; /**< Start of run */
@@ -318,28 +319,6 @@ struct gui_fetch_table {
/* Mandantory entries */
/**
- * Return the filename part of a full path
- *
- * @note used in curl fetcher
- *
- * \param path full path and filename
- * \return filename (will be freed with free())
- */
- char *(*filename_from_path)(char *path);
-
- /**
- * Add a path component/filename to an existing path
- *
- * @note used in save complete and file fetcher
- *
- * \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
- */
- bool (*path_add_part)(char *path, int length, const char *newpart);
-
- /**
* Determine the MIME type of a local file.
*
* @note used in file fetcher
@@ -398,6 +377,7 @@ struct gui_fetch_table {
};
+
/**
* User interface utf8 characterset conversion routines.
*/
@@ -568,6 +548,15 @@ struct gui_table {
struct gui_fetch_table *fetch;
/**
+ * File table
+ *
+ * Provides file and filename operations to the core. The
+ * table is optional and may be NULL in which case the default
+ * posix compliant operations will be used.
+ */
+ struct gui_file_table *file;
+
+ /**
* UTF8 table.
*
* Provides for conversion between the gui local character
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index ecedf417b..8e3ce178d 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -19,6 +19,7 @@
#include "content/hlcache.h"
#include "desktop/download.h"
#include "desktop/gui_factory.h"
+#include "utils/file.h"
/** The global GUI interface table */
struct gui_table *guit = NULL;
@@ -418,12 +419,6 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft)
}
/* check the mandantory fields are set */
- if (gft->filename_from_path == NULL) {
- return NSERROR_BAD_PARAMETER;
- }
- if (gft->path_add_part == NULL) {
- return NSERROR_BAD_PARAMETER;
- }
if (gft->filetype == NULL) {
return NSERROR_BAD_PARAMETER;
}
@@ -446,6 +441,25 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft)
return NSERROR_OK;
}
+/** verify file table is valid */
+static nserror verify_file_register(struct gui_file_table *gft)
+{
+ /* check table is present */
+ if (gft == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* check the mandantory fields are set */
+ if (gft->mkpath == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+ if (gft->basename == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ return NSERROR_OK;
+}
+
static void gui_default_quit(void)
{
}
@@ -559,6 +573,15 @@ nserror gui_factory_register(struct gui_table *gt)
return err;
}
+ /* file table */
+ if (gt->file == NULL) {
+ gt->file = default_file_table;
+ }
+ err = verify_file_register(gt->file);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
/* download table */
if (gt->download == NULL) {
/* set default download table */
diff --git a/desktop/save_complete.c b/desktop/save_complete.c
index 99b1ac4b7..782e35841 100644
--- a/desktop/save_complete.c
+++ b/desktop/save_complete.c
@@ -21,8 +21,6 @@
* Save HTML document with dependencies (implementation).
*/
-#include "utils/config.h"
-
#include <assert.h>
#include <ctype.h>
#include <errno.h>
@@ -30,21 +28,23 @@
#include <string.h>
#include <sys/types.h>
#include <regex.h>
-
#include <dom/dom.h>
-#include "content/content.h"
-#include "content/hlcache.h"
-#include "css/css.h"
-#include "desktop/save_complete.h"
-#include "desktop/gui_factory.h"
-#include "render/box.h"
-#include "render/html.h"
+#include "utils/config.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "utils/utf8.h"
#include "utils/utils.h"
+#include "utils/file.h"
+#include "content/content.h"
+#include "content/hlcache.h"
+#include "css/css.h"
+#include "render/box.h"
+#include "render/html.h"
+
+#include "desktop/gui_factory.h"
+#include "desktop/save_complete.h"
regex_t save_complete_import_re;
@@ -143,19 +143,19 @@ static bool save_complete_save_buffer(save_complete_ctx *ctx,
const char *leafname, const char *data, size_t data_len,
lwc_string *mime_type)
{
+ nserror ret;
FILE *fp;
- bool error;
- char fullpath[PATH_MAX];
+ char *fname = NULL;
- strncpy(fullpath, ctx->path, sizeof fullpath);
- error = guit->fetch->path_add_part(fullpath, sizeof fullpath, leafname);
- if (error == false) {
- warn_user("NoMemory", NULL);
+ ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, leafname);
+ if (ret != NSERROR_OK) {
+ warn_user("NoMemory", 0);
return false;
}
- fp = fopen(fullpath, "wb");
+ fp = fopen(fname, "wb");
if (fp == NULL) {
+ free(fname);
LOG(("fopen(): errno = %i", errno));
warn_user("SaveError", strerror(errno));
return false;
@@ -165,8 +165,10 @@ static bool save_complete_save_buffer(save_complete_ctx *ctx,
fclose(fp);
- if (ctx->set_type != NULL)
- ctx->set_type(fullpath, mime_type);
+ if (ctx->set_type != NULL) {
+ ctx->set_type(fname, mime_type);
+ }
+ free(fname);
return true;
}
@@ -1034,29 +1036,30 @@ static bool save_complete_node_handler(dom_node *node,
static bool save_complete_save_html_document(save_complete_ctx *ctx,
hlcache_handle *c, bool index)
{
- bool error;
+ nserror ret;
FILE *fp;
+ char *fname = NULL;
dom_document *doc;
lwc_string *mime_type;
char filename[32];
- char fullpath[PATH_MAX];
- strncpy(fullpath, ctx->path, sizeof fullpath);
-
- if (index)
+ if (index) {
snprintf(filename, sizeof filename, "index");
- else
+ } else {
snprintf(filename, sizeof filename, "%p", c);
+ }
- error = guit->fetch->path_add_part(fullpath, sizeof fullpath, filename);
- if (error == false) {
+ ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, filename);
+ if (ret != NSERROR_OK) {
warn_user("NoMemory", NULL);
return false;
}
- fp = fopen(fullpath, "wb");
+ fp = fopen(fname, "wb");
if (fp == NULL) {
- warn_user("NoMemory", NULL);
+ free(fname);
+ LOG(("fopen(): errno = %i", errno));
+ warn_user("SaveError", strerror(errno));
return false;
}
@@ -1068,6 +1071,7 @@ static bool save_complete_save_html_document(save_complete_ctx *ctx,
if (save_complete_libdom_treewalk((dom_node *) doc,
save_complete_node_handler, ctx) == false) {
+ free(fname);
warn_user("NoMemory", 0);
fclose(fp);
return false;
@@ -1078,10 +1082,11 @@ static bool save_complete_save_html_document(save_complete_ctx *ctx,
mime_type = content_get_mime_type(c);
if (mime_type != NULL) {
if (ctx->set_type != NULL)
- ctx->set_type(fullpath, mime_type);
+ ctx->set_type(fname, mime_type);
lwc_string_unref(mime_type);
}
+ free(fname);
return true;
}
@@ -1119,19 +1124,18 @@ static bool save_complete_save_html(save_complete_ctx *ctx, hlcache_handle *c,
static bool save_complete_inventory(save_complete_ctx *ctx)
{
+ nserror ret;
FILE *fp;
- bool error;
+ char *fname = NULL;
save_complete_entry *entry;
- char fullpath[PATH_MAX];
- strncpy(fullpath, ctx->path, sizeof fullpath);
- error = guit->fetch->path_add_part(fullpath, sizeof fullpath, "Inventory");
- if (error == false) {
- warn_user("NoMemory", NULL);
+ ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, "Inventory");
+ if (ret != NSERROR_OK) {
return false;
}
- fp = fopen(fullpath, "w");
+ fp = fopen(fname, "w");
+ free(fname);
if (fp == NULL) {
LOG(("fopen(): errno = %i", errno));
warn_user("SaveError", strerror(errno));