cache_util.c revision 9ed34e5219ab3506ccfd2ca58751ce4c81b263a8
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
#define CORE_PRIVATE
#include "mod_cache.h"
/* -------------------------------------------------------------- */
/* return true if the request is conditional */
{
return 1;
}
return 0;
}
/* remove other filters from filter stack */
{
ap_filter_t *f = r->output_filters;
while (f) {
f = f->next;
continue;
}
else {
f = f->next;
}
}
}
const char *url)
{
int i;
/* we can't cache if there's no URL */
/* loop through all the cacheenable entries */
struct cache_enable *ent =
if (!type) {
}
else {
}
}
}
/* then loop through all the cachedisable entries */
/* Looking for urls that contain the full cachedisable url and possibly more. */
/* This means we are disabling cachedisable url and below... */
struct cache_disable *ent =
}
}
return type;
}
/* do a HTTP/1.1 age calculation */
{
/* Perform an HTTP/1.1 age calculation. (RFC2616 13.2.3) */
return apr_time_sec(current_age);
}
request_rec *r)
{
char *val;
apr_time_t age_c = 0;
/*
* We now want to check if our cached data is still fresh. This depends
* on a few things, in this order:
*
* - RFC2616 14.9.4 End to end reload, Cache-Control: no-cache no-cache in
* either the request or the cached response means that we must
* revalidate the request unconditionally, overriding any expiration
* mechanism. It's equivalent to max-age=0,must-revalidate.
*
* - RFC2616 14.32 Pragma: no-cache This is treated the same as
* Cache-Control: no-cache.
*
* - RFC2616 14.9.3 Cache-Control: max-stale, must-revalidate,
* proxy-revalidate if the max-stale request header exists, modify the
* stale calculations below so that an object can be at most <max-stale>
* seconds stale before we request a revalidation, _UNLESS_ a
* must-revalidate or proxy-revalidate cached response header exists to
* stop us doing this.
*
* - RFC2616 14.9.3 Cache-Control: s-maxage the origin server specifies the
* maximum age an object can be before it is considered stale. This
* directive has the effect of proxy|must revalidate, which in turn means
* simple ignore any max-stale setting.
*
* - RFC2616 14.9.4 Cache-Control: max-age this header can appear in both
* requests and responses. If both are specified, the smaller of the two
* takes priority.
*
* - RFC2616 14.21 Expires: if this request header exists in the cached
* entity, and it's value is in the past, it has expired.
*
*/
/* TODO: pragma_cresp not being used? */
}
/* calculate age of object */
/* extract s-maxage */
else
smaxage = -1;
/* extract max-age from request */
else
maxage_req = -1;
/* extract max-age from response */
else
maxage_cresp = -1;
/*
* if both maxage request and response, the smaller one takes priority
*/
if (-1 == maxage_req)
else if (-1 == maxage_cresp)
maxage = maxage_req;
else
/* extract max-stale */
else
maxstale = 0;
/* extract min-fresh */
else
minfresh = 0;
/* override maxstale if must-revalidate or proxy-revalidate */
"proxy-revalidate", NULL))))
maxstale = 0;
/* handle expiration */
(info->expire != APR_DATE_BAD && age < (apr_time_sec(info->expire - info->date) + maxstale - minfresh))) {
/* it's fresh darlings... */
/* set age header on response */
/* add warning if maxstale overrode freshness calculation */
/* make sure we don't stomp on a previous warning */
}
return 1; /* Cache object is fresh */
}
return 0; /* Cache object is stale */
}
/*
* list is a comma-separated list of case-insensitive tokens, with
* optional whitespace around the tokens.
* The return returns 1 if the token val is found in the list, or 0
* otherwise.
*/
{
const char *next;
if (!list) {
return 0;
}
for (;;) {
/* skip whitespace and commas to find the start of the next key */
next++;
}
if (!*next) {
return 0;
}
/* this field matches the key (though it might just be
* a prefix match, so make sure the match is followed
* by either a space or an equals sign)
*/
(*next == ',')) {
/* valid match */
if (val) {
next++;
}
if (*next == '=') {
next++;
next++;
}
if (!*next) {
}
else {
(*next != ',')) {
next++;
}
}
}
}
return 1;
}
}
/* skip to the next field */
do {
next++;
if (!*next) {
return 0;
}
} while (*next != ',');
}
}
/* return each comma separated token, one at a time */
{
apr_size_t i;
const char *s;
if (s != NULL) {
i = s - list;
do
s++;
while (apr_isspace(*s))
; /* noop */
}
else
i--;
*str = s;
if (i)
return apr_pstrndup(p, list, i);
else
return NULL;
}
/*
* Converts apr_time_t expressed as hex digits to
* a true apr_time_t.
*/
{
int i, ch;
apr_time_t j;
for (i = 0, j = 0; i < sizeof(j) * 2; i++) {
ch = x[i];
j <<= 4;
if (apr_isdigit(ch))
j |= ch - '0';
else if (apr_isupper(ch))
else
}
return j;
}
/*
* Converts apr_time_t to apr_time_t expressed as hex digits.
*/
{
int i, ch;
for (i = (sizeof(j) * 2)-1; i >= 0; i--) {
ch = (int)(j & 0xF);
j >>= 4;
if (ch >= 10)
else
y[i] = ch + '0';
}
y[sizeof(j) * 2] = '\0';
}
{
unsigned char digest[16];
char tmp[22];
int i, k, d;
unsigned int x;
static const char enc_table[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@";
/* encode 128 bits as 22 characters, using a modified uuencoding
* the encoding is 3 bytes -> 4 characters* i.e. 128 bits is
* 5 x 3 bytes + 1 byte -> 5 * 4 characters + 2 characters
*/
for (i = 0, k = 0; i < 15; i += 3) {
}
/* one byte left */
x = digest[15];
/* now split into directory levels */
for (i = k = d = 0; d < ndepth; ++d) {
k += nlength;
i += nlength + 1;
}
}
{
char hashfile[66];
return apr_pstrdup(p, hashfile);
}