cookie.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef __COOKIE_H
  2. #define __COOKIE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2006, Daniel Stenberg, <[email protected]>, 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 http://curl.haxx.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. * $Id$
  24. ***************************************************************************/
  25. #include <stdio.h>
  26. #if defined(WIN32)
  27. #include <time.h>
  28. #else
  29. #ifdef HAVE_SYS_TIME_H
  30. #include <sys/time.h>
  31. #endif
  32. #endif
  33. #include <curl/curl.h>
  34. struct Cookie {
  35. struct Cookie *next; /* next in the chain */
  36. char *name; /* <this> = value */
  37. char *value; /* name = <this> */
  38. char *path; /* path = <this> */
  39. char *domain; /* domain = <this> */
  40. curl_off_t expires; /* expires = <this> */
  41. char *expirestr; /* the plain text version */
  42. bool tailmatch; /* weather we do tail-matchning of the domain name */
  43. /* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */
  44. char *version; /* Version = <value> */
  45. char *maxage; /* Max-Age = <value> */
  46. bool secure; /* whether the 'secure' keyword was used */
  47. bool livecookie; /* updated from a server, not a stored file */
  48. };
  49. struct CookieInfo {
  50. /* linked list of cookies we know of */
  51. struct Cookie *cookies;
  52. char *filename; /* file we read from/write to */
  53. bool running; /* state info, for cookie adding information */
  54. long numcookies; /* number of cookies in the "jar" */
  55. bool newsession; /* new session, discard session cookies on load */
  56. };
  57. /* This is the maximum line length we accept for a cookie line. RFC 2109
  58. section 6.3 says:
  59. "at least 4096 bytes per cookie (as measured by the size of the characters
  60. that comprise the cookie non-terminal in the syntax description of the
  61. Set-Cookie header)"
  62. */
  63. #define MAX_COOKIE_LINE 5000
  64. #define MAX_COOKIE_LINE_TXT "4999"
  65. /* This is the maximum length of a cookie name we deal with: */
  66. #define MAX_NAME 1024
  67. #define MAX_NAME_TXT "1023"
  68. struct SessionHandle;
  69. /*
  70. * Add a cookie to the internal list of cookies. The domain and path arguments
  71. * are only used if the header boolean is TRUE.
  72. */
  73. struct Cookie *Curl_cookie_add(struct SessionHandle *data,
  74. struct CookieInfo *, bool header, char *line,
  75. char *domain, char *path);
  76. struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
  77. char *, struct CookieInfo *, bool);
  78. struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
  79. void Curl_cookie_freelist(struct Cookie *);
  80. void Curl_cookie_clearall(struct CookieInfo *cookies);
  81. void Curl_cookie_clearsess(struct CookieInfo *cookies);
  82. void Curl_cookie_cleanup(struct CookieInfo *);
  83. int Curl_cookie_output(struct CookieInfo *, char *);
  84. #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
  85. #define Curl_cookie_list(x) NULL
  86. #define Curl_cookie_loadfiles(x) do { } while (0)
  87. #else
  88. struct curl_slist *Curl_cookie_list(struct SessionHandle *data);
  89. void Curl_cookie_loadfiles(struct SessionHandle *data);
  90. #endif
  91. #endif