Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1 | #ifndef HEADER_CURL_COOKIE_H |
| 2 | #define HEADER_CURL_COOKIE_H |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 3 | /*************************************************************************** |
| 4 | * _ _ ____ _ |
| 5 | * Project ___| | | | _ \| | |
| 6 | * / __| | | | |_) | | |
| 7 | * | (__| |_| | _ <| |___ |
| 8 | * \___|\___/|_| \_\_____| |
| 9 | * |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 10 | * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 11 | * |
| 12 | * This software is licensed as described in the file COPYING, which |
| 13 | * you should have received as part of this distribution. The terms |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 14 | * are also available at https://curl.haxx.se/docs/copyright.html. |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 15 | * |
| 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| 17 | * copies of the Software, and permit persons to whom the Software is |
| 18 | * furnished to do so, under the terms of the COPYING file. |
| 19 | * |
| 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 21 | * KIND, either express or implied. |
| 22 | * |
| 23 | ***************************************************************************/ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 24 | #include "curl_setup.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 25 | |
| 26 | #include <curl/curl.h> |
| 27 | |
| 28 | struct Cookie { |
| 29 | struct Cookie *next; /* next in the chain */ |
| 30 | char *name; /* <this> = value */ |
| 31 | char *value; /* name = <this> */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 32 | char *path; /* path = <this> which is in Set-Cookie: */ |
| 33 | char *spath; /* sanitized cookie path */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 34 | char *domain; /* domain = <this> */ |
| 35 | curl_off_t expires; /* expires = <this> */ |
| 36 | char *expirestr; /* the plain text version */ |
| 37 | bool tailmatch; /* weather we do tail-matchning of the domain name */ |
| 38 | |
| 39 | /* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */ |
| 40 | char *version; /* Version = <value> */ |
| 41 | char *maxage; /* Max-Age = <value> */ |
| 42 | |
| 43 | bool secure; /* whether the 'secure' keyword was used */ |
| 44 | bool livecookie; /* updated from a server, not a stored file */ |
| 45 | bool httponly; /* true if the httponly directive is present */ |
| 46 | }; |
| 47 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 48 | #define COOKIE_HASH_SIZE 256 |
| 49 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 50 | struct CookieInfo { |
| 51 | /* linked list of cookies we know of */ |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 52 | struct Cookie *cookies[COOKIE_HASH_SIZE]; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 53 | |
| 54 | char *filename; /* file we read from/write to */ |
| 55 | bool running; /* state info, for cookie adding information */ |
| 56 | long numcookies; /* number of cookies in the "jar" */ |
| 57 | bool newsession; /* new session, discard session cookies on load */ |
| 58 | }; |
| 59 | |
| 60 | /* This is the maximum line length we accept for a cookie line. RFC 2109 |
| 61 | section 6.3 says: |
| 62 | |
| 63 | "at least 4096 bytes per cookie (as measured by the size of the characters |
| 64 | that comprise the cookie non-terminal in the syntax description of the |
| 65 | Set-Cookie header)" |
| 66 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 67 | We allow max 5000 bytes cookie header. Max 4095 bytes length per cookie |
| 68 | name and value. Name + value may not exceed 4096 bytes. |
| 69 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 70 | */ |
| 71 | #define MAX_COOKIE_LINE 5000 |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 72 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 73 | /* This is the maximum length of a cookie name or content we deal with: */ |
| 74 | #define MAX_NAME 4096 |
| 75 | #define MAX_NAME_TXT "4095" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 76 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 77 | struct Curl_easy; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 78 | /* |
| 79 | * Add a cookie to the internal list of cookies. The domain and path arguments |
| 80 | * are only used if the header boolean is TRUE. |
| 81 | */ |
| 82 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 83 | struct Cookie *Curl_cookie_add(struct Curl_easy *data, |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 84 | struct CookieInfo *, bool header, bool noexpiry, |
| 85 | char *lineptr, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 86 | const char *domain, const char *path); |
| 87 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 88 | struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *, |
| 89 | const char *, bool); |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 90 | void Curl_cookie_freelist(struct Cookie *cookies); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 91 | void Curl_cookie_clearall(struct CookieInfo *cookies); |
| 92 | void Curl_cookie_clearsess(struct CookieInfo *cookies); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 93 | |
| 94 | #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES) |
| 95 | #define Curl_cookie_list(x) NULL |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 96 | #define Curl_cookie_loadfiles(x) Curl_nop_stmt |
| 97 | #define Curl_cookie_init(x,y,z,w) NULL |
| 98 | #define Curl_cookie_cleanup(x) Curl_nop_stmt |
| 99 | #define Curl_flush_cookies(x,y) Curl_nop_stmt |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 100 | #else |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 101 | void Curl_flush_cookies(struct Curl_easy *data, int cleanup); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 102 | void Curl_cookie_cleanup(struct CookieInfo *); |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 103 | struct CookieInfo *Curl_cookie_init(struct Curl_easy *data, |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 104 | const char *, struct CookieInfo *, bool); |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 105 | struct curl_slist *Curl_cookie_list(struct Curl_easy *data); |
| 106 | void Curl_cookie_loadfiles(struct Curl_easy *data); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 107 | #endif |
| 108 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 109 | #endif /* HEADER_CURL_COOKIE_H */ |