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.

159 lines
4.8 KiB

  1. // P3UserEnum.cpp : Implementation of CP3UserEnum
  2. #include "stdafx.h"
  3. #include "P3Admin.h"
  4. #include "P3UserEnum.h"
  5. #include "P3User.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CP3UserEnum
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CP3UserEnum::CP3UserEnum() :
  12. m_pIUnk(NULL), m_pAdminX(NULL), m_hfSearch(INVALID_HANDLE_VALUE)
  13. {
  14. ZeroMemory( m_sDomainName, sizeof(m_sDomainName));
  15. }
  16. CP3UserEnum::~CP3UserEnum()
  17. {
  18. if ( NULL != m_pIUnk )
  19. m_pIUnk->Release();
  20. if ( INVALID_HANDLE_VALUE != m_hfSearch )
  21. FindClose( m_hfSearch );
  22. }
  23. /////////////////////////////////////////////////////////////////////////////
  24. // IEnumVARIANT
  25. STDMETHODIMP CP3UserEnum::Next( /* [in] */ ULONG celt, /* [length_is][size_is][out] */ VARIANT __RPC_FAR *rgVar, /* [out] */ ULONG __RPC_FAR *pCeltFetched)
  26. {
  27. if ( NULL == rgVar || ( 1 != celt && NULL == pCeltFetched ))
  28. return E_POINTER;
  29. if ( NULL == m_pAdminX ) return E_POINTER;
  30. ULONG nActual = 0;
  31. HRESULT hr = S_OK;
  32. VARIANT __RPC_FAR *pVar = rgVar;
  33. VARIANT v;
  34. WCHAR sBuffer[POP3_MAX_PATH];
  35. LPWSTR ps = NULL;
  36. IUnknown *pIUnk;
  37. CComObject<CP3User> *p;
  38. WIN32_FIND_DATA stFindData;
  39. VariantInit( &v );
  40. if ( S_OK == hr )
  41. {
  42. if ( INVALID_HANDLE_VALUE == m_hfSearch )
  43. hr = m_pAdminX->InitFindFirstUser( m_hfSearch, m_sDomainName, sBuffer, sizeof( sBuffer )/sizeof(WCHAR) );
  44. else
  45. hr = m_pAdminX->GetNextUser( m_hfSearch, m_sDomainName, sBuffer, sizeof( sBuffer )/sizeof(WCHAR) );
  46. }
  47. if ( S_OK == hr )
  48. {
  49. hr = CComObject<CP3User>::CreateInstance( &p ); // Reference count still 0
  50. if SUCCEEDED( hr )
  51. {
  52. // Increment the reference count on the source object and pass it to the new object
  53. hr = m_pIUnk->QueryInterface(IID_IUnknown, reinterpret_cast<LPVOID*>( &pIUnk ));
  54. if SUCCEEDED( hr )
  55. {
  56. hr = p->Init( pIUnk, m_pAdminX, m_sDomainName, sBuffer );
  57. if SUCCEEDED( hr )
  58. {
  59. V_VT( &v ) = VT_DISPATCH;
  60. hr = p->QueryInterface(IID_IDispatch, reinterpret_cast<void**>( &V_DISPATCH( &v )));
  61. if SUCCEEDED( hr )
  62. hr = VariantCopy( pVar, &v );
  63. VariantClear( &v );
  64. nActual++;
  65. }
  66. }
  67. if FAILED( hr )
  68. delete p;
  69. }
  70. }
  71. if (pCeltFetched)
  72. *pCeltFetched = nActual;
  73. if (SUCCEEDED(hr) && (nActual < celt))
  74. hr = S_FALSE;
  75. return hr;
  76. }
  77. STDMETHODIMP CP3UserEnum::Skip(ULONG celt)
  78. {
  79. if ( NULL == m_pAdminX ) return E_POINTER;
  80. HRESULT hr = S_OK;
  81. WCHAR sBuffer[POP3_MAX_PATH];
  82. WIN32_FIND_DATA stFindData;
  83. while ( (S_OK == hr) && (0 < celt) )
  84. {
  85. hr = m_pAdminX->GetNextUser( m_hfSearch, m_sDomainName, sBuffer, sizeof( sBuffer )/sizeof(WCHAR) );
  86. celt--;
  87. }
  88. return hr;
  89. }
  90. STDMETHODIMP CP3UserEnum::Reset(void)
  91. {
  92. CloseHandle( m_hfSearch );
  93. m_hfSearch = INVALID_HANDLE_VALUE;
  94. return S_OK;
  95. }
  96. STDMETHODIMP CP3UserEnum::Clone( /* [out] */ IEnumVARIANT __RPC_FAR *__RPC_FAR *ppEnum)
  97. {
  98. if ( NULL == ppEnum ) return E_INVALIDARG;
  99. if ( NULL == m_pAdminX ) return E_POINTER;
  100. HRESULT hr;
  101. LPUNKNOWN pIUnk;
  102. CComObject<CP3UserEnum> *p;
  103. *ppEnum = NULL;
  104. hr = CComObject<CP3UserEnum>::CreateInstance(&p); // Reference count still 0
  105. if SUCCEEDED( hr )
  106. { // Increment the reference count on the source object and pass it to the new enumerator
  107. hr = m_pIUnk->QueryInterface(IID_IUnknown, reinterpret_cast<LPVOID*>( &pIUnk ));
  108. if SUCCEEDED( hr )
  109. {
  110. hr = p->Init( pIUnk, m_pAdminX, m_sDomainName ); // p must call release on pIUnk when done.
  111. if SUCCEEDED( hr )
  112. hr = p->QueryInterface( IID_IUnknown, reinterpret_cast<LPVOID*>( ppEnum ));
  113. }
  114. if FAILED( hr )
  115. delete p; // Release
  116. }
  117. return hr;
  118. }
  119. //////////////////////////////////////////////////////////////////////
  120. // Implementation: public
  121. HRESULT CP3UserEnum::Init(IUnknown *pIUnk, CP3AdminWorker *p, LPCWSTR psDomainName )
  122. {
  123. if ( NULL == pIUnk )
  124. return E_INVALIDARG;
  125. if ( NULL == p )
  126. return E_INVALIDARG;
  127. if ( NULL == psDomainName )
  128. return E_INVALIDARG;
  129. HRESULT hr = S_OK;
  130. m_pIUnk = pIUnk;
  131. m_pAdminX = p;
  132. wcsncpy( m_sDomainName, psDomainName, sizeof( m_sDomainName )/sizeof(WCHAR) );
  133. return hr;
  134. }