share: don't use SSL unless enabled

Don't even declare the struct members for disabled features

Introducing the CURLSHE_NOT_BUILT_IN return code for the share interface
when trying to set a sharing option that has been disabled (or not
enabled) in the library.
This commit is contained in:
Daniel Stenberg 2011-10-03 22:32:36 +02:00
parent 9dd85bced5
commit 15e3e45170
6 changed files with 33 additions and 7 deletions

View File

@ -277,3 +277,6 @@ An invalid share object was passed to the function.
.IP "CURLSHE_NOMEM (4)" .IP "CURLSHE_NOMEM (4)"
Not enough memory was available. Not enough memory was available.
(Added in 7.12.0) (Added in 7.12.0)
.IP "CURLSHE_NOT_BUILT_IN (5)"
The requsted sharing could not be done because the library you use don't have
that particular feature enabled. (Added in 7.23.0)

View File

@ -550,6 +550,7 @@ CURLSHE_BAD_OPTION 7.10.3
CURLSHE_INVALID 7.10.3 CURLSHE_INVALID 7.10.3
CURLSHE_IN_USE 7.10.3 CURLSHE_IN_USE 7.10.3
CURLSHE_NOMEM 7.12.0 CURLSHE_NOMEM 7.12.0
CURLSHE_NOT_BUILT_IN 7.23.0
CURLSHE_OK 7.10.3 CURLSHE_OK 7.10.3
CURLSHOPT_LOCKFUNC 7.10.3 CURLSHOPT_LOCKFUNC 7.10.3
CURLSHOPT_NONE 7.10.3 CURLSHOPT_NONE 7.10.3

View File

@ -2014,8 +2014,9 @@ typedef enum {
CURLSHE_BAD_OPTION, /* 1 */ CURLSHE_BAD_OPTION, /* 1 */
CURLSHE_IN_USE, /* 2 */ CURLSHE_IN_USE, /* 2 */
CURLSHE_INVALID, /* 3 */ CURLSHE_INVALID, /* 3 */
CURLSHE_NOMEM, /* out of memory */ CURLSHE_NOMEM, /* 4 out of memory */
CURLSHE_LAST /* never use */ CURLSHE_NOT_BUILT_IN, /* 5 feature not present in lib */
CURLSHE_LAST /* never use */
} CURLSHcode; } CURLSHcode;
typedef enum { typedef enum {

View File

@ -73,17 +73,20 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
} }
break; break;
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
case CURL_LOCK_DATA_COOKIE: case CURL_LOCK_DATA_COOKIE:
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
if(!share->cookies) { if(!share->cookies) {
share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE );
if(!share->cookies) if(!share->cookies)
return CURLSHE_NOMEM; return CURLSHE_NOMEM;
} }
break; break;
#endif /* CURL_DISABLE_HTTP */ #else /* CURL_DISABLE_HTTP */
return CURLSHE_NOT_BUILT_IN;
#endif
case CURL_LOCK_DATA_SSL_SESSION: case CURL_LOCK_DATA_SSL_SESSION:
#ifdef USE_SSL
if(!share->sslsession) { if(!share->sslsession) {
share->nsslsession = 8; share->nsslsession = 8;
share->sslsession = calloc(share->nsslsession, share->sslsession = calloc(share->nsslsession,
@ -92,6 +95,9 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
return CURLSHE_NOMEM; return CURLSHE_NOMEM;
} }
break; break;
#else
return CURLSHE_NOT_BUILT_IN;
#endif
case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */
@ -112,22 +118,28 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
} }
break; break;
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
case CURL_LOCK_DATA_COOKIE: case CURL_LOCK_DATA_COOKIE:
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
if(share->cookies) { if(share->cookies) {
Curl_cookie_cleanup(share->cookies); Curl_cookie_cleanup(share->cookies);
share->cookies = NULL; share->cookies = NULL;
} }
break; break;
#endif /* CURL_DISABLE_HTTP */ #else /* CURL_DISABLE_HTTP */
return CURLSHE_NOT_BUILT_IN;
#endif
case CURL_LOCK_DATA_SSL_SESSION: case CURL_LOCK_DATA_SSL_SESSION:
#ifdef USE_SSL
if(share->sslsession) { if(share->sslsession) {
free(share->sslsession); free(share->sslsession);
share->sslsession = NULL; share->sslsession = NULL;
share->nsslsession = 0; share->nsslsession = 0;
} }
break; break;
#else
return CURLSHE_NOT_BUILT_IN;
#endif
case CURL_LOCK_DATA_CONNECT: case CURL_LOCK_DATA_CONNECT:
break; break;
@ -186,11 +198,13 @@ curl_share_cleanup(CURLSH *sh)
if(share->cookies) if(share->cookies)
Curl_cookie_cleanup(share->cookies); Curl_cookie_cleanup(share->cookies);
#ifdef USE_SSL
if(share->sslsession) { if(share->sslsession) {
for(i = 0; i < share->nsslsession; ++i) for(i = 0; i < share->nsslsession; ++i)
Curl_ssl_kill_session(&(share->sslsession[i])); Curl_ssl_kill_session(&(share->sslsession[i]));
free(share->sslsession); free(share->sslsession);
} }
#endif
if(share->unlockfunc) if(share->unlockfunc)
share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata);

View File

@ -8,7 +8,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -46,9 +46,13 @@ struct Curl_share {
void *clientdata; void *clientdata;
struct curl_hash *hostcache; struct curl_hash *hostcache;
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
struct CookieInfo *cookies; struct CookieInfo *cookies;
#endif
#ifdef USE_SSL
struct curl_ssl_session *sslsession; struct curl_ssl_session *sslsession;
#endif
unsigned int nsslsession; unsigned int nsslsession;
}; };

View File

@ -384,6 +384,9 @@ curl_share_strerror(CURLSHcode error)
case CURLSHE_NOMEM: case CURLSHE_NOMEM:
return "Out of memory"; return "Out of memory";
case CURLSHE_NOT_BUILT_IN:
return "Feature not enabled in this library";
case CURLSHE_LAST: case CURLSHE_LAST:
break; break;
} }