~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to modules/cache/mod_cache.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
17
/**
 
18
 * @file mod_cache.h
 
19
 * @brief Main include file for the Apache Transparent Cache
 
20
 *
 
21
 * @defgroup MOD_CACHE mod_cache
 
22
 * @ingroup  APACHE_MODS
 
23
 * @{
 
24
 */
 
25
 
 
26
#ifndef MOD_CACHE_H
 
27
#define MOD_CACHE_H 
 
28
 
 
29
#define CORE_PRIVATE
 
30
 
 
31
#include "apr_hooks.h"
 
32
#include "apr.h"
 
33
#include "apr_lib.h"
 
34
#include "apr_strings.h"
 
35
#include "apr_buckets.h"
 
36
#include "apr_md5.h"
 
37
#include "apr_pools.h"
 
38
#include "apr_strings.h"
 
39
#include "apr_optional.h"
 
40
#define APR_WANT_STRFUNC
 
41
#include "apr_want.h"
 
42
 
 
43
#include "httpd.h"
 
44
#include "http_config.h"
 
45
#include "ap_config.h"
 
46
#include "http_core.h"
 
47
#include "http_protocol.h"
 
48
#include "http_request.h"
 
49
#include "http_vhost.h"
 
50
#include "http_main.h"
 
51
#include "http_log.h"
 
52
#include "http_connection.h"
 
53
#include "util_filter.h"
 
54
#include "apr_date.h"
 
55
#include "apr_uri.h"
 
56
 
 
57
#ifdef HAVE_NETDB_H
 
58
#include <netdb.h>
 
59
#endif
 
60
 
 
61
#ifdef HAVE_SYS_SOCKET_H
 
62
#include <sys/socket.h>
 
63
#endif
 
64
 
 
65
#ifdef HAVE_NETINET_IN_H
 
66
#include <netinet/in.h>
 
67
#endif
 
68
 
 
69
#ifdef HAVE_ARPA_INET_H
 
70
#include <arpa/inet.h>
 
71
#endif
 
72
 
 
73
#include "apr_atomic.h"
 
74
 
 
75
#ifndef MAX
 
76
#define MAX(a,b)                ((a) > (b) ? (a) : (b))
 
77
#endif
 
78
#ifndef MIN
 
79
#define MIN(a,b)                ((a) < (b) ? (a) : (b))
 
80
#endif
 
81
 
 
82
#define MSEC_ONE_DAY    ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */
 
83
#define MSEC_ONE_HR     ((apr_time_t)(3600*APR_USEC_PER_SEC))  /* one hour, in microseconds */
 
84
#define MSEC_ONE_MIN    ((apr_time_t)(60*APR_USEC_PER_SEC))    /* one minute, in microseconds */
 
85
#define MSEC_ONE_SEC    ((apr_time_t)(APR_USEC_PER_SEC))       /* one second, in microseconds */
 
86
#define DEFAULT_CACHE_MAXEXPIRE MSEC_ONE_DAY
 
87
#define DEFAULT_CACHE_EXPIRE    MSEC_ONE_HR
 
88
#define DEFAULT_CACHE_LMFACTOR  (0.1)
 
89
 
 
90
/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and 
 
91
 * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
 
92
 */
 
93
#if !defined(WIN32)
 
94
#define CACHE_DECLARE(type)            type
 
95
#define CACHE_DECLARE_NONSTD(type)     type
 
96
#define CACHE_DECLARE_DATA
 
97
#elif defined(CACHE_DECLARE_STATIC)
 
98
#define CACHE_DECLARE(type)            type __stdcall
 
99
#define CACHE_DECLARE_NONSTD(type)     type
 
100
#define CACHE_DECLARE_DATA
 
101
#elif defined(CACHE_DECLARE_EXPORT)
 
102
#define CACHE_DECLARE(type)            __declspec(dllexport) type __stdcall
 
103
#define CACHE_DECLARE_NONSTD(type)     __declspec(dllexport) type
 
104
#define CACHE_DECLARE_DATA             __declspec(dllexport)
 
105
#else
 
106
#define CACHE_DECLARE(type)            __declspec(dllimport) type __stdcall
 
107
#define CACHE_DECLARE_NONSTD(type)     __declspec(dllimport) type
 
108
#define CACHE_DECLARE_DATA             __declspec(dllimport)
 
109
#endif
 
110
 
 
111
struct cache_enable {
 
112
    apr_uri_t url;
 
113
    const char *type;
 
114
    apr_size_t pathlen;
 
115
};
 
116
 
 
117
struct cache_disable {
 
118
    apr_uri_t url;
 
119
    apr_size_t pathlen;
 
120
};
 
121
 
 
122
/* static information about the local cache */
 
123
typedef struct {
 
124
    apr_array_header_t *cacheenable;    /* URLs to cache */
 
125
    apr_array_header_t *cachedisable;   /* URLs not to cache */
 
126
    /* Maximum time to keep cached files in msecs */
 
127
    apr_time_t maxex;
 
128
    int maxex_set;
 
129
    /* default time to keep cached file in msecs */
 
130
    apr_time_t defex;
 
131
    int defex_set;
 
132
    /* factor for estimating expires date */
 
133
    double factor;
 
134
    int factor_set;
 
135
    /** ignore the last-modified header when deciding to cache this request */
 
136
    int no_last_mod_ignore_set;
 
137
    int no_last_mod_ignore; 
 
138
    /** ignore client's requests for uncached responses */
 
139
    int ignorecachecontrol;
 
140
    int ignorecachecontrol_set;
 
141
    /** ignore Cache-Control: private header from server */
 
142
    int store_private;
 
143
    int store_private_set;
 
144
    /** ignore Cache-Control: no-store header from client or server */
 
145
    int store_nostore;
 
146
    int store_nostore_set;
 
147
    /** store the headers that should not be stored in the cache */
 
148
    apr_array_header_t *ignore_headers;
 
149
    /* flag if CacheIgnoreHeader has been set */
 
150
    #define CACHE_IGNORE_HEADERS_SET   1
 
151
    #define CACHE_IGNORE_HEADERS_UNSET 0
 
152
    int ignore_headers_set;
 
153
} cache_server_conf;
 
154
 
 
155
/* cache info information */
 
156
typedef struct cache_info cache_info;
 
157
struct cache_info {
 
158
    int status;
 
159
    apr_time_t date;
 
160
    apr_time_t expire;
 
161
    apr_time_t request_time;
 
162
    apr_time_t response_time;
 
163
};
 
164
 
 
165
/* cache handle information */
 
166
 
 
167
/* XXX TODO On the next structure change/MMN bump, 
 
168
 * count must become an apr_off_t, representing
 
169
 * the potential size of disk cached objects.
 
170
 * Then dig for
 
171
 * "XXX Bad Temporary Cast - see cache_object_t notes" 
 
172
 */
 
173
typedef struct cache_object cache_object_t;
 
174
struct cache_object {
 
175
    const char *key;
 
176
    cache_object_t *next;
 
177
    cache_info info;
 
178
    /* Opaque portion (specific to the implementation) of the cache object */
 
179
    void *vobj;
 
180
    /* FIXME: These are only required for mod_mem_cache. */
 
181
    apr_size_t count;   /* Number of body bytes written to the cache so far */
 
182
    int complete;
 
183
    apr_uint32_t refcount;  /* refcount and bit flag to cleanup object */
 
184
};
 
185
 
 
186
typedef struct cache_handle cache_handle_t;
 
187
struct cache_handle {
 
188
    cache_object_t *cache_obj;
 
189
    apr_table_t *req_hdrs;        /* cached request headers */
 
190
    apr_table_t *resp_hdrs;       /* cached response headers */
 
191
};
 
192
 
 
193
#define CACHE_PROVIDER_GROUP "cache"
 
194
 
 
195
typedef struct {
 
196
    int (*remove_entity) (cache_handle_t *h);
 
197
    apr_status_t (*store_headers)(cache_handle_t *h, request_rec *r, cache_info *i);
 
198
    apr_status_t (*store_body)(cache_handle_t *h, request_rec *r, apr_bucket_brigade *b);
 
199
    apr_status_t (*recall_headers) (cache_handle_t *h, request_rec *r);
 
200
    apr_status_t (*recall_body) (cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb); 
 
201
    int (*create_entity) (cache_handle_t *h, request_rec *r,
 
202
                           const char *urlkey, apr_off_t len);
 
203
    int (*open_entity) (cache_handle_t *h, request_rec *r,
 
204
                           const char *urlkey);
 
205
    int (*remove_url) (cache_handle_t *h, apr_pool_t *p);
 
206
} cache_provider;
 
207
 
 
208
/* A linked-list of authn providers. */
 
209
typedef struct cache_provider_list cache_provider_list;
 
210
 
 
211
struct cache_provider_list {
 
212
    const char *provider_name;
 
213
    const cache_provider *provider;
 
214
    cache_provider_list *next;
 
215
};
 
216
 
 
217
/* per request cache information */
 
218
typedef struct {
 
219
    cache_provider_list *providers;     /* possible cache providers */
 
220
    const cache_provider *provider;     /* current cache provider */
 
221
    const char *provider_name;          /* current cache provider name */
 
222
    int fresh;                          /* is the entitey fresh? */
 
223
    cache_handle_t *handle;             /* current cache handle */
 
224
    cache_handle_t *stale_handle;       /* stale cache handle */
 
225
    apr_table_t *stale_headers;         /* original request headers. */
 
226
    int in_checked;                     /* CACHE_SAVE must cache the entity */
 
227
    int block_response;                 /* CACHE_SAVE must block response. */
 
228
    apr_bucket_brigade *saved_brigade;  /* copy of partial response */
 
229
    apr_off_t saved_size;               /* length of saved_brigade */
 
230
    apr_time_t exp;                     /* expiration */
 
231
    apr_time_t lastmod;                 /* last-modified time */
 
232
    cache_info *info;                   /* current cache info */
 
233
    ap_filter_t *remove_url_filter;     /* Enable us to remove the filter */
 
234
} cache_request_rec;
 
235
 
 
236
 
 
237
/* cache_util.c */
 
238
/* do a HTTP/1.1 age calculation */
 
239
CACHE_DECLARE(apr_time_t) ap_cache_current_age(cache_info *info, const apr_time_t age_value,
 
240
                                               apr_time_t now);
 
241
 
 
242
/**
 
243
 * Check the freshness of the cache object per RFC2616 section 13.2 (Expiration Model)
 
244
 * @param h cache_handle_t
 
245
 * @param r request_rec
 
246
 * @return 0 ==> cache object is stale, 1 ==> cache object is fresh
 
247
 */
 
248
CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, request_rec *r);
 
249
 
 
250
/**
 
251
 * Merge in cached headers into the response
 
252
 * @param h cache_handle_t
 
253
 * @param r request_rec
 
254
 * @param preserve_orig If 1, the values in r->headers_out are preserved.
 
255
 *        Otherwise, they are overwritten by the cached value.
 
256
 */
 
257
CACHE_DECLARE(void) ap_cache_accept_headers(cache_handle_t *h, request_rec *r,
 
258
                                            int preserve_orig);
 
259
 
 
260
CACHE_DECLARE(apr_time_t) ap_cache_hex2usec(const char *x);
 
261
CACHE_DECLARE(void) ap_cache_usec2hex(apr_time_t j, char *y);
 
262
CACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels, 
 
263
                                             int dirlength, 
 
264
                                             const char *name);
 
265
CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf *conf, apr_uri_t uri);
 
266
CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list,
 
267
                                    const char *key, char **val);
 
268
CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
 
269
 
 
270
/* Create a new table consisting of those elements from a request_rec's
 
271
 * headers_out that are allowed to be stored in a cache
 
272
 */
 
273
CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool,
 
274
                                                        apr_table_t *t,
 
275
                                                        server_rec *s);
 
276
 
 
277
/**
 
278
 * cache_storage.c
 
279
 */
 
280
int cache_remove_url(cache_request_rec *cache, apr_pool_t *p);
 
281
int cache_create_entity(request_rec *r, apr_off_t size);
 
282
int cache_select(request_rec *r);
 
283
apr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
 
284
/**
 
285
 * create a key for the cache based on the request record
 
286
 * this is the 'default' version, which can be overridden by a default function
 
287
 */
 
288
const char* cache_create_key( request_rec*r );
 
289
 
 
290
/*
 
291
apr_status_t cache_store_entity_headers(cache_handle_t *h, request_rec *r, cache_info *info);
 
292
apr_status_t cache_store_entity_body(cache_handle_t *h, request_rec *r, apr_bucket_brigade *bb);
 
293
 
 
294
apr_status_t cache_recall_entity_headers(cache_handle_t *h, request_rec *r);
 
295
apr_status_t cache_recall_entity_body(cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
 
296
*/
 
297
 
 
298
/* hooks */
 
299
 
 
300
/* Create a set of CACHE_DECLARE(type), CACHE_DECLARE_NONSTD(type) and 
 
301
 * CACHE_DECLARE_DATA with appropriate export and import tags for the platform
 
302
 */
 
303
#if !defined(WIN32)
 
304
#define CACHE_DECLARE(type)            type
 
305
#define CACHE_DECLARE_NONSTD(type)     type
 
306
#define CACHE_DECLARE_DATA
 
307
#elif defined(CACHE_DECLARE_STATIC)
 
308
#define CACHE_DECLARE(type)            type __stdcall
 
309
#define CACHE_DECLARE_NONSTD(type)     type
 
310
#define CACHE_DECLARE_DATA
 
311
#elif defined(CACHE_DECLARE_EXPORT)
 
312
#define CACHE_DECLARE(type)            __declspec(dllexport) type __stdcall
 
313
#define CACHE_DECLARE_NONSTD(type)     __declspec(dllexport) type
 
314
#define CACHE_DECLARE_DATA             __declspec(dllexport)
 
315
#else
 
316
#define CACHE_DECLARE(type)            __declspec(dllimport) type __stdcall
 
317
#define CACHE_DECLARE_NONSTD(type)     __declspec(dllimport) type
 
318
#define CACHE_DECLARE_DATA             __declspec(dllimport)
 
319
#endif
 
320
 
 
321
APR_DECLARE_OPTIONAL_FN(apr_status_t, 
 
322
                        ap_cache_generate_key, 
 
323
                        (request_rec *r, apr_pool_t*p, char**key ));
 
324
 
 
325
 
 
326
#endif /*MOD_CACHE_H*/
 
327
/** @} */