summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/Makefile4
-rw-r--r--content/backing_store.h100
-rw-r--r--content/no_backing_store.c68
-rw-r--r--desktop/gui.h11
-rw-r--r--desktop/gui_factory.c41
5 files changed, 220 insertions, 4 deletions
diff --git a/content/Makefile b/content/Makefile
index 557e6c787..6482f30a8 100644
--- a/content/Makefile
+++ b/content/Makefile
@@ -1,6 +1,6 @@
# Content sources
S_CONTENT := content.c content_factory.c dirlist.c fetch.c hlcache.c \
- llcache.c mimesniff.c urldb.c
+ llcache.c mimesniff.c urldb.c no_backing_store.c
-S_CONTENT := $(addprefix content/,$(S_CONTENT)) \ No newline at end of file
+S_CONTENT := $(addprefix content/,$(S_CONTENT))
diff --git a/content/backing_store.h b/content/backing_store.h
new file mode 100644
index 000000000..849e11aeb
--- /dev/null
+++ b/content/backing_store.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince@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/>.
+ */
+
+/** \file
+ * Low-level source data cache backing store interface
+ */
+
+#ifndef NETSURF_CONTENT_LLCACHE_PRIVATE_H_
+#define NETSURF_CONTENT_LLCACHE_PRIVATE_H_
+
+#include "content/llcache.h"
+
+/** storage control flags */
+enum backing_store_flags {
+ BACKING_STORE_NONE = 0, /**< no special processing */
+ BACKING_STORE_META = 1, /**< data is metadata */
+ BACKING_STORE_MMAP = 2, /**< when data is retrived this indicates the
+ * returned buffer may be memory mapped,
+ * flag must be cleared if the storage is
+ * allocated and is not memory mapped.
+ */
+};
+
+/** low level cache backing store operation table
+ *
+ * The low level cache (source objects) has the capability to make
+ * objects and their metadata (headers etc) persistant by writing to a
+ * backing store using these operations.
+ */
+struct gui_llcache_table {
+ /**
+ * Initialise the backing store.
+ *
+ * @param parameters to configure backing store.
+ * @return NSERROR_OK on success or error code on faliure.
+ */
+ nserror (*initialise)(const struct llcache_store_parameters *parameters);
+
+ /**
+ * Finalise the backing store.
+ *
+ * @return NSERROR_OK on success or error code on faliure.
+ */
+ nserror (*finalise)(void);
+
+ /**
+ * Place an object in the backing store.
+ *
+ * @param url The url is used as the unique primary key for the data.
+ * @param flags The flags to control how the obejct is stored.
+ * @param data The objects data.
+ * @param datalen The length of the \a data.
+ * @return NSERROR_OK on success or error code on faliure.
+ */
+ nserror (*store)(struct nsurl *url, enum backing_store_flags flags,
+ const uint8_t *data, const size_t datalen);
+
+ /**
+ * Retrive an object from the backing store.
+ *
+ * @param url The url is used as the unique primary key for the data.
+ * @param flags The flags to control how the object is retrived.
+ * @param data The objects data.
+ * @param datalen The length of the \a data retrieved.
+ * @return NSERROR_OK on success or error code on faliure.
+ */
+ nserror (*fetch)(struct nsurl *url, enum backing_store_flags *flags,
+ uint8_t **data, size_t *datalen);
+
+ /**
+ * Invalidate a source object from the backing store.
+ *
+ * The entry (if present in the backing store) must no longer
+ * be returned as a result to the fetch or meta operations.
+ *
+ * @param url The url is used as the unique primary key to invalidate.
+ * @return NSERROR_OK on success or error code on faliure.
+ */
+ nserror (*invalidate)(struct nsurl *url);
+};
+
+extern struct gui_llcache_table* null_llcache_table;
+extern struct gui_llcache_table* filesystem_llcache_table;
+
+#endif
diff --git a/content/no_backing_store.c b/content/no_backing_store.c
new file mode 100644
index 000000000..192101522
--- /dev/null
+++ b/content/no_backing_store.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2014 Vincent Sanders <vince@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/>.
+ */
+
+/** \file
+ * Low-level resource cache null persistant storage implementation.
+ */
+
+#include "utils/nsurl.h"
+
+#include "content/backing_store.h"
+
+
+/* default to disabled backing store */
+static nserror initialise(const struct llcache_store_parameters *parameters)
+{
+ return NSERROR_OK;
+}
+
+static nserror finalise(void)
+{
+ return NSERROR_OK;
+}
+
+static nserror store(nsurl *url,
+ enum backing_store_flags flags,
+ const uint8_t *data,
+ const size_t datalen)
+{
+ return NSERROR_SAVE_FAILED;
+}
+
+static nserror fetch(nsurl *url,
+ enum backing_store_flags *flags,
+ uint8_t **data_out,
+ size_t *datalen_out)
+{
+ return NSERROR_NOT_FOUND;
+}
+
+static nserror invalidate(nsurl *url)
+{
+ return NSERROR_NOT_FOUND;
+}
+
+static struct gui_llcache_table llcache_table = {
+ .initialise = initialise,
+ .finalise = finalise,
+ .store = store,
+ .fetch = fetch,
+ .invalidate = invalidate,
+};
+
+struct gui_llcache_table *null_llcache_table = &llcache_table;
diff --git a/desktop/gui.h b/desktop/gui.h
index c0a5a4e21..24838c9df 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -69,6 +69,7 @@ struct hlcache_handle;
struct download_context;
struct nsurl;
struct gui_file_table;
+struct gui_llcache_table;
typedef struct nsnsclipboard_styles {
size_t start; /**< Start of run */
@@ -520,7 +521,6 @@ struct gui_browser_table {
};
-
/**
* NetSurf operation function table
*
@@ -572,6 +572,15 @@ struct netsurf_table {
* Provides routines for the interactive text search on a page.
*/
struct gui_search_table *search;
+
+ /**
+ * Low level cache table.
+ *
+ * Used by the low level cache to push objects to persistant
+ * storage. The table is optional and may be NULL which
+ * uses the default implementation.
+ */
+ struct gui_llcache_table *llcache;
};
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 756f5dd0e..45d9516fa 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -17,6 +17,8 @@
*/
#include "content/hlcache.h"
+#include "content/backing_store.h"
+
#include "desktop/download.h"
#include "desktop/gui_factory.h"
#include "utils/file.h"
@@ -25,7 +27,6 @@
struct netsurf_table *guit = NULL;
-
static void gui_default_window_set_title(struct gui_window *g, const char *title)
{
}
@@ -400,6 +401,34 @@ static nserror verify_search_register(struct gui_search_table *gst)
return NSERROR_OK;
}
+/** verify low level cache persistant backing store table is valid */
+static nserror verify_llcache_register(struct gui_llcache_table *glt)
+{
+ /* check table is present */
+ if (glt == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* mandantory operations */
+ if (glt->store == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+ if (glt->fetch == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+ if (glt->invalidate == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+ if (glt->initialise == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+ if (glt->finalise == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ return NSERROR_OK;
+}
+
static nsurl *gui_default_get_resource_url(const char *path)
{
return NULL;
@@ -622,6 +651,16 @@ nserror gui_factory_register(struct netsurf_table *gt)
return err;
}
+ /* llcache table */
+ if (gt->llcache == NULL) {
+ /* set default backing store table */
+ gt->llcache = null_llcache_table;
+ }
+ err = verify_llcache_register(gt->llcache);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
guit = gt;
return NSERROR_OK;