Changeset ce5f776 in mod_gnutls for src/gnutls_cache.c
- Timestamp:
- May 2, 2018, 2:30:26 PM (3 years ago)
- Branches:
- asyncio, debian/master, master, proxy-ticket
- Children:
- eaa8a9d
- Parents:
- 5ab2868
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/gnutls_cache.c
r5ab2868 rce5f776 306 306 307 307 308 const char *mgs_cache_inst_config(mgs_cache_t *cache, server_rec *server, 309 const char* type, const char* config, 310 apr_pool_t *pconf, apr_pool_t *ptemp) 311 { 312 /* allocate cache structure if needed */ 313 if (*cache == NULL) 314 { 315 *cache = apr_pcalloc(pconf, sizeof(struct mgs_cache)); 316 if (*cache == NULL) 317 return "Could not allocate memory for cache configuration!"; 318 } 319 mgs_cache_t c = *cache; 320 321 /* Find the right socache provider */ 322 c->prov = ap_lookup_provider(AP_SOCACHE_PROVIDER_GROUP, 323 type, 324 AP_SOCACHE_PROVIDER_VERSION); 325 if (c->prov == NULL) 326 { 327 return apr_psprintf(ptemp, 328 "Could not find socache provider '%s', please " 329 "make sure that the provider name is valid and " 330 "the appropriate module is loaded (maybe " 331 "mod_socache_%s.so?).", 332 type, type); 333 } 334 335 /* shmcb works fine with NULL, but make sure there's a valid (if 336 * empty) string for logging */ 337 if (config != NULL) 338 c->config = apr_pstrdup(pconf, config); 339 else 340 c->config = ""; 341 342 /* Create and configure the cache instance. */ 343 const char *err = c->prov->create(&c->socache, c->config, ptemp, pconf); 344 if (err != NULL) 345 { 346 return apr_psprintf(ptemp, 347 "Creating cache '%s:%s' failed: %s", 348 c->prov->name, c->config, err); 349 } 350 ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, server, 351 "%s: Socache '%s:%s' created.", 352 __func__, c->prov->name, c->config); 353 354 return NULL; 355 } 356 357 358 359 /** 360 * This function is supposed to be called during post_config to 361 * initialize mutex and socache instance associated with an 362 * mgs_cache_t. 363 * 364 * @param cache the mod_gnutls cache structure 365 * 366 * @param cache_name name for socache initialization 367 * 368 * @param mutex_name name to pass to ap_global_mutex_create(), must 369 * have been registered during pre_config. 370 * 371 * @param server server for logging purposes 372 * 373 * @param pconf memory pool for server configuration 374 */ 375 static apr_status_t mgs_cache_inst_init(mgs_cache_t cache, 376 const char *cache_name, 377 const char *mutex_name, 378 server_rec *server, 379 apr_pool_t *pconf) 380 { 381 apr_status_t rv = APR_SUCCESS; 382 383 if (cache->mutex == NULL) 384 { 385 rv = ap_global_mutex_create(&cache->mutex, NULL, 386 mutex_name, 387 NULL, server, pconf, 0); 388 ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, server, 389 "%s: create mutex", __func__); 390 if (rv != APR_SUCCESS) 391 return rv; 392 } 393 394 rv = cache->prov->init(cache->socache, cache_name, NULL, server, pconf); 395 if (rv != APR_SUCCESS) 396 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, server, 397 "Initializing cache '%s:%s' failed!", 398 cache->prov->name, cache->config); 399 else 400 ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, server, 401 "%s: socache '%s:%s' initialized.", __func__, 402 cache->prov->name, cache->config); 403 return rv; 404 } 405 406 407 308 408 static apr_status_t cleanup_socache(void *data) 309 409 { … … 320 420 321 421 322 int mgs_cache_post_config(apr_pool_t *pconf, apr_pool_t *ptemp, 422 int mgs_cache_post_config(apr_pool_t *pconf, 423 apr_pool_t *ptemp __attribute__((unused)), 323 424 server_rec *s, mgs_srvconf_rec *sc) 324 425 { … … 336 437 sc->cache_timeout = apr_time_from_sec(MGS_DEFAULT_CACHE_TIMEOUT); 337 438 338 /* initialize cache structure and mutex if needed */ 339 if (sc->cache == NULL) 340 { 341 sc->cache = apr_pcalloc(pconf, sizeof(struct mgs_cache)); 342 rv = ap_global_mutex_create(&sc->cache->mutex, NULL, 343 MGS_CACHE_MUTEX_NAME, 344 NULL, s, pconf, 0); 345 if (rv != APR_SUCCESS) 346 return rv; 347 } 348 349 /* Find the right socache provider */ 350 sc->cache->prov = ap_lookup_provider(AP_SOCACHE_PROVIDER_GROUP, 351 sc->cache_type, 352 AP_SOCACHE_PROVIDER_VERSION); 353 if (sc->cache->prov) 354 { 355 /* Create and configure the cache instance. */ 356 sc->cache->config = sc->cache_config; 357 const char *err = sc->cache->prov->create(&sc->cache->socache, 358 sc->cache->config, 359 ptemp, pconf); 360 if (err != NULL) 361 { 362 ap_log_error(APLOG_MARK, APLOG_EMERG, APR_EGENERAL, s, 363 "Creating cache '%s:%s' failed: %s", 364 sc->cache_type, sc->cache->config, err); 365 return HTTP_INSUFFICIENT_STORAGE; 366 } 367 ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, s, 368 "%s: Socache '%s' created.", __func__, sc->cache_type); 369 370 // TODO: provide hints 371 rv = sc->cache->prov->init(sc->cache->socache, 372 "mod_gnutls-session", NULL, s, pconf); 373 if (rv != APR_SUCCESS) 374 { 375 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, 376 "Initializing cache '%s:%s' failed!", 377 sc->cache_type, sc->cache->config); 378 return HTTP_INSUFFICIENT_STORAGE; 379 } 380 ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, s, 381 "%s: socache '%s:%s' created.", __func__, 382 sc->cache_type, sc->cache->config); 383 } 384 else 385 { 386 ap_log_error(APLOG_MARK, APLOG_EMERG, APR_EGENERAL, s, 387 "Could not find socache provider '%s', please make sure " 388 "that the provider name is valid and the " 389 "appropriate mod_socache submodule is loaded.", 390 sc->cache_type); 391 return HTTP_NOT_FOUND; 392 } 439 rv = mgs_cache_inst_init(sc->cache, "mod_gnutls-session", 440 MGS_CACHE_MUTEX_NAME, s, pconf); 441 if (rv != APR_SUCCESS) 442 return HTTP_INSUFFICIENT_STORAGE; 393 443 394 444 apr_pool_pre_cleanup_register(pconf, s, cleanup_socache);
Note: See TracChangeset
for help on using the changeset viewer.