Blame SOURCES/cache-request_rec.patch

6163e3
commit 119cbdd525811908738e8f5d894fe4117cf123a9
6163e3
Author: John Dennis <jdennis@redhat.com>
6163e3
Date:   Tue Jun 13 08:22:15 2017 -0400
6163e3
6163e3
    modify cache functions to take request_rec parameter instead of server_rec
6163e3
    
6163e3
    The entire point of the cache is to persist state between requests so
6163e3
    conceptually it makes sense the cache functions would receive a
6163e3
    server_rec pointer because the cache is a server level data
6163e3
    structure. However most cache operations occur in the context of a
6163e3
    request. Passing a request_rec to a cache function has the following
6163e3
    advantages:
6163e3
    
6163e3
    1) Any logging during a cache operation should be tied to the request.
6163e3
    
6163e3
    2) Any need for temporary memory allocation is much easier to handle
6163e3
    with access to the request's memory pool which is cleaned up at the
6163e3
    end of the request as opposed to trying manage memory allocations at
6163e3
    the server level.
6163e3
    
6163e3
    3) Any need for access to the server_rec is trivially easy to obtain
6163e3
    from the request_rec via r->server. In fact the caller of cache
6163e3
    functions inside requests simplyy provided the server_rec parameter
6163e3
    via r->server, so why not just pass the request_rec?
6163e3
    
6163e3
    These changes are in anticipation of adding enhanced logging and
6163e3
    diagnostics into the cache functions, they will need access to the
6163e3
    request_rec and it's memory pool.
6163e3
    
6163e3
    Signed-off-by: John Dennis <jdennis@redhat.com>
6163e3
6163e3
diff --git a/auth_mellon.h b/auth_mellon.h
6163e3
index 78a5f0d..aff658b 100644
6163e3
--- a/auth_mellon.h
6163e3
+++ b/auth_mellon.h
6163e3
@@ -378,23 +378,23 @@ const char *am_cookie_token(request_rec *r);
6163e3
 
6163e3
 
6163e3
 void am_cache_init(am_mod_cfg_rec *mod_cfg);
6163e3
-am_cache_entry_t *am_cache_lock(server_rec *s, 
6163e3
+am_cache_entry_t *am_cache_lock(request_rec *r, 
6163e3
                                 am_cache_key_t type, const char *key);
6163e3
 const char *am_cache_entry_get_string(am_cache_entry_t *e,
6163e3
                                       am_cache_storage_t *slot);
6163e3
-am_cache_entry_t *am_cache_new(server_rec *s,
6163e3
+am_cache_entry_t *am_cache_new(request_rec *r,
6163e3
                                const char *key,
6163e3
                                const char *cookie_token);
6163e3
-void am_cache_unlock(server_rec *s, am_cache_entry_t *entry);
6163e3
+void am_cache_unlock(request_rec *r, am_cache_entry_t *entry);
6163e3
 
6163e3
-void am_cache_update_expires(am_cache_entry_t *t, apr_time_t expires);
6163e3
+void am_cache_update_expires(request_rec *r, am_cache_entry_t *t, apr_time_t expires);
6163e3
 
6163e3
 void am_cache_env_populate(request_rec *r, am_cache_entry_t *session);
6163e3
 int am_cache_env_append(am_cache_entry_t *session,
6163e3
                         const char *var, const char *val);
6163e3
 const char *am_cache_env_fetch_first(am_cache_entry_t *t,
6163e3
                                      const char *var);
6163e3
-void am_cache_delete(server_rec *s, am_cache_entry_t *session);
6163e3
+void am_cache_delete(request_rec *r, am_cache_entry_t *session);
6163e3
 
6163e3
 int am_cache_set_lasso_state(am_cache_entry_t *session,
6163e3
                              const char *lasso_identity,
6163e3
diff --git a/auth_mellon_cache.c b/auth_mellon_cache.c
6163e3
index 7d51589..af5c267 100644
6163e3
--- a/auth_mellon_cache.c
6163e3
+++ b/auth_mellon_cache.c
6163e3
@@ -70,14 +70,14 @@ void am_cache_init(am_mod_cfg_rec *mod_cfg)
6163e3
  * after you are done with it.
6163e3
  *
6163e3
  * Parameters:
6163e3
- *  server_rec *s        The current server.
6163e3
+ *  request_rec *r       The request we are processing.
6163e3
  *  am_cache_key_t type  AM_CACHE_SESSION or AM_CACHE_NAMEID
6163e3
  *  const char *key      The session key or user
6163e3
  *
6163e3
  * Returns:
6163e3
  *  The session entry on success or NULL on failure.
6163e3
  */
6163e3
-am_cache_entry_t *am_cache_lock(server_rec *s, 
6163e3
+am_cache_entry_t *am_cache_lock(request_rec *r, 
6163e3
                                 am_cache_key_t type,
6163e3
                                 const char *key)
6163e3
 {
6163e3
@@ -104,14 +104,14 @@ am_cache_entry_t *am_cache_lock(server_rec *s,
6163e3
         break;
6163e3
     }
6163e3
 
6163e3
-    mod_cfg = am_get_mod_cfg(s);
6163e3
+    mod_cfg = am_get_mod_cfg(r->server);
6163e3
 
6163e3
 
6163e3
     /* Lock the table. */
6163e3
     if((rv = apr_global_mutex_lock(mod_cfg->lock)) != APR_SUCCESS) {
6163e3
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
6163e3
-                     "apr_global_mutex_lock() failed [%d]: %s",
6163e3
-                     rv, apr_strerror(rv, buffer, sizeof(buffer)));
6163e3
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
6163e3
+                      "apr_global_mutex_lock() failed [%d]: %s",
6163e3
+                      rv, apr_strerror(rv, buffer, sizeof(buffer)));
6163e3
         return NULL;
6163e3
     }
6163e3
 
6163e3
@@ -271,7 +271,7 @@ const char *am_cache_entry_get_string(am_cache_entry_t *e,
6163e3
  * Remember to unlock the table with am_cache_unlock(...) afterwards.
6163e3
  *
6163e3
  * Parameters:
6163e3
- *  server_rec *s        The current server.
6163e3
+ *  request_rec *r       The request we are processing.
6163e3
  *  const char *key      The key of the session to allocate.
6163e3
  *  const char *cookie_token  The cookie token to tie the session to.
6163e3
  *
6163e3
@@ -279,7 +279,7 @@ const char *am_cache_entry_get_string(am_cache_entry_t *e,
6163e3
  *  The new session entry on success. NULL if key is a invalid session
6163e3
  *  key.
6163e3
  */
6163e3
-am_cache_entry_t *am_cache_new(server_rec *s,
6163e3
+am_cache_entry_t *am_cache_new(request_rec *r,
6163e3
                                const char *key,
6163e3
                                const char *cookie_token)
6163e3
 {
6163e3
@@ -298,14 +298,14 @@ am_cache_entry_t *am_cache_new(server_rec *s,
6163e3
     }
6163e3
 
6163e3
 
6163e3
-    mod_cfg = am_get_mod_cfg(s);
6163e3
+    mod_cfg = am_get_mod_cfg(r->server);
6163e3
 
6163e3
 
6163e3
     /* Lock the table. */
6163e3
     if((rv = apr_global_mutex_lock(mod_cfg->lock)) != APR_SUCCESS) {
6163e3
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
6163e3
-                     "apr_global_mutex_lock() failed [%d]: %s",
6163e3
-                     rv, apr_strerror(rv, buffer, sizeof(buffer)));
6163e3
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
6163e3
+                      "apr_global_mutex_lock() failed [%d]: %s",
6163e3
+                      rv, apr_strerror(rv, buffer, sizeof(buffer)));
6163e3
         return NULL;
6163e3
     }
6163e3
 
6163e3
@@ -357,11 +357,11 @@ am_cache_entry_t *am_cache_new(server_rec *s,
6163e3
         age = (current_time - t->access) / 1000000;
6163e3
 
6163e3
         if(age < 3600) {
6163e3
-            ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
6163e3
-                         "Dropping LRU entry entry with age = %" APR_TIME_T_FMT
6163e3
-                         "s, which is less than one hour. It may be a good"
6163e3
-                         " idea to increase MellonCacheSize.",
6163e3
-                         age);
6163e3
+            ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
6163e3
+                          "Dropping LRU entry entry with age = %" APR_TIME_T_FMT
6163e3
+                          "s, which is less than one hour. It may be a good"
6163e3
+                          " idea to increase MellonCacheSize.",
6163e3
+                          age);
6163e3
         }
6163e3
     }
6163e3
 
6163e3
@@ -393,8 +393,8 @@ am_cache_entry_t *am_cache_new(server_rec *s,
6163e3
         /* For some strange reason our cookie token is too big to fit in the
6163e3
          * session. This should never happen outside of absurd configurations.
6163e3
          */
6163e3
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
6163e3
-                     "Unable to store cookie token in new session.");
6163e3
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
6163e3
+                      "Unable to store cookie token in new session.");
6163e3
         t->key[0] = '\0'; /* Mark the entry as free. */
6163e3
         apr_global_mutex_unlock(mod_cfg->lock);
6163e3
         return NULL;
6163e3
@@ -407,20 +407,20 @@ am_cache_entry_t *am_cache_new(server_rec *s,
6163e3
 /* This function unlocks a session entry.
6163e3
  *
6163e3
  * Parameters:
6163e3
- *  server_rec *s            The current server.
6163e3
+ *  request_rec *r           The request we are processing.
6163e3
  *  am_cache_entry_t *entry  The session entry.
6163e3
  *
6163e3
  * Returns:
6163e3
  *  Nothing.
6163e3
  */
6163e3
-void am_cache_unlock(server_rec *s, am_cache_entry_t *entry)
6163e3
+void am_cache_unlock(request_rec *r, am_cache_entry_t *entry)
6163e3
 {
6163e3
     am_mod_cfg_rec *mod_cfg;
6163e3
 
6163e3
     /* Update access time. */
6163e3
     entry->access = apr_time_now();
6163e3
 
6163e3
-    mod_cfg = am_get_mod_cfg(s);
6163e3
+    mod_cfg = am_get_mod_cfg(r->server);
6163e3
     apr_global_mutex_unlock(mod_cfg->lock);
6163e3
 }
6163e3
 
6163e3
@@ -429,13 +429,14 @@ void am_cache_unlock(server_rec *s, am_cache_entry_t *entry)
6163e3
  * timestamp is earlier than the previous.
6163e3
  *
6163e3
  * Parameters:
6163e3
+ *  request_rec *r        The request we are processing.
6163e3
  *  am_cache_entry_t *t   The current session.
6163e3
  *  apr_time_t expires    The new timestamp.
6163e3
  *
6163e3
  * Returns:
6163e3
  *  Nothing.
6163e3
  */
6163e3
-void am_cache_update_expires(am_cache_entry_t *t, apr_time_t expires)
6163e3
+void am_cache_update_expires(request_rec *r, am_cache_entry_t *t, apr_time_t expires)
6163e3
 {
6163e3
     /* Check if we should update the expires timestamp. */
6163e3
     if(t->expires == 0 || t->expires > expires) {
6163e3
@@ -698,13 +699,13 @@ void am_cache_env_populate(request_rec *r, am_cache_entry_t *t)
6163e3
 /* This function deletes a given key from the session store.
6163e3
  *
6163e3
  * Parameters:
6163e3
- *  server_rec *s             The current server.
6163e3
+ *  request_rec *r            The request we are processing.
6163e3
  *  am_cache_entry_t *cache   The entry we are deleting.
6163e3
  *
6163e3
  * Returns:
6163e3
  *  Nothing.
6163e3
  */
6163e3
-void am_cache_delete(server_rec *s, am_cache_entry_t *cache)
6163e3
+void am_cache_delete(request_rec *r, am_cache_entry_t *cache)
6163e3
 {
6163e3
     /* We write a null-byte at the beginning of the key to
6163e3
      * mark this slot as unused. 
6163e3
@@ -712,7 +713,7 @@ void am_cache_delete(server_rec *s, am_cache_entry_t *cache)
6163e3
     cache->key[0] = '\0';
6163e3
 
6163e3
     /* Unlock the entry. */
6163e3
-    am_cache_unlock(s, cache);
6163e3
+    am_cache_unlock(r, cache);
6163e3
 }
6163e3
 
6163e3
 
6163e3
diff --git a/auth_mellon_handler.c b/auth_mellon_handler.c
6163e3
index 5661083..44a5ee9 100644
6163e3
--- a/auth_mellon_handler.c
6163e3
+++ b/auth_mellon_handler.c
6163e3
@@ -1479,7 +1479,7 @@ static void am_handle_session_expire(request_rec *r, am_cache_entry_t *session,
6163e3
         /* Updates the expires timestamp if this one is earlier than the
6163e3
          * previous timestamp.
6163e3
          */
6163e3
-        am_cache_update_expires(session, t);
6163e3
+        am_cache_update_expires(r, session, t);
6163e3
     }
6163e3
 }
6163e3
 
6163e3
@@ -1517,10 +1517,10 @@ static int add_attributes(am_cache_entry_t *session, request_rec *r,
6163e3
     /* Set expires to whatever is set by MellonSessionLength. */
6163e3
     if(dir_cfg->session_length == -1) {
6163e3
         /* -1 means "use default. The current default is 86400 seconds. */
6163e3
-        am_cache_update_expires(session, apr_time_now()
6163e3
+        am_cache_update_expires(r, session, apr_time_now()
6163e3
                                 + apr_time_make(86400, 0));
6163e3
     } else {
6163e3
-        am_cache_update_expires(session, apr_time_now()
6163e3
+        am_cache_update_expires(r, session, apr_time_now()
6163e3
                                 + apr_time_make(dir_cfg->session_length, 0));
6163e3
     }
6163e3
 
6163e3
diff --git a/auth_mellon_session.c b/auth_mellon_session.c
6163e3
index fca6c01..856dbb6 100644
6163e3
--- a/auth_mellon_session.c
6163e3
+++ b/auth_mellon_session.c
6163e3
@@ -39,7 +39,7 @@ am_cache_entry_t *am_lock_and_validate(request_rec *r,
6163e3
                                        am_cache_key_t type,
6163e3
                                        const char *key)
6163e3
 {
6163e3
-    am_cache_entry_t *session = am_cache_lock(r->server, type, key);
6163e3
+    am_cache_entry_t *session = am_cache_lock(r, type, key);
6163e3
     if (session == NULL) {
6163e3
         return NULL;
6163e3
     }
6163e3
@@ -54,7 +54,7 @@ am_cache_entry_t *am_lock_and_validate(request_rec *r,
6163e3
                       "request has {%s}.",
6163e3
                       cookie_token_session,
6163e3
                       cookie_token_target);
6163e3
-        am_cache_unlock(r->server, session);
6163e3
+        am_cache_unlock(r, session);
6163e3
         return NULL;
6163e3
     }
6163e3
 
6163e3
@@ -124,7 +124,7 @@ am_cache_entry_t *am_new_request_session(request_rec *r)
6163e3
     am_cookie_set(r, session_id);
6163e3
 
6163e3
     const char *cookie_token = am_cookie_token(r);
6163e3
-    return am_cache_new(r->server, session_id, cookie_token);
6163e3
+    return am_cache_new(r, session_id, cookie_token);
6163e3
 }
6163e3
 
6163e3
 
6163e3
@@ -140,7 +140,7 @@ am_cache_entry_t *am_new_request_session(request_rec *r)
6163e3
  */
6163e3
 void am_release_request_session(request_rec *r, am_cache_entry_t *session)
6163e3
 {
6163e3
-    am_cache_unlock(r->server, session);
6163e3
+    am_cache_unlock(r, session);
6163e3
 }
6163e3
 
6163e3
 
6163e3
@@ -164,5 +164,5 @@ void am_delete_request_session(request_rec *r, am_cache_entry_t *session)
6163e3
     }
6163e3
 
6163e3
     /* Delete session from the session store. */
6163e3
-    am_cache_delete(r->server, session);
6163e3
+    am_cache_delete(r, session);
6163e3
 }