NetSurf
hlcache.h
Go to the documentation of this file.
1/*
2 * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * High-level resource cache interface
22 */
23
24#ifndef NETSURF_CONTENT_HLCACHE_H_
25#define NETSURF_CONTENT_HLCACHE_H_
26
27#include "utils/errors.h"
28#include "utils/nsurl.h"
29
30#include "content/content.h"
31#include "content/llcache.h"
32
33/** High-level cache handle */
35
36/** Context for retrieving a child object */
37typedef struct hlcache_child_context {
38 const char *charset; /**< Charset of parent */
39 bool quirks; /**< Whether parent is quirky */
41
42/** High-level cache event */
43typedef struct hlcache_event {
44 content_msg type; /**< Event type */
45 union content_msg_data data; /**< Event data */
47
49 /** How frequently the background cache clean process is run (ms) */
50 unsigned int bg_clean_time;
51
53};
54
55/**
56 * Client callback for high-level cache events
57 *
58 * \param handle Handle to object generating event
59 * \param event Event data
60 * \param pw Pointer to client-specific data
61 * \return NSERROR_OK on success, appropriate error otherwise.
62 */
64 const hlcache_event *event, void *pw);
65
66/** Flags for high-level cache object retrieval */
68 /* Note: low-level cache retrieval flags occupy the bottom 16 bits of
69 * the flags word. High-level cache flags occupy the top 16 bits.
70 * To avoid confusion, high-level flags are allocated from bit 31 down.
71 */
72 /** It's permitted to convert this request into a download */
74 /* Permit content-type sniffing */
76};
77
78/**
79 * Initialise the high-level cache, preparing the llcache also.
80 *
81 * \param hlcache_parameters Settings to initialise cache with
82 * \return NSERROR_OK on success, appropriate error otherwise.
83 */
85
86/**
87 * Stop the high-level cache periodic functionality so that the
88 * exit sequence can run.
89 */
90void hlcache_stop(void);
91
92/**
93 * Finalise the high-level cache, destroying any remaining contents
94 */
95void hlcache_finalise(void);
96
97/**
98 * Retrieve a high-level cache handle for an object
99 *
100 * \param url URL of the object to retrieve handle for
101 * \param flags Object retrieval flags
102 * \param referer Referring URL, or NULL if none
103 * \param post POST data, or NULL for a GET request
104 * \param cb Callback to handle object events
105 * \param pw Pointer to client-specific data for callback
106 * \param child Child retrieval context, or NULL for top-level content
107 * \param accepted_types Bitmap of acceptable content types
108 * \param result Pointer to location to recieve cache handle
109 * \return NSERROR_OK on success, appropriate error otherwise
110 *
111 * Child contents are keyed on the tuple < URL, quirks >.
112 * The quirks field is ignored for child contents whose behaviour is not
113 * affected by quirks mode.
114 *
115 * \todo The above rules should be encoded in the handler_map.
116 *
117 * \todo Is there any way to sensibly reduce the number of parameters here?
118 */
119nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags,
120 nsurl *referer, llcache_post_data *post,
121 hlcache_handle_callback cb, void *pw,
123 content_type accepted_types, hlcache_handle **result);
124
125/**
126 * Release a high-level cache handle
127 *
128 * \param handle Handle to release
129 * \return NSERROR_OK on success, appropriate error otherwise
130 */
132
133/**
134 * Abort a high-level cache fetch
135 *
136 * \param handle Handle to abort
137 * \return NSERROR_OK on success, appropriate error otherwise
138 */
140
141/**
142 * Replace a high-level cache handle's callback
143 *
144 * \param handle Handle to replace callback of
145 * \param cb New callback routine
146 * \param pw Private data for callback
147 * \return NSERROR_OK on success, appropriate error otherwise
148 */
150 hlcache_handle_callback cb, void *pw);
151
152/**
153 * Retrieve a content object from a cache handle
154 *
155 * \param handle Cache handle to dereference
156 * \return Pointer to content object, or NULL if there is none
157 *
158 * \todo This may not be correct. Ideally, the client should never need to
159 * directly access a content object. It may, therefore, be better to provide a
160 * bunch of veneers here that take a hlcache_handle and invoke the
161 * corresponding content_ API. If there's no content object associated with the
162 * hlcache_handle (e.g. because the source data is still being fetched, so it
163 * doesn't exist yet), then these veneers would behave as a NOP. The important
164 * thing being that the client need not care about this possibility and can
165 * just call the functions with impugnity.
166 */
168
169/**
170 * Clone a high level cache handle.
171 *
172 * \param handle The handle to clone.
173 * \param result The cloned handle.
174 * \return NSERROR_OK on success, appropriate error otherwise
175 *
176 */
178
179
180#endif
STATIC char result[100]
Definition: arexx.c:77
Content handling interface.
content_type
The type of a content.
Definition: content_type.h:53
content_msg
Used in callbacks to indicate what has occurred.
Definition: content_type.h:105
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
struct hlcache_child_context hlcache_child_context
Context for retrieving a child object.
struct hlcache_event hlcache_event
High-level cache event.
nserror hlcache_initialise(const struct hlcache_parameters *hlcache_parameters)
Initialise the high-level cache, preparing the llcache also.
Definition: hlcache.c:552
nserror(* hlcache_handle_callback)(hlcache_handle *handle, const hlcache_event *event, void *pw)
Client callback for high-level cache events.
Definition: hlcache.h:63
struct content * hlcache_handle_get_content(const hlcache_handle *handle)
Retrieve a content object from a cache handle.
Definition: hlcache.c:776
void hlcache_finalise(void)
Finalise the high-level cache, destroying any remaining contents.
Definition: hlcache.c:584
hlcache_retrieve_flag
Flags for high-level cache object retrieval.
Definition: hlcache.h:67
@ HLCACHE_RETRIEVE_SNIFF_TYPE
Definition: hlcache.h:75
@ HLCACHE_RETRIEVE_MAY_DOWNLOAD
It's permitted to convert this request into a download.
Definition: hlcache.h:73
void hlcache_stop(void)
Stop the high-level cache periodic functionality so that the exit sequence can run.
Definition: hlcache.c:577
nserror hlcache_handle_abort(hlcache_handle *handle)
Abort a high-level cache fetch.
Definition: hlcache.c:786
nserror hlcache_handle_clone(hlcache_handle *handle, hlcache_handle **result)
Clone a high level cache handle.
Definition: hlcache.c:869
nserror hlcache_handle_replace_callback(hlcache_handle *handle, hlcache_handle_callback cb, void *pw)
Replace a high-level cache handle's callback.
Definition: hlcache.c:860
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
Definition: hlcache.c:740
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)
Retrieve a high-level cache handle for an object.
Definition: hlcache.c:679
Low-level resource cache (interface)
NetSurf URL handling (interface).
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Content which corresponds to a single URL.
Context for retrieving a child object.
Definition: hlcache.h:37
bool quirks
Whether parent is quirky.
Definition: hlcache.h:39
const char * charset
Charset of parent.
Definition: hlcache.h:38
High-level cache event.
Definition: hlcache.h:43
content_msg type
Event type.
Definition: hlcache.h:44
union content_msg_data data
Event data.
Definition: hlcache.h:45
High-level cache handle.
Definition: hlcache.c:66
unsigned int bg_clean_time
How frequently the background cache clean process is run (ms)
Definition: hlcache.h:50
struct llcache_parameters llcache
Definition: hlcache.h:52
Parameters to configure the low level cache.
Definition: llcache.h:129
POST data object for low-level cache requests.
Definition: llcache.h:40
Extra data for some content_msg messages.
Definition: content.h:60