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.

255 lines
5.8 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: ScriptingContext object
  6. File: Context.cpp
  7. Owner: DmitryR
  8. This file contains the code for the implementation of the
  9. ScriptingContext object, which is passed to server controls
  10. via the OnStartPage method.
  11. ===================================================================*/
  12. #include "denpre.h"
  13. #pragma hdrstop
  14. #include "context.h"
  15. #include "memchk.h"
  16. #pragma warning (disable: 4355) // ignore: "'this' used in base member init
  17. /*===================================================================
  18. CScriptingContext::CScriptingContext
  19. CScriptingContext constructor
  20. Parameters:
  21. IApplicationObject *pAppln Application
  22. ISessionObject *pSession Session
  23. IRequest *pRequest Request
  24. IResponse *pResponse Response
  25. IServer *pServer Server
  26. Returns:
  27. ===================================================================*/
  28. CScriptingContext::CScriptingContext
  29. (
  30. IApplicationObject *pAppln,
  31. ISessionObject *pSession,
  32. IRequest *pRequest,
  33. IResponse *pResponse,
  34. IServer *pServer
  35. )
  36. : m_cRef(1),
  37. m_pAppln(pAppln), m_pSession(pSession),
  38. m_pRequest(pRequest), m_pResponse(pResponse), m_pServer(pServer),
  39. m_ImpISuppErr(this, NULL, IID_IScriptingContext)
  40. {
  41. CDispatch::Init(IID_IScriptingContext);
  42. // AddRef Intrinsics -- they are now true COM objects
  43. if (m_pAppln)
  44. m_pAppln->AddRef();
  45. if (m_pSession)
  46. m_pSession->AddRef();
  47. if (m_pRequest)
  48. m_pRequest->AddRef();
  49. if (m_pResponse)
  50. m_pResponse->AddRef();
  51. if (m_pServer)
  52. m_pServer->AddRef();
  53. }
  54. /*===================================================================
  55. CScriptingContext::~CScriptingContext
  56. CScriptingContext destructor
  57. Parameters:
  58. Returns:
  59. ===================================================================*/
  60. CScriptingContext::~CScriptingContext()
  61. {
  62. Assert(m_cRef == 0);
  63. // Release Intrinsics
  64. if (m_pAppln)
  65. m_pAppln->Release();
  66. if (m_pSession)
  67. m_pSession->Release();
  68. if (m_pRequest)
  69. m_pRequest->Release();
  70. if (m_pResponse)
  71. m_pResponse->Release();
  72. if (m_pServer)
  73. m_pServer->Release();
  74. }
  75. /*===================================================================
  76. IScriptingContext Interface Methods
  77. CScriptingContext::Application
  78. CScriptingContext::Session
  79. CScriptingContext::Request
  80. CScriptingContext::Response
  81. CScriptingContext::Server
  82. Parameters:
  83. [out] Intrinsic object pointer
  84. Returns:
  85. HRESULT
  86. ===================================================================*/
  87. STDMETHODIMP CScriptingContext::get_Request(IRequest **ppRequest)
  88. {
  89. if (m_pRequest)
  90. {
  91. m_pRequest->AddRef();
  92. *ppRequest = m_pRequest;
  93. return S_OK;
  94. }
  95. else
  96. {
  97. *ppRequest = NULL;
  98. return TYPE_E_ELEMENTNOTFOUND;
  99. }
  100. }
  101. STDMETHODIMP CScriptingContext::get_Response(IResponse **ppResponse)
  102. {
  103. if (m_pResponse)
  104. {
  105. m_pResponse->AddRef();
  106. *ppResponse = m_pResponse;
  107. return S_OK;
  108. }
  109. else
  110. {
  111. *ppResponse = m_pResponse;
  112. return TYPE_E_ELEMENTNOTFOUND;
  113. }
  114. }
  115. STDMETHODIMP CScriptingContext::get_Server(IServer **ppServer)
  116. {
  117. if (m_pServer)
  118. {
  119. m_pServer->AddRef();
  120. *ppServer = m_pServer;
  121. return S_OK;
  122. }
  123. else
  124. {
  125. *ppServer = NULL;
  126. return TYPE_E_ELEMENTNOTFOUND;
  127. }
  128. }
  129. STDMETHODIMP CScriptingContext::get_Session(ISessionObject **ppSession)
  130. {
  131. if (m_pSession)
  132. {
  133. m_pSession->AddRef();
  134. *ppSession = m_pSession;
  135. return S_OK;
  136. }
  137. else
  138. {
  139. *ppSession = NULL;
  140. return TYPE_E_ELEMENTNOTFOUND;
  141. }
  142. }
  143. STDMETHODIMP CScriptingContext::get_Application(IApplicationObject **ppAppln)
  144. {
  145. if (m_pAppln)
  146. {
  147. m_pAppln->AddRef();
  148. *ppAppln = m_pAppln;
  149. return S_OK;
  150. }
  151. else
  152. {
  153. *ppAppln = NULL;
  154. return TYPE_E_ELEMENTNOTFOUND;
  155. }
  156. }
  157. /*===================================================================
  158. IUnknown Interface Methods
  159. CScriptingContext::QueryInterface
  160. CScriptingContext::AddRef
  161. CScriptingContext::Release
  162. ===================================================================*/
  163. STDMETHODIMP CScriptingContext::QueryInterface
  164. (
  165. REFIID riid,
  166. PPVOID ppv
  167. )
  168. {
  169. if (riid == IID_IUnknown ||
  170. riid == IID_IDispatch ||
  171. riid == IID_IScriptingContext)
  172. {
  173. AddRef();
  174. *ppv = this;
  175. }
  176. else if (riid == IID_IRequest)
  177. {
  178. if (FAILED(get_Request((IRequest **)ppv)))
  179. return E_NOINTERFACE;
  180. }
  181. else if (riid == IID_IResponse)
  182. {
  183. if (FAILED(get_Response((IResponse **)ppv)))
  184. return E_NOINTERFACE;
  185. }
  186. else if (riid == IID_IServer)
  187. {
  188. if (FAILED(get_Server((IServer **)ppv)))
  189. return E_NOINTERFACE;
  190. }
  191. else if (riid == IID_ISessionObject)
  192. {
  193. if (FAILED(get_Session((ISessionObject **)ppv)))
  194. return E_NOINTERFACE;
  195. }
  196. else if (riid == IID_IApplicationObject)
  197. {
  198. if (FAILED(get_Application((IApplicationObject **)ppv)))
  199. return E_NOINTERFACE;
  200. }
  201. else if (riid == IID_ISupportErrorInfo)
  202. {
  203. m_ImpISuppErr.AddRef();
  204. *ppv = &m_ImpISuppErr;
  205. }
  206. else
  207. {
  208. *ppv = NULL;
  209. return E_NOINTERFACE;
  210. }
  211. return S_OK;
  212. }
  213. STDMETHODIMP_(ULONG) CScriptingContext::AddRef()
  214. {
  215. return ++m_cRef;
  216. }
  217. STDMETHODIMP_(ULONG) CScriptingContext::Release()
  218. {
  219. if (--m_cRef)
  220. return m_cRef;
  221. delete this;
  222. return 0;
  223. }