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.

365 lines
7.6 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2001
  5. //
  6. // File: capools.cxx
  7. //
  8. // Contents: Contains methods for CIISApplicationPools object
  9. //
  10. // History: 11-09-2000 BrentMid Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "iisext.hxx"
  14. #pragma hdrstop
  15. // Class CIISApplicationPools
  16. DEFINE_IPrivateDispatch_Implementation(CIISApplicationPools)
  17. DEFINE_DELEGATING_IDispatch_Implementation(CIISApplicationPools)
  18. DEFINE_CONTAINED_IADs_Implementation(CIISApplicationPools)
  19. DEFINE_IADsExtension_Implementation(CIISApplicationPools)
  20. CIISApplicationPools::CIISApplicationPools():
  21. _pUnkOuter(NULL),
  22. _pADs(NULL),
  23. _pszServerName(NULL),
  24. _pszMetaBasePath(NULL),
  25. _pAdminBase(NULL),
  26. _pDispMgr(NULL),
  27. _fDispInitialized(FALSE)
  28. {
  29. ENLIST_TRACKING(CIISApplicationPools);
  30. }
  31. HRESULT
  32. CIISApplicationPools::CreateApplicationPools(
  33. IUnknown *pUnkOuter,
  34. REFIID riid,
  35. void **ppvObj
  36. )
  37. {
  38. CCredentials Credentials;
  39. CIISApplicationPools FAR * pApplicationPools = NULL;
  40. HRESULT hr = S_OK;
  41. BSTR bstrAdsPath = NULL;
  42. OBJECTINFO ObjectInfo;
  43. POBJECTINFO pObjectInfo = &ObjectInfo;
  44. CLexer * pLexer = NULL;
  45. LPWSTR pszIISPathName = NULL;
  46. memset(pObjectInfo, 0, sizeof(OBJECTINFO));
  47. hr = AllocateApplicationPoolsObject(pUnkOuter, Credentials, &pApplicationPools);
  48. BAIL_ON_FAILURE(hr);
  49. //
  50. // get ServerName and pszPath
  51. //
  52. hr = pApplicationPools->_pADs->get_ADsPath(&bstrAdsPath);
  53. BAIL_ON_FAILURE(hr);
  54. pLexer = new CLexer();
  55. hr = pLexer->Initialize(bstrAdsPath);
  56. BAIL_ON_FAILURE(hr);
  57. //
  58. // Parse the pathname
  59. //
  60. hr = ADsObject(pLexer, pObjectInfo);
  61. BAIL_ON_FAILURE(hr);
  62. pszIISPathName = AllocADsStr(bstrAdsPath);
  63. if (!pszIISPathName) {
  64. hr = E_OUTOFMEMORY;
  65. BAIL_ON_FAILURE(hr);
  66. }
  67. *pszIISPathName = L'\0';
  68. hr = BuildIISPathFromADsPath(
  69. pObjectInfo,
  70. pszIISPathName
  71. );
  72. BAIL_ON_FAILURE(hr);
  73. hr = pApplicationPools->InitializeApplicationPoolsObject(
  74. pObjectInfo->TreeName,
  75. pszIISPathName );
  76. BAIL_ON_FAILURE(hr);
  77. //
  78. // pass non-delegating IUnknown back to the aggregator
  79. //
  80. *ppvObj = (INonDelegatingUnknown FAR *) pApplicationPools;
  81. if (bstrAdsPath)
  82. {
  83. ADsFreeString(bstrAdsPath);
  84. }
  85. if (pLexer) {
  86. delete pLexer;
  87. }
  88. if (pszIISPathName ) {
  89. FreeADsStr( pszIISPathName );
  90. }
  91. FreeObjectInfo( &ObjectInfo );
  92. RRETURN(hr);
  93. error:
  94. if (bstrAdsPath) {
  95. ADsFreeString(bstrAdsPath);
  96. }
  97. if (pLexer) {
  98. delete pLexer;
  99. }
  100. if (pszIISPathName ) {
  101. FreeADsStr( pszIISPathName );
  102. }
  103. FreeObjectInfo( &ObjectInfo );
  104. *ppvObj = NULL;
  105. delete pApplicationPools;
  106. RRETURN(hr);
  107. }
  108. CIISApplicationPools::~CIISApplicationPools( )
  109. {
  110. if (_pszServerName) {
  111. FreeADsStr(_pszServerName);
  112. }
  113. if (_pszMetaBasePath) {
  114. FreeADsStr(_pszMetaBasePath);
  115. }
  116. delete _pDispMgr;
  117. }
  118. STDMETHODIMP
  119. CIISApplicationPools::QueryInterface(
  120. REFIID iid,
  121. LPVOID FAR* ppv
  122. )
  123. {
  124. HRESULT hr = S_OK;
  125. hr = _pUnkOuter->QueryInterface(iid,ppv);
  126. RRETURN(hr);
  127. }
  128. HRESULT
  129. CIISApplicationPools::AllocateApplicationPoolsObject(
  130. IUnknown *pUnkOuter,
  131. CCredentials& Credentials,
  132. CIISApplicationPools ** ppApplicationPools
  133. )
  134. {
  135. CIISApplicationPools FAR * pApplicationPools = NULL;
  136. IADs FAR * pADs = NULL;
  137. CAggregateeDispMgr FAR * pDispMgr = NULL;
  138. HRESULT hr = S_OK;
  139. pApplicationPools = new CIISApplicationPools();
  140. if (pApplicationPools == NULL) {
  141. hr = E_OUTOFMEMORY;
  142. }
  143. BAIL_ON_FAILURE(hr);
  144. pDispMgr = new CAggregateeDispMgr;
  145. if (pDispMgr == NULL) {
  146. hr = E_OUTOFMEMORY;
  147. }
  148. BAIL_ON_FAILURE(hr);
  149. hr = pDispMgr->LoadTypeInfoEntry(
  150. LIBID_IISExt,
  151. IID_IISApplicationPools,
  152. (IISApplicationPools *)pApplicationPools,
  153. DISPID_REGULAR
  154. );
  155. BAIL_ON_FAILURE(hr);
  156. //
  157. // Store the IADs Pointer, but again do NOT ref-count
  158. // this pointer - we keep the pointer around, but do
  159. // a release immediately.
  160. //
  161. hr = pUnkOuter->QueryInterface(IID_IADs, (void **)&pADs);
  162. pADs->Release();
  163. pApplicationPools->_pADs = pADs;
  164. //
  165. // Store the pointer to the pUnkOuter object
  166. // AND DO NOT add ref this pointer
  167. //
  168. pApplicationPools->_pUnkOuter = pUnkOuter;
  169. pApplicationPools->_Credentials = Credentials;
  170. pApplicationPools->_pDispMgr = pDispMgr;
  171. *ppApplicationPools = pApplicationPools;
  172. RRETURN(hr);
  173. error:
  174. delete pDispMgr;
  175. delete pApplicationPools;
  176. RRETURN(hr);
  177. }
  178. HRESULT
  179. CIISApplicationPools::InitializeApplicationPoolsObject(
  180. LPWSTR pszServerName,
  181. LPWSTR pszPath
  182. )
  183. {
  184. HRESULT hr = S_OK;
  185. if (pszServerName) {
  186. _pszServerName = AllocADsStr(pszServerName);
  187. if (!_pszServerName) {
  188. hr = E_OUTOFMEMORY;
  189. BAIL_ON_FAILURE(hr);
  190. }
  191. }
  192. if (pszPath) {
  193. _pszMetaBasePath = AllocADsStr(pszPath);
  194. if (!_pszMetaBasePath) {
  195. hr = E_OUTOFMEMORY;
  196. BAIL_ON_FAILURE(hr);
  197. }
  198. }
  199. hr = InitServerInfo(pszServerName, &_pAdminBase);
  200. BAIL_ON_FAILURE(hr);
  201. error:
  202. RRETURN(hr);
  203. }
  204. STDMETHODIMP
  205. CIISApplicationPools::ADSIInitializeDispatchManager(
  206. long dwExtensionId
  207. )
  208. {
  209. HRESULT hr = S_OK;
  210. if (_fDispInitialized) {
  211. RRETURN(E_FAIL);
  212. }
  213. hr = _pDispMgr->InitializeDispMgr(dwExtensionId);
  214. if (SUCCEEDED(hr)) {
  215. _fDispInitialized = TRUE;
  216. }
  217. RRETURN(hr);
  218. }
  219. STDMETHODIMP
  220. CIISApplicationPools::ADSIInitializeObject(
  221. THIS_ BSTR lpszUserName,
  222. BSTR lpszPassword,
  223. long lnReserved
  224. )
  225. {
  226. CCredentials NewCredentials(lpszUserName, lpszPassword, lnReserved);
  227. _Credentials = NewCredentials;
  228. RRETURN(S_OK);
  229. }
  230. STDMETHODIMP
  231. CIISApplicationPools::ADSIReleaseObject()
  232. {
  233. delete this;
  234. RRETURN(S_OK);
  235. }
  236. STDMETHODIMP
  237. CIISApplicationPools::NonDelegatingQueryInterface(
  238. REFIID iid,
  239. LPVOID FAR* ppv
  240. )
  241. {
  242. ASSERT(ppv);
  243. if (IsEqualIID(iid, IID_IISApplicationPools)) {
  244. *ppv = (IADsUser FAR *) this;
  245. } else if (IsEqualIID(iid, IID_IADsExtension)) {
  246. *ppv = (IADsExtension FAR *) this;
  247. } else if (IsEqualIID(iid, IID_IUnknown)) {
  248. //
  249. // probably not needed since our 3rd party extension does not stand
  250. // alone and provider does not ask for this, but to be safe
  251. //
  252. *ppv = (INonDelegatingUnknown FAR *) this;
  253. } else {
  254. *ppv = NULL;
  255. return E_NOINTERFACE;
  256. }
  257. //
  258. // Delegating AddRef to aggregator for IADsExtesnion and IISApplicationPools.
  259. // AddRef on itself for IPrivateUnknown. (both tested.)
  260. //
  261. ((IUnknown *) (*ppv)) -> AddRef();
  262. return S_OK;
  263. }
  264. //
  265. // IADsExtension::Operate()
  266. //
  267. STDMETHODIMP
  268. CIISApplicationPools::Operate(
  269. THIS_ DWORD dwCode,
  270. VARIANT varUserName,
  271. VARIANT varPassword,
  272. VARIANT varFlags
  273. )
  274. {
  275. RRETURN(E_NOTIMPL);
  276. }