00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00026 #ifndef MOD_CACHE_H
00027 #define MOD_CACHE_H
00028
00029 #define CORE_PRIVATE
00030
00031 #include "apr_hooks.h"
00032 #include "apr.h"
00033 #include "apr_lib.h"
00034 #include "apr_strings.h"
00035 #include "apr_buckets.h"
00036 #include "apr_md5.h"
00037 #include "apr_pools.h"
00038 #include "apr_strings.h"
00039 #include "apr_optional.h"
00040 #define APR_WANT_STRFUNC
00041 #include "apr_want.h"
00042
00043 #include "httpd.h"
00044 #include "http_config.h"
00045 #include "ap_config.h"
00046 #include "http_core.h"
00047 #include "http_protocol.h"
00048 #include "http_request.h"
00049 #include "http_vhost.h"
00050 #include "http_main.h"
00051 #include "http_log.h"
00052 #include "http_connection.h"
00053 #include "util_filter.h"
00054 #include "apr_date.h"
00055 #include "apr_uri.h"
00056
00057 #ifdef HAVE_NETDB_H
00058 #include <netdb.h>
00059 #endif
00060
00061 #ifdef HAVE_SYS_SOCKET_H
00062 #include <sys/socket.h>
00063 #endif
00064
00065 #ifdef HAVE_NETINET_IN_H
00066 #include <netinet/in.h>
00067 #endif
00068
00069 #ifdef HAVE_ARPA_INET_H
00070 #include <arpa/inet.h>
00071 #endif
00072
00073 #include "apr_atomic.h"
00074
00075 #ifndef MAX
00076 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00077 #endif
00078 #ifndef MIN
00079 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00080 #endif
00081
00082 #define MSEC_ONE_DAY ((apr_time_t)(86400*APR_USEC_PER_SEC))
00083 #define MSEC_ONE_HR ((apr_time_t)(3600*APR_USEC_PER_SEC))
00084 #define MSEC_ONE_MIN ((apr_time_t)(60*APR_USEC_PER_SEC))
00085 #define MSEC_ONE_SEC ((apr_time_t)(APR_USEC_PER_SEC))
00086 #define DEFAULT_CACHE_MAXEXPIRE MSEC_ONE_DAY
00087 #define DEFAULT_CACHE_EXPIRE MSEC_ONE_HR
00088 #define DEFAULT_CACHE_LMFACTOR (0.1)
00089
00090
00091
00092
00093 #if !defined(WIN32)
00094 #define CACHE_DECLARE(type) type
00095 #define CACHE_DECLARE_NONSTD(type) type
00096 #define CACHE_DECLARE_DATA
00097 #elif defined(CACHE_DECLARE_STATIC)
00098 #define CACHE_DECLARE(type) type __stdcall
00099 #define CACHE_DECLARE_NONSTD(type) type
00100 #define CACHE_DECLARE_DATA
00101 #elif defined(CACHE_DECLARE_EXPORT)
00102 #define CACHE_DECLARE(type) __declspec(dllexport) type __stdcall
00103 #define CACHE_DECLARE_NONSTD(type) __declspec(dllexport) type
00104 #define CACHE_DECLARE_DATA __declspec(dllexport)
00105 #else
00106 #define CACHE_DECLARE(type) __declspec(dllimport) type __stdcall
00107 #define CACHE_DECLARE_NONSTD(type) __declspec(dllimport) type
00108 #define CACHE_DECLARE_DATA __declspec(dllimport)
00109 #endif
00110
00111 struct cache_enable {
00112 apr_uri_t url;
00113 const char *type;
00114 apr_size_t pathlen;
00115 };
00116
00117 struct cache_disable {
00118 apr_uri_t url;
00119 apr_size_t pathlen;
00120 };
00121
00122
00123 typedef struct {
00124 apr_array_header_t *cacheenable;
00125 apr_array_header_t *cachedisable;
00126
00127 apr_time_t maxex;
00128 int maxex_set;
00129
00130 apr_time_t defex;
00131 int defex_set;
00132
00133 double factor;
00134 int factor_set;
00136 int no_last_mod_ignore_set;
00137 int no_last_mod_ignore;
00139 int ignorecachecontrol;
00140 int ignorecachecontrol_set;
00142 int store_private;
00143 int store_private_set;
00145 int store_nostore;
00146 int store_nostore_set;
00148 apr_array_header_t *ignore_headers;
00149
00150 #define CACHE_IGNORE_HEADERS_SET 1
00151 #define CACHE_IGNORE_HEADERS_UNSET 0
00152 int ignore_headers_set;
00154 int ignorequerystring;
00155 int ignorequerystring_set;
00156 } cache_server_conf;
00157
00158
00159 typedef struct cache_info cache_info;
00160 struct cache_info {
00161 int status;
00162 apr_time_t date;
00163 apr_time_t expire;
00164 apr_time_t request_time;
00165 apr_time_t response_time;
00166 };
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 typedef struct cache_object cache_object_t;
00177 struct cache_object {
00178 const char *key;
00179 cache_object_t *next;
00180 cache_info info;
00181
00182 void *vobj;
00183
00184 apr_size_t count;
00185 int complete;
00186 apr_uint32_t refcount;
00187 };
00188
00189 typedef struct cache_handle cache_handle_t;
00190 struct cache_handle {
00191 cache_object_t *cache_obj;
00192 apr_table_t *req_hdrs;
00193 apr_table_t *resp_hdrs;
00194 };
00195
00196 #define CACHE_PROVIDER_GROUP "cache"
00197
00198 typedef struct {
00199 int (*remove_entity) (cache_handle_t *h);
00200 apr_status_t (*store_headers)(cache_handle_t *h, request_rec *r, cache_info *i);
00201 apr_status_t (*store_body)(cache_handle_t *h, request_rec *r, apr_bucket_brigade *b);
00202 apr_status_t (*recall_headers) (cache_handle_t *h, request_rec *r);
00203 apr_status_t (*recall_body) (cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
00204 int (*create_entity) (cache_handle_t *h, request_rec *r,
00205 const char *urlkey, apr_off_t len);
00206 int (*open_entity) (cache_handle_t *h, request_rec *r,
00207 const char *urlkey);
00208 int (*remove_url) (cache_handle_t *h, apr_pool_t *p);
00209 } cache_provider;
00210
00211
00212 typedef struct cache_provider_list cache_provider_list;
00213
00214 struct cache_provider_list {
00215 const char *provider_name;
00216 const cache_provider *provider;
00217 cache_provider_list *next;
00218 };
00219
00220
00221 typedef struct {
00222 cache_provider_list *providers;
00223 const cache_provider *provider;
00224 const char *provider_name;
00225 int fresh;
00226 cache_handle_t *handle;
00227 cache_handle_t *stale_handle;
00228 apr_table_t *stale_headers;
00229 int in_checked;
00230 int block_response;
00231 apr_bucket_brigade *saved_brigade;
00232 apr_off_t saved_size;
00233 apr_time_t exp;
00234 apr_time_t lastmod;
00235 cache_info *info;
00236 ap_filter_t *remove_url_filter;
00237 char *key;
00238
00239
00240 } cache_request_rec;
00241
00242
00243
00244
00245 CACHE_DECLARE(apr_time_t) ap_cache_current_age(cache_info *info, const apr_time_t age_value,
00246 apr_time_t now);
00247
00254 CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, request_rec *r);
00255
00263 CACHE_DECLARE(void) ap_cache_accept_headers(cache_handle_t *h, request_rec *r,
00264 int preserve_orig);
00265
00266 CACHE_DECLARE(apr_time_t) ap_cache_hex2usec(const char *x);
00267 CACHE_DECLARE(void) ap_cache_usec2hex(apr_time_t j, char *y);
00268 CACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels,
00269 int dirlength,
00270 const char *name);
00271 CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf *conf, apr_uri_t uri);
00272 CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list,
00273 const char *key, char **val);
00274 CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
00275
00276
00277
00278
00279 CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool,
00280 apr_table_t *t,
00281 server_rec *s);
00282
00286 int cache_remove_url(cache_request_rec *cache, apr_pool_t *p);
00287 int cache_create_entity(request_rec *r, apr_off_t size);
00288 int cache_select(request_rec *r);
00289 apr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
00294 const char* cache_create_key( request_rec*r );
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 #if !defined(WIN32)
00310 #define CACHE_DECLARE(type) type
00311 #define CACHE_DECLARE_NONSTD(type) type
00312 #define CACHE_DECLARE_DATA
00313 #elif defined(CACHE_DECLARE_STATIC)
00314 #define CACHE_DECLARE(type) type __stdcall
00315 #define CACHE_DECLARE_NONSTD(type) type
00316 #define CACHE_DECLARE_DATA
00317 #elif defined(CACHE_DECLARE_EXPORT)
00318 #define CACHE_DECLARE(type) __declspec(dllexport) type __stdcall
00319 #define CACHE_DECLARE_NONSTD(type) __declspec(dllexport) type
00320 #define CACHE_DECLARE_DATA __declspec(dllexport)
00321 #else
00322 #define CACHE_DECLARE(type) __declspec(dllimport) type __stdcall
00323 #define CACHE_DECLARE_NONSTD(type) __declspec(dllimport) type
00324 #define CACHE_DECLARE_DATA __declspec(dllimport)
00325 #endif
00326
00327 APR_DECLARE_OPTIONAL_FN(apr_status_t,
00328 ap_cache_generate_key,
00329 (request_rec *r, apr_pool_t*p, char**key ));
00330
00331
00332 #endif
00333