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.

210 lines
5.8 KiB

  1. /*--
  2. Copyright (c) 1995-1999 Microsoft Corporation
  3. Module Name: asp.cpp
  4. Author: John Spaith
  5. Abstract: ASP Handler
  6. --*/
  7. #include "pch.h"
  8. #pragma hdrstop
  9. #include "httpd.h"
  10. //****************************************************************
  11. // Called by httpd before running ASP
  12. //****************************************************************
  13. BOOL InitASP(SCRIPT_LANG *psl, UINT *plCodePage, LCID *plcid)
  14. {
  15. CReg reg(HKEY_LOCAL_MACHINE, RK_ASP);
  16. PCWSTR pwszLanguage = NULL; // don't free this, points to a buffer inside CReg
  17. if (NULL != (pwszLanguage = reg.ValueSZ(RV_ASP_LANGUAGE)) &&
  18. (0 == _wcsicmp(pwszLanguage,L"JSCRIPT") ||
  19. 0 == _wcsicmp(pwszLanguage,L"JAVASCRIPT")))
  20. {
  21. *psl = JSCRIPT;
  22. }
  23. else
  24. *psl = VBSCRIPT;
  25. *plCodePage = (UINT) reg.ValueDW(RV_ASP_CODEPAGE,CP_ACP);
  26. *plcid = (LCID) reg.ValueDW(RV_ASP_LCID,LOCALE_SYSTEM_DEFAULT);
  27. TraceTag(ttidWebServer, "ASP Registry defaults -- language = %s, lcid = %d, codepage = %d\r\n",
  28. (*psl == JSCRIPT) ? L"JSCRIPT" : L"VBSCRIPT", *plCodePage, *plcid);
  29. return TRUE;
  30. }
  31. // This is the only fcn that httpd calls to get the ASP.dll loaded and running.
  32. // NOTE: The ASP dll is responsible for reporting all it's own error messages.
  33. // The only time httpd does this is if the ASP AV'd or if the file wasn't found.
  34. // ExecuteASP in asp.dll only returns FALSE if there was an AV.
  35. BOOL CHttpRequest::ExecuteASP()
  36. {
  37. DEBUG_CODE_INIT;
  38. DWORD dwRet = HSE_STATUS_ERROR;
  39. ASP_CONTROL_BLOCK ACB;
  40. CISAPI *pISAPI = NULL;
  41. HINSTANCE hInst = 0;
  42. // First make sure file exists. If it doesn't, don't bother making the call
  43. // to the dll.
  44. if ( (DWORD)-1 == GetFileAttributes(m_wszPath))
  45. {
  46. m_rs = GLEtoStatus( GetLastError());
  47. myleave(620);
  48. }
  49. if (NULL==(hInst=g_pVars->m_pISAPICache->Load(ASP_DLL_NAME,&pISAPI,SCRIPT_TYPE_ASP)))
  50. {
  51. m_rs = STATUS_INTERNALERR;
  52. myleave(621);
  53. }
  54. if (! FillACB((void *) &ACB,hInst))
  55. {
  56. // FillACB does the right thing in this case, don't do anything here.
  57. myleave(0);
  58. }
  59. StartRemoveISAPICacheIfNeeded();
  60. __try
  61. {
  62. dwRet = pISAPI->CallASP(&ACB);
  63. }
  64. __except(1)
  65. {
  66. m_rs = STATUS_INTERNALERR;
  67. g_pVars->m_pLog->WriteEvent(IDS_HTTPD_EXT_EXCEPTION,L"asp.dll",GetExceptionCode(),"HttpExtensionProc",GetLastError());
  68. myleave(623);
  69. }
  70. m_fKeepAlive = (dwRet==HSE_STATUS_SUCCESS_AND_KEEP_CONN);
  71. done:
  72. // Don't free hInsnt. The cache does this automatically.
  73. TraceTag(ttidWebServer, "ExecuteASP Failed, err = %d, GLE = %d",err,GetLastError());
  74. g_pVars->m_pISAPICache->Unload(pISAPI);
  75. return(dwRet!=HSE_STATUS_ERROR);
  76. }
  77. //**************************************************************
  78. // Callback fcns for ASP
  79. //**************************************************************
  80. // Modifies headers in our extended header information for Response Put Methods.
  81. BOOL WINAPI AddHeader (HCONN hConn, LPSTR lpszName, LPSTR lpszValue)
  82. {
  83. CHECKHCONN(hConn);
  84. return((CHttpRequest*)hConn)->m_bufRespHeaders.AddHeader(lpszName, lpszValue,TRUE);
  85. }
  86. // If there's a buffer, flush it to sock.
  87. BOOL WINAPI Flush(HCONN hConn)
  88. {
  89. CHECKHCONN(hConn);
  90. CHttpRequest *pRequest = (CHttpRequest*)hConn;
  91. // all these rules straight from docs
  92. if (FALSE == pRequest->m_fBufferedResponse)
  93. return FALSE;
  94. return pRequest->m_bufRespBody.SendBuffer(pRequest->m_socket,pRequest);
  95. }
  96. // If there's a buffer, clear it.
  97. BOOL WINAPI Clear(HCONN hConn)
  98. {
  99. CHECKHCONN(hConn);
  100. CHttpRequest *pRequest = (CHttpRequest*)hConn;
  101. // all these rules straight from docs
  102. if (FALSE == pRequest->m_fBufferedResponse)
  103. return FALSE;
  104. pRequest->m_bufRespBody.Reset();
  105. return TRUE;
  106. }
  107. // Toggles buffer. Error checking on this done in ASP calling fnc.
  108. BOOL WINAPI SetBuffer(HCONN hConn, BOOL fBuffer)
  109. {
  110. CHECKHCONN(hConn);
  111. ((CHttpRequest*)hConn)->m_fBufferedResponse = fBuffer;
  112. return TRUE;
  113. }
  114. // Setup struct for ASP dll
  115. BOOL CHttpRequest::FillACB(void *p, HINSTANCE hInst)
  116. {
  117. PASP_CONTROL_BLOCK pcb = (PASP_CONTROL_BLOCK) p;
  118. pcb->cbSize = sizeof(ASP_CONTROL_BLOCK);
  119. pcb->ConnID = (HCONN) this;
  120. pcb->cbTotalBytes = m_dwContentLength;
  121. pcb->wszFileName = m_wszPath;
  122. pcb->pszVirtualFileName = m_pszURL;
  123. if (m_dwContentLength)
  124. {
  125. // If we've received > m_dwPostReadSize bytes POST data, need to do ReadClient.
  126. // This is an unlikely scenario - if they want to do huge file uploads
  127. // we'll point them to ISAPI ReadClient. We've read in 1st buf already.
  128. if (m_dwContentLength > g_pVars->m_dwPostReadSize)
  129. {
  130. HRINPUT hi = m_bufRequest.RecvBody(m_socket, m_dwContentLength - g_pVars->m_dwPostReadSize,TRUE);
  131. if (hi != INPUT_OK && hi != INPUT_NOCHANGE)
  132. {
  133. CHttpResponse resp(m_socket,m_rs = STATUS_BADREQ,CONN_CLOSE,this);
  134. resp.SendResponse();
  135. return FALSE;
  136. }
  137. if (g_pVars->m_fFilters && hi != INPUT_NOCHANGE &&
  138. ! CallFilter(SF_NOTIFY_READ_RAW_DATA))
  139. {
  140. return FALSE;
  141. }
  142. }
  143. pcb->pszForm = (PSTR) m_bufRequest.Data();
  144. }
  145. else
  146. pcb->pszForm = NULL;
  147. pcb->pszQueryString = m_pszQueryString;
  148. pcb->pszCookie = m_pszCookie;
  149. pcb->scriptLang = g_pVars->m_ASPScriptLang;
  150. pcb->lcid = g_pVars->m_ASPlcid;
  151. pcb->lCodePage = g_pVars->m_lASPCodePage;
  152. pcb->hInst = hInst;
  153. pcb->GetServerVariable = ::GetServerVariable;
  154. pcb->WriteClient = ::WriteClient;
  155. pcb->ServerSupportFunction = ::ServerSupportFunction;
  156. pcb->AddHeader = ::AddHeader;
  157. pcb->Flush = ::Flush;
  158. pcb->Clear = ::Clear;
  159. pcb->SetBuffer = ::SetBuffer;
  160. return TRUE;
  161. }