bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / ssl / ssl_scache.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*                      _             _
18  *  _ __ ___   ___   __| |    ___ ___| |  mod_ssl
19  * | '_ ` _ \ / _ \ / _` |   / __/ __| |  Apache Interface to OpenSSL
20  * | | | | | | (_) | (_| |   \__ \__ \ |
21  * |_| |_| |_|\___/ \__,_|___|___/___/_|
22  *                      |_____|
23  *  ssl_scache.c
24  *  Session Cache Abstraction
25  */
26                              /* ``Open-Source Software: generous
27                                   programmers from around the world all
28                                   join forces to help you shoot
29                                   yourself in the foot for free.''
30                                                  -- Unknown         */
31 #include "mod_ssl.h"
32
33 /*  _________________________________________________________________
34 **
35 **  Session Cache: Common Abstraction Layer
36 **  _________________________________________________________________
37 */
38
39 void ssl_scache_init(server_rec *s, apr_pool_t *p)
40 {
41     SSLModConfigRec *mc = myModConfig(s);
42
43     /*
44      * Warn the user that he should use the session cache.
45      * But we can operate without it, of course.
46      */
47     if (mc->nSessionCacheMode == SSL_SCMODE_UNSET) {
48         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
49                      "Init: Session Cache is not configured "
50                      "[hint: SSLSessionCache]");
51         mc->nSessionCacheMode = SSL_SCMODE_NONE;
52         return;
53     }
54
55     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
56         ssl_scache_dbm_init(s, p);
57     else if ((mc->nSessionCacheMode == SSL_SCMODE_SHMHT) ||
58              (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)) {
59         void *data;
60         const char *userdata_key = "ssl_scache_init";
61
62         apr_pool_userdata_get(&data, userdata_key, s->process->pool);
63         if (!data) {
64             apr_pool_userdata_set((const void *)1, userdata_key,
65                                   apr_pool_cleanup_null, s->process->pool);
66             return;
67         }
68         if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
69             ssl_scache_shmht_init(s, p);
70         else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
71             ssl_scache_shmcb_init(s, p);
72     }
73 }
74
75 void ssl_scache_kill(server_rec *s)
76 {
77     SSLModConfigRec *mc = myModConfig(s);
78
79     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
80         ssl_scache_dbm_kill(s);
81     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
82         ssl_scache_shmht_kill(s);
83     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
84         ssl_scache_shmcb_kill(s);
85     return;
86 }
87
88 BOOL ssl_scache_store(server_rec *s, UCHAR *id, int idlen, time_t expiry, SSL_SESSION *sess)
89 {
90     SSLModConfigRec *mc = myModConfig(s);
91     BOOL rv = FALSE;
92
93     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
94         rv = ssl_scache_dbm_store(s, id, idlen, expiry, sess);
95     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
96         rv = ssl_scache_shmht_store(s, id, idlen, expiry, sess);
97     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
98         rv = ssl_scache_shmcb_store(s, id, idlen, expiry, sess);
99     return rv;
100 }
101
102 SSL_SESSION *ssl_scache_retrieve(server_rec *s, UCHAR *id, int idlen)
103 {
104     SSLModConfigRec *mc = myModConfig(s);
105     SSL_SESSION *sess = NULL;
106
107     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
108         sess = ssl_scache_dbm_retrieve(s, id, idlen);
109     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
110         sess = ssl_scache_shmht_retrieve(s, id, idlen);
111     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
112         sess = ssl_scache_shmcb_retrieve(s, id, idlen);
113     return sess;
114 }
115
116 void ssl_scache_remove(server_rec *s, UCHAR *id, int idlen)
117 {
118     SSLModConfigRec *mc = myModConfig(s);
119
120     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
121         ssl_scache_dbm_remove(s, id, idlen);
122     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
123         ssl_scache_shmht_remove(s, id, idlen);
124     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
125         ssl_scache_shmcb_remove(s, id, idlen);
126     return;
127 }
128
129 void ssl_scache_status(server_rec *s, apr_pool_t *p, void (*func)(char *, void *), void *arg)
130 {
131     SSLModConfigRec *mc = myModConfig(s);
132
133     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
134         ssl_scache_dbm_status(s, p, func, arg);
135     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
136         ssl_scache_shmht_status(s, p, func, arg);
137     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
138         ssl_scache_shmcb_status(s, p, func, arg);
139     return;
140 }
141
142 void ssl_scache_expire(server_rec *s)
143 {
144     SSLModConfigRec *mc = myModConfig(s);
145
146     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
147         ssl_scache_dbm_expire(s);
148     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
149         ssl_scache_shmht_expire(s);
150     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
151         ssl_scache_shmcb_expire(s);
152     return;
153 }
154
155 /*  _________________________________________________________________
156 **
157 **  SSL Extension to mod_status
158 **  _________________________________________________________________
159 */
160 #if 0 /* NOT YET */
161 static void ssl_ext_ms_display(request_rec *, int, int);
162
163 void ssl_scache_status_register(apr_pool_t *p)
164 {
165     /* XXX point mod_status to this update, when it grows the opt fn */
166 #if 0
167     ap_hook_register("ap::mod_status::display", ssl_ext_ms_display, AP_HOOK_NOCTX);
168 #endif
169     return;
170 }
171
172 static void ssl_ext_ms_display_cb(char *str, void *_r)
173 {
174     request_rec *r = (request_rec *)_r;
175     if (str != NULL)
176         ap_rputs(str, r);
177     return;
178 }
179
180 static void ssl_ext_ms_display(request_rec *r, int no_table_report, int short_report)
181 {
182     SSLSrvConfigRec *sc = mySrvConfig(r->server);
183
184     if (sc == NULL)
185         return;
186     if (short_report)
187         return;
188     ap_rputs("<hr>\n", r);
189     ap_rputs("<table cellspacing=0 cellpadding=0>\n", r);
190     ap_rputs("<tr><td bgcolor=\"#000000\">\n", r);
191     ap_rputs("<b><font color=\"#ffffff\" face=\"Arial,Helvetica\">SSL/TLS Session Cache Status:</font></b>\r", r);
192     ap_rputs("</td></tr>\n", r);
193     ap_rputs("<tr><td bgcolor=\"#ffffff\">\n", r);
194     ssl_scache_status(r->server, r->pool, ssl_ext_ms_display_cb, r);
195     ap_rputs("</td></tr>\n", r);
196     ap_rputs("</table>\n", r);
197     return;
198 }
199 #endif