aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/cookie.c
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:56 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:56 +0300
commite988f30484abe5fdeedcc7a5d3c226c01a21800c (patch)
tree0a217b173aabb57b7e51f8a169989b1a3e0309fe /contrib/libs/curl/lib/cookie.c
parent33ee501c05d3f24036ae89766a858930ae66c548 (diff)
downloadydb-e988f30484abe5fdeedcc7a5d3c226c01a21800c.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/curl/lib/cookie.c')
-rw-r--r--contrib/libs/curl/lib/cookie.c1050
1 files changed, 525 insertions, 525 deletions
diff --git a/contrib/libs/curl/lib/cookie.c b/contrib/libs/curl/lib/cookie.c
index e88678c219..c2b770fcc5 100644
--- a/contrib/libs/curl/lib/cookie.c
+++ b/contrib/libs/curl/lib/cookie.c
@@ -26,21 +26,21 @@
RECEIVING COOKIE INFORMATION
============================
-struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
- const char *file, struct CookieInfo *inc, bool newsession);
+struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
+ const char *file, struct CookieInfo *inc, bool newsession);
Inits a cookie struct to store data in a local file. This is always
called before any cookies are set.
-struct Cookie *Curl_cookie_add(struct Curl_easy *data,
- struct CookieInfo *c, bool httpheader, char *lineptr,
- const char *domain, const char *path);
+struct Cookie *Curl_cookie_add(struct Curl_easy *data,
+ struct CookieInfo *c, bool httpheader, char *lineptr,
+ const char *domain, const char *path);
- The 'lineptr' parameter is a full "Set-cookie:" line as
+ The 'lineptr' parameter is a full "Set-cookie:" line as
received from a server.
The function need to replace previously stored lines that this new
- line supersedes.
+ line supersedes.
It may remove lines that are expired.
@@ -50,8 +50,8 @@ struct Cookie *Curl_cookie_add(struct Curl_easy *data,
SENDING COOKIE INFORMATION
==========================
-struct Cookies *Curl_cookie_getlist(struct CookieInfo *cookie,
- char *host, char *path, bool secure);
+struct Cookies *Curl_cookie_getlist(struct CookieInfo *cookie,
+ char *host, char *path, bool secure);
For a given host and path, return a linked list of cookies that
the client should send to the server if used now. The secure
@@ -86,35 +86,35 @@ Example set of cookies:
#include "urldata.h"
#include "cookie.h"
-#include "psl.h"
+#include "psl.h"
#include "strtok.h"
#include "sendf.h"
#include "slist.h"
#include "share.h"
#include "strtoofft.h"
-#include "strcase.h"
+#include "strcase.h"
#include "curl_get_line.h"
#include "curl_memrchr.h"
-#include "inet_pton.h"
+#include "inet_pton.h"
#include "parsedate.h"
#include "rand.h"
#include "rename.h"
-/* The last 3 #include files should be in this order */
-#include "curl_printf.h"
-#include "curl_memory.h"
+/* The last 3 #include files should be in this order */
+#include "curl_printf.h"
+#include "curl_memory.h"
#include "memdebug.h"
static void freecookie(struct Cookie *co)
{
- free(co->expirestr);
- free(co->domain);
- free(co->path);
- free(co->spath);
- free(co->name);
- free(co->value);
- free(co->maxage);
- free(co->version);
+ free(co->expirestr);
+ free(co->domain);
+ free(co->path);
+ free(co->spath);
+ free(co->name);
+ free(co->value);
+ free(co->maxage);
+ free(co->version);
free(co);
}
@@ -126,7 +126,7 @@ static bool tailmatch(const char *cooke_domain, const char *hostname)
if(hostname_len < cookie_domain_len)
return FALSE;
- if(!strcasecompare(cooke_domain, hostname + hostname_len-cookie_domain_len))
+ if(!strcasecompare(cooke_domain, hostname + hostname_len-cookie_domain_len))
return FALSE;
/* A lead char of cookie_domain is not '.'.
@@ -144,37 +144,37 @@ static bool tailmatch(const char *cooke_domain, const char *hostname)
}
/*
- * Return true if the given string is an IP(v4|v6) address.
- */
-static bool isip(const char *domain)
-{
- struct in_addr addr;
-#ifdef ENABLE_IPV6
- struct in6_addr addr6;
-#endif
-
- if(Curl_inet_pton(AF_INET, domain, &addr)
-#ifdef ENABLE_IPV6
- || Curl_inet_pton(AF_INET6, domain, &addr6)
-#endif
- ) {
- /* domain name given as IP address */
- return TRUE;
- }
-
- return FALSE;
-}
-
-/*
+ * Return true if the given string is an IP(v4|v6) address.
+ */
+static bool isip(const char *domain)
+{
+ struct in_addr addr;
+#ifdef ENABLE_IPV6
+ struct in6_addr addr6;
+#endif
+
+ if(Curl_inet_pton(AF_INET, domain, &addr)
+#ifdef ENABLE_IPV6
+ || Curl_inet_pton(AF_INET6, domain, &addr6)
+#endif
+ ) {
+ /* domain name given as IP address */
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*
* matching cookie path and url path
* RFC6265 5.1.4 Paths and Path-Match
*/
-static bool pathmatch(const char *cookie_path, const char *request_uri)
+static bool pathmatch(const char *cookie_path, const char *request_uri)
{
size_t cookie_path_len;
size_t uri_path_len;
- char *uri_path = NULL;
- char *pos;
+ char *uri_path = NULL;
+ char *pos;
bool ret = FALSE;
/* cookie_path must not have last '/' separator. ex: /sample */
@@ -241,13 +241,13 @@ pathmatched:
}
/*
- * Return the top-level domain, for optimal hashing.
- */
-static const char *get_top_domain(const char * const domain, size_t *outlen)
-{
+ * Return the top-level domain, for optimal hashing.
+ */
+static const char *get_top_domain(const char * const domain, size_t *outlen)
+{
size_t len = 0;
- const char *first = NULL, *last;
-
+ const char *first = NULL, *last;
+
if(domain) {
len = strlen(domain);
last = memrchr(domain, '.', len);
@@ -256,46 +256,46 @@ static const char *get_top_domain(const char * const domain, size_t *outlen)
if(first)
len -= (++first - domain);
}
- }
-
- if(outlen)
- *outlen = len;
-
- return first? first: domain;
-}
-
-/*
- * A case-insensitive hash for the cookie domains.
- */
-static size_t cookie_hash_domain(const char *domain, const size_t len)
-{
- const char *end = domain + len;
- size_t h = 5381;
-
- while(domain < end) {
- h += h << 5;
- h ^= Curl_raw_toupper(*domain++);
- }
-
- return (h % COOKIE_HASH_SIZE);
-}
-
-/*
- * Hash this domain.
- */
-static size_t cookiehash(const char * const domain)
-{
- const char *top;
- size_t len;
-
- if(!domain || isip(domain))
- return 0;
-
- top = get_top_domain(domain, &len);
- return cookie_hash_domain(top, len);
-}
-
-/*
+ }
+
+ if(outlen)
+ *outlen = len;
+
+ return first? first: domain;
+}
+
+/*
+ * A case-insensitive hash for the cookie domains.
+ */
+static size_t cookie_hash_domain(const char *domain, const size_t len)
+{
+ const char *end = domain + len;
+ size_t h = 5381;
+
+ while(domain < end) {
+ h += h << 5;
+ h ^= Curl_raw_toupper(*domain++);
+ }
+
+ return (h % COOKIE_HASH_SIZE);
+}
+
+/*
+ * Hash this domain.
+ */
+static size_t cookiehash(const char * const domain)
+{
+ const char *top;
+ size_t len;
+
+ if(!domain || isip(domain))
+ return 0;
+
+ top = get_top_domain(domain, &len);
+ return cookie_hash_domain(top, len);
+}
+
+/*
* cookie path sanitize
*/
static char *sanitize_cookie_path(const char *cookie_path)
@@ -306,14 +306,14 @@ static char *sanitize_cookie_path(const char *cookie_path)
return NULL;
/* some stupid site sends path attribute with '"'. */
- len = strlen(new_path);
+ len = strlen(new_path);
if(new_path[0] == '\"') {
- memmove((void *)new_path, (const void *)(new_path + 1), len);
- len--;
+ memmove((void *)new_path, (const void *)(new_path + 1), len);
+ len--;
}
- if(len && (new_path[len - 1] == '\"')) {
- new_path[len - 1] = 0x0;
- len--;
+ if(len && (new_path[len - 1] == '\"')) {
+ new_path[len - 1] = 0x0;
+ len--;
}
/* RFC6265 5.2.4 The Path Attribute */
@@ -325,7 +325,7 @@ static char *sanitize_cookie_path(const char *cookie_path)
}
/* convert /hoge/ to /hoge */
- if(len && new_path[len - 1] == '/') {
+ if(len && new_path[len - 1] == '/') {
new_path[len - 1] = 0x0;
}
@@ -334,26 +334,26 @@ static char *sanitize_cookie_path(const char *cookie_path)
/*
* Load cookies from all given cookie files (CURLOPT_COOKIEFILE).
- *
- * NOTE: OOM or cookie parsing failures are ignored.
+ *
+ * NOTE: OOM or cookie parsing failures are ignored.
*/
-void Curl_cookie_loadfiles(struct Curl_easy *data)
+void Curl_cookie_loadfiles(struct Curl_easy *data)
{
struct curl_slist *list = data->change.cookielist;
if(list) {
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
while(list) {
- struct CookieInfo *newcookies = Curl_cookie_init(data,
- list->data,
- data->cookies,
- data->set.cookiesession);
- if(!newcookies)
- /* Failure may be due to OOM or a bad cookie; both are ignored
- * but only the first should be
- */
- infof(data, "ignoring failed cookie_init for %s\n", list->data);
- else
- data->cookies = newcookies;
+ struct CookieInfo *newcookies = Curl_cookie_init(data,
+ list->data,
+ data->cookies,
+ data->set.cookiesession);
+ if(!newcookies)
+ /* Failure may be due to OOM or a bad cookie; both are ignored
+ * but only the first should be
+ */
+ infof(data, "ignoring failed cookie_init for %s\n", list->data);
+ else
+ data->cookies = newcookies;
list = list->next;
}
curl_slist_free_all(data->change.cookielist); /* clean up list */
@@ -370,7 +370,7 @@ void Curl_cookie_loadfiles(struct Curl_easy *data)
*/
static void strstore(char **str, const char *newstr)
{
- free(*str);
+ free(*str);
*str = strdup(newstr);
}
@@ -379,39 +379,39 @@ static void strstore(char **str, const char *newstr)
*/
static void remove_expired(struct CookieInfo *cookies)
{
- struct Cookie *co, *nx;
+ struct Cookie *co, *nx;
curl_off_t now = (curl_off_t)time(NULL);
- unsigned int i;
-
- for(i = 0; i < COOKIE_HASH_SIZE; i++) {
- struct Cookie *pv = NULL;
- co = cookies->cookies[i];
- while(co) {
- nx = co->next;
- if(co->expires && co->expires < now) {
- if(!pv) {
- cookies->cookies[i] = co->next;
- }
- else {
- pv->next = co->next;
- }
- cookies->numcookies--;
- freecookie(co);
+ unsigned int i;
+
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ struct Cookie *pv = NULL;
+ co = cookies->cookies[i];
+ while(co) {
+ nx = co->next;
+ if(co->expires && co->expires < now) {
+ if(!pv) {
+ cookies->cookies[i] = co->next;
+ }
+ else {
+ pv->next = co->next;
+ }
+ cookies->numcookies--;
+ freecookie(co);
}
else {
- pv = co;
+ pv = co;
}
- co = nx;
+ co = nx;
}
}
}
-/* Make sure domain contains a dot or is localhost. */
-static bool bad_domain(const char *domain)
-{
- return !strchr(domain, '.') && !strcasecompare(domain, "localhost");
-}
-
+/* Make sure domain contains a dot or is localhost. */
+static bool bad_domain(const char *domain)
+{
+ return !strchr(domain, '.') && !strcasecompare(domain, "localhost");
+}
+
/****************************************************************************
*
* Curl_cookie_add()
@@ -421,19 +421,19 @@ static bool bad_domain(const char *domain)
* Be aware that sometimes we get an IP-only host name, and that might also be
* a numerical IPv6 address.
*
- * Returns NULL on out of memory or invalid cookie. This is suboptimal,
- * as they should be treated separately.
+ * Returns NULL on out of memory or invalid cookie. This is suboptimal,
+ * as they should be treated separately.
***************************************************************************/
struct Cookie *
-Curl_cookie_add(struct Curl_easy *data,
+Curl_cookie_add(struct Curl_easy *data,
/* The 'data' pointer here may be NULL at times, and thus
must only be used very carefully for things that can deal
with data being NULL. Such as infof() and similar */
struct CookieInfo *c,
bool httpheader, /* TRUE if HTTP header-style line */
- bool noexpire, /* if TRUE, skip remove_expired() */
+ bool noexpire, /* if TRUE, skip remove_expired() */
char *lineptr, /* first character of the line */
const char *domain, /* default domain */
const char *path, /* full path used when this cookie is set,
@@ -443,11 +443,11 @@ Curl_cookie_add(struct Curl_easy *data,
{
struct Cookie *clist;
struct Cookie *co;
- struct Cookie *lastc = NULL;
+ struct Cookie *lastc = NULL;
time_t now = time(NULL);
bool replace_old = FALSE;
bool badcookie = FALSE; /* cookies are good by default. mmmmm yummy */
- size_t myhash;
+ size_t myhash;
#ifdef CURL_DISABLE_VERBOSE_STRINGS
(void)data;
@@ -460,19 +460,19 @@ Curl_cookie_add(struct Curl_easy *data,
if(httpheader) {
/* This line was read off a HTTP-header */
- char name[MAX_NAME];
- char what[MAX_NAME];
+ char name[MAX_NAME];
+ char what[MAX_NAME];
const char *ptr;
const char *semiptr;
- size_t linelength = strlen(lineptr);
- if(linelength > MAX_COOKIE_LINE) {
- /* discard overly long lines at once */
+ size_t linelength = strlen(lineptr);
+ if(linelength > MAX_COOKIE_LINE) {
+ /* discard overly long lines at once */
free(co);
return NULL;
}
- semiptr = strchr(lineptr, ';'); /* first, find a semicolon */
+ semiptr = strchr(lineptr, ';'); /* first, find a semicolon */
while(*lineptr && ISBLANK(*lineptr))
lineptr++;
@@ -480,9 +480,9 @@ Curl_cookie_add(struct Curl_easy *data,
ptr = lineptr;
do {
/* we have a <what>=<this> pair or a stand-alone word here */
- name[0] = what[0] = 0; /* init the buffers */
- if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;\r\n=] =%"
- MAX_NAME_TXT "[^;\r\n]",
+ name[0] = what[0] = 0; /* init the buffers */
+ if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;\r\n=] =%"
+ MAX_NAME_TXT "[^;\r\n]",
name, what)) {
/* Use strstore() below to properly deal with received cookie
headers that have the same string property set more than once,
@@ -490,44 +490,44 @@ Curl_cookie_add(struct Curl_easy *data,
const char *whatptr;
bool done = FALSE;
bool sep;
- size_t len = strlen(what);
- size_t nlen = strlen(name);
- const char *endofn = &ptr[ nlen ];
-
- if(nlen >= (MAX_NAME-1) || len >= (MAX_NAME-1) ||
- ((nlen + len) > MAX_NAME)) {
- /* too long individual name or contents, or too long combination of
- name + contents. Chrome and Firefox support 4095 or 4096 bytes
- combo. */
- freecookie(co);
- infof(data, "oversized cookie dropped, name/val %zu + %zu bytes\n",
- nlen, len);
- return NULL;
- }
+ size_t len = strlen(what);
+ size_t nlen = strlen(name);
+ const char *endofn = &ptr[ nlen ];
+
+ if(nlen >= (MAX_NAME-1) || len >= (MAX_NAME-1) ||
+ ((nlen + len) > MAX_NAME)) {
+ /* too long individual name or contents, or too long combination of
+ name + contents. Chrome and Firefox support 4095 or 4096 bytes
+ combo. */
+ freecookie(co);
+ infof(data, "oversized cookie dropped, name/val %zu + %zu bytes\n",
+ nlen, len);
+ return NULL;
+ }
/* name ends with a '=' ? */
sep = (*endofn == '=')?TRUE:FALSE;
- if(nlen) {
- endofn--; /* move to the last character */
- if(ISBLANK(*endofn)) {
- /* skip trailing spaces in name */
- while(*endofn && ISBLANK(*endofn) && nlen) {
- endofn--;
- nlen--;
- }
- name[nlen] = 0; /* new end of name */
- }
- }
-
+ if(nlen) {
+ endofn--; /* move to the last character */
+ if(ISBLANK(*endofn)) {
+ /* skip trailing spaces in name */
+ while(*endofn && ISBLANK(*endofn) && nlen) {
+ endofn--;
+ nlen--;
+ }
+ name[nlen] = 0; /* new end of name */
+ }
+ }
+
/* Strip off trailing whitespace from the 'what' */
while(len && ISBLANK(what[len-1])) {
- what[len-1] = 0;
+ what[len-1] = 0;
len--;
}
/* Skip leading whitespace from the 'what' */
- whatptr = what;
+ whatptr = what;
while(*whatptr && ISBLANK(*whatptr))
whatptr++;
@@ -544,22 +544,22 @@ Curl_cookie_add(struct Curl_easy *data,
co->prefix |= COOKIE_PREFIX__HOST;
}
- if(!co->name) {
- /* The very first name/value pair is the actual cookie name */
- if(!sep) {
- /* Bad name/value pair. */
- badcookie = TRUE;
- break;
- }
- co->name = strdup(name);
- co->value = strdup(whatptr);
- done = TRUE;
- if(!co->name || !co->value) {
- badcookie = TRUE;
- break;
- }
- }
- else if(!len) {
+ if(!co->name) {
+ /* The very first name/value pair is the actual cookie name */
+ if(!sep) {
+ /* Bad name/value pair. */
+ badcookie = TRUE;
+ break;
+ }
+ co->name = strdup(name);
+ co->value = strdup(whatptr);
+ done = TRUE;
+ if(!co->name || !co->value) {
+ badcookie = TRUE;
+ break;
+ }
+ }
+ else if(!len) {
/* this was a "<name>=" with no content, and we must allow
'secure' and 'httponly' specified this weirdly */
done = TRUE;
@@ -577,7 +577,7 @@ Curl_cookie_add(struct Curl_easy *data,
break;
}
}
- else if(strcasecompare("httponly", name))
+ else if(strcasecompare("httponly", name))
co->httponly = TRUE;
else if(sep)
/* there was a '=' so we're not done parsing this field */
@@ -585,69 +585,69 @@ Curl_cookie_add(struct Curl_easy *data,
}
if(done)
;
- else if(strcasecompare("path", name)) {
+ else if(strcasecompare("path", name)) {
strstore(&co->path, whatptr);
if(!co->path) {
badcookie = TRUE; /* out of memory bad */
break;
}
- free(co->spath); /* if this is set again */
+ free(co->spath); /* if this is set again */
co->spath = sanitize_cookie_path(co->path);
if(!co->spath) {
badcookie = TRUE; /* out of memory bad */
break;
}
}
- else if(strcasecompare("domain", name)) {
- bool is_ip;
-
+ else if(strcasecompare("domain", name)) {
+ bool is_ip;
+
/* Now, we make sure that our host is within the given domain,
or the given domain is not valid and thus cannot be set. */
if('.' == whatptr[0])
whatptr++; /* ignore preceding dot */
-#ifndef USE_LIBPSL
- /*
- * Without PSL we don't know when the incoming cookie is set on a
- * TLD or otherwise "protected" suffix. To reduce risk, we require a
- * dot OR the exact host name being "localhost".
- */
- if(bad_domain(whatptr))
- domain = ":";
-#endif
-
- is_ip = isip(domain ? domain : whatptr);
-
- if(!domain
- || (is_ip && !strcmp(whatptr, domain))
- || (!is_ip && tailmatch(whatptr, domain))) {
- strstore(&co->domain, whatptr);
+#ifndef USE_LIBPSL
+ /*
+ * Without PSL we don't know when the incoming cookie is set on a
+ * TLD or otherwise "protected" suffix. To reduce risk, we require a
+ * dot OR the exact host name being "localhost".
+ */
+ if(bad_domain(whatptr))
+ domain = ":";
+#endif
+
+ is_ip = isip(domain ? domain : whatptr);
+
+ if(!domain
+ || (is_ip && !strcmp(whatptr, domain))
+ || (!is_ip && tailmatch(whatptr, domain))) {
+ strstore(&co->domain, whatptr);
if(!co->domain) {
badcookie = TRUE;
break;
}
- if(!is_ip)
- co->tailmatch = TRUE; /* we always do that if the domain name was
- given */
+ if(!is_ip)
+ co->tailmatch = TRUE; /* we always do that if the domain name was
+ given */
}
else {
/* we did not get a tailmatch and then the attempted set domain
is not a domain to which the current host belongs. Mark as
bad. */
- badcookie = TRUE;
+ badcookie = TRUE;
infof(data, "skipped cookie with bad tailmatch domain: %s\n",
whatptr);
}
}
- else if(strcasecompare("version", name)) {
+ else if(strcasecompare("version", name)) {
strstore(&co->version, whatptr);
if(!co->version) {
badcookie = TRUE;
break;
}
}
- else if(strcasecompare("max-age", name)) {
+ else if(strcasecompare("max-age", name)) {
/* Defined in RFC2109:
Optional. The Max-Age attribute defines the lifetime of the
@@ -663,7 +663,7 @@ Curl_cookie_add(struct Curl_easy *data,
break;
}
}
- else if(strcasecompare("expires", name)) {
+ else if(strcasecompare("expires", name)) {
strstore(&co->expirestr, whatptr);
if(!co->expirestr) {
badcookie = TRUE;
@@ -684,54 +684,54 @@ Curl_cookie_add(struct Curl_easy *data,
continue;
}
- ptr = semiptr + 1;
+ ptr = semiptr + 1;
while(*ptr && ISBLANK(*ptr))
ptr++;
- semiptr = strchr(ptr, ';'); /* now, find the next semicolon */
+ semiptr = strchr(ptr, ';'); /* now, find the next semicolon */
if(!semiptr && *ptr)
/* There are no more semicolons, but there's a final name=value pair
coming up */
- semiptr = strchr(ptr, '\0');
+ semiptr = strchr(ptr, '\0');
} while(semiptr);
- if(co->maxage) {
- CURLofft offt;
- offt = curlx_strtoofft((*co->maxage == '\"')?
- &co->maxage[1]:&co->maxage[0], NULL, 10,
- &co->expires);
- if(offt == CURL_OFFT_FLOW)
- /* overflow, used max value */
- co->expires = CURL_OFF_T_MAX;
- else if(!offt) {
- if(!co->expires)
- /* already expired */
- co->expires = 1;
- else if(CURL_OFF_T_MAX - now < co->expires)
- /* would overflow */
- co->expires = CURL_OFF_T_MAX;
- else
- co->expires += now;
- }
- }
- else if(co->expirestr) {
- /* Note that if the date couldn't get parsed for whatever reason,
- the cookie will be treated as a session cookie */
+ if(co->maxage) {
+ CURLofft offt;
+ offt = curlx_strtoofft((*co->maxage == '\"')?
+ &co->maxage[1]:&co->maxage[0], NULL, 10,
+ &co->expires);
+ if(offt == CURL_OFFT_FLOW)
+ /* overflow, used max value */
+ co->expires = CURL_OFF_T_MAX;
+ else if(!offt) {
+ if(!co->expires)
+ /* already expired */
+ co->expires = 1;
+ else if(CURL_OFF_T_MAX - now < co->expires)
+ /* would overflow */
+ co->expires = CURL_OFF_T_MAX;
+ else
+ co->expires += now;
+ }
+ }
+ else if(co->expirestr) {
+ /* Note that if the date couldn't get parsed for whatever reason,
+ the cookie will be treated as a session cookie */
co->expires = Curl_getdate_capped(co->expirestr);
-
- /* Session cookies have expires set to 0 so if we get that back
- from the date parser let's add a second to make it a
- non-session cookie */
- if(co->expires == 0)
- co->expires = 1;
- else if(co->expires < 0)
- co->expires = 0;
- }
-
+
+ /* Session cookies have expires set to 0 so if we get that back
+ from the date parser let's add a second to make it a
+ non-session cookie */
+ if(co->expires == 0)
+ co->expires = 1;
+ else if(co->expires < 0)
+ co->expires = 0;
+ }
+
if(!badcookie && !co->domain) {
if(domain) {
/* no domain was given in the header line, set the default */
- co->domain = strdup(domain);
+ co->domain = strdup(domain);
if(!co->domain)
badcookie = TRUE;
}
@@ -749,10 +749,10 @@ Curl_cookie_add(struct Curl_easy *data,
if(!queryp)
endslash = strrchr(path, '/');
else
- endslash = memrchr(path, '/', (queryp - path));
+ endslash = memrchr(path, '/', (queryp - path));
if(endslash) {
- size_t pathlen = (endslash-path + 1); /* include end slash */
- co->path = malloc(pathlen + 1); /* one extra for the zero byte */
+ size_t pathlen = (endslash-path + 1); /* include end slash */
+ co->path = malloc(pathlen + 1); /* one extra for the zero byte */
if(co->path) {
memcpy(co->path, path, pathlen);
co->path[pathlen] = 0; /* null-terminate */
@@ -778,7 +778,7 @@ Curl_cookie_add(struct Curl_easy *data,
reading the odd netscape cookies-file format here */
char *ptr;
char *firstptr;
- char *tok_buf = NULL;
+ char *tok_buf = NULL;
int fields;
/* IE introduced HTTP-only cookies to prevent XSS attacks. Cookies
@@ -799,19 +799,19 @@ Curl_cookie_add(struct Curl_easy *data,
return NULL;
}
/* strip off the possible end-of-line characters */
- ptr = strchr(lineptr, '\r');
+ ptr = strchr(lineptr, '\r');
if(ptr)
- *ptr = 0; /* clear it */
- ptr = strchr(lineptr, '\n');
+ *ptr = 0; /* clear it */
+ ptr = strchr(lineptr, '\n');
if(ptr)
- *ptr = 0; /* clear it */
+ *ptr = 0; /* clear it */
- firstptr = strtok_r(lineptr, "\t", &tok_buf); /* tokenize it on the TAB */
+ firstptr = strtok_r(lineptr, "\t", &tok_buf); /* tokenize it on the TAB */
/* Now loop through the fields and init the struct we already have
allocated */
- for(ptr = firstptr, fields = 0; ptr && !badcookie;
- ptr = strtok_r(NULL, "\t", &tok_buf), fields++) {
+ for(ptr = firstptr, fields = 0; ptr && !badcookie;
+ ptr = strtok_r(NULL, "\t", &tok_buf), fields++) {
switch(fields) {
case 0:
if(ptr[0]=='.') /* skip preceding dots */
@@ -825,7 +825,7 @@ Curl_cookie_add(struct Curl_easy *data,
domain can access the variable. Set TRUE when the cookie says
.domain.com and to false when the domain is complete www.domain.com
*/
- co->tailmatch = strcasecompare(ptr, "TRUE")?TRUE:FALSE;
+ co->tailmatch = strcasecompare(ptr, "TRUE")?TRUE:FALSE;
break;
case 2:
/* The file format allows the path field to remain not filled in */
@@ -861,8 +861,8 @@ Curl_cookie_add(struct Curl_easy *data,
}
break;
case 4:
- if(curlx_strtoofft(ptr, NULL, 10, &co->expires))
- badcookie = TRUE;
+ if(curlx_strtoofft(ptr, NULL, 10, &co->expires))
+ badcookie = TRUE;
break;
case 5:
co->name = strdup(ptr);
@@ -931,50 +931,50 @@ Curl_cookie_add(struct Curl_easy *data,
}
co->livecookie = c->running;
- co->creationtime = ++c->lastct;
+ co->creationtime = ++c->lastct;
/* now, we have parsed the incoming line, we must now check if this
- supersedes an already existing cookie, which it may if the previous have
+ supersedes an already existing cookie, which it may if the previous have
the same domain and path as this */
/* at first, remove expired cookies */
- if(!noexpire)
- remove_expired(c);
-
-#ifdef USE_LIBPSL
- /* Check if the domain is a Public Suffix and if yes, ignore the cookie. */
- if(domain && co->domain && !isip(co->domain)) {
- const psl_ctx_t *psl = Curl_psl_use(data);
- int acceptable;
-
- if(psl) {
- acceptable = psl_is_cookie_domain_acceptable(psl, domain, co->domain);
- Curl_psl_release(data);
- }
- else
- acceptable = !bad_domain(domain);
-
- if(!acceptable) {
- infof(data, "cookie '%s' dropped, domain '%s' must not "
- "set cookies for '%s'\n", co->name, domain, co->domain);
- freecookie(co);
- return NULL;
- }
- }
-#endif
-
- myhash = cookiehash(co->domain);
- clist = c->cookies[myhash];
+ if(!noexpire)
+ remove_expired(c);
+
+#ifdef USE_LIBPSL
+ /* Check if the domain is a Public Suffix and if yes, ignore the cookie. */
+ if(domain && co->domain && !isip(co->domain)) {
+ const psl_ctx_t *psl = Curl_psl_use(data);
+ int acceptable;
+
+ if(psl) {
+ acceptable = psl_is_cookie_domain_acceptable(psl, domain, co->domain);
+ Curl_psl_release(data);
+ }
+ else
+ acceptable = !bad_domain(domain);
+
+ if(!acceptable) {
+ infof(data, "cookie '%s' dropped, domain '%s' must not "
+ "set cookies for '%s'\n", co->name, domain, co->domain);
+ freecookie(co);
+ return NULL;
+ }
+ }
+#endif
+
+ myhash = cookiehash(co->domain);
+ clist = c->cookies[myhash];
replace_old = FALSE;
while(clist) {
- if(strcasecompare(clist->name, co->name)) {
+ if(strcasecompare(clist->name, co->name)) {
/* the names are identical */
if(clist->domain && co->domain) {
- if(strcasecompare(clist->domain, co->domain) &&
- (clist->tailmatch == co->tailmatch))
+ if(strcasecompare(clist->domain, co->domain) &&
+ (clist->tailmatch == co->tailmatch))
/* The domains are identical */
- replace_old = TRUE;
+ replace_old = TRUE;
}
else if(!clist->domain && !co->domain)
replace_old = TRUE;
@@ -1032,18 +1032,18 @@ Curl_cookie_add(struct Curl_easy *data,
if(replace_old) {
co->next = clist->next; /* get the next-pointer first */
- /* when replacing, creationtime is kept from old */
- co->creationtime = clist->creationtime;
-
+ /* when replacing, creationtime is kept from old */
+ co->creationtime = clist->creationtime;
+
/* then free all the old pointers */
free(clist->name);
- free(clist->value);
- free(clist->domain);
- free(clist->path);
- free(clist->spath);
- free(clist->expirestr);
- free(clist->version);
- free(clist->maxage);
+ free(clist->value);
+ free(clist->domain);
+ free(clist->path);
+ free(clist->spath);
+ free(clist->expirestr);
+ free(clist->version);
+ free(clist->maxage);
*clist = *co; /* then store all the new data */
@@ -1066,7 +1066,7 @@ Curl_cookie_add(struct Curl_easy *data,
if(c->running)
/* Only show this when NOT reading the cookies from a file */
infof(data, "%s cookie %s=\"%s\" for domain %s, path %s, "
- "expire %" CURL_FORMAT_CURL_OFF_T "\n",
+ "expire %" CURL_FORMAT_CURL_OFF_T "\n",
replace_old?"Replaced":"Added", co->name, co->value,
co->domain, co->path, co->expires);
@@ -1075,14 +1075,14 @@ Curl_cookie_add(struct Curl_easy *data,
if(lastc)
lastc->next = co;
else
- c->cookies[myhash] = co;
+ c->cookies[myhash] = co;
c->numcookies++; /* one more cookie in the jar */
}
return co;
}
-
+
/*****************************************************************************
*
* Curl_cookie_init()
@@ -1094,17 +1094,17 @@ Curl_cookie_add(struct Curl_easy *data,
*
* Note that 'data' might be called as NULL pointer.
*
- * Returns NULL on out of memory. Invalid cookies are ignored.
+ * Returns NULL on out of memory. Invalid cookies are ignored.
****************************************************************************/
-struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
+struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
const char *file,
struct CookieInfo *inc,
bool newsession)
{
struct CookieInfo *c;
- FILE *fp = NULL;
- bool fromfile = TRUE;
- char *line = NULL;
+ FILE *fp = NULL;
+ bool fromfile = TRUE;
+ char *line = NULL;
if(NULL == inc) {
/* we didn't get a struct, create one */
@@ -1112,8 +1112,8 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
if(!c)
return NULL; /* failed to get memory */
c->filename = strdup(file?file:"none"); /* copy the name just in case */
- if(!c->filename)
- goto fail; /* failed to get memory */
+ if(!c->filename)
+ goto fail; /* failed to get memory */
}
else {
/* we got an already existing one, use that */
@@ -1121,16 +1121,16 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
}
c->running = FALSE; /* this is not running, this is init */
- if(file && !strcmp(file, "-")) {
+ if(file && !strcmp(file, "-")) {
fp = stdin;
- fromfile = FALSE;
+ fromfile = FALSE;
}
else if(file && !*file) {
/* points to a "" string */
fp = NULL;
}
else
- fp = file?fopen(file, FOPEN_READTEXT):NULL;
+ fp = file?fopen(file, FOPEN_READTEXT):NULL;
c->newsession = newsession; /* new session? */
@@ -1138,27 +1138,27 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
char *lineptr;
bool headerline;
- line = malloc(MAX_COOKIE_LINE);
- if(!line)
- goto fail;
+ line = malloc(MAX_COOKIE_LINE);
+ if(!line)
+ goto fail;
while(Curl_get_line(line, MAX_COOKIE_LINE, fp)) {
- if(checkprefix("Set-Cookie:", line)) {
- /* This is a cookie line, get it! */
- lineptr = &line[11];
- headerline = TRUE;
- }
- else {
- lineptr = line;
- headerline = FALSE;
- }
- while(*lineptr && ISBLANK(*lineptr))
- lineptr++;
+ if(checkprefix("Set-Cookie:", line)) {
+ /* This is a cookie line, get it! */
+ lineptr = &line[11];
+ headerline = TRUE;
+ }
+ else {
+ lineptr = line;
+ headerline = FALSE;
+ }
+ while(*lineptr && ISBLANK(*lineptr))
+ lineptr++;
Curl_cookie_add(data, c, headerline, TRUE, lineptr, NULL, NULL, TRUE);
}
- free(line); /* free the line buffer */
- remove_expired(c); /* run this once, not on every cookie */
-
+ free(line); /* free the line buffer */
+ remove_expired(c); /* run this once, not on every cookie */
+
if(fromfile)
fclose(fp);
}
@@ -1168,16 +1168,16 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
data->state.cookie_engine = TRUE;
return c;
-
-fail:
- free(line);
- if(!inc)
- /* Only clean up if we allocated it here, as the original could still be in
- * use by a share handle */
- Curl_cookie_cleanup(c);
- if(fromfile && fp)
- fclose(fp);
- return NULL; /* out of memory */
+
+fail:
+ free(line);
+ if(!inc)
+ /* Only clean up if we allocated it here, as the original could still be in
+ * use by a share handle */
+ Curl_cookie_cleanup(c);
+ if(fromfile && fp)
+ fclose(fp);
+ return NULL; /* out of memory */
}
/* sort this so that the longest path gets before the shorter path */
@@ -1201,61 +1201,61 @@ static int cookie_sort(const void *p1, const void *p2)
if(l1 != l2)
return (l2 > l1) ? 1 : -1 ; /* avoid size_t <=> int conversions */
- /* 3 - compare cookie name lengths */
- l1 = c1->name ? strlen(c1->name) : 0;
- l2 = c2->name ? strlen(c2->name) : 0;
-
- if(l1 != l2)
- return (l2 > l1) ? 1 : -1;
-
- /* 4 - compare cookie creation time */
- return (c2->creationtime > c1->creationtime) ? 1 : -1;
-}
-
-/* sort cookies only according to creation time */
-static int cookie_sort_ct(const void *p1, const void *p2)
-{
- struct Cookie *c1 = *(struct Cookie **)p1;
- struct Cookie *c2 = *(struct Cookie **)p2;
-
- return (c2->creationtime > c1->creationtime) ? 1 : -1;
-}
-
-#define CLONE(field) \
- do { \
- if(src->field) { \
- d->field = strdup(src->field); \
- if(!d->field) \
- goto fail; \
- } \
- } while(0)
+ /* 3 - compare cookie name lengths */
+ l1 = c1->name ? strlen(c1->name) : 0;
+ l2 = c2->name ? strlen(c2->name) : 0;
-static struct Cookie *dup_cookie(struct Cookie *src)
-{
- struct Cookie *d = calloc(sizeof(struct Cookie), 1);
- if(d) {
- CLONE(expirestr);
- CLONE(domain);
- CLONE(path);
- CLONE(spath);
- CLONE(name);
- CLONE(value);
- CLONE(maxage);
- CLONE(version);
- d->expires = src->expires;
- d->tailmatch = src->tailmatch;
- d->secure = src->secure;
- d->livecookie = src->livecookie;
- d->httponly = src->httponly;
- d->creationtime = src->creationtime;
- }
- return d;
-
- fail:
- freecookie(d);
- return NULL;
+ if(l1 != l2)
+ return (l2 > l1) ? 1 : -1;
+
+ /* 4 - compare cookie creation time */
+ return (c2->creationtime > c1->creationtime) ? 1 : -1;
}
+/* sort cookies only according to creation time */
+static int cookie_sort_ct(const void *p1, const void *p2)
+{
+ struct Cookie *c1 = *(struct Cookie **)p1;
+ struct Cookie *c2 = *(struct Cookie **)p2;
+
+ return (c2->creationtime > c1->creationtime) ? 1 : -1;
+}
+
+#define CLONE(field) \
+ do { \
+ if(src->field) { \
+ d->field = strdup(src->field); \
+ if(!d->field) \
+ goto fail; \
+ } \
+ } while(0)
+
+static struct Cookie *dup_cookie(struct Cookie *src)
+{
+ struct Cookie *d = calloc(sizeof(struct Cookie), 1);
+ if(d) {
+ CLONE(expirestr);
+ CLONE(domain);
+ CLONE(path);
+ CLONE(spath);
+ CLONE(name);
+ CLONE(value);
+ CLONE(maxage);
+ CLONE(version);
+ d->expires = src->expires;
+ d->tailmatch = src->tailmatch;
+ d->secure = src->secure;
+ d->livecookie = src->livecookie;
+ d->httponly = src->httponly;
+ d->creationtime = src->creationtime;
+ }
+ return d;
+
+ fail:
+ freecookie(d);
+ return NULL;
+}
+
/*****************************************************************************
*
* Curl_cookie_getlist()
@@ -1274,30 +1274,30 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
{
struct Cookie *newco;
struct Cookie *co;
- struct Cookie *mainco = NULL;
+ struct Cookie *mainco = NULL;
size_t matches = 0;
- bool is_ip;
- const size_t myhash = cookiehash(host);
+ bool is_ip;
+ const size_t myhash = cookiehash(host);
- if(!c || !c->cookies[myhash])
+ if(!c || !c->cookies[myhash])
return NULL; /* no cookie struct or no cookies in the struct */
/* at first, remove expired cookies */
remove_expired(c);
- /* check if host is an IP(v4|v6) address */
- is_ip = isip(host);
-
- co = c->cookies[myhash];
+ /* check if host is an IP(v4|v6) address */
+ is_ip = isip(host);
+ co = c->cookies[myhash];
+
while(co) {
- /* if the cookie requires we're secure we must only continue if we are! */
- if(co->secure?secure:TRUE) {
+ /* if the cookie requires we're secure we must only continue if we are! */
+ if(co->secure?secure:TRUE) {
/* now check if the domain is correct */
if(!co->domain ||
- (co->tailmatch && !is_ip && tailmatch(co->domain, host)) ||
- ((!co->tailmatch || is_ip) && strcasecompare(host, co->domain)) ) {
+ (co->tailmatch && !is_ip && tailmatch(co->domain, host)) ||
+ ((!co->tailmatch || is_ip) && strcasecompare(host, co->domain)) ) {
/* the right part of the host matches the domain stuff in the
cookie data */
@@ -1308,7 +1308,7 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
/* and now, we know this is a match and we should create an
entry for the return-linked-list */
- newco = dup_cookie(co);
+ newco = dup_cookie(co);
if(newco) {
/* then modify our next */
newco->next = mainco;
@@ -1318,8 +1318,8 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
matches++;
}
- else
- goto fail;
+ else
+ goto fail;
}
}
}
@@ -1340,7 +1340,7 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
co = mainco;
- for(i = 0; co; co = co->next)
+ for(i = 0; co; co = co->next)
array[i++] = co;
/* now sort the cookie pointers in path length order */
@@ -1349,19 +1349,19 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
/* remake the linked list order according to the new order */
mainco = array[0]; /* start here */
- for(i = 0; i<matches-1; i++)
- array[i]->next = array[i + 1];
+ for(i = 0; i<matches-1; i++)
+ array[i]->next = array[i + 1];
array[matches-1]->next = NULL; /* terminate the list */
free(array); /* remove the temporary data again */
}
return mainco; /* return the new list */
-
-fail:
- /* failure, clear up the allocated chain and return NULL */
- Curl_cookie_freelist(mainco);
- return NULL;
+
+fail:
+ /* failure, clear up the allocated chain and return NULL */
+ Curl_cookie_freelist(mainco);
+ return NULL;
}
/*****************************************************************************
@@ -1374,11 +1374,11 @@ fail:
void Curl_cookie_clearall(struct CookieInfo *cookies)
{
if(cookies) {
- unsigned int i;
- for(i = 0; i < COOKIE_HASH_SIZE; i++) {
- Curl_cookie_freelist(cookies->cookies[i]);
- cookies->cookies[i] = NULL;
- }
+ unsigned int i;
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ Curl_cookie_freelist(cookies->cookies[i]);
+ cookies->cookies[i] = NULL;
+ }
cookies->numcookies = 0;
}
}
@@ -1391,13 +1391,13 @@ void Curl_cookie_clearall(struct CookieInfo *cookies)
*
****************************************************************************/
-void Curl_cookie_freelist(struct Cookie *co)
+void Curl_cookie_freelist(struct Cookie *co)
{
struct Cookie *next;
- while(co) {
- next = co->next;
- freecookie(co);
- co = next;
+ while(co) {
+ next = co->next;
+ freecookie(co);
+ co = next;
}
}
@@ -1412,36 +1412,36 @@ void Curl_cookie_freelist(struct Cookie *co)
void Curl_cookie_clearsess(struct CookieInfo *cookies)
{
struct Cookie *first, *curr, *next, *prev = NULL;
- unsigned int i;
+ unsigned int i;
- if(!cookies)
+ if(!cookies)
return;
- for(i = 0; i < COOKIE_HASH_SIZE; i++) {
- if(!cookies->cookies[i])
- continue;
-
- first = curr = prev = cookies->cookies[i];
-
- for(; curr; curr = next) {
- next = curr->next;
- if(!curr->expires) {
- if(first == curr)
- first = next;
-
- if(prev == curr)
- prev = next;
- else
- prev->next = next;
-
- freecookie(curr);
- cookies->numcookies--;
- }
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ if(!cookies->cookies[i])
+ continue;
+
+ first = curr = prev = cookies->cookies[i];
+
+ for(; curr; curr = next) {
+ next = curr->next;
+ if(!curr->expires) {
+ if(first == curr)
+ first = next;
+
+ if(prev == curr)
+ prev = next;
+ else
+ prev->next = next;
+
+ freecookie(curr);
+ cookies->numcookies--;
+ }
else
- prev = curr;
- }
+ prev = curr;
+ }
- cookies->cookies[i] = first;
+ cookies->cookies[i] = first;
}
}
@@ -1450,16 +1450,16 @@ void Curl_cookie_clearsess(struct CookieInfo *cookies)
*
* Curl_cookie_cleanup()
*
- * Free a "cookie object" previous created with Curl_cookie_init().
+ * Free a "cookie object" previous created with Curl_cookie_init().
*
****************************************************************************/
void Curl_cookie_cleanup(struct CookieInfo *c)
{
if(c) {
- unsigned int i;
- free(c->filename);
- for(i = 0; i < COOKIE_HASH_SIZE; i++)
- Curl_cookie_freelist(c->cookies[i]);
+ unsigned int i;
+ free(c->filename);
+ for(i = 0; i < COOKIE_HASH_SIZE; i++)
+ Curl_cookie_freelist(c->cookies[i]);
free(c); /* free the base struct as well */
}
}
@@ -1478,7 +1478,7 @@ static char *get_netscape_format(const struct Cookie *co)
"%s\t" /* tailmatch */
"%s\t" /* path */
"%s\t" /* secure */
- "%" CURL_FORMAT_CURL_OFF_T "\t" /* expires */
+ "%" CURL_FORMAT_CURL_OFF_T "\t" /* expires */
"%s\t" /* name */
"%s", /* value */
co->httponly?"#HttpOnly_":"",
@@ -1507,7 +1507,7 @@ static int cookie_output(struct Curl_easy *data,
{
struct Cookie *co;
FILE *out = NULL;
- bool use_stdout = FALSE;
+ bool use_stdout = FALSE;
char *tempstore = NULL;
bool error = false;
@@ -1521,7 +1521,7 @@ static int cookie_output(struct Curl_easy *data,
if(!strcmp("-", filename)) {
/* use stdout */
out = stdout;
- use_stdout = TRUE;
+ use_stdout = TRUE;
}
else {
unsigned char randsuffix[9];
@@ -1538,44 +1538,44 @@ static int cookie_output(struct Curl_easy *data,
goto error;
}
- fputs("# Netscape HTTP Cookie File\n"
+ fputs("# Netscape HTTP Cookie File\n"
"# https://curl.se/docs/http-cookies.html\n"
- "# This file was generated by libcurl! Edit at your own risk.\n\n",
- out);
+ "# This file was generated by libcurl! Edit at your own risk.\n\n",
+ out);
- if(c->numcookies) {
+ if(c->numcookies) {
unsigned int i;
size_t nvalid = 0;
struct Cookie **array;
array = calloc(1, sizeof(struct Cookie *) * c->numcookies);
- if(!array) {
+ if(!array) {
goto error;
- }
+ }
/* only sort the cookies with a domain property */
- for(i = 0; i < COOKIE_HASH_SIZE; i++) {
- for(co = c->cookies[i]; co; co = co->next) {
- if(!co->domain)
- continue;
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ for(co = c->cookies[i]; co; co = co->next) {
+ if(!co->domain)
+ continue;
array[nvalid++] = co;
- }
- }
-
+ }
+ }
+
qsort(array, nvalid, sizeof(struct Cookie *), cookie_sort_ct);
-
+
for(i = 0; i < nvalid; i++) {
char *format_ptr = get_netscape_format(array[i]);
if(format_ptr == NULL) {
fprintf(out, "#\n# Fatal libcurl error\n");
- free(array);
+ free(array);
goto error;
}
fprintf(out, "%s\n", format_ptr);
free(format_ptr);
}
-
- free(array);
+
+ free(array);
}
if(!use_stdout) {
@@ -1597,51 +1597,51 @@ cleanup:
return error ? 1 : 0;
}
-static struct curl_slist *cookie_list(struct Curl_easy *data)
+static struct curl_slist *cookie_list(struct Curl_easy *data)
{
struct curl_slist *list = NULL;
struct curl_slist *beg;
struct Cookie *c;
char *line;
- unsigned int i;
+ unsigned int i;
if((data->cookies == NULL) ||
(data->cookies->numcookies == 0))
return NULL;
- for(i = 0; i < COOKIE_HASH_SIZE; i++) {
- for(c = data->cookies->cookies[i]; c; c = c->next) {
- if(!c->domain)
- continue;
- line = get_netscape_format(c);
- if(!line) {
- curl_slist_free_all(list);
- return NULL;
- }
- beg = Curl_slist_append_nodup(list, line);
- if(!beg) {
- free(line);
- curl_slist_free_all(list);
- return NULL;
- }
- list = beg;
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ for(c = data->cookies->cookies[i]; c; c = c->next) {
+ if(!c->domain)
+ continue;
+ line = get_netscape_format(c);
+ if(!line) {
+ curl_slist_free_all(list);
+ return NULL;
+ }
+ beg = Curl_slist_append_nodup(list, line);
+ if(!beg) {
+ free(line);
+ curl_slist_free_all(list);
+ return NULL;
+ }
+ list = beg;
}
}
return list;
}
-struct curl_slist *Curl_cookie_list(struct Curl_easy *data)
+struct curl_slist *Curl_cookie_list(struct Curl_easy *data)
{
- struct curl_slist *list;
- Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
- list = cookie_list(data);
- Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
- return list;
-}
-
+ struct curl_slist *list;
+ Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
+ list = cookie_list(data);
+ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+ return list;
+}
+
void Curl_flush_cookies(struct Curl_easy *data, bool 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