summaryrefslogtreecommitdiff
path: root/desktop/gui_factory.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-05-07 16:14:18 +0100
committerVincent Sanders <vince@kyllikki.org>2014-05-07 16:24:51 +0100
commitc56642819eed87431dff3446fe111f7f3eefaa7d (patch)
tree397126ca4baac425f9c1c44f3d5c56c681e2c4fe /desktop/gui_factory.c
parentc1e2da80dfa62793ea107cf12408c814e268a54b (diff)
downloadnetsurf-c56642819eed87431dff3446fe111f7f3eefaa7d.tar.gz
netsurf-c56642819eed87431dff3446fe111f7f3eefaa7d.tar.bz2
add file operations table and make all frontends use it.
This rationalises the path construction and basename file operations. The default implementation is POSIX which works for all frontends except windows, riscos and amiga which have differeing path separators and rules. These implementations are significantly more robust than the previous nine implementations and also do not use unsafe strncpy or buffers with arbitrary length limits. These implementations also carry full documentation comments.
Diffstat (limited to 'desktop/gui_factory.c')
-rw-r--r--desktop/gui_factory.c35
1 files changed, 29 insertions, 6 deletions
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 */