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.

422 lines
15 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Utility.cpp
  5. Abstract:
  6. This file contains the implementation of the client-side proxy for IPCHUtility.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 07/17/2000
  9. created
  10. Kalyani Narlanka (KalyaniN) 03/15/01
  11. Moved Incident and Encryption Objects from HelpService to HelpCtr to improve Perf.
  12. ******************************************************************************/
  13. #include "stdafx.h"
  14. ////////////////////////////////////////////////////////////////////////////////
  15. #define PROXY_PROPERTY_GET(func,meth,pVal) \
  16. __HCP_BEGIN_PROPERTY_GET__NOLOCK(func,hr,pVal); \
  17. \
  18. CComPtr<IPCHUtility> util; \
  19. \
  20. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureDirectConnection( util )); \
  21. \
  22. __MPC_EXIT_IF_METHOD_FAILS(hr, util->##meth( pVal )); \
  23. \
  24. __HCP_END_PROPERTY(hr)
  25. #define PROXY_PROPERTY_GET1(func,meth,a,pVal) \
  26. __HCP_BEGIN_PROPERTY_GET__NOLOCK(func,hr,pVal); \
  27. \
  28. CComPtr<IPCHUtility> util; \
  29. \
  30. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureDirectConnection( util )); \
  31. \
  32. __MPC_EXIT_IF_METHOD_FAILS(hr, util->##meth( a, pVal )); \
  33. \
  34. __HCP_END_PROPERTY(hr)
  35. #define PROXY_PROPERTY_GET2(func,meth,a,b,pVal) \
  36. __HCP_BEGIN_PROPERTY_GET__NOLOCK(func,hr,pVal); \
  37. \
  38. CComPtr<IPCHUtility> util; \
  39. \
  40. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureDirectConnection( util )); \
  41. \
  42. __MPC_EXIT_IF_METHOD_FAILS(hr, util->##meth( a, b, pVal )); \
  43. \
  44. __HCP_END_PROPERTY(hr)
  45. #define PROXY_PROPERTY_GET3(func,meth,a,b,c,d,pVal) \
  46. __HCP_BEGIN_PROPERTY_GET(func,hr,pVal); \
  47. \
  48. CComPtr<IPCHUtility> util; \
  49. \
  50. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureDirectConnection( util )); \
  51. \
  52. __MPC_EXIT_IF_METHOD_FAILS(hr, util->##meth( a, b, c, d, pVal )); \
  53. \
  54. __HCP_END_PROPERTY(hr)
  55. ////////////////////////////////////////////////////////////////////////////////
  56. CPCHProxy_IPCHUtility::CPCHProxy_IPCHUtility()
  57. {
  58. // CPCHSecurityHandle m_SecurityHandle;
  59. m_parent = NULL; // CPCHProxy_IPCHService* m_parent;
  60. //
  61. // MPC::CComPtrThreadNeutral<IPCHUtility> m_Direct_Utility;
  62. //
  63. m_UserSettings2 = NULL; // CPCHProxy_IPCHUserSettings2* m_UserSettings2;
  64. m_TaxonomyDatabase = NULL; // CPCHProxy_IPCHTaxonomyDatabase* m_TaxonomyDatabase;
  65. }
  66. CPCHProxy_IPCHUtility::~CPCHProxy_IPCHUtility()
  67. {
  68. Passivate();
  69. }
  70. ////////////////////
  71. HRESULT CPCHProxy_IPCHUtility::ConnectToParent( /*[in]*/ CPCHProxy_IPCHService* parent, /*[in]*/ CPCHHelpCenterExternal* ext )
  72. {
  73. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHUtility::ConnectToParent" );
  74. HRESULT hr;
  75. __MPC_PARAMCHECK_BEGIN(hr)
  76. __MPC_PARAMCHECK_NOTNULL(parent);
  77. __MPC_PARAMCHECK_END();
  78. m_parent = parent;
  79. m_SecurityHandle.Initialize( ext, (IPCHUtility*)this );
  80. hr = S_OK;
  81. __HCP_FUNC_CLEANUP;
  82. __HCP_FUNC_EXIT(hr);
  83. }
  84. void CPCHProxy_IPCHUtility::Passivate()
  85. {
  86. MPC::SmartLock<_ThreadModel> lock( this );
  87. if(m_UserSettings2)
  88. {
  89. m_UserSettings2->Passivate();
  90. MPC::Release2<IPCHUserSettings2>( m_UserSettings2 );
  91. }
  92. if(m_TaxonomyDatabase)
  93. {
  94. m_TaxonomyDatabase->Passivate();
  95. MPC::Release2<IPCHTaxonomyDatabase>( m_TaxonomyDatabase );
  96. }
  97. m_Direct_Utility.Release();
  98. m_SecurityHandle.Passivate();
  99. m_parent = NULL;
  100. }
  101. HRESULT CPCHProxy_IPCHUtility::EnsureDirectConnection( /*[out]*/ CComPtr<IPCHUtility>& util, /*[in]*/ bool fRefresh )
  102. {
  103. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHUtility::EnsureDirectConnection" );
  104. HRESULT hr;
  105. ProxySmartLock lock( &m_DirectLock );
  106. if(fRefresh) m_Direct_Utility.Release();
  107. util.Release(); __MPC_EXIT_IF_METHOD_FAILS(hr, m_Direct_Utility.Access( &util ));
  108. if(!util)
  109. {
  110. DEBUG_AppendPerf( DEBUG_PERF_PROXIES, "CPCHProxy_IPCHUtility::EnsureDirectConnection - IN" );
  111. if(m_parent)
  112. {
  113. CComPtr<IPCHService> svc;
  114. lock = NULL;
  115. __MPC_EXIT_IF_METHOD_FAILS(hr, m_parent->EnsureDirectConnection( svc ));
  116. lock = &m_DirectLock;
  117. __MPC_EXIT_IF_METHOD_FAILS(hr, GetUserSettings2());
  118. //
  119. // First try with the last user settings, then fall back to machine default.
  120. //
  121. if(FAILED(hr = svc->Utility( CComBSTR( m_UserSettings2->THS().GetSKU() ), m_UserSettings2->THS().GetLanguage(), &util )) || !util)
  122. {
  123. __MPC_EXIT_IF_METHOD_FAILS(hr, svc->Utility( NULL, 0, &util ));
  124. }
  125. m_Direct_Utility = util;
  126. __MPC_EXIT_IF_METHOD_FAILS(hr, m_UserSettings2->EnsureInSync());
  127. }
  128. DEBUG_AppendPerf( DEBUG_PERF_PROXIES, "CPCHProxy_IPCHUtility::EnsureDirectConnection - OUT" );
  129. if(!util)
  130. {
  131. __MPC_SET_ERROR_AND_EXIT(hr, E_HANDLE);
  132. }
  133. }
  134. hr = S_OK;
  135. __HCP_FUNC_CLEANUP;
  136. __HCP_FUNC_EXIT(hr);
  137. }
  138. HRESULT CPCHProxy_IPCHUtility::GetUserSettings2( /*[out]*/ CPCHProxy_IPCHUserSettings2* *pVal )
  139. {
  140. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHUtility::GetUserSettings2" );
  141. HRESULT hr;
  142. MPC::SmartLock<_ThreadModel> lock( this );
  143. if(m_UserSettings2 == NULL)
  144. {
  145. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &m_UserSettings2 ));
  146. __MPC_EXIT_IF_METHOD_FAILS(hr, m_UserSettings2->ConnectToParent( this, m_SecurityHandle ));
  147. }
  148. hr = S_OK;
  149. __HCP_FUNC_CLEANUP;
  150. if(FAILED(hr)) MPC::Release2<IPCHUserSettings2>( m_UserSettings2 );
  151. (void)MPC::CopyTo2<IPCHUserSettings2>( m_UserSettings2, pVal );
  152. __HCP_FUNC_EXIT(hr);
  153. }
  154. HRESULT CPCHProxy_IPCHUtility::GetDatabase( /*[out]*/ CPCHProxy_IPCHTaxonomyDatabase* *pVal )
  155. {
  156. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHUtility::GetDatabase" );
  157. HRESULT hr;
  158. MPC::SmartLock<_ThreadModel> lock( this );
  159. if(m_TaxonomyDatabase == NULL)
  160. {
  161. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &m_TaxonomyDatabase ));
  162. __MPC_EXIT_IF_METHOD_FAILS(hr, m_TaxonomyDatabase->ConnectToParent( this, m_SecurityHandle ));
  163. }
  164. hr = S_OK;
  165. __HCP_FUNC_CLEANUP;
  166. if(FAILED(hr)) MPC::Release2<IPCHTaxonomyDatabase>( m_TaxonomyDatabase );
  167. (void)MPC::CopyTo2<IPCHTaxonomyDatabase>( m_TaxonomyDatabase, pVal );
  168. __HCP_FUNC_EXIT(hr);
  169. }
  170. ////////////////////////////////////////////////////////////////////////////////
  171. STDMETHODIMP CPCHProxy_IPCHUtility::get_UserSettings( /*[out, retval]*/ IPCHUserSettings* *pVal )
  172. {
  173. __HCP_BEGIN_PROPERTY_GET("CPCHProxy_IPCHUtility::get_UserSettings",hr,pVal);
  174. __MPC_EXIT_IF_METHOD_FAILS(hr, GetUserSettings2());
  175. __MPC_EXIT_IF_METHOD_FAILS(hr, m_UserSettings2->QueryInterface( IID_IPCHUserSettings, (void**)pVal ));
  176. __HCP_END_PROPERTY(hr);
  177. }
  178. STDMETHODIMP CPCHProxy_IPCHUtility::get_Channels( /*[out, retval]*/ ISAFReg* *pVal )
  179. {
  180. PROXY_PROPERTY_GET("CPCHProxy_IPCHUtility::get_Channels",get_Channels,pVal);
  181. }
  182. STDMETHODIMP CPCHProxy_IPCHUtility::get_Security( /*[out, retval]*/ IPCHSecurity* *pVal )
  183. {
  184. PROXY_PROPERTY_GET("CPCHProxy_IPCHUtility::get_Security",get_Security,pVal);
  185. }
  186. STDMETHODIMP CPCHProxy_IPCHUtility::get_Database( /*[out, retval]*/ IPCHTaxonomyDatabase* *pVal )
  187. {
  188. __HCP_BEGIN_PROPERTY_GET("CPCHProxy_IPCHUtility::get_UserSettings",hr,pVal);
  189. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDatabase());
  190. __MPC_EXIT_IF_METHOD_FAILS(hr, m_TaxonomyDatabase->QueryInterface( IID_IPCHTaxonomyDatabase, (void**)pVal ));
  191. __HCP_END_PROPERTY(hr);
  192. }
  193. STDMETHODIMP CPCHProxy_IPCHUtility::FormatError( /*[in ]*/ VARIANT vError ,
  194. /*[out, retval]*/ BSTR *pVal )
  195. {
  196. PROXY_PROPERTY_GET1("CPCHProxy_IPCHUtility::FormatError",FormatError,vError,pVal);
  197. }
  198. STDMETHODIMP CPCHProxy_IPCHUtility::CreateObject_SearchEngineMgr( /*[out, retval]*/ IPCHSEManager* *ppSE )
  199. {
  200. PROXY_PROPERTY_GET("CPCHProxy_IPCHUtility::CreateObject_SearchEngineMgr",CreateObject_SearchEngineMgr,ppSE);
  201. }
  202. STDMETHODIMP CPCHProxy_IPCHUtility::CreateObject_DataCollection( /*[out, retval]*/ ISAFDataCollection* *ppDC )
  203. {
  204. PROXY_PROPERTY_GET("CPCHProxy_IPCHUtility::CreateObject_DataCollection",CreateObject_DataCollection,ppDC);
  205. }
  206. STDMETHODIMP CPCHProxy_IPCHUtility::CreateObject_Cabinet( /*[out, retval]*/ ISAFCabinet* *ppCB )
  207. {
  208. PROXY_PROPERTY_GET("CPCHProxy_IPCHUtility::CreateObject_Cabinet",CreateObject_Cabinet,ppCB);
  209. }
  210. STDMETHODIMP CPCHProxy_IPCHUtility::CreateObject_Encryption( /*[out, retval]*/ ISAFEncrypt* *ppEn )
  211. {
  212. PROXY_PROPERTY_GET("CPCHProxy_IPCHUtility::CreateObject_Encryption",CreateObject_Encryption,ppEn);
  213. }
  214. STDMETHODIMP CPCHProxy_IPCHUtility::CreateObject_Channel( /*[in]*/ BSTR bstrVendorID ,
  215. /*[in]*/ BSTR bstrProductID ,
  216. /*[out, retval]*/ ISAFChannel* *ppCh )
  217. {
  218. PROXY_PROPERTY_GET2("CPCHProxy_IPCHUtility::CreateObject_Channel",CreateObject_Channel,bstrVendorID,bstrProductID,ppCh);
  219. }
  220. STDMETHODIMP CPCHProxy_IPCHUtility::CreateObject_RemoteDesktopConnection( /*[out, retval]*/ ISAFRemoteDesktopConnection* *ppRDC )
  221. {
  222. PROXY_PROPERTY_GET("CPCHProxy_IPCHUtility::CreateObject_RemoteDesktopConnection",CreateObject_RemoteDesktopConnection,ppRDC);
  223. }
  224. STDMETHODIMP CPCHProxy_IPCHUtility::CreateObject_RemoteDesktopSession( /*[in]*/ REMOTE_DESKTOP_SHARING_CLASS sharingClass ,
  225. /*[in]*/ long lTimeout ,
  226. /*[in]*/ BSTR bstrConnectionParms ,
  227. /*[in]*/ BSTR bstrUserHelpBlob ,
  228. /*[out, retval]*/ ISAFRemoteDesktopSession* *ppRCS )
  229. {
  230. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHUtility::CreateObject_RemoteDesktopSession" );
  231. HRESULT hr;
  232. CComPtr<IClassFactory> fact;
  233. CComQIPtr<IPCHUtility> disp;
  234. //
  235. // This is handled in a special way.
  236. //
  237. // Instead of using the implementation inside HelpSvc, we QI the PCHSVC broker and then forward the call to it.
  238. //
  239. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoGetClassObject( CLSID_PCHService, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&fact ));
  240. if((disp = fact))
  241. {
  242. __MPC_EXIT_IF_METHOD_FAILS(hr, disp->CreateObject_RemoteDesktopSession( sharingClass, lTimeout, bstrConnectionParms, bstrUserHelpBlob, ppRCS ));
  243. }
  244. else
  245. {
  246. __MPC_SET_ERROR_AND_EXIT(hr, E_NOINTERFACE);
  247. }
  248. hr = S_OK;
  249. __HCP_FUNC_CLEANUP;
  250. __HCP_FUNC_EXIT(hr);
  251. }
  252. STDMETHODIMP CPCHProxy_IPCHUtility::ConnectToExpert( /*[in] */ BSTR bstrExpertConnectParm ,
  253. /*[in] */ LONG lTimeout ,
  254. /*[out, retval]*/ LONG *lSafErrorCode )
  255. {
  256. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHUtility::ConnectToExpert" );
  257. HRESULT hr;
  258. CComPtr<IClassFactory> fact;
  259. CComQIPtr<IPCHUtility> disp;
  260. //
  261. // This is handled in a special way.
  262. //
  263. // Instead of using the implementation inside HelpSvc, we QI the PCHSVC broker and then forward the call to it.
  264. //
  265. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoGetClassObject( CLSID_PCHService, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&fact ));
  266. if((disp = fact))
  267. {
  268. __MPC_EXIT_IF_METHOD_FAILS(hr, disp->ConnectToExpert( bstrExpertConnectParm, lTimeout, lSafErrorCode));
  269. }
  270. else
  271. {
  272. __MPC_SET_ERROR_AND_EXIT(hr, E_NOINTERFACE);
  273. }
  274. hr = S_OK;
  275. __HCP_FUNC_CLEANUP;
  276. __HCP_FUNC_EXIT(hr);
  277. }
  278. STDMETHODIMP CPCHProxy_IPCHUtility::SwitchDesktopMode( /*[in]*/ int nMode ,
  279. /*[in]*/ int nRAType )
  280. {
  281. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHUtility::ConnectToExpert" );
  282. HRESULT hr;
  283. CComPtr<IClassFactory> fact;
  284. CComQIPtr<IPCHUtility> disp;
  285. //
  286. // This is handled in a special way.
  287. //
  288. // Instead of using the implementation inside HelpSvc, we QI the PCHSVC broker and then forward the call to it.
  289. //
  290. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoGetClassObject( CLSID_PCHService, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&fact ));
  291. if((disp = fact))
  292. {
  293. __MPC_EXIT_IF_METHOD_FAILS(hr, disp->SwitchDesktopMode (nMode, nRAType));
  294. }
  295. else
  296. {
  297. __MPC_SET_ERROR_AND_EXIT(hr, E_NOINTERFACE);
  298. }
  299. hr = S_OK;
  300. __HCP_FUNC_CLEANUP;
  301. __HCP_FUNC_EXIT(hr);
  302. }