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.

642 lines
18 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1994-1996 **/
  4. /**********************************************************************/
  5. /*
  6. httpreq.hxx
  7. This module contains the http request class
  8. FILE HISTORY:
  9. Johnl 23-Aug-1994 Created
  10. MuraliK 22-Jan-1996 Cache UNC virtual root impersonation handle.
  11. */
  12. #ifndef _HTTPREQ_HXX_
  13. #define _HTTPREQ_HXX_
  14. # include "basereq.hxx"
  15. # include "tsunami.hxx"
  16. # include "wamreq.hxx"
  17. # include "WamW3.hxx"
  18. # include "ExecDesc.hxx"
  19. // Forward reference
  20. class HTTP_REQUEST;
  21. class FILENAME_LOCK;
  22. //
  23. // The sub-states a PUT request can pass through.
  24. //
  25. enum PUT_STATE
  26. {
  27. PSTATE_START = 0, // The PUT is just starting
  28. PSTATE_READING, // The PUT is reading from the network
  29. PSTATE_DISCARD_READ, // Reading a chunk to be discarded.
  30. PSTATE_DISCARD_CHUNK // Discarding a read chunk.
  31. };
  32. //
  33. // The type of write actions we can take.
  34. //
  35. enum WRITE_TYPE
  36. {
  37. WTYPE_CREATE = 0, // Create a file
  38. WTYPE_WRITE, // Write a file
  39. WTYPE_DELETE // Delete a file
  40. };
  41. extern BOOL DisposeOpenURIFileInfo(IN PVOID pvOldBlock);
  42. extern BOOL GetTrueRedirectionSource( LPSTR pszURL,
  43. PIIS_SERVER_INSTANCE pInstance,
  44. CHAR * pszDestination,
  45. BOOL bIsString,
  46. STR * pstrTrueSource );
  47. extern VOID
  48. IncrErrorCount(
  49. IMDCOM* pCom,
  50. DWORD dwProp,
  51. LPCSTR pszPath,
  52. LPBOOL pbOverTheLimit
  53. );
  54. /*******************************************************************
  55. CLASS: HTTP_REQUEST
  56. SYNOPSIS: Parses and stores the information related to an HTTP request.
  57. Also implements the verbs in the request.
  58. HISTORY:
  59. Johnl 24-Aug-1994 Created
  60. ********************************************************************/
  61. class HTTP_REQUEST : public HTTP_REQ_BASE
  62. {
  63. public:
  64. //
  65. // Prototype member function pointer for RFC822 field name processing
  66. //
  67. typedef BOOL (HTTP_REQUEST::*PMFN_ONGRAMMAR)( CHAR * pszValue );
  68. //
  69. // Prototype member function pointer for GetInfo?() functions
  70. // ? := A .. Z
  71. //
  72. typedef BOOL (HTTP_REQUEST::*PFN_GET_INFO)(
  73. const CHAR * pszValName,
  74. DWORD cchValName,
  75. CHAR * pchBuffer,
  76. DWORD * lpcchBuffer
  77. );
  78. //
  79. // This is the work entry point that is driven by the completion of the
  80. // async IO.
  81. //
  82. virtual BOOL DoWork( BOOL * pfFinished );
  83. //
  84. // Parses the client's HTTP request
  85. //
  86. virtual BOOL Parse( const CHAR* pchRequest,
  87. DWORD cbData,
  88. DWORD * pcbExtraData,
  89. BOOL * pfHandled,
  90. BOOL * pfFinished );
  91. virtual VOID EndOfRequest( VOID );
  92. virtual VOID SessionTerminated( VOID);
  93. //
  94. // Parse the verb and URL information
  95. //
  96. dllexp
  97. BOOL OnVerb ( CHAR * pszValue );
  98. BOOL OnURL ( CHAR * pszValue );
  99. BOOL OnVersion ( CHAR * pszValue );
  100. BOOL OnAccept ( CHAR * pszValue );
  101. // BOOL OnAcceptEncoding( CHAR * pszValue );
  102. // BOOL OnAcceptLanguage( CHAR * pszValue );
  103. // BOOL OnAuthorization ( CHAR * pszValue );
  104. BOOL OnConnection ( CHAR * pszValue );
  105. // BOOL OnContentLength ( CHAR * pszValue );
  106. BOOL OnContentType ( CHAR * pszValue );
  107. // BOOL OnDate ( CHAR * pszValue );
  108. // BOOL OnForwarded ( CHAR * pszValue );
  109. // BOOL OnFrom ( CHAR * pszValue );
  110. // BOOL OnIfModifiedSince( CHAR * pszValue );
  111. // BOOL OnMandatory ( CHAR * pszValue );
  112. // BOOL OnMessageID ( CHAR * pszValue );
  113. // BOOL OnMimeVersion ( CHAR * pszValue );
  114. // BOOL OnPragma ( CHAR * pszValue );
  115. // BOOL OnProxyAuthorization( CHAR * pszValue );
  116. // BOOL OnReferer ( CHAR * pszValue );
  117. // BOOL OnUserAgent ( CHAR * pszValue );
  118. BOOL OnTransferEncoding( CHAR * pszValue );
  119. BOOL OnLockToken ( CHAR * pszValue );
  120. BOOL OnTranslate ( CHAR * pszValue );
  121. BOOL OnIf ( CHAR * pszValue );
  122. BOOL ProcessURL( BOOL * pfFinished, BOOL * pfHandled = NULL );
  123. //
  124. // Verb worker methods
  125. //
  126. BOOL DoGet ( BOOL * pfFinished );
  127. BOOL DoTrace ( BOOL * pfFinished );
  128. BOOL DoTraceCk ( BOOL * pfFinished );
  129. BOOL DoPut ( BOOL * pfFinished );
  130. BOOL DoDelete ( BOOL * pfFinished );
  131. BOOL DoUnknown ( BOOL * pfFinished );
  132. BOOL DoOptions ( BOOL * pfFinished );
  133. BOOL DoDirList ( const STR & strPath,
  134. BUFFER * pbufResp,
  135. BOOL * pfFinished );
  136. //
  137. // HTTP redirector methods
  138. //
  139. BOOL DoRedirect( BOOL *pfFinished );
  140. // Re-processes the specified URL applying htverb
  141. //
  142. dllexp
  143. BOOL ReprocessURL( TCHAR * pchURL,
  144. enum HTTP_VERB htverb = HTV_UNKNOWN );
  145. BOOL BuildResponseHeader( BUFFER * pbufResponse,
  146. STR * pstrPath = NULL,
  147. TS_OPEN_FILE_INFO * pFile = NULL,
  148. BOOL * pfHandled = NULL,
  149. STR * pstrAlternateStatus = NULL,
  150. LPBOOL pfFinished = NULL );
  151. BOOL BuildFileResponseHeader( BUFFER * pbufResponse,
  152. STR * pstrPath = NULL,
  153. TS_OPEN_FILE_INFO * pFile = NULL,
  154. BOOL * pfHandled = NULL,
  155. LPBOOL pfFinished = NULL );
  156. BOOL RequestRenegotiate( LPBOOL pAccepted );
  157. BOOL DoneRenegotiate( BOOL fSuccess );
  158. //
  159. // Retrieves various bits of request information
  160. //
  161. dllexp BOOL GetInfo( const CHAR * pszValName,
  162. STR * pstr,
  163. BOOL * pfFound = NULL );
  164. dllexp BOOL GetInfoForName(
  165. const CHAR * pszValName,
  166. CHAR * pchBuffer,
  167. DWORD * lpcchBuffer
  168. );
  169. BOOL ValidateURL( MB & mb, LPSTR szPath );
  170. BOOL IsAcceptAllSet( VOID ) const
  171. { return _fAcceptsAll; }
  172. HANDLE QueryFileHandle( VOID ) const
  173. { return _pGetFile ? _pGetFile->QueryFileHandle() : INVALID_HANDLE_VALUE; }
  174. dllexp
  175. BOOL LookupVirtualRoot( OUT STR * pstrPath,
  176. IN const CHAR * pszURL,
  177. IN ULONG cchURL,
  178. OUT DWORD * pcchDirRoot = NULL,
  179. OUT DWORD * pcchVRoot = NULL,
  180. OUT DWORD * pdwMask = NULL,
  181. OUT BOOL * pfFinished = NULL,
  182. IN BOOL fGetAcl = FALSE,
  183. OUT PW3_METADATA* ppMetaData = NULL,
  184. OUT PW3_URI_INFO* ppURIBlob = NULL );
  185. BOOL CacheUri( IN PW3_SERVER_INSTANCE pInstance,
  186. OUT PW3_URI_INFO* ppURIInfo,
  187. IN PW3_METADATA pMetaData,
  188. IN LPCSTR pszURL,
  189. IN ULONG cchURL,
  190. IN STR* pstrPhysicalPath,
  191. IN STR* pstrUnmappedPhysicalPath
  192. );
  193. DWORD GetFilePerms( VOID ) const
  194. { return _pMetaData->QueryAccessPerms(); }
  195. STR * QueryDefaultFiles( VOID )
  196. { return _pMetaData->QueryDefaultDocs(); }
  197. BOOL NormalizeUrl( LPSTR pszUrl );
  198. //
  199. // Manages buffer lists
  200. //
  201. static DWORD Initialize( VOID );
  202. static VOID Terminate( VOID );
  203. BOOL ProcessAsyncGatewayIO(VOID);
  204. VOID CancelAsyncGatewayIO(VOID);
  205. BOOL CancelPreconditions();
  206. VOID CloseGetFile(VOID);
  207. //
  208. // Binds this HTTP_REQUEST to a WAM_REQUEST - called when running an ISA
  209. //
  210. VOID SetWamRequest( WAM_REQUEST * pWamRequest )
  211. { _pWamRequest = pWamRequest; }
  212. WAM_REQUEST * QueryWamRequest( VOID) const
  213. { return ( _pWamRequest); }
  214. //
  215. // Called when an ISA wants to run a CGI or an ISAPI
  216. //
  217. BOOL ExecuteChildCGIBGI( CHAR * pszURL,
  218. DWORD dwChildExecFlags,
  219. CHAR * pszVerb );
  220. //
  221. // Called when an ISA wants to run a shell command
  222. //
  223. BOOL ExecuteChildCommand( CHAR * pszCommand,
  224. DWORD dwChildExecFlags );
  225. BOOL RequestAbortiveClose();
  226. BOOL CloseConnection();
  227. //
  228. // Constructor/Destructor
  229. //
  230. HTTP_REQUEST( CLIENT_CONN * pClientConn,
  231. PVOID pvInitialBuff,
  232. DWORD cbInitialBuff );
  233. virtual ~HTTP_REQUEST( VOID );
  234. //
  235. // Verb execution prototype
  236. //
  237. typedef BOOL (HTTP_REQUEST::*PMFN_DOVERB)( BOOL * pfFinished );
  238. PW3_METADATA GetWAMMetaData();
  239. DWORD QueryVersionMajor() { return ((DWORD)_VersionMajor & 0xf); }
  240. DWORD QueryVersionMinor() { return ((DWORD)_VersionMinor & 0xf); }
  241. VOID CleanupWriteState(VOID);
  242. VOID CheckValidAuth( VOID );
  243. virtual DWORD BuildAllowHeader(CHAR *pszURL, CHAR *pszTail);
  244. protected:
  245. //
  246. // Deals with a Map request
  247. //
  248. BOOL ProcessISMAP( LPTS_OPEN_FILE_INFO gFile,
  249. CHAR * pchFile,
  250. BUFFER * pstrResponse,
  251. BOOL * pfFound,
  252. BOOL * pfHandled );
  253. //
  254. // Deals with a CGI and BGI requests
  255. //
  256. BOOL ParseExecute( EXEC_DESCRIPTOR * pExec,
  257. BOOL fExecChildCGIBGI,
  258. BOOL *pfVerbExcluded,
  259. PW3_URI_INFO pURIInfo,
  260. enum HTTP_VERB Verb,
  261. CHAR * pszVerb );
  262. VOID SetupDAVExecute( EXEC_DESCRIPTOR * pExec,
  263. CHAR *szDavDll);
  264. BOOL ProcessGateway( EXEC_DESCRIPTOR * pExec,
  265. BOOL * pfHandled,
  266. BOOL * pfFinished,
  267. BOOL fTrusted = FALSE );
  268. BOOL ProcessCGI( EXEC_DESCRIPTOR * pExec,
  269. const STR * pstrPath,
  270. const STR * strWorkingDir,
  271. BOOL * pfHandled,
  272. BOOL * pfFinished = NULL,
  273. STR * pstrCmdLine = NULL );
  274. BOOL ProcessBGI( EXEC_DESCRIPTOR * pExec,
  275. BOOL * pfHandled,
  276. BOOL * pfFinished,
  277. BOOL fTrusted = FALSE,
  278. BOOL fStarScript = FALSE );
  279. BOOL DoWamRequest( EXEC_DESCRIPTOR * pExec,
  280. const STR & strPath,
  281. BOOL * pfHandled,
  282. BOOL * pfFinished );
  283. virtual BOOL Reset( BOOL fResetPipelineInfo );
  284. virtual VOID ReleaseCacheInfo( VOID );
  285. //
  286. // Range management
  287. //
  288. BOOL ScanRange( LPDWORD pdwOffset,
  289. LPDWORD pdwSizeToSend,
  290. BOOL *pfEntireFile,
  291. BOOL *pfIsLastRange );
  292. BOOL SendRange( DWORD dwBufLen,
  293. DWORD dwOffset,
  294. DWORD dwSizeToSend,
  295. BOOL fIsLast );
  296. void ProcessRangeRequest( STR *pstrPath,
  297. DWORD * pdwOffset,
  298. DWORD * pdwSizeToSend,
  299. BOOL * pfIsNxRange );
  300. //
  301. // Checks for and sends the default file if the feature is
  302. // enabled and the file exists
  303. //
  304. BOOL CheckDefaultLoad( STR * pstrPath,
  305. BOOL * pfHandled,
  306. BOOL * pfFinished );
  307. //
  308. // Did the client indicate they accept the specified MIME type?
  309. //
  310. BOOL DoesClientAccept( PCSTR pstr );
  311. //
  312. // Undoes the special parsing we did for gateway processing
  313. //
  314. DWORD QueryUrlFileSystemType()
  315. { return _dwFileSystemType; }
  316. BOOL DoAccessCheckOnUrl()
  317. { return TRUE; }
  318. //
  319. // Cleanup any temporary file.
  320. //
  321. VOID CleanupTempFile( VOID );
  322. //
  323. // ReadMetaData() is now called in two places. The second place is during
  324. // the execution of a child gateway from an ISA.
  325. //
  326. BOOL ReadMetaData( IN LPSTR strURL,
  327. OUT STR * pstrPhysicalPath,
  328. OUT PW3_METADATA * ppMetaData );
  329. //
  330. // Handle the various IF modifiers.
  331. //
  332. BOOL CheckPreconditions(LPTS_OPEN_FILE_INFO pFile,
  333. BOOL *pfFinished,
  334. BOOL *bReturn
  335. );
  336. BOOL CheckPreconditions(HANDLE hFile,
  337. BOOL bExisted,
  338. BOOL *pfFinished,
  339. BOOL *bReturn
  340. );
  341. BOOL SendPreconditionResponse( DWORD HT_Response,
  342. DWORD dwFlags,
  343. BOOL *pfFinished
  344. );
  345. BOOL FindInETagList( PCHAR LocalETag,
  346. PCHAR ETagList,
  347. BOOL bWeakCompare
  348. );
  349. BOOL BuildPutDeleteHeader(
  350. enum WRITE_TYPE Action
  351. );
  352. //
  353. // Support for down level clients (ones that dont send a host header)
  354. //
  355. BOOL DLCHandleRequest( BOOL * pfFinished );
  356. BOOL DLCMungeSimple( VOID );
  357. BOOL DLCGetCookie( CHAR * pszCookies,
  358. CHAR * pszCookieName,
  359. DWORD cbCookieName,
  360. STR * pstrCookieValue );
  361. VOID VerifyMimeType( VOID );
  362. BOOL FindHost( VOID );
  363. BOOL SendMetaDataError(PMETADATA_ERROR_INFO pErrorInfo);
  364. private:
  365. //
  366. // Flags
  367. //
  368. DWORD _fAcceptsAll:1; // Passed "Accept: */*" in the accept list
  369. DWORD _fAnyParams:1; // Did the URL have a '?'?
  370. DWORD _fSendToDav:1; // Send this request to DAV (if no CGI/BGI).
  371. DWORD _fDisableScriptmap:1; // If we get a TRANSLATE header, don't do script maps.
  372. DWORD _dwScriptMapFlags;
  373. STR _strGatewayImage; // .exe or .dll to run
  374. PMFN_DOVERB _pmfnVerb;
  375. //
  376. // Handle of directory, document or map file
  377. //
  378. TS_OPEN_FILE_INFO * _pGetFile;
  379. //
  380. // These are for the lookaside buffer list
  381. //
  382. static BOOL _fGlobalInit;
  383. //
  384. // This just caches the memory for the mime type
  385. //
  386. STR _strReturnMimeType;
  387. //
  388. // URL File system type
  389. //
  390. DWORD _dwFileSystemType;
  391. //
  392. // Execution descriptor block -> used when executing ISA or CGI
  393. //
  394. EXEC_DESCRIPTOR _Exec;
  395. DWORD _dwCallLevel;
  396. //
  397. // Ptr to wam request -> used when executing an ISA
  398. //
  399. WAM_REQUEST * _pWamRequest;
  400. //
  401. // PUT request related members
  402. enum PUT_STATE _putstate;
  403. STR _strTempFileName;
  404. HANDLE _hTempFileHandle;
  405. BOOL _bFileExisted:1;
  406. FILENAME_LOCK *_pFileNameLock;
  407. //
  408. // Used for possible EXECUTE vroots with default load file specified
  409. //
  410. BOOL _fPossibleDefaultExecute:1;
  411. static PFN_GET_INFO sm_GetInfoFuncs[26];
  412. BOOL GetInfoA(
  413. const CHAR * pszValName,
  414. DWORD cchValName,
  415. CHAR * pchBuffer,
  416. DWORD * lpcchBuffer
  417. );
  418. BOOL GetInfoC(
  419. const CHAR * pszValName,
  420. DWORD cchValName,
  421. CHAR * pchBuffer,
  422. DWORD * lpcchBuffer
  423. );
  424. BOOL GetInfoH(
  425. const CHAR * pszValName,
  426. DWORD cchValName,
  427. CHAR * pchBuffer,
  428. DWORD * lpcchBuffer
  429. );
  430. BOOL GetInfoI(
  431. const CHAR * pszValName,
  432. DWORD cchValName,
  433. CHAR * pchBuffer,
  434. DWORD * lpcchBuffer
  435. );
  436. BOOL GetInfoL(
  437. const CHAR * pszValName,
  438. DWORD cchValName,
  439. CHAR * pchBuffer,
  440. DWORD * lpcchBuffer
  441. );
  442. BOOL GetInfoP(
  443. const CHAR * pszValName,
  444. DWORD cchValName,
  445. CHAR * pchBuffer,
  446. DWORD * lpcchBuffer
  447. );
  448. BOOL GetInfoR(
  449. const CHAR * pszValName,
  450. DWORD cchValName,
  451. CHAR * pchBuffer,
  452. DWORD * lpcchBuffer
  453. );
  454. BOOL GetInfoS(
  455. const CHAR * pszValName,
  456. DWORD cchValName,
  457. CHAR * pchBuffer,
  458. DWORD * lpcchBuffer
  459. );
  460. BOOL GetInfoU(
  461. const CHAR * pszValName,
  462. DWORD cchValName,
  463. CHAR * pchBuffer,
  464. DWORD * lpcchBuffer
  465. );
  466. BOOL GetInfoMisc(
  467. const CHAR * pszValName,
  468. DWORD cchValName,
  469. CHAR * pchBuffer,
  470. DWORD * lpcchBuffer
  471. );
  472. //
  473. // Down level client support string
  474. //
  475. STR _strDLCString;
  476. };
  477. // IndexOfChar() is useful for computing the index into sm_GetInfoFuncs[]
  478. # define IndexOfChar(c) ((toupper(c)) - 'A')
  479. #endif //!_HTTPREQ_HXX_