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.

411 lines
14 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. TrustedScripts.h
  5. Abstract:
  6. This file contains the declaration of the CPCHService class.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 03/14/2000
  9. created
  10. ******************************************************************************/
  11. #if !defined(__INCLUDED___PCH___TRUSTEDSCRIPTS_H___)
  12. #define __INCLUDED___PCH___TRUSTEDSCRIPTS_H___
  13. //
  14. // From HelpServiceTypeLib.idl
  15. //
  16. #include <HelpServiceTypeLib.h>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. class ATL_NO_VTABLE CPCHDispatchWrapper :
  19. public CComObjectRootEx<CComSingleThreadModel>,
  20. public IDispatch
  21. {
  22. CComQIPtr<IDispatch> m_real;
  23. public:
  24. DECLARE_NO_REGISTRY()
  25. DECLARE_NOT_AGGREGATABLE(CPCHDispatchWrapper)
  26. DECLARE_PROTECT_FINAL_CONSTRUCT()
  27. BEGIN_COM_MAP(CPCHDispatchWrapper)
  28. COM_INTERFACE_ENTRY(IDispatch)
  29. END_COM_MAP()
  30. static HRESULT CreateInstance( /*[in]*/ IUnknown* real, /*[out]*/ IUnknown* *punk )
  31. {
  32. __HCP_FUNC_ENTRY( "CPCHDispatchWrapper::CreateInstance" );
  33. HRESULT hr;
  34. CComObject<CPCHDispatchWrapper>* obj = NULL;
  35. __MPC_EXIT_IF_METHOD_FAILS(hr, obj->CreateInstance( &obj )); obj->AddRef();
  36. ((CPCHDispatchWrapper*)obj)->m_real = real;
  37. __MPC_EXIT_IF_METHOD_FAILS(hr, obj->QueryInterface( IID_IUnknown, (void**)punk ));
  38. hr = S_OK;
  39. __HCP_FUNC_CLEANUP;
  40. if(obj) obj->Release();
  41. __HCP_FUNC_EXIT(hr);
  42. }
  43. ////////////////////////////////////////
  44. //
  45. // IDispatch
  46. //
  47. STDMETHOD(GetTypeInfoCount)( UINT* pctinfo )
  48. {
  49. return m_real ? m_real->GetTypeInfoCount( pctinfo ) : E_FAIL;
  50. }
  51. STDMETHOD(GetTypeInfo)( UINT itinfo ,
  52. LCID lcid ,
  53. ITypeInfo* *pptinfo )
  54. {
  55. return m_real ? m_real->GetTypeInfo( itinfo, lcid, pptinfo ) : E_FAIL;
  56. }
  57. STDMETHOD(GetIDsOfNames)( REFIID riid ,
  58. LPOLESTR* rgszNames ,
  59. UINT cNames ,
  60. LCID lcid ,
  61. DISPID* rgdispid )
  62. {
  63. return m_real ? m_real->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgdispid ) : E_FAIL;
  64. }
  65. STDMETHOD(Invoke)( DISPID dispidMember ,
  66. REFIID riid ,
  67. LCID lcid ,
  68. WORD wFlags ,
  69. DISPPARAMS* pdispparams ,
  70. VARIANT* pvarResult ,
  71. EXCEPINFO* pexcepinfo ,
  72. UINT* puArgErr )
  73. {
  74. return m_real ? m_real->Invoke( dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr ) : E_FAIL;
  75. }
  76. };
  77. ////////////////////////////////////////////////////////////////////////////////
  78. class ATL_NO_VTABLE CPCHScriptWrapper_ClientSideRoot :
  79. public CComObjectRootEx<CComSingleThreadModel>,
  80. public IDispatchImpl<IPCHActiveScriptSite, &IID_IPCHActiveScriptSite, &LIBID_HelpServiceTypeLib>,
  81. public IActiveScript,
  82. public IActiveScriptParse
  83. {
  84. class NamedItem
  85. {
  86. public:
  87. CComBSTR m_bstrName;
  88. DWORD m_dwFlags;
  89. bool operator==( /*[in]*/ LPCOLESTR szKey ) const;
  90. };
  91. typedef std::list< NamedItem > NamedList;
  92. typedef NamedList::iterator NamedIter;
  93. typedef NamedList::const_iterator NamedIterConst;
  94. ////////////////////
  95. class TypeLibItem
  96. {
  97. public:
  98. GUID m_guidTypeLib;
  99. DWORD m_dwMajor;
  100. DWORD m_dwMinor;
  101. DWORD m_dwFlags;
  102. bool operator==( /*[in]*/ REFGUID rguidTypeLib ) const;
  103. };
  104. typedef std::list< TypeLibItem > TypeLibList;
  105. typedef TypeLibList::iterator TypeLibIter;
  106. typedef TypeLibList::const_iterator TypeLibIterConst;
  107. ////////////////////
  108. const CLSID* m_pWrappedCLSID;
  109. NamedList m_lstNamed;
  110. TypeLibList m_lstTypeLib;
  111. SCRIPTSTATE m_ss;
  112. CComPtr<IActiveScriptSite> m_Browser;
  113. CComPtr<IPCHActiveScript> m_Script;
  114. ////////////////////////////////////////
  115. public:
  116. CPCHScriptWrapper_ClientSideRoot();
  117. virtual ~CPCHScriptWrapper_ClientSideRoot();
  118. HRESULT FinalConstructInner( /*[in]*/ const CLSID* pWrappedCLSID );
  119. void FinalRelease();
  120. ////////////////////////////////////////
  121. // IActiveScript
  122. STDMETHOD(SetScriptSite )( /*[in]*/ IActiveScriptSite* pass );
  123. STDMETHOD(GetScriptSite )( /*[in ]*/ REFIID riid ,
  124. /*[out]*/ void* *ppvObject );
  125. STDMETHOD(SetScriptState)( /*[in ]*/ SCRIPTSTATE ss );
  126. STDMETHOD(GetScriptState)( /*[out]*/ SCRIPTSTATE *pss );
  127. STDMETHOD(Close)();
  128. STDMETHOD(AddNamedItem)( /*[in]*/ LPCOLESTR pstrName ,
  129. /*[in]*/ DWORD dwFlags );
  130. STDMETHOD(AddTypeLib)( /*[in]*/ REFGUID rguidTypeLib ,
  131. /*[in]*/ DWORD dwMajor ,
  132. /*[in]*/ DWORD dwMinor ,
  133. /*[in]*/ DWORD dwFlags );
  134. STDMETHOD(GetScriptDispatch)( /*[in ]*/ LPCOLESTR pstrItemName ,
  135. /*[out]*/ IDispatch* *ppdisp );
  136. STDMETHOD(GetCurrentScriptThreadID)( /*[out]*/ SCRIPTTHREADID *pstidThread );
  137. STDMETHOD(GetScriptThreadID)( /*[in ]*/ DWORD dwWin32ThreadId ,
  138. /*[out]*/ SCRIPTTHREADID *pstidThread );
  139. STDMETHOD(GetScriptThreadState)( /*[in ]*/ SCRIPTTHREADID stidThread ,
  140. /*[out]*/ SCRIPTTHREADSTATE *pstsState );
  141. STDMETHOD(InterruptScriptThread)( /*[in]*/ SCRIPTTHREADID stidThread ,
  142. /*[in]*/ const EXCEPINFO* pexcepinfo ,
  143. /*[in]*/ DWORD dwFlags );
  144. STDMETHOD(Clone)( /*[out]*/ IActiveScript* *ppscript );
  145. // IActiveScriptParse
  146. STDMETHOD(InitNew)();
  147. STDMETHOD(AddScriptlet)( /*[in ]*/ LPCOLESTR pstrDefaultName ,
  148. /*[in ]*/ LPCOLESTR pstrCode ,
  149. /*[in ]*/ LPCOLESTR pstrItemName ,
  150. /*[in ]*/ LPCOLESTR pstrSubItemName ,
  151. /*[in ]*/ LPCOLESTR pstrEventName ,
  152. /*[in ]*/ LPCOLESTR pstrDelimiter ,
  153. /*[in ]*/ DWORD_PTR dwSourceContextCookie ,
  154. /*[in ]*/ ULONG ulStartingLineNumber ,
  155. /*[in ]*/ DWORD dwFlags ,
  156. /*[out]*/ BSTR *pbstrName ,
  157. /*[out]*/ EXCEPINFO *pexcepinfo );
  158. STDMETHOD(ParseScriptText)( /*[in ]*/ LPCOLESTR pstrCode ,
  159. /*[in ]*/ LPCOLESTR pstrItemName ,
  160. /*[in ]*/ IUnknown* punkContext ,
  161. /*[in ]*/ LPCOLESTR pstrDelimiter ,
  162. /*[in ]*/ DWORD_PTR dwSourceContextCookie ,
  163. /*[in ]*/ ULONG ulStartingLineNumber ,
  164. /*[in ]*/ DWORD dwFlags ,
  165. /*[out]*/ VARIANT *pvarResult ,
  166. /*[out]*/ EXCEPINFO *pexcepinfo );
  167. ////////////////////////////////////////
  168. // IPCHActiveScriptSite
  169. STDMETHOD(Remote_GetLCID)( /*[out]*/ BSTR *plcid );
  170. STDMETHOD(Remote_GetItemInfo)( /*[in ]*/ BSTR bstrName ,
  171. /*[in ]*/ DWORD dwReturnMask ,
  172. /*[out]*/ IUnknown* *ppiunkItem ,
  173. /*[out]*/ ITypeInfo* *ppti );
  174. STDMETHOD(Remote_GetDocVersionString)( /*[out]*/ BSTR *pbstrVersion );
  175. STDMETHOD(Remote_OnScriptTerminate)( /*[in]*/ VARIANT* pvarResult );
  176. STDMETHOD(Remote_OnStateChange)( /*[in]*/ SCRIPTSTATE ssScriptState );
  177. STDMETHOD(Remote_OnScriptError)( /*[in]*/ IUnknown* pscripterror );
  178. STDMETHOD(Remote_OnEnterScript)();
  179. STDMETHOD(Remote_OnLeaveScript)();
  180. };
  181. ////////////////////////////////////////
  182. template < const CLSID* pWrappedCLSID > class ATL_NO_VTABLE CPCHScriptWrapper_ClientSide :
  183. public CPCHScriptWrapper_ClientSideRoot,
  184. public CComCoClass< CPCHScriptWrapper_ClientSide, pWrappedCLSID >
  185. {
  186. public:
  187. DECLARE_NO_REGISTRY()
  188. DECLARE_NOT_AGGREGATABLE(CPCHScriptWrapper_ClientSide)
  189. DECLARE_PROTECT_FINAL_CONSTRUCT()
  190. BEGIN_COM_MAP(CPCHScriptWrapper_ClientSide)
  191. COM_INTERFACE_ENTRY(IDispatch)
  192. COM_INTERFACE_ENTRY(IPCHActiveScriptSite)
  193. COM_INTERFACE_ENTRY(IActiveScript)
  194. COM_INTERFACE_ENTRY(IActiveScriptParse)
  195. END_COM_MAP()
  196. HRESULT FinalConstruct()
  197. {
  198. return FinalConstructInner( pWrappedCLSID );
  199. }
  200. };
  201. ////////////////////////////////////////////////////////////////////////////////
  202. class ATL_NO_VTABLE CPCHScriptWrapper_ServerSide :
  203. public CComObjectRootEx<CComSingleThreadModel>,
  204. public IDispatchImpl<IPCHActiveScript, &IID_IPCHActiveScript, &LIBID_HelpServiceTypeLib>,
  205. public IActiveScriptSite
  206. {
  207. CComBSTR m_bstrURL;
  208. CComPtr<IPCHActiveScriptSite> m_Browser;
  209. CComPtr<IActiveScript> m_Script;
  210. CComPtr<IActiveScriptParse> m_ScriptParse;
  211. public:
  212. class KeyValue
  213. {
  214. public:
  215. MPC::wstring m_strKey;
  216. MPC::wstring m_strValue;
  217. bool operator==( /*[in]*/ LPCOLESTR szKey ) const;
  218. };
  219. typedef std::list< KeyValue > HeaderList;
  220. typedef HeaderList::iterator HeaderIter;
  221. typedef HeaderList::const_iterator HeaderIterConst;
  222. ////////////////////////////////////////
  223. BEGIN_COM_MAP(CPCHScriptWrapper_ServerSide)
  224. COM_INTERFACE_ENTRY(IDispatch)
  225. COM_INTERFACE_ENTRY(IPCHActiveScript)
  226. COM_INTERFACE_ENTRY(IActiveScriptSite)
  227. END_COM_MAP()
  228. CPCHScriptWrapper_ServerSide();
  229. virtual ~CPCHScriptWrapper_ServerSide();
  230. HRESULT FinalConstructInner( /*[in]*/ const CLSID* pWrappedCLSID, /*[in]*/ BSTR bstrURL );
  231. void FinalRelease();
  232. // IPCHActiveScript
  233. STDMETHOD(Remote_SetScriptSite)( /*[in]*/ IPCHActiveScriptSite* pass );
  234. STDMETHOD(Remote_SetScriptState)( /*[in] */ SCRIPTSTATE ss );
  235. STDMETHOD(Remote_GetScriptState)( /*[out]*/ SCRIPTSTATE *pssState );
  236. STDMETHOD(Remote_Close)();
  237. STDMETHOD(Remote_AddNamedItem)( /*[in]*/ BSTR bstrName ,
  238. /*[in]*/ DWORD dwFlags );
  239. STDMETHOD(Remote_AddTypeLib)( /*[in]*/ BSTR bstrTypeLib ,
  240. /*[in]*/ DWORD dwMajor ,
  241. /*[in]*/ DWORD dwMinor ,
  242. /*[in]*/ DWORD dwFlags );
  243. STDMETHOD(Remote_GetScriptDispatch)( /*[in ]*/ BSTR bstrItemName ,
  244. /*[out]*/ IDispatch* *ppdisp );
  245. STDMETHOD(Remote_GetCurrentScriptThreadID)( /*[out]*/ SCRIPTTHREADID *pstidThread );
  246. STDMETHOD(Remote_GetScriptThreadID)( /*[in ]*/ DWORD dwWin32ThreadId ,
  247. /*[out]*/ SCRIPTTHREADID *pstidThread );
  248. STDMETHOD(Remote_GetScriptThreadState)( /*[in ]*/ SCRIPTTHREADID stidThread ,
  249. /*[out]*/ SCRIPTTHREADSTATE *pstsState );
  250. STDMETHOD(Remote_InterruptScriptThread)( /*[in]*/ SCRIPTTHREADID stidThread ,
  251. /*[in]*/ DWORD dwFlags );
  252. STDMETHOD(Remote_InitNew)();
  253. STDMETHOD(Remote_AddScriptlet)( /*[in ]*/ BSTR bstrDefaultName ,
  254. /*[in ]*/ BSTR bstrCode ,
  255. /*[in ]*/ BSTR bstrItemName ,
  256. /*[in ]*/ BSTR bstrSubItemName ,
  257. /*[in ]*/ BSTR bstrEventName ,
  258. /*[in ]*/ BSTR bstrDelimiter ,
  259. /*[in ]*/ DWORD_PTR dwSourceContextCookie ,
  260. /*[in ]*/ ULONG ulStartingLineNumber ,
  261. /*[in ]*/ DWORD dwFlags ,
  262. /*[out]*/ BSTR *pbstrName );
  263. STDMETHOD(Remote_ParseScriptText)( /*[in ]*/ BSTR bstrCode ,
  264. /*[in ]*/ BSTR bstrItemName ,
  265. /*[in ]*/ IUnknown* punkContext ,
  266. /*[in ]*/ BSTR bstrDelimiter ,
  267. /*[in ]*/ DWORD_PTR dwSourceContextCookie ,
  268. /*[in ]*/ ULONG ulStartingLineNumber ,
  269. /*[in ]*/ DWORD dwFlags ,
  270. /*[out]*/ VARIANT* pvarResult );
  271. ////////////////////////////////////////
  272. // IPCHActiveScriptSite
  273. STDMETHOD(GetLCID)( /*[out]*/ LCID *plcid );
  274. STDMETHOD(GetItemInfo)( /*[in]*/ LPCOLESTR pstrName, /*[in]*/ DWORD dwReturnMask, /*[out]*/ IUnknown* *ppiunkItem, /*[out]*/ ITypeInfo* *ppti );
  275. STDMETHOD(GetDocVersionString)( /*[out]*/ BSTR *pbstrVersion );
  276. STDMETHOD(OnScriptTerminate)( /*[in]*/ const VARIANT* pvarResult, /*[in]*/ const EXCEPINFO* pexcepinfo );
  277. STDMETHOD(OnStateChange)( /*[in]*/ SCRIPTSTATE ssScriptState );
  278. STDMETHOD(OnScriptError)( /*[in]*/ IActiveScriptError *pscripterror );
  279. STDMETHOD(OnEnterScript)( void );
  280. STDMETHOD(OnLeaveScript)( void );
  281. static HRESULT ProcessBody( /*[in]*/ BSTR bstrCode, /*[out]*/ CComBSTR& bstrRealCode, /*[out]*/ HeaderList& lst );
  282. };
  283. class CPCHScriptWrapper_Launcher :
  284. public CComObjectRootEx<MPC::CComSafeMultiThreadModel>,
  285. public MPC::Thread< CPCHScriptWrapper_Launcher, IUnknown, COINIT_APARTMENTTHREADED >
  286. {
  287. MPC::CComPtrThreadNeutral<IUnknown> m_engine;
  288. const CLSID* m_pCLSID;
  289. CComBSTR m_bstrURL;
  290. HRESULT m_hr;
  291. //////////////////////////////////////////////////////////////////////
  292. HRESULT Run();
  293. HRESULT CreateEngine();
  294. public:
  295. CPCHScriptWrapper_Launcher();
  296. ~CPCHScriptWrapper_Launcher();
  297. HRESULT CreateScriptWrapper( /*[in ]*/ REFCLSID rclsid ,
  298. /*[in ]*/ BSTR bstrCode ,
  299. /*[in ]*/ BSTR bstrURL ,
  300. /*[out]*/ IUnknown* *ppObj );
  301. };
  302. #endif // !defined(__INCLUDED___PCH___TRUSTEDSCRIPTS_H___)