aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2011-04-04 15:46:42 +0200
committerDaniel Stenberg <daniel@haxx.se>2011-04-04 19:27:26 +0200
commit9d1e914a56e8a4030d8917875eaedaddf5cff97c (patch)
tree103f73104c796dd3000b7063623d20a256601d6a /lib
parentd3408d05935e61a303b5761cc5aa029eb54408f8 (diff)
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')
-rw-r--r--lib/cookie.c33
-rw-r--r--lib/cookie.h12
-rw-r--r--lib/easy.c9
-rw-r--r--lib/share.c4
-rw-r--r--lib/url.c39
5 files changed, 44 insertions, 53 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 */
diff --git a/lib/cookie.h b/lib/cookie.h
index e8c005f20..6b159b238 100644
--- a/lib/cookie.h
+++ b/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
* 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,
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 *,
const char *, bool);
void Curl_cookie_freelist(struct Cookie *cookies, bool cookiestoo);
void Curl_cookie_clearall(struct CookieInfo *cookies);
void Curl_cookie_clearsess(struct CookieInfo *cookies);
-void Curl_cookie_cleanup(struct CookieInfo *);
int Curl_cookie_output(struct CookieInfo *, const char *);
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
#define Curl_cookie_list(x) NULL
#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
+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);
void Curl_cookie_loadfiles(struct SessionHandle *data);
#endif
diff --git a/lib/easy.c b/lib/easy.c
index 6f553475b..7015eced2 100644
--- a/lib/easy.c
+++ b/lib/easy.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
@@ -654,7 +654,6 @@ CURL *curl_easy_duphandle(CURL *incurl)
outcurl->progress.flags = data->progress.flags;
outcurl->progress.callback = data->progress.callback;
-#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
if(data->cookies) {
/* If cookies are enabled in the parent handle, we enable them
in the clone as well! */
@@ -665,18 +664,14 @@ CURL *curl_easy_duphandle(CURL *incurl)
if(!outcurl->cookies)
goto fail;
}
-#endif /* CURL_DISABLE_HTTP */
/* duplicate all values in 'change' */
-
-#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
if(data->change.cookielist) {
outcurl->change.cookielist =
Curl_slist_duplicate(data->change.cookielist);
if(!outcurl->change.cookielist)
goto fail;
}
-#endif /* CURL_DISABLE_HTTP */
if(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);
if(outcurl->state.headerbuff)
free(outcurl->state.headerbuff);
-#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
if(outcurl->change.cookielist)
curl_slist_free_all(outcurl->change.cookielist);
-#endif
if(outcurl->change.url)
free(outcurl->change.url);
if(outcurl->change.referer)
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, <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
@@ -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);
diff --git a/lib/url.c b/lib/url.c
index 25f03b7e2..5ece35ed2 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -377,39 +377,6 @@ CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src)
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
* cleanup and free all resources associated with this sessionhandle.
@@ -548,9 +515,7 @@ CURLcode Curl_close(struct SessionHandle *data)
Curl_safefree(data->state.headerbuff);
-#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
- flush_cookies(data, 1);
-#endif
+ Curl_flush_cookies(data, 1);
Curl_digest_cleanup(data);
@@ -1393,7 +1358,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
}
else if(Curl_raw_equal(argptr, "FLUSH")) {
/* flush cookies to file */
- flush_cookies(data, 0);
+ Curl_flush_cookies(data, 0);
break;
}