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.

380 lines
10 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Utility.cpp
  5. Abstract:
  6. This file contains the implementation of the class exposed as the "window.external" object.
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 07/23/99
  9. created
  10. Davide Massarenti (dmassare) 07/25/99
  11. modified
  12. Kalyani Narlanka (KalyaniN) 03/15/01
  13. Moved Incident and Encryption Objects from HelpService to HelpCtr to improve Perf.
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "rdshost_i.c"
  17. /////////////////////////////////////////////////////////////////////////////
  18. HRESULT CPCHUtility::FinalConstruct()
  19. {
  20. __HCP_FUNC_ENTRY( "CPCHUtility::FinalConstruct" );
  21. HRESULT hr;
  22. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &m_UserSettings ));
  23. hr = S_OK;
  24. __HCP_FUNC_CLEANUP;
  25. __HCP_FUNC_EXIT(hr);
  26. }
  27. HRESULT CPCHUtility::InitUserSettings( /*[in]*/ Taxonomy::Settings& ts )
  28. {
  29. return m_UserSettings ? m_UserSettings->InitUserSettings( ts ) : E_FAIL;
  30. }
  31. /////////////////////////////////////////////////////////////////////////////
  32. STDMETHODIMP CPCHUtility::get_UserSettings( /*[out, retval]*/ IPCHUserSettings* *pVal )
  33. {
  34. __HCP_BEGIN_PROPERTY_GET("CPCHUtility::get_UserSettings",hr,pVal);
  35. __MPC_EXIT_IF_METHOD_FAILS(hr, m_UserSettings.QueryInterface( pVal ));
  36. __HCP_END_PROPERTY(hr);
  37. }
  38. STDMETHODIMP CPCHUtility::get_Channels( /*[out, retval]*/ ISAFReg* *pVal )
  39. {
  40. __HCP_BEGIN_PROPERTY_GET("CPCHUtility::get_Channels",hr,pVal);
  41. CComPtr<CSAFRegDummy> obj;
  42. Taxonomy::Settings ts;
  43. __MPC_EXIT_IF_METHOD_FAILS(hr, InitUserSettings( ts ));
  44. //
  45. // Get the channels registry, but make a read-only copy.
  46. //
  47. __MPC_EXIT_IF_METHOD_FAILS(hr, CSAFReg::s_GLOBAL->CreateReadOnlyCopy( ts, &obj ));
  48. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( pVal ));
  49. __HCP_END_PROPERTY(hr);
  50. }
  51. STDMETHODIMP CPCHUtility::get_Security( /*[out, retval]*/ IPCHSecurity* *pVal )
  52. {
  53. __HCP_BEGIN_PROPERTY_GET("CPCHUtility::get_Security",hr,pVal);
  54. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurity::s_GLOBAL->QueryInterface( IID_IPCHSecurity, (void**)pVal ));
  55. __HCP_END_PROPERTY(hr);
  56. }
  57. STDMETHODIMP CPCHUtility::get_Database( /*[out, retval]*/ IPCHTaxonomyDatabase* *pVal )
  58. {
  59. __HCP_FUNC_ENTRY( "CPCHUtility::get_Database" );
  60. HRESULT hr;
  61. CComPtr<CPCHTaxonomyDatabase> pObj;
  62. __MPC_PARAMCHECK_BEGIN(hr)
  63. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  64. __MPC_PARAMCHECK_END();
  65. //
  66. // Create a new collection and fill it from the database.
  67. //
  68. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pObj ));
  69. __MPC_EXIT_IF_METHOD_FAILS(hr, InitUserSettings( pObj->GetTS() ));
  70. __MPC_EXIT_IF_METHOD_FAILS(hr, pObj.QueryInterface( pVal ));
  71. hr = S_OK;
  72. __HCP_FUNC_CLEANUP;
  73. __HCP_FUNC_EXIT(hr);
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. STDMETHODIMP CPCHUtility::FormatError( /*[in]*/ VARIANT vError, /*[out, retval]*/ BSTR *pVal )
  77. {
  78. __HCP_FUNC_ENTRY( "CPCHUtility::CreateObject_DataCollection" );
  79. HRESULT hr;
  80. HRESULT hrIn;
  81. LPWSTR lpMsgBuf = NULL;
  82. __MPC_PARAMCHECK_BEGIN(hr)
  83. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  84. __MPC_PARAMCHECK_END();
  85. if(vError.vt == VT_ERROR)
  86. {
  87. hrIn = vError.scode;
  88. }
  89. else if(vError.vt == VT_I4)
  90. {
  91. hrIn = vError.lVal;
  92. }
  93. else
  94. {
  95. CComVariant v;
  96. __MPC_EXIT_IF_METHOD_FAILS(hr, v.ChangeType( VT_I4, &vError ));
  97. hrIn = v.lVal;
  98. }
  99. if(HRESULT_FACILITY(hrIn) == FACILITY_WIN32)
  100. {
  101. if(::FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  102. FORMAT_MESSAGE_FROM_SYSTEM |
  103. FORMAT_MESSAGE_IGNORE_INSERTS,
  104. NULL,
  105. hrIn,
  106. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  107. (LPWSTR)&lpMsgBuf,
  108. 0,
  109. NULL ))
  110. {
  111. __MPC_EXIT_IF_ALLOC_FAILS(hr,*pVal,::SysAllocString( lpMsgBuf ));
  112. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  113. }
  114. }
  115. //
  116. // Unknown error....
  117. //
  118. {
  119. WCHAR rgFmt[128];
  120. WCHAR rgBuf[512];
  121. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::LocalizeString( IDS_HELPSVC_UNKNOWNERROR, rgFmt, MAXSTRLEN(rgFmt), /*fMUI*/true ));
  122. _snwprintf( rgBuf, MAXSTRLEN(rgBuf), rgFmt, hrIn );
  123. __MPC_EXIT_IF_ALLOC_FAILS(hr,*pVal,::SysAllocString( rgBuf ));
  124. }
  125. hr = S_OK;
  126. __HCP_FUNC_CLEANUP;
  127. if(lpMsgBuf) ::LocalFree( lpMsgBuf );
  128. __HCP_FUNC_EXIT(hr);
  129. }
  130. STDMETHODIMP CPCHUtility::CreateObject_SearchEngineMgr( /*[out , retval]*/ IPCHSEManager* *ppSE )
  131. {
  132. __HCP_FUNC_ENTRY( "CPCHUtility::CreateObject_SearchEngineMgr" );
  133. HRESULT hr;
  134. SearchEngine::Manager_Object* semgr = NULL;
  135. Taxonomy::Settings ts;
  136. //
  137. // Create a new data collection.
  138. //
  139. __MPC_EXIT_IF_METHOD_FAILS(hr, semgr->CreateInstance( &semgr )); semgr->AddRef();
  140. __MPC_EXIT_IF_METHOD_FAILS(hr, InitUserSettings ( ts ));
  141. __MPC_EXIT_IF_METHOD_FAILS(hr, semgr->InitializeFromDatabase( ts ));
  142. __MPC_EXIT_IF_METHOD_FAILS(hr, semgr->QueryInterface( IID_IPCHSEManager, (void**)ppSE ));
  143. hr = S_OK;
  144. __HCP_FUNC_CLEANUP;
  145. MPC::Release( semgr );
  146. __HCP_FUNC_EXIT(hr);
  147. }
  148. STDMETHODIMP CPCHUtility::CreateObject_DataCollection( /*[out, retval]*/ ISAFDataCollection* *ppDC )
  149. {
  150. __HCP_FUNC_ENTRY( "CPCHUtility::CreateObject_DataCollection" );
  151. HRESULT hr;
  152. CComPtr<CSAFDataCollection> pchdc;
  153. //
  154. // Create a new data collection.
  155. //
  156. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pchdc ));
  157. __MPC_EXIT_IF_METHOD_FAILS(hr, pchdc.QueryInterface( ppDC ));
  158. hr = S_OK;
  159. __HCP_FUNC_CLEANUP;
  160. __HCP_FUNC_EXIT(hr);
  161. }
  162. STDMETHODIMP CPCHUtility::CreateObject_Cabinet( /*[out , retval]*/ ISAFCabinet* *ppCB )
  163. {
  164. __HCP_FUNC_ENTRY( "CPCHUtility::CreateObject_Cabinet" );
  165. HRESULT hr;
  166. CComPtr<CSAFCabinet> cabinet;
  167. //
  168. // Create a new data collection.
  169. //
  170. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &cabinet ));
  171. __MPC_EXIT_IF_METHOD_FAILS(hr, cabinet.QueryInterface( ppCB ));
  172. hr = S_OK;
  173. __HCP_FUNC_CLEANUP;
  174. __HCP_FUNC_EXIT(hr);
  175. }
  176. STDMETHODIMP CPCHUtility::CreateObject_Encryption( /*[out, retval]*/ ISAFEncrypt* *ppEn )
  177. {
  178. __HCP_BEGIN_PROPERTY_GET("CPCHUtility::CreateObject_Encryption",hr,ppEn);
  179. CComPtr<CSAFEncrypt> pEn;
  180. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pEn ));
  181. __MPC_EXIT_IF_METHOD_FAILS(hr, pEn.QueryInterface( ppEn ));
  182. __HCP_END_PROPERTY(hr);
  183. }
  184. STDMETHODIMP CPCHUtility::CreateObject_Channel( /*[in] */ BSTR bstrVendorID ,
  185. /*[in] */ BSTR bstrProductID ,
  186. /*[out, retval]*/ ISAFChannel* *ppCh )
  187. {
  188. __HCP_FUNC_ENTRY( "CPCHUtility::CreateObject_Channel" );
  189. HRESULT hr;
  190. CSAFChannel_Object* safchan = NULL;
  191. Taxonomy::Settings ts;
  192. CSAFChannelRecord cr;
  193. bool fFound;
  194. __MPC_EXIT_IF_METHOD_FAILS(hr, InitUserSettings( ts ));
  195. cr.m_ths = ts;
  196. cr.m_bstrVendorID = bstrVendorID;
  197. cr.m_bstrProductID = bstrProductID;
  198. __MPC_EXIT_IF_METHOD_FAILS(hr, CSAFReg::s_GLOBAL->Synchronize( cr, fFound ));
  199. if(!fFound)
  200. {
  201. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  202. }
  203. //
  204. // Locate a channel.
  205. //
  206. __MPC_EXIT_IF_METHOD_FAILS(hr, safchan->CreateInstance( &safchan )); safchan->AddRef();
  207. __MPC_EXIT_IF_METHOD_FAILS(hr, safchan->Init( cr ));
  208. __MPC_EXIT_IF_METHOD_FAILS(hr, safchan->QueryInterface( IID_ISAFChannel, (void**)ppCh ));
  209. hr = S_OK;
  210. __HCP_FUNC_CLEANUP;
  211. MPC::Release( safchan );
  212. __HCP_FUNC_EXIT(hr);
  213. }
  214. STDMETHODIMP CPCHUtility::CreateObject_RemoteDesktopConnection( /*[out, retval]*/ ISAFRemoteDesktopConnection* *ppRDC )
  215. {
  216. __HCP_FUNC_ENTRY( "CPCHUtility::CreateObject_RemoteDesktopConnection" );
  217. HRESULT hr;
  218. CComPtr<CSAFRemoteDesktopConnection> rdc;
  219. //
  220. // Create a new RemoteDesktopConnection Object..
  221. //
  222. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &rdc ));
  223. __MPC_EXIT_IF_METHOD_FAILS(hr, rdc.QueryInterface( ppRDC ));
  224. hr = S_OK;
  225. __HCP_FUNC_CLEANUP;
  226. __HCP_FUNC_EXIT(hr);
  227. }
  228. STDMETHODIMP CPCHUtility::CreateObject_RemoteDesktopSession( /*[in] */ REMOTE_DESKTOP_SHARING_CLASS sharingClass ,
  229. /*[in] */ long lTimeout ,
  230. /*[in] */ BSTR bstrConnectionParms ,
  231. /*[in] */ BSTR bstrUserHelpBlob ,
  232. /*[out, retval]*/ ISAFRemoteDesktopSession* *ppRCS )
  233. {
  234. return E_NOTIMPL; // Implementation moved to the PCHSVC broker...
  235. }
  236. STDMETHODIMP CPCHUtility::ConnectToExpert(/* [in] */ BSTR bstrExpertConnectParm,
  237. /* [in] */ LONG lTimeout,
  238. /* [retval][out] */ LONG *lSafErrorCode)
  239. {
  240. return E_NOTIMPL; // Implementation moved to the PCHSVC broker...
  241. }
  242. STDMETHODIMP CPCHUtility::SwitchDesktopMode(/* [in]*/ int nMode,
  243. /* [in]*/ int nRAType)
  244. {
  245. return E_NOTIMPL; // Implementation moved to the PCHSVC broker...
  246. }