SSLSESSION_SHARED: new macro to check if session is shared

Added convenience macro to use to check if a handle is using a shared
SSL session, and fixed so that Curl_ssl_close_all() doesn't lock when
the session isn't shared.
This commit is contained in:
Daniel Stenberg 2011-11-25 14:58:55 +01:00
parent 703fa0a6a8
commit 8f50a5c7e5

View File

@ -66,6 +66,11 @@
/* The last #include file should be: */ /* The last #include file should be: */
#include "memdebug.h" #include "memdebug.h"
/* convenience macro to check if this handle is using a shared SSL session */
#define SSLSESSION_SHARED(data) (data->share && \
(data->share->specifier & \
(1<<CURL_LOCK_DATA_SSL_SESSION)))
static bool safe_strequal(char* str1, char* str2) static bool safe_strequal(char* str1, char* str2)
{ {
if(str1 && str2) if(str1 && str2)
@ -242,8 +247,7 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
return TRUE; return TRUE;
/* Lock if shared */ /* Lock if shared */
if(data->share && if(SSLSESSION_SHARED(data)) {
(data->share->specifier & (1<<CURL_LOCK_DATA_SSL_SESSION)) ) {
Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE); Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
general_age = &data->share->sessionage; general_age = &data->share->sessionage;
} }
@ -270,8 +274,7 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
} }
/* Unlock */ /* Unlock */
if(data->share && if(SSLSESSION_SHARED(data))
(data->share->specifier & (1<<CURL_LOCK_DATA_SSL_SESSION)) )
Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION); Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
return no_match; return no_match;
@ -310,7 +313,7 @@ void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
int i; int i;
struct SessionHandle *data=conn->data; struct SessionHandle *data=conn->data;
if(data->share && data->share->sslsession == data->state.session) if(SSLSESSION_SHARED(data))
Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION,
CURL_LOCK_ACCESS_SINGLE); CURL_LOCK_ACCESS_SINGLE);
@ -323,7 +326,7 @@ void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
} }
} }
if(data->share && data->share->sslsession == data->state.session) if(SSLSESSION_SHARED(data))
Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION); Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
} }
@ -356,7 +359,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
the oldest if necessary) */ the oldest if necessary) */
/* If using shared SSL session, lock! */ /* If using shared SSL session, lock! */
if(data->share && data->share->sslsession == data->state.session) { if(SSLSESSION_SHARED(data)) {
Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE); Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
general_age = &data->share->sessionage; general_age = &data->share->sessionage;
} }
@ -390,7 +393,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
/* Unlock */ /* Unlock */
if(data->share && data->share->sslsession == data->state.session) if(SSLSESSION_SHARED(data))
Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION); Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
if(!Curl_clone_ssl_config(&conn->ssl_config, &store->ssl_config)) { if(!Curl_clone_ssl_config(&conn->ssl_config, &store->ssl_config)) {
@ -406,12 +409,8 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
void Curl_ssl_close_all(struct SessionHandle *data) void Curl_ssl_close_all(struct SessionHandle *data)
{ {
long i; long i;
/* kill the session ID cache */ /* kill the session ID cache if not shared */
if(data->state.session && if(data->state.session && !SSLSESSION_SHARED(data)) {
!(data->share && data->share->sslsession == data->state.session)) {
Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
for(i=0; i< data->set.ssl.numsessions; i++) for(i=0; i< data->set.ssl.numsessions; i++)
/* the single-killer function handles empty table slots */ /* the single-killer function handles empty table slots */
Curl_ssl_kill_session(&data->state.session[i]); Curl_ssl_kill_session(&data->state.session[i]);
@ -419,8 +418,6 @@ void Curl_ssl_close_all(struct SessionHandle *data)
/* free the cache data */ /* free the cache data */
free(data->state.session); free(data->state.session);
data->state.session = NULL; data->state.session = NULL;
Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
} }
curlssl_close_all(data); curlssl_close_all(data);