diff options
author | Daniel Stenberg <daniel@haxx.se> | 2011-04-04 15:46:42 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-04-04 19:27:26 +0200 |
commit | 9d1e914a56e8a4030d8917875eaedaddf5cff97c (patch) | |
tree | 103f73104c796dd3000b7063623d20a256601d6a /lib/cookie.c | |
parent | d3408d05935e61a303b5761cc5aa029eb54408f8 (diff) | |
download | curl-9d1e914a56e8a4030d8917875eaedaddf5cff97c.tar.gz |
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
Diffstat (limited to 'lib/cookie.c')
-rw-r--r-- | lib/cookie.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/cookie.c b/lib/cookie.c index d40cbb8f8..4140d94b8 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, 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 * you should have received as part of this distribution. The terms @@ -1134,4 +1134,35 @@ struct curl_slist *Curl_cookie_list(struct SessionHandle *data) return list; } +void Curl_flush_cookies(struct SessionHandle *data, int cleanup) +{ + if(data->set.str[STRING_COOKIEJAR]) { + if(data->change.cookielist) { + /* If there is a list of cookie files to read, do it first so that + we have all the told files read before we write the new jar. + Curl_cookie_loadfiles() LOCKS and UNLOCKS the share itself! */ + Curl_cookie_loadfiles(data); + } + + Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); + + /* if we have a destination file for all the cookies to get dumped to */ + if(Curl_cookie_output(data->cookies, data->set.str[STRING_COOKIEJAR])) + infof(data, "WARNING: failed to save cookies in %s\n", + data->set.str[STRING_COOKIEJAR]); + } + else { + if(cleanup && data->change.cookielist) + /* since nothing is written, we can just free the list of cookie file + names */ + curl_slist_free_all(data->change.cookielist); /* clean up list */ + Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); + } + + if(cleanup && (!data->share || (data->cookies != data->share->cookies))) { + Curl_cookie_cleanup(data->cookies); + } + Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); +} + #endif /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */ |