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.

242 lines
4.7 KiB

  1. // WMDMStorageEnum.cpp : Implementation of CWMDMStorageEnum
  2. #include "stdafx.h"
  3. #include "mswmdm.h"
  4. #include "WMDMStorageEnum.h"
  5. #include "Storage.h"
  6. #include "loghelp.h"
  7. #include "scserver.h"
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CWMDMStorageEnum
  10. extern CSecureChannelServer *g_pAppSCServer;
  11. CWMDMStorageEnum::CWMDMStorageEnum()
  12. : m_pEnum(NULL)
  13. {
  14. GlobalAddRef();
  15. }
  16. CWMDMStorageEnum::~CWMDMStorageEnum()
  17. {
  18. if (m_pEnum)
  19. m_pEnum->Release();
  20. GlobalRelease();
  21. }
  22. // IWMDMEnumStorage
  23. HRESULT CWMDMStorageEnum::Next(ULONG celt,
  24. IWMDMStorage **ppStorage,
  25. ULONG *pceltFetched)
  26. {
  27. HRESULT hr;
  28. HRESULT hr2 = S_OK;
  29. ULONG ulX=0;
  30. IMDSPStorage **ppStorageList = NULL;
  31. CComObject<CWMDMStorage> *pStgObj = NULL;
  32. if (g_pAppSCServer)
  33. {
  34. if(!g_pAppSCServer->fIsAuthenticated())
  35. {
  36. hr = WMDM_E_NOTCERTIFIED;
  37. goto exit;
  38. }
  39. }
  40. else
  41. {
  42. hr = E_FAIL;
  43. goto exit;
  44. }
  45. if (!ppStorage || !pceltFetched || celt == 0)
  46. {
  47. hr = E_INVALIDARG;
  48. goto exit;
  49. }
  50. ppStorageList = new IMDSPStorage *[celt];
  51. if (!ppStorageList)
  52. {
  53. hr = E_OUTOFMEMORY; // @@@@ May have to be added to doc as the return status?
  54. goto exit;
  55. }
  56. memset( ppStorageList, 0, celt * sizeof(IMDSPStorage *));
  57. hr = m_pEnum->Next(celt, ppStorageList, pceltFetched);
  58. if (FAILED(hr))
  59. {
  60. goto cleanup;
  61. }
  62. for (ulX=0;ulX<*pceltFetched;ulX++)
  63. {
  64. // Rio600 SP behaves badly for celt > 1.
  65. if( ppStorageList[ulX] == NULL )
  66. {
  67. *pceltFetched = ulX;
  68. goto cleanup;
  69. }
  70. hr2 = CComObject<CWMDMStorage>::CreateInstance(&pStgObj);
  71. if (FAILED(hr2))
  72. {
  73. goto cleanup;
  74. }
  75. hr2 = pStgObj->QueryInterface(IID_IWMDMStorage, reinterpret_cast<void**>(&ppStorage[ulX]));
  76. if (FAILED(hr2))
  77. {
  78. delete pStgObj;
  79. goto cleanup;
  80. }
  81. pStgObj->SetContainedPointer(ppStorageList[ulX], m_wSPIndex);
  82. }
  83. cleanup:
  84. if (FAILED(hr2))
  85. {
  86. // We need to clean up the output array if we failed
  87. // @@@ ulX is unsigned: -1<ulX is always 0 use a signed var
  88. for (ulX--;-1<ulX;ulX--)
  89. {
  90. ppStorage[ulX]->Release();
  91. ppStorage[ulX] = NULL;
  92. }
  93. *pceltFetched=0;
  94. // If we got here then next must have succeeded but not the object creation
  95. hr = hr2;
  96. }
  97. if (*pceltFetched == 0)
  98. {
  99. *ppStorage = NULL;
  100. }
  101. for (ulX=0;ulX<*pceltFetched;ulX++)
  102. ppStorageList[ulX]->Release();
  103. if (ppStorageList)
  104. delete [] ppStorageList;
  105. exit:
  106. hrLogDWORD("IWMDMEnumStorage::Next returned 0x%08lx", hr, hr);
  107. return hr;
  108. }
  109. HRESULT CWMDMStorageEnum::Skip(ULONG celt, ULONG *pceltFetched)
  110. {
  111. HRESULT hr;
  112. if (g_pAppSCServer)
  113. {
  114. if(!g_pAppSCServer->fIsAuthenticated())
  115. {
  116. hr = WMDM_E_NOTCERTIFIED;
  117. goto exit;
  118. }
  119. }
  120. else
  121. {
  122. hr = E_FAIL;
  123. goto exit;
  124. }
  125. if (!pceltFetched || celt == 0)
  126. {
  127. hr = E_INVALIDARG;
  128. goto exit;
  129. }
  130. hr = m_pEnum->Skip(celt, pceltFetched);
  131. exit:
  132. hrLogDWORD("IWMDMEnumStorage::Skip returned 0x%08lx", hr, hr);
  133. return hr;
  134. }
  135. HRESULT CWMDMStorageEnum::Reset()
  136. {
  137. HRESULT hr;
  138. if (g_pAppSCServer)
  139. {
  140. if(!g_pAppSCServer->fIsAuthenticated())
  141. {
  142. hr = WMDM_E_NOTCERTIFIED;
  143. goto exit;
  144. }
  145. }
  146. else
  147. {
  148. hr = E_FAIL;
  149. goto exit;
  150. }
  151. hr = m_pEnum->Reset();
  152. hrLogDWORD("IWMDMEnumStorage::Reset returned 0x%08lx", hr, hr);
  153. exit:
  154. return hr;
  155. }
  156. HRESULT CWMDMStorageEnum::Clone(IWMDMEnumStorage **ppEnumStorage)
  157. {
  158. HRESULT hr;
  159. CComObject<CWMDMStorageEnum> *pEnumObj = NULL;
  160. if (g_pAppSCServer)
  161. {
  162. if(!g_pAppSCServer->fIsAuthenticated())
  163. {
  164. hr = WMDM_E_NOTCERTIFIED;
  165. goto exit;
  166. }
  167. }
  168. else
  169. {
  170. hr = E_FAIL;
  171. goto exit;
  172. }
  173. if (!ppEnumStorage)
  174. {
  175. hr = E_INVALIDARG;
  176. goto exit;
  177. }
  178. hr = CComObject<CWMDMStorageEnum>::CreateInstance(&pEnumObj);
  179. if (FAILED(hr))
  180. {
  181. goto exit;
  182. }
  183. hr = pEnumObj->QueryInterface(IID_IWMDMEnumStorage, reinterpret_cast<void**>(ppEnumStorage));
  184. if (FAILED(hr))
  185. {
  186. delete pEnumObj;
  187. goto exit;
  188. }
  189. pEnumObj->SetContainedPointer(m_pEnum, m_wSPIndex);
  190. exit:
  191. hrLogDWORD("IWMDMEnumStorage::Clone returned 0x%08lx", hr, hr);
  192. return hr;
  193. }
  194. void CWMDMStorageEnum::SetContainedPointer(IMDSPEnumStorage *pEnum, WORD wSPIndex)
  195. {
  196. m_pEnum = pEnum;
  197. m_pEnum->AddRef();
  198. m_wSPIndex = wSPIndex;
  199. return;
  200. }