NetSurf
Data Structures | Typedefs | Enumerations | Functions
llcache.h File Reference

Low-level resource cache (interface) More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "utils/errors.h"
#include "utils/nsurl.h"
Include dependency graph for llcache.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  llcache_post_data
 POST data object for low-level cache requests. More...
 
struct  llcache_event
 Low-level cache events. More...
 
struct  llcache_store_parameters
 Parameters to configure the low level cache backing store. More...
 
struct  llcache_parameters
 Parameters to configure the low level cache. More...
 

Typedefs

typedef struct llcache_handle llcache_handle
 Handle for low-level cache object. More...
 
typedef struct llcache_post_data llcache_post_data
 POST data object for low-level cache requests. More...
 
typedef nserror(* llcache_handle_callback) (llcache_handle *handle, const llcache_event *event, void *pw)
 Client callback for low-level cache events. More...
 

Enumerations

enum  llcache_retrieve_flag { LLCACHE_RETRIEVE_FORCE_FETCH = (1 << 0) , LLCACHE_RETRIEVE_VERIFIABLE = (1 << 1) , LLCACHE_RETRIEVE_NO_ERROR_PAGES = (1 << 2) , LLCACHE_RETRIEVE_STREAM_DATA = (1 << 3) }
 Flags for low-level cache object retrieval. More...
 
enum  llcache_event_type {
  LLCACHE_EVENT_GOT_CERTS , LLCACHE_EVENT_HAD_HEADERS , LLCACHE_EVENT_HAD_DATA , LLCACHE_EVENT_DONE ,
  LLCACHE_EVENT_ERROR , LLCACHE_EVENT_PROGRESS , LLCACHE_EVENT_REDIRECT
}
 Low-level cache event types. More...
 

Functions

nserror llcache_initialise (const struct llcache_parameters *parameters)
 Initialise the low-level cache. More...
 
void llcache_finalise (void)
 Finalise the low-level cache. More...
 
void llcache_clean (bool purge)
 Cause the low-level cache to attempt to perform cleanup. 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...
 

Detailed Description

Low-level resource cache (interface)

Definition in file llcache.h.

Typedef Documentation

◆ llcache_handle

Handle for low-level cache object.

Definition at line 37 of file llcache.h.

◆ llcache_handle_callback

typedef nserror(* llcache_handle_callback) (llcache_handle *handle, const llcache_event *event, void *pw)

Client callback for low-level cache events.

Parameters
handleHandle for which event is issued
eventEvent data
pwPointer to client-specific data
Returns
NSERROR_OK on success, appropriate error otherwise.

Definition at line 113 of file llcache.h.

◆ llcache_post_data

POST data object for low-level cache requests.

Enumeration Type Documentation

◆ llcache_event_type

Low-level cache event types.

Enumerator
LLCACHE_EVENT_GOT_CERTS 

SSL certificates arrived.

LLCACHE_EVENT_HAD_HEADERS 

Received all headers.

LLCACHE_EVENT_HAD_DATA 

Received some data.

LLCACHE_EVENT_DONE 

Finished fetching data.

LLCACHE_EVENT_ERROR 

An error occurred during fetch.

LLCACHE_EVENT_PROGRESS 

Fetch progress update.

LLCACHE_EVENT_REDIRECT 

Fetch URL redirect occured.

Definition at line 67 of file llcache.h.

◆ llcache_retrieve_flag

Flags for low-level cache object retrieval.

Enumerator
LLCACHE_RETRIEVE_FORCE_FETCH 

Force a new fetch.

LLCACHE_RETRIEVE_VERIFIABLE 

Requested URL was verified.

No error pages

LLCACHE_RETRIEVE_NO_ERROR_PAGES 

Stream data (implies that object is not cacheable)

LLCACHE_RETRIEVE_STREAM_DATA 

Definition at line 52 of file llcache.h.

Function Documentation

◆ 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_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_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: