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.

670 lines
16 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. httpfilt.h
  5. Abstract:
  6. This module contains the Microsoft HTTP filter extension info
  7. Revision History:
  8. --*/
  9. #ifndef _HTTPFILT_H_
  10. #define _HTTPFILT_H_
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. //
  15. // Define ULONG_PTR if necessary
  16. //
  17. #if !defined(__midl) && defined(_X86_) && _MSC_VER >= 1300
  18. #define _W64 __w64
  19. #else
  20. #define _W64
  21. #endif
  22. //
  23. // The INT_PTR is guaranteed to be the same size as a pointer. Its
  24. // size with change with pointer size (32/64). It should be used
  25. // anywhere that a pointer is cast to an integer type. UINT_PTR is
  26. // the unsigned variation.
  27. //
  28. // __int3264 is intrinsic to 64b MIDL but not to old MIDL or to C compiler.
  29. //
  30. #if ( 501 < __midl )
  31. typedef unsigned __int3264 ULONG_PTR, *PULONG_PTR;
  32. #else // midl64
  33. // old midl and C++ compiler
  34. #if defined(_WIN64)
  35. typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
  36. #else
  37. typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
  38. #endif
  39. #endif // midl64
  40. //
  41. // Current version of the filter spec is 4.0
  42. //
  43. #define HTTP_FILTER_REVISION MAKELONG( 0, 4)
  44. #define SF_MAX_USERNAME (256+1)
  45. #define SF_MAX_PASSWORD (256+1)
  46. #define SF_MAX_AUTH_TYPE (32+1)
  47. #define SF_MAX_FILTER_DESC_LEN (256+1)
  48. //
  49. // These values can be used with the pfnSFCallback function supplied in
  50. // the filter context structure
  51. //
  52. enum SF_REQ_TYPE
  53. {
  54. //
  55. // Sends a complete HTTP server response header including
  56. // the status, server version, message time and MIME version.
  57. //
  58. // Server extensions should append other information at the end,
  59. // such as Content-type, Content-length etc followed by an extra
  60. // '\r\n'.
  61. //
  62. // pData - Zero terminated string pointing to optional
  63. // status string (i.e., "401 Access Denied") or NULL for
  64. // the default response of "200 OK".
  65. //
  66. // ul1 - Zero terminated string pointing to optional data to be
  67. // appended and set with the header. If NULL, the header will
  68. // be terminated with an empty line.
  69. //
  70. SF_REQ_SEND_RESPONSE_HEADER,
  71. //
  72. // If the server denies the HTTP request, add the specified headers
  73. // to the server error response.
  74. //
  75. // This allows an authentication filter to advertise its services
  76. // w/o filtering every request. Generally the headers will be
  77. // WWW-Authenticate headers with custom authentication schemes but
  78. // no restriction is placed on what headers may be specified.
  79. //
  80. // pData - Zero terminated string pointing to one or more header lines
  81. // with terminating '\r\n'.
  82. //
  83. SF_REQ_ADD_HEADERS_ON_DENIAL,
  84. //
  85. // Only used by raw data filters that return SF_STATUS_READ_NEXT
  86. //
  87. // ul1 - size in bytes for the next read
  88. //
  89. SF_REQ_SET_NEXT_READ_SIZE,
  90. //
  91. // Used to indicate this request is a proxy request
  92. //
  93. // ul1 - The proxy flags to set
  94. // 0x00000001 - This is a HTTP proxy request
  95. //
  96. //
  97. SF_REQ_SET_PROXY_INFO,
  98. //
  99. // Returns the connection ID contained in the ConnID field of an
  100. // ISAPI Application's Extension Control Block. This value can be used
  101. // as a key to cooridinate shared data between Filters and Applications.
  102. //
  103. // pData - Pointer to DWORD that receives the connection ID.
  104. //
  105. SF_REQ_GET_CONNID,
  106. //
  107. // Used to set a SSPI security context + impersonation token
  108. // derived from a client certificate.
  109. //
  110. // pData - certificate info ( PHTTP_FILTER_CERTIFICATE_INFO )
  111. // ul1 - CtxtHandle*
  112. // ul2 - impersonation handle
  113. //
  114. SF_REQ_SET_CERTIFICATE_INFO,
  115. //
  116. // Used to get an IIS property
  117. // as defined in SF_PROPERTY_IIS
  118. //
  119. // ul1 - Property ID
  120. //
  121. SF_REQ_GET_PROPERTY,
  122. //
  123. // Used to normalize an URL
  124. //
  125. // pData - URL to normalize
  126. //
  127. SF_REQ_NORMALIZE_URL,
  128. //
  129. // Disable Notifications
  130. //
  131. // ul1 - notifications to disable
  132. //
  133. SF_REQ_DISABLE_NOTIFICATIONS,
  134. } ;
  135. enum SF_PROPERTY_IIS
  136. {
  137. SF_PROPERTY_SSL_CTXT,
  138. SF_PROPERTY_INSTANCE_NUM_ID
  139. } ;
  140. //
  141. // These values are returned by the filter entry point when a new request is
  142. // received indicating their interest in this particular request
  143. //
  144. enum SF_STATUS_TYPE
  145. {
  146. //
  147. // The filter has handled the HTTP request. The server should disconnect
  148. // the session.
  149. //
  150. SF_STATUS_REQ_FINISHED = 0x8000000,
  151. //
  152. // Same as SF_STATUS_FINISHED except the server should keep the TCP
  153. // session open if the option was negotiated
  154. //
  155. SF_STATUS_REQ_FINISHED_KEEP_CONN,
  156. //
  157. // The next filter in the notification chain should be called
  158. //
  159. SF_STATUS_REQ_NEXT_NOTIFICATION,
  160. //
  161. // This filter handled the notification. No other handles should be
  162. // called for this particular notification type
  163. //
  164. SF_STATUS_REQ_HANDLED_NOTIFICATION,
  165. //
  166. // An error occurred. The server should use GetLastError() and indicate
  167. // the error to the client
  168. //
  169. SF_STATUS_REQ_ERROR,
  170. //
  171. // The filter is an opaque stream filter and we're negotiating the
  172. // session parameters. Only valid for raw read notification.
  173. //
  174. SF_STATUS_REQ_READ_NEXT
  175. };
  176. //
  177. // pvNotification points to this structure for all request notification types
  178. //
  179. typedef struct _HTTP_FILTER_CONTEXT
  180. {
  181. DWORD cbSize;
  182. //
  183. // This is the structure revision level.
  184. //
  185. DWORD Revision;
  186. //
  187. // Private context information for the server.
  188. //
  189. PVOID ServerContext;
  190. DWORD ulReserved;
  191. //
  192. // TRUE if this request is coming over a secure port
  193. //
  194. BOOL fIsSecurePort;
  195. //
  196. // A context that can be used by the filter
  197. //
  198. PVOID pFilterContext;
  199. //
  200. // Server callbacks
  201. //
  202. BOOL (WINAPI * GetServerVariable) (
  203. struct _HTTP_FILTER_CONTEXT * pfc,
  204. LPSTR lpszVariableName,
  205. LPVOID lpvBuffer,
  206. LPDWORD lpdwSize
  207. );
  208. BOOL (WINAPI * AddResponseHeaders) (
  209. struct _HTTP_FILTER_CONTEXT * pfc,
  210. LPSTR lpszHeaders,
  211. DWORD dwReserved
  212. );
  213. BOOL (WINAPI * WriteClient) (
  214. struct _HTTP_FILTER_CONTEXT * pfc,
  215. LPVOID Buffer,
  216. LPDWORD lpdwBytes,
  217. DWORD dwReserved
  218. );
  219. VOID * (WINAPI * AllocMem) (
  220. struct _HTTP_FILTER_CONTEXT * pfc,
  221. DWORD cbSize,
  222. DWORD dwReserved
  223. );
  224. BOOL (WINAPI * ServerSupportFunction) (
  225. struct _HTTP_FILTER_CONTEXT * pfc,
  226. enum SF_REQ_TYPE sfReq,
  227. PVOID pData,
  228. ULONG_PTR ul1,
  229. ULONG_PTR ul2
  230. );
  231. } HTTP_FILTER_CONTEXT, *PHTTP_FILTER_CONTEXT;
  232. //
  233. // This structure is the notification info for the read and send raw data
  234. // notification types
  235. //
  236. typedef struct _HTTP_FILTER_RAW_DATA
  237. {
  238. //
  239. // This is a pointer to the data for the filter to process.
  240. //
  241. PVOID pvInData;
  242. DWORD cbInData; // Number of valid data bytes
  243. DWORD cbInBuffer; // Total size of buffer
  244. DWORD dwReserved;
  245. } HTTP_FILTER_RAW_DATA, *PHTTP_FILTER_RAW_DATA;
  246. //
  247. // This structure is the notification info for when the server is about to
  248. // process the client headers
  249. //
  250. typedef struct _HTTP_FILTER_PREPROC_HEADERS
  251. {
  252. //
  253. // For SF_NOTIFY_PREPROC_HEADERS, retrieves the specified header value.
  254. // Header names should include the trailing ':'. The special values
  255. // 'method', 'url' and 'version' can be used to retrieve the individual
  256. // portions of the request line
  257. //
  258. BOOL (WINAPI * GetHeader) (
  259. struct _HTTP_FILTER_CONTEXT * pfc,
  260. LPSTR lpszName,
  261. LPVOID lpvBuffer,
  262. LPDWORD lpdwSize
  263. );
  264. //
  265. // Replaces this header value to the specified value. To delete a header,
  266. // specified a value of '\0'.
  267. //
  268. BOOL (WINAPI * SetHeader) (
  269. struct _HTTP_FILTER_CONTEXT * pfc,
  270. LPSTR lpszName,
  271. LPSTR lpszValue
  272. );
  273. //
  274. // Adds the specified header and value
  275. //
  276. BOOL (WINAPI * AddHeader) (
  277. struct _HTTP_FILTER_CONTEXT * pfc,
  278. LPSTR lpszName,
  279. LPSTR lpszValue
  280. );
  281. DWORD HttpStatus; // New in 4.0, status for SEND_RESPONSE
  282. DWORD dwReserved; // New in 4.0
  283. } HTTP_FILTER_PREPROC_HEADERS, *PHTTP_FILTER_PREPROC_HEADERS;
  284. typedef HTTP_FILTER_PREPROC_HEADERS HTTP_FILTER_SEND_RESPONSE;
  285. typedef HTTP_FILTER_PREPROC_HEADERS *PHTTP_FILTER_SEND_RESPONSE;
  286. //
  287. // Authentication information for this request.
  288. //
  289. typedef struct _HTTP_FILTER_AUTHENT
  290. {
  291. //
  292. // Pointer to username and password, empty strings for the anonymous user
  293. //
  294. // Client's can overwrite these buffers which are guaranteed to be at
  295. // least SF_MAX_USERNAME and SF_MAX_PASSWORD bytes large.
  296. //
  297. CHAR * pszUser;
  298. DWORD cbUserBuff;
  299. CHAR * pszPassword;
  300. DWORD cbPasswordBuff;
  301. } HTTP_FILTER_AUTHENT, *PHTTP_FILTER_AUTHENT;
  302. //
  303. // Indicates the server is going to use the specific physical mapping for
  304. // the specified URL. Filters can modify the physical path in place.
  305. //
  306. typedef struct _HTTP_FILTER_URL_MAP
  307. {
  308. const CHAR * pszURL;
  309. CHAR * pszPhysicalPath;
  310. DWORD cbPathBuff;
  311. } HTTP_FILTER_URL_MAP, *PHTTP_FILTER_URL_MAP;
  312. //
  313. // Bitfield indicating the requested resource has been denied by the server due
  314. // to a logon failure, an ACL on a resource, an ISAPI Filter or an
  315. // ISAPI Application/CGI Application.
  316. //
  317. // SF_DENIED_BY_CONFIG can appear with SF_DENIED_LOGON if the server
  318. // configuration did not allow the user to logon.
  319. //
  320. #define SF_DENIED_LOGON 0x00000001
  321. #define SF_DENIED_RESOURCE 0x00000002
  322. #define SF_DENIED_FILTER 0x00000004
  323. #define SF_DENIED_APPLICATION 0x00000008
  324. #define SF_DENIED_BY_CONFIG 0x00010000
  325. typedef struct _HTTP_FILTER_ACCESS_DENIED
  326. {
  327. const CHAR * pszURL; // Requesting URL
  328. const CHAR * pszPhysicalPath; // Physical path of resource
  329. DWORD dwReason; // Bitfield of SF_DENIED flags
  330. } HTTP_FILTER_ACCESS_DENIED, *PHTTP_FILTER_ACCESS_DENIED;
  331. //
  332. // The log information about to be written to the server log file. The
  333. // string pointers can be replaced but the memory must remain valid until
  334. // the next notification
  335. //
  336. typedef struct _HTTP_FILTER_LOG
  337. {
  338. const CHAR * pszClientHostName;
  339. const CHAR * pszClientUserName;
  340. const CHAR * pszServerName;
  341. const CHAR * pszOperation;
  342. const CHAR * pszTarget;
  343. const CHAR * pszParameters;
  344. DWORD dwHttpStatus;
  345. DWORD dwWin32Status;
  346. DWORD dwBytesSent; // IIS 4.0 and later
  347. DWORD dwBytesRecvd; // IIS 4.0 and later
  348. DWORD msTimeForProcessing; // IIS 4.0 and later
  349. } HTTP_FILTER_LOG, *PHTTP_FILTER_LOG;
  350. //
  351. // Called once the client request has been authenticated.
  352. //
  353. typedef struct _HTTP_FILTER_AUTH_COMPLETE_INFO
  354. {
  355. //
  356. // For SF_NOTIFY_AUTH_COMPLETE, retrieves the specified header value.
  357. // Header names should include the trailing ':'. The special values
  358. // 'method', 'url' and 'version' can be used to retrieve the individual
  359. // portions of the request line
  360. //
  361. BOOL (WINAPI * GetHeader) (
  362. struct _HTTP_FILTER_CONTEXT * pfc,
  363. LPSTR lpszName,
  364. LPVOID lpvBuffer,
  365. LPDWORD lpdwSize
  366. );
  367. //
  368. // Replaces this header value to the specified value. To delete a header,
  369. // specified a value of '\0'.
  370. //
  371. BOOL (WINAPI * SetHeader) (
  372. struct _HTTP_FILTER_CONTEXT * pfc,
  373. LPSTR lpszName,
  374. LPSTR lpszValue
  375. );
  376. //
  377. // Adds the specified header and value
  378. //
  379. BOOL (WINAPI * AddHeader) (
  380. struct _HTTP_FILTER_CONTEXT * pfc,
  381. LPSTR lpszName,
  382. LPSTR lpszValue
  383. );
  384. //
  385. // Get the authenticated user impersonation token
  386. //
  387. BOOL (WINAPI * GetUserToken) (
  388. struct _HTTP_FILTER_CONTEXT * pfc,
  389. HANDLE * phToken
  390. );
  391. //
  392. // Status code to use when sending response
  393. //
  394. DWORD HttpStatus;
  395. //
  396. // Determines whether to reset auth if URL changed
  397. //
  398. BOOL fResetAuth;
  399. //
  400. // Reserved
  401. //
  402. DWORD dwReserved;
  403. } HTTP_FILTER_AUTH_COMPLETE_INFO, *PHTTP_FILTER_AUTH_COMPLETE_INFO;
  404. //
  405. // General purpose notification triggered by ISAPI extension
  406. //
  407. typedef struct _HTTP_FILTER_EXTENSION_TRIGGER_INFO
  408. {
  409. //
  410. // Type of triggered notification (client application specific)
  411. //
  412. DWORD dwTriggerType;
  413. //
  414. // Context of triggered notification
  415. //
  416. VOID * pvTriggerContext;
  417. } HTTP_FILTER_EXTENSION_TRIGGER_INFO, *PHTTP_FILTER_EXTENSION_TRIGGER_INFO;
  418. //
  419. // Notification Flags
  420. //
  421. // SF_NOTIFY_SECURE_PORT
  422. // SF_NOTIFY_NONSECURE_PORT
  423. //
  424. // Indicates whether the application wants to be notified for transactions
  425. // that are happenning on the server port(s) that support data encryption
  426. // (such as PCT and SSL), on only the non-secure port(s) or both.
  427. //
  428. // SF_NOTIFY_READ_RAW_DATA
  429. //
  430. // Applications are notified after the server reads a block of memory
  431. // from the client but before the server does any processing on the
  432. // block. The data block may contain HTTP headers and entity data.
  433. //
  434. //
  435. //
  436. #define SF_NOTIFY_SECURE_PORT 0x00000001
  437. #define SF_NOTIFY_NONSECURE_PORT 0x00000002
  438. #define SF_NOTIFY_READ_RAW_DATA 0x00008000
  439. #define SF_NOTIFY_PREPROC_HEADERS 0x00004000
  440. #define SF_NOTIFY_AUTHENTICATION 0x00002000
  441. #define SF_NOTIFY_URL_MAP 0x00001000
  442. #define SF_NOTIFY_ACCESS_DENIED 0x00000800
  443. #define SF_NOTIFY_SEND_RESPONSE 0x00000040
  444. #define SF_NOTIFY_SEND_RAW_DATA 0x00000400
  445. #define SF_NOTIFY_LOG 0x00000200
  446. #define SF_NOTIFY_END_OF_REQUEST 0x00000080
  447. #define SF_NOTIFY_END_OF_NET_SESSION 0x00000100
  448. #define SF_NOTIFY_AUTH_COMPLETE 0x04000000
  449. #define SF_NOTIFY_EXTENSION_TRIGGER 0x02000000
  450. //
  451. // Filter ordering flags
  452. //
  453. // Filters will tend to be notified by their specified
  454. // ordering. For ties, notification order is determined by load order.
  455. //
  456. // SF_NOTIFY_ORDER_HIGH - Authentication or data transformation filters
  457. // SF_NOTIFY_ORDER_MEDIUM
  458. // SF_NOTIFY_ORDER_LOW - Logging filters that want the results of any other
  459. // filters might specify this order.
  460. //
  461. #define SF_NOTIFY_ORDER_HIGH 0x00080000
  462. #define SF_NOTIFY_ORDER_MEDIUM 0x00040000
  463. #define SF_NOTIFY_ORDER_LOW 0x00020000
  464. #define SF_NOTIFY_ORDER_DEFAULT SF_NOTIFY_ORDER_LOW
  465. #define SF_NOTIFY_ORDER_MASK (SF_NOTIFY_ORDER_HIGH | \
  466. SF_NOTIFY_ORDER_MEDIUM | \
  467. SF_NOTIFY_ORDER_LOW)
  468. //
  469. // Filter version information, passed to GetFilterVersion
  470. //
  471. typedef struct _HTTP_FILTER_VERSION
  472. {
  473. //
  474. // Version of the spec the server is using
  475. //
  476. DWORD dwServerFilterVersion;
  477. //
  478. // Fields specified by the client
  479. //
  480. DWORD dwFilterVersion;
  481. CHAR lpszFilterDesc[SF_MAX_FILTER_DESC_LEN];
  482. DWORD dwFlags;
  483. } HTTP_FILTER_VERSION, *PHTTP_FILTER_VERSION;
  484. //
  485. // A filter DLL's entry point looks like this. The return code should be
  486. // an SF_STATUS_TYPE
  487. //
  488. // NotificationType - Type of notification
  489. // pvNotification - Pointer to notification specific data
  490. //
  491. DWORD
  492. WINAPI
  493. HttpFilterProc(
  494. HTTP_FILTER_CONTEXT * pfc,
  495. DWORD NotificationType,
  496. VOID * pvNotification
  497. );
  498. BOOL
  499. WINAPI
  500. GetFilterVersion(
  501. HTTP_FILTER_VERSION * pVer
  502. );
  503. BOOL
  504. WINAPI
  505. TerminateFilter(
  506. DWORD dwFlags
  507. );
  508. #ifdef __cplusplus
  509. }
  510. #endif
  511. #endif //_HTTPFILT_H_
  512.