Source code of Windows XP (NT5)
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.

231 lines
5.9 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Request, Response objects
  6. File: cookies.h
  7. Owner: DGottner
  8. This file contains the definiton of the CCookie class, which
  9. contains all of the state for an HTTP cookie
  10. ===================================================================*/
  11. #include "denpre.h"
  12. #pragma hdrstop
  13. #include "asptlb.h"
  14. #include "dispatch.h"
  15. #include "hashing.h"
  16. #include "memcls.h"
  17. class CCookie;
  18. // Type for an object-destroyed callback
  19. typedef void (*PFNDESTROYED)(void);
  20. /* C C o o k i e P a i r
  21. *
  22. * Implements a name/value pair in the Cookie dictionary
  23. */
  24. class CCookiePair : public CLinkElem
  25. {
  26. public:
  27. char *m_szValue;
  28. BOOL m_fDuplicate; // TRUE if we have a strdup'ed copy of m_pKey, m_szValue
  29. HRESULT Init(const char *szKey, const char *szValue, BOOL fDuplicate = FALSE);
  30. CCookiePair();
  31. ~CCookiePair();
  32. };
  33. /*
  34. * C C o o k i e S u p p o r t E r r
  35. *
  36. * Implements ISupportErrorInfo for the CCookie class. The CSupportError class
  37. * is not adequate because it will only report a max of one interface which
  38. * supports error info. (We have two)
  39. */
  40. class CCookieSupportErr : public ISupportErrorInfo
  41. {
  42. private:
  43. CCookie * m_pCookie;
  44. public:
  45. CCookieSupportErr(CCookie *pCookie);
  46. // IUnknown members that delegate to m_pCookie
  47. //
  48. STDMETHODIMP QueryInterface(const GUID &, void **);
  49. STDMETHODIMP_(ULONG) AddRef(void);
  50. STDMETHODIMP_(ULONG) Release(void);
  51. // ISupportErrorInfo members
  52. //
  53. STDMETHODIMP InterfaceSupportsErrorInfo(const GUID &);
  54. };
  55. /*
  56. * C W r i t e C o o k i e
  57. *
  58. * Implements IWriteCookie which is the interface that Response.Cookies
  59. * returns.
  60. */
  61. class CWriteCookie : public IWriteCookieImpl
  62. {
  63. private:
  64. CCookie * m_pCookie;
  65. public:
  66. CWriteCookie(CCookie *);
  67. // The Big Three
  68. //
  69. STDMETHODIMP QueryInterface(const IID &rIID, void **ppvObj);
  70. STDMETHODIMP_(ULONG) AddRef();
  71. STDMETHODIMP_(ULONG) Release();
  72. // IWriteCookie implementation
  73. //
  74. STDMETHODIMP put_Item(VARIANT varKey, BSTR bstrValue);
  75. STDMETHODIMP put_Expires(DATE dtExpires);
  76. STDMETHODIMP put_Domain(BSTR bstrDomain);
  77. STDMETHODIMP put_Path(BSTR bstrPath);
  78. STDMETHODIMP put_Secure(VARIANT_BOOL fSecure);
  79. STDMETHODIMP get_HasKeys(VARIANT_BOOL *pfHasKeys);
  80. STDMETHODIMP get__NewEnum(IUnknown **ppEnum);
  81. };
  82. /*
  83. * C R e a d C o o k i e
  84. *
  85. * Implements IReadCookie which is the interface that Request.Cookies
  86. * returns.
  87. */
  88. class CReadCookie : public IReadCookieImpl
  89. {
  90. private:
  91. CCookie * m_pCookie;
  92. public:
  93. CReadCookie(CCookie *);
  94. // The Big Three
  95. //
  96. STDMETHODIMP QueryInterface(const IID &rIID, void **ppvObj);
  97. STDMETHODIMP_(ULONG) AddRef();
  98. STDMETHODIMP_(ULONG) Release();
  99. // IReadCookie implementation
  100. //
  101. STDMETHODIMP get_Item(VARIANT i, VARIANT *pVariantReturn);
  102. STDMETHODIMP get_HasKeys(VARIANT_BOOL *pfHasKeys);
  103. STDMETHODIMP get__NewEnum(IUnknown **ppEnumReturn);
  104. STDMETHODIMP get_Count(int *pcValues);
  105. STDMETHODIMP get_Key(VARIANT VarKey, VARIANT *pvar);
  106. };
  107. /*
  108. * C C o o k i e
  109. *
  110. * Implements CCookie, which is the object stored in the Request.Cookies
  111. * dictionary.
  112. */
  113. class CCookie : public IUnknown
  114. {
  115. friend class CWriteCookie;
  116. friend class CReadCookie;
  117. friend class CCookieIterator;
  118. protected:
  119. ULONG m_cRefs; // reference count
  120. PFNDESTROYED m_pfnDestroy; // To call on closure
  121. private:
  122. CWriteCookie m_WriteCookieInterface; // implementation of IWriteCookie
  123. CReadCookie m_ReadCookieInterface; // implementation of IStringList
  124. CCookieSupportErr m_CookieSupportErrorInfo; // implementation of ISupportErrorInfo
  125. CIsapiReqInfo * m_pIReq; // pointer to CIsapiReqInfo for this cookie
  126. UINT m_lCodePage; // code page used for UNICODE conversions
  127. char * m_szValue; // value of cookie when not a dictionary
  128. CHashTableMBStr m_mpszValues; // dictionary of values for the cookie
  129. time_t m_tExpires; // date & time when cookie expires
  130. char * m_szDomain; // Cookie's domain
  131. CHAR * m_szPath; // Cookie's path (If UNICODE, stored as UTF-8)
  132. VARIANT_BOOL m_fSecure:1; // does cookie require security?
  133. BOOL m_fDirty:1; // does cookie need to be sent?
  134. BOOL m_fDuplicate:1; // does cookie contain dynamically allocated string?
  135. public:
  136. CCookie(CIsapiReqInfo *, UINT lCodePage, IUnknown * = NULL, PFNDESTROYED = NULL);
  137. ~CCookie();
  138. HRESULT AddValue(char *szValue, BOOL fDuplicate = FALSE);
  139. HRESULT AddKeyAndValue(char *szKey, char *szValue, BOOL fDuplicate = FALSE);
  140. size_t GetHTTPCookieSize(); // return information on how big a buffer should be
  141. char * GetHTTPCookie(char *szBuffer); // return the cookie value HTTP encoded
  142. size_t GetCookieHeaderSize(const char *szName); // return buffer size needed for Set-Cookie header
  143. char *GetCookieHeader(const char *szName, char *szBuffer); // return cookie header
  144. BOOL IsDirty() { return m_fDirty; }
  145. HRESULT Init();
  146. // The Big Three
  147. //
  148. STDMETHODIMP QueryInterface(const GUID &Iid, void **ppvObj);
  149. STDMETHODIMP_(ULONG) AddRef();
  150. STDMETHODIMP_(ULONG) Release();
  151. // Cache on per-class basis
  152. ACACHE_INCLASS_DEFINITIONS()
  153. };
  154. /*
  155. * C C o o k i e I t e r a t o r
  156. *
  157. * IEnumVariant implementation for Cookie dictionaries
  158. */
  159. class CCookieIterator : public IEnumVARIANT
  160. {
  161. public:
  162. CCookieIterator(CCookie *pCookie);
  163. ~CCookieIterator();
  164. // The Big Three
  165. STDMETHODIMP QueryInterface(const GUID &, void **);
  166. STDMETHODIMP_(ULONG) AddRef();
  167. STDMETHODIMP_(ULONG) Release();
  168. // standard methods for iterators
  169. STDMETHODIMP Clone(IEnumVARIANT **ppEnumReturn);
  170. STDMETHODIMP Next(unsigned long cElements, VARIANT *rgVariant, unsigned long *pcElementsFetched);
  171. STDMETHODIMP Skip(unsigned long cElements);
  172. STDMETHODIMP Reset();
  173. private:
  174. ULONG m_cRefs; // reference count
  175. CCookie *m_pCookie; // pointer to iteratee
  176. CCookiePair *m_pCurrent; // pointer to current item
  177. };