Apache HTTPD
cache_util.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
26#ifndef CACHE_UTIL_H
27#define CACHE_UTIL_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "mod_cache.h"
34
35#include "apr_hooks.h"
36#include "apr.h"
37#include "apr_lib.h"
38#include "apr_strings.h"
39#include "apr_buckets.h"
40#include "apr_md5.h"
41#include "apr_pools.h"
42#include "apr_strings.h"
43#include "apr_optional.h"
44#define APR_WANT_STRFUNC
45#include "apr_want.h"
46
47#include "httpd.h"
48#include "http_config.h"
49#include "ap_config.h"
50#include "http_core.h"
51#include "http_protocol.h"
52#include "http_request.h"
53#include "http_vhost.h"
54#include "http_main.h"
55#include "http_log.h"
56#include "http_connection.h"
57#include "util_filter.h"
58#include "apr_uri.h"
59
60#ifdef HAVE_NETDB_H
61#include <netdb.h>
62#endif
63
64#ifdef HAVE_SYS_SOCKET_H
65#include <sys/socket.h>
66#endif
67
68#ifdef HAVE_NETINET_IN_H
69#include <netinet/in.h>
70#endif
71
72#ifdef HAVE_ARPA_INET_H
73#include <arpa/inet.h>
74#endif
75
76#include "apr_atomic.h"
77
78#ifndef MAX
79#define MAX(a,b) ((a) > (b) ? (a) : (b))
80#endif
81#ifndef MIN
82#define MIN(a,b) ((a) < (b) ? (a) : (b))
83#endif
84
85#define MSEC_ONE_DAY ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */
86#define MSEC_ONE_HR ((apr_time_t)(3600*APR_USEC_PER_SEC)) /* one hour, in microseconds */
87#define MSEC_ONE_MIN ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */
88#define MSEC_ONE_SEC ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */
89
90#define DEFAULT_CACHE_MAXEXPIRE MSEC_ONE_DAY
91#define DEFAULT_CACHE_MINEXPIRE 0
92#define DEFAULT_CACHE_EXPIRE MSEC_ONE_HR
93#define DEFAULT_CACHE_LMFACTOR (0.1)
94#define DEFAULT_CACHE_MAXAGE 5
95#define DEFAULT_X_CACHE 0
96#define DEFAULT_X_CACHE_DETAIL 0
97#define DEFAULT_CACHE_STALE_ON_ERROR 1
98#define DEFAULT_CACHE_LOCKPATH "/mod_cache-lock"
99#define CACHE_LOCKNAME_KEY "mod_cache-lockname"
100#define CACHE_LOCKFILE_KEY "mod_cache-lockfile"
101#define CACHE_CTX_KEY "mod_cache-ctx"
102#define CACHE_SEPARATOR ", \t"
103
113
118
119/* static information about the local cache */
120typedef struct {
121 apr_array_header_t *cacheenable; /* URLs to cache */
122 apr_array_header_t *cachedisable; /* URLs not to cache */
127 const char *lockpath;
131 unsigned int ignorecachecontrol:1;
133 unsigned int ignorequerystring:1;
135 unsigned int quick:1;
136 /* thundering herd lock */
137 unsigned int lock:1;
138 unsigned int x_cache:1;
139 unsigned int x_cache_detail:1;
140 /* flag if CacheIgnoreHeader has been set */
141 #define CACHE_IGNORE_HEADERS_SET 1
142 #define CACHE_IGNORE_HEADERS_UNSET 0
143 unsigned int ignore_headers_set:1;
144 /* flag if CacheIgnoreURLSessionIdentifiers has been set */
145 #define CACHE_IGNORE_SESSION_ID_SET 1
146 #define CACHE_IGNORE_SESSION_ID_UNSET 0
147 unsigned int ignore_session_id_set:1;
148 unsigned int base_uri_set:1;
150 unsigned int ignorequerystring_set:1;
151 unsigned int quick_set:1;
152 unsigned int lock_set:1;
153 unsigned int lockpath_set:1;
154 unsigned int lockmaxage_set:1;
155 unsigned int x_cache_set:1;
156 unsigned int x_cache_detail_set:1;
158
159typedef struct {
160 /* Minimum time to keep cached files in msecs */
162 /* Maximum time to keep cached files in msecs */
164 /* default time to keep cached file in msecs */
166 /* factor for estimating expires date */
167 double factor;
168 /* cache enabled for this location */
170 /* cache disabled for this location */
171 unsigned int disable:1;
172 /* set X-Cache headers */
173 unsigned int x_cache:1;
174 unsigned int x_cache_detail:1;
175 /* serve stale on error */
176 unsigned int stale_on_error:1;
178 unsigned int no_last_mod_ignore:1;
180 unsigned int store_expired:1;
182 unsigned int store_private:1;
184 unsigned int store_nostore:1;
185 unsigned int minex_set:1;
186 unsigned int maxex_set:1;
187 unsigned int defex_set:1;
188 unsigned int factor_set:1;
189 unsigned int x_cache_set:1;
190 unsigned int x_cache_detail_set:1;
191 unsigned int stale_on_error_set:1;
193 unsigned int store_expired_set:1;
194 unsigned int store_private_set:1;
195 unsigned int store_nostore_set:1;
196 unsigned int enable_set:1;
197 unsigned int disable_set:1;
199
200/* A linked-list of authn providers. */
202
208
209/* per request cache information */
210typedef struct {
211 cache_provider_list *providers; /* possible cache providers */
212 const cache_provider *provider; /* current cache provider */
213 const char *provider_name; /* current cache provider name */
214 int fresh; /* is the entity fresh? */
215 cache_handle_t *handle; /* current cache handle */
216 cache_handle_t *stale_handle; /* stale cache handle */
217 apr_table_t *stale_headers; /* original request headers. */
218 int in_checked; /* CACHE_SAVE must cache the entity */
219 int block_response; /* CACHE_SAVE must block response. */
220 apr_bucket_brigade *saved_brigade; /* copy of partial response */
221 apr_off_t saved_size; /* length of saved_brigade */
222 apr_time_t exp; /* expiration */
223 apr_time_t lastmod; /* last-modified time */
224 cache_info *info; /* current cache info */
225 ap_filter_t *save_filter; /* Enable us to restore the filter on error */
226 ap_filter_t *remove_url_filter; /* Enable us to remove the filter */
227 const char *key; /* The cache key created for this
228 * request
229 */
230 apr_off_t size; /* the content length from the headers, or -1 */
231 apr_bucket_brigade *out; /* brigade to reuse for upstream responses */
232 cache_control_t control_in; /* cache control incoming */
234
243
252
261 request_rec *r);
262
285 request_rec *r);
286
301
303 cache_server_conf *conf);
304
315const char *cache_table_getm(apr_pool_t *p, const apr_table_t *t,
316 const char *key);
317
322char *cache_strqtok(char *str, const char *sep, char **last);
323
329
335
336#ifdef __cplusplus
337}
338#endif
339
340#endif /* !CACHE_UTIL_H */
Symbol export macros and hook functions.
APR Atomic Operations.
APR-UTIL Buckets/Bucket Brigades.
Apache hook functions.
APR general purpose library routines.
APR MD5 Routines.
APR-UTIL registration of functions exported by modules.
APR memory allocation.
APR Strings library.
APR-UTIL URI Routines.
APR Standard Headers Support.
request_rec * r
cache_provider_list * cache_get_providers(request_rec *r, cache_server_conf *conf)
Definition cache_util.c:184
char * cache_strqtok(char *str, const char *sep, char **last)
Definition cache_util.c:929
apr_table_t * cache_merge_headers_out(request_rec *r)
int ap_cache_check_no_cache(cache_request_rec *cache, request_rec *r)
Definition cache_util.c:450
const char * cache_table_getm(apr_pool_t *p, const apr_table_t *t, const char *key)
apr_status_t cache_remove_lock(cache_server_conf *conf, cache_request_rec *cache, request_rec *r, apr_bucket_brigade *bb)
Definition cache_util.c:390
int cache_check_freshness(cache_handle_t *h, cache_request_rec *cache, request_rec *r)
Definition cache_util.c:533
int ap_cache_check_no_store(cache_request_rec *cache, request_rec *r)
Definition cache_util.c:493
int cache_use_early_url(request_rec *r)
Definition cache_util.c:130
apr_status_t cache_try_lock(cache_server_conf *conf, cache_request_rec *cache, request_rec *r)
Definition cache_util.c:279
apr_size_t size
int apr_status_t
Definition apr_errno.h:44
const char * key
const apr_hash_t * h
Definition apr_hash.h:97
apr_interval_time_t t
const char * sep
const char char ** last
apr_int64_t apr_time_t
Definition apr_time.h:45
Apache Configuration.
Apache connection library.
CORE HTTP Daemon.
Apache Logging library.
Command line options.
HTTP protocol handling.
Apache Request library.
Virtual Host package.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
Main include file for the Apache Transparent Cache.
The representation of a filter chain.
unsigned int store_nostore_set
Definition cache_util.h:195
unsigned int maxex_set
Definition cache_util.h:186
apr_array_header_t * cacheenable
Definition cache_util.h:169
unsigned int store_private
Definition cache_util.h:182
unsigned int store_private_set
Definition cache_util.h:194
unsigned int no_last_mod_ignore
Definition cache_util.h:178
unsigned int store_expired
Definition cache_util.h:180
unsigned int defex_set
Definition cache_util.h:187
unsigned int factor_set
Definition cache_util.h:188
unsigned int store_nostore
Definition cache_util.h:184
unsigned int enable_set
Definition cache_util.h:196
unsigned int store_expired_set
Definition cache_util.h:193
unsigned int minex_set
Definition cache_util.h:185
unsigned int stale_on_error_set
Definition cache_util.h:191
unsigned int stale_on_error
Definition cache_util.h:176
unsigned int disable_set
Definition cache_util.h:197
apr_time_t defex
Definition cache_util.h:165
apr_time_t maxex
Definition cache_util.h:163
unsigned int no_last_mod_ignore_set
Definition cache_util.h:192
unsigned int x_cache_detail
Definition cache_util.h:174
unsigned int x_cache
Definition cache_util.h:173
unsigned int x_cache_detail_set
Definition cache_util.h:190
apr_time_t minex
Definition cache_util.h:161
unsigned int x_cache_set
Definition cache_util.h:189
unsigned int disable
Definition cache_util.h:171
apr_uri_t url
Definition cache_util.h:115
apr_size_t pathlen
Definition cache_util.h:116
apr_uri_t url
Definition cache_util.h:109
const char * type
Definition cache_util.h:110
apr_size_t pathlen
Definition cache_util.h:111
const char * provider_name
Definition cache_util.h:204
const cache_provider * provider
Definition cache_util.h:205
cache_provider_list * next
Definition cache_util.h:206
ap_filter_t * remove_url_filter
Definition cache_util.h:226
apr_bucket_brigade * out
Definition cache_util.h:231
cache_handle_t * stale_handle
Definition cache_util.h:216
const char * key
Definition cache_util.h:227
apr_bucket_brigade * saved_brigade
Definition cache_util.h:220
apr_table_t * stale_headers
Definition cache_util.h:217
const cache_provider * provider
Definition cache_util.h:212
cache_control_t control_in
Definition cache_util.h:232
cache_info * info
Definition cache_util.h:224
apr_time_t lastmod
Definition cache_util.h:223
const char * provider_name
Definition cache_util.h:213
apr_off_t saved_size
Definition cache_util.h:221
ap_filter_t * save_filter
Definition cache_util.h:225
cache_handle_t * handle
Definition cache_util.h:215
cache_provider_list * providers
Definition cache_util.h:211
apr_uri_t * base_uri
Definition cache_util.h:129
unsigned int x_cache_detail_set
Definition cache_util.h:156
unsigned int lock_set
Definition cache_util.h:152
unsigned int x_cache
Definition cache_util.h:138
unsigned int ignorequerystring
Definition cache_util.h:133
unsigned int ignorecachecontrol
Definition cache_util.h:131
unsigned int ignore_session_id_set
Definition cache_util.h:147
unsigned int ignorequerystring_set
Definition cache_util.h:150
unsigned int ignore_headers_set
Definition cache_util.h:143
unsigned int lockpath_set
Definition cache_util.h:153
apr_time_t lockmaxage
Definition cache_util.h:128
apr_array_header_t * ignore_headers
Definition cache_util.h:124
apr_array_header_t * cachedisable
Definition cache_util.h:122
unsigned int ignorecachecontrol_set
Definition cache_util.h:149
apr_array_header_t * ignore_session_id
Definition cache_util.h:126
unsigned int quick_set
Definition cache_util.h:151
unsigned int quick
Definition cache_util.h:135
unsigned int lockmaxage_set
Definition cache_util.h:154
apr_array_header_t * cacheenable
Definition cache_util.h:121
unsigned int lock
Definition cache_util.h:137
const char * lockpath
Definition cache_util.h:127
unsigned int base_uri_set
Definition cache_util.h:148
unsigned int x_cache_set
Definition cache_util.h:155
unsigned int x_cache_detail
Definition cache_util.h:139
A structure that represents the current request.
Definition httpd.h:845
#define str
Apache filter library.