Source code of Windows XP (NT5)
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.

220 lines
6.2 KiB

  1. //
  2. // MODULE: LocalECB.H
  3. //
  4. // PURPOSE: Implementation of CLocalECB class, which implements CAbstractECB by emulating Win32's
  5. // EXTENSION_CONTROL_BLOCK.
  6. //
  7. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint - Local TS only
  8. //
  9. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  10. //
  11. // AUTHOR: Joe Mabel
  12. //
  13. // ORIGINAL DATE: 01-07-99
  14. //
  15. // NOTES:
  16. //
  17. // Version Date By Comments
  18. //--------------------------------------------------------------------
  19. // V3.1 01-07-99 JM Original
  20. //
  21. #include "stdafx.h"
  22. #include "LocalECB.h"
  23. #include "RenderConnector.h"
  24. #include "locale.h"
  25. // >>> Warning: Possible redefinition
  26. // should use #include "apgtscls.h"
  27. // Oleg 01.12.99
  28. #define CONT_TYPE_STR "application/x-www-form-urlencoded"
  29. //////////////////////////////////////////////////////////////////////
  30. // Construction/Destruction
  31. //////////////////////////////////////////////////////////////////////
  32. CLocalECB::CLocalECB(const VARIANT& name, const VARIANT& value, int count,
  33. HANDLE hEvent, CString* pstrWriteClient,
  34. CRenderConnector* pRenderConnector,
  35. bool bSetLocale, CString& strLocaleSetting)
  36. : CTSNameValueMgr(name, value, count),
  37. m_dwHttpStatusCode(500),
  38. m_hEvent(hEvent),
  39. m_strWriteClient(*pstrWriteClient),
  40. m_pRenderConnector(pRenderConnector),
  41. m_bSetLocale( bSetLocale ),
  42. m_strLocaleSetting( strLocaleSetting )
  43. {
  44. }
  45. CLocalECB::CLocalECB(const CArrNameValue& arr, HANDLE hEvent,
  46. CString* pstrWriteClient, CRenderConnector* pRenderConnector,
  47. bool bSetLocale, CString& strLocaleSetting)
  48. : CTSNameValueMgr(arr),
  49. m_dwHttpStatusCode(500),
  50. m_hEvent(hEvent),
  51. m_strWriteClient(*pstrWriteClient),
  52. m_pRenderConnector(pRenderConnector),
  53. m_bSetLocale( bSetLocale ),
  54. m_strLocaleSetting( strLocaleSetting )
  55. {
  56. }
  57. CLocalECB::CLocalECB(CString* pstrWriteClient)
  58. : CTSNameValueMgr(),
  59. m_dwHttpStatusCode(500),
  60. m_hEvent(NULL),
  61. m_strWriteClient(*pstrWriteClient),
  62. m_pRenderConnector(NULL),
  63. m_bSetLocale( false )
  64. {
  65. }
  66. CLocalECB::~CLocalECB()
  67. {
  68. }
  69. // ConnID is irrelevant on Local TS, so we always return 0.
  70. HCONN CLocalECB::GetConnID() const
  71. {
  72. return 0;
  73. }
  74. DWORD CLocalECB::SetHttpStatusCode(DWORD dwHttpStatusCode)
  75. {
  76. m_dwHttpStatusCode = dwHttpStatusCode;
  77. return m_dwHttpStatusCode;
  78. }
  79. // We act as if Method is always "POST"
  80. LPSTR CLocalECB::GetMethod() const
  81. {
  82. return "POST";
  83. }
  84. // Since we are always emulating "POST", there is no query string
  85. LPSTR CLocalECB::GetQueryString() const
  86. {
  87. return "";
  88. }
  89. DWORD CLocalECB::GetBytesAvailable() const
  90. {
  91. return CTSNameValueMgr::GetData().GetLength();
  92. }
  93. LPBYTE CLocalECB::GetData() const
  94. {
  95. return (LPBYTE)(LPCTSTR)CTSNameValueMgr::GetData();
  96. }
  97. // always say it's valid content ("application/x-www-form-urlencoded")
  98. LPSTR CLocalECB::GetContentType() const
  99. {
  100. return CONT_TYPE_STR;
  101. }
  102. // In Local TS, always return a null string.
  103. BOOL CLocalECB::GetServerVariable
  104. ( /*HCONN hConn,*/
  105. LPCSTR lpszVariableName,
  106. LPVOID lpvBuffer,
  107. LPDWORD lpdwSize )
  108. {
  109. if (CString(_T("SERVER_NAME")) == CString(lpszVariableName))
  110. {
  111. memset(lpvBuffer, 0, *lpdwSize);
  112. _tcsncpy((LPTSTR)lpvBuffer, _T("Local TS - no IP address"), *lpdwSize-2); // -2 in case og unicode
  113. return TRUE;
  114. }
  115. return FALSE;
  116. }
  117. BOOL CLocalECB::WriteClient
  118. ( /*HCONN ConnID,*/
  119. LPCSTR Buffer, // EXTENSION_CONTROL_BLOCK::WriteClient uses LPVOID, but it should
  120. // only be legit to pass SBCS text, so we're enforcing that.
  121. // Also, we're adding const-ness. Clearly, this really is const,
  122. // but EXTENSION_CONTROL_BLOCK::WriteClient fails to declare it so.
  123. LPDWORD lpdwBytes
  124. /* , DWORD dwReserved */
  125. )
  126. {
  127. if (*lpdwBytes <= 0)
  128. {
  129. if (m_pRenderConnector)
  130. m_pRenderConnector->Render(_T(""));
  131. else
  132. m_strWriteClient = _T("");
  133. if (m_hEvent)
  134. ::SetEvent(m_hEvent);
  135. return FALSE;
  136. }
  137. TCHAR* buf = new TCHAR[*lpdwBytes+1];
  138. //[BC-03022001] - added check for NULL ptr to satisfy MS code analysis tool.
  139. if(!buf)
  140. return FALSE;
  141. memcpy(buf, Buffer, *lpdwBytes);
  142. buf[*lpdwBytes] = 0;
  143. // Set the locale if requested.
  144. CString strOrigLocale;
  145. if (m_bSetLocale)
  146. strOrigLocale= _tsetlocale( LC_CTYPE, m_strLocaleSetting );
  147. if (m_pRenderConnector)
  148. {
  149. m_pRenderConnector->Render(buf);
  150. m_pRenderConnector->SetLocked(false);
  151. }
  152. else
  153. m_strWriteClient = buf;
  154. // Restore the locale if requested.
  155. if (m_bSetLocale)
  156. strOrigLocale= _tsetlocale( LC_CTYPE, strOrigLocale );
  157. if (m_hEvent)
  158. ::SetEvent(m_hEvent);
  159. delete [] buf;
  160. return TRUE;
  161. }
  162. // The 2 imaginably germane values of dwHSERRequest are:
  163. // HSE_REQ_SEND_RESPONSE_HEADER:Sends a complete HTTP server response header, including the
  164. // status, server version, message time, and MIME version. The ISAPI extension should
  165. // append other HTTP headers such as the content type and content length, followed by
  166. // an extra \r\n. This option allows the function to take only text, up to the first
  167. // \0 terminator. The function with this parameter should only be called once per request.
  168. // HSE_REQ_DONE_WITH_SESSION: Specifies that if the server extension holds on to the session
  169. // because of extended processing requirements, the server must be notified when the
  170. // session is finished so the server can close it and free its related structures.
  171. // The parameters lpdwSize, and lpdwDataType are ignored.
  172. // The lpvBuffer parameter may optionally point to a DWORD that contains HSE_STATUS codes.
  173. // IIS recognizes HSE_STATUS_SUCCESS_WITH_KEEP_CONN for keeping the IIS connection alive
  174. // if the client also requests to keep the connection alive.
  175. // This parameter must be sent to the server if the HSE_IO_DISCONNECT_AFTER_SEND parameter
  176. // has been included in the HSE_TF_INFO structure as part of a HSE_REQ_TRANSMIT_FILE request.
  177. // This parameter will explicitly close the connection.
  178. // >>> Have no idea how to emulate server's behavior in case of local troubleshooter.
  179. // Oleg 01.13.99
  180. BOOL CLocalECB::ServerSupportFunction
  181. ( /*HCONN hConn,*/
  182. DWORD dwHSERRequest,
  183. LPVOID lpvBuffer,
  184. LPDWORD lpdwSize,
  185. LPDWORD lpdwDataType )
  186. {
  187. return FALSE;
  188. }
  189. const CString& CLocalECB::GetWriteClient() const
  190. {
  191. return m_strWriteClient;
  192. }