85 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) 122 size_t cookie_domain_len = strlen(cooke_domain);
123 size_t hostname_len = strlen(hostname);
125 if(hostname_len < cookie_domain_len)
128 if(!
strcasecompare(cooke_domain, hostname + hostname_len-cookie_domain_len))
138 if(hostname_len == cookie_domain_len)
140 if(
'.' == *(hostname + hostname_len - cookie_domain_len - 1))
149 static bool pathmatch(
const char *cookie_path,
const char *request_uri)
151 size_t cookie_path_len;
153 char *uri_path = NULL;
158 cookie_path_len = strlen(cookie_path);
159 if(1 == cookie_path_len) {
164 uri_path =
strdup(request_uri);
167 pos = strchr(uri_path,
'?');
172 if(0 == strlen(uri_path) || uri_path[0] !=
'/') {
188 uri_path_len = strlen(uri_path);
190 if(uri_path_len < cookie_path_len) {
196 if(strncmp(cookie_path, uri_path, cookie_path_len)) {
202 if(cookie_path_len == uri_path_len) {
208 if(uri_path[cookie_path_len] ==
'/') {
226 char *new_path =
strdup(cookie_path);
231 len = strlen(new_path);
232 if(new_path[0] ==
'\"') {
233 memmove((
void *)new_path, (
const void *)(new_path + 1), len);
236 if(len && (new_path[len - 1] ==
'\"')) {
237 new_path[len - 1] = 0x0;
242 if(new_path[0] !=
'/') {
250 if(len && new_path[len - 1] ==
'/') {
251 new_path[len - 1] = 0x0;
276 infof(data,
"ignoring failed cookie_init for %s\n", list->
data);
304 struct Cookie *co, *nx, *pv;
335 struct in6_addr addr6;
379 struct Cookie *lastc = NULL;
380 time_t
now = time(NULL);
381 bool replace_old =
FALSE;
382 bool badcookie =
FALSE;
385 const psl_ctx_t *psl;
388 #ifdef CURL_DISABLE_VERBOSE_STRINGS 404 size_t linelength = strlen(lineptr);
411 semiptr = strchr(lineptr,
';');
413 while(*lineptr &&
ISBLANK(*lineptr))
419 name[0] = what[0] = 0;
429 size_t len = strlen(what);
430 size_t nlen = strlen(name);
431 const char *endofn = &ptr[ nlen ];
433 infof(data,
"cookie size: name/val %d + %d bytes\n",
442 infof(data,
"oversized cookie dropped, name/val %d + %d bytes\n",
454 while(*endofn &&
ISBLANK(*endofn) && nlen) {
463 while(len &&
ISBLANK(what[len-1])) {
470 while(*whatptr &&
ISBLANK(*whatptr))
473 if(!co->
name && sep) {
515 if(
'.' == whatptr[0])
527 dotp = strchr(whatptr,
'.');
533 is_ip =
isip(domain ? domain : whatptr);
536 || (is_ip && !strcmp(whatptr, domain))
537 || (!is_ip &&
tailmatch(whatptr, domain))) {
552 infof(data,
"skipped cookie with bad tailmatch domain: %s\n",
594 if(!semiptr || !*semiptr) {
603 semiptr = strchr(ptr,
';');
608 semiptr = strchr(ptr,
'\0');
641 if(!badcookie && !co->
domain) {
650 if(!badcookie && !co->
path && path) {
654 char *queryp = strchr(path,
'?');
660 endslash = strrchr(path,
'/');
662 endslash =
memrchr(path,
'/', (
size_t)(queryp - path));
664 size_t pathlen = (
size_t)(endslash-path + 1);
668 co->
path[pathlen] = 0;
678 if(badcookie || !co->
name) {
691 char *tok_buf = NULL;
701 if(strncmp(lineptr,
"#HttpOnly_", 10) == 0) {
706 if(lineptr[0]==
'#') {
712 ptr = strchr(lineptr,
'\r');
715 ptr = strchr(lineptr,
'\n');
719 firstptr =
strtok_r(lineptr,
"\t", &tok_buf);
723 for(ptr = firstptr, fields = 0; ptr && !badcookie;
724 ptr =
strtok_r(NULL,
"\t", &tok_buf), fields++) {
750 if(strcmp(
"TRUE", ptr) && strcmp(
"FALSE", ptr)) {
800 if(!badcookie && (7 != fields))
832 if(psl && !psl_is_cookie_domain_acceptable(psl, domain, co->
domain)) {
834 "cookie '%s' dropped, domain '%s' must not set cookies for '%s'\n",
918 infof(data,
"%s cookie %s=\"%s\" for domain %s, path %s, " 920 replace_old?
"Replaced":
"Added", co->
name, co->
value,
941 bool partial =
FALSE;
943 char *b = fgets(buf, len, input);
945 size_t rlen = strlen(b);
946 if(rlen && (b[rlen-1] ==
'\n')) {
981 bool fromfile =
TRUE;
999 if(file && !strcmp(file,
"-")) {
1003 else if(file && !*file) {
1022 lineptr = &line[11];
1029 while(*lineptr &&
ISBLANK(*lineptr))
1063 l1 = c1->
path ? strlen(c1->
path) : 0;
1064 l2 = c2->
path ? strlen(c2->
path) : 0;
1067 return (l2 > l1) ? 1 : -1 ;
1074 return (l2 > l1) ? 1 : -1 ;
1084 #define CLONE(field) \ 1087 d->field = strdup(src->field); \ 1131 const char *host,
const char *
path,
1136 time_t
now = time(NULL);
1137 struct Cookie *mainco = NULL;
1176 newco->
next = mainco;
1209 for(i = 0; co; co = co->
next)
1218 for(i = 0; i<matches-1; i++)
1219 array[i]->
next = array[i + 1];
1220 array[matches-1]->
next = NULL;
1272 struct Cookie *first, *curr, *
next, *prev = NULL;
1274 if(!cookies || !cookies->
cookies)
1277 first = curr = prev = cookies->
cookies;
1279 for(; curr; curr =
next) {
1341 co->
secure?
"TRUE":
"FALSE",
1359 bool use_stdout =
FALSE;
1370 if(!strcmp(
"-", dumphere)) {
1381 fputs(
"# Netscape HTTP Cookie File\n" 1382 "# https://curl.haxx.se/docs/http-cookies.html\n" 1383 "# This file was generated by libcurl! Edit at your own risk.\n\n",
1390 if(format_ptr == NULL) {
1391 fprintf(out,
"#\n# Fatal libcurl error\n");
1396 fprintf(out,
"%s\n", format_ptr);
1460 infof(data,
"WARNING: failed to save cookies in %s\n",
struct CookieInfo * Curl_cookie_init(struct Curl_easy *data, const char *file, struct CookieInfo *inc, bool newsession)
static char * get_line(char *buf, int len, FILE *input)
static void strstore(char **str, const char *newstr)
struct curl_slist * Curl_slist_append_nodup(struct curl_slist *list, char *data)
UNITTEST_START char * ptr
static void remove_expired(struct CookieInfo *cookies)
static int cookie_sort(const void *p1, const void *p2)
#define strcasecompare(a, b)
static int cookie_output(struct CookieInfo *c, const char *dumphere)
static char * get_netscape_format(const struct Cookie *co)
void Curl_cookie_loadfiles(struct Curl_easy *data)
static bool pathmatch(const char *cookie_path, const char *request_uri)
struct Curl_share * share
void Curl_cookie_clearsess(struct CookieInfo *cookies)
struct DynamicStatic change
memcpy(filename, filename1, strlen(filename1))
CURLSHcode Curl_share_unlock(struct Curl_easy *data, curl_lock_data type)
curl_easy_setopt expects a curl_off_t argument for this option curl_easy_setopt expects a curl_write_callback argument for this option curl_easy_setopt expects a curl_ioctl_callback argument for this option curl_easy_setopt expects a curl_opensocket_callback argument for this option curl_easy_setopt expects a curl_debug_callback argument for this option curl_easy_setopt expects a curl_conv_callback argument for this option curl_easy_setopt expects a private data pointer as argument for this option curl_easy_setopt expects a FILE *argument for this option curl_easy_setopt expects a struct curl_httppost *argument for this option curl_easy_setopt expects a struct curl_slist *argument for this option curl_easy_getinfo expects a pointer to char *for this info curl_easy_getinfo expects a pointer to double for this info curl_easy_getinfo expects a pointer to struct curl_tlssessioninfo *for this info curl_easy_getinfo expects a pointer to curl_socket_t for this info size_t
static char * sanitize_cookie_path(const char *cookie_path)
struct curl_slist * Curl_cookie_list(struct Curl_easy *data)
static struct Cookie * dup_cookie(struct Cookie *src)
void Curl_flush_cookies(struct Curl_easy *data, int cleanup)
static void freecookie(struct Cookie *co)
CURLofft curlx_strtoofft(const char *str, char **endp, int base, curl_off_t *num)
struct CookieInfo * cookies
CURL_TYPEOF_CURL_OFF_T curl_off_t
struct CookieInfo * cookies
struct curl_slist * cookielist
int Curl_inet_pton(int af, const char *src, void *dst)
static struct curl_slist * cookie_list(struct Curl_easy *data)
struct Cookie * Curl_cookie_add(struct Curl_easy *data, struct CookieInfo *c, bool httpheader, char *lineptr, const char *domain, const char *path)
static bool isip(const char *domain)
CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused)
static bool tailmatch(const char *cooke_domain, const char *hostname)
struct Cookie * Curl_cookie_getlist(struct CookieInfo *c, const char *host, const char *path, bool secure)
UNITTEST_START int * value
CURLSHcode Curl_share_lock(struct Curl_easy *data, curl_lock_data type, curl_lock_access accesstype)
#define checkprefix(a, b)
void Curl_cookie_cleanup(struct CookieInfo *c)
void Curl_cookie_freelist(struct Cookie *co)
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
#define calloc(nbelem, size)
void Curl_cookie_clearall(struct CookieInfo *cookies)
#define CURL_FORMAT_CURL_OFF_T