NetSurf
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
llcache.c File Reference

Low-level resource cache implementation. More...

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <nsutils/time.h>
#include <nsutils/base64.h>
#include "netsurf/inttypes.h"
#include "utils/config.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/nsurl.h"
#include "utils/utils.h"
#include "utils/time.h"
#include "utils/http.h"
#include "utils/nsoption.h"
#include "netsurf/misc.h"
#include "desktop/gui_internal.h"
#include "content/fetch.h"
#include "content/backing_store.h"
#include "content/urldb.h"
Include dependency graph for llcache.c:

Go to the source code of this file.

Data Structures

struct  llcache_handle
 Handle to low-level cache object. More...
 
struct  llcache_object_user
 Low-level cache object user record. More...
 
struct  llcache_fetch_ctx
 Low-level cache object fetch context. More...
 
struct  llcache_cache_control
 Cache control data. More...
 
struct  llcache_header
 Representation of a fetch header. More...
 
struct  llcache_object
 Low-level cache object. More...
 
struct  llcache_s
 Core llcache control context. More...
 

Macros

#define INVALID_AGE   -1
 Cache control value for invalid age. More...
 
#define REDIRECT_LIMIT   10
 
#define MAX_PERSIST_PER_RUN   128
 

Typedefs

typedef struct llcache_object llcache_object
 Type of low-level cache object. More...
 
typedef struct llcache_object_user llcache_object_user
 Low-level cache object user record. More...
 

Enumerations

enum  llcache_fetch_state { LLCACHE_FETCH_INIT , LLCACHE_FETCH_HEADERS , LLCACHE_FETCH_DATA , LLCACHE_FETCH_COMPLETE }
 State of a low-level cache object fetch. More...
 
enum  llcache_validate { LLCACHE_VALIDATE_FRESH , LLCACHE_VALIDATE_ALWAYS , LLCACHE_VALIDATE_ONCE }
 Validation control. More...
 
enum  llcache_store_state { LLCACHE_STATE_RAM = 0 , LLCACHE_STATE_DISC }
 Current status of an object's data. More...
 

Functions

static void llcache_fetch_callback (const fetch_msg *msg, void *p)
 Handler for fetch events. More...
 
static void llcache_users_not_caught_up (void)
 Ask for llcache_catch_up_all_users to be scheduled ASAP to pump the user state machines. More...
 
static nserror llcache_object_user_new (llcache_handle_callback cb, void *pw, llcache_object_user **user)
 Create a new object user. More...
 
static nserror llcache_object_user_destroy (llcache_object_user *user)
 Destroy an object user. More...
 
static nserror llcache_object_remove_user (llcache_object *object, llcache_object_user *user)
 Remove a user from a low-level cache object. More...
 
static nserror llcache_send_event_to_users (llcache_object *object, llcache_event *event)
 Iterate the users of an object, calling their callbacks. More...
 
static nserror llcache_object_new (nsurl *url, llcache_object **result)
 Create a new low-level cache object. More...
 
static nserror llcache_post_data_clone (const llcache_post_data *orig, llcache_post_data **clone)
 Clone a POST data object. More...
 
static nserror llcache_fetch_split_header (const uint8_t *data, size_t len, char **name, char **value)
 Split a fetch header into name and value. More...
 
static nserror llcache_fetch_parse_cache_control (llcache_object *object, char *value)
 parse cache control header value More...
 
static nserror llcache_fetch_header_cache_control (llcache_object *object, char *name, char *value)
 Update cache control from appropriate header. More...
 
static void llcache_destroy_headers (llcache_object *object)
 Destroy headers. More...
 
static void llcache_invalidate_cache_control_data (llcache_object *object)
 Invalidate cache control data. More...
 
static nserror llcache_fetch_process_header (llcache_object *object, const uint8_t *data, size_t len)
 Process a fetch header. More...
 
static nserror get_referer_header (nsurl *url, nsurl *referer, char **header_out)
 construct a Referer header appropriate for the request More...
 
static nserror llcache_object_refetch (llcache_object *object)
 (Re)fetch an object More...
 
static nserror llcache_object_fetch (llcache_object *object, uint32_t flags, nsurl *referer, const llcache_post_data *post, uint32_t redirect_count, bool hsts_in_use)
 Kick-off a fetch for an object. More...
 
static nserror llcache_object_destroy (llcache_object *object)
 Destroy a low-level cache object. More...
 
static nserror llcache_object_add_to_list (llcache_object *object, llcache_object **list)
 Add a low-level cache object to a cache list. More...
 
static int llcache_object_rfc2616_remaining_lifetime (const llcache_cache_control *cd)
 Determine the remaining lifetime of a cache object using the. More...
 
static bool llcache_object_is_fresh (const llcache_object *object)
 Determine if an object is still fresh. More...
 
static nserror llcache_object_clone_cache_data (llcache_object *source, llcache_object *destination, bool deep)
 Clone an object's cache data. More...
 
static nserror llcache_object_remove_from_list (llcache_object *object, llcache_object **list)
 Remove a low-level cache object from a cache list. More...
 
static nserror llcache_retrieve_persisted_data (llcache_object *object)
 Retrieve source data for an object from persistent store if necessary. More...
 
static nserror llcache_serialise_metadata (llcache_object *object, uint8_t **data_out, size_t *datasize_out)
 Generate a serialised version of an object's metadata. More...
 
static nserror llcache_process_metadata (llcache_object *object)
 Deserialisation of an object's metadata. More...
 
static bool llcache__scheme_is_persistable (const nsurl *url)
 Check whether a scheme is persistable. More...
 
static bool llcache__scheme_is_cachable (const nsurl *url)
 Check whether a scheme is cachable. More...
 
static nserror llcache_object_fetch_persistent (llcache_object *object, uint32_t flags, nsurl *referer, const llcache_post_data *post, uint32_t redirect_count)
 Attempt to retrieve an object from persistent storage. More...
 
static nserror llcache_object_retrieve_from_cache (nsurl *url, uint32_t flags, nsurl *referer, const llcache_post_data *post, uint32_t redirect_count, bool hsts_in_use, llcache_object **result)
 Retrieve a potentially cached object. More...
 
static nserror llcache_object_retrieve (nsurl *url, uint32_t flags, nsurl *referer, const llcache_post_data *post, uint32_t redirect_count, bool hsts_in_use, llcache_object **result)
 Retrieve an object from the cache, fetching it if necessary. More...
 
static nserror llcache_object_add_user (llcache_object *object, llcache_object_user *user)
 Add a user to a low-level cache object. More...
 
static nserror llcache_hsts_transform_url (nsurl *url, nsurl **result, bool *hsts_in_use)
 Transform a request-URI based on HSTS policy. More...
 
static nserror llcache_hsts_update_policy (llcache_object *object)
 Update HSTS policy for target domain. More...
 
static nserror llcache_fetch_redirect (llcache_object *object, const char *target, llcache_object **replacement)
 Handle FETCH_REDIRECT event. More...
 
static nserror llcache_object_cache_update (llcache_object *object)
 Update an object's cache state. More...
 
static nserror llcache_fetch_notmodified (llcache_object *object, llcache_object **replacement)
 Handle FETCH_NOTMODIFIED event. More...
 
static nserror llcache_fetch_process_data (llcache_object *object, const uint8_t *data, size_t len)
 Process a chunk of fetched data. More...
 
static nserror llcache_fetch_auth (llcache_object *object, const char *realm)
 Handle an authentication request. More...
 
static nserror llcache_fetch_cert_error (llcache_object *object)
 Handle a TLS certificate verification failure. More...
 
static nserror llcache_fetch_ssl_error (llcache_object *object)
 Handle a TLS connection setup failure. More...
 
static nserror llcache_fetch_timeout (llcache_object *object)
 handle time out while trying to fetch. More...
 
static nserror build_candidate_list (struct llcache_object ***lst_out, int *lst_len_out)
 Construct a sorted list of objects available for writeout operation. More...
 
static nserror write_backing_store (struct llcache_object *object, size_t *written_out, unsigned long *elapsed)
 Write an object to the backing store. More...
 
static void llcache_persist_slowcheck (void *p)
 Check for overall write performance. More...
 
static void llcache_persist (void *p)
 Possibly write objects data to backing store. More...
 
static llcache_object_userllcache_object_find_user (const llcache_handle *handle)
 Find a user of a low-level cache object. More...
 
static bool llcache_object_in_list (const llcache_object *object, const llcache_object *list)
 Determine if a low-level cache object resides in a given list. More...
 
static nserror llcache_object_notify_users (llcache_object *object)
 Notify users of an object's current state. More...
 
static nserror llcache_object_snapshot (llcache_object *object, llcache_object **snapshot)
 Make a snapshot of the current state of an llcache_object. More...
 
static uint32_t total_object_size (llcache_object *object)
 total ram usage of object More...
 
static void llcache_catch_up_all_users (void *ignored)
 Catch up the cache users with state changes from fetchers. More...
 
void llcache_clean (bool purge)
 Cause the low-level cache to attempt to perform cleanup. More...
 
nserror llcache_initialise (const struct llcache_parameters *prm)
 Initialise the low-level cache. More...
 
void llcache_finalise (void)
 Finalise the low-level cache. More...
 
nserror llcache_handle_retrieve (nsurl *url, uint32_t flags, nsurl *referer, const llcache_post_data *post, llcache_handle_callback cb, void *pw, llcache_handle **result)
 Retrieve a handle for a low-level cache object. More...
 
nserror llcache_handle_change_callback (llcache_handle *handle, llcache_handle_callback cb, void *pw)
 Change the callback associated with a low-level cache handle. More...
 
nserror llcache_handle_release (llcache_handle *handle)
 Release a low-level cache handle. More...
 
nserror llcache_handle_clone (llcache_handle *handle, llcache_handle **result)
 Clone a low-level cache handle, producing a new handle to the same fetch/content. More...
 
nserror llcache_handle_abort (llcache_handle *handle)
 Abort a low-level fetch, informing all users of this action. More...
 
nserror llcache_handle_force_stream (llcache_handle *handle)
 Force a low-level cache handle into streaming mode. More...
 
nserror llcache_handle_invalidate_cache_data (llcache_handle *handle)
 Invalidate cache data for a low-level cache object. More...
 
nsurlllcache_handle_get_url (const llcache_handle *handle)
 Retrieve the post-redirect URL of a low-level cache object. More...
 
const uint8_t * llcache_handle_get_source_data (const llcache_handle *handle, size_t *size)
 Retrieve source data of a low-level cache object. More...
 
const char * llcache_handle_get_header (const llcache_handle *handle, const char *key)
 Retrieve a header value associated with a low-level cache object. More...
 
bool llcache_handle_references_same_object (const llcache_handle *a, const llcache_handle *b)
 Determine if the same underlying object is referenced by the given handles. More...
 

Variables

static struct llcache_sllcache = NULL
 low level cache state More...
 

Detailed Description

Low-level resource cache implementation.

This is the implementation of the low level cache. This cache stores source objects in memory and may use a persistent backing store to extend their lifetime.

Todo:
fix writeout conditions and ordering.
Todo:
instrument and (auto)tune

Definition in file llcache.c.

Macro Definition Documentation

◆ INVALID_AGE

#define INVALID_AGE   -1

Cache control value for invalid age.

Definition at line 136 of file llcache.c.

◆ MAX_PERSIST_PER_RUN

#define MAX_PERSIST_PER_RUN   128

◆ REDIRECT_LIMIT

#define REDIRECT_LIMIT   10

Typedef Documentation

◆ llcache_object

Type of low-level cache object.

Definition at line 71 of file llcache.c.

◆ llcache_object_user

Low-level cache object user record.

Enumeration Type Documentation

◆ llcache_fetch_state

State of a low-level cache object fetch.

Enumerator
LLCACHE_FETCH_INIT 

Initial state, before fetch.

LLCACHE_FETCH_HEADERS 

Fetching headers.

LLCACHE_FETCH_DATA 

Fetching object data.

LLCACHE_FETCH_COMPLETE 

Fetch completed.

Definition at line 61 of file llcache.c.

◆ llcache_store_state

Current status of an object's data.

Enumerator
LLCACHE_STATE_RAM 

source data is stored in RAM only

LLCACHE_STATE_DISC 

source data is stored on disc

Definition at line 159 of file llcache.c.

◆ llcache_validate

Validation control.

Enumerator
LLCACHE_VALIDATE_FRESH 

Only revalidate if not fresh.

LLCACHE_VALIDATE_ALWAYS 

Always revalidate.

LLCACHE_VALIDATE_ONCE 

Revalidate once only.

Definition at line 127 of file llcache.c.

Function Documentation

◆ build_candidate_list()

static nserror build_candidate_list ( struct llcache_object ***  lst_out,
int *  lst_len_out 
)
static

Construct a sorted list of objects available for writeout operation.

The list contains fresh cacheable objects held in RAM with no pending fetches. Any objects with a remaining lifetime less than the configured minimum lifetime are simply not considered, they will become stale before pushing to backing store is worth the cost.

Todo:
calculate useful cost metrics to improve sorting.
Parameters
[out]lst_outlist of candidate objects.
[out]lst_len_outNumber of candidate objects in result.
Returns
NSERROR_OK with lst_out and lst_len_out updated or error code.
Todo:
sort list here

Definition at line 2775 of file llcache.c.

References llcache_object::cache, llcache_s::cached_objects, llcache_object::candidate_count, llcache_fetch_ctx::fetch, llcache_object::fetch, llcache, llcache__scheme_is_persistable(), llcache_object_rfc2616_remaining_lifetime(), LLCACHE_STATE_RAM, MAX_PERSIST_PER_RUN, llcache_s::minimum_lifetime, llcache_object::next, NSERROR_NOMEM, NSERROR_NOT_FOUND, NSERROR_OK, llcache_object::store_state, and llcache_object::url.

Referenced by llcache_persist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_referer_header()

static nserror get_referer_header ( nsurl url,
nsurl referer,
char **  header_out 
)
static

construct a Referer header appropriate for the request

Parameters
urlThe url being navigated to
refererThe referring url
header_outA pointer to receive the header. The buffer must be freed by the caller.
Returns
NSERROR_OK and header_out updated on success else error code

Definition at line 819 of file llcache.c.

References NSERROR_BAD_URL, NSERROR_INVALID, NSERROR_NOMEM, NSERROR_OK, nsoption_bool, nsurl_access(), nsurl_get_component(), nsurl_length(), NSURL_SCHEME, and SLEN.

Referenced by llcache_object_refetch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache__scheme_is_cachable()

static bool llcache__scheme_is_cachable ( const nsurl url)
inlinestatic

Check whether a scheme is cachable.

Parameters
urlURL to check.
Returns
true iff url has a cachable scheme.

Definition at line 1810 of file llcache.c.

References nsurl_get_component(), and NSURL_SCHEME.

Referenced by llcache_object_retrieve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache__scheme_is_persistable()

static bool llcache__scheme_is_persistable ( const nsurl url)
inlinestatic

Check whether a scheme is persistable.

Parameters
urlURL to check.
Returns
true iff url has a persistable scheme.

Definition at line 1782 of file llcache.c.

References nsurl_get_component(), and NSURL_SCHEME.

Referenced by build_candidate_list(), and llcache_object_fetch_persistent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_catch_up_all_users()

static void llcache_catch_up_all_users ( void *  ignored)
static

Catch up the cache users with state changes from fetchers.

Parameters
ignoredWe ignore this because all our state comes from llcache.

Definition at line 3679 of file llcache.c.

References llcache_s::all_caught_up, llcache_s::cached_objects, llcache, llcache_object_notify_users(), llcache_object::next, and llcache_s::uncached_objects.

Referenced by llcache_users_not_caught_up().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_clean()

void llcache_clean ( bool  purge)

Cause the low-level cache to attempt to perform cleanup.

No guarantees are made as to whether or not cleanups will take place and what, if any, space savings will be made.

Parameters
purgeAny objects held in the cache that are safely removable will be freed regardless of the configured size limits.

Definition at line 3725 of file llcache.c.

References BACKING_STORE_NONE, llcache_object::cache, llcache_s::cached_objects, llcache_object::candidate_count, llcache_fetch_ctx::fetch, llcache_object::fetch, guit, gui_llcache_table::invalidate, llcache_object::last_used, llcache_s::limit, llcache, netsurf_table::llcache, llcache_object_destroy(), llcache_object_remove_from_list(), llcache_object_rfc2616_remaining_lifetime(), llcache_persist(), LLCACHE_STATE_DISC, LLCACHE_STATE_RAM, llcache_object::next, NSLOG, nsurl_access(), PRIsizet, gui_llcache_table::release, llcache_object::source_data, llcache_object::source_len, llcache_object::store_state, total_object_size(), llcache_s::uncached_objects, llcache_object::url, and llcache_object::users.

Referenced by ami_memory_low_mem_handler(), hlcache_clean(), and llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_destroy_headers()

static void llcache_destroy_headers ( llcache_object object)
inlinestatic

Destroy headers.

Parameters
objectThe object to destroy headers within.

Definition at line 700 of file llcache.c.

References llcache_object::headers, llcache_header::name, llcache_object::num_headers, and llcache_header::value.

Referenced by llcache_fetch_auth(), and llcache_fetch_process_header().

Here is the caller graph for this function:

◆ llcache_fetch_auth()

static nserror llcache_fetch_auth ( llcache_object object,
const char *  realm 
)
static

Handle an authentication request.

Parameters
objectObject being fetched
realmAuthentication realm
Returns
NSERROR_OK on success, appropriate error otherwise.
Todo:
If there was no WWW-Authenticate header, use response body
Todo:
More appropriate error message

Definition at line 2574 of file llcache.c.

References llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_abort(), llcache_destroy_headers(), LLCACHE_EVENT_ERROR, LLCACHE_FETCH_COMPLETE, llcache_invalidate_cache_control_data(), llcache_object_refetch(), llcache_send_event_to_users(), NSERROR_BAD_AUTH, NSERROR_OK, nsurl_access(), llcache_fetch_ctx::tried_with_auth, llcache_object::url, and urldb_get_auth_details().

Referenced by llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_callback()

static void llcache_fetch_callback ( const fetch_msg msg,
void *  p 
)
static

Handler for fetch events.

Parameters
msgFetch event
pOur private data
Todo:
Consider using errorcode for something

Definition at line 3058 of file llcache.c.

References fetch_msg::auth, fetch_msg::buf, llcache_object::candidate, cert_chain_dup(), cert_chain_free(), fetch_msg::chain, llcache_object::chain, fetch_msg::data, fetch_msg::error, llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_abort(), FETCH_AUTH, FETCH_CERT_ERR, FETCH_CERTS, FETCH_DATA, FETCH_ERROR, FETCH_FINISHED, FETCH_HEADER, FETCH_NOTMODIFIED, FETCH_PROGRESS, FETCH_REDIRECT, FETCH_SSL_ERR, FETCH_TIMEDOUT, guit, fetch_msg::header_or_data, fetch_msg::len, llcache, llcache_clean(), LLCACHE_EVENT_ERROR, LLCACHE_EVENT_GOT_CERTS, LLCACHE_EVENT_PROGRESS, llcache_fetch_auth(), llcache_fetch_cert_error(), LLCACHE_FETCH_COMPLETE, LLCACHE_FETCH_HEADERS, llcache_fetch_notmodified(), llcache_fetch_process_data(), llcache_fetch_process_header(), llcache_fetch_redirect(), llcache_fetch_ssl_error(), llcache_fetch_timeout(), llcache_hsts_update_policy(), llcache_invalidate_cache_control_data(), llcache_object_cache_update(), llcache_persist(), llcache_send_event_to_users(), llcache_users_not_caught_up(), messages_get_errorcode(), netsurf_table::misc, NSERROR_NOMEM, NSERROR_OK, NSERROR_UNKNOWN, NSLOG, fetch_msg::progress, fetch_msg::realm, fetch_msg::redirect, gui_misc_table::schedule, llcache_object::source_data, llcache_object::source_len, and fetch_msg::type.

Referenced by llcache_object_refetch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_cert_error()

static nserror llcache_fetch_cert_error ( llcache_object object)
static

Handle a TLS certificate verification failure.

Parameters
objectObject being fetched
Returns
NSERROR_OK on success, appropriate error otherwise
Todo:
More appropriate error message
Todo:
More appropriate error message

Definition at line 2627 of file llcache.c.

References llcache_object::fetch, llcache_fetch_ctx::hsts_in_use, LLCACHE_EVENT_ERROR, LLCACHE_FETCH_COMPLETE, llcache_invalidate_cache_control_data(), llcache_send_event_to_users(), messages_get(), NSERROR_BAD_CERTS, NSERROR_OK, and NSERROR_UNKNOWN.

Referenced by llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_header_cache_control()

static nserror llcache_fetch_header_cache_control ( llcache_object object,
char *  name,
char *  value 
)
static

Update cache control from appropriate header.

Parameters
objectObject to parse header for
nameheader name
valueheader value
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 620 of file llcache.c.

References llcache_object::cache, llcache_cache_control::date, llcache_cache_control::etag, llcache_cache_control::expires, llcache_cache_control::last_modified, llcache, llcache_fetch_parse_cache_control(), nsc_strntimet(), NSERROR_NOMEM, NSERROR_OK, and NSLOG.

Referenced by llcache_fetch_process_header().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_notmodified()

static nserror llcache_fetch_notmodified ( llcache_object object,
llcache_object **  replacement 
)
static

Handle FETCH_NOTMODIFIED event.

Parameters
objectObject to process
replacementPointer to location to receive replacement object
Returns
NSERROR_OK.

Definition at line 2442 of file llcache.c.

References llcache_object::cache, llcache_object::candidate, llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_abort(), LLCACHE_FETCH_COMPLETE, llcache_hsts_update_policy(), llcache_invalidate_cache_control_data(), llcache_object_add_user(), llcache_object_cache_update(), llcache_object_clone_cache_data(), llcache_object_remove_user(), LLCACHE_VALIDATE_FRESH, LLCACHE_VALIDATE_ONCE, llcache_object_user::next, llcache_cache_control::no_cache, NSERROR_OK, and llcache_object::users.

Referenced by llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_parse_cache_control()

static nserror llcache_fetch_parse_cache_control ( llcache_object object,
char *  value 
)
static

parse cache control header value

Parameters
objectObject to parse header for
valueheader value
Returns
NSERROR_OK on success, appropriate error otherwise
Todo:
When we get a disk cache we should distinguish between these two.

Definition at line 582 of file llcache.c.

References http_cache_control_destroy(), http_cache_control_has_max_age(), http_cache_control_max_age(), http_cache_control_no_cache(), http_cache_control_no_store(), http_parse_cache_control(), LLCACHE_VALIDATE_ALWAYS, and NSERROR_OK.

Referenced by llcache_fetch_header_cache_control().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_process_data()

static nserror llcache_fetch_process_data ( llcache_object object,
const uint8_t *  data,
size_t  len 
)
static

Process a chunk of fetched data.

Parameters
objectObject being fetched
dataData to process
lenByte length of data
Returns
NSERROR_OK on success, appropriate error otherwise.
Note
On entry into this state, check if we need to invalidate the cache control data. We are guaranteed to have received all response headers.

There are two cases in which we want to suppress cacheing of an object:

1) The HTTP response code is not 200 or 203 2) The request URI had a query string and the response headers did not provide an explicit object expiration time.

Definition at line 2510 of file llcache.c.

References llcache_object::cache, llcache_object::candidate, llcache_cache_control::expires, llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_http_code(), INVALID_AGE, LLCACHE_FETCH_DATA, llcache_invalidate_cache_control_data(), llcache_cache_control::max_age, NSERROR_NOMEM, NSERROR_OK, nsurl_has_component(), NSURL_QUERY, llcache_object::source_alloc, llcache_object::source_data, llcache_object::source_len, llcache_fetch_ctx::state, and llcache_object::url.

Referenced by llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_process_header()

static nserror llcache_fetch_process_header ( llcache_object object,
const uint8_t *  data,
size_t  len 
)
static

Process a fetch header.

Parameters
objectObject being fetched
dataHeader string
lenByte length of header
Returns
NSERROR_OK on success, appropriate error otherwise
Note
The headers for multiple HTTP responses may be delivered to us if the fetch layer receives a 401 response for which it has authentication credentials. This will result in a silent re-request after which we'll receive the actual response headers for the object we want to fetch (assuming that the credentials were correct of course)

Therefore, if the header is an HTTP response start marker, then we must discard any headers we've read so far, reset the cache data that we might have computed, and start again.

Todo:
Properly parse the response line

Definition at line 734 of file llcache.c.

References llcache_object::cache, llcache_object::headers, llcache_destroy_headers(), llcache_fetch_header_cache_control(), llcache_fetch_split_header(), llcache_invalidate_cache_control_data(), llcache_header::name, NSERROR_NOMEM, NSERROR_OK, llcache_object::num_headers, llcache_cache_control::res_time, and SLEN.

Referenced by llcache_fetch_callback(), and llcache_process_metadata().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_redirect()

static nserror llcache_fetch_redirect ( llcache_object object,
const char *  target,
llcache_object **  replacement 
)
static

Handle FETCH_REDIRECT event.

Parameters
objectObject being redirected
targetTarget of redirect (may be relative)
replacementPointer to location to receive replacement object
Returns
NSERROR_OK on success, appropriate error otherwise
Todo:
300, 305, 307 with POST

Definition at line 2287 of file llcache.c.

References llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_abort(), fetch_can_fetch(), fetch_http_code(), llcache_fetch_ctx::flags, llcache, LLCACHE_EVENT_ERROR, LLCACHE_EVENT_REDIRECT, LLCACHE_FETCH_COMPLETE, llcache_hsts_transform_url(), llcache_hsts_update_policy(), llcache_invalidate_cache_control_data(), llcache_object_add_user(), llcache_object_remove_user(), llcache_object_retrieve(), llcache_send_event_to_users(), messages_get(), llcache_object_user::next, NSERROR_BAD_REDIRECT, NSERROR_OK, NSLOG, nsurl_get_component(), nsurl_join(), NSURL_SCHEME, nsurl_unref(), llcache_fetch_ctx::redirect_count, REDIRECT_LIMIT, llcache_fetch_ctx::referer, llcache_object::url, and llcache_object::users.

Referenced by llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_split_header()

static nserror llcache_fetch_split_header ( const uint8_t *  data,
size_t  len,
char **  name,
char **  value 
)
static

Split a fetch header into name and value.

HTTP header splitting according to grammar defined in RFC7230 section 3.2 https://tools.ietf.org/html/rfc7230#section-3.2

This implementation is non conformant in that it:

  • includes carrige return and newline in whitespace (3.2.3)
  • allows whitespace before and after the field-name token (3.2.4)
  • does not handle obsolete line folding (3.2.4)
Parameters
dataHeader string
lenByte length of header
namePointer to location to receive header name
valuePointer to location to receive header value
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 496 of file llcache.c.

References NSERROR_NOMEM, NSERROR_OK, and strndup().

Referenced by llcache_fetch_process_header().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_ssl_error()

static nserror llcache_fetch_ssl_error ( llcache_object object)
static

Handle a TLS connection setup failure.

Parameters
objectObject being fetched
Returns
NSERROR_OK on success, appropriate error otherwise
Todo:
More appropriate error message

Definition at line 2679 of file llcache.c.

References llcache_object::fetch, llcache_fetch_ctx::hsts_in_use, LLCACHE_EVENT_ERROR, LLCACHE_FETCH_COMPLETE, llcache_invalidate_cache_control_data(), llcache_object_refetch(), llcache_send_event_to_users(), messages_get(), NSERROR_OK, NSERROR_UNKNOWN, and llcache_fetch_ctx::tried_with_tls_downgrade.

Referenced by llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_fetch_timeout()

static nserror llcache_fetch_timeout ( llcache_object object)
static

handle time out while trying to fetch.

Parameters
objectObject being fetched
Returns
NSERROR_OK on success otherwise error code

Definition at line 2726 of file llcache.c.

References llcache_object::candidate, llcache_object::fetch, LLCACHE_EVENT_ERROR, LLCACHE_FETCH_COMPLETE, llcache_invalidate_cache_control_data(), llcache_object_refetch(), llcache_send_event_to_users(), NSERROR_TIMEOUT, and llcache_fetch_ctx::retries_remaining.

Referenced by llcache_fetch_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_finalise()

void llcache_finalise ( void  )

Finalise the low-level cache.

Definition at line 3916 of file llcache.c.

References llcache_s::cached_objects, gui_llcache_table::finalise, guit, llcache_object_user::handle, llcache, netsurf_table::llcache, llcache_object_destroy(), llcache_persist(), netsurf_table::misc, llcache_object_user::next, llcache_object::next, NSLOG, PRIu64, gui_misc_table::schedule, llcache_s::total_elapsed, llcache_s::total_written, llcache_s::uncached_objects, and llcache_object::users.

Referenced by hlcache_finalise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_handle_abort()

nserror llcache_handle_abort ( llcache_handle handle)

Abort a low-level fetch, informing all users of this action.

Parameters
handleHandle to abort
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 4098 of file llcache.c.

References llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_abort(), llcache_object_user::handle, llcache_object_user::iterator_target, llcache, LLCACHE_FETCH_COMPLETE, llcache_invalidate_cache_control_data(), llcache_object_add_to_list(), llcache_object_add_user(), llcache_object_destroy(), llcache_object_find_user(), llcache_object_remove_user(), llcache_object_snapshot(), llcache_object_user::next, NSERROR_NOMEM, NSERROR_OK, llcache_handle::object, llcache_object_user::prev, llcache_object_user::queued_for_delete, and llcache_s::uncached_objects.

Referenced by browser_window_convert_to_download(), browser_window_download(), content_abort(), content_llcache_callback(), download_callback(), download_context_abort(), hlcache_handle_abort(), hlcache_handle_release(), and hlcache_migrate_ctx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_handle_change_callback()

nserror llcache_handle_change_callback ( llcache_handle handle,
llcache_handle_callback  cb,
void *  pw 
)

Change the callback associated with a low-level cache handle.

Parameters
handleHandle to change callback of
cbNew callback
pwClient data for new callback
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 4047 of file llcache.c.

References llcache_handle::cb, NSERROR_OK, and llcache_handle::pw.

Referenced by content__clone(), content__init(), and download_context_create().

Here is the caller graph for this function:

◆ llcache_handle_clone()

nserror llcache_handle_clone ( llcache_handle handle,
llcache_handle **  result 
)

Clone a low-level cache handle, producing a new handle to the same fetch/content.

Parameters
handleHandle to clone
resultPointer to location to receive cloned handle
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 4082 of file llcache.c.

References llcache_handle::cb, llcache_object_user::handle, llcache_object_add_user(), llcache_object_user_new(), NSERROR_OK, llcache_handle::object, llcache_handle::pw, result, and llcache_handle::state.

Referenced by content__clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_handle_force_stream()

nserror llcache_handle_force_stream ( llcache_handle handle)

Force a low-level cache handle into streaming mode.

Parameters
handleHandle to stream
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 4160 of file llcache.c.

References llcache_s::cached_objects, llcache, llcache_object_add_to_list(), llcache_object_find_user(), llcache_object_in_list(), llcache_object_remove_from_list(), LLCACHE_RETRIEVE_STREAM_DATA, llcache_object_user::next, NSERROR_OK, llcache_handle::object, llcache_object_user::prev, and llcache_s::uncached_objects.

Referenced by hlcache_migrate_ctx(), and nsvideo_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_handle_get_header()

const char * llcache_handle_get_header ( const llcache_handle handle,
const char *  key 
)

Retrieve a header value associated with a low-level cache object.

Parameters
handleHandle to retrieve header from
keyHeader name
Returns
Header value, or NULL if header does not exist
Todo:

Make the key an enumeration, to avoid needless string comparisons

Forcing the client to parse the header value seems wrong. Better would be to return the actual value part and an array of key-value pairs for any additional parameters.

Deal with multiple headers of the same key (e.g. Set-Cookie)

Definition at line 4210 of file llcache.c.

References llcache_object::headers, llcache_header::name, llcache_handle::object, and llcache_header::value.

Referenced by content_factory_create_content(), download_context_process_headers(), hlcache_llcache_callback(), and nscss_create().

Here is the caller graph for this function:

◆ llcache_handle_get_source_data()

const uint8_t * llcache_handle_get_source_data ( const llcache_handle handle,
size_t *  size 
)

Retrieve source data of a low-level cache object.

Parameters
handleHandle to retrieve source data from
sizePointer to location to receive byte length of data
Returns
Pointer to source data

Definition at line 4201 of file llcache.c.

References llcache_handle::object, llcache_object::source_data, and llcache_object::source_len.

Referenced by content__get_source_data(), and content_llcache_callback().

Here is the caller graph for this function:

◆ llcache_handle_get_url()

nsurl * llcache_handle_get_url ( const llcache_handle handle)

Retrieve the post-redirect URL of a low-level cache object.

Parameters
handleHandle to retrieve URL from
Returns
Post-redirect URL of cache object

Definition at line 4195 of file llcache.c.

References llcache_handle::object, and llcache_object::url.

Referenced by content__get_title(), content__init(), content_add_user(), content_close(), content_convert(), content_destroy(), content_get_url(), content_open(), content_remove_user(), download_context_get_url(), download_context_process_headers(), gif_convert(), hlcache_handle_get_url(), image_cache_snentryf(), nsbmp_convert(), nsico_convert(), nsjpeg_convert(), nsjpegxl_convert(), nspng_convert(), and nssprite_convert().

Here is the caller graph for this function:

◆ llcache_handle_invalidate_cache_data()

nserror llcache_handle_invalidate_cache_data ( llcache_handle handle)

Invalidate cache data for a low-level cache object.

Parameters
handleHandle to invalidate
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 4182 of file llcache.c.

References llcache_object::cache, llcache_fetch_ctx::fetch, llcache_object::fetch, LLCACHE_VALIDATE_FRESH, LLCACHE_VALIDATE_ONCE, llcache_cache_control::no_cache, NSERROR_OK, and llcache_handle::object.

Referenced by content__invalidate_reuse_data().

Here is the caller graph for this function:

◆ llcache_handle_references_same_object()

bool llcache_handle_references_same_object ( const llcache_handle a,
const llcache_handle b 
)

Determine if the same underlying object is referenced by the given handles.

Parameters
aFirst handle
bSecond handle
Returns
True if handles reference the same object, false otherwise

Definition at line 4229 of file llcache.c.

References llcache_handle::object.

Referenced by hlcache_find_content().

Here is the caller graph for this function:

◆ llcache_handle_release()

nserror llcache_handle_release ( llcache_handle handle)

Release a low-level cache handle.

Parameters
handleHandle to release
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 4058 of file llcache.c.

References llcache_object_user::iterator_target, llcache_object_find_user(), llcache_object_remove_user(), llcache_object_user_destroy(), NSERROR_OK, llcache_handle::object, and llcache_object_user::queued_for_delete.

Referenced by browser_window_convert_to_download(), browser_window_download(), content_destroy(), download_context_destroy(), hlcache_finalise(), hlcache_find_content(), hlcache_handle_abort(), hlcache_handle_release(), and hlcache_migrate_ctx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_handle_retrieve()

nserror llcache_handle_retrieve ( nsurl url,
uint32_t  flags,
nsurl referer,
const llcache_post_data post,
llcache_handle_callback  cb,
void *  pw,
llcache_handle **  result 
)

Retrieve a handle for a low-level cache object.

Parameters
urlURL of the object to fetch
flagsObject retrieval flags
refererReferring URL, or NULL if none
postPOST data, or NULL for a GET request
cbClient callback for events
pwPointer to client-specific data
resultPointer to location to recieve cache handle
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 3990 of file llcache.c.

References fetch_can_fetch(), llcache_object_user::handle, llcache_hsts_transform_url(), llcache_object_add_user(), llcache_object_retrieve(), llcache_object_user_destroy(), llcache_object_user_new(), llcache_users_not_caught_up(), NSERROR_NO_FETCH_HANDLER, NSERROR_OK, nsurl_unref(), result, and llcache_object::url.

Referenced by browser_window_download(), and hlcache_handle_retrieve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_hsts_transform_url()

static nserror llcache_hsts_transform_url ( nsurl url,
nsurl **  result,
bool *  hsts_in_use 
)
static

Transform a request-URI based on HSTS policy.

Parameters
urlURL to transform
resultPointer to location to receive transformed URL
hsts_in_usePointer to location to receive HSTS in-use flag
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 2200 of file llcache.c.

References NSERROR_OK, nsurl_get_component(), nsurl_ref(), nsurl_replace_scheme(), NSURL_SCHEME, result, and urldb_get_hsts_enabled().

Referenced by llcache_fetch_redirect(), and llcache_handle_retrieve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_hsts_update_policy()

static nserror llcache_hsts_update_policy ( llcache_object object)
static

Update HSTS policy for target domain.

Parameters
objectNewly-fetched cache object
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 2246 of file llcache.c.

References llcache_object::fetch, llcache_object::headers, llcache_header::name, NSERROR_OK, nsurl_get_component(), NSURL_SCHEME, llcache_fetch_ctx::tainted_tls, llcache_object::url, urldb_set_hsts_policy(), and llcache_header::value.

Referenced by llcache_fetch_callback(), llcache_fetch_notmodified(), and llcache_fetch_redirect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_initialise()

nserror llcache_initialise ( const struct llcache_parameters parameters)

Initialise the low-level cache.

Parameters
parameterscache configuration parameters.
Returns
NSERROR_OK on success, appropriate error otherwise.

Definition at line 3891 of file llcache.c.

References llcache_s::all_caught_up, llcache_s::fetch_attempts, llcache_parameters::fetch_attempts, guit, gui_llcache_table::initialise, llcache_s::limit, llcache_parameters::limit, llcache, netsurf_table::llcache, llcache_s::maximum_bandwidth, llcache_parameters::maximum_bandwidth, llcache_s::minimum_bandwidth, llcache_parameters::minimum_bandwidth, llcache_s::minimum_lifetime, llcache_parameters::minimum_lifetime, NSERROR_NOMEM, NSLOG, llcache_parameters::store, llcache_s::time_quantum, and llcache_parameters::time_quantum.

Referenced by hlcache_initialise().

Here is the caller graph for this function:

◆ llcache_invalidate_cache_control_data()

static void llcache_invalidate_cache_control_data ( llcache_object object)
inlinestatic

Invalidate cache control data.

Parameters
objectThe object to invalidate cache control for.

Definition at line 717 of file llcache.c.

References llcache_object::cache, llcache_cache_control::etag, and INVALID_AGE.

Referenced by llcache_fetch_auth(), llcache_fetch_callback(), llcache_fetch_cert_error(), llcache_fetch_notmodified(), llcache_fetch_process_data(), llcache_fetch_process_header(), llcache_fetch_redirect(), llcache_fetch_ssl_error(), llcache_fetch_timeout(), llcache_handle_abort(), and llcache_object_refetch().

Here is the caller graph for this function:

◆ llcache_object_add_to_list()

static nserror llcache_object_add_to_list ( llcache_object object,
llcache_object **  list 
)
static

Add a low-level cache object to a cache list.

Parameters
objectObject to add
listList to add to
Returns
NSERROR_OK

Definition at line 1116 of file llcache.c.

References NSERROR_OK, and llcache_object::prev.

Referenced by llcache_handle_abort(), llcache_handle_force_stream(), llcache_object_retrieve(), and llcache_object_retrieve_from_cache().

Here is the caller graph for this function:

◆ llcache_object_add_user()

static nserror llcache_object_add_user ( llcache_object object,
llcache_object_user user 
)
static

Add a user to a low-level cache object.

Parameters
objectObject to add user to
userUser to add
Returns
NSERROR_OK.

Definition at line 2171 of file llcache.c.

References llcache_object_user::handle, llcache, llcache_object_user::next, NSERROR_OK, NSLOG, llcache_handle::object, llcache_object_user::prev, and llcache_object::users.

Referenced by llcache_fetch_notmodified(), llcache_fetch_redirect(), llcache_handle_abort(), llcache_handle_clone(), and llcache_handle_retrieve().

Here is the caller graph for this function:

◆ llcache_object_cache_update()

static nserror llcache_object_cache_update ( llcache_object object)
static

Update an object's cache state.

Parameters
objectObject to update cache for
Returns
NSERROR_OK.

Definition at line 2427 of file llcache.c.

References llcache_object::cache, llcache_cache_control::date, and NSERROR_OK.

Referenced by llcache_fetch_callback(), and llcache_fetch_notmodified().

Here is the caller graph for this function:

◆ llcache_object_clone_cache_data()

static nserror llcache_object_clone_cache_data ( llcache_object source,
llcache_object destination,
bool  deep 
)
static

Clone an object's cache data.

Postcondition
If deep is false, then any pointers in source will be set to NULL
Parameters
sourceSource object containing cache data to clone
destinationDestination object to clone cache data into
deepWhether to deep-copy the data or not
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 1211 of file llcache.c.

References llcache_cache_control::age, llcache_object::cache, llcache_cache_control::date, llcache_cache_control::etag, llcache_cache_control::expires, llcache_cache_control::fin_time, INVALID_AGE, llcache_cache_control::last_modified, LLCACHE_VALIDATE_FRESH, llcache_cache_control::max_age, llcache_cache_control::no_cache, NSERROR_NOMEM, NSERROR_OK, llcache_cache_control::req_time, and llcache_cache_control::res_time.

Referenced by llcache_fetch_notmodified(), and llcache_object_retrieve_from_cache().

Here is the caller graph for this function:

◆ llcache_object_destroy()

static nserror llcache_object_destroy ( llcache_object object)
static

Destroy a low-level cache object.

Precondition
Object is detached from cache list
Object has no users
Object is not a candidate (i.e. object::candidate_count == 0)
Parameters
objectObject to destroy
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 1058 of file llcache.c.

References BACKING_STORE_NONE, llcache_object::cache, cert_chain_free(), llcache_object::chain, llcache_post_data::data, llcache_cache_control::etag, llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_abort(), fetch_multipart_data_destroy(), guit, llcache_object::headers, llcache, netsurf_table::llcache, LLCACHE_STATE_DISC, llcache_post_data::multipart, llcache_header::name, NSERROR_OK, NSLOG, nsurl_access(), nsurl_unref(), llcache_fetch_ctx::post, llcache_fetch_ctx::referer, gui_llcache_table::release, llcache_object::source_data, llcache_object::store_state, llcache_post_data::type, llcache_object::url, llcache_post_data::urlenc, and llcache_header::value.

Referenced by llcache_clean(), llcache_finalise(), llcache_handle_abort(), llcache_object_retrieve(), llcache_object_retrieve_from_cache(), and llcache_object_snapshot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_fetch()

static nserror llcache_object_fetch ( llcache_object object,
uint32_t  flags,
nsurl referer,
const llcache_post_data post,
uint32_t  redirect_count,
bool  hsts_in_use 
)
static

Kick-off a fetch for an object.

Precondition
object::url must contain the URL to fetch
If there is a freshness validation candidate, object::candidate and object::cache must be filled in
There must not be a fetch in progress for object
Parameters
objectObject to fetch
flagsFetch flags
refererReferring URL, or NULL for none
postPOST data, or NULL for GET
redirect_countNumber of redirects followed so far
hsts_in_useWhether HSTS applies to this fetch
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 1019 of file llcache.c.

References llcache_s::fetch_attempts, llcache, llcache_object_refetch(), llcache_post_data_clone(), NSERROR_OK, NSLOG, and nsurl_ref().

Referenced by llcache_object_retrieve(), and llcache_object_retrieve_from_cache().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_fetch_persistent()

static nserror llcache_object_fetch_persistent ( llcache_object object,
uint32_t  flags,
nsurl referer,
const llcache_post_data post,
uint32_t  redirect_count 
)
static

Attempt to retrieve an object from persistent storage.

Parameters
objectThe object to populate from persistent store.
flagsFetch flags.
refererThe referring url.
postPost data for fetch.
redirect_counthow many times this fetch has been redirected.
Returns
NSERROR_OK if the object was successfully retrieved from the cache else appropriate error code.

Definition at line 1853 of file llcache.c.

References llcache__scheme_is_persistable(), LLCACHE_FETCH_COMPLETE, llcache_post_data_clone(), llcache_process_metadata(), NSERROR_NOT_FOUND, NSERROR_OK, nsurl_ref(), and llcache_object::url.

Referenced by llcache_object_retrieve_from_cache().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_find_user()

static llcache_object_user * llcache_object_find_user ( const llcache_handle handle)
static

Find a user of a low-level cache object.

Parameters
handleExternal cache handle to search for
Returns
Pointer to corresponding user, or NULL if not found

Definition at line 3271 of file llcache.c.

References llcache_object_user::handle, llcache_object_user::next, llcache_handle::object, and llcache_object::users.

Referenced by llcache_handle_abort(), llcache_handle_force_stream(), and llcache_handle_release().

Here is the caller graph for this function:

◆ llcache_object_in_list()

static bool llcache_object_in_list ( const llcache_object object,
const llcache_object list 
)
static

Determine if a low-level cache object resides in a given list.

Parameters
objectObject to search for
listList to search in
Returns
True if object resides in list, false otherwise

Definition at line 3294 of file llcache.c.

References llcache_object::next.

Referenced by llcache_handle_force_stream().

Here is the caller graph for this function:

◆ llcache_object_is_fresh()

static bool llcache_object_is_fresh ( const llcache_object object)
static

Determine if an object is still fresh.

Parameters
objectObject to consider
Returns
True if object is still fresh, false otherwise

Definition at line 1179 of file llcache.c.

References cd, llcache_object::fetch, llcache, LLCACHE_FETCH_COMPLETE, llcache_object_rfc2616_remaining_lifetime(), LLCACHE_VALIDATE_FRESH, NSLOG, and llcache_fetch_ctx::state.

Referenced by llcache_object_retrieve_from_cache().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_new()

static nserror llcache_object_new ( nsurl url,
llcache_object **  result 
)
static

Create a new low-level cache object.

Parameters
urlURL of object to create
resultPointer to location to receive result
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 423 of file llcache.c.

References llcache, NSERROR_NOMEM, NSERROR_OK, NSLOG, nsurl_access(), nsurl_ref(), result, and llcache_object::url.

Referenced by llcache_object_retrieve(), llcache_object_retrieve_from_cache(), and llcache_object_snapshot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_notify_users()

static nserror llcache_object_notify_users ( llcache_object object)
static

Notify users of an object's current state.

Parameters
objectObject to notify users about
Returns
NSERROR_OK on success, appropriate error otherwise

State transitions and event emission for users. Rows: user state. Cols: object state.

User - Obj INIT HEADERS DATA COMPLETE INIT - T T* T* HEADERS - - T T* DATA - - M T COMPLETE - - - -

T => transition user to object state M => no transition required, but may need to emit event

The transitions marked with an asterisk can be removed by moving the user context into the subsequent state and then reevaluating.

Events are issued as follows:

HAD_HEADERS: on transition from HEADERS -> DATA state HAD_DATA : in DATA state, whenever there's new source data DONE : on transition from DATA -> COMPLETE state

Definition at line 3313 of file llcache.c.

References llcache_handle::bytes, llcache_handle::cb, llcache_object::chain, llcache_object::fetch, llcache_fetch_ctx::flags, llcache_object_user::handle, llcache_object_user::iterator_target, llcache, LLCACHE_EVENT_DONE, LLCACHE_EVENT_GOT_CERTS, LLCACHE_EVENT_HAD_DATA, LLCACHE_EVENT_HAD_HEADERS, LLCACHE_FETCH_COMPLETE, LLCACHE_FETCH_DATA, LLCACHE_FETCH_HEADERS, LLCACHE_FETCH_INIT, llcache_object_remove_user(), llcache_object_user_destroy(), LLCACHE_RETRIEVE_STREAM_DATA, llcache_users_not_caught_up(), llcache_object_user::next, NSERROR_NEED_DATA, NSERROR_OK, NSLOG, llcache_handle::pw, llcache_object_user::queued_for_delete, llcache_object::source_len, llcache_handle::state, and llcache_object::users.

Referenced by llcache_catch_up_all_users().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_refetch()

static nserror llcache_object_refetch ( llcache_object object)
static

(Re)fetch an object

Sets up headers and attempts to start an actual fetch from the fetchers system updating the llcache object with the new fetch on successful start.

Precondition
The fetch parameters in object->fetch must be populated
Parameters
objectObject to refetch
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 903 of file llcache.c.

References llcache_object::cache, llcache_cache_control::etag, llcache_fetch_ctx::fetch, llcache_object::fetch, fetch_start(), llcache_fetch_ctx::flags, get_referer_header(), llcache_cache_control::last_modified, llcache, llcache_fetch_callback(), LLCACHE_FETCH_INIT, llcache_invalidate_cache_control_data(), LLCACHE_RETRIEVE_NO_ERROR_PAGES, LLCACHE_RETRIEVE_VERIFIABLE, NSERROR_NOMEM, NSERROR_OK, NSLOG, llcache_fetch_ctx::post, llcache_fetch_ctx::referer, rfc1123_date(), SLEN, llcache_fetch_ctx::tried_with_tls_downgrade, llcache_post_data::type, and llcache_object::url.

Referenced by llcache_fetch_auth(), llcache_fetch_ssl_error(), llcache_fetch_timeout(), and llcache_object_fetch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_remove_from_list()

static nserror llcache_object_remove_from_list ( llcache_object object,
llcache_object **  list 
)
static

Remove a low-level cache object from a cache list.

Parameters
objectObject to remove
listList to remove from
Returns
NSERROR_OK

Definition at line 1267 of file llcache.c.

References llcache_object::next, NSERROR_OK, and llcache_object::prev.

Referenced by llcache_clean(), llcache_handle_force_stream(), and llcache_object_retrieve_from_cache().

Here is the caller graph for this function:

◆ llcache_object_remove_user()

static nserror llcache_object_remove_user ( llcache_object object,
llcache_object_user user 
)
static

Remove a user from a low-level cache object.

Parameters
objectObject to remove user from
userUser to remove
Returns
NSERROR_OK.

Definition at line 348 of file llcache.c.

References llcache_object_user::handle, llcache, llcache_object_user::next, NSERROR_OK, NSLOG, llcache_handle::object, llcache_object_user::prev, and llcache_object::users.

Referenced by llcache_fetch_notmodified(), llcache_fetch_redirect(), llcache_handle_abort(), llcache_handle_release(), llcache_object_notify_users(), and llcache_send_event_to_users().

Here is the caller graph for this function:

◆ llcache_object_retrieve()

static nserror llcache_object_retrieve ( nsurl url,
uint32_t  flags,
nsurl referer,
const llcache_post_data post,
uint32_t  redirect_count,
bool  hsts_in_use,
llcache_object **  result 
)
static

Retrieve an object from the cache, fetching it if necessary.

Parameters
urlURL of object to retrieve
flagsFetch flags
refererReferring URL, or NULL if none
postPOST data, or NULL for a GET request
redirect_countNumber of redirects followed so far
hsts_in_useWhether HSTS applies to this fetch
resultPointer to location to receive retrieved object
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 2090 of file llcache.c.

References llcache, llcache__scheme_is_cachable(), llcache_object_add_to_list(), llcache_object_destroy(), llcache_object_fetch(), llcache_object_new(), llcache_object_retrieve_from_cache(), LLCACHE_RETRIEVE_FORCE_FETCH, NSERROR_OK, NSLOG, nsurl_access(), nsurl_defragment(), nsurl_unref(), result, and llcache_s::uncached_objects.

Referenced by llcache_fetch_redirect(), and llcache_handle_retrieve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_retrieve_from_cache()

static nserror llcache_object_retrieve_from_cache ( nsurl url,
uint32_t  flags,
nsurl referer,
const llcache_post_data post,
uint32_t  redirect_count,
bool  hsts_in_use,
llcache_object **  result 
)
static

Retrieve a potentially cached object.

Parameters
urlURL of object to retrieve
flagsFetch flags
refererReferring URL, or NULL if none
postPOST data, or NULL for a GET request
redirect_countNumber of redirects followed so far
hsts_in_useWhether HSTS applies to this fetch
resultPointer to location to receive retrieved object
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 1914 of file llcache.c.

References llcache_object::cache, llcache_s::cached_objects, llcache_object::candidate, llcache_object::candidate_count, llcache, llcache_object_add_to_list(), llcache_object_clone_cache_data(), llcache_object_destroy(), llcache_object_fetch(), llcache_object_fetch_persistent(), llcache_object_is_fresh(), llcache_object_new(), llcache_object_remove_from_list(), llcache_retrieve_persisted_data(), llcache_object::next, NSERROR_OK, NSLOG, nsurl_access(), nsurl_compare(), NSURL_COMPLETE, llcache_cache_control::req_time, result, and llcache_object::url.

Referenced by llcache_object_retrieve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_rfc2616_remaining_lifetime()

static int llcache_object_rfc2616_remaining_lifetime ( const llcache_cache_control cd)
static

Determine the remaining lifetime of a cache object using the.

Parameters
cdcache control data.
Returns
The length of time remaining for the object or 0 if expired.

Definition at line 1136 of file llcache.c.

References cd, INVALID_AGE, llcache, LLCACHE_VALIDATE_FRESH, max, and NSLOG.

Referenced by build_candidate_list(), llcache_clean(), and llcache_object_is_fresh().

Here is the caller graph for this function:

◆ llcache_object_snapshot()

static nserror llcache_object_snapshot ( llcache_object object,
llcache_object **  snapshot 
)
static

Make a snapshot of the current state of an llcache_object.

This has the side-effect of the new object being non-cacheable, also not-fetching and not a candidate for any other object.

Also note that this new object has no users and at least one should be assigned to it before llcache_clean is entered or it will be immediately cleaned up.

Parameters
objectThe object to take a snapshot of
snapshotPointer to receive snapshot of object
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 3580 of file llcache.c.

References cert_chain_dup(), llcache_object::chain, llcache_object::fetch, llcache_object::headers, LLCACHE_FETCH_COMPLETE, llcache_object_destroy(), llcache_object_new(), llcache_header::name, NSERROR_NOMEM, NSERROR_OK, llcache_object::num_headers, snapshot, llcache_object::source_alloc, llcache_object::source_data, llcache_object::source_len, llcache_fetch_ctx::state, llcache_object::url, and llcache_header::value.

Referenced by llcache_handle_abort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_object_user_destroy()

static nserror llcache_object_user_destroy ( llcache_object_user user)
static

Destroy an object user.

Parameters
userUser to destroy
Returns
NSERROR_OK on success, appropriate error otherwise
Precondition
User is not attached to an object

Definition at line 326 of file llcache.c.

References llcache_object_user::handle, llcache, llcache_object_user::next, NSERROR_OK, NSLOG, and llcache_object_user::prev.

Referenced by llcache_handle_release(), llcache_handle_retrieve(), llcache_object_notify_users(), and llcache_send_event_to_users().

Here is the caller graph for this function:

◆ llcache_object_user_new()

static nserror llcache_object_user_new ( llcache_handle_callback  cb,
void *  pw,
llcache_object_user **  user 
)
static

Create a new object user.

Parameters
cbCallback routine.
pwPrivate data for callback.
userPointer to location to receive result.
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 288 of file llcache.c.

References llcache_handle::cb, llcache_object_user::handle, llcache, NSERROR_NOMEM, NSERROR_OK, NSLOG, and llcache_handle::pw.

Referenced by llcache_handle_clone(), and llcache_handle_retrieve().

Here is the caller graph for this function:

◆ llcache_persist()

static void llcache_persist ( void *  p)
static

Possibly write objects data to backing store.

Parameters
pThe context pointer passed to the callback.

Definition at line 2938 of file llcache.c.

References build_candidate_list(), guit, llcache, llcache_persist(), llcache_persist_slowcheck(), llcache_s::maximum_bandwidth, netsurf_table::misc, llcache_object::next, NSERROR_OK, NSLOG, nsurl_access(), PRIsizet, gui_misc_table::schedule, llcache_s::time_quantum, llcache_s::total_elapsed, llcache_s::total_written, llcache_object::url, and write_backing_store().

Referenced by llcache_clean(), llcache_fetch_callback(), llcache_finalise(), and llcache_persist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_persist_slowcheck()

static void llcache_persist_slowcheck ( void *  p)
static

Check for overall write performance.

If the overall write bandwidth has fallen below a useful level for the backing store to be effective disable it.

It is important to ensure a useful amount of data has been written before calculating bandwidths otherwise tiny files taking a disproportionately long time to write might trigger this erroneously.

Parameters
pThe context pointer passed to the callback.

Definition at line 2915 of file llcache.c.

References gui_llcache_table::finalise, guit, llcache, netsurf_table::llcache, llcache_s::minimum_bandwidth, NSLOG, PRIsizet, PRIu64, llcache_s::total_elapsed, and llcache_s::total_written.

Referenced by llcache_persist().

Here is the caller graph for this function:

◆ llcache_post_data_clone()

static nserror llcache_post_data_clone ( const llcache_post_data orig,
llcache_post_data **  clone 
)
static

Clone a POST data object.

Parameters
origObject to clone
clonePointer to location to receive clone
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 445 of file llcache.c.

References llcache_post_data::data, fetch_multipart_data_clone(), llcache_post_data::multipart, NSERROR_NOMEM, NSERROR_OK, llcache_post_data::type, and llcache_post_data::urlenc.

Referenced by llcache_object_fetch(), and llcache_object_fetch_persistent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_process_metadata()

static nserror llcache_process_metadata ( llcache_object object)
static

Deserialisation of an object's metadata.

Attempt to retrieve and deserialise the metadata for an object from the backing store.

This must only update object if it is successful otherwise difficult to debug crashes happen later by using bad leftover object state.

Parameters
objectThe object to retrieve the metadata for.
Returns
NSERROR_OK if the metatdata was retrieved and deserialised or error code if URL is not in persistent storage or in event of deserialisation error.
Todo:
really not sure this is right, nothing is allocated here?

Definition at line 1532 of file llcache.c.

References BACKING_STORE_META, cert_chain_alloc(), cert_chain_free(), cert_chain::certs, cert_chain::der, cert_chain::der_length, cert_chain::err, gui_llcache_table::fetch, guit, line(), llcache, netsurf_table::llcache, llcache_fetch_process_header(), LLCACHE_STATE_DISC, MAX_CERT_DEPTH, nsc_snptimet(), NSERROR_BAD_URL, NSERROR_INVALID, NSERROR_NOMEM, NSERROR_OK, NSLOG, nsurl_access(), nsurl_compare(), NSURL_COMPLETE, nsurl_create(), nsurl_unref(), PRIsizet, gui_llcache_table::release, SSL_CERT_ERR_MAX_KNOWN, SSL_CERT_ERR_OK, SSL_CERT_ERR_UNKNOWN, and llcache_object::url.

Referenced by llcache_object_fetch_persistent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_retrieve_persisted_data()

static nserror llcache_retrieve_persisted_data ( llcache_object object)
static

Retrieve source data for an object from persistent store if necessary.

If an object's source data has been placed in the persistent store and there is no in-memory copy, then attempt to retrieve the source data.

Parameters
objectthe object to operate on.
Returns
appropriate error code.

Definition at line 1290 of file llcache.c.

References BACKING_STORE_NONE, gui_llcache_table::fetch, guit, netsurf_table::llcache, LLCACHE_STATE_DISC, NSERROR_OK, llcache_object::source_data, llcache_object::source_len, llcache_object::store_state, and llcache_object::url.

Referenced by llcache_object_retrieve_from_cache().

Here is the caller graph for this function:

◆ llcache_send_event_to_users()

static nserror llcache_send_event_to_users ( llcache_object object,
llcache_event event 
)
static

Iterate the users of an object, calling their callbacks.

Parameters
objectThe object to iterate
eventThe event to pass to the callback.
Returns
NSERROR_OK on success, appropriate error otherwise.

Definition at line 384 of file llcache.c.

References llcache_handle::cb, llcache_object_user::handle, llcache_object_user::iterator_target, llcache_object_remove_user(), llcache_object_user_destroy(), llcache_object_user::next, NSERROR_OK, llcache_handle::pw, and llcache_object_user::queued_for_delete.

Referenced by llcache_fetch_auth(), llcache_fetch_callback(), llcache_fetch_cert_error(), llcache_fetch_redirect(), llcache_fetch_ssl_error(), and llcache_fetch_timeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_serialise_metadata()

static nserror llcache_serialise_metadata ( llcache_object object,
uint8_t **  data_out,
size_t *  datasize_out 
)
static

Generate a serialised version of an object's metadata.

The metadata includes object headers.

Parameters
objectThe cache object to serialise the metadata of.
data_outWhere the serialised buffer will be placed.
datasize_outThe size of the serialised data.
Returns
NSERROR_OK on success with data_out and datasize_out updated, NSERROR_NOMEM on memory exhaustion or NSERROR_INVALID if there was an error serialising the stream.

Definition at line 1322 of file llcache.c.

References llcache_object::cache, cert_chain::certs, llcache_object::chain, cert_chain::der, cert_chain::der_length, cert_chain::err, llcache_cache_control::fin_time, llcache_object::headers, llcache, llcache_header::name, nsc_sntimet(), NSERROR_INVALID, NSERROR_NOMEM, NSERROR_OK, NSLOG, nsurl_access(), nsurl_length(), llcache_object::num_headers, PRIsizet, llcache_cache_control::req_time, llcache_cache_control::res_time, llcache_object::source_len, llcache_object::url, and llcache_header::value.

Referenced by write_backing_store().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ llcache_users_not_caught_up()

static void llcache_users_not_caught_up ( void  )
static

Ask for llcache_catch_up_all_users to be scheduled ASAP to pump the user state machines.

Definition at line 3705 of file llcache.c.

References llcache_s::all_caught_up, guit, llcache, llcache_catch_up_all_users(), netsurf_table::misc, and gui_misc_table::schedule.

Referenced by llcache_fetch_callback(), llcache_handle_retrieve(), and llcache_object_notify_users().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ total_object_size()

static uint32_t total_object_size ( llcache_object object)
inlinestatic

total ram usage of object

Parameters
objectThe object to calculate the total RAM usage of.
Returns
The total RAM usage in bytes.

Definition at line 3646 of file llcache.c.

References cert_chain_size(), llcache_object::chain, llcache_object::headers, llcache_header::name, nsurl_length(), llcache_object::num_headers, llcache_object::source_data, llcache_object::url, and llcache_header::value.

Referenced by llcache_clean().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_backing_store()

static nserror write_backing_store ( struct llcache_object object,
size_t *  written_out,
unsigned long *  elapsed 
)
static

Write an object to the backing store.

Parameters
objectThe object to put in the backing store.
written_outThe amount of data written out.
elapsedThe time in ms it took to complete the write to backing store.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 2839 of file llcache.c.

References BACKING_STORE_META, BACKING_STORE_NONE, guit, gui_llcache_table::invalidate, netsurf_table::llcache, llcache_serialise_metadata(), LLCACHE_STATE_DISC, NSERROR_OK, gui_llcache_table::release, llcache_object::source_data, llcache_object::source_len, gui_llcache_table::store, and llcache_object::url.

Referenced by llcache_persist().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ llcache

struct llcache_s* llcache = NULL
static