2010-03-28 16:56:39 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2009 John-Mark Bell <jmb@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
|
2010-04-08 15:21:50 +04:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-03-28 16:56:39 +04:00
|
|
|
* 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
|
|
|
|
* High-level resource cache (implementation)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-04-04 21:17:24 +04:00
|
|
|
#include "utils/http.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "utils/log.h"
|
2010-04-04 21:17:24 +04:00
|
|
|
#include "utils/messages.h"
|
2010-04-08 15:21:50 +04:00
|
|
|
#include "utils/ring.h"
|
2010-08-10 23:58:39 +04:00
|
|
|
#include "utils/utils.h"
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "desktop/gui_misc.h"
|
|
|
|
#include "desktop/gui_internal.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-05-09 13:15:42 +04:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/mimesniff.h"
|
|
|
|
#include "content/hlcache.h"
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
typedef struct hlcache_entry hlcache_entry;
|
|
|
|
typedef struct hlcache_retrieval_ctx hlcache_retrieval_ctx;
|
|
|
|
|
|
|
|
/** High-level cache retrieval context */
|
|
|
|
struct hlcache_retrieval_ctx {
|
2010-04-08 15:21:50 +04:00
|
|
|
struct hlcache_retrieval_ctx *r_prev; /**< Previous retrieval context in the ring */
|
|
|
|
struct hlcache_retrieval_ctx *r_next; /**< Next retrieval context in the ring */
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
llcache_handle *llcache; /**< Low-level cache handle */
|
|
|
|
|
|
|
|
hlcache_handle *handle; /**< High-level handle for object */
|
2010-03-30 01:17:18 +04:00
|
|
|
|
2010-04-06 01:35:38 +04:00
|
|
|
uint32_t flags; /**< Retrieval flags */
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_type accepted_types; /**< Accepted types */
|
2010-04-04 21:17:24 +04:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
hlcache_child_context child; /**< Child context */
|
2011-12-09 01:58:26 +04:00
|
|
|
|
|
|
|
bool migrate_target; /**< Whether this context is the migration target */
|
2010-03-28 16:56:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/** High-level cache handle */
|
|
|
|
struct hlcache_handle {
|
|
|
|
hlcache_entry *entry; /**< Pointer to cache entry */
|
|
|
|
|
|
|
|
hlcache_handle_callback cb; /**< Client callback */
|
|
|
|
void *pw; /**< Client data */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Entry in high-level cache */
|
|
|
|
struct hlcache_entry {
|
|
|
|
struct content *content; /**< Pointer to associated content */
|
|
|
|
|
|
|
|
hlcache_entry *next; /**< Next sibling */
|
|
|
|
hlcache_entry *prev; /**< Previous sibling */
|
|
|
|
};
|
|
|
|
|
2011-09-10 04:55:39 +04:00
|
|
|
/** Current state of the cache.
|
2011-09-08 16:04:57 +04:00
|
|
|
*
|
|
|
|
* Global state of the cache.
|
|
|
|
*/
|
|
|
|
struct hlcache_s {
|
|
|
|
struct hlcache_parameters params;
|
|
|
|
|
|
|
|
/** List of cached content objects */
|
|
|
|
hlcache_entry *content_list;
|
|
|
|
|
|
|
|
/** Ring of retrieval contexts */
|
|
|
|
hlcache_retrieval_ctx *retrieval_ctx_ring;
|
|
|
|
|
|
|
|
/* statsistics */
|
2011-09-10 04:55:39 +04:00
|
|
|
unsigned int hit_count;
|
|
|
|
unsigned int miss_count;
|
2011-09-08 16:04:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/** high level cache state */
|
|
|
|
static struct hlcache_s *hlcache = NULL;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2010-04-08 15:21:50 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/******************************************************************************
|
2014-01-19 14:51:14 +04:00
|
|
|
* High-level cache internals *
|
2010-03-28 16:56:39 +04:00
|
|
|
******************************************************************************/
|
|
|
|
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/**
|
|
|
|
* Attempt to clean the cache
|
|
|
|
*/
|
|
|
|
static void hlcache_clean(void *ignored)
|
2010-04-27 10:48:09 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
hlcache_entry *entry, *next;
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
for (entry = hlcache->content_list; entry != NULL; entry = next) {
|
|
|
|
next = entry->next;
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (entry->content == NULL)
|
|
|
|
continue;
|
2010-10-29 01:00:07 +04:00
|
|
|
|
2014-11-09 01:08:29 +03:00
|
|
|
if (content__get_status(entry->content) == CONTENT_STATUS_LOADING)
|
2014-01-19 14:51:14 +04:00
|
|
|
continue;
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (content_count_users(entry->content) != 0)
|
|
|
|
continue;
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/** \todo This is over-zealous: all unused contents
|
|
|
|
* will be immediately destroyed. Ideally, we want to
|
|
|
|
* purge all unused contents that are using stale
|
|
|
|
* source data, and enough fresh contents such that
|
|
|
|
* the cache fits in the configured cache size limit.
|
|
|
|
*/
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Remove entry from cache */
|
|
|
|
if (entry->prev == NULL)
|
|
|
|
hlcache->content_list = entry->next;
|
|
|
|
else
|
|
|
|
entry->prev->next = entry->next;
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (entry->next != NULL)
|
|
|
|
entry->next->prev = entry->prev;
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Destroy content */
|
|
|
|
content_destroy(entry->content);
|
2010-04-27 10:48:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Destroy entry */
|
|
|
|
free(entry);
|
2010-04-27 10:48:09 +04:00
|
|
|
}
|
2011-09-08 16:04:57 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Attempt to clean the llcache */
|
2014-05-29 17:00:13 +04:00
|
|
|
llcache_clean(false);
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Re-schedule ourselves */
|
2014-03-08 18:13:27 +04:00
|
|
|
guit->browser->schedule(hlcache->params.bg_clean_time, hlcache_clean, NULL);
|
2010-04-12 00:21:13 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/**
|
|
|
|
* Determine if the specified MIME type is acceptable
|
|
|
|
*
|
|
|
|
* \param mime_type MIME type to consider
|
|
|
|
* \param accepted_types Array of acceptable types, or NULL for any
|
|
|
|
* \param computed_type Pointer to location to receive computed type of object
|
|
|
|
* \return True if the type is acceptable, false otherwise
|
|
|
|
*/
|
|
|
|
static bool hlcache_type_is_acceptable(lwc_string *mime_type,
|
|
|
|
content_type accepted_types, content_type *computed_type)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
content_type type;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
type = content_factory_type_from_mime_type(mime_type);
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
*computed_type = type;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return ((accepted_types & type) != 0);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/**
|
|
|
|
* Veneer between content callback API and hlcache callback API
|
|
|
|
*
|
|
|
|
* \param c Content to emit message for
|
|
|
|
* \param msg Message to emit
|
|
|
|
* \param data Data for message
|
|
|
|
* \param pw Pointer to private data (hlcache_handle)
|
|
|
|
*/
|
|
|
|
static void hlcache_content_callback(struct content *c, content_msg msg,
|
|
|
|
union content_msg_data data, void *pw)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
hlcache_handle *handle = pw;
|
|
|
|
hlcache_event event;
|
|
|
|
nserror error = NSERROR_OK;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
event.type = msg;
|
|
|
|
event.data = data;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (handle->cb != NULL)
|
|
|
|
error = handle->cb(handle, &event, handle->pw);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (error != NSERROR_OK)
|
|
|
|
LOG(("Error in callback: %d", error));
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/**
|
|
|
|
* Find a content for the high-level cache handle
|
|
|
|
*
|
|
|
|
* \param ctx High-level cache retrieval context
|
|
|
|
* \param effective_type Effective MIME type of content
|
|
|
|
* \return NSERROR_OK on success,
|
|
|
|
* NSERROR_NEED_DATA on success where data is needed,
|
|
|
|
* appropriate error otherwise
|
|
|
|
*
|
|
|
|
* \pre handle::state == HLCACHE_HANDLE_NEW
|
|
|
|
* \pre Headers must have been received for associated low-level handle
|
|
|
|
* \post Low-level handle is either released, or associated with new content
|
|
|
|
* \post High-level handle is registered with content
|
|
|
|
*/
|
|
|
|
static nserror hlcache_find_content(hlcache_retrieval_ctx *ctx,
|
|
|
|
lwc_string *effective_type)
|
2010-04-04 16:41:19 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
hlcache_entry *entry;
|
|
|
|
hlcache_event event;
|
|
|
|
nserror error = NSERROR_OK;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Search list of cached contents for a suitable one */
|
|
|
|
for (entry = hlcache->content_list; entry != NULL; entry = entry->next) {
|
|
|
|
hlcache_handle entry_handle = { entry, NULL, NULL };
|
|
|
|
const llcache_handle *entry_llcache;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (entry->content == NULL)
|
|
|
|
continue;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Ignore contents in the error state */
|
|
|
|
if (content_get_status(&entry_handle) == CONTENT_STATUS_ERROR)
|
|
|
|
continue;
|
2010-04-04 16:41:19 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Ensure that content is shareable */
|
|
|
|
if (content_is_shareable(entry->content) == false)
|
|
|
|
continue;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Ensure that quirks mode is acceptable */
|
|
|
|
if (content_matches_quirks(entry->content,
|
|
|
|
ctx->child.quirks) == false)
|
|
|
|
continue;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Ensure that content uses same low-level object as
|
|
|
|
* low-level handle */
|
|
|
|
entry_llcache = content_get_llcache_handle(entry->content);
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (llcache_handle_references_same_object(entry_llcache,
|
|
|
|
ctx->llcache))
|
|
|
|
break;
|
|
|
|
}
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (entry == NULL) {
|
|
|
|
/* No existing entry, so need to create one */
|
|
|
|
entry = malloc(sizeof(hlcache_entry));
|
|
|
|
if (entry == NULL)
|
2010-04-04 16:41:19 +04:00
|
|
|
return NSERROR_NOMEM;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Create content using llhandle */
|
|
|
|
entry->content = content_factory_create_content(ctx->llcache,
|
|
|
|
ctx->child.charset, ctx->child.quirks,
|
|
|
|
effective_type);
|
|
|
|
if (entry->content == NULL) {
|
2010-04-04 16:41:19 +04:00
|
|
|
free(entry);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Insert into cache */
|
2010-04-04 16:41:19 +04:00
|
|
|
entry->prev = NULL;
|
2011-09-08 16:04:57 +04:00
|
|
|
entry->next = hlcache->content_list;
|
|
|
|
if (hlcache->content_list != NULL)
|
|
|
|
hlcache->content_list->prev = entry;
|
|
|
|
hlcache->content_list = entry;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Signal to caller that we created a content */
|
|
|
|
error = NSERROR_NEED_DATA;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
hlcache->miss_count++;
|
|
|
|
} else {
|
|
|
|
/* Found a suitable content: no longer need low-level handle */
|
|
|
|
llcache_handle_release(ctx->llcache);
|
|
|
|
hlcache->hit_count++;
|
|
|
|
}
|
2010-04-04 16:41:19 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Associate handle with content */
|
|
|
|
if (content_add_user(entry->content,
|
|
|
|
hlcache_content_callback, ctx->handle) == false)
|
|
|
|
return NSERROR_NOMEM;
|
2010-04-12 03:02:49 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Associate cache entry with handle */
|
|
|
|
ctx->handle->entry = entry;
|
2010-04-12 03:02:49 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Catch handle up with state of content */
|
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
content_status status = content_get_status(ctx->handle);
|
2011-03-16 01:02:06 +03:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (status == CONTENT_STATUS_LOADING) {
|
|
|
|
event.type = CONTENT_MSG_LOADING;
|
|
|
|
ctx->handle->cb(ctx->handle, &event, ctx->handle->pw);
|
|
|
|
} else if (status == CONTENT_STATUS_READY) {
|
|
|
|
event.type = CONTENT_MSG_LOADING;
|
|
|
|
ctx->handle->cb(ctx->handle, &event, ctx->handle->pw);
|
2011-12-04 18:55:23 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
event.type = CONTENT_MSG_READY;
|
|
|
|
ctx->handle->cb(ctx->handle, &event,
|
|
|
|
ctx->handle->pw);
|
|
|
|
}
|
|
|
|
} else if (status == CONTENT_STATUS_DONE) {
|
|
|
|
event.type = CONTENT_MSG_LOADING;
|
|
|
|
ctx->handle->cb(ctx->handle, &event, ctx->handle->pw);
|
2011-12-04 18:55:23 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
event.type = CONTENT_MSG_READY;
|
|
|
|
ctx->handle->cb(ctx->handle, &event,
|
|
|
|
ctx->handle->pw);
|
|
|
|
}
|
2011-12-04 18:55:23 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
event.type = CONTENT_MSG_DONE;
|
|
|
|
ctx->handle->cb(ctx->handle, &event,
|
|
|
|
ctx->handle->pw);
|
2011-12-04 18:55:23 +04:00
|
|
|
}
|
2014-01-19 14:51:14 +04:00
|
|
|
}
|
2011-12-04 18:55:23 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return error;
|
2011-12-04 18:55:23 +04:00
|
|
|
}
|
|
|
|
|
2010-04-12 00:21:13 +04:00
|
|
|
/**
|
2014-01-19 14:51:14 +04:00
|
|
|
* Migrate a retrieval context into its final destination content
|
|
|
|
*
|
|
|
|
* \param ctx Context to migrate
|
|
|
|
* \param effective_type The effective MIME type of the content, or NULL
|
|
|
|
* \return NSERROR_OK on success,
|
|
|
|
* NSERROR_NEED_DATA on success where data is needed,
|
|
|
|
* appropriate error otherwise
|
2010-04-12 00:21:13 +04:00
|
|
|
*/
|
2014-01-19 14:51:14 +04:00
|
|
|
static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx,
|
|
|
|
lwc_string *effective_type)
|
2010-04-12 00:21:13 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
content_type type = CONTENT_NONE;
|
|
|
|
nserror error = NSERROR_OK;
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
ctx->migrate_target = true;
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
if ((effective_type != NULL) &&
|
|
|
|
hlcache_type_is_acceptable(effective_type,
|
|
|
|
ctx->accepted_types,
|
|
|
|
&type)) {
|
2014-01-19 14:51:14 +04:00
|
|
|
error = hlcache_find_content(ctx, effective_type);
|
|
|
|
if (error != NSERROR_OK && error != NSERROR_NEED_DATA) {
|
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
hlcache_event hlevent;
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
hlevent.type = CONTENT_MSG_ERROR;
|
|
|
|
hlevent.data.error = messages_get("MiscError");
|
2011-03-04 00:13:58 +03:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
ctx->handle->cb(ctx->handle, &hlevent,
|
|
|
|
ctx->handle->pw);
|
|
|
|
}
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
llcache_handle_abort(ctx->llcache);
|
|
|
|
llcache_handle_release(ctx->llcache);
|
|
|
|
}
|
|
|
|
} else if (type == CONTENT_NONE &&
|
|
|
|
(ctx->flags & HLCACHE_RETRIEVE_MAY_DOWNLOAD)) {
|
|
|
|
/* Unknown type, and we can download, so convert */
|
|
|
|
llcache_handle_force_stream(ctx->llcache);
|
|
|
|
|
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
hlcache_event hlevent;
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
hlevent.type = CONTENT_MSG_DOWNLOAD;
|
|
|
|
hlevent.data.download = ctx->llcache;
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
ctx->handle->cb(ctx->handle, &hlevent,
|
|
|
|
ctx->handle->pw);
|
|
|
|
}
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Ensure caller knows we need data */
|
|
|
|
error = NSERROR_NEED_DATA;
|
|
|
|
} else {
|
|
|
|
/* Unacceptable type: report error */
|
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
hlcache_event hlevent;
|
2010-04-12 00:21:13 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
hlevent.type = CONTENT_MSG_ERROR;
|
|
|
|
hlevent.data.error = messages_get("UnacceptableType");
|
|
|
|
|
|
|
|
ctx->handle->cb(ctx->handle, &hlevent,
|
|
|
|
ctx->handle->pw);
|
|
|
|
}
|
|
|
|
|
|
|
|
llcache_handle_abort(ctx->llcache);
|
|
|
|
llcache_handle_release(ctx->llcache);
|
2010-04-12 00:21:13 +04:00
|
|
|
}
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
ctx->migrate_target = false;
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* No longer require retrieval context */
|
|
|
|
RING_REMOVE(hlcache->retrieval_ctx_ring, ctx);
|
|
|
|
free((char *) ctx->child.charset);
|
|
|
|
free(ctx);
|
|
|
|
|
|
|
|
return error;
|
2010-04-12 00:21:13 +04:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
|
|
|
* Handler for low-level cache events
|
|
|
|
*
|
|
|
|
* \param handle Handle for which event is issued
|
2010-04-08 15:21:50 +04:00
|
|
|
* \param event Event data
|
|
|
|
* \param pw Pointer to client-specific data
|
2010-03-28 16:56:39 +04:00
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
2014-01-19 14:51:14 +04:00
|
|
|
static nserror hlcache_llcache_callback(llcache_handle *handle,
|
2010-03-28 16:56:39 +04:00
|
|
|
const llcache_event *event, void *pw)
|
|
|
|
{
|
|
|
|
hlcache_retrieval_ctx *ctx = pw;
|
2011-09-04 10:28:09 +04:00
|
|
|
lwc_string *effective_type = NULL;
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror error;
|
|
|
|
|
|
|
|
assert(ctx->llcache == handle);
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case LLCACHE_EVENT_HAD_HEADERS:
|
2011-09-04 10:28:09 +04:00
|
|
|
error = mimesniff_compute_effective_type(handle, NULL, 0,
|
2011-09-10 04:55:39 +04:00
|
|
|
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
|
2012-02-08 04:52:16 +04:00
|
|
|
ctx->accepted_types == CONTENT_IMAGE,
|
2011-09-04 10:28:09 +04:00
|
|
|
&effective_type);
|
|
|
|
if (error == NSERROR_OK || error == NSERROR_NOT_FOUND) {
|
2011-09-10 04:55:39 +04:00
|
|
|
/* If the sniffer was successful or failed to find
|
|
|
|
* a Content-Type header when sniffing was
|
2011-09-04 10:28:09 +04:00
|
|
|
* prohibited, we must migrate the retrieval context. */
|
|
|
|
error = hlcache_migrate_ctx(ctx, effective_type);
|
|
|
|
|
|
|
|
if (effective_type != NULL)
|
|
|
|
lwc_string_unref(effective_type);
|
|
|
|
}
|
2010-04-06 01:35:38 +04:00
|
|
|
|
2011-09-10 04:55:39 +04:00
|
|
|
/* No need to report that we need data:
|
2011-09-04 10:28:09 +04:00
|
|
|
* we'll get some anyway if there is any */
|
|
|
|
if (error == NSERROR_NEED_DATA)
|
|
|
|
error = NSERROR_OK;
|
2010-04-06 01:35:38 +04:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
return error;
|
2010-04-06 01:35:38 +04:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
break;
|
|
|
|
case LLCACHE_EVENT_HAD_DATA:
|
2011-09-10 04:55:39 +04:00
|
|
|
error = mimesniff_compute_effective_type(handle,
|
2011-09-04 10:28:09 +04:00
|
|
|
event->data.data.buf, event->data.data.len,
|
|
|
|
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
|
2012-02-08 04:52:16 +04:00
|
|
|
ctx->accepted_types == CONTENT_IMAGE,
|
2011-09-04 10:28:09 +04:00
|
|
|
&effective_type);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
assert(0 && "MIME sniff failed with data");
|
|
|
|
}
|
2010-04-04 21:17:24 +04:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
error = hlcache_migrate_ctx(ctx, effective_type);
|
2010-04-04 21:17:24 +04:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
lwc_string_unref(effective_type);
|
2010-04-04 21:17:24 +04:00
|
|
|
|
2011-09-04 10:28:09 +04:00
|
|
|
return error;
|
2010-04-04 21:17:24 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
break;
|
|
|
|
case LLCACHE_EVENT_DONE:
|
2011-09-04 10:28:09 +04:00
|
|
|
/* DONE event before we could determine the effective MIME type.
|
|
|
|
*/
|
2011-09-08 12:26:16 +04:00
|
|
|
error = mimesniff_compute_effective_type(handle,
|
2012-02-08 04:52:16 +04:00
|
|
|
NULL, 0, false, false, &effective_type);
|
2011-09-08 12:26:16 +04:00
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
error = hlcache_migrate_ctx(ctx, effective_type);
|
|
|
|
|
|
|
|
lwc_string_unref(effective_type);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
hlcache_event hlevent;
|
|
|
|
|
|
|
|
hlevent.type = CONTENT_MSG_ERROR;
|
|
|
|
hlevent.data.error = messages_get("BadType");
|
|
|
|
|
|
|
|
ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw);
|
|
|
|
}
|
|
|
|
break;
|
2010-03-28 16:56:39 +04:00
|
|
|
case LLCACHE_EVENT_ERROR:
|
2010-03-31 01:36:39 +04:00
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
hlcache_event hlevent;
|
|
|
|
|
|
|
|
hlevent.type = CONTENT_MSG_ERROR;
|
|
|
|
hlevent.data.error = event->data.msg;
|
|
|
|
|
|
|
|
ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw);
|
2011-09-10 04:55:39 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
break;
|
|
|
|
case LLCACHE_EVENT_PROGRESS:
|
|
|
|
break;
|
2013-05-27 17:51:00 +04:00
|
|
|
case LLCACHE_EVENT_REDIRECT:
|
|
|
|
if (ctx->handle->cb != NULL) {
|
|
|
|
hlcache_event hlevent;
|
|
|
|
|
|
|
|
hlevent.type = CONTENT_MSG_REDIRECT;
|
|
|
|
hlevent.data.redirect.from = event->data.redirect.from;
|
|
|
|
hlevent.data.redirect.to = event->data.redirect.to;
|
|
|
|
|
|
|
|
ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw);
|
|
|
|
}
|
|
|
|
break;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Public API *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
nserror
|
|
|
|
hlcache_initialise(const struct hlcache_parameters *hlcache_parameters)
|
2011-09-04 10:28:09 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
nserror ret;
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
hlcache = calloc(1, sizeof(struct hlcache_s));
|
|
|
|
if (hlcache == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
2011-12-09 01:58:26 +04:00
|
|
|
|
2014-03-22 18:54:51 +04:00
|
|
|
ret = llcache_initialise(&hlcache_parameters->llcache);
|
2014-01-19 14:51:14 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
free(hlcache);
|
|
|
|
hlcache = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
hlcache->params = *hlcache_parameters;
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Schedule the cache cleanup */
|
2014-03-08 18:13:27 +04:00
|
|
|
guit->browser->schedule(hlcache->params.bg_clean_time, hlcache_clean, NULL);
|
2011-09-10 04:55:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
void hlcache_stop(void)
|
|
|
|
{
|
|
|
|
/* Remove the hlcache_clean schedule */
|
2014-03-08 18:13:27 +04:00
|
|
|
guit->browser->schedule(-1, hlcache_clean, NULL);
|
2014-01-19 14:51:14 +04:00
|
|
|
}
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
void hlcache_finalise(void)
|
|
|
|
{
|
|
|
|
uint32_t num_contents, prev_contents;
|
|
|
|
hlcache_entry *entry;
|
|
|
|
hlcache_retrieval_ctx *ctx, *next;
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Obtain initial count of contents remaining */
|
|
|
|
for (num_contents = 0, entry = hlcache->content_list;
|
|
|
|
entry != NULL; entry = entry->next) {
|
|
|
|
num_contents++;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("%d contents remain before cache drain", num_contents));
|
|
|
|
|
|
|
|
/* Drain cache */
|
|
|
|
do {
|
|
|
|
prev_contents = num_contents;
|
|
|
|
|
|
|
|
hlcache_clean(NULL);
|
|
|
|
|
|
|
|
for (num_contents = 0, entry = hlcache->content_list;
|
|
|
|
entry != NULL; entry = entry->next) {
|
|
|
|
num_contents++;
|
2011-09-04 10:28:09 +04:00
|
|
|
}
|
2014-01-19 14:51:14 +04:00
|
|
|
} while (num_contents > 0 && num_contents != prev_contents);
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
LOG(("%d contents remaining:", num_contents));
|
|
|
|
for (entry = hlcache->content_list; entry != NULL; entry = entry->next) {
|
|
|
|
hlcache_handle entry_handle = { entry, NULL, NULL };
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (entry->content != NULL) {
|
|
|
|
LOG((" %p : %s (%d users)", entry,
|
|
|
|
nsurl_access(
|
|
|
|
hlcache_handle_get_url(&entry_handle)),
|
|
|
|
content_count_users(entry->content)));
|
|
|
|
} else {
|
|
|
|
LOG((" %p", entry));
|
|
|
|
}
|
|
|
|
}
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* Clean up retrieval contexts */
|
|
|
|
if (hlcache->retrieval_ctx_ring != NULL) {
|
|
|
|
ctx = hlcache->retrieval_ctx_ring;
|
|
|
|
|
|
|
|
do {
|
|
|
|
next = ctx->r_next;
|
|
|
|
|
|
|
|
if (ctx->llcache != NULL)
|
|
|
|
llcache_handle_release(ctx->llcache);
|
|
|
|
|
|
|
|
if (ctx->handle != NULL)
|
|
|
|
free(ctx->handle);
|
|
|
|
|
|
|
|
if (ctx->child.charset != NULL)
|
|
|
|
free((char *) ctx->child.charset);
|
|
|
|
|
|
|
|
free(ctx);
|
|
|
|
|
|
|
|
ctx = next;
|
|
|
|
} while (ctx != hlcache->retrieval_ctx_ring);
|
|
|
|
|
|
|
|
hlcache->retrieval_ctx_ring = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("hit/miss %d/%d", hlcache->hit_count, hlcache->miss_count));
|
|
|
|
|
|
|
|
free(hlcache);
|
|
|
|
hlcache = NULL;
|
|
|
|
|
|
|
|
LOG(("Finalising low-level cache"));
|
|
|
|
llcache_finalise();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags,
|
|
|
|
nsurl *referer, llcache_post_data *post,
|
|
|
|
hlcache_handle_callback cb, void *pw,
|
|
|
|
hlcache_child_context *child,
|
|
|
|
content_type accepted_types, hlcache_handle **result)
|
|
|
|
{
|
|
|
|
hlcache_retrieval_ctx *ctx;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
assert(cb != NULL);
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(hlcache_retrieval_ctx));
|
|
|
|
if (ctx == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
ctx->handle = calloc(1, sizeof(hlcache_handle));
|
|
|
|
if (ctx->handle == NULL) {
|
|
|
|
free(ctx);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child != NULL) {
|
|
|
|
if (child->charset != NULL) {
|
|
|
|
ctx->child.charset = strdup(child->charset);
|
|
|
|
if (ctx->child.charset == NULL) {
|
|
|
|
free(ctx->handle);
|
|
|
|
free(ctx);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
2011-09-04 10:28:09 +04:00
|
|
|
}
|
2014-01-19 14:51:14 +04:00
|
|
|
ctx->child.quirks = child->quirks;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->flags = flags;
|
|
|
|
ctx->accepted_types = accepted_types;
|
|
|
|
|
|
|
|
ctx->handle->cb = cb;
|
|
|
|
ctx->handle->pw = pw;
|
|
|
|
|
|
|
|
error = llcache_handle_retrieve(url, flags, referer, post,
|
|
|
|
hlcache_llcache_callback, ctx,
|
|
|
|
&ctx->llcache);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
free((char *) ctx->child.charset);
|
|
|
|
free(ctx->handle);
|
|
|
|
free(ctx);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
RING_INSERT(hlcache->retrieval_ctx_ring, ctx);
|
|
|
|
|
|
|
|
*result = ctx->handle;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2011-12-07 00:47:15 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
nserror hlcache_handle_release(hlcache_handle *handle)
|
|
|
|
{
|
|
|
|
if (handle->entry != NULL) {
|
|
|
|
content_remove_user(handle->entry->content,
|
|
|
|
hlcache_content_callback, handle);
|
|
|
|
} else {
|
|
|
|
RING_ITERATE_START(struct hlcache_retrieval_ctx,
|
|
|
|
hlcache->retrieval_ctx_ring,
|
|
|
|
ictx) {
|
|
|
|
if (ictx->handle == handle &&
|
|
|
|
ictx->migrate_target == false) {
|
|
|
|
/* This is the nascent context for us,
|
|
|
|
* so abort the fetch */
|
|
|
|
llcache_handle_abort(ictx->llcache);
|
|
|
|
llcache_handle_release(ictx->llcache);
|
|
|
|
/* Remove us from the ring */
|
|
|
|
RING_REMOVE(hlcache->retrieval_ctx_ring, ictx);
|
|
|
|
/* Throw us away */
|
|
|
|
free((char *) ictx->child.charset);
|
|
|
|
free(ictx);
|
|
|
|
/* And stop */
|
|
|
|
RING_ITERATE_STOP(hlcache->retrieval_ctx_ring,
|
|
|
|
ictx);
|
|
|
|
}
|
|
|
|
} RING_ITERATE_END(hlcache->retrieval_ctx_ring, ictx);
|
2011-09-04 10:28:09 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
handle->cb = NULL;
|
|
|
|
handle->pw = NULL;
|
2011-12-09 01:58:26 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
free(handle);
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return NSERROR_OK;
|
2011-09-04 10:28:09 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
struct content *hlcache_handle_get_content(const hlcache_handle *handle)
|
2010-04-04 21:17:24 +04:00
|
|
|
{
|
2014-11-06 02:44:31 +03:00
|
|
|
if ((handle != NULL) && (handle->entry != NULL)) {
|
2014-01-19 14:51:14 +04:00
|
|
|
return handle->entry->content;
|
2014-11-06 02:44:31 +03:00
|
|
|
}
|
2010-04-06 01:35:38 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return NULL;
|
2010-04-04 21:17:24 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
nserror hlcache_handle_abort(hlcache_handle *handle)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
struct hlcache_entry *entry = handle->entry;
|
|
|
|
struct content *c;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (entry == NULL) {
|
|
|
|
/* This handle is not yet associated with a cache entry.
|
|
|
|
* The implication is that the fetch for the handle has
|
|
|
|
* not progressed to the point where the entry can be
|
|
|
|
* created. */
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
RING_ITERATE_START(struct hlcache_retrieval_ctx,
|
|
|
|
hlcache->retrieval_ctx_ring,
|
|
|
|
ictx) {
|
|
|
|
if (ictx->handle == handle &&
|
|
|
|
ictx->migrate_target == false) {
|
|
|
|
/* This is the nascent context for us,
|
|
|
|
* so abort the fetch */
|
|
|
|
llcache_handle_abort(ictx->llcache);
|
|
|
|
llcache_handle_release(ictx->llcache);
|
|
|
|
/* Remove us from the ring */
|
|
|
|
RING_REMOVE(hlcache->retrieval_ctx_ring, ictx);
|
|
|
|
/* Throw us away */
|
|
|
|
free((char *) ictx->child.charset);
|
|
|
|
free(ictx);
|
|
|
|
/* And stop */
|
|
|
|
RING_ITERATE_STOP(hlcache->retrieval_ctx_ring,
|
|
|
|
ictx);
|
|
|
|
}
|
|
|
|
} RING_ITERATE_END(hlcache->retrieval_ctx_ring, ictx);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2010-04-08 11:09:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
c = entry->content;
|
2010-04-11 20:37:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (content_count_users(c) > 1) {
|
|
|
|
/* We are not the only user of 'c' so clone it. */
|
|
|
|
struct content *clone = content_clone(c);
|
2010-04-11 20:34:23 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (clone == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
entry = calloc(sizeof(struct hlcache_entry), 1);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (entry == NULL) {
|
|
|
|
content_destroy(clone);
|
2010-03-28 16:56:39 +04:00
|
|
|
return NSERROR_NOMEM;
|
2014-01-19 14:51:14 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (content_add_user(clone,
|
|
|
|
hlcache_content_callback, handle) == false) {
|
|
|
|
content_destroy(clone);
|
2010-03-28 16:56:39 +04:00
|
|
|
free(entry);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
content_remove_user(c, hlcache_content_callback, handle);
|
|
|
|
|
|
|
|
entry->content = clone;
|
|
|
|
handle->entry = entry;
|
2010-03-28 16:56:39 +04:00
|
|
|
entry->prev = NULL;
|
2011-09-08 16:04:57 +04:00
|
|
|
entry->next = hlcache->content_list;
|
|
|
|
if (hlcache->content_list != NULL)
|
|
|
|
hlcache->content_list->prev = entry;
|
|
|
|
hlcache->content_list = entry;
|
2011-09-04 10:28:09 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
c = clone;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return content_abort(c);
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
nserror hlcache_handle_replace_callback(hlcache_handle *handle,
|
|
|
|
hlcache_handle_callback cb, void *pw)
|
|
|
|
{
|
|
|
|
handle->cb = cb;
|
|
|
|
handle->pw = pw;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
nserror hlcache_handle_clone(hlcache_handle *handle, hlcache_handle **result)
|
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
return NSERROR_CLONE_FAILED;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* See hlcache.h for documentation */
|
|
|
|
nsurl *hlcache_handle_get_url(const hlcache_handle *handle)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2014-01-19 14:51:14 +04:00
|
|
|
nsurl *result = NULL;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
assert(handle != NULL);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
if (handle->entry != NULL) {
|
|
|
|
result = content_get_url(handle->entry->content);
|
|
|
|
} else {
|
|
|
|
RING_ITERATE_START(struct hlcache_retrieval_ctx,
|
|
|
|
hlcache->retrieval_ctx_ring,
|
|
|
|
ictx) {
|
|
|
|
if (ictx->handle == handle) {
|
|
|
|
/* This is the nascent context for us */
|
|
|
|
result = llcache_handle_get_url(ictx->llcache);
|
2010-04-04 16:41:19 +04:00
|
|
|
|
2014-01-19 14:51:14 +04:00
|
|
|
/* And stop */
|
|
|
|
RING_ITERATE_STOP(hlcache->retrieval_ctx_ring,
|
|
|
|
ictx);
|
|
|
|
}
|
|
|
|
} RING_ITERATE_END(hlcache->retrieval_ctx_ring, ictx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|