2002-09-03 13:52:59 +02:00
|
|
|
|
/***************************************************************************
|
2004-05-12 14:04:38 +02:00
|
|
|
|
* _ _ ____ _
|
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
|
* | (__| |_| | _ <| |___
|
2001-01-03 10:29:33 +01:00
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
|
*
|
2004-01-07 10:19:33 +01:00
|
|
|
|
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2001-01-03 10:29:33 +01:00
|
|
|
|
*
|
2002-09-03 13:52:59 +02:00
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
2004-05-12 14:04:38 +02:00
|
|
|
|
*
|
2001-01-03 10:29:33 +01:00
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
2002-09-03 13:52:59 +02:00
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
2001-01-03 10:29:33 +01:00
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
* $Id$
|
2002-09-03 13:52:59 +02:00
|
|
|
|
***************************************************************************/
|
1999-12-29 15:20:26 +01:00
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RECEIVING COOKIE INFORMATION
|
|
|
|
|
============================
|
|
|
|
|
|
|
|
|
|
struct CookieInfo *cookie_init(char *file);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
Inits a cookie struct to store data in a local file. This is always
|
|
|
|
|
called before any cookies are set.
|
|
|
|
|
|
|
|
|
|
int cookies_set(struct CookieInfo *cookie, char *cookie_line);
|
|
|
|
|
|
|
|
|
|
The 'cookie_line' parameter is a full "Set-cookie:" line as
|
|
|
|
|
received from a server.
|
|
|
|
|
|
|
|
|
|
The function need to replace previously stored lines that this new
|
|
|
|
|
line superceeds.
|
|
|
|
|
|
|
|
|
|
It may remove lines that are expired.
|
|
|
|
|
|
|
|
|
|
It should return an indication of success/error.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SENDING COOKIE INFORMATION
|
|
|
|
|
==========================
|
|
|
|
|
|
|
|
|
|
struct Cookies *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
|
|
|
|
|
boolean informs the cookie if a secure connection is achieved or
|
|
|
|
|
not.
|
|
|
|
|
|
|
|
|
|
It shall only return cookies that haven't expired.
|
|
|
|
|
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
Example set of cookies:
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
Set-cookie: PRODUCTINFO=webxpress; domain=.fidelity.com; path=/; secure
|
|
|
|
|
Set-cookie: PERSONALIZE=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
|
|
|
|
domain=.fidelity.com; path=/ftgw; secure
|
|
|
|
|
Set-cookie: FidHist=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
|
|
|
|
domain=.fidelity.com; path=/; secure
|
|
|
|
|
Set-cookie: FidOrder=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
|
|
|
|
domain=.fidelity.com; path=/; secure
|
|
|
|
|
Set-cookie: DisPend=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
|
|
|
|
domain=.fidelity.com; path=/; secure
|
|
|
|
|
Set-cookie: FidDis=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
|
|
|
|
domain=.fidelity.com; path=/; secure
|
|
|
|
|
Set-cookie:
|
|
|
|
|
Session_Key@6791a9e0-901a-11d0-a1c8-9b012c88aa77=none;expires=Monday,
|
|
|
|
|
13-Jun-1988 03:04:55 GMT; domain=.fidelity.com; path=/; secure
|
|
|
|
|
****/
|
|
|
|
|
|
2003-03-31 17:59:17 +02:00
|
|
|
|
|
2000-08-24 16:26:33 +02:00
|
|
|
|
#include "setup.h"
|
|
|
|
|
|
2002-06-11 13:13:01 +02:00
|
|
|
|
#ifndef CURL_DISABLE_HTTP
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
2003-08-11 11:55:11 +02:00
|
|
|
|
#include "urldata.h"
|
1999-12-29 15:20:26 +01:00
|
|
|
|
#include "cookie.h"
|
|
|
|
|
#include "getdate.h"
|
2000-05-22 16:12:12 +02:00
|
|
|
|
#include "strequal.h"
|
2001-05-30 13:06:56 +02:00
|
|
|
|
#include "strtok.h"
|
2003-08-11 11:55:11 +02:00
|
|
|
|
#include "sendf.h"
|
2004-05-11 13:30:23 +02:00
|
|
|
|
#include "memory.h"
|
1999-12-29 15:20:26 +01:00
|
|
|
|
|
2000-10-09 13:12:34 +02:00
|
|
|
|
/* The last #include file should be: */
|
2003-06-26 08:50:32 +02:00
|
|
|
|
#ifdef CURLDEBUG
|
2000-10-09 13:12:34 +02:00
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-05-12 14:04:38 +02:00
|
|
|
|
static void freecookie(struct Cookie *co)
|
2002-05-07 11:58:13 +02:00
|
|
|
|
{
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(co->expirestr)
|
|
|
|
|
free(co->expirestr);
|
2002-05-07 11:58:13 +02:00
|
|
|
|
if(co->domain)
|
|
|
|
|
free(co->domain);
|
|
|
|
|
if(co->path)
|
|
|
|
|
free(co->path);
|
|
|
|
|
if(co->name)
|
|
|
|
|
free(co->name);
|
|
|
|
|
if(co->value)
|
|
|
|
|
free(co->value);
|
|
|
|
|
|
|
|
|
|
free(co);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-30 19:03:43 +02:00
|
|
|
|
static bool tailmatch(const char *little, const char *bigone)
|
|
|
|
|
{
|
2004-02-26 14:40:43 +01:00
|
|
|
|
size_t littlelen = strlen(little);
|
|
|
|
|
size_t biglen = strlen(bigone);
|
2003-04-30 19:03:43 +02:00
|
|
|
|
|
|
|
|
|
if(littlelen > biglen)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2004-03-10 10:41:37 +01:00
|
|
|
|
return (bool)strequal(little, bigone+biglen-littlelen);
|
2003-04-30 19:03:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
*
|
2001-08-23 16:05:25 +02:00
|
|
|
|
* Curl_cookie_add()
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*
|
|
|
|
|
* Add a single cookie line to the cookie keeping object.
|
|
|
|
|
*
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
2001-01-05 11:11:41 +01:00
|
|
|
|
struct Cookie *
|
2003-08-11 11:55:11 +02:00
|
|
|
|
Curl_cookie_add(struct SessionHandle *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 */
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2003-08-11 11:55:11 +02:00
|
|
|
|
struct CookieInfo *c,
|
2001-01-05 11:11:41 +01:00
|
|
|
|
bool httpheader, /* TRUE if HTTP header-style line */
|
2002-07-30 00:22:49 +02:00
|
|
|
|
char *lineptr, /* first character of the line */
|
2003-04-30 19:03:43 +02:00
|
|
|
|
char *domain, /* default domain */
|
|
|
|
|
char *path) /* full path used when this cookie is set,
|
|
|
|
|
used to get default path for the cookie
|
|
|
|
|
unless set */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
{
|
|
|
|
|
struct Cookie *clist;
|
2004-06-22 23:15:51 +02:00
|
|
|
|
char *what;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
char name[MAX_NAME];
|
|
|
|
|
char *ptr;
|
|
|
|
|
char *semiptr;
|
|
|
|
|
struct Cookie *co;
|
2001-08-23 16:05:25 +02:00
|
|
|
|
struct Cookie *lastc=NULL;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
bool replace_old = FALSE;
|
2003-04-30 19:03:43 +02:00
|
|
|
|
bool badcookie = FALSE; /* cookies are good by default. mmmmm yummy */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
|
|
|
|
|
/* First, alloc and init a new struct for it */
|
2004-02-26 15:52:16 +01:00
|
|
|
|
co = (struct Cookie *)calloc(sizeof(struct Cookie), 1);
|
1999-12-29 15:20:26 +01:00
|
|
|
|
if(!co)
|
|
|
|
|
return NULL; /* bail out if we're this low on memory */
|
|
|
|
|
|
|
|
|
|
if(httpheader) {
|
|
|
|
|
/* This line was read off a HTTP-header */
|
2002-02-26 14:07:53 +01:00
|
|
|
|
char *sep;
|
2004-06-22 23:15:51 +02:00
|
|
|
|
|
|
|
|
|
what = malloc(MAX_COOKIE_LINE);
|
|
|
|
|
if(!what) {
|
|
|
|
|
free(co);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
semiptr=strchr(lineptr, ';'); /* first, find a semicolon */
|
2002-07-30 00:22:49 +02:00
|
|
|
|
|
|
|
|
|
while(*lineptr && isspace((int)*lineptr))
|
|
|
|
|
lineptr++;
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
ptr = lineptr;
|
2000-09-26 00:14:42 +02:00
|
|
|
|
do {
|
1999-12-29 15:20:26 +01:00
|
|
|
|
/* we have a <what>=<this> pair or a 'secure' word here */
|
2002-02-26 14:07:53 +01:00
|
|
|
|
sep = strchr(ptr, '=');
|
|
|
|
|
if(sep && (!semiptr || (semiptr>sep)) ) {
|
|
|
|
|
/*
|
|
|
|
|
* There is a = sign and if there was a semicolon too, which make sure
|
|
|
|
|
* that the semicolon comes _after_ the equal sign.
|
|
|
|
|
*/
|
|
|
|
|
|
2000-02-02 00:54:51 +01:00
|
|
|
|
name[0]=what[0]=0; /* init the buffers */
|
2002-02-26 14:07:53 +01:00
|
|
|
|
if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;=]=%"
|
2002-02-27 08:38:04 +01:00
|
|
|
|
MAX_COOKIE_LINE_TXT "[^;\r\n]",
|
1999-12-29 15:20:26 +01:00
|
|
|
|
name, what)) {
|
2002-02-27 08:38:04 +01:00
|
|
|
|
/* this is a <name>=<what> pair */
|
|
|
|
|
|
2002-04-14 20:21:17 +02:00
|
|
|
|
char *whatptr;
|
|
|
|
|
|
2002-02-27 08:38:04 +01:00
|
|
|
|
/* Strip off trailing whitespace from the 'what' */
|
2004-02-26 14:40:43 +01:00
|
|
|
|
size_t len=strlen(what);
|
2002-02-27 08:38:04 +01:00
|
|
|
|
while(len && isspace((int)what[len-1])) {
|
|
|
|
|
what[len-1]=0;
|
|
|
|
|
len--;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-14 20:21:17 +02:00
|
|
|
|
/* Skip leading whitespace from the 'what' */
|
|
|
|
|
whatptr=what;
|
|
|
|
|
while(isspace((int)*whatptr)) {
|
|
|
|
|
whatptr++;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
if(strequal("path", name)) {
|
2002-04-14 20:21:17 +02:00
|
|
|
|
co->path=strdup(whatptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->path) {
|
|
|
|
|
badcookie = TRUE; /* out of memory bad */
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
else if(strequal("domain", name)) {
|
2003-04-30 19:03:43 +02:00
|
|
|
|
/* note that this name may or may not have a preceeding dot, but
|
|
|
|
|
we don't care about that, we treat the names the same anyway */
|
|
|
|
|
|
2004-01-29 14:56:45 +01:00
|
|
|
|
const char *domptr=whatptr;
|
2003-04-30 19:03:43 +02:00
|
|
|
|
int dotcount=1;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
static const char *seventhree[]= {
|
|
|
|
|
"com", "edu", "net", "org", "gov", "mil", "int"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Count the dots, we need to make sure that there are THREE dots
|
|
|
|
|
in the normal domains, or TWO in the seventhree-domains. */
|
|
|
|
|
|
|
|
|
|
if('.' == whatptr[0])
|
|
|
|
|
/* don't count the initial dot, assume it */
|
2004-01-29 14:56:45 +01:00
|
|
|
|
domptr++;
|
2003-04-30 19:03:43 +02:00
|
|
|
|
|
|
|
|
|
do {
|
2004-01-29 14:56:45 +01:00
|
|
|
|
domptr = strchr(domptr, '.');
|
|
|
|
|
if(domptr) {
|
|
|
|
|
domptr++;
|
2003-04-30 19:03:43 +02:00
|
|
|
|
dotcount++;
|
|
|
|
|
}
|
2004-01-29 14:56:45 +01:00
|
|
|
|
} while(domptr);
|
2003-04-30 19:03:43 +02:00
|
|
|
|
|
|
|
|
|
for(i=0;
|
|
|
|
|
i<sizeof(seventhree)/sizeof(seventhree[0]); i++) {
|
|
|
|
|
if(tailmatch(seventhree[i], whatptr)) {
|
|
|
|
|
dotcount++; /* we allow one dot less for these */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-05 01:05:57 +02:00
|
|
|
|
/* The original Netscape cookie spec defined that this domain name
|
|
|
|
|
MUST have three dots (or two if one of the seven holy TLDs),
|
|
|
|
|
but it seems that these kinds of cookies are in use "out there"
|
|
|
|
|
so we cannot be that strict. I've therefore lowered the check
|
|
|
|
|
to not allow less than two dots. */
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2003-08-05 01:05:57 +02:00
|
|
|
|
if(dotcount < 2) {
|
2003-04-30 19:03:43 +02:00
|
|
|
|
/* Received and skipped a cookie with a domain using too few
|
|
|
|
|
dots. */
|
|
|
|
|
badcookie=TRUE; /* mark this as a bad cookie */
|
2003-08-11 11:55:11 +02:00
|
|
|
|
infof(data, "skipped cookie with illegal dotcount domain: %s",
|
|
|
|
|
whatptr);
|
2003-05-16 00:28:19 +02:00
|
|
|
|
}
|
2003-04-30 19:03:43 +02:00
|
|
|
|
else {
|
|
|
|
|
/* Now, we make sure that our host is within the given domain,
|
|
|
|
|
or the given domain is not valid and thus cannot be set. */
|
|
|
|
|
|
2004-05-21 22:40:15 +02:00
|
|
|
|
if('.' == whatptr[0])
|
|
|
|
|
whatptr++; /* ignore preceeding dot */
|
|
|
|
|
|
2003-04-30 19:03:43 +02:00
|
|
|
|
if(!domain || tailmatch(whatptr, domain)) {
|
2004-01-29 14:56:45 +01:00
|
|
|
|
const char *tailptr=whatptr;
|
|
|
|
|
if(tailptr[0] == '.')
|
|
|
|
|
tailptr++;
|
2004-05-12 14:04:38 +02:00
|
|
|
|
co->domain=strdup(tailptr); /* don't prefix w/dots
|
|
|
|
|
internally */
|
|
|
|
|
if(!co->domain) {
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-04-30 19:03:43 +02:00
|
|
|
|
co->tailmatch=TRUE; /* we always do that if the domain name was
|
|
|
|
|
given */
|
|
|
|
|
}
|
2003-05-16 00:28:19 +02:00
|
|
|
|
else {
|
2003-04-30 19:03:43 +02:00
|
|
|
|
/* 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;
|
2003-08-11 11:55:11 +02:00
|
|
|
|
infof(data, "skipped cookie with bad tailmatch domain: %s",
|
|
|
|
|
whatptr);
|
2003-05-16 00:28:19 +02:00
|
|
|
|
}
|
2003-04-30 19:03:43 +02:00
|
|
|
|
}
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
2000-02-02 00:54:51 +01:00
|
|
|
|
else if(strequal("version", name)) {
|
2002-04-14 20:21:17 +02:00
|
|
|
|
co->version=strdup(whatptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->version) {
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-02-02 00:54:51 +01:00
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
*/
|
2002-04-14 20:21:17 +02:00
|
|
|
|
co->maxage = strdup(whatptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->maxage) {
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-02-02 00:54:51 +01:00
|
|
|
|
co->expires =
|
2002-02-27 08:38:04 +01:00
|
|
|
|
atoi((*co->maxage=='\"')?&co->maxage[1]:&co->maxage[0]) + now;
|
2000-02-02 00:54:51 +01:00
|
|
|
|
}
|
1999-12-29 15:20:26 +01:00
|
|
|
|
else if(strequal("expires", name)) {
|
2002-04-14 20:21:17 +02:00
|
|
|
|
co->expirestr=strdup(whatptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->expirestr) {
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-05-22 16:12:12 +02:00
|
|
|
|
co->expires = curl_getdate(what, &now);
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
else if(!co->name) {
|
|
|
|
|
co->name = strdup(name);
|
2002-04-14 20:21:17 +02:00
|
|
|
|
co->value = strdup(whatptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->name || !co->value) {
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
2001-08-14 10:17:29 +02:00
|
|
|
|
/*
|
|
|
|
|
else this is the second (or more) name we don't know
|
|
|
|
|
about! */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* this is an "illegal" <what>=<this> pair */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2001-08-23 16:05:25 +02:00
|
|
|
|
if(sscanf(ptr, "%" MAX_COOKIE_LINE_TXT "[^;\r\n]",
|
1999-12-29 15:20:26 +01:00
|
|
|
|
what)) {
|
|
|
|
|
if(strequal("secure", what))
|
|
|
|
|
co->secure = TRUE;
|
2001-08-14 10:17:29 +02:00
|
|
|
|
/* else,
|
|
|
|
|
unsupported keyword without assign! */
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-26 14:07:53 +01:00
|
|
|
|
if(!semiptr || !*semiptr) {
|
|
|
|
|
/* we already know there are no more cookies */
|
|
|
|
|
semiptr = NULL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2000-09-26 00:14:42 +02:00
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
ptr=semiptr+1;
|
|
|
|
|
while(ptr && *ptr && isspace((int)*ptr))
|
|
|
|
|
ptr++;
|
|
|
|
|
semiptr=strchr(ptr, ';'); /* now, find the next semicolon */
|
2002-01-08 00:05:36 +01:00
|
|
|
|
|
|
|
|
|
if(!semiptr && *ptr)
|
|
|
|
|
/* There are no more semicolons, but there's a final name=value pair
|
|
|
|
|
coming up */
|
2002-02-26 14:07:53 +01:00
|
|
|
|
semiptr=strchr(ptr, '\0');
|
2000-09-26 00:14:42 +02:00
|
|
|
|
} while(semiptr);
|
2001-09-26 09:08:29 +02:00
|
|
|
|
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!badcookie && !co->domain) {
|
|
|
|
|
if(domain) {
|
|
|
|
|
/* no domain was given in the header line, set the default */
|
|
|
|
|
co->domain=strdup(domain);
|
|
|
|
|
if(!co->domain)
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
}
|
2002-02-26 14:07:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!badcookie && !co->path && path) {
|
|
|
|
|
/* no path was given in the header line, set the default */
|
2003-04-30 19:03:43 +02:00
|
|
|
|
char *endslash = strrchr(path, '/');
|
|
|
|
|
if(endslash) {
|
2004-02-26 14:40:43 +01:00
|
|
|
|
size_t pathlen = endslash-path+1; /* include the ending slash */
|
2003-04-30 19:03:43 +02:00
|
|
|
|
co->path=malloc(pathlen+1); /* one extra for the zero byte */
|
|
|
|
|
if(co->path) {
|
|
|
|
|
memcpy(co->path, path, pathlen);
|
|
|
|
|
co->path[pathlen]=0; /* zero terminate */
|
|
|
|
|
}
|
2004-05-12 14:04:38 +02:00
|
|
|
|
else
|
|
|
|
|
badcookie = TRUE;
|
2003-04-30 19:03:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2004-06-22 23:15:51 +02:00
|
|
|
|
free(what);
|
|
|
|
|
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(badcookie || !co->name) {
|
|
|
|
|
/* we didn't get a cookie name or a bad one,
|
|
|
|
|
this is an illegal line, bail out */
|
|
|
|
|
freecookie(co);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* This line is NOT a HTTP header style line, we do offer support for
|
|
|
|
|
reading the odd netscape cookies-file format here */
|
|
|
|
|
char *firstptr;
|
2001-05-29 21:17:39 +02:00
|
|
|
|
char *tok_buf;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
int fields;
|
|
|
|
|
|
|
|
|
|
if(lineptr[0]=='#') {
|
|
|
|
|
/* don't even try the comments */
|
|
|
|
|
free(co);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* strip off the possible end-of-line characters */
|
2000-05-22 16:12:12 +02:00
|
|
|
|
ptr=strchr(lineptr, '\r');
|
|
|
|
|
if(ptr)
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*ptr=0; /* clear it */
|
2000-05-22 16:12:12 +02:00
|
|
|
|
ptr=strchr(lineptr, '\n');
|
|
|
|
|
if(ptr)
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*ptr=0; /* clear it */
|
|
|
|
|
|
2004-05-12 14:04:38 +02:00
|
|
|
|
firstptr=strtok_r(lineptr, "\t", &tok_buf); /* tokenize it on the TAB */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
|
|
|
|
|
/* Here's a quick check to eliminate normal HTTP-headers from this */
|
|
|
|
|
if(!firstptr || strchr(firstptr, ':')) {
|
|
|
|
|
free(co);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now loop through the fields and init the struct we already have
|
|
|
|
|
allocated */
|
2004-05-12 14:04:38 +02:00
|
|
|
|
for(ptr=firstptr, fields=0; ptr && !badcookie;
|
2003-04-30 19:03:43 +02:00
|
|
|
|
ptr=strtok_r(NULL, "\t", &tok_buf), fields++) {
|
1999-12-29 15:20:26 +01:00
|
|
|
|
switch(fields) {
|
|
|
|
|
case 0:
|
2003-05-16 00:28:19 +02:00
|
|
|
|
if(ptr[0]=='.') /* skip preceeding dots */
|
|
|
|
|
ptr++;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
co->domain = strdup(ptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->domain)
|
|
|
|
|
badcookie = TRUE;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2001-05-23 15:04:19 +02:00
|
|
|
|
/* This field got its explanation on the 23rd of May 2001 by
|
|
|
|
|
Andr<EFBFBD>s Garc<EFBFBD>a:
|
|
|
|
|
|
|
|
|
|
flag: A TRUE/FALSE value indicating if all machines within a given
|
|
|
|
|
domain can access the variable. This value is set automatically by
|
|
|
|
|
the browser, depending on the value you set for the domain.
|
|
|
|
|
|
|
|
|
|
As far as I can see, it is set to true when the cookie says
|
|
|
|
|
.domain.com and to false when the domain is complete www.domain.com
|
|
|
|
|
*/
|
2004-03-10 10:41:37 +01:00
|
|
|
|
co->tailmatch=(bool)strequal(ptr, "TRUE"); /* store information */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2001-05-23 11:26:45 +02:00
|
|
|
|
/* It turns out, that sometimes the file format allows the path
|
|
|
|
|
field to remain not filled in, we try to detect this and work
|
|
|
|
|
around it! Andr<EFBFBD>s Garc<EFBFBD>a made us aware of this... */
|
|
|
|
|
if (strcmp("TRUE", ptr) && strcmp("FALSE", ptr)) {
|
|
|
|
|
/* only if the path doesn't look like a boolean option! */
|
|
|
|
|
co->path = strdup(ptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->path)
|
|
|
|
|
badcookie = TRUE;
|
2001-05-23 11:26:45 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* this doesn't look like a path, make one up! */
|
|
|
|
|
co->path = strdup("/");
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->path)
|
|
|
|
|
badcookie = TRUE;
|
2001-05-23 11:26:45 +02:00
|
|
|
|
fields++; /* add a field and fall down to secure */
|
|
|
|
|
/* FALLTHROUGH */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
case 3:
|
2004-03-10 10:41:37 +01:00
|
|
|
|
co->secure = (bool)strequal(ptr, "TRUE");
|
1999-12-29 15:20:26 +01:00
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
co->expires = atoi(ptr);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
co->name = strdup(ptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->name)
|
|
|
|
|
badcookie = TRUE;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
co->value = strdup(ptr);
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->value)
|
|
|
|
|
badcookie = TRUE;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-11 11:55:11 +02:00
|
|
|
|
if(6 == fields) {
|
|
|
|
|
/* we got a cookie with blank contents, fix it */
|
|
|
|
|
co->value = strdup("");
|
2004-05-12 14:04:38 +02:00
|
|
|
|
if(!co->value)
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
else
|
|
|
|
|
fields++;
|
2003-08-11 11:55:11 +02:00
|
|
|
|
}
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
|
|
|
|
if(!badcookie && (7 != fields))
|
|
|
|
|
/* we did not find the sufficient number of fields */
|
|
|
|
|
badcookie = TRUE;
|
|
|
|
|
|
|
|
|
|
if(badcookie) {
|
|
|
|
|
freecookie(co);
|
1999-12-29 15:20:26 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-07 11:58:13 +02:00
|
|
|
|
if(!c->running && /* read from a file */
|
|
|
|
|
c->newsession && /* clean session cookies */
|
|
|
|
|
!co->expires) { /* this is a session cookie since it doesn't expire! */
|
2004-05-12 14:04:38 +02:00
|
|
|
|
freecookie(co);
|
2002-05-07 11:58:13 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-23 16:05:25 +02:00
|
|
|
|
co->livecookie = c->running;
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
/* now, we have parsed the incoming line, we must now check if this
|
|
|
|
|
superceeds an already existing cookie, which it may if the previous have
|
|
|
|
|
the same domain and path as this */
|
|
|
|
|
|
|
|
|
|
clist = c->cookies;
|
|
|
|
|
replace_old = FALSE;
|
|
|
|
|
while(clist) {
|
|
|
|
|
if(strequal(clist->name, co->name)) {
|
|
|
|
|
/* the names are identical */
|
|
|
|
|
|
|
|
|
|
if(clist->domain && co->domain) {
|
2003-05-16 00:28:19 +02:00
|
|
|
|
if(strequal(clist->domain, co->domain))
|
|
|
|
|
/* The domains are identical */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
replace_old=TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if(!clist->domain && !co->domain)
|
|
|
|
|
replace_old = TRUE;
|
|
|
|
|
|
|
|
|
|
if(replace_old) {
|
|
|
|
|
/* the domains were identical */
|
|
|
|
|
|
|
|
|
|
if(clist->path && co->path) {
|
|
|
|
|
if(strequal(clist->path, co->path)) {
|
|
|
|
|
replace_old = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
replace_old = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else if(!clist->path && !co->path)
|
|
|
|
|
replace_old = TRUE;
|
|
|
|
|
else
|
|
|
|
|
replace_old = FALSE;
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-23 16:05:25 +02:00
|
|
|
|
if(replace_old && !co->livecookie && clist->livecookie) {
|
|
|
|
|
/* Both cookies matched fine, except that the already present
|
|
|
|
|
cookie is "live", which means it was set from a header, while
|
|
|
|
|
the new one isn't "live" and thus only read from a file. We let
|
|
|
|
|
live cookies stay alive */
|
|
|
|
|
|
|
|
|
|
/* Free the newcomer and get out of here! */
|
2004-05-12 14:04:38 +02:00
|
|
|
|
freecookie(co);
|
2001-08-23 16:05:25 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
if(replace_old) {
|
|
|
|
|
co->next = clist->next; /* get the next-pointer first */
|
|
|
|
|
|
|
|
|
|
/* then free all the old pointers */
|
|
|
|
|
if(clist->name)
|
|
|
|
|
free(clist->name);
|
|
|
|
|
if(clist->value)
|
|
|
|
|
free(clist->value);
|
|
|
|
|
if(clist->domain)
|
|
|
|
|
free(clist->domain);
|
|
|
|
|
if(clist->path)
|
|
|
|
|
free(clist->path);
|
|
|
|
|
if(clist->expirestr)
|
|
|
|
|
free(clist->expirestr);
|
|
|
|
|
|
2000-02-02 00:54:51 +01:00
|
|
|
|
if(clist->version)
|
|
|
|
|
free(clist->version);
|
|
|
|
|
if(clist->maxage)
|
|
|
|
|
free(clist->maxage);
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*clist = *co; /* then store all the new data */
|
2001-10-24 13:36:55 +02:00
|
|
|
|
|
|
|
|
|
free(co); /* free the newly alloced memory */
|
|
|
|
|
co = clist; /* point to the previous struct instead */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
|
2002-01-07 15:56:15 +01:00
|
|
|
|
/* We have replaced a cookie, now skip the rest of the list but
|
|
|
|
|
make sure the 'lastc' pointer is properly set */
|
|
|
|
|
do {
|
|
|
|
|
lastc = clist;
|
|
|
|
|
clist = clist->next;
|
|
|
|
|
} while(clist);
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
2001-08-23 16:05:25 +02:00
|
|
|
|
lastc = clist;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
clist = clist->next;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 11:55:11 +02:00
|
|
|
|
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 %d\n",
|
|
|
|
|
replace_old?"Replaced":"Added", co->name, co->value,
|
|
|
|
|
co->domain, co->path, co->expires);
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
if(!replace_old) {
|
2001-08-23 16:05:25 +02:00
|
|
|
|
/* then make the last item point on this new one */
|
|
|
|
|
if(lastc)
|
|
|
|
|
lastc->next = co;
|
|
|
|
|
else
|
|
|
|
|
c->cookies = co;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
2001-08-23 16:05:25 +02:00
|
|
|
|
|
2001-08-29 11:32:18 +02:00
|
|
|
|
c->numcookies++; /* one more cookie in the jar */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
return co;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
2001-08-23 16:05:25 +02:00
|
|
|
|
* Curl_cookie_init()
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*
|
|
|
|
|
* Inits a cookie struct to read data from a local file. This is always
|
|
|
|
|
* called before any cookies are set. File may be NULL.
|
|
|
|
|
*
|
2002-05-07 11:58:13 +02:00
|
|
|
|
* If 'newsession' is TRUE, discard all "session cookies" on read from file.
|
|
|
|
|
*
|
1999-12-29 15:20:26 +01:00
|
|
|
|
****************************************************************************/
|
2003-08-11 11:55:11 +02:00
|
|
|
|
struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
|
|
|
|
|
char *file,
|
2002-05-07 11:58:13 +02:00
|
|
|
|
struct CookieInfo *inc,
|
|
|
|
|
bool newsession)
|
1999-12-29 15:20:26 +01:00
|
|
|
|
{
|
|
|
|
|
char line[MAX_COOKIE_LINE];
|
|
|
|
|
struct CookieInfo *c;
|
|
|
|
|
FILE *fp;
|
2000-02-11 00:14:53 +01:00
|
|
|
|
bool fromfile=TRUE;
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2001-08-23 16:05:25 +02:00
|
|
|
|
if(NULL == inc) {
|
|
|
|
|
/* we didn't get a struct, create one */
|
|
|
|
|
c = (struct CookieInfo *)malloc(sizeof(struct CookieInfo));
|
|
|
|
|
if(!c)
|
|
|
|
|
return NULL; /* failed to get memory */
|
|
|
|
|
memset(c, 0, sizeof(struct CookieInfo));
|
|
|
|
|
c->filename = strdup(file?file:"none"); /* copy the name just in case */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* we got an already existing one, use that */
|
|
|
|
|
c = inc;
|
|
|
|
|
}
|
|
|
|
|
c->running = FALSE; /* this is not running, this is init */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
|
2001-10-10 14:48:32 +02:00
|
|
|
|
if(file && strequal(file, "-")) {
|
2000-02-11 00:14:53 +01:00
|
|
|
|
fp = stdin;
|
|
|
|
|
fromfile=FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
fp = file?fopen(file, "r"):NULL;
|
|
|
|
|
|
2002-05-07 11:58:13 +02:00
|
|
|
|
c->newsession = newsession; /* new session? */
|
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
if(fp) {
|
2001-08-23 16:05:25 +02:00
|
|
|
|
char *lineptr;
|
|
|
|
|
bool headerline;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
while(fgets(line, MAX_COOKIE_LINE, fp)) {
|
2002-10-28 22:52:00 +01:00
|
|
|
|
if(checkprefix("Set-Cookie:", line)) {
|
1999-12-29 15:20:26 +01:00
|
|
|
|
/* This is a cookie line, get it! */
|
2001-08-23 16:05:25 +02:00
|
|
|
|
lineptr=&line[11];
|
|
|
|
|
headerline=TRUE;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2001-08-23 16:05:25 +02:00
|
|
|
|
lineptr=line;
|
|
|
|
|
headerline=FALSE;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
2001-08-23 16:05:25 +02:00
|
|
|
|
while(*lineptr && isspace((int)*lineptr))
|
|
|
|
|
lineptr++;
|
|
|
|
|
|
2003-08-11 11:55:11 +02:00
|
|
|
|
Curl_cookie_add(data, c, headerline, lineptr, NULL, NULL);
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
2000-02-11 00:14:53 +01:00
|
|
|
|
if(fromfile)
|
|
|
|
|
fclose(fp);
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-07 11:58:13 +02:00
|
|
|
|
c->running = TRUE; /* now, we're running */
|
2001-08-23 16:05:25 +02:00
|
|
|
|
|
1999-12-29 15:20:26 +01:00
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
2001-08-23 16:05:25 +02:00
|
|
|
|
* Curl_cookie_getlist()
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*
|
|
|
|
|
* 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 boolean informs
|
|
|
|
|
* the cookie if a secure connection is achieved or not.
|
|
|
|
|
*
|
|
|
|
|
* It shall only return cookies that haven't expired.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2001-01-05 11:11:41 +01:00
|
|
|
|
struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
|
|
|
|
|
char *host, char *path, bool secure)
|
1999-12-29 15:20:26 +01:00
|
|
|
|
{
|
|
|
|
|
struct Cookie *newco;
|
|
|
|
|
struct Cookie *co;
|
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
struct Cookie *mainco=NULL;
|
|
|
|
|
|
|
|
|
|
if(!c || !c->cookies)
|
|
|
|
|
return NULL; /* no cookie struct or no cookies in the struct */
|
|
|
|
|
|
|
|
|
|
co = c->cookies;
|
|
|
|
|
|
|
|
|
|
while(co) {
|
2003-04-30 19:03:43 +02:00
|
|
|
|
/* only process this cookie if it is not expired or had no expire
|
|
|
|
|
date AND that if the cookie requires we're secure we must only
|
|
|
|
|
continue if we are! */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
if( (co->expires<=0 || (co->expires> now)) &&
|
|
|
|
|
(co->secure?secure:TRUE) ) {
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2003-04-30 19:03:43 +02:00
|
|
|
|
/* now check if the domain is correct */
|
|
|
|
|
if(!co->domain ||
|
|
|
|
|
(co->tailmatch && tailmatch(co->domain, host)) ||
|
|
|
|
|
(!co->tailmatch && strequal(host, co->domain)) ) {
|
|
|
|
|
/* the right part of the host matches the domain stuff in the
|
|
|
|
|
cookie data */
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2003-04-30 19:03:43 +02:00
|
|
|
|
/* now check the left part of the path with the cookies path
|
|
|
|
|
requirement */
|
|
|
|
|
if(!co->path ||
|
|
|
|
|
checkprefix(co->path, path) ) {
|
|
|
|
|
|
|
|
|
|
/* and now, we know this is a match and we should create an
|
|
|
|
|
entry for the return-linked-list */
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2003-04-30 19:03:43 +02:00
|
|
|
|
newco = (struct Cookie *)malloc(sizeof(struct Cookie));
|
|
|
|
|
if(newco) {
|
|
|
|
|
/* first, copy the whole source cookie: */
|
|
|
|
|
memcpy(newco, co, sizeof(struct Cookie));
|
|
|
|
|
|
|
|
|
|
/* then modify our next */
|
|
|
|
|
newco->next = mainco;
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2003-04-30 19:03:43 +02:00
|
|
|
|
/* point the main to us */
|
|
|
|
|
mainco = newco;
|
|
|
|
|
}
|
2004-05-10 16:04:06 +02:00
|
|
|
|
else {
|
|
|
|
|
/* failure, clear up the allocated chain and return NULL */
|
|
|
|
|
while(mainco) {
|
|
|
|
|
co = mainco->next;
|
|
|
|
|
free(mainco);
|
|
|
|
|
mainco = co;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2003-04-30 19:03:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
co = co->next;
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mainco; /* return the new list */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
2001-08-23 16:05:25 +02:00
|
|
|
|
* Curl_cookie_freelist()
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*
|
2001-08-23 16:05:25 +02:00
|
|
|
|
* Free a list of cookies previously returned by Curl_cookie_getlist();
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2001-01-05 11:11:41 +01:00
|
|
|
|
void Curl_cookie_freelist(struct Cookie *co)
|
1999-12-29 15:20:26 +01:00
|
|
|
|
{
|
|
|
|
|
struct Cookie *next;
|
|
|
|
|
if(co) {
|
|
|
|
|
while(co) {
|
|
|
|
|
next = co->next;
|
|
|
|
|
free(co); /* we only free the struct since the "members" are all
|
|
|
|
|
just copied! */
|
|
|
|
|
co = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
2001-08-23 16:05:25 +02:00
|
|
|
|
* Curl_cookie_cleanup()
|
1999-12-29 15:20:26 +01:00
|
|
|
|
*
|
|
|
|
|
* Free a "cookie object" previous created with cookie_init().
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
2001-01-05 11:11:41 +01:00
|
|
|
|
void Curl_cookie_cleanup(struct CookieInfo *c)
|
1999-12-29 15:20:26 +01:00
|
|
|
|
{
|
|
|
|
|
struct Cookie *co;
|
|
|
|
|
struct Cookie *next;
|
|
|
|
|
if(c) {
|
|
|
|
|
if(c->filename)
|
|
|
|
|
free(c->filename);
|
|
|
|
|
co = c->cookies;
|
|
|
|
|
|
|
|
|
|
while(co) {
|
|
|
|
|
next = co->next;
|
2004-05-12 14:04:38 +02:00
|
|
|
|
freecookie(co);
|
1999-12-29 15:20:26 +01:00
|
|
|
|
co = next;
|
|
|
|
|
}
|
2000-10-09 13:12:34 +02:00
|
|
|
|
free(c); /* free the base struct as well */
|
1999-12-29 15:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-23 16:05:25 +02:00
|
|
|
|
/*
|
2001-08-29 11:32:18 +02:00
|
|
|
|
* Curl_cookie_output()
|
2001-08-23 16:05:25 +02:00
|
|
|
|
*
|
2001-08-29 11:32:18 +02:00
|
|
|
|
* Writes all internally known cookies to the specified file. Specify
|
|
|
|
|
* "-" as file name to write to stdout.
|
2001-08-23 16:05:25 +02:00
|
|
|
|
*
|
2001-08-29 11:32:18 +02:00
|
|
|
|
* The function returns non-zero on write failure.
|
2001-08-23 16:05:25 +02:00
|
|
|
|
*/
|
2001-08-29 11:32:18 +02:00
|
|
|
|
int Curl_cookie_output(struct CookieInfo *c, char *dumphere)
|
2001-08-23 16:05:25 +02:00
|
|
|
|
{
|
|
|
|
|
struct Cookie *co;
|
2001-08-29 11:32:18 +02:00
|
|
|
|
FILE *out;
|
|
|
|
|
bool use_stdout=FALSE;
|
|
|
|
|
|
2001-09-10 09:43:08 +02:00
|
|
|
|
if((NULL == c) || (0 == c->numcookies))
|
2001-08-29 11:32:18 +02:00
|
|
|
|
/* If there are no known cookies, we don't write or even create any
|
|
|
|
|
destination file */
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if(strequal("-", dumphere)) {
|
|
|
|
|
/* use stdout */
|
|
|
|
|
out = stdout;
|
|
|
|
|
use_stdout=TRUE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
out = fopen(dumphere, "w");
|
|
|
|
|
if(!out)
|
|
|
|
|
return 1; /* failure */
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-23 16:05:25 +02:00
|
|
|
|
if(c) {
|
2001-08-29 11:32:18 +02:00
|
|
|
|
fputs("# Netscape HTTP Cookie File\n"
|
|
|
|
|
"# http://www.netscape.com/newsref/std/cookie_spec.html\n"
|
2001-10-08 08:43:22 +02:00
|
|
|
|
"# This file was generated by libcurl! Edit at your own risk.\n\n",
|
2001-08-29 11:32:18 +02:00
|
|
|
|
out);
|
2001-08-23 16:05:25 +02:00
|
|
|
|
co = c->cookies;
|
2004-05-12 14:04:38 +02:00
|
|
|
|
|
2001-08-23 16:05:25 +02:00
|
|
|
|
while(co) {
|
2001-08-29 11:32:18 +02:00
|
|
|
|
fprintf(out,
|
2003-04-30 19:03:43 +02:00
|
|
|
|
"%s%s\t" /* domain */
|
|
|
|
|
"%s\t" /* tailmatch */
|
2001-08-29 11:32:18 +02:00
|
|
|
|
"%s\t" /* path */
|
|
|
|
|
"%s\t" /* secure */
|
|
|
|
|
"%u\t" /* expires */
|
|
|
|
|
"%s\t" /* name */
|
|
|
|
|
"%s\n", /* value */
|
2003-04-30 19:03:43 +02:00
|
|
|
|
|
|
|
|
|
/* Make sure all domains are prefixed with a dot if they allow
|
|
|
|
|
tailmatching. This is Mozilla-style. */
|
|
|
|
|
(co->tailmatch && co->domain && co->domain[0] != '.')? ".":"",
|
2001-09-26 09:08:29 +02:00
|
|
|
|
co->domain?co->domain:"unknown",
|
2003-04-30 19:03:43 +02:00
|
|
|
|
co->tailmatch?"TRUE":"FALSE",
|
2001-09-26 09:08:29 +02:00
|
|
|
|
co->path?co->path:"/",
|
2001-08-29 11:32:18 +02:00
|
|
|
|
co->secure?"TRUE":"FALSE",
|
|
|
|
|
(unsigned int)co->expires,
|
|
|
|
|
co->name,
|
2001-09-26 09:08:29 +02:00
|
|
|
|
co->value?co->value:"");
|
2001-08-23 16:05:25 +02:00
|
|
|
|
|
|
|
|
|
co=co->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-08-29 11:32:18 +02:00
|
|
|
|
|
|
|
|
|
if(!use_stdout)
|
|
|
|
|
fclose(out);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2001-08-23 16:05:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-11 13:13:01 +02:00
|
|
|
|
#endif /* CURL_DISABLE_HTTP */
|