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.

413 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. ulparse.h
  5. Abstract:
  6. Contains public definitions for ulparse.c.
  7. Author:
  8. Henry Sanders (henrysa) 11-May-1998
  9. Revision History:
  10. Rajesh Sundaram (rajeshs) 15-Feb-2002 - Reorganized from parse.h
  11. rcvhdrs.h, parsep.h.
  12. --*/
  13. #ifndef _ULPARSE_H_
  14. #define _ULPARSE_H_
  15. NTSTATUS
  16. UlLookupHeader(
  17. IN PUL_INTERNAL_REQUEST pRequest,
  18. IN PUCHAR pHttpRequest,
  19. IN ULONG HttpRequestLength,
  20. IN PHEADER_MAP_ENTRY pCurrentHeaderMap,
  21. IN ULONG HeaderMapCount,
  22. IN BOOLEAN bIgnore,
  23. OUT ULONG * pBytesTaken
  24. );
  25. NTSTATUS
  26. UlParseHeaderWithHint(
  27. IN PUL_INTERNAL_REQUEST pRequest,
  28. IN PUCHAR pHttpRequest,
  29. IN ULONG HttpRequestLength,
  30. IN PHEADER_MAP_ENTRY pHeaderHintMap,
  31. OUT ULONG * pBytesTaken
  32. );
  33. NTSTATUS
  34. UlParseHeader(
  35. IN PUL_INTERNAL_REQUEST pRequest,
  36. IN PUCHAR pHttpRequest,
  37. IN ULONG HttpRequestLength,
  38. OUT ULONG * pBytesTaken
  39. );
  40. NTSTATUS
  41. UlParseHeaders(
  42. PUL_INTERNAL_REQUEST pRequest,
  43. PUCHAR pBuffer,
  44. ULONG BufferLength,
  45. PULONG pBytesTaken
  46. );
  47. //
  48. // The main HTTP parse routine(s).
  49. //
  50. NTSTATUS
  51. UlParseHttp(
  52. IN PUL_INTERNAL_REQUEST pRequest,
  53. IN PUCHAR pHttpRequest,
  54. IN ULONG HttpRequestLength,
  55. OUT ULONG *pBytesTaken
  56. );
  57. NTSTATUS
  58. UlGenerateRoutingToken(
  59. IN OUT PUL_INTERNAL_REQUEST pRequest,
  60. IN BOOLEAN IpBased
  61. );
  62. NTSTATUS
  63. UlGenerateFixedHeaders(
  64. IN HTTP_VERSION Version,
  65. IN PHTTP_RESPONSE pUserResponse,
  66. IN USHORT HttpStatusCode,
  67. IN ULONG BufferLength,
  68. IN KPROCESSOR_MODE AccessMode,
  69. OUT PUCHAR pBuffer,
  70. OUT PULONG pBytesCopied
  71. );
  72. //
  73. // Date header cache.
  74. //
  75. ULONG
  76. UlGenerateDateHeader(
  77. OUT PUCHAR pBuffer,
  78. OUT PLARGE_INTEGER pSystemTime
  79. );
  80. NTSTATUS
  81. UlInitializeDateCache(
  82. VOID
  83. );
  84. VOID
  85. UlTerminateDateCache(
  86. VOID
  87. );
  88. NTSTATUS
  89. UlComputeFixedHeaderSize(
  90. IN HTTP_VERSION Version,
  91. IN PHTTP_RESPONSE pUserResponse,
  92. IN KPROCESSOR_MODE AccessMode,
  93. OUT PULONG pHeaderLength
  94. );
  95. ULONG
  96. UlComputeMaxVariableHeaderSize(
  97. VOID
  98. );
  99. VOID
  100. UlGenerateVariableHeaders(
  101. IN UL_CONN_HDR ConnHeader,
  102. IN BOOLEAN GenerateDate,
  103. IN PUCHAR pContentLengthString,
  104. IN ULONG ContentLengthStringLength,
  105. OUT PUCHAR pBuffer,
  106. OUT PULONG pBytesCopied,
  107. OUT PLARGE_INTEGER pDateTime
  108. );
  109. NTSTATUS
  110. UlAppendHeaderValue(
  111. IN PUL_INTERNAL_REQUEST pRequest,
  112. IN PUL_HTTP_HEADER pHttpHeader,
  113. IN PUCHAR pHeader,
  114. IN USHORT HeaderLength
  115. );
  116. //
  117. // Server header handlers.
  118. //
  119. //
  120. NTSTATUS
  121. UlSingleHeaderHandler(
  122. IN PUL_INTERNAL_REQUEST pRequest,
  123. IN PUCHAR pHeader,
  124. IN USHORT HeaderLength,
  125. IN HTTP_HEADER_ID HeaderID,
  126. OUT PULONG pBytesTaken
  127. );
  128. NTSTATUS
  129. UlMultipleHeaderHandler(
  130. IN PUL_INTERNAL_REQUEST pRequest,
  131. IN PUCHAR pHeader,
  132. IN USHORT HeaderLength,
  133. IN HTTP_HEADER_ID HeaderID,
  134. OUT PULONG pBytesTaken
  135. );
  136. NTSTATUS
  137. UlAcceptHeaderHandler(
  138. IN PUL_INTERNAL_REQUEST pRequest,
  139. IN PUCHAR pHeader,
  140. IN USHORT HeaderLength,
  141. IN HTTP_HEADER_ID HeaderID,
  142. OUT PULONG pBytesTaken
  143. );
  144. NTSTATUS
  145. UlHostHeaderHandler(
  146. IN PUL_INTERNAL_REQUEST pRequest,
  147. IN PUCHAR pHeader,
  148. IN USHORT HeaderLength,
  149. IN HTTP_HEADER_ID HeaderID,
  150. OUT PULONG pBytesTaken
  151. );
  152. //
  153. // Utils
  154. //
  155. PCHAR
  156. UlCopyHttpVerb(
  157. IN OUT PCHAR psz,
  158. IN PUL_INTERNAL_REQUEST pRequest,
  159. IN CHAR chTerminator
  160. );
  161. ULONG
  162. UlCheckCacheControlHeaders(
  163. IN PUL_INTERNAL_REQUEST pRequest,
  164. IN PUL_URI_CACHE_ENTRY pUriCacheEntry,
  165. IN BOOLEAN ResumeParsingOnSendCompletion
  166. );
  167. BOOLEAN
  168. UlIsAcceptHeaderOk(
  169. IN PUL_INTERNAL_REQUEST pRequest,
  170. IN PUL_URI_CACHE_ENTRY pUriCacheEntry
  171. );
  172. __inline BOOLEAN
  173. UlIsContentEncodingOk(
  174. IN PUL_INTERNAL_REQUEST pRequest,
  175. IN PUL_URI_CACHE_ENTRY pUriCacheEntry
  176. )
  177. /*++
  178. Routine Description:
  179. Checks the cached response against the AcceptEncoding header in the request
  180. to see if it can satisfy the requested Content-Encoding(s).
  181. It is assumed that the Content-Type of the cached item is acceptable to the
  182. client.
  183. Arguments:
  184. pRequest - The request to check.
  185. pUriCacheEntry - The cache entry that might possibly match.
  186. Returns:
  187. TRUE At least one of the possible media encodings matched the Content-
  188. Encoding of the cached entry.
  189. FALSE None of the requested media encodings matched the Content-Type
  190. of the cached entry.
  191. --*/
  192. {
  193. BOOLEAN bRet = FALSE;
  194. ULONG Len;
  195. PUCHAR pHdr;
  196. PUCHAR pTmp;
  197. PUCHAR pEncoding;
  198. ULONG EncodingLen;
  199. ASSERT(UL_IS_VALID_INTERNAL_REQUEST(pRequest));
  200. ASSERT(IS_VALID_URI_CACHE_ENTRY(pUriCacheEntry));
  201. if (pRequest->HeaderValid[HttpHeaderAcceptEncoding])
  202. {
  203. Len = pRequest->Headers[HttpHeaderAcceptEncoding].HeaderLength;
  204. pHdr = pRequest->Headers[HttpHeaderAcceptEncoding].pHeader;
  205. }
  206. else
  207. {
  208. Len = 0;
  209. pHdr = NULL;
  210. }
  211. pEncoding = pUriCacheEntry->pContentEncoding;
  212. EncodingLen = pUriCacheEntry->ContentEncodingLength ;
  213. if (Len && pHdr)
  214. {
  215. //
  216. // If there is a q-value present on the request Accept-Encoding, bail out
  217. //
  218. if ( strnchr( (const char *) pHdr, ';', Len ) )
  219. {
  220. bRet = FALSE;
  221. goto end;
  222. }
  223. //
  224. // See if the cached item is encoded or in its "identity" form.
  225. //
  226. if ( 0 == EncodingLen )
  227. {
  228. //
  229. // Since the only way the "identity" form of a request can be specificly
  230. // excluded is by use of a q-value, and we know we don't have a q-value
  231. // at this point, we may serve the cached item.
  232. //
  233. bRet = TRUE;
  234. goto end;
  235. }
  236. //
  237. // If non-zero, EncodingLen includes the terminating NULL.
  238. // Don't compare the NULL.
  239. //
  240. EncodingLen--;
  241. //
  242. // Walk the Accept-Encoding list, looking for a match
  243. //
  244. while ( Len )
  245. {
  246. //
  247. // Wildcard check
  248. //
  249. if ( '*' == *pHdr && !IS_HTTP_TOKEN(pHdr[1]))
  250. {
  251. // Wildcard Hit!
  252. bRet = TRUE;
  253. goto end;
  254. }
  255. if (EncodingLen > Len)
  256. {
  257. // Bad! No more string left...Bail out.
  258. bRet = FALSE;
  259. goto end;
  260. }
  261. //
  262. // Exact token match
  263. // FUTURE: This should be case-insensitive compare
  264. //
  265. if ( (0 == _strnicmp(
  266. (const char *) pHdr,
  267. (const char *) pEncoding,
  268. EncodingLen
  269. )) &&
  270. !IS_HTTP_TOKEN(pHdr[EncodingLen]) )
  271. {
  272. // Hit!
  273. bRet = TRUE;
  274. goto end;
  275. }
  276. //
  277. // Didn't match this one; advance to next Content-Type in the Accept field
  278. //
  279. pTmp = (PUCHAR) strnchr( (const char *) pHdr, ',', Len);
  280. if (pTmp)
  281. {
  282. // Found a comma; step over it and any whitespace.
  283. ASSERT ( Len > DIFF(pTmp - pHdr));
  284. Len -= (DIFF(pTmp - pHdr) +1);
  285. pHdr = (pTmp+1);
  286. while( Len && IS_HTTP_LWS(*pHdr) )
  287. {
  288. pHdr++;
  289. Len--;
  290. }
  291. }
  292. else
  293. {
  294. bRet = FALSE;
  295. goto end;
  296. }
  297. }
  298. }
  299. else
  300. {
  301. //
  302. // If there wasn't an Accept-Encoding on the request, only serve if the
  303. // cached item is in its "identity" form.
  304. //
  305. if (0 == EncodingLen)
  306. {
  307. bRet = TRUE;
  308. }
  309. }
  310. //
  311. // If we got here, NOT OK!
  312. //
  313. end:
  314. UlTrace(PARSER,
  315. ("UlIsContentEncodingOk: returning %s\n",
  316. bRet ? "TRUE" : "FALSE"
  317. ));
  318. return bRet;
  319. }
  320. VOID
  321. UlGetTypeAndSubType(
  322. IN PCSTR pStr,
  323. IN ULONG StrLen,
  324. IN PUL_CONTENT_TYPE pContentType
  325. );
  326. #if DBG
  327. PCSTR
  328. UlVerbToString(
  329. HTTP_VERB Verb
  330. );
  331. PCSTR
  332. UlParseStateToString(
  333. PARSE_STATE ParseState
  334. );
  335. #endif // DBG
  336. #endif // _ULPARSE_H_