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.

300 lines
4.9 KiB

  1. /*++=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. iw3spoof.cxx
  5. Abstract:
  6. Implements the W3Spoof object's IW3Spoof interface.
  7. Author:
  8. Paul M Midgen (pmidge) 08-February-2001
  9. Revision History:
  10. 08-February-2001 pmidge
  11. Created
  12. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--*/
  13. #include "common.h"
  14. HRESULT
  15. __stdcall
  16. CW3Spoof::GetRuntime(IW3SpoofRuntime** pprt)
  17. {
  18. DEBUG_ENTER((
  19. DBG_W3SOBJ,
  20. rt_hresult,
  21. "CW3Spoof::GetRuntime",
  22. "this=%#x; pprt=%#x",
  23. this,
  24. pprt
  25. ));
  26. HRESULT hr = S_OK;
  27. if( !pprt )
  28. {
  29. hr = E_POINTER;
  30. }
  31. else
  32. {
  33. *pprt = NULL;
  34. if( m_prt )
  35. {
  36. hr = m_prt->QueryInterface(IID_IW3SpoofRuntime, (void**) pprt);
  37. DEBUG_TRACE(W3SOBJ, ("returning IW3SpoofRuntime instance %#x", *pprt));
  38. }
  39. else
  40. {
  41. hr = E_FAIL;
  42. }
  43. }
  44. DEBUG_LEAVE(hr);
  45. return hr;
  46. }
  47. HRESULT
  48. __stdcall
  49. CW3Spoof::GetTypeLibrary(ITypeLib** pptl)
  50. {
  51. DEBUG_ENTER((
  52. DBG_W3SOBJ,
  53. rt_hresult,
  54. "CW3Spoof::GetTypeLibrary",
  55. "this=%#x; pptl=%#x",
  56. this,
  57. pptl
  58. ));
  59. HRESULT hr = S_OK;
  60. if( !pptl )
  61. {
  62. hr = E_POINTER;
  63. }
  64. else
  65. {
  66. *pptl = NULL;
  67. if( m_ptl )
  68. {
  69. hr = m_ptl->QueryInterface(IID_ITypeLib, (void**) pptl);
  70. DEBUG_TRACE(W3SOBJ, ("returning ITypeLib instance %#x", *pptl));
  71. }
  72. else
  73. {
  74. hr = E_FAIL;
  75. }
  76. }
  77. DEBUG_LEAVE(hr);
  78. return hr;
  79. }
  80. HRESULT
  81. __stdcall
  82. CW3Spoof::GetScriptEngine(IActiveScript** ppas)
  83. {
  84. DEBUG_ENTER((
  85. DBG_W3SOBJ,
  86. rt_hresult,
  87. "CW3Spoof::GetScriptEngine",
  88. "this=%#x; ppas=%#x",
  89. this,
  90. ppas
  91. ));
  92. HRESULT hr = S_OK;
  93. if( !ppas )
  94. {
  95. hr = E_POINTER;
  96. }
  97. else
  98. {
  99. *ppas = NULL;
  100. if( m_pas )
  101. {
  102. hr = m_pas->QueryInterface(IID_IActiveScript, (void**) ppas);
  103. DEBUG_TRACE(W3SOBJ, ("returning IActiveScript instance %#x", *ppas));
  104. }
  105. else
  106. {
  107. hr = E_FAIL;
  108. }
  109. }
  110. DEBUG_LEAVE(hr);
  111. return hr;
  112. }
  113. HRESULT
  114. __stdcall
  115. CW3Spoof::GetScriptPath(LPWSTR client, LPWSTR* path)
  116. {
  117. DEBUG_ENTER((
  118. DBG_W3SOBJ,
  119. rt_hresult,
  120. "CW3Spoof::GetScriptPath",
  121. "this=%#x; client=%S; path=%#x",
  122. this,
  123. client,
  124. path
  125. ));
  126. HRESULT hr = S_OK;
  127. if( !path )
  128. {
  129. hr = E_POINTER;
  130. goto quit;
  131. }
  132. if( !client )
  133. {
  134. hr = E_INVALIDARG;
  135. goto quit;
  136. }
  137. if( m_clientmap && (m_clientmap->Get(client, (void**) path) != ERROR_SUCCESS) )
  138. {
  139. *path = L"default.js";
  140. }
  141. DEBUG_TRACE(W3SOBJ, ("script path is %S", *path));
  142. quit:
  143. DEBUG_LEAVE(hr);
  144. return hr;
  145. }
  146. HRESULT
  147. __stdcall
  148. CW3Spoof::Notify(LPWSTR clientid, PSESSIONOBJ pso, STATE state)
  149. {
  150. DEBUG_ENTER((
  151. DBG_W3SOBJ,
  152. rt_hresult,
  153. "CW3Spoof::Notify",
  154. "this=%#x; clientid=%S; pso=%#x; state=%s",
  155. this,
  156. clientid,
  157. pso,
  158. MapStateToString(state)
  159. ));
  160. HRESULT hr = S_OK;
  161. //
  162. // states not directly handled:
  163. //
  164. // ST_CREATED
  165. // ST_OPENING
  166. // ST_CLOSING
  167. //
  168. switch( state )
  169. {
  170. case ST_OPEN :
  171. {
  172. DEBUG_TRACE(W3SOBJ, ("registering session object"));
  173. m_CP.FireOnSessionOpen(clientid);
  174. hr = m_sessionmap->Insert(clientid, (void*) pso);
  175. }
  176. break;
  177. case ST_CLOSED :
  178. {
  179. DEBUG_TRACE(W3SOBJ, ("unregistering session object"));
  180. m_CP.FireOnSessionClose(clientid);
  181. m_sessionmap->Delete(clientid, NULL);
  182. }
  183. break;
  184. case ST_ERROR :
  185. {
  186. m_CP.FireOnSessionStateChange(clientid, state);
  187. m_sessionmap->Delete(clientid, NULL);
  188. }
  189. break;
  190. default :
  191. {
  192. m_CP.FireOnSessionStateChange(clientid, state);
  193. }
  194. }
  195. DEBUG_LEAVE(hr);
  196. return hr;
  197. }
  198. HRESULT
  199. __stdcall
  200. CW3Spoof::WaitForUnload(void)
  201. {
  202. DEBUG_ENTER((
  203. DBG_W3SOBJ,
  204. rt_hresult,
  205. "CW3Spoof::WaitForUnload",
  206. "this=%#x",
  207. this
  208. ));
  209. HRESULT hr = S_OK;
  210. WaitForSingleObject(m_evtServerUnload, INFINITE);
  211. DEBUG_LEAVE(hr);
  212. return hr;
  213. }
  214. HRESULT
  215. __stdcall
  216. CW3Spoof::Terminate(void)
  217. {
  218. DEBUG_ENTER((
  219. DBG_W3SOBJ,
  220. rt_hresult,
  221. "CW3Spoof::Terminate",
  222. "this=%#x",
  223. this
  224. ));
  225. HRESULT hr = S_OK;
  226. _SetState(ST_CLOSING);
  227. _TerminateThreads();
  228. SAFETERMINATE(m_prt);
  229. SAFERELEASE(m_ptl);
  230. SAFERELEASE(m_pas);
  231. SAFEDELETE(m_clientmap);
  232. SAFEDELETE(m_sessionmap);
  233. SAFECLOSE(m_evtServerUnload);
  234. _SetState(ST_CLOSED);
  235. DEBUG_LEAVE(hr);
  236. return hr;
  237. }