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.

305 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. ucparse.h
  5. Abstract:
  6. Contains definitions for ucparse.c .
  7. Author:
  8. Rajesh Sundaram (rajeshsu) 15-Feb-2002.
  9. Revision History:
  10. --*/
  11. #ifndef _UCPARSE_H_
  12. #define _UCPARSE_H_
  13. /***************************************************************************++
  14. Macros related to client URI parsing and canonicalization.
  15. --***************************************************************************/
  16. //
  17. // Char Types: Used to determine the next state, given the current state
  18. // and the current char type
  19. //
  20. #define CHAR_END_OF_STRING 0 // 0
  21. #define CHAR_FORWARD_SLASH (HTTP_CHAR_SLASH >>HTTP_CHAR_SHIFT) // Must be 1
  22. #define CHAR_DOT (HTTP_CHAR_DOT >>HTTP_CHAR_SHIFT) // Must be 2
  23. #define CHAR_QUEST_HASH (HTTP_CHAR_QM_HASH>>HTTP_CHAR_SHIFT) // Must be 3
  24. #define CHAR_PATH_CHAR 4 // valid URI path chars
  25. #define CHAR_INVALID_CHAR 5 // invalid URI chars
  26. #define CHAR_EXTENDED_CHAR CHAR_PATH_CHAR // chars >= 0x80
  27. #define CHAR_TOTAL_TYPES 6
  28. //
  29. // Total states in the canonicalizer state machine
  30. //
  31. #define TOTAL_STATES 8
  32. //
  33. // Actions performed during state transitions
  34. //
  35. #define ACT_ERROR 0 // Error in the URI
  36. #define ACT_EMIT_CHAR 1 // Emit the current char
  37. #define ACT_EMIT_DOT_CHAR 2 // Emit a '.' and the current char
  38. #define ACT_EMIT_DOT_DOT_CHAR 3 // Emit a '..' and the current char
  39. #define ACT_BACKUP 4 // Backup to a previous '/'
  40. #define ACT_NONE 5 // Do nothing
  41. #define ACT_BACKUP_EMIT_CHAR 6 // Backup to '/' and emit the current char
  42. #define ACT_PANIC 7 // Internal error; bug in the code
  43. //
  44. // The following table serves two purposes:
  45. // (1) help determine the next state based on the current state and
  46. // the current char type
  47. // (2) Determine the action that needs to be performed
  48. //
  49. // The first 4 bits denote the action and last 4 bits denote the next state.
  50. // e.g. if the current state = 0,
  51. // the current char = '/' (type = CHAR_FORWARD_SLASH = 1)
  52. // then, the next state = NextStateTable[0][CHAR_FORWARD_SLASH]&0xf => 1
  53. // the action = NextStateTable[0][CHAR_FORWARD_SLASH]>>4 => 1
  54. // Hence, the next state is 1 and action is 1 (i.e. ACT_EMIT_CHAR).
  55. //
  56. // NOTE: Junk columns are added to make the column count a power of 2.
  57. #define INIT_TRANSITION_TABLE \
  58. { \
  59. /*State EOS / . (?/#) (P/E) I Junk Junk */ \
  60. /* 0 */ {0x07, 0x11, 0x07, 0x07, 0x07, 0x07, 0x77, 0x77}, \
  61. /* 1 */ {0x56, 0x51, 0x53, 0x12, 0x14, 0x07, 0x77, 0x77}, \
  62. /* 2 */ {0x56, 0x12, 0x12, 0x12, 0x12, 0x07, 0x77, 0x77}, \
  63. /* 3 */ {0x56, 0x51, 0x55, 0x12, 0x24, 0x07, 0x77, 0x77}, \
  64. /* 4 */ {0x56, 0x11, 0x14, 0x12, 0x14, 0x07, 0x77, 0x77}, \
  65. /* 5 */ {0x46, 0x41, 0x34, 0x62, 0x34, 0x07, 0x77, 0x77}, \
  66. /* 6 */ {0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77}, \
  67. /* 7 */ {0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77}, \
  68. }
  69. #define UC_COPY_HEADER_NAME_SP(pBuffer, i) \
  70. do { \
  71. PHEADER_MAP_ENTRY _pEntry; \
  72. _pEntry = &(g_RequestHeaderMapTable[g_RequestHeaderMap[i]]); \
  73. \
  74. RtlCopyMemory( \
  75. (pBuffer), \
  76. _pEntry->MixedCaseHeader, \
  77. _pEntry->HeaderLength \
  78. ); \
  79. \
  80. (pBuffer) += _pEntry->HeaderLength; \
  81. *(pBuffer)++ = SP; \
  82. \
  83. } while (0, 0)
  84. // 1 for SP char.
  85. #define UC_HEADER_NAME_SP_LENGTH(id) \
  86. (g_RequestHeaderMapTable[g_RequestHeaderMap[id]].HeaderLength + 1)
  87. ULONG
  88. UcComputeRequestHeaderSize(
  89. IN PUC_PROCESS_SERVER_INFORMATION pServInfo,
  90. IN PHTTP_REQUEST pHttpRequest,
  91. IN BOOLEAN bChunked,
  92. IN BOOLEAN bContentLengthHeader,
  93. IN PUC_HTTP_AUTH pAuth,
  94. IN PUC_HTTP_AUTH pProxyAuth,
  95. IN PBOOLEAN bPreAuth,
  96. IN PBOOLEAN bProxyPreAuth
  97. );
  98. NTSTATUS
  99. UcGenerateRequestHeaders(
  100. IN PHTTP_REQUEST pRequest,
  101. IN PUC_HTTP_REQUEST pKeRequest,
  102. IN BOOLEAN bChunked,
  103. IN ULONGLONG ContentLength
  104. );
  105. NTSTATUS
  106. UcGenerateContentLength(
  107. IN ULONGLONG ContentLength,
  108. IN PUCHAR pBuffer,
  109. IN ULONG BufferLen,
  110. OUT PULONG BytesWritten
  111. );
  112. ULONG
  113. UcComputeConnectVerbHeaderSize(
  114. IN PUC_PROCESS_SERVER_INFORMATION pServInfo,
  115. IN PUC_HTTP_AUTH pProxyAuthInfo
  116. );
  117. NTSTATUS
  118. UcGenerateConnectVerbHeader(
  119. IN PUC_HTTP_REQUEST pRequest,
  120. IN PUC_HTTP_REQUEST pHeadRequest,
  121. IN PUC_HTTP_AUTH pProxyAuthInfo
  122. );
  123. NTSTATUS
  124. UnescapeW(
  125. IN PCWSTR pWChar,
  126. OUT PWCHAR pOutWChar
  127. );
  128. __inline
  129. BOOLEAN
  130. UcCheckDisconnectInfo(
  131. IN PHTTP_VERSION pVersion,
  132. IN PHTTP_KNOWN_HEADER pKnownHeaders
  133. );
  134. NTSTATUS
  135. UcCanonicalizeURI(
  136. IN LPCWSTR pInUri,
  137. IN USHORT InUriLen,
  138. IN PUCHAR pOutUri,
  139. IN OUT PUSHORT pOutUriLen,
  140. IN BOOLEAN bEncode
  141. );
  142. //
  143. // Response parser functions
  144. //
  145. NTSTATUS
  146. UcFindHeaderNameEnd(
  147. IN PUCHAR pHttpRequest,
  148. IN ULONG HttpRequestLength,
  149. OUT PULONG HeaderNameLength
  150. );
  151. NTSTATUS
  152. UcFindHeaderValueEnd(
  153. IN PUCHAR pHeader,
  154. IN ULONG HeaderValueLength,
  155. IN PUCHAR *ppFoldingHeader,
  156. IN PULONG pBytesTaken
  157. );
  158. NTSTATUS
  159. UcpLookupHeader(
  160. IN PUC_HTTP_REQUEST pRequest,
  161. IN PUCHAR pHttpRequest,
  162. IN ULONG HttpRequestLength,
  163. IN PHEADER_MAP_ENTRY pHeaderMap,
  164. IN ULONG HeaderMapCount,
  165. OUT ULONG * pBytesTaken
  166. );
  167. NTSTATUS
  168. UcParseHeader(
  169. IN PUC_HTTP_REQUEST pRequest,
  170. IN PUCHAR pHttpRequest,
  171. IN ULONG HttpRequestLength,
  172. OUT ULONG * pBytesTaken
  173. );
  174. NTSTATUS
  175. UcParseWWWAuthenticateHeader(
  176. IN PCSTR pAuthHeader,
  177. IN ULONG AuthHeaderLength,
  178. OUT PHTTP_AUTH_PARSED_PARAMS pAuthSchemeParams
  179. );
  180. LONG
  181. UcpFindAttribValuePair(
  182. PCSTR *ppHeader,
  183. ULONG *pHeaderLength,
  184. PCSTR *Attrib,
  185. ULONG *AttribLen,
  186. PCSTR *Value,
  187. ULONG *ValueLen
  188. );
  189. NTSTATUS
  190. UcpParseAuthParams(
  191. PHTTP_AUTH_SCHEME pAuthScheme,
  192. PHTTP_AUTH_PARSED_PARAMS pAuthParsedParams,
  193. PCSTR *ppHeader,
  194. ULONG *pHeaderLength
  195. );
  196. NTSTATUS
  197. UcpParseAuthBlob(
  198. PHTTP_AUTH_SCHEME pAuthScheme,
  199. PHTTP_AUTH_PARSED_PARAMS pAuthParsedParams,
  200. PCSTR *ppHeader,
  201. ULONG *pHeaderLength
  202. );
  203. NTSTATUS
  204. UcSingleHeaderHandler(
  205. IN PUC_HTTP_REQUEST pRequest,
  206. IN PUCHAR pHeader,
  207. IN ULONG HeaderLength,
  208. IN HTTP_HEADER_ID HeaderID
  209. );
  210. NTSTATUS
  211. UcMultipleHeaderHandler(
  212. IN PUC_HTTP_REQUEST pRequest,
  213. IN PUCHAR pHeader,
  214. IN ULONG HeaderLength,
  215. IN HTTP_HEADER_ID HeaderID
  216. );
  217. NTSTATUS
  218. UcAuthenticateHeaderHandler(
  219. IN PUC_HTTP_REQUEST pRequest,
  220. IN PUCHAR pHeader,
  221. IN ULONG HeaderLength,
  222. IN HTTP_HEADER_ID HeaderID
  223. );
  224. NTSTATUS
  225. UcContentLengthHeaderHandler(
  226. IN PUC_HTTP_REQUEST pRequest,
  227. IN PUCHAR pHeader,
  228. IN ULONG HeaderLength,
  229. IN HTTP_HEADER_ID HeaderID
  230. );
  231. NTSTATUS
  232. UcTransferEncodingHeaderHandler(
  233. IN PUC_HTTP_REQUEST pRequest,
  234. IN PUCHAR pHeader,
  235. IN ULONG HeaderLength,
  236. IN HTTP_HEADER_ID HeaderID
  237. );
  238. NTSTATUS
  239. UcConnectionHeaderHandler(
  240. IN PUC_HTTP_REQUEST pRequest,
  241. IN PUCHAR pHeader,
  242. IN ULONG HeaderLength,
  243. IN HTTP_HEADER_ID HeaderID
  244. );
  245. NTSTATUS
  246. UcContentTypeHeaderHandler(
  247. IN PUC_HTTP_REQUEST pRequest,
  248. IN PUCHAR pHeader,
  249. IN ULONG HeaderLength,
  250. IN HTTP_HEADER_ID HeaderID
  251. );
  252. #endif // _UCPARSE_H_