Changeset 556783e in mod_gnutls for src/gnutls_cache.c
- Timestamp:
- Jul 24, 2019, 2:29:40 AM (19 months ago)
- Branches:
- asyncio, master, proxy-ticket
- Children:
- e376ed8
- Parents:
- 81018a4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/gnutls_cache.c
r81018a4 r556783e 175 175 #define SOCACHE_FETCH_BUF_SIZE (8 * 1024) 176 176 177 gnutls_datum_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server, 178 gnutls_datum_t key, apr_pool_t *pool) 179 { 180 gnutls_datum_t data = {NULL, 0}; 181 data.data = gnutls_malloc(SOCACHE_FETCH_BUF_SIZE); 182 if (data.data == NULL) 183 return data; 184 data.size = SOCACHE_FETCH_BUF_SIZE; 185 177 apr_status_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server, 178 gnutls_datum_t key, gnutls_datum_t *output, 179 apr_pool_t *pool) 180 { 186 181 apr_pool_t *spool; 187 182 apr_pool_create(&spool, pool); … … 191 186 apr_status_t rv = cache->prov->retrieve(cache->socache, server, 192 187 key.data, key.size, 193 data.data, &data.size,188 output->data, &output->size, 194 189 spool); 195 190 if (cache->prov->flags & AP_SOCACHE_FLAG_NOTMPSAFE) … … 207 202 "error fetching from cache '%s:%s'", 208 203 cache->prov->name, cache->config); 204 } 205 else 206 { 207 ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, server, 208 "fetched %u bytes from cache '%s:%s'", 209 output->size, cache->prov->name, cache->config); 210 } 211 apr_pool_destroy(spool); 212 213 return rv; 214 } 215 216 217 218 /** 219 * Fetch function for the GnuTLS session cache, see 220 * gnutls_db_set_retrieve_function(). 221 * 222 * *Warning*: The `data` element of the returned `gnutls_datum_t` is 223 * allocated using `gnutls_malloc()` for compatibility with the GnuTLS 224 * session caching API, and must be released using `gnutls_free()`. 225 * 226 * @param baton mgs_handle_t for the connection, as set via 227 * gnutls_db_set_ptr() 228 * 229 * @param key object key to fetch 230 * 231 * @return the requested cache entry, or `{NULL, 0}` 232 */ 233 static gnutls_datum_t socache_fetch_session(void *baton, gnutls_datum_t key) 234 { 235 gnutls_datum_t data = {NULL, 0}; 236 gnutls_datum_t dbmkey; 237 mgs_handle_t *ctxt = baton; 238 239 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0) 240 return data; 241 242 data.data = gnutls_malloc(SOCACHE_FETCH_BUF_SIZE); 243 if (data.data == NULL) 244 return data; 245 data.size = SOCACHE_FETCH_BUF_SIZE; 246 247 apr_status_t rv = mgs_cache_fetch(ctxt->sc->cache, ctxt->c->base_server, 248 dbmkey, &data, ctxt->c->pool); 249 250 if (rv != APR_SUCCESS) 251 { 209 252 /* free unused buffer */ 210 253 gnutls_free(data.data); … … 214 257 else 215 258 { 216 ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, server,217 "fetched %u bytes from cache '%s:%s'",218 data.size, cache->prov->name, cache->config);219 220 259 /* Realloc buffer to data.size. Data size must be less than or 221 260 * equal to the initial buffer size, so this REALLY should not … … 224 263 if (__builtin_expect(data.data == NULL, 0)) 225 264 { 226 ap_log_ error(APLOG_MARK, APLOG_CRIT, APR_ENOMEM, server,265 ap_log_cerror(APLOG_MARK, APLOG_CRIT, APR_ENOMEM, ctxt->c, 227 266 "%s: Could not realloc fetch buffer to data size!", 228 267 __func__); … … 230 269 } 231 270 } 232 apr_pool_destroy(spool);233 271 234 272 return data; 235 }236 237 238 239 /**240 * Fetch function for the GnuTLS session cache, see241 * gnutls_db_set_retrieve_function().242 *243 * *Warning*: The `data` element of the returned `gnutls_datum_t` is244 * allocated using `gnutls_malloc()` for compatibility with the GnuTLS245 * session caching API, and must be released using `gnutls_free()`.246 *247 * @param baton mgs_handle_t for the connection, as set via248 * gnutls_db_set_ptr()249 *250 * @param key object key to fetch251 *252 * @return the requested cache entry, or `{NULL, 0}`253 */254 static gnutls_datum_t socache_fetch_session(void *baton, gnutls_datum_t key)255 {256 gnutls_datum_t data = {NULL, 0};257 gnutls_datum_t dbmkey;258 mgs_handle_t *ctxt = baton;259 260 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0)261 return data;262 263 return mgs_cache_fetch(ctxt->sc->cache, ctxt->c->base_server,264 dbmkey, ctxt->c->pool);265 273 } 266 274
Note: See TracChangeset
for help on using the changeset viewer.