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.

191 lines
4.9 KiB

  1. #include "pch.hxx"
  2. #include "syncop.h"
  3. #include "sync.h"
  4. #include "enumsync.h"
  5. //--------------------------------------------------------------------------
  6. // CEnumerateSyncOps::CEnumerateSyncOps
  7. //--------------------------------------------------------------------------
  8. CEnumerateSyncOps::CEnumerateSyncOps(void)
  9. {
  10. m_cRef = 1;
  11. m_pid = NULL;
  12. m_iid = 0;
  13. m_cid = 0;
  14. m_cidBuf = 0;
  15. m_pDB = NULL;
  16. m_idServer = FOLDERID_INVALID;
  17. }
  18. //--------------------------------------------------------------------------
  19. // CEnumerateSyncOps::~CEnumerateSyncOps
  20. //--------------------------------------------------------------------------
  21. CEnumerateSyncOps::~CEnumerateSyncOps(void)
  22. {
  23. SafeMemFree(m_pid);
  24. SafeRelease(m_pDB);
  25. }
  26. //--------------------------------------------------------------------------
  27. // CEnumerateSyncOps::QueryInterface
  28. //--------------------------------------------------------------------------
  29. STDMETHODIMP CEnumerateSyncOps::QueryInterface(REFIID riid, LPVOID *ppv)
  30. {
  31. if (IID_IUnknown == riid)
  32. *ppv = (IUnknown *)this;
  33. else
  34. {
  35. *ppv = NULL;
  36. return(E_NOINTERFACE);
  37. }
  38. ((IUnknown *)*ppv)->AddRef();
  39. return(S_OK);
  40. }
  41. //--------------------------------------------------------------------------
  42. // CEnumerateSyncOps::AddRef
  43. //--------------------------------------------------------------------------
  44. STDMETHODIMP_(ULONG) CEnumerateSyncOps::AddRef(void)
  45. {
  46. return InterlockedIncrement(&m_cRef);
  47. }
  48. //--------------------------------------------------------------------------
  49. // CEnumerateSyncOps::Release
  50. //--------------------------------------------------------------------------
  51. STDMETHODIMP_(ULONG) CEnumerateSyncOps::Release(void)
  52. {
  53. LONG cRef = InterlockedDecrement(&m_cRef);
  54. if (0 == cRef)
  55. delete this;
  56. return (ULONG)cRef;
  57. }
  58. //--------------------------------------------------------------------------
  59. // CEnumerateSyncOps::Initialize
  60. //--------------------------------------------------------------------------
  61. HRESULT CEnumerateSyncOps::Initialize(IDatabase *pDB, FOLDERID idServer)
  62. {
  63. SYNCOPINFO info;
  64. HROWSET hRowset;
  65. DWORD cBuf;
  66. HRESULT hr;
  67. ROWORDINAL iRow;
  68. Assert(pDB);
  69. Assert(idServer != m_idServer);
  70. // Save parent
  71. m_idServer = idServer;
  72. // Save pStore
  73. if (m_pDB != NULL)
  74. m_pDB->Release();
  75. m_pDB = pDB;
  76. m_pDB->AddRef();
  77. m_iid = 0;
  78. m_cid = 0;
  79. ZeroMemory(&info, sizeof(SYNCOPINFO));
  80. info.idServer = idServer;
  81. hr = m_pDB->FindRecord(IINDEX_ALL, 1, &info, &iRow);
  82. if (hr != DB_S_FOUND)
  83. return(S_OK);
  84. m_pDB->FreeRecord(&info);
  85. hr = m_pDB->CreateRowset(IINDEX_ALL, NOFLAGS, &hRowset);
  86. if (FAILED(hr))
  87. return(hr);
  88. hr = m_pDB->SeekRowset(hRowset, SEEK_ROWSET_BEGIN, iRow - 1, NULL);
  89. if (SUCCEEDED(hr))
  90. {
  91. while (S_OK == m_pDB->QueryRowset(hRowset, 1, (LPVOID *)&info, NULL))
  92. {
  93. if (info.idServer != idServer)
  94. {
  95. m_pDB->FreeRecord(&info);
  96. break;
  97. }
  98. if (m_cid == m_cidBuf)
  99. {
  100. cBuf = m_cidBuf + 256;
  101. if (!MemRealloc((void **)&m_pid, cBuf * sizeof(SYNCOPID)))
  102. {
  103. m_pDB->FreeRecord(&info);
  104. hr = E_OUTOFMEMORY;
  105. break;
  106. }
  107. m_cidBuf = cBuf;
  108. }
  109. m_pid[m_cid] = info.idOperation;
  110. m_cid++;
  111. m_pDB->FreeRecord(&info);
  112. }
  113. }
  114. m_pDB->CloseRowset(&hRowset);
  115. return(hr);
  116. }
  117. //--------------------------------------------------------------------------
  118. // CEnumerateSyncOps::Next
  119. //--------------------------------------------------------------------------
  120. STDMETHODIMP CEnumerateSyncOps::Next(LPSYNCOPINFO pInfo)
  121. {
  122. HRESULT hr;
  123. // Validate
  124. Assert(m_pDB != NULL);
  125. Assert(pInfo != NULL);
  126. if (m_iid >= m_cid)
  127. return(S_FALSE);
  128. ZeroMemory(pInfo, sizeof(SYNCOPINFO));
  129. pInfo->idOperation = m_pid[m_iid++];
  130. // Locate where the first record with idParent
  131. hr = m_pDB->FindRecord(IINDEX_PRIMARY, 1, pInfo, NULL);
  132. // Not Found
  133. if (DB_S_NOTFOUND == hr)
  134. hr = E_FAIL;
  135. else if (SUCCEEDED(hr))
  136. hr = S_OK;
  137. return(hr);
  138. }
  139. //--------------------------------------------------------------------------
  140. // CEnumerateSyncOps::Release
  141. //--------------------------------------------------------------------------
  142. STDMETHODIMP CEnumerateSyncOps::Count(ULONG *pcItems)
  143. {
  144. Assert(pcItems != NULL);
  145. *pcItems = m_cid;
  146. return(S_OK);
  147. }
  148. STDMETHODIMP CEnumerateSyncOps::Reset()
  149. {
  150. m_iid = 0;
  151. return(S_OK);
  152. }
  153. STDMETHODIMP CEnumerateSyncOps::Skip(ULONG cItems)
  154. {
  155. m_iid += cItems;
  156. return(S_OK);
  157. }