From 59a68232cc91cf8fe45986a54e17583cfab84154 Mon Sep 17 00:00:00 2001 From: Andreas Steinmetz Date: Tue, 23 Aug 2005 13:35:00 +0000 Subject: [PATCH] Split mod_disk_cache.c into mod_disk_cache.c and mod_disk_cache.h to allow inclusion of mod_disk_cache.h in htcacheclean.c. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@239406 13f79535-47bb-0310-9956-ffa450edef68 --- modules/cache/mod_disk_cache.c | 65 +---------------------- modules/cache/mod_disk_cache.h | 95 ++++++++++++++++++++++++++++++++++ support/htcacheclean.c | 50 +----------------- 3 files changed, 97 insertions(+), 113 deletions(-) create mode 100644 modules/cache/mod_disk_cache.h diff --git a/modules/cache/mod_disk_cache.c b/modules/cache/mod_disk_cache.c index 4983874ed1..e3d24dfdee 100644 --- a/modules/cache/mod_disk_cache.c +++ b/modules/cache/mod_disk_cache.c @@ -17,6 +17,7 @@ #include "apr_file_io.h" #include "apr_strings.h" #include "mod_cache.h" +#include "mod_disk_cache.h" #include "ap_provider.h" #include "util_filter.h" #include "util_script.h" @@ -50,66 +51,6 @@ * CRLF */ -#define VARY_FORMAT_VERSION 3 -#define DISK_FORMAT_VERSION 4 - -typedef struct { - /* Indicates the format of the header struct stored on-disk. */ - apr_uint32_t format; - /* The HTTP status code returned for this response. */ - int status; - /* The size of the entity name that follows. */ - apr_size_t name_len; - /* The number of times we've cached this entity. */ - apr_size_t entity_version; - /* Miscellaneous time values. */ - apr_time_t date; - apr_time_t expire; - apr_time_t request_time; - apr_time_t response_time; -} disk_cache_info_t; - -/* - * disk_cache_object_t - * Pointed to by cache_object_t::vobj - */ -typedef struct disk_cache_object { - const char *root; /* the location of the cache directory */ - apr_size_t root_len; - char *tempfile; /* temp file tohold the content */ - const char *prefix; - const char *datafile; /* name of file where the data will go */ - const char *hdrsfile; /* name of file where the hdrs will go */ - const char *hashfile; /* Computed hash key for this URI */ - const char *name; /* Requested URI without vary bits - suitable for mortals. */ - const char *key; /* On-disk prefix; URI with Vary bits (if present) */ - apr_file_t *fd; /* data file */ - apr_file_t *hfd; /* headers file */ - apr_file_t *tfd; /* temporary file for data */ - apr_off_t file_size; /* File size of the cached data file */ - disk_cache_info_t disk_info; /* Header information. */ -} disk_cache_object_t; - - -/* - * mod_disk_cache configuration - */ -/* TODO: Make defaults OS specific */ -#define CACHEFILE_LEN 20 /* must be less than HASH_LEN/2 */ -#define DEFAULT_DIRLEVELS 3 -#define DEFAULT_DIRLENGTH 2 -#define DEFAULT_MIN_FILE_SIZE 1 -#define DEFAULT_MAX_FILE_SIZE 1000000 - -typedef struct { - const char* cache_root; - apr_size_t cache_root_len; - int dirlevels; /* Number of levels of subdirectories */ - int dirlength; /* Length of subdirectory names */ - apr_size_t minfs; /* minumum file size for cached files */ - apr_size_t maxfs; /* maximum file size for cached files */ -} disk_cache_conf; - module AP_MODULE_DECLARE_DATA disk_cache_module; /* Forward declarations */ @@ -124,9 +65,6 @@ static apr_status_t read_array(request_rec *r, apr_array_header_t* arr, /* * Local static functions */ -#define CACHE_HEADER_SUFFIX ".header" -#define CACHE_DATA_SUFFIX ".data" -#define CACHE_VDIR_SUFFIX ".vary" static char *header_file(apr_pool_t *p, disk_cache_conf *conf, disk_cache_object_t *dobj, const char *name) @@ -378,7 +316,6 @@ static void tokens_to_array(apr_pool_t *p, const char *data, /* * Hook and mod_cache callback functions */ -#define AP_TEMPFILE "/aptmpXXXXXX" static int create_entity(cache_handle_t *h, request_rec *r, const char *key, apr_off_t len) { disk_cache_conf *conf = ap_get_module_config(r->server->module_config, diff --git a/modules/cache/mod_disk_cache.h b/modules/cache/mod_disk_cache.h new file mode 100644 index 0000000000..7a1ff0801a --- /dev/null +++ b/modules/cache/mod_disk_cache.h @@ -0,0 +1,95 @@ +/* Copyright 2000-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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +#ifndef MOD_DISK_CACHE_H +#define MOD_DISK_CACHE_H + +/* + * include for mod_disk_cache: Disk Based HTTP 1.1 Cache. + */ + +#define VARY_FORMAT_VERSION 3 +#define DISK_FORMAT_VERSION 4 + +#define CACHE_HEADER_SUFFIX ".header" +#define CACHE_DATA_SUFFIX ".data" +#define CACHE_VDIR_SUFFIX ".vary" + +#define AP_TEMPFILE_PREFIX "/" +#define AP_TEMPFILE_BASE "aptmp" +#define AP_TEMPFILE_SUFFIX "XXXXXX" +#define AP_TEMPFILE_BASELEN strlen(AP_TEMPFILE_BASE) +#define AP_TEMPFILE_NAMELEN strlen(AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX) +#define AP_TEMPFILE AP_TEMPFILE_PREFIX AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX + +typedef struct { + /* Indicates the format of the header struct stored on-disk. */ + apr_uint32_t format; + /* The HTTP status code returned for this response. */ + int status; + /* The size of the entity name that follows. */ + apr_size_t name_len; + /* The number of times we've cached this entity. */ + apr_size_t entity_version; + /* Miscellaneous time values. */ + apr_time_t date; + apr_time_t expire; + apr_time_t request_time; + apr_time_t response_time; +} disk_cache_info_t; + +/* + * disk_cache_object_t + * Pointed to by cache_object_t::vobj + */ +typedef struct disk_cache_object { + const char *root; /* the location of the cache directory */ + apr_size_t root_len; + char *tempfile; /* temp file tohold the content */ + const char *prefix; + const char *datafile; /* name of file where the data will go */ + const char *hdrsfile; /* name of file where the hdrs will go */ + const char *hashfile; /* Computed hash key for this URI */ + const char *name; /* Requested URI without vary bits - suitable for mortals. */ + const char *key; /* On-disk prefix; URI with Vary bits (if present) */ + apr_file_t *fd; /* data file */ + apr_file_t *hfd; /* headers file */ + apr_file_t *tfd; /* temporary file for data */ + apr_off_t file_size; /* File size of the cached data file */ + disk_cache_info_t disk_info; /* Header information. */ +} disk_cache_object_t; + + +/* + * mod_disk_cache configuration + */ +/* TODO: Make defaults OS specific */ +#define CACHEFILE_LEN 20 /* must be less than HASH_LEN/2 */ +#define DEFAULT_DIRLEVELS 3 +#define DEFAULT_DIRLENGTH 2 +#define DEFAULT_MIN_FILE_SIZE 1 +#define DEFAULT_MAX_FILE_SIZE 1000000 + +typedef struct { + const char* cache_root; + apr_size_t cache_root_len; + int dirlevels; /* Number of levels of subdirectories */ + int dirlength; /* Length of subdirectory names */ + apr_size_t minfs; /* minumum file size for cached files */ + apr_size_t maxfs; /* maximum file size for cached files */ +} disk_cache_conf; + +#endif /*MOD_DISK_CACHE_H*/ diff --git a/support/htcacheclean.c b/support/htcacheclean.c index 6fa1842ca4..15fd29bf1d 100644 --- a/support/htcacheclean.c +++ b/support/htcacheclean.c @@ -34,6 +34,7 @@ #include "apr_getopt.h" #include "apr_ring.h" #include "apr_date.h" +#include "../modules/cache/mod_disk_cache.h" #if APR_HAVE_UNISTD_H #include @@ -42,55 +43,6 @@ #include #endif -/* mod_disk_cache.c extract start */ - -#define VARY_FORMAT_VERSION 3 -#define DISK_FORMAT_VERSION 4 - -typedef struct { - /* Indicates the format of the header struct stored on-disk. */ - apr_uint32_t format; - /* The HTTP status code returned for this response. */ - int status; - /* The size of the entity name that follows. */ - apr_size_t name_len; - /* The number of times we've cached this entity. */ - apr_size_t entity_version; - /* Miscellaneous time values. */ - apr_time_t date; - apr_time_t expire; - apr_time_t request_time; - apr_time_t response_time; -} disk_cache_info_t; - -#define CACHE_HEADER_SUFFIX ".header" -#define CACHE_DATA_SUFFIX ".data" -/* mod_disk_cache.c extract end */ - -/* mod_disk_cache.c related definitions start */ - -/* - * this is based on #define AP_TEMPFILE "/aptmpXXXXXX" - * - * the above definition could be reworked into the following: - * - * #define AP_TEMPFILE_PREFIX "/" - * #define AP_TEMPFILE_BASE "aptmp" - * #define AP_TEMPFILE_SUFFIX "XXXXXX" - * #define AP_TEMPFILE_BASELEN strlen(AP_TEMPFILE_BASE) - * #define AP_TEMPFILE_NAMELEN strlen(AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX) - * #define AP_TEMPFILE AP_TEMPFILE_PREFIX AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX - * - * these definitions would then match the definitions below: - */ - -#define AP_TEMPFILE_BASE "aptmp" -#define AP_TEMPFILE_SUFFIX "XXXXXX" -#define AP_TEMPFILE_BASELEN strlen(AP_TEMPFILE_BASE) -#define AP_TEMPFILE_NAMELEN strlen(AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX) - -/* mod_disk_cache.c related definitions end */ - /* define the following for debugging */ #undef DEBUG -- 2.50.1