mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
Now we're setting a default domain for received cookies so that we can
properly match those cookies in subsequent requests
This commit is contained in:
parent
9efdb68035
commit
598e8dfbfb
15
lib/cookie.c
15
lib/cookie.c
@ -104,7 +104,8 @@ Example set of cookies:
|
|||||||
struct Cookie *
|
struct Cookie *
|
||||||
Curl_cookie_add(struct CookieInfo *c,
|
Curl_cookie_add(struct CookieInfo *c,
|
||||||
bool httpheader, /* TRUE if HTTP header-style line */
|
bool httpheader, /* TRUE if HTTP header-style line */
|
||||||
char *lineptr) /* first non-space of the line */
|
char *lineptr, /* first non-space of the line */
|
||||||
|
char *domain) /* default domain */
|
||||||
{
|
{
|
||||||
struct Cookie *clist;
|
struct Cookie *clist;
|
||||||
char what[MAX_COOKIE_LINE];
|
char what[MAX_COOKIE_LINE];
|
||||||
@ -194,6 +195,10 @@ Curl_cookie_add(struct CookieInfo *c,
|
|||||||
ptr++;
|
ptr++;
|
||||||
semiptr=strchr(ptr, ';'); /* now, find the next semicolon */
|
semiptr=strchr(ptr, ';'); /* now, find the next semicolon */
|
||||||
} while(semiptr);
|
} while(semiptr);
|
||||||
|
|
||||||
|
if(NULL == co->domain)
|
||||||
|
/* no domain given in the header line, set the default now */
|
||||||
|
co->domain=strdup(domain);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* This line is NOT a HTTP header style line, we do offer support for
|
/* This line is NOT a HTTP header style line, we do offer support for
|
||||||
@ -441,7 +446,7 @@ struct CookieInfo *Curl_cookie_init(char *file, struct CookieInfo *inc)
|
|||||||
while(*lineptr && isspace((int)*lineptr))
|
while(*lineptr && isspace((int)*lineptr))
|
||||||
lineptr++;
|
lineptr++;
|
||||||
|
|
||||||
Curl_cookie_add(c, headerline, lineptr);
|
Curl_cookie_add(c, headerline, lineptr, NULL);
|
||||||
}
|
}
|
||||||
if(fromfile)
|
if(fromfile)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -632,13 +637,13 @@ int Curl_cookie_output(struct CookieInfo *c, char *dumphere)
|
|||||||
"%u\t" /* expires */
|
"%u\t" /* expires */
|
||||||
"%s\t" /* name */
|
"%s\t" /* name */
|
||||||
"%s\n", /* value */
|
"%s\n", /* value */
|
||||||
co->domain,
|
co->domain?co->domain:"unknown",
|
||||||
co->field1==2?"TRUE":"FALSE",
|
co->field1==2?"TRUE":"FALSE",
|
||||||
co->path,
|
co->path?co->path:"/",
|
||||||
co->secure?"TRUE":"FALSE",
|
co->secure?"TRUE":"FALSE",
|
||||||
(unsigned int)co->expires,
|
(unsigned int)co->expires,
|
||||||
co->name,
|
co->name,
|
||||||
co->value);
|
co->value?co->value:"");
|
||||||
|
|
||||||
co=co->next;
|
co=co->next;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,13 @@ struct CookieInfo {
|
|||||||
#define MAX_NAME 256
|
#define MAX_NAME 256
|
||||||
#define MAX_NAME_TXT "255"
|
#define MAX_NAME_TXT "255"
|
||||||
|
|
||||||
struct Cookie *Curl_cookie_add(struct CookieInfo *, bool, char *);
|
/*
|
||||||
|
* Add a cookie to the internal list of cookies. The domain argument is only
|
||||||
|
* used if the header boolean is TRUE.
|
||||||
|
*/
|
||||||
|
struct Cookie *Curl_cookie_add(struct CookieInfo *, bool header, char *line,
|
||||||
|
char *domain);
|
||||||
|
|
||||||
struct CookieInfo *Curl_cookie_init(char *, struct CookieInfo *);
|
struct CookieInfo *Curl_cookie_init(char *, struct CookieInfo *);
|
||||||
struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
|
struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
|
||||||
void Curl_cookie_freelist(struct Cookie *);
|
void Curl_cookie_freelist(struct Cookie *);
|
||||||
|
@ -620,7 +620,7 @@ Transfer(struct connectdata *c_conn)
|
|||||||
}
|
}
|
||||||
else if(data->cookies &&
|
else if(data->cookies &&
|
||||||
strnequal("Set-Cookie:", p, 11)) {
|
strnequal("Set-Cookie:", p, 11)) {
|
||||||
Curl_cookie_add(data->cookies, TRUE, &p[12]);
|
Curl_cookie_add(data->cookies, TRUE, &p[12], conn->name);
|
||||||
}
|
}
|
||||||
else if(strnequal("Last-Modified:", p,
|
else if(strnequal("Last-Modified:", p,
|
||||||
strlen("Last-Modified:")) &&
|
strlen("Last-Modified:")) &&
|
||||||
|
Loading…
Reference in New Issue
Block a user