mirror of
https://github.com/moparisthebest/curl
synced 2025-03-11 07:39:50 -04:00
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
This commit is contained in:
parent
d3408d0593
commit
9d1e914a56
33
lib/cookie.c
33
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
|
* 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
|
||||||
@ -1134,4 +1134,35 @@ struct curl_slist *Curl_cookie_list(struct SessionHandle *data)
|
|||||||
return list;
|
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 */
|
#endif /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */
|
||||||
|
12
lib/cookie.h
12
lib/cookie.h
@ -7,7 +7,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1998 - 2008, 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
|
||||||
@ -87,20 +87,24 @@ struct Cookie *Curl_cookie_add(struct SessionHandle *data,
|
|||||||
struct CookieInfo *, bool header, char *lineptr,
|
struct CookieInfo *, bool header, char *lineptr,
|
||||||
const char *domain, const char *path);
|
const char *domain, const char *path);
|
||||||
|
|
||||||
struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
|
|
||||||
const char *, struct CookieInfo *, bool);
|
|
||||||
struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *,
|
struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *,
|
||||||
const char *, bool);
|
const char *, bool);
|
||||||
void Curl_cookie_freelist(struct Cookie *cookies, bool cookiestoo);
|
void Curl_cookie_freelist(struct Cookie *cookies, bool cookiestoo);
|
||||||
void Curl_cookie_clearall(struct CookieInfo *cookies);
|
void Curl_cookie_clearall(struct CookieInfo *cookies);
|
||||||
void Curl_cookie_clearsess(struct CookieInfo *cookies);
|
void Curl_cookie_clearsess(struct CookieInfo *cookies);
|
||||||
void Curl_cookie_cleanup(struct CookieInfo *);
|
|
||||||
int Curl_cookie_output(struct CookieInfo *, const char *);
|
int Curl_cookie_output(struct CookieInfo *, const char *);
|
||||||
|
|
||||||
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
|
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
|
||||||
#define Curl_cookie_list(x) NULL
|
#define Curl_cookie_list(x) NULL
|
||||||
#define Curl_cookie_loadfiles(x) do { } while (0)
|
#define Curl_cookie_loadfiles(x) do { } while (0)
|
||||||
|
#define Curl_cookie_init(x,y,z,w) NULL
|
||||||
|
#define Curl_cookie_cleanup(x)
|
||||||
|
#define Curl_flush_cookies(x,y)
|
||||||
#else
|
#else
|
||||||
|
void Curl_flush_cookies(struct SessionHandle *data, int cleanup);
|
||||||
|
void Curl_cookie_cleanup(struct CookieInfo *);
|
||||||
|
struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
|
||||||
|
const char *, struct CookieInfo *, bool);
|
||||||
struct curl_slist *Curl_cookie_list(struct SessionHandle *data);
|
struct curl_slist *Curl_cookie_list(struct SessionHandle *data);
|
||||||
void Curl_cookie_loadfiles(struct SessionHandle *data);
|
void Curl_cookie_loadfiles(struct SessionHandle *data);
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
* 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
|
||||||
@ -654,7 +654,6 @@ CURL *curl_easy_duphandle(CURL *incurl)
|
|||||||
outcurl->progress.flags = data->progress.flags;
|
outcurl->progress.flags = data->progress.flags;
|
||||||
outcurl->progress.callback = data->progress.callback;
|
outcurl->progress.callback = data->progress.callback;
|
||||||
|
|
||||||
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
|
|
||||||
if(data->cookies) {
|
if(data->cookies) {
|
||||||
/* If cookies are enabled in the parent handle, we enable them
|
/* If cookies are enabled in the parent handle, we enable them
|
||||||
in the clone as well! */
|
in the clone as well! */
|
||||||
@ -665,18 +664,14 @@ CURL *curl_easy_duphandle(CURL *incurl)
|
|||||||
if(!outcurl->cookies)
|
if(!outcurl->cookies)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
#endif /* CURL_DISABLE_HTTP */
|
|
||||||
|
|
||||||
/* duplicate all values in 'change' */
|
/* duplicate all values in 'change' */
|
||||||
|
|
||||||
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
|
|
||||||
if(data->change.cookielist) {
|
if(data->change.cookielist) {
|
||||||
outcurl->change.cookielist =
|
outcurl->change.cookielist =
|
||||||
Curl_slist_duplicate(data->change.cookielist);
|
Curl_slist_duplicate(data->change.cookielist);
|
||||||
if(!outcurl->change.cookielist)
|
if(!outcurl->change.cookielist)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
#endif /* CURL_DISABLE_HTTP */
|
|
||||||
|
|
||||||
if(data->change.url) {
|
if(data->change.url) {
|
||||||
outcurl->change.url = strdup(data->change.url);
|
outcurl->change.url = strdup(data->change.url);
|
||||||
@ -724,10 +719,8 @@ CURL *curl_easy_duphandle(CURL *incurl)
|
|||||||
Curl_rm_connc(outcurl->state.connc);
|
Curl_rm_connc(outcurl->state.connc);
|
||||||
if(outcurl->state.headerbuff)
|
if(outcurl->state.headerbuff)
|
||||||
free(outcurl->state.headerbuff);
|
free(outcurl->state.headerbuff);
|
||||||
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
|
|
||||||
if(outcurl->change.cookielist)
|
if(outcurl->change.cookielist)
|
||||||
curl_slist_free_all(outcurl->change.cookielist);
|
curl_slist_free_all(outcurl->change.cookielist);
|
||||||
#endif
|
|
||||||
if(outcurl->change.url)
|
if(outcurl->change.url)
|
||||||
free(outcurl->change.url);
|
free(outcurl->change.url);
|
||||||
if(outcurl->change.referer)
|
if(outcurl->change.referer)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1998 - 2009, 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
|
||||||
@ -170,10 +170,8 @@ curl_share_cleanup(CURLSH *sh)
|
|||||||
share->hostcache = NULL;
|
share->hostcache = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#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);
|
||||||
#endif /* CURL_DISABLE_HTTP */
|
|
||||||
|
|
||||||
if(share->unlockfunc)
|
if(share->unlockfunc)
|
||||||
share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata);
|
share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata);
|
||||||
|
39
lib/url.c
39
lib/url.c
@ -377,39 +377,6 @@ CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
|
|
||||||
static void 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
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the internal function curl_easy_cleanup() calls. This should
|
* This is the internal function curl_easy_cleanup() calls. This should
|
||||||
* cleanup and free all resources associated with this sessionhandle.
|
* cleanup and free all resources associated with this sessionhandle.
|
||||||
@ -548,9 +515,7 @@ CURLcode Curl_close(struct SessionHandle *data)
|
|||||||
|
|
||||||
Curl_safefree(data->state.headerbuff);
|
Curl_safefree(data->state.headerbuff);
|
||||||
|
|
||||||
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
|
Curl_flush_cookies(data, 1);
|
||||||
flush_cookies(data, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Curl_digest_cleanup(data);
|
Curl_digest_cleanup(data);
|
||||||
|
|
||||||
@ -1393,7 +1358,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
|||||||
}
|
}
|
||||||
else if(Curl_raw_equal(argptr, "FLUSH")) {
|
else if(Curl_raw_equal(argptr, "FLUSH")) {
|
||||||
/* flush cookies to file */
|
/* flush cookies to file */
|
||||||
flush_cookies(data, 0);
|
Curl_flush_cookies(data, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user