mod_cache.h revision c49200a2bdbb8fa1f2e5c3b87cc497ecdeefa8fe
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* ====================================================================
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * The Apache Software License, Version 1.1
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen *
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * reserved.
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen *
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Redistribution and use in source and binary forms, with or without
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * modification, are permitted provided that the following conditions
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * are met:
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen *
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 1. Redistributions of source code must retain the above copyright
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * notice, this list of conditions and the following disclaimer.
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen *
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 2. Redistributions in binary form must reproduce the above copyright
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * notice, this list of conditions and the following disclaimer in
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * the documentation and/or other materials provided with the
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * distribution.
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen *
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 3. The end-user documentation included with the redistribution,
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * if any, must include the following acknowledgment:
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * "This product includes software developed by the
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Apache Software Foundation (http://www.apache.org/)."
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Alternately, this acknowledgment may appear in the software itself,
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * if and wherever such third-party acknowledgments normally appear.
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen *
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 4. The names "Apache" and "Apache Software Foundation" must
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * not be used to endorse or promote products derived from this
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen * software without prior written permission. For written
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * permission, please contact apache@apache.org.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen * 5. Products derived from this software may not be called "Apache",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * nor may "Apache" appear in their name, without prior written
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * permission of the Apache Software Foundation.
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen *
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen * SUCH DAMAGE.
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen * ====================================================================
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen *
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen * This software consists of voluntary contributions made by many
d5bae4060a1ba3fe663991169de7102f81039304Timo Sirainen * individuals on behalf of the Apache Software Foundation. For more
d5bae4060a1ba3fe663991169de7102f81039304Timo Sirainen * information on the Apache Software Foundation, please see
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * <http://www.apache.org/>.
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Portions of this software are based upon public domain software
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * originally written at the National Center for Supercomputing Applications,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * University of Illinois, Urbana-Champaign.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
1930b9fae508a90de5f08fcd74602cbe3a5a5964Timo Sirainen#ifndef MOD_CACHE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MOD_CACHE_H
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/*
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Main include file for the Apache Transparent Cache
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen */
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen#define CORE_PRIVATE
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen
ee1681a053a515048d82fb57c366c26696fa0a33Timo Sirainen#include "apr_hooks.h"
ee1681a053a515048d82fb57c366c26696fa0a33Timo Sirainen#include "apr.h"
ee1681a053a515048d82fb57c366c26696fa0a33Timo Sirainen#include "apr_compat.h"
d5bae4060a1ba3fe663991169de7102f81039304Timo Sirainen#include "apr_lib.h"
ee1681a053a515048d82fb57c366c26696fa0a33Timo Sirainen#include "apr_strings.h"
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen#include "apr_buckets.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "apr_md5.h"
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen#include "apr_pools.h"
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen#include "apr_strings.h"
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen#include "apr_optional.h"
033557e1c8ebec5ae31f2f24fab90226a1945168Timo Sirainen#define APR_WANT_STRFUNC
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen#include "apr_want.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
dc4e0821e709d93c8504e50b4ba0aaeb5ce9e032Timo Sirainen#include "httpd.h"
dc4e0821e709d93c8504e50b4ba0aaeb5ce9e032Timo Sirainen#include "http_config.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "ap_config.h"
0360636eced27e96661f210828d1203871e6c47cTimo Sirainen#include "http_core.h"
5b440b4d921cb1a36d74b4082599ccd3bb0f0401Timo Sirainen#include "http_protocol.h"
819e20e6f108db20751e19784ee5a091b3f50046Timo Sirainen#include "http_request.h"
d5bae4060a1ba3fe663991169de7102f81039304Timo Sirainen#include "http_vhost.h"
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen#include "http_main.h"
033557e1c8ebec5ae31f2f24fab90226a1945168Timo Sirainen#include "http_log.h"
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen#include "http_connection.h"
c0bfb67ba32064347bac3241f1aac9b8a809e2f1Timo Sirainen#include "util_filter.h"
d5bae4060a1ba3fe663991169de7102f81039304Timo Sirainen#include "apr_date.h"
b6ccb2a38287c42aa53f66a927a6ada9d324b0beTimo Sirainen#include "apr_uri.h"
033557e1c8ebec5ae31f2f24fab90226a1945168Timo Sirainen
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen#ifdef HAVE_NETDB_H
a6249a80d437771867cf654ae9d11f8418c9d07bTimo Sirainen#include <netdb.h>
da8115ebacf055f87ec71ae1155a421452f2e0d5Timo Sirainen#endif
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen
c0bfb67ba32064347bac3241f1aac9b8a809e2f1Timo Sirainen#ifdef HAVE_SYS_SOCKET_H
a0b92d47480ac4135b5dec900c4358defbb3e0e6Timo Sirainen#include <sys/socket.h>
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#endif
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#ifdef HAVE_NETINET_IN_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include <netinet/in.h>
e32cf1b4430c4a5f28c9b5bb8b1366e7b06ed68dTimo Sirainen#endif
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
033557e1c8ebec5ae31f2f24fab90226a1945168Timo Sirainen#ifdef HAVE_ARPA_INET_H
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen#include <arpa/inet.h>
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#endif
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
3054cbf69a94ca08123ca3a8d6a2c19a1784e11dTimo Sirainen#ifndef MAX
38da5c23b0a8b4012e79fcf647a8749786c83c51Timo Sirainen#define MAX(a,b) ((a) > (b) ? (a) : (b))
bb592fc58fe5c3e81ad941637fbb30d1d1cd8694Timo Sirainen#endif
b7b81543899e306c71e6152516d8698416162bcbTimo Sirainen#ifndef MIN
b7b81543899e306c71e6152516d8698416162bcbTimo Sirainen#define MIN(a,b) ((a) < (b) ? (a) : (b))
d67f54632110cfb6aafe2d7cd1f99b031c0b208aTimo Sirainen#endif
2087637d10ad94ea029fe055f8ee55cd594955a8Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* default completion is 60% */
1582b4d531679849bba299c17b6ec9402b7df67dTimo Sirainen#define DEFAULT_CACHE_COMPLETION (60)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MAX_URL_LENGTH 1024
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MSEC_ONE_DAY ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MSEC_ONE_HR ((apr_time_t)(3600*APR_USEC_PER_SEC)) /* one hour, in microseconds */
dc4e0821e709d93c8504e50b4ba0aaeb5ce9e032Timo Sirainen#define MSEC_ONE_MIN ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen#define MSEC_ONE_SEC ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */
dc4e0821e709d93c8504e50b4ba0aaeb5ce9e032Timo Sirainen#define DEFAULT_CACHE_MAXEXPIRE MSEC_ONE_DAY
dc4e0821e709d93c8504e50b4ba0aaeb5ce9e032Timo Sirainen#define DEFAULT_CACHE_EXPIRE MSEC_ONE_HR
dc4e0821e709d93c8504e50b4ba0aaeb5ce9e032Timo Sirainen#define DEFAULT_CACHE_LMFACTOR (0.1)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
aba2f05e938a7f635b3f114d56c7c3413ee858feTimo Sirainen * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen */
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen#if !defined(WIN32)
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen#define CACHE_DECLARE(type) type
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen#define CACHE_DECLARE_NONSTD(type) type
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen#define CACHE_DECLARE_DATA
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen#elif defined(CACHE_DECLARE_STATIC)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE(type) type __stdcall
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen#define CACHE_DECLARE_NONSTD(type) type
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen#define CACHE_DECLARE_DATA
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen#elif defined(CACHE_DECLARE_EXPORT)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE(type) __declspec(dllexport) type __stdcall
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllexport) type
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen#define CACHE_DECLARE_DATA __declspec(dllexport)
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen#else
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE(type) __declspec(dllimport) type __stdcall
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllimport) type
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen#define CACHE_DECLARE_DATA __declspec(dllimport)
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen#endif
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainenstruct cache_enable {
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen const char *url;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *type;
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainenstruct cache_disable {
eb99fc24b7d1b2abb6b9217e2b732595069c908eTimo Sirainen const char *url;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen};
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen/* static information about the local cache */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainentypedef struct {
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen int cacheon; /* Cache enabled? */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen int cacheon_set;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_array_header_t *cacheenable; /* URLs to cache */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_array_header_t *cachedisable; /* URLs not to cache */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_time_t maxex; /* Maximum time to keep cached files in msecs */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen int maxex_set;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_time_t defex; /* default time to keep cached file in msecs */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen int defex_set;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen double factor; /* factor for estimating expires date */
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen int factor_set;
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen int complete; /* Force cache completion after this point */
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen int complete_set;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /** ignore the last-modified header when deciding to cache this request */
d67ac5f76cc02c227f4997878bb4aef48ee298faTimo Sirainen int no_last_mod_ignore_set;
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen int no_last_mod_ignore;
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen /** ignore client's requests for uncached responses */
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen int ignorecachecontrol;
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen int ignorecachecontrol_set;
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen} cache_server_conf;
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen/* cache info information */
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainentypedef struct cache_info cache_info;
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainenstruct cache_info {
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen char *content_type;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen char *etag;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen char *lastmods; /* last modified of cache entity */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen char *filename;
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen apr_time_t date;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_time_t lastmod;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen char lastmod_str[APR_RFC822_DATE_LEN];
d77c309fccbc6a7594f8cb08fb01009fa613c568Timo Sirainen apr_time_t expire;
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen apr_time_t request_time;
da8115ebacf055f87ec71ae1155a421452f2e0d5Timo Sirainen apr_time_t response_time;
8a6fc472a12c5ec09e2bd19f1b3acd553d75ff91Timo Sirainen apr_size_t len;
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen};
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen/* cache handle information */
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainentypedef struct cache_object cache_object_t;
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainenstruct cache_object {
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen char *key;
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen cache_object_t *next;
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen cache_info info;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void *vobj; /* Opaque portion (specific to the cache implementation) of the cache object */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen apr_size_t count; /* Number of body bytes written to the cache so far */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int complete;
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen};
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainentypedef struct cache_handle cache_handle_t;
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainenstruct cache_handle {
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen cache_object_t *cache_obj;
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen int (*remove_entity) (cache_handle_t *h);
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen apr_status_t (*write_headers)(cache_handle_t *h, request_rec *r, cache_info *i);
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen apr_status_t (*write_body)(cache_handle_t *h, request_rec *r, apr_bucket_brigade *b);
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen apr_status_t (*read_headers) (cache_handle_t *h, request_rec *r);
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen apr_status_t (*read_body) (cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen};
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen/* per request cache information */
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainentypedef struct {
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen const char *types; /* the types of caches allowed */
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen const char *type; /* the type of cache selected */
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen int fresh; /* is the entitey fresh? */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen cache_handle_t *handle; /* current cache handle */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen int in_checked; /* CACHE_IN must cache the entity */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen} cache_request_rec;
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen/* cache_util.c */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen/**
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen *
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo SirainenCACHE_DECLARE(apr_time_t) ap_cache_hex2msec(const char *x);
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo SirainenCACHE_DECLARE(void) ap_cache_msec2hex(apr_time_t j, char *y);
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo SirainenCACHE_DECLARE(char *) generate_name(apr_pool_t *p, int dirlevels,
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo Sirainen int dirlength,
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo Sirainen const char *name);
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo SirainenCACHE_DECLARE(int) ap_cache_request_is_conditional(request_rec *r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo SirainenCACHE_DECLARE(void) ap_cache_reset_output_filters(request_rec *r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo SirainenCACHE_DECLARE(const char *)ap_cache_get_cachetype(request_rec *r, cache_server_conf *conf, const char *url);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo SirainenCACHE_DECLARE(int) ap_cache_liststr(const char *list, const char *key, char **val);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo SirainenCACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/**
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * cache_storage.c
da8115ebacf055f87ec71ae1155a421452f2e0d5Timo Sirainen */
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainenint cache_remove_url(request_rec *r, const char *types, char *url);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint cache_create_entity(request_rec *r, const char *types, char *url, apr_size_t size);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint cache_remove_entity(request_rec *r, const char *types, cache_handle_t *h);
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenint cache_select_url(request_rec *r, const char *types, char *url);
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenapr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
d22301419109ed4a38351715e6760011421dadecTimo Sirainen/**
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainen * create a key for the cache based on the request record
d22301419109ed4a38351715e6760011421dadecTimo Sirainen * this is the 'default' version, which can be overridden by a default function
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainen */
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenconst char* cache_create_key( request_rec*r );
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainen
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenapr_status_t cache_write_entity_headers(cache_handle_t *h, request_rec *r, cache_info *info);
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenapr_status_t cache_write_entity_body(cache_handle_t *h, request_rec *r, apr_bucket_brigade *bb);
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainen
d22301419109ed4a38351715e6760011421dadecTimo Sirainenapr_status_t cache_read_entity_headers(cache_handle_t *h, request_rec *r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenapr_status_t cache_read_entity_body(cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen/* hooks */
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen/* Create a set of CACHE_DECLARE(type), CACHE_DECLARE_NONSTD(type) and
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen * CACHE_DECLARE_DATA with appropriate export and import tags for the platform
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#if !defined(WIN32)
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen#define CACHE_DECLARE(type) type
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen#define CACHE_DECLARE_NONSTD(type) type
ee1681a053a515048d82fb57c366c26696fa0a33Timo Sirainen#define CACHE_DECLARE_DATA
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen#elif defined(CACHE_DECLARE_STATIC)
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen#define CACHE_DECLARE(type) type __stdcall
3ccab0bac68040f179a7de45c516cec258e28fdbTimo Sirainen#define CACHE_DECLARE_NONSTD(type) type
3ccab0bac68040f179a7de45c516cec258e28fdbTimo Sirainen#define CACHE_DECLARE_DATA
3ccab0bac68040f179a7de45c516cec258e28fdbTimo Sirainen#elif defined(CACHE_DECLARE_EXPORT)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE(type) __declspec(dllexport) type __stdcall
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllexport) type
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE_DATA __declspec(dllexport)
fdcb22a688c4676face8db865736b217d9c07d19Timo Sirainen#else
6e1e9e341ffe21a69a23229c2b896d03066a071eTimo Sirainen#define CACHE_DECLARE(type) __declspec(dllimport) type __stdcall
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllimport) type
8da095519878426b012058e6f331a669f327f47fTimo Sirainen#define CACHE_DECLARE_DATA __declspec(dllimport)
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen#endif
2e7e4804d8a88b10e00a3f9ec3726759ae0a6a13Timo Sirainen
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo SirainenAPR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, create_entity,
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen (cache_handle_t *h, request_rec *r, const char *type,
2e7e4804d8a88b10e00a3f9ec3726759ae0a6a13Timo Sirainen const char *urlkey, apr_size_t len))
2e7e4804d8a88b10e00a3f9ec3726759ae0a6a13Timo SirainenAPR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, open_entity,
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainen (cache_handle_t *h, request_rec *r, const char *type,
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen const char *urlkey))
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo SirainenAPR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, remove_url,
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen (const char *type, const char *urlkey))
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen
85452efe6f9edd85e2ce45bfc4f198e9cb9b82bdTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo SirainenAPR_DECLARE_OPTIONAL_FN(apr_status_t,
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen ap_cache_generate_key,
0d16525a729011f4fced989a3da74d755ea49e6dTimo Sirainen (request_rec *r, apr_pool_t*p, char**key ));
ee1681a053a515048d82fb57c366c26696fa0a33Timo Sirainen
0d16525a729011f4fced989a3da74d755ea49e6dTimo Sirainen
0d16525a729011f4fced989a3da74d755ea49e6dTimo Sirainen#endif /*MOD_CACHE_H*/
0d16525a729011f4fced989a3da74d755ea49e6dTimo Sirainen