733
733
struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
734
734
char *host, char *path, bool secure)
736
struct Cookie *newco;
738
time_t now = time(NULL);
739
struct Cookie *mainco=NULL;
741
if(!c || !c->cookies)
742
return NULL; /* no cookie struct or no cookies in the struct */
747
/* only process this cookie if it is not expired or had no expire
748
date AND that if the cookie requires we're secure we must only
749
continue if we are! */
750
if( (co->expires<=0 || (co->expires> now)) &&
751
(co->secure?secure:TRUE) ) {
753
/* now check if the domain is correct */
755
(co->tailmatch && tailmatch(co->domain, host)) ||
756
(!co->tailmatch && strequal(host, co->domain)) ) {
757
/* the right part of the host matches the domain stuff in the
760
/* now check the left part of the path with the cookies path
763
checkprefix(co->path, path) ) {
765
/* and now, we know this is a match and we should create an
766
entry for the return-linked-list */
768
newco = (struct Cookie *)malloc(sizeof(struct Cookie));
770
/* first, copy the whole source cookie: */
771
memcpy(newco, co, sizeof(struct Cookie));
773
/* then modify our next */
774
newco->next = mainco;
776
/* point the main to us */
780
/* failure, clear up the allocated chain and return NULL */
795
return mainco; /* return the new list */
736
struct Cookie *newco;
738
time_t now = time(NULL);
739
struct Cookie *mainco=NULL;
741
if(!c || !c->cookies)
742
return NULL; /* no cookie struct or no cookies in the struct */
747
/* only process this cookie if it is not expired or had no expire
748
date AND that if the cookie requires we're secure we must only
749
continue if we are! */
750
if( (co->expires<=0 || (co->expires> now)) &&
751
(co->secure?secure:TRUE) ) {
753
/* now check if the domain is correct */
755
(co->tailmatch && tailmatch(co->domain, host)) ||
756
(!co->tailmatch && strequal(host, co->domain)) ) {
757
/* the right part of the host matches the domain stuff in the
760
/* now check the left part of the path with the cookies path
763
checkprefix(co->path, path) ) {
765
/* and now, we know this is a match and we should create an
766
entry for the return-linked-list */
768
newco = (struct Cookie *)malloc(sizeof(struct Cookie));
770
/* first, copy the whole source cookie: */
771
memcpy(newco, co, sizeof(struct Cookie));
773
/* then modify our next */
774
newco->next = mainco;
776
/* point the main to us */
780
/* failure, clear up the allocated chain and return NULL */
795
return mainco; /* return the new list */
798
/*****************************************************************************
800
* Curl_cookie_clearall()
802
* Clear all existing cookies and reset the counter.
804
****************************************************************************/
805
void Curl_cookie_clearall(struct CookieInfo *cookies)
807
Curl_cookie_freelist(cookies->cookies);
808
cookies->cookies = NULL;
809
cookies->numcookies = 0;
799
812
/*****************************************************************************
807
820
void Curl_cookie_freelist(struct Cookie *co)
813
free(co); /* we only free the struct since the "members" are all
826
free(co); /* we only free the struct since the "members" are all
834
/*****************************************************************************
836
* Curl_cookie_clearsess()
838
* Free all session cookies in the cookies list.
840
****************************************************************************/
841
void Curl_cookie_clearsess(struct CookieInfo *cookies)
843
struct Cookie *first, *curr, *next, *prev = NULL;
845
if(!cookies->cookies)
848
first = curr = prev = cookies->cookies;
850
for(; curr; curr = next) {
862
cookies->numcookies--;
868
cookies->cookies = first;
820
872
/*****************************************************************************
851
903
static char *get_netscape_format(const struct Cookie *co)
854
"%s%s\t" /* domain */
855
"%s\t" /* tailmatch */
858
"%" FORMAT_OFF_T "\t" /* expires */
861
/* Make sure all domains are prefixed with a dot if they allow
862
tailmatching. This is Mozilla-style. */
863
(co->tailmatch && co->domain && co->domain[0] != '.')? ".":"",
864
co->domain?co->domain:"unknown",
865
co->tailmatch?"TRUE":"FALSE",
866
co->path?co->path:"/",
867
co->secure?"TRUE":"FALSE",
870
co->value?co->value:"");
906
"%s%s\t" /* domain */
907
"%s\t" /* tailmatch */
910
"%" FORMAT_OFF_T "\t" /* expires */
913
/* Make sure all domains are prefixed with a dot if they allow
914
tailmatching. This is Mozilla-style. */
915
(co->tailmatch && co->domain && co->domain[0] != '.')? ".":"",
916
co->domain?co->domain:"unknown",
917
co->tailmatch?"TRUE":"FALSE",
918
co->path?co->path:"/",
919
co->secure?"TRUE":"FALSE",
922
co->value?co->value:"");