1 #ifndef EL__CACHE_CACHE_H
2 #define EL__CACHE_CACHE_H
4 #include "main/object.h"
5 #include "util/lists.h"
11 /* This enum describes the level of caching of certain cache entry. That is,
12 * under what conditions shall it be reloaded, if ever. The one with lowest
13 * value is most agressively cached, however the cache is most reluctant to
14 * cache the one with highest value. */
15 /* TODO: Invert order to be more intuitive. But be careful, many tests rely on
16 * current order. --Miciah,Zas */
18 CACHE_MODE_INCREMENT
= -1,
21 CACHE_MODE_CHECK_IF_MODIFIED
,
22 CACHE_MODE_FORCE_RELOAD
,
27 OBJECT_HEAD(struct cache_entry
);
29 /* Items in this list are ALLOCATED IN A NON-STANDARD WAY! Thus if you
30 * are gonna mess with them (you shouldn't), you need to use the
32 LIST_OF(struct fragment
) frag
;
34 struct uri
*uri
; /* Identifier for the cached data */
35 struct uri
*proxy_uri
; /* Proxy identifier or same as @uri */
36 struct uri
*redirect
; /* Location we were redirected to */
38 unsigned char *head
; /* The protocol header */
39 unsigned char *content_type
; /* MIME type: <type> "/" <subtype> */
40 unsigned char *last_modified
; /* Latest modification date */
41 unsigned char *etag
; /* ETag value from the HTTP header */
42 unsigned char *ssl_info
; /* SSL ciphers used during transfer */
43 unsigned char *encoding_info
; /* Encoding used during transfer */
45 unsigned int cache_id
; /* Change each time entry is modified. */
47 time_t seconds
; /* Access time. Used by 'If-Modified-Since' */
49 off_t length
; /* The expected and complete size */
50 off_t data_size
; /* The actual size of all fragments */
52 struct listbox_item
*box_item
; /* Dialog data for cache manager */
53 #ifdef CONFIG_SCRIPTING_SPIDERMONKEY
54 struct JSObject
*jsobject
; /* Instance of cache_entry_class */
57 timeval_T max_age
; /* Expiration time */
59 unsigned int expire
:1; /* Whether to honour max_age */
60 unsigned int preformatted
:1; /* Has content been preformatted? */
61 unsigned int redirect_get
:1; /* Follow redirect using get method? */
62 unsigned int incomplete
:1; /* Has all data been downloaded? */
63 unsigned int valid
:1; /* Is cache entry usable? */
65 /* This is a mark for internal workings of garbage_collection(), whether
66 * the cache_entry should be busted or not. You are not likely to see
67 * an entry with this set to 1 in wild nature ;-). */
68 unsigned int gc_target
:1; /* The GC touch of death */
69 unsigned int cgi
:1; /* Is a CGI output? */
71 enum cache_mode cache_mode
; /* Reload condition */
75 LIST_HEAD(struct fragment
);
80 unsigned char data
[1]; /* Must be last */
84 /* Searches the cache for an entry matching the URI. Returns NULL if no one
86 struct cache_entry
*find_in_cache(struct uri
*uri
);
88 /* Searches the cache for a matching entry else a new one is added. Returns
89 * NULL if allocation fails. */
90 struct cache_entry
*get_cache_entry(struct uri
*uri
);
92 /* Searches the cache for a matching entry and checks if it is still valid and
93 * usable. Returns NULL if the @cache_mode suggests to reload it again. */
94 struct cache_entry
*get_validated_cache_entry(struct uri
*uri
, enum cache_mode cache_mode
);
96 /* Checks if a dangling cache entry pointer is still valid. */
97 int cache_entry_is_valid(struct cache_entry
*cached
);
99 /* Follow all redirects and return the resulting cache entry or NULL if there
100 * are missing redirects. */
101 struct cache_entry
*follow_cached_redirects(struct cache_entry
*cached
);
103 /* Works like find_in_cache(), but will follow cached redirects using
104 * follow_cached_redirects(). */
105 struct cache_entry
*get_redirected_cache_entry(struct uri
*uri
);
107 /* Add a fragment to the @cached object at the given @offset containing @length
108 * bytes from the @data pointer. */
109 /* Returns -1 upon error,
110 * 1 if cache entry was enlarged,
111 * 0 if only old data were overwritten. */
112 int add_fragment(struct cache_entry
*cached
, off_t offset
,
113 const unsigned char *data
, ssize_t length
);
115 /* Defragments the cache entry and returns the resulting fragment containing the
116 * complete source of all currently downloaded fragments. Returns NULL if
117 * validation of the fragments fails. */
118 struct fragment
*get_cache_fragment(struct cache_entry
*cached
);
120 /* Should be called when creation of a new cache has been completed. Most
121 * importantly, it will updates cached->incomplete. */
122 void normalize_cache_entry(struct cache_entry
*cached
, off_t length
);
124 void free_entry_to(struct cache_entry
*cached
, off_t offset
);
125 void delete_entry_content(struct cache_entry
*cached
);
126 void delete_cache_entry(struct cache_entry
*cached
);
128 /* Sets up the cache entry to redirect to a new location
129 * @location decides where to redirect to by resolving it relative to the
131 * @get controls the method should be used when handling the redirect.
132 * @incomplete will become the new value of the incomplete member if it
134 * Returns the URI being redirected to or NULL if allocation failed.
137 redirect_cache(struct cache_entry
*cached
, unsigned char *location
,
138 int get
, int incomplete
);
140 /* The garbage collector trigger. If @whole is zero, remove unused cache
141 * entries which are bigger than the cache size limit set by user. For @zero
142 * being one, remove all unused cache entries. */
143 void garbage_collection(int whole
);
145 /* Used by the resource and memory info dialogs for getting information about
147 unsigned longlong
get_cache_size(void);
148 int get_cache_entry_count(void);
149 int get_cache_entry_used_count(void);
150 int get_cache_entry_loading_count(void);