cache_util.c revision e8f95a682820a599fe41b22977010636be5c2717
/* Copyright 2001-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define CORE_PRIVATE
#include "mod_cache.h"
#include <ap_provider.h>
/* -------------------------------------------------------------- */
/* Determine if "url" matches the hostname, scheme and port and path
* in "filter". All but the path comparisons are case-insensitive.
*/
{
/* Compare the hostnames */
return 0;
}
return 0;
}
}
/* Compare the schemes */
return 0;
}
return 0;
}
}
/* Compare the ports */
return 0;
}
/* NOTE: ap_port_of_scheme will return 0 if given NULL input */
return 0;
}
}
return 0;
}
}
/* Url has met all of the filter conditions so far, determine
* if the paths match.
*/
}
{
int i;
/* loop through all the cacheenable entries */
struct cache_enable *ent =
/* Fetch from global config and add to the list. */
"0");
if (!provider) {
/* Log an error! */
}
else {
if (!providers) {
}
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 =
/* Stop searching now. */
return NULL;
}
}
return providers;
}
/* do a HTTP/1.1 age calculation */
const apr_time_t age_value,
{
/* Perform an HTTP/1.1 age calculation. (RFC2616 13.2.3) */
return apr_time_sec(current_age);
}
request_rec *r)
{
const char *pragma;
char *val;
apr_time_t age_c = 0;
&cache_module);
/*
* 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.
*
*/
/* This value comes from the client's initial request. */
if (!conf->ignorecachecontrol) {
/* Treat as stale, causing revalidation */
return 0;
}
"Incoming request is asking for a uncached version of "
"%s, but we know better and are ignoring it",
r->unparsed_uri);
}
/* These come from the cached entity. */
}
/* calculate age of object */
/* extract s-maxage */
}
else {
smaxage = -1;
}
/* extract max-age from request */
if (!conf->ignorecachecontrol
}
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 (maxage_req == -1) {
}
else if (maxage_cresp == -1) {
maxage = maxage_req;
}
else {
}
/* extract max-stale */
}
else {
maxstale = 0;
}
/* extract min-fresh */
if (!conf->ignorecachecontrol
}
else {
minfresh = 0;
}
/* override maxstale if must-revalidate or proxy-revalidate */
"must-revalidate", NULL)) ||
(cc_cresp &&
"proxy-revalidate", NULL)))) {
maxstale = 0;
}
/* handle expiration */
const char *warn_head;
/* 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 */
"110 Response is stale");
}
}
/*
* If none of Expires, Cache-Control: max-age, or Cache-Control:
* s-maxage appears in the response, and the respose header age
* calculated is more than 24 hours add the warning 113
*/
/* Make sure we don't stomp on a previous warning, and don't dup
* a 113 marning that is already present. Also, make sure to add
* the new warning to the correct *headers_out location.
*/
"113 Heuristic expiration");
}
}
return 1; /* Cache object is fresh (enough) */
}
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 */
const char **str)
{
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);
}
/* Create a new table consisting of those elements from an input
* headers table that are allowed to be stored in a cache.
*/
apr_table_t *t,
server_rec *s)
{
char **header;
int i;
/* Make a copy of the headers, and remove from
* the copy any hop-by-hop headers, as defined in Section
* 13.5.1 of RFC 2616
*/
&cache_module);
/* Remove the user defined headers set with CacheIgnoreHeaders.
* This may break RFC 2616 compliance on behalf of the administrator.
*/
}
return headers_out;
}