Added some RFC2109 support
This commit is contained in:
parent
0bc8d2ea1f
commit
c6a8bb3d56
28
lib/cookie.c
28
lib/cookie.c
@ -101,6 +101,7 @@ struct Cookie *cookie_add(struct CookieInfo *c,
|
|||||||
*semiptr='\0'; /* zero terminate for a while */
|
*semiptr='\0'; /* zero terminate for a while */
|
||||||
/* we have a <what>=<this> pair or a 'secure' word here */
|
/* we have a <what>=<this> pair or a 'secure' word here */
|
||||||
if(strchr(ptr, '=')) {
|
if(strchr(ptr, '=')) {
|
||||||
|
name[0]=what[0]=0; /* init the buffers */
|
||||||
if(2 == sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
|
if(2 == sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
|
||||||
MAX_COOKIE_LINE_TXT "[^\r\n]",
|
MAX_COOKIE_LINE_TXT "[^\r\n]",
|
||||||
name, what)) {
|
name, what)) {
|
||||||
@ -111,6 +112,23 @@ struct Cookie *cookie_add(struct CookieInfo *c,
|
|||||||
else if(strequal("domain", name)) {
|
else if(strequal("domain", name)) {
|
||||||
co->domain=strdup(what);
|
co->domain=strdup(what);
|
||||||
}
|
}
|
||||||
|
else if(strequal("version", name)) {
|
||||||
|
co->version=strdup(what);
|
||||||
|
}
|
||||||
|
else if(strequal("max-age", name)) {
|
||||||
|
/* Defined in RFC2109:
|
||||||
|
|
||||||
|
Optional. The Max-Age attribute defines the lifetime of the
|
||||||
|
cookie, in seconds. The delta-seconds value is a decimal non-
|
||||||
|
negative integer. After delta-seconds seconds elapse, the
|
||||||
|
client should discard the cookie. A value of zero means the
|
||||||
|
cookie should be discarded immediately.
|
||||||
|
|
||||||
|
*/
|
||||||
|
co->maxage = strdup(what);
|
||||||
|
co->expires =
|
||||||
|
atoi((*co->maxage=='\"')?&co->maxage[1]:&co->maxage[0]);
|
||||||
|
}
|
||||||
else if(strequal("expires", name)) {
|
else if(strequal("expires", name)) {
|
||||||
co->expirestr=strdup(what);
|
co->expirestr=strdup(what);
|
||||||
co->expires = get_date(what, &now);
|
co->expires = get_date(what, &now);
|
||||||
@ -264,6 +282,11 @@ struct Cookie *cookie_add(struct CookieInfo *c,
|
|||||||
if(clist->expirestr)
|
if(clist->expirestr)
|
||||||
free(clist->expirestr);
|
free(clist->expirestr);
|
||||||
|
|
||||||
|
if(clist->version)
|
||||||
|
free(clist->version);
|
||||||
|
if(clist->maxage)
|
||||||
|
free(clist->maxage);
|
||||||
|
|
||||||
*clist = *co; /* then store all the new data */
|
*clist = *co; /* then store all the new data */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,6 +471,11 @@ void cookie_cleanup(struct CookieInfo *c)
|
|||||||
if(co->expirestr)
|
if(co->expirestr)
|
||||||
free(co->expirestr);
|
free(co->expirestr);
|
||||||
|
|
||||||
|
if(co->version)
|
||||||
|
free(co->version);
|
||||||
|
if(co->maxage)
|
||||||
|
free(co->maxage);
|
||||||
|
|
||||||
next = co->next;
|
next = co->next;
|
||||||
free(co);
|
free(co);
|
||||||
co = next;
|
co = next;
|
||||||
|
21
lib/cookie.h
21
lib/cookie.h
@ -11,14 +11,19 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
struct Cookie {
|
struct Cookie {
|
||||||
struct Cookie *next; /* next in the chain */
|
struct Cookie *next; /* next in the chain */
|
||||||
char *name; /* <this> = value */
|
char *name; /* <this> = value */
|
||||||
char *value; /* name = <this> */
|
char *value; /* name = <this> */
|
||||||
char *path; /* path = <this> */
|
char *path; /* path = <this> */
|
||||||
char *domain; /* domain = <this> */
|
char *domain; /* domain = <this> */
|
||||||
time_t expires; /* expires = <this> */
|
time_t expires; /* expires = <this> */
|
||||||
char *expirestr; /* the plain text version */
|
char *expirestr; /* the plain text version */
|
||||||
bool secure; /* whether the 'secure' keyword was used */
|
|
||||||
|
/* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */
|
||||||
|
char *version; /* Version = <value> */
|
||||||
|
char *maxage; /* Max-Age = <value> */
|
||||||
|
|
||||||
|
bool secure; /* whether the 'secure' keyword was used */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CookieInfo {
|
struct CookieInfo {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user