Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.5 KiB

  1. #ifndef _COOKIE_JAR_H_
  2. #define _COOKIE_JAR_H_
  3. #include <wininetp.h>
  4. #include "httpp.h"
  5. //---------------------------------------------------------------------------
  6. //
  7. // CCookieBase
  8. //
  9. // Provides operator new which allocates extra memory
  10. // after object and initializes the memory to zero.
  11. //
  12. //---------------------------------------------------------------------------
  13. class CCookieBase
  14. {
  15. public:
  16. void * operator new(size_t cb, size_t cbExtra);
  17. void operator delete(void *pv);
  18. };
  19. //---------------------------------------------------------------------------
  20. //
  21. // CCookie
  22. //
  23. // Holds a single cookie value.
  24. //
  25. //---------------------------------------------------------------------------
  26. class CCookie : public CCookieBase
  27. {
  28. public:
  29. ~CCookie();
  30. static CCookie *Construct(const char *pchName);
  31. BOOL SetValue(const char *pchValue);
  32. BOOL CanSend(BOOL fSecure);
  33. BOOL IsPersistent() { return (_dwFlags & COOKIE_SESSION) == 0; }
  34. BOOL PurgeAll(void *);
  35. DWORD _dwFlags;
  36. CCookie * _pCookieNext;
  37. char * _pchName;
  38. char * _pchValue;
  39. FILETIME _ftExpiry;
  40. };
  41. //---------------------------------------------------------------------------
  42. //
  43. // CCookieLocation
  44. //
  45. // Holds all cookies for a given domain and path.
  46. //
  47. //---------------------------------------------------------------------------
  48. class CCookieLocation : public CCookieBase
  49. {
  50. public:
  51. ~CCookieLocation();
  52. static CCookieLocation *Construct(const char *pchRDomain, const char *pchPath);
  53. CCookie * GetCookie(const char *pchName, BOOL fCreate);
  54. BOOL ReadCacheFile();
  55. BOOL ReadCacheFileIfNeeded();
  56. void Purge(BOOL (CCookie::*)(void *), void *);
  57. BOOL IsMatch(const char *pchRDomain, const char *pchPath);
  58. FILETIME _ftCacheFileLastModified;
  59. CCookie * _pCookieKids;
  60. CCookieLocation*_pLocationNext;
  61. char * _pchRDomain;
  62. char * _pchPath;
  63. int _cchPath;
  64. BYTE _fReadFromCacheFileNeeded;
  65. };
  66. //---------------------------------------------------------------------------
  67. //
  68. // CCookieJar
  69. //
  70. // Maintains fixed size hash table of cookie location objects.
  71. //
  72. //---------------------------------------------------------------------------
  73. enum SET_COOKIE_RESULT
  74. {
  75. SET_COOKIE_FAIL = 0,
  76. SET_COOKIE_SUCCESS = 1,
  77. SET_COOKIE_DISALLOW = 2,
  78. SET_COOKIE_PENDING = 3
  79. };
  80. class CCookieJar : public CCookieBase
  81. {
  82. public:
  83. static CCookieJar * Construct();
  84. CCookieJar();
  85. ~CCookieJar();
  86. DWORD SetCookie(HTTP_REQUEST_HANDLE_OBJECT *pRequest, const char *pchURL, char *pchHeader, DWORD dwFlags);
  87. CCookieLocation* GetCookies(const char *pchRDomain, const char *pchPath, CCookieLocation *pLast, FILETIME *ftCurrentTime);
  88. void Purge();
  89. CCookieLocation** GetBucket(const char *pchRDomain);
  90. CCookieLocation * GetLocation(const char *pchRDomain, const char *pchPath, BOOL fCreate);
  91. void Serialize(HANDLE hCookieFile);
  92. enum { htsize=32 };
  93. CCookieLocation * _apLocation[htsize];
  94. CCritSec _csCookieJar;
  95. private:
  96. void serializeCookie(const CCookie *pCookie, HANDLE hCookieFile, const char *pchDomain, const char *pchPath);
  97. void expireCookies(CCookieLocation *pLocation, FILETIME *ftRefTime);
  98. };
  99. #endif