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.

248 lines
4.9 KiB

  1. #ifndef _DIGESTCONTEXTCACHE_HXX_
  2. #define _DIGESTCONTEXTCACHE_HXX_
  3. #include "usercache.hxx"
  4. //
  5. // The check period for how long a Digest server context can be in the
  6. // cache. Digest server contexts can be in the cache for up to two
  7. // times this value (in seconds)
  8. //
  9. #define DEFAULT_CACHED_DIGEST_CONTEXT_TTL ( 30 )
  10. class DIGEST_CONTEXT_CACHE_KEY : public CACHE_KEY
  11. {
  12. public:
  13. DIGEST_CONTEXT_CACHE_KEY(){}
  14. BOOL
  15. QueryIsEqual(
  16. const CACHE_KEY * pCompareKey
  17. ) const
  18. {
  19. DIGEST_CONTEXT_CACHE_KEY * pDigestContextKey =
  20. ( DIGEST_CONTEXT_CACHE_KEY * ) pCompareKey;
  21. DBG_ASSERT( pDigestContextKey != NULL );
  22. //
  23. // Compare the two context handle
  24. //
  25. return memcmp( &m_hServerContext,
  26. &pDigestContextKey->m_hServerContext,
  27. sizeof( CtxtHandle ) ) == 0;
  28. }
  29. DWORD
  30. QueryKeyHash(
  31. VOID
  32. ) const
  33. {
  34. return HashBlob( &m_hServerContext, sizeof( CtxtHandle ) );
  35. }
  36. HRESULT
  37. SetKey(
  38. DIGEST_CONTEXT_CACHE_KEY * pCacheKey
  39. )
  40. {
  41. if( pCacheKey == NULL )
  42. {
  43. DBG_ASSERT( FALSE );
  44. return HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  45. }
  46. memcpy( &m_hServerContext,
  47. &pCacheKey->m_hServerContext,
  48. sizeof( CtxtHandle ) );
  49. return NO_ERROR;
  50. }
  51. HRESULT
  52. CreateCacheKey(
  53. CtxtHandle * phCtxtHandle
  54. )
  55. {
  56. if( phCtxtHandle == NULL )
  57. {
  58. DBG_ASSERT( FALSE );
  59. return HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  60. }
  61. memcpy( &m_hServerContext,
  62. phCtxtHandle,
  63. sizeof( CtxtHandle ) );
  64. return NO_ERROR;
  65. }
  66. CtxtHandle *
  67. QueryContextHandle(
  68. VOID
  69. )
  70. {
  71. return &m_hServerContext;
  72. }
  73. private:
  74. CtxtHandle m_hServerContext;
  75. };
  76. #define DIGEST_CONTEXT_CACHE_ENTRY_SIGNATURE 'ECCD'
  77. #define DIGEST_CONTEXT_CACHE_ENTRY_FREE_SIGNATURE 'fCCD'
  78. class DIGEST_CONTEXT_CACHE_ENTRY : public CACHE_ENTRY
  79. {
  80. public:
  81. DIGEST_CONTEXT_CACHE_ENTRY(
  82. OBJECT_CACHE * pObjectCache
  83. )
  84. : CACHE_ENTRY( pObjectCache ),
  85. m_dwSignature( DIGEST_CONTEXT_CACHE_ENTRY_SIGNATURE )
  86. { }
  87. virtual ~DIGEST_CONTEXT_CACHE_ENTRY();
  88. CACHE_KEY *
  89. QueryCacheKey(
  90. VOID
  91. ) const
  92. {
  93. return ( CACHE_KEY * ) &m_cacheKey;
  94. }
  95. HRESULT
  96. SetCacheKey(
  97. DIGEST_CONTEXT_CACHE_KEY * pCacheKey
  98. )
  99. {
  100. return m_cacheKey.SetKey( pCacheKey );
  101. }
  102. BOOL
  103. CheckSignature(
  104. VOID
  105. ) const
  106. {
  107. return m_dwSignature == DIGEST_CONTEXT_CACHE_ENTRY_SIGNATURE;
  108. }
  109. VOID *
  110. operator new(
  111. #if DBG
  112. size_t size
  113. #else
  114. size_t
  115. #endif
  116. )
  117. {
  118. DBG_ASSERT( size == sizeof( DIGEST_CONTEXT_CACHE_ENTRY ) );
  119. DBG_ASSERT( sm_pachDigestContextCacheEntry != NULL );
  120. return sm_pachDigestContextCacheEntry->Alloc();
  121. }
  122. VOID
  123. operator delete(
  124. VOID * pDigestContextCacheEntry
  125. )
  126. {
  127. DBG_ASSERT( pDigestContextCacheEntry != NULL );
  128. DBG_ASSERT( sm_pachDigestContextCacheEntry != NULL );
  129. DBG_REQUIRE( sm_pachDigestContextCacheEntry->Free(
  130. pDigestContextCacheEntry ) );
  131. }
  132. static
  133. HRESULT
  134. Initialize(
  135. VOID
  136. );
  137. static
  138. VOID
  139. Terminate(
  140. VOID
  141. );
  142. private:
  143. DWORD m_dwSignature;
  144. //
  145. // Cache key
  146. //
  147. DIGEST_CONTEXT_CACHE_KEY m_cacheKey;
  148. //
  149. // Allocation cache for DIGEST_CONTEXT_CACHE_ENTRY
  150. //
  151. static ALLOC_CACHE_HANDLER * sm_pachDigestContextCacheEntry;
  152. };
  153. class DIGEST_CONTEXT_CACHE : public OBJECT_CACHE
  154. {
  155. public:
  156. DIGEST_CONTEXT_CACHE()
  157. {
  158. #if DBG
  159. m_pTraceLog = CreateRefTraceLog( 10000, 0 );
  160. #else
  161. m_pTraceLog = NULL;
  162. #endif
  163. }
  164. virtual ~DIGEST_CONTEXT_CACHE()
  165. {
  166. #if DBG
  167. DestroyRefTraceLog( m_pTraceLog );
  168. #endif
  169. }
  170. WCHAR *
  171. QueryName(
  172. VOID
  173. ) const
  174. {
  175. return L"DIGEST_CONTEXT_CACHE";
  176. }
  177. HRESULT
  178. Initialize(
  179. VOID
  180. );
  181. VOID
  182. Terminate(
  183. VOID
  184. );
  185. HRESULT
  186. AddContextCacheEntry(
  187. IN CtxtHandle * phCtxtHandle
  188. );
  189. PTRACE_LOG
  190. QueryTraceLog() const
  191. {
  192. return m_pTraceLog;
  193. }
  194. private:
  195. DIGEST_CONTEXT_CACHE(const DIGEST_CONTEXT_CACHE &);
  196. void operator=(const DIGEST_CONTEXT_CACHE &);
  197. PTRACE_LOG m_pTraceLog;
  198. };
  199. #endif