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.

275 lines
7.4 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. sxsasmcache.cpp
  5. Abstract:
  6. CAssemblyCache implementation for installation
  7. Author:
  8. Xiaoyu Wu (xiaoyuw) April 2000
  9. Revision History:
  10. xiaoyuw 10/26/2000 revise during Bate2 code review period
  11. xiaoyuw 12/21/2000 using new API
  12. --*/
  13. #include "stdinc.h"
  14. #include "fusionbuffer.h"
  15. #include "sxsp.h"
  16. #include "sxsasmitem.h"
  17. #include "sxsasmcache.h"
  18. #include "sxsasmname.h"
  19. #include "fusiontrace.h"
  20. STDAPI
  21. CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved)
  22. {
  23. HRESULT hr = NOERROR;
  24. FN_TRACE_HR(hr);
  25. CSmartPtr<CAssemblyCache> pAsmCache;
  26. if (ppAsmCache != NULL)
  27. *ppAsmCache = NULL;
  28. PARAMETER_CHECK(ppAsmCache != NULL);
  29. IFW32FALSE_EXIT(pAsmCache.Win32Allocate(__FILE__, __LINE__));
  30. IFCOMFAILED_EXIT(pAsmCache->QueryInterface(IID_IAssemblyCache, (PVOID*)ppAsmCache));
  31. pAsmCache.Detach();
  32. hr = NOERROR;
  33. Exit:
  34. return hr;
  35. }
  36. // Fusion -> Sxs
  37. BOOL
  38. SxspTranslateReferenceFrom(
  39. IN LPCFUSION_INSTALL_REFERENCE pFusionReference,
  40. OUT SXS_INSTALL_REFERENCEW &SxsReference
  41. )
  42. {
  43. FN_PROLOG_WIN32
  44. PARAMETER_CHECK(pFusionReference != NULL);
  45. PARAMETER_CHECK(pFusionReference->cbSize <= SxsReference.cbSize);
  46. if (RTL_CONTAINS_FIELD(pFusionReference, pFusionReference->cbSize, guidScheme) &&
  47. RTL_CONTAINS_FIELD(&SxsReference, SxsReference.cbSize, guidScheme))
  48. SxsReference.guidScheme = pFusionReference->guidScheme;
  49. if (RTL_CONTAINS_FIELD(pFusionReference, pFusionReference->cbSize, szIdentifier) &&
  50. RTL_CONTAINS_FIELD(&SxsReference, SxsReference.cbSize, lpIdentifier))
  51. SxsReference.lpIdentifier = pFusionReference->szIdentifier;
  52. if (RTL_CONTAINS_FIELD(pFusionReference, pFusionReference->cbSize, szNonCannonicalData) &&
  53. RTL_CONTAINS_FIELD(&SxsReference, SxsReference.cbSize, lpNonCanonicalData))
  54. SxsReference.lpNonCanonicalData = pFusionReference->szNonCannonicalData;
  55. FN_EPILOG
  56. }
  57. // Sxs -> Fusion
  58. BOOL
  59. SxspTranslateReferenceFrom(
  60. IN PCSXS_INSTALL_REFERENCEW pSxsReference,
  61. OUT FUSION_INSTALL_REFERENCE &FusionReference
  62. )
  63. {
  64. FN_PROLOG_WIN32
  65. //
  66. // Pointer must be non-null, and the SXS structure must be either
  67. // the same size or smaller than the equivalent Fusion structure.
  68. //
  69. PARAMETER_CHECK(pSxsReference);
  70. //
  71. // Assume size has been set by caller.
  72. //
  73. PARAMETER_CHECK(pSxsReference->cbSize <= FusionReference.cbSize);
  74. if (RTL_CONTAINS_FIELD(&FusionReference, FusionReference.cbSize, guidScheme) &&
  75. RTL_CONTAINS_FIELD(pSxsReference, pSxsReference->cbSize, guidScheme))
  76. FusionReference.guidScheme = pSxsReference->guidScheme;
  77. if (RTL_CONTAINS_FIELD(&FusionReference, FusionReference.cbSize, szIdentifier) &&
  78. RTL_CONTAINS_FIELD(pSxsReference, pSxsReference->cbSize, lpIdentifier))
  79. FusionReference.szIdentifier = pSxsReference->lpIdentifier;
  80. if (RTL_CONTAINS_FIELD(&FusionReference, FusionReference.cbSize, szNonCannonicalData) &&
  81. RTL_CONTAINS_FIELD(pSxsReference, pSxsReference->cbSize, lpNonCanonicalData))
  82. FusionReference.szNonCannonicalData = pSxsReference->lpNonCanonicalData;
  83. FN_EPILOG
  84. }
  85. STDMETHODIMP
  86. CAssemblyCache::UninstallAssembly(
  87. /* [in] */ DWORD dwFlags,
  88. /* [in] */ LPCWSTR pszAssemblyName,
  89. /* [in] */ LPCFUSION_INSTALL_REFERENCE pRefData,
  90. /* [out, optional] */ ULONG *pulDisposition)
  91. {
  92. HRESULT hr=S_OK;
  93. FN_TRACE_HR(hr);
  94. SXS_UNINSTALLW Uninstall;
  95. SXS_INSTALL_REFERENCEW Reference = { sizeof(Reference) };
  96. DWORD dwDisposition;
  97. if (pulDisposition != NULL)
  98. *pulDisposition = 0;
  99. PARAMETER_CHECK((pszAssemblyName!= NULL) && (dwFlags ==0));
  100. ZeroMemory(&Uninstall, sizeof(Uninstall));
  101. Uninstall.cbSize = sizeof(Uninstall);
  102. Uninstall.lpAssemblyIdentity = pszAssemblyName;
  103. if (pRefData != NULL)
  104. {
  105. IFW32FALSE_EXIT(::SxspTranslateReferenceFrom(pRefData, Reference));
  106. Uninstall.lpInstallReference = &Reference;
  107. Uninstall.dwFlags |= SXS_UNINSTALL_FLAG_REFERENCE_VALID;
  108. }
  109. IFW32FALSE_EXIT(::SxsUninstallW(&Uninstall, &dwDisposition));
  110. if (pulDisposition != NULL)
  111. *pulDisposition = static_cast<DWORD>(dwDisposition);
  112. FN_EPILOG
  113. }
  114. STDMETHODIMP CAssemblyCache::QueryAssemblyInfo(
  115. /* [in] */ DWORD dwFlags,
  116. /* [in] */ LPCWSTR pwzTextualAssembly,
  117. /* [in, out] */ ASSEMBLY_INFO *pAsmInfo)
  118. {
  119. HRESULT hr = NOERROR;
  120. FN_TRACE_HR(hr);
  121. PARAMETER_CHECK(((dwFlags == 0) && (pwzTextualAssembly !=NULL)));
  122. IFW32FALSE_EXIT(::SxsQueryAssemblyInfo(dwFlags, pwzTextualAssembly, pAsmInfo));
  123. hr = NOERROR;
  124. Exit:
  125. return hr;
  126. }
  127. STDMETHODIMP
  128. CAssemblyCache::CreateAssemblyCacheItem(
  129. /* [in] */ DWORD dwFlags,
  130. /* [in] */ PVOID pvReserved,
  131. /* [out] */ IAssemblyCacheItem **ppAsmItem,
  132. /* [in, optional] */ LPCWSTR pszAssemblyName) // uncanonicalized, comma separted name=value pairs.
  133. {
  134. HRESULT hr = NOERROR;
  135. FN_TRACE_HR(hr);
  136. CSmartPtr<CAssemblyCacheItem> pAsmItem;
  137. if (ppAsmItem != NULL)
  138. *ppAsmItem = NULL;
  139. PARAMETER_CHECK((ppAsmItem != NULL) && (dwFlags == 0) && (pvReserved == NULL));
  140. IFW32FALSE_EXIT(pAsmItem.Win32Allocate(__FILE__, __LINE__));
  141. IFCOMFAILED_EXIT(pAsmItem->Initialize());
  142. IFCOMFAILED_EXIT(pAsmItem->QueryInterface(IID_IAssemblyCacheItem, (PVOID*)ppAsmItem));
  143. pAsmItem.Detach(); // void
  144. hr = NOERROR;
  145. Exit:
  146. return hr;
  147. }
  148. STDMETHODIMP
  149. CAssemblyCache::InstallAssembly(
  150. /* [in] */ DWORD dwFlags,
  151. /* [in] */ LPCWSTR pszManifestPath,
  152. /* [in] */ LPCFUSION_INSTALL_REFERENCE pRefData)
  153. {
  154. HRESULT hr = NOERROR;
  155. FN_TRACE_HR(hr);
  156. SXS_INSTALLW Install = { sizeof(SXS_INSTALLW) };
  157. SXS_INSTALL_REFERENCEW Reference = { sizeof(Reference) };
  158. PARAMETER_CHECK((pszManifestPath != NULL) && (dwFlags == 0));
  159. Install.lpManifestPath = pszManifestPath;
  160. if ( pRefData == NULL )
  161. {
  162. Install.dwFlags = SXS_INSTALL_FLAG_INSTALLED_BY_DARWIN;
  163. }
  164. else
  165. {
  166. //
  167. // Otherwise, the pvReserved is really a "reference"
  168. //
  169. Install.dwFlags |= SXS_INSTALL_FLAG_REFERENCE_VALID;
  170. IFW32FALSE_EXIT(::SxspTranslateReferenceFrom(pRefData, Reference));
  171. Install.lpReference = &Reference;
  172. }
  173. IFW32FALSE_EXIT(::SxsInstallW(&Install));
  174. FN_EPILOG
  175. }
  176. STDMETHODIMP
  177. CAssemblyCache::CreateAssemblyScavenger(
  178. IAssemblyScavenger **ppAsmScavenger )
  179. {
  180. return E_NOTIMPL;
  181. }
  182. //
  183. // IUnknown boilerplate...
  184. //
  185. STDMETHODIMP
  186. CAssemblyCache::QueryInterface(REFIID riid, void** ppvObj)
  187. {
  188. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IAssemblyCache))
  189. {
  190. *ppvObj = static_cast<IAssemblyCache*> (this);
  191. AddRef();
  192. return S_OK;
  193. }
  194. else
  195. {
  196. *ppvObj = NULL;
  197. return E_NOINTERFACE;
  198. }
  199. }
  200. STDMETHODIMP_(ULONG)
  201. CAssemblyCache::AddRef()
  202. {
  203. return ::SxspInterlockedIncrement(&m_cRef);
  204. }
  205. STDMETHODIMP_(ULONG)
  206. CAssemblyCache::Release()
  207. {
  208. ULONG lRet = ::SxspInterlockedDecrement(&m_cRef);
  209. if (!lRet)
  210. FUSION_DELETE_SINGLETON(this);
  211. return lRet;
  212. }