cookie.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef HEADER_CURL_COOKIE_H
  2. #define HEADER_CURL_COOKIE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  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
  14. * are also available at https://curl.se/docs/copyright.html.
  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. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #include <curl/curl.h>
  26. struct Cookie {
  27. struct Cookie *next; /* next in the chain */
  28. char *name; /* <this> = value */
  29. char *value; /* name = <this> */
  30. char *path; /* path = <this> which is in Set-Cookie: */
  31. char *spath; /* sanitized cookie path */
  32. char *domain; /* domain = <this> */
  33. curl_off_t expires; /* expires = <this> */
  34. char *expirestr; /* the plain text version */
  35. bool tailmatch; /* whether we do tail-matching of the domain name */
  36. /* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */
  37. char *version; /* Version = <value> */
  38. char *maxage; /* Max-Age = <value> */
  39. bool secure; /* whether the 'secure' keyword was used */
  40. bool livecookie; /* updated from a server, not a stored file */
  41. bool httponly; /* true if the httponly directive is present */
  42. int creationtime; /* time when the cookie was written */
  43. unsigned char prefix; /* bitmap fields indicating which prefix are set */
  44. };
  45. /*
  46. * Available cookie prefixes, as defined in
  47. * draft-ietf-httpbis-rfc6265bis-02
  48. */
  49. #define COOKIE_PREFIX__SECURE (1<<0)
  50. #define COOKIE_PREFIX__HOST (1<<1)
  51. #define COOKIE_HASH_SIZE 256
  52. struct CookieInfo {
  53. /* linked list of cookies we know of */
  54. struct Cookie *cookies[COOKIE_HASH_SIZE];
  55. char *filename; /* file we read from/write to */
  56. bool running; /* state info, for cookie adding information */
  57. long numcookies; /* number of cookies in the "jar" */
  58. bool newsession; /* new session, discard session cookies on load */
  59. int lastct; /* last creation-time used in the jar */
  60. };
  61. /* This is the maximum line length we accept for a cookie line. RFC 2109
  62. section 6.3 says:
  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. We allow max 5000 bytes cookie header. Max 4095 bytes length per cookie
  67. name and value. Name + value may not exceed 4096 bytes.
  68. */
  69. #define MAX_COOKIE_LINE 5000
  70. /* This is the maximum length of a cookie name or content we deal with: */
  71. #define MAX_NAME 4096
  72. #define MAX_NAME_TXT "4095"
  73. struct Curl_easy;
  74. /*
  75. * Add a cookie to the internal list of cookies. The domain and path arguments
  76. * are only used if the header boolean is TRUE.
  77. */
  78. struct Cookie *Curl_cookie_add(struct Curl_easy *data,
  79. struct CookieInfo *, bool header, bool noexpiry,
  80. char *lineptr,
  81. const char *domain, const char *path,
  82. bool secure);
  83. struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *,
  84. const char *, bool);
  85. void Curl_cookie_freelist(struct Cookie *cookies);
  86. void Curl_cookie_clearall(struct CookieInfo *cookies);
  87. void Curl_cookie_clearsess(struct CookieInfo *cookies);
  88. #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
  89. #define Curl_cookie_list(x) NULL
  90. #define Curl_cookie_loadfiles(x) Curl_nop_stmt
  91. #define Curl_cookie_init(x,y,z,w) NULL
  92. #define Curl_cookie_cleanup(x) Curl_nop_stmt
  93. #define Curl_flush_cookies(x,y) Curl_nop_stmt
  94. #else
  95. void Curl_flush_cookies(struct Curl_easy *data, bool cleanup);
  96. void Curl_cookie_cleanup(struct CookieInfo *);
  97. struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
  98. const char *, struct CookieInfo *, bool);
  99. struct curl_slist *Curl_cookie_list(struct Curl_easy *data);
  100. void Curl_cookie_loadfiles(struct Curl_easy *data);
  101. #endif
  102. #endif /* HEADER_CURL_COOKIE_H */