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.

225 lines
6.2 KiB

  1. // P3Domain.cpp : Implementation of CP3Domain
  2. #include "stdafx.h"
  3. #include "P3Admin.h"
  4. #include "P3Domain.h"
  5. #include "P3Users.h"
  6. #include <limits.h>
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. CP3Domain::CP3Domain() :
  11. m_pIUnk(NULL), m_pAdminX(NULL)
  12. {
  13. ZeroMemory( m_sDomainName, sizeof(m_sDomainName));
  14. }
  15. CP3Domain::~CP3Domain()
  16. {
  17. if ( NULL != m_pIUnk )
  18. m_pIUnk->Release();
  19. }
  20. //////////////////////////////////////////////////////////////////////
  21. // IP3Domain
  22. //////////////////////////////////////////////////////////////////////
  23. STDMETHODIMP CP3Domain::get_Lock(BOOL *pVal)
  24. {
  25. if ( NULL == pVal ) return E_INVALIDARG;
  26. if ( NULL == m_pAdminX ) return E_POINTER;
  27. return m_pAdminX->GetDomainLock( m_sDomainName, pVal );
  28. }
  29. STDMETHODIMP CP3Domain::put_Lock(BOOL newVal)
  30. {
  31. if ( NULL == m_pAdminX ) return E_POINTER;
  32. return m_pAdminX->SetDomainLock( m_sDomainName, newVal );
  33. }
  34. STDMETHODIMP CP3Domain::get_MessageCount(long *pVal)
  35. {
  36. if ( NULL == pVal ) return E_INVALIDARG;
  37. HRESULT hr;
  38. long lMessageCount = 0, lUserMessageCount;
  39. VARIANT v;
  40. IP3Users *pIUsers;
  41. IEnumVARIANT *pIEnumVARIANT;
  42. IP3User *pIUser;
  43. *pVal = -1;
  44. VariantInit( &v );
  45. hr = get_Users( &pIUsers );
  46. if ( S_OK == hr )
  47. {
  48. hr = pIUsers->get__NewEnum( &pIEnumVARIANT );
  49. if ( S_OK == hr )
  50. {
  51. hr = pIEnumVARIANT->Next( 1, &v, NULL );
  52. while ( S_OK == hr )
  53. {
  54. if ( VT_DISPATCH == V_VT( &v ))
  55. {
  56. hr = V_DISPATCH( &v )->QueryInterface( IID_IP3User, reinterpret_cast<LPVOID*>( &pIUser ));
  57. if ( S_OK == hr )
  58. {
  59. hr = pIUser->get_MessageCount( &lUserMessageCount );
  60. if ( S_OK == hr )
  61. lMessageCount += lUserMessageCount;
  62. pIUser->Release();
  63. }
  64. }
  65. else
  66. hr = E_UNEXPECTED;
  67. VariantClear( &v );
  68. if ( S_OK == hr )
  69. hr = pIEnumVARIANT->Next( 1, &v, NULL );
  70. }
  71. if ( S_FALSE == hr ) // Reached the end of the enumeration
  72. hr = S_OK;
  73. }
  74. pIUsers->Release();
  75. }
  76. if ( S_OK == hr )
  77. *pVal = lMessageCount;
  78. return hr;
  79. }
  80. STDMETHODIMP CP3Domain::get_MessageDiskUsage(long *plFactor, long *pVal)
  81. {
  82. if ( NULL == plFactor ) return E_INVALIDARG;
  83. if ( NULL == pVal ) return E_INVALIDARG;
  84. HRESULT hr = S_OK;
  85. long lDiskUsage, lFactor;
  86. __int64 i64DiskUsage = 0;
  87. VARIANT v;
  88. IP3Users *pIUsers;
  89. IEnumVARIANT *pIEnumVARIANT;
  90. IP3User *pIUser;
  91. *pVal = -1;
  92. VariantInit( &v );
  93. hr = get_Users( &pIUsers );
  94. if ( S_OK == hr )
  95. {
  96. hr = pIUsers->get__NewEnum( &pIEnumVARIANT );
  97. if ( S_OK == hr )
  98. {
  99. hr = pIEnumVARIANT->Next( 1, &v, NULL );
  100. while ( S_OK == hr )
  101. {
  102. if ( VT_DISPATCH == V_VT( &v ))
  103. {
  104. hr = V_DISPATCH( &v )->QueryInterface( IID_IP3User, reinterpret_cast<LPVOID*>( &pIUser ));
  105. if ( S_OK == hr )
  106. {
  107. hr = pIUser->get_MessageDiskUsage( &lFactor, &lDiskUsage );
  108. if ( S_OK == hr )
  109. i64DiskUsage += (lDiskUsage * lFactor);
  110. pIUser->Release();
  111. }
  112. }
  113. else
  114. hr = E_UNEXPECTED;
  115. VariantClear( &v );
  116. if ( S_OK == hr )
  117. hr = pIEnumVARIANT->Next( 1, &v, NULL );
  118. }
  119. if ( S_FALSE == hr ) // Reached the end of the enumeration
  120. hr = S_OK;
  121. }
  122. pIUsers->Release();
  123. }
  124. lFactor = 1;
  125. while ( i64DiskUsage > INT_MAX )
  126. {
  127. lFactor *= 10;
  128. i64DiskUsage = i64DiskUsage / 10;
  129. }
  130. *plFactor = lFactor;
  131. *pVal = static_cast<int>( i64DiskUsage );
  132. return hr;
  133. }
  134. // VB Script can't use the property above!
  135. STDMETHODIMP CP3Domain::GetMessageDiskUsage(VARIANT *pvFactor, VARIANT *pvValue)
  136. {
  137. if ( NULL == pvValue ) return E_INVALIDARG;
  138. HRESULT hr;
  139. long lFactor, lValue;
  140. VariantInit( pvFactor );
  141. VariantInit( pvValue );
  142. hr = get_MessageDiskUsage( &lFactor, &lValue );
  143. if ( S_OK == hr )
  144. {
  145. V_VT( pvFactor ) = VT_I4;
  146. V_I4( pvFactor ) = lFactor;
  147. V_VT( pvValue ) = VT_I4;
  148. V_I4( pvValue ) = lValue;
  149. }
  150. return hr;
  151. }
  152. STDMETHODIMP CP3Domain::get_Name(BSTR *pVal)
  153. {
  154. if ( NULL == pVal ) return E_INVALIDARG;
  155. *pVal = SysAllocString( m_sDomainName );
  156. return S_OK;
  157. }
  158. STDMETHODIMP CP3Domain::get_Users(IP3Users **ppIUsers)
  159. {
  160. if ( NULL == ppIUsers ) return E_INVALIDARG;
  161. HRESULT hr;
  162. LPUNKNOWN pIUnk;
  163. CComObject<CP3Users> *p;
  164. hr = CComObject<CP3Users>::CreateInstance( &p ); // Reference count still 0
  165. if SUCCEEDED( hr )
  166. {
  167. hr = m_pIUnk->QueryInterface(IID_IUnknown, reinterpret_cast<LPVOID*>( &pIUnk ));
  168. if SUCCEEDED( hr )
  169. {
  170. hr = p->Init( pIUnk, m_pAdminX, m_sDomainName );
  171. if SUCCEEDED( hr )
  172. hr = p->QueryInterface(IID_IP3Users, reinterpret_cast<void**>( ppIUsers ));
  173. }
  174. if FAILED( hr )
  175. delete p; // Release
  176. }
  177. return hr;
  178. }
  179. //////////////////////////////////////////////////////////////////////
  180. // Implementation: public
  181. //////////////////////////////////////////////////////////////////////
  182. HRESULT CP3Domain::Init(IUnknown *pIUnk, CP3AdminWorker *p, LPWSTR psDomainName )
  183. {
  184. if ( NULL == pIUnk ) return E_INVALIDARG;
  185. if ( NULL == p ) return E_INVALIDARG;
  186. if ( NULL == psDomainName ) return E_INVALIDARG;
  187. m_pIUnk = pIUnk;
  188. m_pAdminX = p;
  189. wcsncpy( m_sDomainName, psDomainName, sizeof(m_sDomainName)/sizeof(WCHAR)-1);
  190. return S_OK;
  191. }