Skip to content

Commit

Permalink
SSLSESSION_SHARED: new macro to check if session is shared
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bagder committed Nov 25, 2011
1 parent 703fa0a commit 8f50a5c
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions lib/sslgen.c
Expand Up @@ -66,6 +66,11 @@
/* The last #include file should be: */
#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)
{
if(str1 && str2)
Expand Down Expand Up @@ -242,8 +247,7 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
return TRUE;

/* Lock if shared */
if(data->share &&
(data->share->specifier & (1<<CURL_LOCK_DATA_SSL_SESSION)) ) {
if(SSLSESSION_SHARED(data)) {
Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
general_age = &data->share->sessionage;
}
Expand All @@ -270,8 +274,7 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
}

/* Unlock */
if(data->share &&
(data->share->specifier & (1<<CURL_LOCK_DATA_SSL_SESSION)) )
if(SSLSESSION_SHARED(data))
Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);

return no_match;
Expand Down Expand Up @@ -310,7 +313,7 @@ void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
int i;
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_LOCK_ACCESS_SINGLE);

Expand All @@ -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);
}

Expand Down Expand Up @@ -356,7 +359,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
the oldest if necessary) */

/* 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);
general_age = &data->share->sessionage;
}
Expand Down Expand Up @@ -390,7 +393,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,


/* Unlock */
if(data->share && data->share->sslsession == data->state.session)
if(SSLSESSION_SHARED(data))
Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);

if(!Curl_clone_ssl_config(&conn->ssl_config, &store->ssl_config)) {
Expand All @@ -406,21 +409,15 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
void Curl_ssl_close_all(struct SessionHandle *data)
{
long i;
/* kill the session ID cache */
if(data->state.session &&
!(data->share && data->share->sslsession == data->state.session)) {

Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);

/* kill the session ID cache if not shared */
if(data->state.session && !SSLSESSION_SHARED(data)) {
for(i=0; i< data->set.ssl.numsessions; i++)
/* the single-killer function handles empty table slots */
Curl_ssl_kill_session(&data->state.session[i]);

/* free the cache data */
free(data->state.session);
data->state.session = NULL;

Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
}

curlssl_close_all(data);
Expand Down

0 comments on commit 8f50a5c

Please sign in to comment.