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.

282 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. parsep.h
  5. Abstract:
  6. Contains all of the kernel mode HTTP parsing code.
  7. Author:
  8. Henry Sanders (henrysa) 04-May-1998
  9. Revision History:
  10. --*/
  11. #ifndef _PARSEP_H_
  12. #define _PARSEP_H_
  13. #define MIN_VERSION_SIZE (sizeof("HTTP/1.1") - 1)
  14. #define MAX_VERB_LENGTH (sizeof("PROPPATCH"))
  15. #define HTTP_11_VERSION 0x312e312f50545448
  16. #define HTTP_10_VERSION 0x302e312f50545448
  17. #define UPCASE_MASK ((ULONGLONG)0xdfdfdfdfdfdfdfdf)
  18. #define MAX_HEADER_LONG_COUNT 3
  19. #define MAX_HEADER_LENGTH (MAX_HEADER_LONG_COUNT * sizeof(ULONGLONG))
  20. #define NUMBER_HEADER_INDICIES 26
  21. //
  22. // Default Server: header if none provided by the application.
  23. //
  24. #define DEFAULT_SERVER_HDR "Microsoft-IIS/UL"
  25. #define DEFAULT_SERVER_HDR_LENGTH (sizeof(DEFAULT_SERVER_HDR) - sizeof(CHAR))
  26. //
  27. // Size of a Date: value if we need to generate it ourselves.
  28. //
  29. #define DATE_HDR_LENGTH (sizeof("Thu, 26 Aug 1999 17:14:02 GMT") - sizeof(CHAR))
  30. //
  31. // Size of Connection: header values
  32. //
  33. #define CONN_CLOSE_HDR "close"
  34. #define CONN_CLOSE_HDR_LENGTH (sizeof(CONN_CLOSE_HDR) - sizeof(CHAR))
  35. #define CONN_KEEPALIVE_HDR "keep-alive"
  36. #define CONN_KEEPALIVE_HDR_LENGTH (sizeof(CONN_KEEPALIVE_HDR) - sizeof(CHAR))
  37. //
  38. // These are backwards because of little endian.
  39. //
  40. #define HTTP_PREFIX 'PTTH'
  41. #define HTTP_PREFIX_SIZE 4
  42. #define HTTP_PREFIX_MASK 0xdfdfdfdf
  43. #define HTTP_PREFIX1 '\0//:'
  44. #define HTTP_PREFIX1_SIZE 3
  45. #define HTTP_PREFIX1_MASK 0x00ffffff
  46. #define HTTP_PREFIX2 '//:S'
  47. #define HTTP_PREFIX2_SIZE 4
  48. #define HTTP_PREFIX2_MASK 0xffffffdf
  49. typedef NTSTATUS (*PFN_HEADER_HANDLER)(
  50. PUL_INTERNAL_REQUEST pRequest,
  51. PUCHAR pHttpRequest,
  52. ULONG HttpRequestLength,
  53. HTTP_HEADER_ID HeaderID,
  54. ULONG * pBytesTaken
  55. );
  56. //
  57. // Structure of the fast verb lookup table. The table consists of a series of
  58. // entries where each entry contains an HTTP verb represented as a ulonglong,
  59. // a mask to use for comparing that verb, the length of the verb and the
  60. // translated id.
  61. //
  62. typedef struct _FAST_VERB_ENTRY
  63. {
  64. union
  65. {
  66. UCHAR Char[sizeof(ULONGLONG)+1];
  67. ULONGLONG LongLong;
  68. } RawVerb;
  69. ULONGLONG RawVerbMask;
  70. ULONG RawVerbLength;
  71. HTTP_VERB TranslatedVerb;
  72. } FAST_VERB_ENTRY, *PFAST_VERB_ENTRY;
  73. //
  74. // Stucture of the all verb lookup table. This table holds all verbs that
  75. // we understand, including those that are too long to fit in the fast
  76. // verb table.
  77. //
  78. typedef struct _LONG_VERB_ENTRY
  79. {
  80. ULONG RawVerbLength;
  81. UCHAR RawVerb[MAX_VERB_LENGTH];
  82. HTTP_VERB TranslatedVerb;
  83. } LONG_VERB_ENTRY, *PLONG_VERB_ENTRY;
  84. //
  85. // Structure for a header map entry. Each header map entry contains a
  86. // verb and a series of masks to use in checking that verb.
  87. //
  88. typedef struct _HEADER_MAP_ENTRY
  89. {
  90. ULONG HeaderLength;
  91. ULONG ArrayCount;
  92. ULONG MinBytesNeeded;
  93. union
  94. {
  95. UCHAR HeaderChar[MAX_HEADER_LENGTH];
  96. ULONGLONG HeaderLong[MAX_HEADER_LONG_COUNT];
  97. } Header;
  98. ULONGLONG HeaderMask[MAX_HEADER_LONG_COUNT];
  99. UCHAR MixedCaseHeader[MAX_HEADER_LENGTH];
  100. HTTP_HEADER_ID HeaderID;
  101. PFN_HEADER_HANDLER pHandler;
  102. } HEADER_MAP_ENTRY, *PHEADER_MAP_ENTRY;
  103. //
  104. // Structure for a header index table entry.
  105. //
  106. typedef struct _HEADER_INDEX_ENTRY
  107. {
  108. PHEADER_MAP_ENTRY pHeaderMap;
  109. ULONG Count;
  110. } HEADER_INDEX_ENTRY, *PHEADER_INDEX_ENTRY;
  111. //
  112. // A (complex) macro to create a mask for a header map entry,
  113. // given the header length and the mask offset (in bytes). This
  114. // mask will need to be touched up for non-alphabetic characters.
  115. //
  116. #define CREATE_HEADER_MASK(hlength, maskoffset) \
  117. ((hlength) > (maskoffset) ? UPCASE_MASK : \
  118. (((maskoffset) - (hlength)) >= 8 ? 0 : \
  119. (UPCASE_MASK >> ( ((maskoffset) - (hlength)) * (ULONGLONG)8))))
  120. //
  121. // Macro for creating header map entries. The mask entries are created
  122. // by the init code.
  123. //
  124. #define CREATE_HEADER_MAP_ENTRY(header, ID, handler) { \
  125. \
  126. sizeof(#header) - 1, \
  127. ((sizeof(#header) - 1) / 8) + \
  128. (((sizeof(#header) - 1) % 8) == 0 ? 0 : 1), \
  129. (((sizeof(#header) - 1) / 8) + \
  130. (((sizeof(#header) - 1) % 8) == 0 ? 0 : 1)) * 8, \
  131. { #header }, \
  132. { 0, 0, 0}, \
  133. { #header }, \
  134. ID, \
  135. handler, \
  136. }
  137. //
  138. // Macro for defining fast verb table entries. Note that we don't subtrace 1
  139. // from the various sizeof occurences because we'd just have to add it back
  140. // in to account for the seperating space.
  141. //
  142. #define CREATE_FAST_VERB_ENTRY(verb) { {#verb " "}, \
  143. (0xffffffffffffffff >> \
  144. ((8 - (sizeof(#verb))) * 8)), \
  145. (sizeof(#verb)), HttpVerb##verb }
  146. //
  147. // Macro for defining all verb table entries.
  148. //
  149. #define CREATE_LONG_VERB_ENTRY(verb) { sizeof(#verb) - 1, \
  150. #verb,\
  151. HttpVerb##verb }
  152. #define IS_UTF8_TRAILBYTE(ch) (((ch) & 0xc0) == 0x80)
  153. NTSTATUS
  154. CheckForAbsoluteUrl(
  155. IN PUL_INTERNAL_REQUEST pRequest,
  156. IN PUCHAR pURL,
  157. IN ULONG URLLength,
  158. IN PUCHAR * pHostPtr,
  159. IN ULONG * BytesTaken
  160. );
  161. NTSTATUS
  162. LookupVerb(
  163. IN PUL_INTERNAL_REQUEST pRequest,
  164. IN PUCHAR pHttpRequest,
  165. IN ULONG HttpRequestLength,
  166. OUT ULONG * pBytesTaken
  167. );
  168. NTSTATUS
  169. ParseHeader(
  170. IN PUL_INTERNAL_REQUEST pRequest,
  171. IN PUCHAR pHttpRequest,
  172. IN ULONG HttpRequestLength,
  173. OUT ULONG * pBytesTaken
  174. );
  175. NTSTATUS
  176. LookupHeader(
  177. IN PUL_INTERNAL_REQUEST pRequest,
  178. IN PUCHAR pHttpRequest,
  179. IN ULONG HttpRequestLength,
  180. IN PHEADER_MAP_ENTRY pCurrentHeaderMap,
  181. IN ULONG HeaderMapCount,
  182. OUT ULONG * pBytesTaken
  183. );
  184. typedef enum _URL_PART
  185. {
  186. Scheme,
  187. HostName,
  188. AbsPath,
  189. QueryString
  190. } URL_PART;
  191. NTSTATUS
  192. UlpCleanAndCopyUrl(
  193. IN URL_PART UrlPart,
  194. IN OUT PWSTR pDestination,
  195. IN PUCHAR pSource,
  196. IN ULONG SourceLength,
  197. OUT PULONG pBytesCopied,
  198. OUT PWSTR * ppQueryString OPTIONAL,
  199. OUT PULONG pUrlHash
  200. );
  201. // Call this only after the entire request has been parsed
  202. //
  203. NTSTATUS
  204. UlpCookUrl(
  205. IN PUL_INTERNAL_REQUEST pRequest
  206. );
  207. #endif // _PARSEP_H_