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
5.7 KiB

  1. /*++
  2. Module Name:
  3. RepEnum.cpp
  4. Abstract:
  5. This file contains the Implementation of the Class CReplicaEnum.
  6. This class implements the IEnumVARIANT which enumerates DfsReplicas.
  7. --*/
  8. #include "stdafx.h"
  9. #include "DfsCore.h"
  10. #include "DfsRep.h"
  11. #include "RepEnum.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. // ~CReplicaEnum
  14. CReplicaEnum :: ~CReplicaEnum()
  15. {
  16. _FreeMemberVariables();
  17. }
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Initialize
  20. STDMETHODIMP CReplicaEnum :: Initialize
  21. (
  22. REPLICAINFOLIST* i_priList,
  23. BSTR i_bstrEntryPath
  24. )
  25. {
  26. /*++
  27. Routine Description:
  28. Initializes the ReplicaEnum object.
  29. It copies the replica list passed to it by the junction point
  30. object. Sorting is done during the copying.
  31. --*/
  32. if (!i_priList || !i_bstrEntryPath)
  33. return E_INVALIDARG;
  34. _FreeMemberVariables();
  35. HRESULT hr = S_OK;
  36. do {
  37. m_bstrEntryPath = i_bstrEntryPath;
  38. BREAK_OUTOFMEMORY_IF_NULL((BSTR)m_bstrEntryPath, &hr);
  39. REPLICAINFOLIST::iterator i;
  40. REPLICAINFOLIST::iterator j;
  41. for (i = i_priList->begin(); i != i_priList->end(); i++)
  42. {
  43. // Find insertion position.
  44. for (j = m_Replicas.begin(); j != m_Replicas.end(); j++)
  45. {
  46. if (lstrcmpi((*i)->m_bstrServerName, (*j)->m_bstrServerName) < 0 ||
  47. lstrcmpi((*i)->m_bstrShareName, (*j)->m_bstrShareName) <= 0)
  48. break;
  49. }
  50. REPLICAINFO* pTemp = (*i)->Copy();
  51. BREAK_OUTOFMEMORY_IF_NULL(pTemp, &hr);
  52. m_Replicas.insert(j, pTemp);
  53. }
  54. } while (0);
  55. if (SUCCEEDED(hr))
  56. m_iCurrentInEnumOfReplicas = m_Replicas.begin();
  57. else
  58. _FreeMemberVariables();
  59. return hr;
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // IEnumVariant Methods
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Next
  65. STDMETHODIMP CReplicaEnum :: Next
  66. (
  67. ULONG i_ulNumOfReplicas, // Number of replicas to fetch
  68. VARIANT * o_pIReplicaArray, // VARIANT array to return fetched replicas.
  69. ULONG * o_ulNumOfReplicasFetched // Return the number of replicas fetched.
  70. )
  71. {
  72. /*++
  73. Routine Description:
  74. Gets the next object in the list.
  75. Arguments:
  76. i_ulNumOfReplicas - the number of replicas to return
  77. o_pIReplicaArray - an array of variants in which to return the replicas
  78. o_ulNumOfReplicasFetched - the number of replicas that are actually returned
  79. --*/
  80. if (!i_ulNumOfReplicas || !o_pIReplicaArray)
  81. return E_INVALIDARG;
  82. HRESULT hr = S_OK;
  83. ULONG nCount = 0; //Count of Elements Fetched.
  84. IDfsReplica *pIReplicaPtr = NULL;
  85. // Create replica object using the internal replica list.
  86. for (nCount = 0;
  87. nCount < i_ulNumOfReplicas && m_iCurrentInEnumOfReplicas != m_Replicas.end();
  88. m_iCurrentInEnumOfReplicas++)
  89. {
  90. // Create a replica object.
  91. hr = CoCreateInstance(CLSID_DfsReplica, NULL, CLSCTX_INPROC_SERVER,
  92. IID_IDfsReplica, (void **)&pIReplicaPtr);
  93. BREAK_IF_FAILED(hr);
  94. //Initialize the replica object.
  95. hr = pIReplicaPtr->Initialize(m_bstrEntryPath,
  96. (*m_iCurrentInEnumOfReplicas)->m_bstrServerName,
  97. (*m_iCurrentInEnumOfReplicas)->m_bstrShareName,
  98. (*m_iCurrentInEnumOfReplicas)->m_lDfsStorageState);
  99. if (FAILED(hr))
  100. {
  101. pIReplicaPtr->Release();
  102. break;
  103. }
  104. V_VT (&o_pIReplicaArray[nCount]) = VT_DISPATCH;
  105. o_pIReplicaArray[nCount].pdispVal = pIReplicaPtr;
  106. nCount++;
  107. }
  108. //VB does not send o_ulNumOfReplicasFetched;
  109. if (o_ulNumOfReplicasFetched)
  110. *o_ulNumOfReplicasFetched = nCount;
  111. if (SUCCEEDED(hr) && !nCount)
  112. return S_FALSE;
  113. else
  114. return hr;
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. // Skip
  118. STDMETHODIMP CReplicaEnum :: Skip
  119. (
  120. ULONG i_ulReplicasToSkip //Number of items to skip.
  121. )
  122. {
  123. /*++
  124. Routine Description:
  125. Skips the next 'n' objects in the list.
  126. Arguments:
  127. i_ulReplicasToSkip - the number of objects to skip over
  128. Return value:
  129. S_OK, On success
  130. S_FALSE, if the end of the list is reached
  131. --*/
  132. for (unsigned int j = 0; j < i_ulReplicasToSkip && m_iCurrentInEnumOfReplicas != m_Replicas.end(); j++)
  133. {
  134. m_iCurrentInEnumOfReplicas++;
  135. }
  136. return (m_iCurrentInEnumOfReplicas != m_Replicas.end()) ? S_OK : S_FALSE;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // Reset
  140. STDMETHODIMP CReplicaEnum :: Reset()
  141. {
  142. /*++
  143. Routine Description:
  144. Resets the current enumeration pointer to the start of the list
  145. --*/
  146. m_iCurrentInEnumOfReplicas = m_Replicas.begin();
  147. return S_OK;
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. // Clone
  151. STDMETHODIMP CReplicaEnum :: Clone
  152. (
  153. IEnumVARIANT **o_ppEnum //Return IEnumVARIANT pointer.
  154. )
  155. {
  156. /*++
  157. Routine Description:
  158. Creates a clone of the enumerator object
  159. Arguments:
  160. o_ppEnum - address of the pointer to the IEnumVARIANT interface
  161. of the newly created enumerator object
  162. Notes:
  163. This has not been implemented.
  164. --*/
  165. return E_NOTIMPL;
  166. }