21
21
22
22
#include "auth_mellon.h"
23
23
24
+ /* Calculate the pointer to a cache entry.
25
+ *
26
+ * Parameters:
27
+ * am_mod_cfg_rec *mod_cfg The module configuration.
28
+ * void *table The base pointer for the table.
29
+ * apr_size_t index The index we are looking for.
30
+ *
31
+ * Returns:
32
+ * The session entry with the given index.
33
+ */
34
+ static inline am_cache_entry_t * am_cache_entry_ptr (am_mod_cfg_rec * mod_cfg ,
35
+ void * table , apr_size_t index )
36
+ {
37
+ uint8_t * table_calc ;
38
+ table_calc = table ;
39
+ return (am_cache_entry_t * )& table_calc [mod_cfg -> init_entry_size * index ];
40
+ }
41
+
24
42
/* Initialize the session table.
25
43
*
26
44
* Parameters:
31
49
*/
32
50
void am_cache_init (am_mod_cfg_rec * mod_cfg )
33
51
{
34
- am_cache_entry_t * table ;
35
- int i ;
52
+ void * table ;
53
+ apr_size_t i ;
36
54
/* Initialize the session table. */
37
55
table = apr_shm_baseaddr_get (mod_cfg -> cache );
38
56
for (i = 0 ; i < mod_cfg -> cache_size ; i ++ ) {
39
- table [i ].key [0 ] = '\0' ;
40
- table [i ].access = 0 ;
57
+ am_cache_entry_t * e = am_cache_entry_ptr (mod_cfg , table , i );
58
+ e -> key [0 ] = '\0' ;
59
+ e -> access = 0 ;
41
60
}
42
61
}
43
62
@@ -59,8 +78,8 @@ am_cache_entry_t *am_cache_lock(server_rec *s,
59
78
const char * key )
60
79
{
61
80
am_mod_cfg_rec * mod_cfg ;
62
- am_cache_entry_t * table ;
63
- int i ;
81
+ void * table ;
82
+ apr_size_t i ;
64
83
int rv ;
65
84
char buffer [512 ];
66
85
@@ -96,20 +115,21 @@ am_cache_entry_t *am_cache_lock(server_rec *s,
96
115
97
116
98
117
for (i = 0 ; i < mod_cfg -> init_cache_size ; i ++ ) {
118
+ am_cache_entry_t * e = am_cache_entry_ptr (mod_cfg , table , i );
99
119
const char * tablekey ;
100
120
101
- if (table [ i ]. key [0 ] == '\0' ) {
121
+ if (e -> key [0 ] == '\0' ) {
102
122
/* This entry is empty. Skip it. */
103
123
continue ;
104
124
}
105
125
106
126
switch (type ) {
107
127
case AM_CACHE_SESSION :
108
- tablekey = table [ i ]. key ;
128
+ tablekey = e -> key ;
109
129
break ;
110
130
case AM_CACHE_NAMEID :
111
131
/* tablekey may be NULL */
112
- tablekey = am_cache_env_fetch_first (& table [ i ] , "NAME_ID" );
132
+ tablekey = am_cache_env_fetch_first (e , "NAME_ID" );
113
133
break ;
114
134
default :
115
135
tablekey = NULL ;
@@ -121,9 +141,9 @@ am_cache_entry_t *am_cache_lock(server_rec *s,
121
141
122
142
if (strcmp (tablekey , key ) == 0 ) {
123
143
/* We found the entry. */
124
- if (table [ i ]. expires > apr_time_now ()) {
144
+ if (e -> expires > apr_time_now ()) {
125
145
/* And it hasn't expired. */
126
- return & table [ i ] ;
146
+ return e ;
127
147
}
128
148
}
129
149
}
0 commit comments