113498266Sopenharmony_ci#ifndef HEADER_CURL_COOKIE_H 213498266Sopenharmony_ci#define HEADER_CURL_COOKIE_H 313498266Sopenharmony_ci/*************************************************************************** 413498266Sopenharmony_ci * _ _ ____ _ 513498266Sopenharmony_ci * Project ___| | | | _ \| | 613498266Sopenharmony_ci * / __| | | | |_) | | 713498266Sopenharmony_ci * | (__| |_| | _ <| |___ 813498266Sopenharmony_ci * \___|\___/|_| \_\_____| 913498266Sopenharmony_ci * 1013498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 1113498266Sopenharmony_ci * 1213498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which 1313498266Sopenharmony_ci * you should have received as part of this distribution. The terms 1413498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html. 1513498266Sopenharmony_ci * 1613498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell 1713498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is 1813498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file. 1913498266Sopenharmony_ci * 2013498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 2113498266Sopenharmony_ci * KIND, either express or implied. 2213498266Sopenharmony_ci * 2313498266Sopenharmony_ci * SPDX-License-Identifier: curl 2413498266Sopenharmony_ci * 2513498266Sopenharmony_ci ***************************************************************************/ 2613498266Sopenharmony_ci#include "curl_setup.h" 2713498266Sopenharmony_ci 2813498266Sopenharmony_ci#include <curl/curl.h> 2913498266Sopenharmony_ci 3013498266Sopenharmony_cistruct Cookie { 3113498266Sopenharmony_ci struct Cookie *next; /* next in the chain */ 3213498266Sopenharmony_ci char *name; /* <this> = value */ 3313498266Sopenharmony_ci char *value; /* name = <this> */ 3413498266Sopenharmony_ci char *path; /* path = <this> which is in Set-Cookie: */ 3513498266Sopenharmony_ci char *spath; /* sanitized cookie path */ 3613498266Sopenharmony_ci char *domain; /* domain = <this> */ 3713498266Sopenharmony_ci curl_off_t expires; /* expires = <this> */ 3813498266Sopenharmony_ci bool tailmatch; /* whether we do tail-matching of the domain name */ 3913498266Sopenharmony_ci bool secure; /* whether the 'secure' keyword was used */ 4013498266Sopenharmony_ci bool livecookie; /* updated from a server, not a stored file */ 4113498266Sopenharmony_ci bool httponly; /* true if the httponly directive is present */ 4213498266Sopenharmony_ci int creationtime; /* time when the cookie was written */ 4313498266Sopenharmony_ci unsigned char prefix; /* bitmap fields indicating which prefix are set */ 4413498266Sopenharmony_ci}; 4513498266Sopenharmony_ci 4613498266Sopenharmony_ci/* 4713498266Sopenharmony_ci * Available cookie prefixes, as defined in 4813498266Sopenharmony_ci * draft-ietf-httpbis-rfc6265bis-02 4913498266Sopenharmony_ci */ 5013498266Sopenharmony_ci#define COOKIE_PREFIX__SECURE (1<<0) 5113498266Sopenharmony_ci#define COOKIE_PREFIX__HOST (1<<1) 5213498266Sopenharmony_ci 5313498266Sopenharmony_ci#define COOKIE_HASH_SIZE 63 5413498266Sopenharmony_ci 5513498266Sopenharmony_cistruct CookieInfo { 5613498266Sopenharmony_ci /* linked list of cookies we know of */ 5713498266Sopenharmony_ci struct Cookie *cookies[COOKIE_HASH_SIZE]; 5813498266Sopenharmony_ci curl_off_t next_expiration; /* the next time at which expiration happens */ 5913498266Sopenharmony_ci int numcookies; /* number of cookies in the "jar" */ 6013498266Sopenharmony_ci int lastct; /* last creation-time used in the jar */ 6113498266Sopenharmony_ci bool running; /* state info, for cookie adding information */ 6213498266Sopenharmony_ci bool newsession; /* new session, discard session cookies on load */ 6313498266Sopenharmony_ci}; 6413498266Sopenharmony_ci 6513498266Sopenharmony_ci/* The maximum sizes we accept for cookies. RFC 6265 section 6.1 says 6613498266Sopenharmony_ci "general-use user agents SHOULD provide each of the following minimum 6713498266Sopenharmony_ci capabilities": 6813498266Sopenharmony_ci 6913498266Sopenharmony_ci - At least 4096 bytes per cookie (as measured by the sum of the length of 7013498266Sopenharmony_ci the cookie's name, value, and attributes). 7113498266Sopenharmony_ci In the 6265bis draft document section 5.4 it is phrased even stronger: "If 7213498266Sopenharmony_ci the sum of the lengths of the name string and the value string is more than 7313498266Sopenharmony_ci 4096 octets, abort these steps and ignore the set-cookie-string entirely." 7413498266Sopenharmony_ci*/ 7513498266Sopenharmony_ci 7613498266Sopenharmony_ci/** Limits for INCOMING cookies **/ 7713498266Sopenharmony_ci 7813498266Sopenharmony_ci/* The longest we allow a line to be when reading a cookie from a HTTP header 7913498266Sopenharmony_ci or from a cookie jar */ 8013498266Sopenharmony_ci#define MAX_COOKIE_LINE 5000 8113498266Sopenharmony_ci 8213498266Sopenharmony_ci/* Maximum length of an incoming cookie name or content we deal with. Longer 8313498266Sopenharmony_ci cookies are ignored. */ 8413498266Sopenharmony_ci#define MAX_NAME 4096 8513498266Sopenharmony_ci 8613498266Sopenharmony_ci/* Maximum number of Set-Cookie: lines accepted in a single response. If more 8713498266Sopenharmony_ci such header lines are received, they are ignored. This value must be less 8813498266Sopenharmony_ci than 256 since an unsigned char is used to count. */ 8913498266Sopenharmony_ci#define MAX_SET_COOKIE_AMOUNT 50 9013498266Sopenharmony_ci 9113498266Sopenharmony_ci/** Limits for OUTGOING cookies **/ 9213498266Sopenharmony_ci 9313498266Sopenharmony_ci/* Maximum size for an outgoing cookie line libcurl will use in an http 9413498266Sopenharmony_ci request. This is the default maximum length used in some versions of Apache 9513498266Sopenharmony_ci httpd. */ 9613498266Sopenharmony_ci#define MAX_COOKIE_HEADER_LEN 8190 9713498266Sopenharmony_ci 9813498266Sopenharmony_ci/* Maximum number of cookies libcurl will send in a single request, even if 9913498266Sopenharmony_ci there might be more cookies that match. One reason to cap the number is to 10013498266Sopenharmony_ci keep the maximum HTTP request within the maximum allowed size. */ 10113498266Sopenharmony_ci#define MAX_COOKIE_SEND_AMOUNT 150 10213498266Sopenharmony_ci 10313498266Sopenharmony_cistruct Curl_easy; 10413498266Sopenharmony_ci/* 10513498266Sopenharmony_ci * Add a cookie to the internal list of cookies. The domain and path arguments 10613498266Sopenharmony_ci * are only used if the header boolean is TRUE. 10713498266Sopenharmony_ci */ 10813498266Sopenharmony_ci 10913498266Sopenharmony_cistruct Cookie *Curl_cookie_add(struct Curl_easy *data, 11013498266Sopenharmony_ci struct CookieInfo *c, bool header, 11113498266Sopenharmony_ci bool noexpiry, const char *lineptr, 11213498266Sopenharmony_ci const char *domain, const char *path, 11313498266Sopenharmony_ci bool secure); 11413498266Sopenharmony_ci 11513498266Sopenharmony_cistruct Cookie *Curl_cookie_getlist(struct Curl_easy *data, 11613498266Sopenharmony_ci struct CookieInfo *c, const char *host, 11713498266Sopenharmony_ci const char *path, bool secure); 11813498266Sopenharmony_civoid Curl_cookie_freelist(struct Cookie *cookies); 11913498266Sopenharmony_civoid Curl_cookie_clearall(struct CookieInfo *cookies); 12013498266Sopenharmony_civoid Curl_cookie_clearsess(struct CookieInfo *cookies); 12113498266Sopenharmony_ci 12213498266Sopenharmony_ci#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES) 12313498266Sopenharmony_ci#define Curl_cookie_list(x) NULL 12413498266Sopenharmony_ci#define Curl_cookie_loadfiles(x) Curl_nop_stmt 12513498266Sopenharmony_ci#define Curl_cookie_init(x,y,z,w) NULL 12613498266Sopenharmony_ci#define Curl_cookie_cleanup(x) Curl_nop_stmt 12713498266Sopenharmony_ci#define Curl_flush_cookies(x,y) Curl_nop_stmt 12813498266Sopenharmony_ci#else 12913498266Sopenharmony_civoid Curl_flush_cookies(struct Curl_easy *data, bool cleanup); 13013498266Sopenharmony_civoid Curl_cookie_cleanup(struct CookieInfo *c); 13113498266Sopenharmony_cistruct CookieInfo *Curl_cookie_init(struct Curl_easy *data, 13213498266Sopenharmony_ci const char *file, struct CookieInfo *inc, 13313498266Sopenharmony_ci bool newsession); 13413498266Sopenharmony_cistruct curl_slist *Curl_cookie_list(struct Curl_easy *data); 13513498266Sopenharmony_civoid Curl_cookie_loadfiles(struct Curl_easy *data); 13613498266Sopenharmony_ci#endif 13713498266Sopenharmony_ci 13813498266Sopenharmony_ci#endif /* HEADER_CURL_COOKIE_H */ 139