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.

147 lines
3.3 KiB

  1. //Implementation of CAuthMethods class
  2. #include "stdafx.h"
  3. #include "Pop3Auth.h"
  4. #include "AuthMethodsEnum.h"
  5. #include <pop3regkeys.h>
  6. CAuthMethodsEnum::CAuthMethodsEnum()
  7. {
  8. m_pAuthVector=NULL;
  9. m_ulCurrentMethod=0;
  10. }
  11. CAuthMethodsEnum::~CAuthMethodsEnum()
  12. {
  13. }
  14. /////////////////////////////////////////////////////////////////////////////
  15. // IEnumVARIANT
  16. STDMETHODIMP CAuthMethodsEnum::Next( /* [in] */ ULONG celt, /* [length_is][size_is][out] */ VARIANT __RPC_FAR *rgVar, /* [out] */ ULONG __RPC_FAR *pCeltFetched)
  17. {
  18. if ( NULL == rgVar || ( 1 != celt && NULL == pCeltFetched ))
  19. return E_POINTER;
  20. if ( NULL == m_pAuthVector )
  21. {
  22. return E_FAIL;
  23. }
  24. if( celt == 0 )
  25. {
  26. return E_INVALIDARG;
  27. }
  28. VARIANT vResult;
  29. VariantInit(&vResult);
  30. HRESULT hr=E_FAIL;
  31. while(m_ulCurrentMethod < m_pAuthVector->size() )
  32. {
  33. if( ! ((*m_pAuthVector)[m_ulCurrentMethod]->bIsValid) )
  34. {
  35. m_ulCurrentMethod++;
  36. }
  37. }
  38. if(m_ulCurrentMethod < m_pAuthVector->size())
  39. {
  40. V_VT( &vResult ) = VT_DISPATCH;
  41. hr=((*m_pAuthVector)[m_ulCurrentMethod])->pIAuthMethod->
  42. QueryInterface(IID_IDispatch,reinterpret_cast<void**>( &V_DISPATCH( &vResult ) ) );
  43. if(SUCCEEDED(hr))
  44. {
  45. hr=VariantCopy(rgVar, &vResult);
  46. if(SUCCEEDED(hr))
  47. {
  48. if(pCeltFetched)
  49. {
  50. *pCeltFetched=1;
  51. }
  52. if(celt > 1)
  53. {
  54. hr=S_FALSE;
  55. }
  56. m_ulCurrentMethod++;
  57. }
  58. else
  59. {
  60. VariantClear(&vResult);
  61. }
  62. }
  63. }
  64. return hr;
  65. }
  66. STDMETHODIMP CAuthMethodsEnum::Skip(ULONG celt)
  67. {
  68. HRESULT hr = S_OK;
  69. ULONG ulSize;
  70. if(m_pAuthVector != NULL)
  71. {
  72. ulSize=m_pAuthVector->size();
  73. if(ulSize < celt + m_ulCurrentMethod )
  74. {
  75. m_ulCurrentMethod+=celt;
  76. }
  77. else
  78. {
  79. m_ulCurrentMethod=ulSize;
  80. }
  81. }
  82. return hr;
  83. }
  84. STDMETHODIMP CAuthMethodsEnum::Reset(void)
  85. {
  86. m_ulCurrentMethod=0;
  87. return S_OK;
  88. }
  89. STDMETHODIMP CAuthMethodsEnum::Clone( /* [out] */ IEnumVARIANT __RPC_FAR *__RPC_FAR *ppEnum)
  90. {
  91. if ( NULL == ppEnum )
  92. {
  93. return E_POINTER;
  94. }
  95. if ( NULL == m_pAuthVector)
  96. {
  97. return E_FAIL;
  98. }
  99. HRESULT hr=S_OK;
  100. CComObject<CAuthMethodsEnum> *pAuthEnum;
  101. *ppEnum=NULL;
  102. hr = CComObject<CAuthMethodsEnum>::CreateInstance(&pAuthEnum); // Reference count still 0
  103. if(SUCCEEDED(hr))
  104. {
  105. hr=pAuthEnum->Init(m_pAuthVector);
  106. if(SUCCEEDED(hr))
  107. {
  108. hr=pAuthEnum->QueryInterface(IID_IEnumVARIANT,(void **)(ppEnum) );
  109. if(FAILED(hr))
  110. {
  111. delete(pAuthEnum);
  112. }
  113. }
  114. if(FAILED(hr))
  115. {
  116. delete(pAuthEnum);
  117. }
  118. }
  119. return hr;
  120. }
  121. HRESULT CAuthMethodsEnum::Init( AUTHVECTOR *pAuthVector )
  122. {
  123. if(NULL==pAuthVector)
  124. {
  125. return E_INVALIDARG;
  126. }
  127. m_ulCurrentMethod=0;
  128. m_pAuthVector=pAuthVector;
  129. return S_OK;
  130. }