]> granicus.if.org Git - apache/commitdiff
Remove the MOD_CACHE_REQUEST_REC hack, and pass the cache_request_rec
authorGraham Leggett <minfrin@apache.org>
Wed, 22 Sep 2010 19:35:26 +0000 (19:35 +0000)
committerGraham Leggett <minfrin@apache.org>
Wed, 22 Sep 2010 19:35:26 +0000 (19:35 +0000)
structure through mod_cache's function parameters in the usual way.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1000152 13f79535-47bb-0310-9956-ffa450edef68

modules/cache/cache_storage.c
modules/cache/cache_storage.h
modules/cache/cache_util.c
modules/cache/mod_cache.c
modules/cache/mod_cache.h

index c0084f9d2e837facef7d700aa820c2e6d0186400..fdf5b8f6d7bd504b62606ac5705b389b1c8bc643 100644 (file)
@@ -68,19 +68,15 @@ int cache_remove_url(cache_request_rec *cache, apr_pool_t *p)
  * decide whether or not it wants to cache this particular entity.
  * If the size is unknown, a size of -1 should be set.
  */
-int cache_create_entity(request_rec *r, apr_off_t size, apr_bucket_brigade *in)
+int cache_create_entity(cache_request_rec *cache, request_rec *r,
+                        apr_off_t size, apr_bucket_brigade *in)
 {
     cache_provider_list *list;
     cache_handle_t *h = apr_pcalloc(r->pool, sizeof(cache_handle_t));
     char *key;
     apr_status_t rv;
-    cache_request_rec *cache;
-    void *data;
 
-    apr_pool_userdata_get(&data, MOD_CACHE_REQUEST_REC, r->pool);
-    cache = data;
-
-    rv = cache_generate_key(r, r->pool, &key);
+    rv = cache_generate_key(cache, r, r->pool, &key);
     if (rv != APR_SUCCESS) {
         return rv;
     }
@@ -189,19 +185,14 @@ CACHE_DECLARE(void) ap_cache_accept_headers(cache_handle_t *h, request_rec *r,
  * This function returns OK if successful, DECLINED if no
  * cached entity fits the bill.
  */
-int cache_select(request_rec *r)
+int cache_select(cache_request_rec *cache, request_rec *r)
 {
     cache_provider_list *list;
     apr_status_t rv;
     cache_handle_t *h;
     char *key;
-    cache_request_rec *cache;
-    void *data;
-
-    apr_pool_userdata_get(&data, MOD_CACHE_REQUEST_REC, r->pool);
-    cache = data;
 
-    rv = cache_generate_key(r, r->pool, &key);
+    rv = cache_generate_key(cache, r, r->pool, &key);
     if (rv != APR_SUCCESS) {
         return rv;
     }
@@ -282,7 +273,7 @@ int cache_select(request_rec *r)
             cache->provider_name = list->provider_name;
 
             /* Is our cached response fresh enough? */
-            fresh = ap_cache_check_freshness(h, r);
+            fresh = ap_cache_check_freshness(h, cache, r);
             if (!fresh) {
                 const char *etag, *lastmod;
 
@@ -366,19 +357,15 @@ int cache_select(request_rec *r)
     return DECLINED;
 }
 
-apr_status_t cache_generate_key_default(request_rec *r, apr_pool_t* p,
-                                        char**key)
+apr_status_t cache_generate_key_default(cache_request_rec *cache, request_rec *r,
+                                        apr_pool_t* p, char **key)
 {
     cache_server_conf *conf;
-    cache_request_rec *cache;
     char *port_str, *hn, *lcs;
     const char *hostname, *scheme;
     int i;
     char *path, *querystring;
-    void *data;
 
-    apr_pool_userdata_get(&data, MOD_CACHE_REQUEST_REC, r->pool);
-    cache = data;
     if (!cache) {
         /* This should never happen */
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
index 18749172b537999891d491a807df706d7a2425aa..a19dd6d1649b4d2fd2868ee84070abb3681c149e 100644 (file)
@@ -35,11 +35,12 @@ extern "C" {
 /**
  * cache_storage.c
  */
-#define MOD_CACHE_REQUEST_REC "mod_cache_request_rec"
 int cache_remove_url(cache_request_rec *cache, apr_pool_t *p);
-int cache_create_entity(request_rec *r, apr_off_t size, apr_bucket_brigade *in);
-int cache_select(request_rec *r);
-apr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
+int cache_create_entity(cache_request_rec *cache, request_rec *r,
+                        apr_off_t size, apr_bucket_brigade *in);
+int cache_select(cache_request_rec *cache, request_rec *r);
+apr_status_t cache_generate_key_default(cache_request_rec *cache, request_rec *r,
+                                        apr_pool_t* p, char **key);
 
 #ifdef __cplusplus
 }
index ee8540380e694539b55792eca689e747224cff8b..34b447d07503dd4a5f22818a3b1a55b29efca082 100644 (file)
@@ -230,7 +230,8 @@ CACHE_DECLARE(apr_int64_t) ap_cache_current_age(cache_info *info,
  * the backend.
  */
 CACHE_DECLARE(apr_status_t) ap_cache_try_lock(cache_server_conf *conf,
-        request_rec *r, char *key) {
+        cache_request_rec *cache, request_rec *r, char *key)
+{
     apr_status_t status;
     const char *lockname;
     const char *path;
@@ -255,7 +256,7 @@ CACHE_DECLARE(apr_status_t) ap_cache_try_lock(cache_server_conf *conf,
 
     /* create the key if it doesn't exist */
     if (!key) {
-        cache_generate_key(r, r->pool, &key);
+        cache_generate_key(cache, r, r->pool, &key);
     }
 
     /* create a hashed filename from the key, and save it for later */
@@ -322,7 +323,9 @@ CACHE_DECLARE(apr_status_t) ap_cache_try_lock(cache_server_conf *conf,
  * removed if the bucket brigade contains an EOS bucket.
  */
 CACHE_DECLARE(apr_status_t) ap_cache_remove_lock(cache_server_conf *conf,
-        request_rec *r, char *key, apr_bucket_brigade *bb) {
+        cache_request_rec *cache, request_rec *r, char *key,
+        apr_bucket_brigade *bb)
+{
     void *dummy;
     const char *lockname;
 
@@ -360,7 +363,7 @@ CACHE_DECLARE(apr_status_t) ap_cache_remove_lock(cache_server_conf *conf,
 
         /* create the key if it doesn't exist */
         if (!key) {
-            cache_generate_key(r, r->pool, &key);
+            cache_generate_key(cache, r, r->pool, &key);
         }
 
         /* create a hashed filename from the key, and save it for later */
@@ -439,6 +442,7 @@ CACHE_DECLARE(int) ap_cache_check_allowed(request_rec *r) {
 
 
 CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
+                                            cache_request_rec *cache,
                                             request_rec *r)
 {
     apr_status_t status;
@@ -687,7 +691,7 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
      * A lock that exceeds a maximum age will be deleted, and another
      * request gets to make a new lock and try again.
      */
-    status = ap_cache_try_lock(conf, r, (char *)h->cache_obj->key);
+    status = ap_cache_try_lock(conf, cache, r, (char *)h->cache_obj->key);
     if (APR_SUCCESS == status) {
         /* we obtained a lock, follow the stale path */
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
index d1188261cf9441f8ecef16ad28e870068dd5ed68..118c44790fe73a59f43d1964f196ab7bf5bf512b 100644 (file)
@@ -98,9 +98,6 @@ static int cache_quick_handler(request_rec *r, int lookup)
     cache->size = -1;
     cache->out = apr_brigade_create(r->pool, r->connection->bucket_alloc);
 
-    /* store away the per request config where the API can find it */
-    apr_pool_userdata_setn(cache, MOD_CACHE_REQUEST_REC, NULL, r->pool);
-
     /* save away the possible providers */
     cache->providers = providers;
 
@@ -128,7 +125,7 @@ static int cache_quick_handler(request_rec *r, int lookup)
      *   add cache_out filter
      *   return OK
      */
-    rv = cache_select(r);
+    rv = cache_select(cache, r);
     if (rv != OK) {
         if (rv == DECLINED) {
             if (!lookup) {
@@ -140,7 +137,7 @@ static int cache_quick_handler(request_rec *r, int lookup)
                  * backend without any attempt to cache. this stops
                  * duplicated simultaneous attempts to cache an entity.
                  */
-                rv = ap_cache_try_lock(conf, r, NULL);
+                rv = ap_cache_try_lock(conf, cache, r, NULL);
                 if (APR_SUCCESS == rv) {
 
                     /*
@@ -358,9 +355,6 @@ static int cache_handler(request_rec *r)
     cache->size = -1;
     cache->out = apr_brigade_create(r->pool, r->connection->bucket_alloc);
 
-    /* store away the per request config where the API can find it */
-    apr_pool_userdata_setn(cache, MOD_CACHE_REQUEST_REC, NULL, r->pool);
-
     /* save away the possible providers */
     cache->providers = providers;
 
@@ -374,7 +368,7 @@ static int cache_handler(request_rec *r)
      *   add cache_out filter
      *   return OK
      */
-    rv = cache_select(r);
+    rv = cache_select(cache, r);
     if (rv != OK) {
         if (rv == DECLINED) {
 
@@ -385,7 +379,7 @@ static int cache_handler(request_rec *r)
              * backend without any attempt to cache. this stops
              * duplicated simultaneous attempts to cache an entity.
              */
-            rv = ap_cache_try_lock(conf, r, NULL);
+            rv = ap_cache_try_lock(conf, cache, r, NULL);
             if (APR_SUCCESS == rv) {
 
                 /*
@@ -596,7 +590,7 @@ static int cache_save_store(ap_filter_t *f, apr_bucket_brigade *in,
             ap_remove_output_filter(f);
 
             /* give someone else the chance to cache the file */
-            ap_cache_remove_lock(conf, f->r, cache->handle ?
+            ap_cache_remove_lock(conf, cache, f->r, cache->handle ?
                     (char *)cache->handle->cache_obj->key : NULL, NULL);
 
             /* give up trying to cache, just step out the way */
@@ -617,7 +611,7 @@ static int cache_save_store(ap_filter_t *f, apr_bucket_brigade *in,
         }
 
         /* conditionally remove the lock as soon as we see the eos bucket */
-        ap_cache_remove_lock(conf, f->r, cache->handle ?
+        ap_cache_remove_lock(conf, cache, f->r, cache->handle ?
                 (char *)cache->handle->cache_obj->key : NULL, cache->out);
 
         if (APR_BRIGADE_EMPTY(cache->out)) {
@@ -638,7 +632,7 @@ static int cache_save_store(ap_filter_t *f, apr_bucket_brigade *in,
                 ap_remove_output_filter(f);
 
                 /* give someone else the chance to cache the file */
-                ap_cache_remove_lock(conf, f->r, cache->handle ?
+                ap_cache_remove_lock(conf, cache, f->r, cache->handle ?
                         (char *)cache->handle->cache_obj->key : NULL, NULL);
 
                 return ap_pass_brigade(f->next, in);
@@ -912,7 +906,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
         ap_remove_output_filter(f);
 
         /* remove the lock file unconditionally */
-        ap_cache_remove_lock(conf, r, cache->handle ?
+        ap_cache_remove_lock(conf, cache, r, cache->handle ?
                 (char *)cache->handle->cache_obj->key : NULL, NULL);
 
         /* ship the data up the stack */
@@ -1007,7 +1001,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
 
     /* no cache handle, create a new entity only for non-HEAD requests */
     if (!cache->handle && !r->header_only) {
-        rv = cache_create_entity(r, size, in);
+        rv = cache_create_entity(cache, r, size, in);
         info = apr_pcalloc(r->pool, sizeof(cache_info));
         /* We only set info->status upon the initial creation. */
         info->status = r->status;
@@ -1016,7 +1010,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
     if (rv != OK) {
         /* Caching layer declined the opportunity to cache the response */
         ap_remove_output_filter(f);
-        ap_cache_remove_lock(conf, r, cache->handle ?
+        ap_cache_remove_lock(conf, cache, r, cache->handle ?
                 (char *)cache->handle->cache_obj->key : NULL, NULL);
         return ap_pass_brigade(f->next, in);
     }
@@ -1219,7 +1213,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
         }
 
         /* let someone else attempt to cache */
-        ap_cache_remove_lock(conf, r, cache->handle ?
+        ap_cache_remove_lock(conf, cache, r, cache->handle ?
                 (char *)cache->handle->cache_obj->key : NULL, NULL);
 
         return ap_pass_brigade(f->next, bb);
@@ -1230,7 +1224,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
                      "cache: store_headers failed");
 
         ap_remove_output_filter(f);
-        ap_cache_remove_lock(conf, r, cache->handle ?
+        ap_cache_remove_lock(conf, cache, r, cache->handle ?
                 (char *)cache->handle->cache_obj->key : NULL, NULL);
         return ap_pass_brigade(f->next, in);
     }
index c77ddc0b107e0a13387946c4c635d2a04d68ead6..be1104b2fc354439f23577ca793cd59697348586 100644 (file)
@@ -260,7 +260,7 @@ typedef struct {
     cache_provider_list *providers;     /* possible cache providers */
     const cache_provider *provider;     /* current cache provider */
     const char *provider_name;          /* current cache provider name */
-    int fresh;                          /* is the entitey fresh? */
+    int fresh;                          /* is the entity fresh? */
     cache_handle_t *handle;             /* current cache handle */
     cache_handle_t *stale_handle;       /* stale cache handle */
     apr_table_t *stale_headers;         /* original request headers. */
@@ -291,7 +291,8 @@ CACHE_DECLARE(apr_time_t) ap_cache_current_age(cache_info *info, const apr_time_
  * @param r request_rec
  * @return 0 ==> cache object is stale, 1 ==> cache object is fresh
  */
-CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, request_rec *r);
+CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, cache_request_rec *cache,
+                                            request_rec *r);
 
 /**
  * Check the whether the request allows a cached object to be served as per RFC2616
@@ -324,7 +325,7 @@ CACHE_DECLARE(int) ap_cache_check_allowed(request_rec *r);
  * the backend.
  */
 CACHE_DECLARE(apr_status_t) ap_cache_try_lock(cache_server_conf *conf,
-               request_rec *r, char *key);
+        cache_request_rec *cache, request_rec *r, char *key);
 
 /**
  * Remove the cache lock, if present.
@@ -339,7 +340,8 @@ CACHE_DECLARE(apr_status_t) ap_cache_try_lock(cache_server_conf *conf,
  * removed if the bucket brigade contains an EOS bucket.
  */
 CACHE_DECLARE(apr_status_t) ap_cache_remove_lock(cache_server_conf *conf,
-               request_rec *r, char *key, apr_bucket_brigade *bb);
+        cache_request_rec *cache, request_rec *r, char *key,
+        apr_bucket_brigade *bb);
 
 /**
  * Merge in cached headers into the response
@@ -390,7 +392,8 @@ CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool,
 
 APR_DECLARE_OPTIONAL_FN(apr_status_t,
                         ap_cache_generate_key,
-                        (request_rec *r, apr_pool_t*p, char**key ));
+                        (cache_request_rec *cache, request_rec *r,
+                         apr_pool_t*p, char **key));
 
 
 #endif /*MOD_CACHE_H*/