mod_expires.c revision 0f081398cf0eef8cc7c66a535d450110a92dc8ae
/* ====================================================================
* Copyright (c) 1995-1999 The Apache Group. 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. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" 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 names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``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 GROUP OR
* IT'S 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 Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
/*
* version 0.0.11
* status beta
*
* Andrew Wilson <Andrew.Wilson@cm.cf.ac.uk> 26.Jan.96
*
* This module allows you to control the form of the Expires: header
* that Apache issues for each access. Directives can appear in
* configuration files or in .htaccess files so expiry semantics can
* be defined on a per-directory basis.
*
* DIRECTIVE SYNTAX
*
* Valid directives are:
*
* ExpiresActive on | off
* ExpiresDefault <code><seconds>
*
* Valid values for <code> are:
*
* 'M' expires header shows file modification date + <seconds>
* 'A' expires header shows access time + <seconds>
*
* [I'm not sure which of these is best under different
* circumstances, I guess it's for other people to explore.
* The effects may be indistinguishable for a number of cases]
*
* <seconds> should be an integer value [acceptable to atoi()]
*
* There is NO space between the <code> and <seconds>.
*
* For example, a directory which contains information which changes
* frequently might contain:
*
* # reports generated by cron every hour. don't let caches
* # hold onto stale information
* ExpiresDefault M3600
*
* Another example, our html pages can change all the time, the gifs
* tend not to change often:
*
* # pages are hot (1 week), images are cold (1 month)
*
* Expires can be turned on for all URLs on the server by placing the
* following directive in a conf file:
*
* ExpiresActive on
*
* ExpiresActive can also appear in .htaccess files, enabling the
* behaviour to be turned on or off for each chosen directory.
*
* # turn off Expires behaviour in this directory
* # and subdirectories
* ExpiresActive off
*
* Directives defined for a directory are valid in subdirectories
* unless explicitly overridden by new directives in the subdirectory
* .htaccess files.
*
* ALTERNATIVE DIRECTIVE SYNTAX
*
* Directives can also be defined in a more readable syntax of the form:
*
* ExpiresDefault "<base> [plus] {<num> <type>}*"
*
* where <base> is one of:
* access
* now equivalent to 'access'
* modification
*
* where the 'plus' keyword is optional
*
* where <num> should be an integer value [acceptable to atoi()]
*
* where <type> is one of:
* years
* months
* weeks
* days
* hours
* minutes
* seconds
*
* For example, any of the following directives can be used to make
* documents expire 1 month after being accessed, by default:
*
* ExpiresDefault "access plus 1 month"
* ExpiresDefault "access plus 4 weeks"
* ExpiresDefault "access plus 30 days"
*
* The expiry time can be fine-tuned by adding several '<num> <type>'
* clauses:
*
*
* ---
*
* Change-log:
* 29.Jan.96 Hardened the add_* functions. Server will now bail out
* if bad directives are given in the conf files.
* 02.Feb.96 Returns DECLINED if not 'ExpiresActive on', giving other
* expires-aware modules a chance to play with the same
* directives. [Michael Rutman]
* 03.Feb.96 Call tzset() before localtime(). Trying to get the module
* to work properly in non GMT timezones.
* 12.Feb.96 Modified directive syntax to allow more readable commands:
* ExpiresDefault "now plus 10 days 20 seconds"
* ExpiresDefault "access plus 30 days"
* ExpiresDefault "modification plus 1 year 10 months 30 days"
* 13.Feb.96 Fix call to table_get() with NULL 2nd parameter [Rob Hartill]
* 19.Feb.96 Call gm_timestr_822() to get time formatted correctly, can't
* rely on presence of HTTP_TIME_FORMAT in Apache 1.1+.
* 21.Feb.96 This version (0.0.9) reverses assumptions made in 0.0.8
* 08.Jun.96 allows ExpiresDefault to be used with responses that use
* the DefaultType by not DECLINING, but instead skipping
* the table_get check and then looking for an ExpiresDefault.
* [Rob Hartill]
* 04.Nov.96 'const' definitions added.
*
* TODO
* add support for Cache-Control: max-age=20 from the HTTP/1.1
* proposal (in this case, a ttl of 20 seconds) [ask roy]
* add per-file expiry and explicit expiry times - duplicates some
* of the mod_cern_meta.c functionality. eg:
* ExpiresExplicit index.html "modification plus 30 days"
*
* BUGS
* Hi, welcome to the internet.
*/
#include <ctype.h>
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
typedef struct {
int active;
char *expiresdefault;
/* from mod_dir, why is this alias used?
*/
#define DIR_CMD_PERMS OR_INDEXES
#define ACTIVE_ON 1
#define ACTIVE_OFF 0
#define ACTIVE_DONTCARE 2
{
return (void *) new;
}
{
/* if we're here at all it's because someone explicitly
* set the active flag
*/
if (arg == 0) {
};
return NULL;
}
/* check_code() parse 'code' and return NULL or an error response
* string. If we return NULL then real_code contains code converted
* to the cnnnn format.
*/
{
char *word;
char base = 'X';
int modifier = 0;
int num = 0;
int factor = 0;
/* 0.0.4 compatibility?
*/
return NULL;
};
/* <base> [plus] {<num> <type>}*
*/
/* <base>
*/
base = 'A';
}
base = 'M';
}
else {
return ap_pstrcat(p, "bad expires code, unrecognised <base> '",
};
/* [plus]
*/
};
/* {<num> <type>}*
*/
while (word[0]) {
/* <num>
*/
if (ap_isdigit(word[0])) {
}
else {
return ap_pstrcat(p, "bad expires code, numeric value expected <num> '",
};
/* <type>
*/
if (word[0]) {
/* do nothing */
}
else {
};
factor = 0;
}
}
}
}
}
factor = 60;
}
factor = 1;
}
else {
return ap_pstrcat(p, "bad expires code, unrecognised <type>",
};
/* next <num>
*/
};
return NULL;
}
static const char *set_expiresbytype(cmd_parms *cmd, expires_dir_config * dir_config, char *mime, char *code)
{
return NULL;
};
}
{
return NULL;
};
}
static const command_rec expires_cmds[] =
{
"Limited to 'on' or 'off'"},
"a MIME type followed by an expiry date code"},
"an expiry date code"},
{NULL}
};
{
}
else {
};
};
return new;
}
static int add_expires(request_rec *r)
{
char *code;
char age[20];
return DECLINED;
return DECLINED;
"internal error: %s", r->filename);
return SERVER_ERROR;
};
return DECLINED;
/* we perhaps could use the default_type(r) in its place but that
* may be 2nd guesing the desired configuration... calling table_get
* with a NULL key will SEGV us
*
* I still don't know *why* r->content_type would ever be NULL, this
* is possibly a result of fixups being called in many different
* places. Fixups is probably the wrong place to be doing all this
* work... Bah.
*
* Changed as of 08.Jun.96 don't DECLINE, look for an ExpiresDefault.
*/
if (r->content_type == NULL)
else
/* no expires defined for that type, is there a default? */
if (code[0] == '\0')
return OK;
};
/* we have our code */
switch (code[0]) {
case 'M':
/* file doesn't exist on disk, so we can't do anything based on
* modification time. Note that this does _not_ log an error.
*/
return DECLINED;
}
break;
case 'A':
/* there's been some discussion and it's possible that
* 'access time' will be stored in request structure
*/
base = r->request_time;
break;
default:
/* expecting the add_* routines to be case-hardened this
* is just a reminder that module is beta
*/
"internal error: bad expires code: %s", r->filename);
return SERVER_ERROR;
};
tzset(); /* redundant? called implicitly by localtime, at least
* under FreeBSD
*/
return OK;
}
{
NULL, /* initializer */
create_dir_expires_config, /* dir config creater */
merge_expires_dir_configs, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server configs */
expires_cmds, /* command table */
NULL, /* handlers */
NULL, /* filename translation */
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
NULL, /* type_checker */
add_expires, /* fixups */
NULL, /* logger */
NULL, /* header parser */
NULL, /* child_init */
NULL, /* child_exit */
NULL /* post read-request */
};