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.

211 lines
6.9 KiB

  1. // stdcooki.h : Declaration of base cookie class and related classes
  2. #ifndef __STDCOOKI_H_INCLUDED__
  3. #define __STDCOOKI_H_INCLUDED__
  4. // forward declarations
  5. class CCookie;
  6. class CRefcountedObject
  7. {
  8. public:
  9. inline CRefcountedObject()
  10. : m_nRefcount( 1 )
  11. {};
  12. virtual ~CRefcountedObject() {};
  13. inline void AddRef() {m_nRefcount++;}
  14. inline void Release()
  15. {
  16. if (0 >= --m_nRefcount)
  17. delete this;
  18. }
  19. private:
  20. int m_nRefcount;
  21. };
  22. class CHasMachineName
  23. {
  24. public:
  25. virtual void SetMachineName( LPCTSTR lpcszMachineName ) = 0;
  26. virtual LPCTSTR QueryNonNULLMachineName() = 0;
  27. virtual LPCTSTR QueryTargetServer() = 0;
  28. // returns <0, 0 or >0
  29. HRESULT CompareMachineNames( CHasMachineName& refHasMachineName, int* pnResult );
  30. };
  31. //
  32. // CBaseCookieBlock holds a block of cookies and the data
  33. // to which the cookies point. It starts off with a
  34. // reference count of 1. When a data object is created
  35. // which references one of these cookies, AddRef() the cookie block; when such
  36. // a data object is released, Release() the cookie block. Similarly,
  37. // when the parent cookie is finished with the cookie block, it should
  38. // Release() the cookie block. The cookie block will delete itself
  39. // when the reference count reaches 0. Do not attempt to explicitly
  40. // delete the cookie block.
  41. //
  42. class CBaseCookieBlock : public CRefcountedObject
  43. {
  44. public:
  45. virtual CCookie* QueryBaseCookie(int i) = 0;
  46. virtual int QueryNumCookies() = 0;
  47. };
  48. template<class COOKIE_TYPE>
  49. class CCookieBlock
  50. : public CBaseCookieBlock
  51. {
  52. private:
  53. COOKIE_TYPE* m_aCookies;
  54. int m_cCookies;
  55. public:
  56. CCookieBlock(COOKIE_TYPE* aCookies, // use vector ctor, we use vector dtor
  57. int cCookies );
  58. virtual ~CCookieBlock();
  59. virtual CCookie* QueryBaseCookie(int i);
  60. virtual int QueryNumCookies();
  61. };
  62. // ISSUE-2002/03/28-JonN QueryBaseCookie(i) should assert range
  63. #define DEFINE_COOKIE_BLOCK(COOKIE_TYPE) \
  64. template <> \
  65. CCookieBlock<COOKIE_TYPE>::CCookieBlock<COOKIE_TYPE> \
  66. (COOKIE_TYPE* aCookies, int cCookies) \
  67. : m_aCookies( aCookies ) \
  68. , m_cCookies( cCookies ) \
  69. { \
  70. ASSERT(NULL != aCookies && 0 < cCookies); \
  71. } \
  72. template <> \
  73. CCookieBlock<COOKIE_TYPE>::~CCookieBlock<COOKIE_TYPE>() \
  74. { \
  75. delete[] m_aCookies; \
  76. } \
  77. template <> \
  78. CCookie* CCookieBlock<COOKIE_TYPE>::QueryBaseCookie(int i) \
  79. { \
  80. return (CCookie*)&(m_aCookies[i]); \
  81. } \
  82. template <> \
  83. int CCookieBlock<COOKIE_TYPE>::QueryNumCookies() \
  84. { \
  85. return m_cCookies; \
  86. }
  87. #define COMPARESIMILARCOOKIE_FULL -1
  88. //
  89. // I am trying to allow child classes to derive from CCookie using
  90. // multiple inheritance, but this is tricky
  91. //
  92. class CCookie
  93. {
  94. public:
  95. CTypedPtrList<CPtrList, CBaseCookieBlock*> m_listScopeCookieBlocks;
  96. CTypedPtrList<CPtrList, CBaseCookieBlock*> m_listResultCookieBlocks;
  97. HSCOPEITEM m_hScopeItem;
  98. private:
  99. LONG m_nResultCookiesRefcount;
  100. public:
  101. inline CCookie()
  102. : m_nResultCookiesRefcount( 0 ),
  103. m_hScopeItem (0)
  104. {
  105. }
  106. inline void ReleaseScopeChildren()
  107. {
  108. while ( !m_listScopeCookieBlocks.IsEmpty() )
  109. {
  110. (m_listScopeCookieBlocks.RemoveHead())->Release();
  111. }
  112. }
  113. // returns new refcount
  114. inline ULONG AddRefResultChildren()
  115. {
  116. return ++m_nResultCookiesRefcount;
  117. }
  118. inline void ReleaseResultChildren()
  119. {
  120. ASSERT( 0 < m_nResultCookiesRefcount );
  121. if ( 0 >= --m_nResultCookiesRefcount )
  122. {
  123. while ( !m_listResultCookieBlocks.IsEmpty() )
  124. {
  125. (m_listResultCookieBlocks.RemoveHead())->Release();
  126. }
  127. }
  128. }
  129. virtual ~CCookie();
  130. // On entry, if not COMPARESIMILARCOOKIE_FULL, *pnResult is the column on which to sort,
  131. // otherwise, try to do a full cookie comparison.
  132. // On exit, *pnResult should be <0, 0 or >0.
  133. // Note that this is a sorting function and should not be used to establish
  134. // object identity where better identity functions are available.
  135. virtual HRESULT CompareSimilarCookies( CCookie* pOtherCookie, int* pnResult ) = 0;
  136. };
  137. #define DECLARE_FORWARDS_MACHINE_NAME(targ) \
  138. virtual LPCTSTR QueryNonNULLMachineName(); \
  139. virtual LPCTSTR QueryTargetServer(); \
  140. virtual void SetMachineName( LPCTSTR lpcszMachineName );
  141. #define DEFINE_FORWARDS_MACHINE_NAME(thisclass,targ) \
  142. LPCTSTR thisclass::QueryNonNULLMachineName() \
  143. { \
  144. ASSERT( (targ) != NULL ); \
  145. return ((CHasMachineName*)(targ))->QueryNonNULLMachineName(); \
  146. } \
  147. LPCTSTR thisclass::QueryTargetServer() \
  148. { \
  149. ASSERT( (targ) != NULL ); \
  150. return ((CHasMachineName*)(targ))->QueryTargetServer(); \
  151. } \
  152. void thisclass::SetMachineName( LPCTSTR lpcszMachineName ) \
  153. { \
  154. ASSERT( (targ) != NULL ); \
  155. ((CHasMachineName*)(targ))->SetMachineName( lpcszMachineName ); \
  156. }
  157. #define STORES_MACHINE_NAME \
  158. public: \
  159. CString m_strMachineName; \
  160. virtual void SetMachineName( LPCTSTR lpcszMachineName ) \
  161. { \
  162. m_strMachineName = lpcszMachineName; \
  163. } \
  164. virtual LPCTSTR QueryNonNULLMachineName() \
  165. { \
  166. return (LPCTSTR)m_strMachineName; \
  167. } \
  168. virtual LPCTSTR QueryTargetServer() \
  169. { \
  170. return (m_strMachineName.IsEmpty()) \
  171. ? NULL : (LPCTSTR)(m_strMachineName); \
  172. }
  173. class CStoresMachineName : public CHasMachineName
  174. {
  175. public:
  176. CStoresMachineName( LPCTSTR lpcszMachineName )
  177. : m_strMachineName( lpcszMachineName )
  178. {}
  179. STORES_MACHINE_NAME;
  180. };
  181. #endif // ~__STDCOOKI_H_INCLUDED__