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.

241 lines
6.0 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Request, Response objects
  6. File: clcert.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 CClCert;
  18. // Type for an object-destroyed callback
  19. typedef void (*PFNDESTROYED)(void);
  20. /*
  21. * C C l C e r t S u p p o r t E r r
  22. *
  23. * Implements ISupportErrorInfo for the CClCert class. The CSupportError class
  24. * is not adequate because it will only report a max of one interface which
  25. * supports error info. (We have two)
  26. */
  27. class CClCertSupportErr : public ISupportErrorInfo
  28. {
  29. private:
  30. CClCert * m_pClCert;
  31. public:
  32. CClCertSupportErr(CClCert *pClCert);
  33. // IUnknown members that delegate to m_pClCert
  34. //
  35. STDMETHODIMP QueryInterface(const GUID &, void **);
  36. STDMETHODIMP_(ULONG) AddRef(void);
  37. STDMETHODIMP_(ULONG) Release(void);
  38. // ISupportErrorInfo members
  39. //
  40. STDMETHODIMP InterfaceSupportsErrorInfo(const GUID &);
  41. };
  42. /*
  43. * C R e a d C l C e r t
  44. *
  45. * Implements IClCert which is the interface that Request.ClientCert
  46. * returns. It is an IRequestDictionary.
  47. */
  48. class CReadClCert : public IRequestDictionaryImpl
  49. {
  50. private:
  51. CClCert * m_pClCert;
  52. public:
  53. CReadClCert(CClCert *);
  54. // The Big Three
  55. //
  56. STDMETHODIMP QueryInterface(const IID &rIID, void **ppvObj);
  57. STDMETHODIMP_(ULONG) AddRef();
  58. STDMETHODIMP_(ULONG) Release();
  59. // IRequestDictionary implementation
  60. //
  61. STDMETHODIMP get_Item(VARIANT i, VARIANT *pVariantReturn);
  62. STDMETHODIMP get__NewEnum(IUnknown **ppEnumReturn);
  63. STDMETHODIMP get_Count(int *pcValues);
  64. STDMETHODIMP get_Key(VARIANT VarKey, VARIANT *pvar);
  65. };
  66. /*
  67. * C C l C e r t
  68. *
  69. * Implements CClCert, which is the object stored in the Request.Cookies
  70. * dictionary.
  71. */
  72. class CClCert : public IUnknown
  73. {
  74. friend CReadClCert;
  75. protected:
  76. ULONG m_cRefs; // reference count
  77. PFNDESTROYED m_pfnDestroy; // To call on closure
  78. private:
  79. CReadClCert m_ReadClCertInterface; // implementation of IStringList
  80. CClCertSupportErr m_ClCertSupportErrorInfo; // implementation of ISupportErrorInfo
  81. char * m_szValue; // value of clcert when not a dictionary
  82. VARENUM m_veType;
  83. UINT m_cLen;
  84. public:
  85. CClCert(IUnknown * = NULL, PFNDESTROYED = NULL);
  86. ~CClCert();
  87. HRESULT AddValue(char *szValue, VARENUM ve = VT_BSTR, UINT l = 0 );
  88. size_t GetHTTPClCertSize(); // return information on how big a buffer should be
  89. char * GetHTTPClCert(char *szBuffer); // return the clcert value HTTP encoded
  90. size_t GetClCertHeaderSize(const char *szName); // return buffer size for header
  91. char *GetClCertHeader(const char *szName, char *szBuffer); // return cookie header
  92. HRESULT Init();
  93. // The Big Three
  94. //
  95. STDMETHODIMP QueryInterface(const GUID &Iid, void **ppvObj);
  96. STDMETHODIMP_(ULONG) AddRef();
  97. STDMETHODIMP_(ULONG) Release();
  98. // Cache on per-class basis
  99. ACACHE_INCLASS_DEFINITIONS()
  100. };
  101. //
  102. // simple class to handle extensible buffer
  103. // It is guaranteed that a portion of the buffer
  104. // can be appended to itself.
  105. // extension is done on a XBF_EXTEND granularity
  106. //
  107. #define XBF_EXTEND 512
  108. class XBF {
  109. public:
  110. XBF( LPSTR pB, int cB ) { m_pV = pB; m_cAlloc = cB; m_cSize = 0; }
  111. ~XBF() {}
  112. void Reset() { m_cSize = 0; m_cAlloc = 0; m_pV = NULL; }
  113. // Append a string with '\0' delimiter
  114. LPSTR AddStringZ( LPSTR pszV, BOOL fXt = FALSE )
  115. {
  116. return AddBlob( pszV, strlen(pszV) +1, fXt );
  117. }
  118. // Append a string w/o '\0' delimiter
  119. LPSTR AddString( LPSTR pszV, BOOL fXt = FALSE )
  120. {
  121. return AddBlob( pszV, strlen(pszV), fXt );
  122. }
  123. // Append a byte range
  124. LPSTR AddBlob( LPSTR pszV, int cV, BOOL fXt = FALSE )
  125. {
  126. if ( m_cSize + cV > m_cAlloc )
  127. {
  128. if ( !fXt || !Extend( m_cSize + cV ) )
  129. {
  130. return NULL;
  131. }
  132. }
  133. LPSTR pV;
  134. memcpy( pV = m_pV + m_cSize, pszV, cV );
  135. m_cSize += cV;
  136. return pV;
  137. }
  138. LPSTR ReserveRange( int cV , int align = 1)
  139. {
  140. int curUsed = ((m_cSize + (align - 1)) & ~(align - 1));
  141. if ( (curUsed + cV) > m_cAlloc )
  142. {
  143. return NULL;
  144. }
  145. return m_pV + curUsed;
  146. }
  147. VOID SkipRange( int cV, int align = 1)
  148. {
  149. m_cSize += ((cV + (align - 1)) & ~(align - 1));
  150. }
  151. BOOL Extend( int cA );
  152. // pointer to buffer
  153. LPSTR QueryBuf() const { return m_pV; }
  154. // size of buffer
  155. int QuerySize() { return m_cSize; }
  156. int QueryAllocSize() { return m_cAlloc; }
  157. private:
  158. int m_cAlloc; // allocated memory
  159. int m_cSize; // used memory
  160. LPSTR m_pV; // buffer
  161. } ;
  162. class CCertRequest {
  163. public:
  164. CCertRequest( CRequest* Req ) { pReq = Req; }
  165. ~CCertRequest() {}
  166. HRESULT AddStringPair( CollectionType Source, LPSTR szName,
  167. LPSTR szValue, XBF *pxbf, BOOL fDuplicate, UINT lCodePage );
  168. HRESULT AddDatePair( CollectionType Source, LPSTR szName,
  169. FILETIME* pValue, XBF *pxbf );
  170. HRESULT AddDwordPair( CollectionType Source, LPSTR szName,
  171. LPDWORD pValue, XBF *pxbf );
  172. HRESULT AddBinaryPair( CollectionType Source, LPSTR szName,
  173. LPBYTE pValue, DWORD cValue, XBF *pxbf, UINT lCodePage );
  174. HRESULT AddUuBinaryPair( CollectionType Source, LPSTR szName,
  175. LPBYTE pValue, DWORD cValue, XBF *pxbf, UINT lCodePage );
  176. HRESULT AddName( LPSTR szName, CRequestHit **ppReqHit, XBF *pxbf );
  177. HRESULT ParseRDNS( CERT_NAME_INFO* pNameInfo, LPSTR pszPrefix, XBF *pxbf, UINT lCodePage );
  178. HRESULT ParseCertificate( LPBYTE pCert, DWORD cCert, DWORD dwEncoding, DWORD dwFlags, UINT lCodePage );
  179. HRESULT NoCertificate();
  180. private:
  181. CRequest *pReq;
  182. } ;