From e9b89f776db705ee4403a2235ec21aabab12c8f6 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 17 Jun 2015 09:26:05 +0100 Subject: Allow the resource scheme to provide data directly. This allows front ends to provide resources from compiled in data instead of requiring the resources to be available on disc and forcing a redirect. --- desktop/gui_factory.c | 16 ++++++++++++++++ desktop/gui_fetch.h | 31 +++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'desktop') diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 50244e334..22364ab97 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -501,6 +501,16 @@ static nsurl *gui_default_get_resource_url(const char *path) return NULL; } +static nserror gui_default_get_resource_data(const char *path, const uint8_t **data, size_t *data_len) +{ + return NSERROR_NOT_FOUND; +} + +static nserror gui_default_release_resource_data(const uint8_t *data) +{ + return NSERROR_OK; +} + static char *gui_default_mimetype(const char *path) { return strdup(guit->fetch->filetype(path)); @@ -523,6 +533,12 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft) if (gft->get_resource_url == NULL) { gft->get_resource_url = gui_default_get_resource_url; } + if (gft->get_resource_data == NULL) { + gft->get_resource_data = gui_default_get_resource_data; + } + if (gft->release_resource_data == NULL) { + gft->release_resource_data = gui_default_release_resource_data; + } if (gft->mimetype == NULL) { gft->mimetype = gui_default_mimetype; } diff --git a/desktop/gui_fetch.h b/desktop/gui_fetch.h index 46d31e0f4..20db39d20 100644 --- a/desktop/gui_fetch.h +++ b/desktop/gui_fetch.h @@ -47,9 +47,9 @@ struct gui_fetch_table { /* Optional entries */ /** - * Callback to translate resource to full url. + * Translate resource to full url. * - * @note used in resource fetcher + * @note Only used in resource fetcher * * Transforms a resource: path into a full URL. The returned URL * is used as the target for a redirect. The caller takes ownership of @@ -61,6 +61,33 @@ struct gui_fetch_table { */ struct nsurl* (*get_resource_url)(const char *path); + /** + * Translate resource to source data. + * + * @note Only used in resource fetcher + * + * Obtains the data for a resource directly + * + * \param path The path of the resource to locate. + * \param data Pointer to recive data into + * \param data_len Pointer to length of returned data + * \return NSERROR_OK and the data and length values updated + * else appropriate error code. + */ + nserror (*get_resource_data)(const char *path, const uint8_t **data, size_t *data_len); + + /** + * Releases source data. + * + * @note Only used in resource fetcher + * + * Releases source data obtained from get_resource_data() + * + * \param data The value returned from a previous get_resource_data call + * \return NSERROR_OK on success else appropriate error code. + */ + nserror (*release_resource_data)(const uint8_t *data); + /** * Find a MIME type for a local file * -- cgit v1.2.3