From 6dfe0ec31ed5ac5c9868b08bd8340a2101e8b667 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 13 Aug 2002 14:20:47 +0000 Subject: Sterling Hughes brings the share interface --- lib/share.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 lib/share.c (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c new file mode 100644 index 000000000..1050e50a1 --- /dev/null +++ b/lib/share.c @@ -0,0 +1,169 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * + * In order to be useful for every potential user, curl and libcurl are + * dual-licensed under the MPL and the MIT/X-derivate licenses. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the MPL or the MIT/X-derivate + * licenses. You may pick one of these licenses. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * $Id$ + *****************************************************************************/ + +#include "setup.h" +#include +#include +#include "share.h" +#include "urldata.h" + +/* The last #include file should be: */ +#ifdef MALLOCDEBUG +#include "memdebug.h" +#endif + +#define CURL_SHARE_SET_LOCKED(__share, __type) ((__share)->locked += (__type)) +#define CURL_SHARE_SET_UNLOCKED(__share, __type) ((__share)->locked -= (__type)) + +#define CURL_SHARE_SET_USED(__share, __type) ((__share)->specifier += (__type)) +#define CURL_SHARE_SET_UNUSED(__share, __type) ((__share)->specifier -= (__type)) +#define CURL_SHARE_IS_USED(__share, __type) ((__share)->specifier & (__type)) +#define CURL_SHARE_IS_LOCKED(__share, __type) ((__share)->locked & (__type)) + +#define CURL_SHARE_IS_DIRTY(__share) ((__share)->dirty) + +#define CURL_SHARE_GET(__handle) (((struct SessionHandle *) (__handle))->share) + +curl_share * +curl_share_init (void) +{ + curl_share *share = (curl_share *) malloc (sizeof (curl_share)); + if (share) { + memset (share, 0, sizeof (curl_share)); + } + + return share; +} + +CURLcode +curl_share_setopt (curl_share *share, curl_lock_type option, int enable) +{ + if (CURL_SHARE_IS_DIRTY(share)) { + return CURLE_SHARE_IN_USE; + } + + if (enable) { + CURL_SHARE_SET_USED (share, option); + } + else { + CURL_SHARE_SET_UNUSED (share, option); + } + + return CURLE_OK; +} + +CURLcode +curl_share_set_lock_function (curl_share *share, curl_lock_function lock) +{ + if (CURL_SHARE_IS_DIRTY(share)) { + return CURLE_SHARE_IN_USE; + } + + share->lockfunc = lock; + return CURLE_OK; +} + +CURLcode +curl_share_set_unlock_function (curl_share *share, curl_unlock_function unlock) +{ + if (CURL_SHARE_IS_DIRTY(share)) { + return CURLE_SHARE_IN_USE; + } + + share->unlockfunc = unlock; + return CURLE_OK; +} + +CURLcode +curl_share_set_lock_data (curl_share *share, void *data) +{ + if (CURL_SHARE_IS_DIRTY(share)) { + return CURLE_SHARE_IN_USE; + } + + share->clientdata = data; + return CURLE_OK; +} + +Curl_share_error +Curl_share_acquire_lock (CURL *handle, curl_lock_type type) +{ + curl_share *share = CURL_SHARE_GET (handle); + if (share == NULL) { + return SHARE_ERROR_INVALID; + } + + if (! (share->specifier & type)) { + return SHARE_ERROR_NOT_REGISTERED; + } + + if (CURL_SHARE_IS_LOCKED (share, type)) { + return SHARE_ERROR_OK; + } + + share->lockfunc (handle, type, share->clientdata); + CURL_SHARE_SET_LOCKED (share, type); + + return SHARE_ERROR_OK; +} + +Curl_share_error +Curl_share_release_lock (CURL *handle, curl_lock_type type) +{ + curl_share *share = CURL_SHARE_GET(handle); + if (share == NULL) { + return SHARE_ERROR_INVALID; + } + + if (! (share->specifier & type)) { + return SHARE_ERROR_NOT_REGISTERED; + } + + if (!CURL_SHARE_IS_LOCKED (share, type)) { + return SHARE_ERROR_OK; + } + + share->unlockfunc (handle, type, share->clientdata); + CURL_SHARE_SET_UNLOCKED (share, type); + + return SHARE_ERROR_OK; +} + +CURLcode curl_share_destroy (curl_share *share) +{ + if (CURL_SHARE_IS_DIRTY(share)) { + return CURLE_SHARE_IN_USE; + } + + free (share); + + return CURLE_OK; +} + +/* + * local variables: + * eval: (load-file "../curl-mode.el") + * end: + * vim600: fdm=marker + * vim: et sw=2 ts=2 sts=2 tw=78 + */ -- cgit v1.2.1 From ba4e69bebc8f7f32f3bc7faa1e13e7580754075b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2002 11:52:59 +0000 Subject: updated source code boilerplate/header --- lib/share.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 1050e50a1..14bbae0cb 100644 --- a/lib/share.c +++ b/lib/share.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -7,19 +7,19 @@ * * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * - * In order to be useful for every potential user, curl and libcurl are - * dual-licensed under the MPL and the MIT/X-derivate licenses. - * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the MPL or the MIT/X-derivate - * licenses. You may pick one of these licenses. + * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * $Id$ - *****************************************************************************/ + ***************************************************************************/ #include "setup.h" #include -- cgit v1.2.1 From 9a239edb5254fb684ec8095624d763ddeb49d063 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 8 Jan 2003 15:50:52 +0000 Subject: updated to use the modified share-types --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 14bbae0cb..f0203f1a9 100644 --- a/lib/share.c +++ b/lib/share.c @@ -44,7 +44,7 @@ #define CURL_SHARE_GET(__handle) (((struct SessionHandle *) (__handle))->share) -curl_share * +CURLSH * curl_share_init (void) { curl_share *share = (curl_share *) malloc (sizeof (curl_share)); -- cgit v1.2.1 From f152f23a680670e72e230d6247a2ed4552750480 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 9 Jan 2003 10:21:03 +0000 Subject: Updated more and now looks and and the API possibly works almost like the design document specifies. There is still no code inside that uses this. --- lib/share.c | 177 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 79 insertions(+), 98 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index f0203f1a9..4d12b66e5 100644 --- a/lib/share.c +++ b/lib/share.c @@ -24,141 +24,122 @@ #include "setup.h" #include #include -#include "share.h" #include "urldata.h" +#include "share.h" /* The last #include file should be: */ #ifdef MALLOCDEBUG #include "memdebug.h" #endif -#define CURL_SHARE_SET_LOCKED(__share, __type) ((__share)->locked += (__type)) -#define CURL_SHARE_SET_UNLOCKED(__share, __type) ((__share)->locked -= (__type)) - -#define CURL_SHARE_SET_USED(__share, __type) ((__share)->specifier += (__type)) -#define CURL_SHARE_SET_UNUSED(__share, __type) ((__share)->specifier -= (__type)) -#define CURL_SHARE_IS_USED(__share, __type) ((__share)->specifier & (__type)) -#define CURL_SHARE_IS_LOCKED(__share, __type) ((__share)->locked & (__type)) - -#define CURL_SHARE_IS_DIRTY(__share) ((__share)->dirty) - -#define CURL_SHARE_GET(__handle) (((struct SessionHandle *) (__handle))->share) - CURLSH * -curl_share_init (void) +curl_share_init(void) { - curl_share *share = (curl_share *) malloc (sizeof (curl_share)); - if (share) { - memset (share, 0, sizeof (curl_share)); - } + struct Curl_share *share = + (struct Curl_share *)malloc(sizeof(struct Curl_share)); + if (share) + memset (share, 0, sizeof(struct Curl_share)); return share; } -CURLcode -curl_share_setopt (curl_share *share, curl_lock_type option, int enable) +CURLSHcode +curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) { - if (CURL_SHARE_IS_DIRTY(share)) { - return CURLE_SHARE_IN_USE; + struct Curl_share *share = (struct Curl_share *)sh; + va_list param; + int type; + curl_lock_function lockfunc; + curl_unlock_function unlockfunc; + void *ptr; + + if (share->dirty) + /* don't allow setting options while one or more handles are already + using this share */ + return CURLSHE_IN_USE; + + va_start(param, option); + + switch(option) { + case CURLSHOPT_SHARE: + /* this is a type this share will share */ + type = va_arg(param, int); + share->specifier |= (1<specifier &= ~(1<lockfunc = lockfunc; + break; + + case CURLSHOPT_UNLOCKFUNC: + unlockfunc = va_arg(param, curl_unlock_function); + share->unlockfunc = unlockfunc; + break; + + case CURLSHOPT_USERDATA: + ptr = va_arg(param, void *); + share->clientdata = ptr; + break; + + default: + return CURLSHE_BAD_OPTION; } - if (enable) { - CURL_SHARE_SET_USED (share, option); - } - else { - CURL_SHARE_SET_UNUSED (share, option); - } - - return CURLE_OK; -} - -CURLcode -curl_share_set_lock_function (curl_share *share, curl_lock_function lock) -{ - if (CURL_SHARE_IS_DIRTY(share)) { - return CURLE_SHARE_IN_USE; - } - - share->lockfunc = lock; - return CURLE_OK; + return CURLSHE_OK; } -CURLcode -curl_share_set_unlock_function (curl_share *share, curl_unlock_function unlock) +CURLSHcode curl_share_cleanup(CURLSH *sh) { - if (CURL_SHARE_IS_DIRTY(share)) { - return CURLE_SHARE_IN_USE; - } + struct Curl_share *share = (struct Curl_share *)sh; + if (share->dirty) + return CURLSHE_IN_USE; - share->unlockfunc = unlock; - return CURLE_OK; + free (share); + + return CURLSHE_OK; } -CURLcode -curl_share_set_lock_data (curl_share *share, void *data) -{ - if (CURL_SHARE_IS_DIRTY(share)) { - return CURLE_SHARE_IN_USE; - } - - share->clientdata = data; - return CURLE_OK; -} -Curl_share_error -Curl_share_acquire_lock (CURL *handle, curl_lock_type type) +CURLSHcode +Curl_share_acquire_lock(struct SessionHandle *data, curl_lock_data type) { - curl_share *share = CURL_SHARE_GET (handle); - if (share == NULL) { - return SHARE_ERROR_INVALID; - } + struct Curl_share *share = data->share; - if (! (share->specifier & type)) { - return SHARE_ERROR_NOT_REGISTERED; - } + if (share == NULL) + return CURLSHE_INVALID; - if (CURL_SHARE_IS_LOCKED (share, type)) { - return SHARE_ERROR_OK; + if(share->specifier & (1<lockfunc (data, type, CURL_LOCK_ACCESS_SINGLE, share->clientdata); + share->locked |= (1<lockfunc (handle, type, share->clientdata); - CURL_SHARE_SET_LOCKED (share, type); - - return SHARE_ERROR_OK; + return CURLSHE_OK; } -Curl_share_error -Curl_share_release_lock (CURL *handle, curl_lock_type type) +CURLSHcode +Curl_share_release_lock(struct SessionHandle *data, curl_lock_data type) { - curl_share *share = CURL_SHARE_GET(handle); - if (share == NULL) { - return SHARE_ERROR_INVALID; - } + struct Curl_share *share = data->share; - if (! (share->specifier & type)) { - return SHARE_ERROR_NOT_REGISTERED; - } + if (share == NULL) + return CURLSHE_INVALID; - if (!CURL_SHARE_IS_LOCKED (share, type)) { - return SHARE_ERROR_OK; + if(share->specifier & (1<unlockfunc (data, type, share->clientdata); + share->locked &= ~(1<unlockfunc (handle, type, share->clientdata); - CURL_SHARE_SET_UNLOCKED (share, type); - - return SHARE_ERROR_OK; + return CURLSHE_OK; } -CURLcode curl_share_destroy (curl_share *share) -{ - if (CURL_SHARE_IS_DIRTY(share)) { - return CURLE_SHARE_IN_USE; - } - - free (share); - - return CURLE_OK; -} /* * local variables: -- cgit v1.2.1 From f26a338a54e04d0a6907f5d2479d8b0fa9daf297 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 21:08:12 +0000 Subject: copyright year update in the source header --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 4d12b66e5..6c5d9aa0b 100644 --- a/lib/share.c +++ b/lib/share.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From a7c72b7abf1213c471f3fd11e6b8e3a37d526f60 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Jan 2003 10:14:20 +0000 Subject: removed the local variables for emacs and vim, use the new sample.emacs way for emacs, and vim users should provide a similar non-polluting style --- lib/share.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 6c5d9aa0b..dcf7e90bb 100644 --- a/lib/share.c +++ b/lib/share.c @@ -139,12 +139,3 @@ Curl_share_release_lock(struct SessionHandle *data, curl_lock_data type) return CURLSHE_OK; } - - -/* - * local variables: - * eval: (load-file "../curl-mode.el") - * end: - * vim600: fdm=marker - * vim: et sw=2 ts=2 sts=2 tw=78 - */ -- cgit v1.2.1 From beb13a1d3e832ae97221ba1d9ad7f9bc262de798 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Barette-LaPierre Date: Tue, 4 Feb 2003 23:48:46 +0000 Subject: added the sharing of DNS cache --- lib/share.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index dcf7e90bb..8e5ec0ea0 100644 --- a/lib/share.c +++ b/lib/share.c @@ -65,12 +65,53 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) /* this is a type this share will share */ type = va_arg(param, int); share->specifier |= (1<hostcache) { + share->hostcache = Curl_hash_alloc(7, Curl_freednsinfo); + } + break; + + case CURL_LOCK_DATA_COOKIE: + break; + + case CURL_LOCK_DATA_SSL_SESSION: + break; + + case CURL_LOCK_DATA_CONNECT: + break; + + default: + return CURLSHE_BAD_OPTION; + } break; case CURLSHOPT_UNSHARE: /* this is a type this share will no longer share */ type = va_arg(param, int); share->specifier &= ~(1<hostcache) { + Curl_hash_destroy(share->hostcache); + share->hostcache = NULL; + } + break; + + case CURL_LOCK_DATA_COOKIE: + break; + + case CURL_LOCK_DATA_SSL_SESSION: + break; + + case CURL_LOCK_DATA_CONNECT: + break; + + default: + return CURLSHE_BAD_OPTION; + } break; case CURLSHOPT_LOCKFUNC: @@ -108,7 +149,7 @@ CURLSHcode curl_share_cleanup(CURLSH *sh) CURLSHcode -Curl_share_acquire_lock(struct SessionHandle *data, curl_lock_data type) +Curl_share_lock(struct SessionHandle *data, curl_lock_data type, curl_lock_access access) { struct Curl_share *share = data->share; @@ -116,8 +157,7 @@ Curl_share_acquire_lock(struct SessionHandle *data, curl_lock_data type) return CURLSHE_INVALID; if(share->specifier & (1<lockfunc (data, type, CURL_LOCK_ACCESS_SINGLE, share->clientdata); - share->locked |= (1<lockfunc (data, type, access, share->clientdata); } /* else if we don't share this, pretend successful lock */ @@ -125,7 +165,7 @@ Curl_share_acquire_lock(struct SessionHandle *data, curl_lock_data type) } CURLSHcode -Curl_share_release_lock(struct SessionHandle *data, curl_lock_data type) +Curl_share_unlock(struct SessionHandle *data, curl_lock_data type) { struct Curl_share *share = data->share; @@ -134,7 +174,6 @@ Curl_share_release_lock(struct SessionHandle *data, curl_lock_data type) if(share->specifier & (1<unlockfunc (data, type, share->clientdata); - share->locked &= ~(1< Date: Thu, 6 Feb 2003 19:28:17 +0000 Subject: include stdarg.h since we use va_* stuff --- lib/share.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 8e5ec0ea0..cd555a88f 100644 --- a/lib/share.c +++ b/lib/share.c @@ -22,6 +22,7 @@ ***************************************************************************/ #include "setup.h" +#include #include #include #include "urldata.h" -- cgit v1.2.1 From e727fb82f2cfb7fe01a2d03c7d39af60b23f842f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 13 Jun 2003 06:48:04 +0000 Subject: Marty Kuhrt's #include fixes for VMS --- lib/share.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index cd555a88f..df4d5ec14 100644 --- a/lib/share.c +++ b/lib/share.c @@ -24,6 +24,7 @@ #include "setup.h" #include #include +#include #include #include "urldata.h" #include "share.h" -- cgit v1.2.1 From ed908b7f89eb55fc5163d821feab6adc6b0dfa1b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 26 Jun 2003 11:28:26 +0000 Subject: use CURLDEBUG instead of MALLOCDEBUG --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index df4d5ec14..798a0a497 100644 --- a/lib/share.c +++ b/lib/share.c @@ -30,7 +30,7 @@ #include "share.h" /* The last #include file should be: */ -#ifdef MALLOCDEBUG +#ifdef CURLDEBUG #include "memdebug.h" #endif -- cgit v1.2.1 From 41ae97e710f728495a1d6adba6476c21b94c4881 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 4 Aug 2003 15:02:42 +0000 Subject: Dirk Manske's patch that introduces cookie support to the share interface. --- lib/share.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 798a0a497..9b5f79f9e 100644 --- a/lib/share.c +++ b/lib/share.c @@ -76,6 +76,9 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) break; case CURL_LOCK_DATA_COOKIE: + if (!share->cookies) { + share->cookies = Curl_cookie_init( NULL, NULL, TRUE ); + } break; case CURL_LOCK_DATA_SSL_SESSION: @@ -103,6 +106,10 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) break; case CURL_LOCK_DATA_COOKIE: + if (share->cookies) { + Curl_cookie_cleanup(share->cookies); + share->cookies = NULL; + } break; case CURL_LOCK_DATA_SSL_SESSION: @@ -144,6 +151,12 @@ CURLSHcode curl_share_cleanup(CURLSH *sh) if (share->dirty) return CURLSHE_IN_USE; + if(share->hostcache) + Curl_hash_destroy(share->hostcache); + + if(share->cookies) + Curl_cookie_cleanup(share->cookies); + free (share); return CURLSHE_OK; @@ -151,7 +164,8 @@ CURLSHcode curl_share_cleanup(CURLSH *sh) CURLSHcode -Curl_share_lock(struct SessionHandle *data, curl_lock_data type, curl_lock_access access) +Curl_share_lock(struct SessionHandle *data, curl_lock_data type, + curl_lock_access access) { struct Curl_share *share = data->share; -- cgit v1.2.1 From 8dd069604ce80652935215f0e0986cf487e4ac6d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 11 Aug 2003 06:30:02 +0000 Subject: Dirk Manske's bugfix for the share stuff --- lib/share.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 9b5f79f9e..37acef195 100644 --- a/lib/share.c +++ b/lib/share.c @@ -39,8 +39,10 @@ curl_share_init(void) { struct Curl_share *share = (struct Curl_share *)malloc(sizeof(struct Curl_share)); - if (share) + if (share) { memset (share, 0, sizeof(struct Curl_share)); + share->specifier |= (1<dirty) + + if (share == NULL) + return CURLSHE_INVALID; + + share->lockfunc(NULL, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE, + share->clientdata); + + if (share->dirty) { + share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); return CURLSHE_IN_USE; + } if(share->hostcache) Curl_hash_destroy(share->hostcache); @@ -157,6 +169,7 @@ CURLSHcode curl_share_cleanup(CURLSH *sh) if(share->cookies) Curl_cookie_cleanup(share->cookies); + share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); free (share); return CURLSHE_OK; @@ -173,7 +186,7 @@ Curl_share_lock(struct SessionHandle *data, curl_lock_data type, return CURLSHE_INVALID; if(share->specifier & (1<lockfunc (data, type, access, share->clientdata); + share->lockfunc(data, type, access, share->clientdata); } /* else if we don't share this, pretend successful lock */ -- cgit v1.2.1 From 96e217b49628a7dd19ad4be66b1842dcf0940309 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 11 Aug 2003 09:56:06 +0000 Subject: the new cookie functions that require 'data' passed in --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 37acef195..d883ff0de 100644 --- a/lib/share.c +++ b/lib/share.c @@ -79,7 +79,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) case CURL_LOCK_DATA_COOKIE: if (!share->cookies) { - share->cookies = Curl_cookie_init( NULL, NULL, TRUE ); + share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); } break; -- cgit v1.2.1 From 053f6c85efd0bf698f73343989474d672d0563a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Jan 2004 09:19:33 +0000 Subject: updated year in the copyright string --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index d883ff0de..f077e834e 100644 --- a/lib/share.c +++ b/lib/share.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 4d17d6876e4b2f08380812c4ec113073b0a14639 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 29 Jan 2004 13:56:45 +0000 Subject: Dan Fandrich's cleanup patch to make pedantic compiler options cause less warnings. Minor edits by me. --- lib/share.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index f077e834e..d6cb7cfdc 100644 --- a/lib/share.c +++ b/lib/share.c @@ -178,7 +178,7 @@ curl_share_cleanup(CURLSH *sh) CURLSHcode Curl_share_lock(struct SessionHandle *data, curl_lock_data type, - curl_lock_access access) + curl_lock_access accesstype) { struct Curl_share *share = data->share; @@ -186,7 +186,7 @@ Curl_share_lock(struct SessionHandle *data, curl_lock_data type, return CURLSHE_INVALID; if(share->specifier & (1<lockfunc(data, type, access, share->clientdata); + share->lockfunc(data, type, accesstype, share->clientdata); } /* else if we don't share this, pretend successful lock */ -- cgit v1.2.1 From be2cdf14f3e5043c2909898975913a1316d00850 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 26 Feb 2004 11:39:38 +0000 Subject: Don't call the lock/unlock functions if they are NULL. They can still be NULL without violating protocol. --- lib/share.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index d6cb7cfdc..ff1aef2e5 100644 --- a/lib/share.c +++ b/lib/share.c @@ -186,7 +186,8 @@ Curl_share_lock(struct SessionHandle *data, curl_lock_data type, return CURLSHE_INVALID; if(share->specifier & (1<lockfunc(data, type, accesstype, share->clientdata); + if(share->lockfunc) /* only call this if set! */ + share->lockfunc(data, type, accesstype, share->clientdata); } /* else if we don't share this, pretend successful lock */ @@ -202,7 +203,8 @@ Curl_share_unlock(struct SessionHandle *data, curl_lock_data type) return CURLSHE_INVALID; if(share->specifier & (1<unlockfunc (data, type, share->clientdata); + if(share->unlockfunc) /* only call this if set! */ + share->unlockfunc (data, type, share->clientdata); } return CURLSHE_OK; -- cgit v1.2.1 From 7ea837a18c7d22c790daf2733eaffcc5450b1bd9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 30 Mar 2004 13:02:31 +0000 Subject: adjusted to the new dns cache function to hide more hostip internals --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index ff1aef2e5..e554339de 100644 --- a/lib/share.c +++ b/lib/share.c @@ -73,7 +73,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) { case CURL_LOCK_DATA_DNS: if (!share->hostcache) { - share->hostcache = Curl_hash_alloc(7, Curl_freednsinfo); + share->hostcache = Curl_mk_dnscache(); } break; -- cgit v1.2.1 From bbafb2eb27954c34967f91c705e74cc0c186970d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 May 2004 11:30:23 +0000 Subject: curl_global_init_mem() allows the memory functions to be replaced. memory.h is included everywhere for this. --- lib/share.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index e554339de..ced7e188d 100644 --- a/lib/share.c +++ b/lib/share.c @@ -28,11 +28,10 @@ #include #include "urldata.h" #include "share.h" +#include "memory.h" /* The last #include file should be: */ -#ifdef CURLDEBUG #include "memdebug.h" -#endif CURLSH * curl_share_init(void) -- cgit v1.2.1 From b6ee33c6e11decca2842a356c6d68f2bd28d00a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 13 May 2004 15:18:29 +0000 Subject: check that memory allocation functions truly return good data or bail out --- lib/share.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index ced7e188d..d1292c4ae 100644 --- a/lib/share.c +++ b/lib/share.c @@ -68,28 +68,28 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) /* this is a type this share will share */ type = va_arg(param, int); share->specifier |= (1<hostcache) { - share->hostcache = Curl_mk_dnscache(); - } - break; - - case CURL_LOCK_DATA_COOKIE: - if (!share->cookies) { - share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); - } - break; - - case CURL_LOCK_DATA_SSL_SESSION: - break; - - case CURL_LOCK_DATA_CONNECT: - break; - - default: - return CURLSHE_BAD_OPTION; + switch( type ) { + case CURL_LOCK_DATA_DNS: + if (!share->hostcache) { + share->hostcache = Curl_mk_dnscache(); + if(!share->hostcache) + return CURLSHE_NOMEM; + } + break; + + case CURL_LOCK_DATA_COOKIE: + if (!share->cookies) { + share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); + if(!share->cookies) + return CURLSHE_NOMEM; + } + break; + + case CURL_LOCK_DATA_SSL_SESSION: /* not supported (yet) */ + case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ + + default: + return CURLSHE_BAD_OPTION; } break; -- cgit v1.2.1 From 90037b85d1a6c46979729d0735eef094516dc31f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Jun 2004 08:23:55 +0000 Subject: Alexander Krasnostavsky's fix to make libcurl build fine with configure --disable-http, which thus builds a libcurl without HTTP support. --- lib/share.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index d1292c4ae..ad68496f6 100644 --- a/lib/share.c +++ b/lib/share.c @@ -76,7 +76,8 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) return CURLSHE_NOMEM; } break; - + +#ifndef CURL_DISABLE_HTTP case CURL_LOCK_DATA_COOKIE: if (!share->cookies) { share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); @@ -84,6 +85,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) return CURLSHE_NOMEM; } break; +#endif /* CURL_DISABLE_HTTP */ case CURL_LOCK_DATA_SSL_SESSION: /* not supported (yet) */ case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ @@ -106,12 +108,14 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) } break; +#ifndef CURL_DISABLE_HTTP case CURL_LOCK_DATA_COOKIE: if (share->cookies) { Curl_cookie_cleanup(share->cookies); share->cookies = NULL; } break; +#endif /* CURL_DISABLE_HTTP */ case CURL_LOCK_DATA_SSL_SESSION: break; @@ -165,8 +169,10 @@ curl_share_cleanup(CURLSH *sh) if(share->hostcache) Curl_hash_destroy(share->hostcache); +#ifndef CURL_DISABLE_HTTP if(share->cookies) Curl_cookie_cleanup(share->cookies); +#endif /* CURL_DISABLE_HTTP */ share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); free (share); -- cgit v1.2.1 From a9572bf88ae9d1efcdbc77b04ee88badfae3efbb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 2 Jul 2004 08:28:31 +0000 Subject: =?UTF-8?q?Andr=E9s=20Garc=EDa=20found=20out=20the=20share=20clean?= =?UTF-8?q?up=20code=20crashes=20when=20you=20cleanup=20and=20there=20are?= =?UTF-8?q?=20not=20lock/unlock=20functions=20set!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/share.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index ad68496f6..5c01845df 100644 --- a/lib/share.c +++ b/lib/share.c @@ -1,8 +1,8 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -10,7 +10,7 @@ * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. - * + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. @@ -135,7 +135,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) case CURLSHOPT_UNLOCKFUNC: unlockfunc = va_arg(param, curl_unlock_function); - share->unlockfunc = unlockfunc; + share->unlockfunc = unlockfunc; break; case CURLSHOPT_USERDATA: @@ -154,15 +154,17 @@ CURLSHcode curl_share_cleanup(CURLSH *sh) { struct Curl_share *share = (struct Curl_share *)sh; - + if (share == NULL) return CURLSHE_INVALID; - - share->lockfunc(NULL, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE, - share->clientdata); - + + if(share->lockfunc) + share->lockfunc(NULL, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE, + share->clientdata); + if (share->dirty) { - share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); + if(share->unlockfunc) + share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); return CURLSHE_IN_USE; } @@ -174,9 +176,10 @@ curl_share_cleanup(CURLSH *sh) Curl_cookie_cleanup(share->cookies); #endif /* CURL_DISABLE_HTTP */ - share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); - free (share); - + if(share->unlockfunc) + share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); + free(share); + return CURLSHE_OK; } -- cgit v1.2.1 From ac269a8f68323db6b579f11f864035bc2691081d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 5 Dec 2004 23:59:32 +0000 Subject: Dan Fandrich added the --disable-cookies option to configure to build libcurl without cookie support. This is mainly useful if you want to build a minimalistic libcurl with no cookies support at all. Like for embedded systems or similar. --- lib/share.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 5c01845df..de13b6021 100644 --- a/lib/share.c +++ b/lib/share.c @@ -77,7 +77,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) } break; -#ifndef CURL_DISABLE_HTTP +#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: if (!share->cookies) { share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); @@ -108,7 +108,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) } break; -#ifndef CURL_DISABLE_HTTP +#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: if (share->cookies) { Curl_cookie_cleanup(share->cookies); @@ -171,7 +171,7 @@ curl_share_cleanup(CURLSH *sh) if(share->hostcache) Curl_hash_destroy(share->hostcache); -#ifndef CURL_DISABLE_HTTP +#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(share->cookies) Curl_cookie_cleanup(share->cookies); #endif /* CURL_DISABLE_HTTP */ -- cgit v1.2.1 From cbd1a77ec24e397d05f20c6de106625676343c9d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2007 09:21:35 +0000 Subject: if () => if() while () => while() and some other minor re-indentings --- lib/share.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index de13b6021..eb2ee78ce 100644 --- a/lib/share.c +++ b/lib/share.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -38,7 +38,7 @@ curl_share_init(void) { struct Curl_share *share = (struct Curl_share *)malloc(sizeof(struct Curl_share)); - if (share) { + if(share) { memset (share, 0, sizeof(struct Curl_share)); share->specifier |= (1<dirty) + if(share->dirty) /* don't allow setting options while one or more handles are already using this share */ return CURLSHE_IN_USE; @@ -70,7 +70,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) share->specifier |= (1<hostcache) { + if(!share->hostcache) { share->hostcache = Curl_mk_dnscache(); if(!share->hostcache) return CURLSHE_NOMEM; @@ -79,7 +79,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: - if (!share->cookies) { + if(!share->cookies) { share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); if(!share->cookies) return CURLSHE_NOMEM; @@ -102,7 +102,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) switch( type ) { case CURL_LOCK_DATA_DNS: - if (share->hostcache) { + if(share->hostcache) { Curl_hash_destroy(share->hostcache); share->hostcache = NULL; } @@ -110,7 +110,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: - if (share->cookies) { + if(share->cookies) { Curl_cookie_cleanup(share->cookies); share->cookies = NULL; } @@ -155,14 +155,14 @@ curl_share_cleanup(CURLSH *sh) { struct Curl_share *share = (struct Curl_share *)sh; - if (share == NULL) + if(share == NULL) return CURLSHE_INVALID; if(share->lockfunc) share->lockfunc(NULL, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE, share->clientdata); - if (share->dirty) { + if(share->dirty) { if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); return CURLSHE_IN_USE; @@ -190,7 +190,7 @@ Curl_share_lock(struct SessionHandle *data, curl_lock_data type, { struct Curl_share *share = data->share; - if (share == NULL) + if(share == NULL) return CURLSHE_INVALID; if(share->specifier & (1<share; - if (share == NULL) + if(share == NULL) return CURLSHE_INVALID; if(share->specifier & (1< Date: Tue, 18 Mar 2008 08:14:37 +0000 Subject: - Added curl_easy_getinfo typechecker. - Added macros for curl_share_setopt and curl_multi_setopt to check at least the correct number of arguments. --- lib/share.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index eb2ee78ce..3a5f072bd 100644 --- a/lib/share.c +++ b/lib/share.c @@ -46,6 +46,7 @@ curl_share_init(void) return share; } +#undef curl_share_setopt CURLSHcode curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) { -- cgit v1.2.1 From 59e378f48fed849e8e41f0bc6a10bf7a1732ae8a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 05:29:05 +0000 Subject: remove unnecessary typecasting of malloc() --- lib/share.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 3a5f072bd..6430611b3 100644 --- a/lib/share.c +++ b/lib/share.c @@ -36,8 +36,7 @@ CURLSH * curl_share_init(void) { - struct Curl_share *share = - (struct Curl_share *)malloc(sizeof(struct Curl_share)); + struct Curl_share *share = malloc(sizeof(struct Curl_share)); if(share) { memset (share, 0, sizeof(struct Curl_share)); share->specifier |= (1< Date: Sun, 19 Oct 2008 20:17:16 +0000 Subject: attempt to fix or allow further detection of an elusive icc SIGSEGV --- lib/share.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 6430611b3..838a15916 100644 --- a/lib/share.c +++ b/lib/share.c @@ -168,8 +168,10 @@ curl_share_cleanup(CURLSH *sh) return CURLSHE_IN_USE; } - if(share->hostcache) + if(share->hostcache) { Curl_hash_destroy(share->hostcache); + share->hostcache = NULL; + } #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(share->cookies) -- cgit v1.2.1 From 2a868173497c0b7ae251537903ee9941dddebeba Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 20 Dec 2008 22:51:57 +0000 Subject: malloc+memset => calloc --- lib/share.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 838a15916..382e4b3d0 100644 --- a/lib/share.c +++ b/lib/share.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -36,11 +36,9 @@ CURLSH * curl_share_init(void) { - struct Curl_share *share = malloc(sizeof(struct Curl_share)); - if(share) { - memset (share, 0, sizeof(struct Curl_share)); + struct Curl_share *share = calloc(sizeof(struct Curl_share), 1); + if(share) share->specifier |= (1< Date: Tue, 21 Apr 2009 11:46:16 +0000 Subject: libcurl's memory.h renamed to curl_memory.h --- lib/share.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 382e4b3d0..9eb8b99b9 100644 --- a/lib/share.c +++ b/lib/share.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -28,7 +28,7 @@ #include #include "urldata.h" #include "share.h" -#include "memory.h" +#include "curl_memory.h" /* The last #include file should be: */ #include "memdebug.h" -- cgit v1.2.1 From 59939313f8452a9d817c178425c2ba3b91798ea9 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 18 Nov 2009 10:33:54 +0000 Subject: Make usage of calloc()'s arguments consistent with rest of code base --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 9eb8b99b9..5e5866c17 100644 --- a/lib/share.c +++ b/lib/share.c @@ -36,7 +36,7 @@ CURLSH * curl_share_init(void) { - struct Curl_share *share = calloc(sizeof(struct Curl_share), 1); + struct Curl_share *share = calloc(1, sizeof(struct Curl_share)); if(share) share->specifier |= (1< Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/share.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 5e5866c17..e6b8e7a1f 100644 --- a/lib/share.c +++ b/lib/share.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 9d1e914a56e8a4030d8917875eaedaddf5cff97c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 4 Apr 2011 15:46:42 +0200 Subject: disable cookies: remove ifdefs, move code 1 - make sure to #define macros for cookie functions in the cookie header when cookies are disabled to avoid having to use #ifdefs in code using those functions. 2 - move cookie-specific code to cookie.c and use the functio conditionally as mentioned in (1). net result: 6 #if lines removed, and 9 lines of code less --- lib/share.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index e6b8e7a1f..146228551 100644 --- a/lib/share.c +++ b/lib/share.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -170,10 +170,8 @@ curl_share_cleanup(CURLSH *sh) share->hostcache = NULL; } -#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(share->cookies) Curl_cookie_cleanup(share->cookies); -#endif /* CURL_DISABLE_HTTP */ if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); -- cgit v1.2.1 From b903186fa0189ff241d756d25d07fdfe9885ae49 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 20 Apr 2011 15:17:42 +0200 Subject: source cleanup: unify look, style and indent levels By the use of a the new lib/checksrc.pl script that checks that our basic source style rules are followed. --- lib/share.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 146228551..33dcecf4c 100644 --- a/lib/share.c +++ b/lib/share.c @@ -96,32 +96,31 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) /* this is a type this share will no longer share */ type = va_arg(param, int); share->specifier &= ~(1<hostcache) { - Curl_hash_destroy(share->hostcache); - share->hostcache = NULL; - } - break; + switch( type ) { + case CURL_LOCK_DATA_DNS: + if(share->hostcache) { + Curl_hash_destroy(share->hostcache); + share->hostcache = NULL; + } + break; #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) - case CURL_LOCK_DATA_COOKIE: - if(share->cookies) { - Curl_cookie_cleanup(share->cookies); - share->cookies = NULL; - } - break; + case CURL_LOCK_DATA_COOKIE: + if(share->cookies) { + Curl_cookie_cleanup(share->cookies); + share->cookies = NULL; + } + break; #endif /* CURL_DISABLE_HTTP */ - case CURL_LOCK_DATA_SSL_SESSION: - break; + case CURL_LOCK_DATA_SSL_SESSION: + break; - case CURL_LOCK_DATA_CONNECT: - break; + case CURL_LOCK_DATA_CONNECT: + break; - default: - return CURLSHE_BAD_OPTION; + default: + return CURLSHE_BAD_OPTION; } break; -- cgit v1.2.1 From f1586cb4775681810afd8e6626e7842d459f3b85 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Jul 2011 17:23:27 +0200 Subject: stdio.h, stdlib.h, string.h, stdarg.h and ctype.h inclusion done in setup_once.h --- lib/share.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 33dcecf4c..a3db4ded9 100644 --- a/lib/share.c +++ b/lib/share.c @@ -21,9 +21,7 @@ ***************************************************************************/ #include "setup.h" -#include -#include -#include + #include #include "urldata.h" #include "share.h" -- cgit v1.2.1 From 5793bc370c794a10e6ed014cb535a47672842ae6 Mon Sep 17 00:00:00 2001 From: Alejandro Alvarez Date: Tue, 20 Sep 2011 17:43:54 +0200 Subject: SSL session sharing support added With locking, plus test, plus documentation --- lib/share.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index a3db4ded9..a3eae1639 100644 --- a/lib/share.c +++ b/lib/share.c @@ -25,6 +25,7 @@ #include #include "urldata.h" #include "share.h" +#include "sslgen.h" #include "curl_memory.h" /* The last #include file should be: */ @@ -82,7 +83,16 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) break; #endif /* CURL_DISABLE_HTTP */ - case CURL_LOCK_DATA_SSL_SESSION: /* not supported (yet) */ + case CURL_LOCK_DATA_SSL_SESSION: + if(!share->sslsession) { + share->nsslsession = 8; + share->sslsession = calloc(share->nsslsession, + sizeof(struct curl_ssl_session)); + if(!share->sslsession) + return CURLSHE_NOMEM; + } + break; + case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ default: @@ -112,6 +122,11 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) #endif /* CURL_DISABLE_HTTP */ case CURL_LOCK_DATA_SSL_SESSION: + if(share->sslsession) { + free(share->sslsession); + share->sslsession = NULL; + share->nsslsession = 0; + } break; case CURL_LOCK_DATA_CONNECT: @@ -148,6 +163,7 @@ CURLSHcode curl_share_cleanup(CURLSH *sh) { struct Curl_share *share = (struct Curl_share *)sh; + unsigned int i; if(share == NULL) return CURLSHE_INVALID; @@ -170,6 +186,12 @@ curl_share_cleanup(CURLSH *sh) if(share->cookies) Curl_cookie_cleanup(share->cookies); + if(share->sslsession) { + for(i = 0; i < share->nsslsession; ++i) + Curl_ssl_kill_session(&(share->sslsession[i])); + free(share->sslsession); + } + if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); free(share); -- cgit v1.2.1 From 15e3e451702396e870c00d186ff7710792a1f28e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 3 Oct 2011 22:32:36 +0200 Subject: 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. --- lib/share.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index a3eae1639..6f8ba49cd 100644 --- a/lib/share.c +++ b/lib/share.c @@ -73,17 +73,20 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) } break; -#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: +#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(!share->cookies) { share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); if(!share->cookies) return CURLSHE_NOMEM; } break; -#endif /* CURL_DISABLE_HTTP */ +#else /* CURL_DISABLE_HTTP */ + return CURLSHE_NOT_BUILT_IN; +#endif case CURL_LOCK_DATA_SSL_SESSION: +#ifdef USE_SSL if(!share->sslsession) { share->nsslsession = 8; share->sslsession = calloc(share->nsslsession, @@ -92,6 +95,9 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) return CURLSHE_NOMEM; } break; +#else + return CURLSHE_NOT_BUILT_IN; +#endif case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ @@ -112,22 +118,28 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) } break; -#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: +#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(share->cookies) { Curl_cookie_cleanup(share->cookies); share->cookies = NULL; } break; -#endif /* CURL_DISABLE_HTTP */ +#else /* CURL_DISABLE_HTTP */ + return CURLSHE_NOT_BUILT_IN; +#endif case CURL_LOCK_DATA_SSL_SESSION: +#ifdef USE_SSL if(share->sslsession) { free(share->sslsession); share->sslsession = NULL; share->nsslsession = 0; } break; +#else + return CURLSHE_NOT_BUILT_IN; +#endif case CURL_LOCK_DATA_CONNECT: break; @@ -186,11 +198,13 @@ curl_share_cleanup(CURLSH *sh) if(share->cookies) Curl_cookie_cleanup(share->cookies); +#ifdef USE_SSL if(share->sslsession) { for(i = 0; i < share->nsslsession; ++i) Curl_ssl_kill_session(&(share->sslsession[i])); free(share->sslsession); } +#endif if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); -- cgit v1.2.1 From ca2c32636191ba33dbad91e88d8ceecc74bacbd1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 4 Oct 2011 16:34:45 +0200 Subject: curl_share_cleanup: avoid compiler warning Move the variable declaration to within the #ifdef --- lib/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 6f8ba49cd..59f33eb10 100644 --- a/lib/share.c +++ b/lib/share.c @@ -175,7 +175,6 @@ CURLSHcode curl_share_cleanup(CURLSH *sh) { struct Curl_share *share = (struct Curl_share *)sh; - unsigned int i; if(share == NULL) return CURLSHE_INVALID; @@ -200,6 +199,7 @@ curl_share_cleanup(CURLSH *sh) #ifdef USE_SSL if(share->sslsession) { + unsigned int i; for(i = 0; i < share->nsslsession; ++i) Curl_ssl_kill_session(&(share->sslsession[i])); free(share->sslsession); -- cgit v1.2.1 From 90fcad63cbb9943c7c7a564944a3bce7d10e581a Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 20 Oct 2011 17:54:18 -0700 Subject: Fixed compilation when HTTP or cookies are disabled --- lib/share.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 59f33eb10..71c2ef308 100644 --- a/lib/share.c +++ b/lib/share.c @@ -194,8 +194,10 @@ curl_share_cleanup(CURLSH *sh) share->hostcache = NULL; } +#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(share->cookies) Curl_cookie_cleanup(share->cookies); +#endif #ifdef USE_SSL if(share->sslsession) { -- cgit v1.2.1 From 35f61c404d434e00da0f502a073cd3a0201fa504 Mon Sep 17 00:00:00 2001 From: Alejandro Alvarez Ayllon Date: Thu, 17 Nov 2011 23:34:38 +0100 Subject: SSL session share: move the age counter to the share object Previously the age counter would be counted individually in each easy handle that shared SSL sessions! --- lib/share.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 71c2ef308..a89e15e3d 100644 --- a/lib/share.c +++ b/lib/share.c @@ -91,6 +91,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) share->nsslsession = 8; share->sslsession = calloc(share->nsslsession, sizeof(struct curl_ssl_session)); + share->sessionage = 0; if(!share->sslsession) return CURLSHE_NOMEM; } -- cgit v1.2.1 From d56b4c3f89ad3ee28dc62a22cffe2c85ced19830 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 18 Jan 2012 23:39:30 +0100 Subject: ssl session caching: fix compiler warnings --- lib/share.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index a89e15e3d..839b33e60 100644 --- a/lib/share.c +++ b/lib/share.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -88,8 +88,8 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) case CURL_LOCK_DATA_SSL_SESSION: #ifdef USE_SSL if(!share->sslsession) { - share->nsslsession = 8; - share->sslsession = calloc(share->nsslsession, + share->max_ssl_sessions = 8; + share->sslsession = calloc(share->max_ssl_sessions, sizeof(struct curl_ssl_session)); share->sessionage = 0; if(!share->sslsession) @@ -132,11 +132,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) case CURL_LOCK_DATA_SSL_SESSION: #ifdef USE_SSL - if(share->sslsession) { - free(share->sslsession); - share->sslsession = NULL; - share->nsslsession = 0; - } + Curl_safefree(share->sslsession); break; #else return CURLSHE_NOT_BUILT_IN; @@ -202,8 +198,8 @@ curl_share_cleanup(CURLSH *sh) #ifdef USE_SSL if(share->sslsession) { - unsigned int i; - for(i = 0; i < share->nsslsession; ++i) + size_t i; + for(i = 0; i < share->max_ssl_sessions; i++) Curl_ssl_kill_session(&(share->sslsession[i])); free(share->sslsession); } -- cgit v1.2.1 From 3da2c0f6d231dabcf0f4402eadc14d954b88a858 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 15 Jun 2012 22:37:19 +0200 Subject: curl_share_setopt: use va_end() As spotted by Coverity, va_end() was not used previously. To make it used I took away a bunch of return statements and made them into assignments instead. --- lib/share.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'lib/share.c') diff --git a/lib/share.c b/lib/share.c index 839b33e60..477c35b0b 100644 --- a/lib/share.c +++ b/lib/share.c @@ -51,6 +51,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) curl_lock_function lockfunc; curl_unlock_function unlockfunc; void *ptr; + CURLSHcode res = CURLSHE_OK; if(share->dirty) /* don't allow setting options while one or more handles are already @@ -69,7 +70,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) if(!share->hostcache) { share->hostcache = Curl_mk_dnscache(); if(!share->hostcache) - return CURLSHE_NOMEM; + res = CURLSHE_NOMEM; } break; @@ -78,12 +79,12 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) if(!share->cookies) { share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); if(!share->cookies) - return CURLSHE_NOMEM; + res = CURLSHE_NOMEM; } - break; #else /* CURL_DISABLE_HTTP */ - return CURLSHE_NOT_BUILT_IN; + res = CURLSHE_NOT_BUILT_IN; #endif + break; case CURL_LOCK_DATA_SSL_SESSION: #ifdef USE_SSL @@ -93,17 +94,18 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) sizeof(struct curl_ssl_session)); share->sessionage = 0; if(!share->sslsession) - return CURLSHE_NOMEM; + res = CURLSHE_NOMEM; } - break; #else - return CURLSHE_NOT_BUILT_IN; + res = CURLSHE_NOT_BUILT_IN; #endif + break; case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ + break; default: - return CURLSHE_BAD_OPTION; + res = CURLSHE_BAD_OPTION; } break; @@ -125,24 +127,25 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) Curl_cookie_cleanup(share->cookies); share->cookies = NULL; } - break; #else /* CURL_DISABLE_HTTP */ - return CURLSHE_NOT_BUILT_IN; + res = CURLSHE_NOT_BUILT_IN; #endif + break; case CURL_LOCK_DATA_SSL_SESSION: #ifdef USE_SSL Curl_safefree(share->sslsession); - break; #else - return CURLSHE_NOT_BUILT_IN; + res = CURLSHE_NOT_BUILT_IN; #endif + break; case CURL_LOCK_DATA_CONNECT: break; default: - return CURLSHE_BAD_OPTION; + res = CURLSHE_BAD_OPTION; + break; } break; @@ -162,10 +165,13 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) break; default: - return CURLSHE_BAD_OPTION; + res = CURLSHE_BAD_OPTION; + break; } - return CURLSHE_OK; + va_end(param); + + return res; } CURLSHcode -- cgit v1.2.1