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.

635 lines
13 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2001
  3. Module Name:
  4. WHttpImp.hxx
  5. Abstract:
  6. HTTP2 WinHttp import functionality.
  7. Author:
  8. KamenM 10-30-01 Created
  9. Revision History:
  10. --*/
  11. #if _MSC_VER >= 1200
  12. #pragma once
  13. #endif
  14. #ifndef __WHTTPIMP_HXX__
  15. #define __WHTTPIMP_HXX__
  16. typedef HINTERNET
  17. (WINAPI *WinHttpOpenFn)
  18. (
  19. IN LPCWSTR pwszUserAgent,
  20. IN DWORD dwAccessType,
  21. IN LPCWSTR pwszProxyName OPTIONAL,
  22. IN LPCWSTR pwszProxyBypass OPTIONAL,
  23. IN DWORD dwFlags
  24. );
  25. typedef WINHTTP_STATUS_CALLBACK
  26. (WINAPI *WinHttpSetStatusCallbackFn)
  27. (
  28. IN HINTERNET hInternet,
  29. IN WINHTTP_STATUS_CALLBACK lpfnInternetCallback,
  30. IN DWORD dwNotificationFlags,
  31. IN DWORD_PTR dwReserved
  32. );
  33. typedef BOOL
  34. (WINAPI *WinHttpSetOptionFn)
  35. (
  36. IN HINTERNET hInternet,
  37. IN DWORD dwOption,
  38. IN LPVOID lpBuffer,
  39. IN DWORD dwBufferLength
  40. );
  41. typedef HINTERNET
  42. (WINAPI *WinHttpConnectFn)
  43. (
  44. IN HINTERNET hSession,
  45. IN LPCWSTR pswzServerName,
  46. IN INTERNET_PORT nServerPort,
  47. IN DWORD dwReserved
  48. );
  49. typedef HINTERNET
  50. (WINAPI *WinHttpOpenRequestFn)
  51. (
  52. IN HINTERNET hConnect,
  53. IN LPCWSTR pwszVerb,
  54. IN LPCWSTR pwszObjectName,
  55. IN LPCWSTR pwszVersion,
  56. IN LPCWSTR pwszReferrer OPTIONAL,
  57. IN LPCWSTR FAR * ppwszAcceptTypes OPTIONAL,
  58. IN DWORD dwFlags
  59. );
  60. typedef BOOL
  61. (WINAPI *WinHttpQueryOptionFn)
  62. (
  63. IN HINTERNET hInternet,
  64. IN DWORD dwOption,
  65. OUT LPVOID lpBuffer OPTIONAL,
  66. IN OUT LPDWORD lpdwBufferLength
  67. );
  68. typedef BOOL
  69. (WINAPI *WinHttpSendRequestFn)
  70. (
  71. IN HINTERNET hRequest,
  72. IN LPCWSTR pwszHeaders OPTIONAL,
  73. IN DWORD dwHeadersLength,
  74. IN LPVOID lpOptional OPTIONAL,
  75. IN DWORD dwOptionalLength,
  76. IN DWORD dwTotalLength,
  77. IN DWORD_PTR dwContext
  78. );
  79. typedef BOOL
  80. (WINAPI *WinHttpWriteDataFn)
  81. (
  82. IN HINTERNET hRequest,
  83. IN LPCVOID lpBuffer,
  84. IN DWORD dwNumberOfBytesToWrite,
  85. OUT LPDWORD lpdwNumberOfBytesWritten
  86. );
  87. typedef BOOL
  88. (WINAPI *WinHttpReceiveResponseFn)
  89. (
  90. IN HINTERNET hRequest,
  91. IN LPVOID lpReserved
  92. );
  93. typedef BOOL
  94. (WINAPI *WinHttpReadDataFn)
  95. (
  96. IN HINTERNET hRequest,
  97. IN LPVOID lpBuffer,
  98. IN DWORD dwNumberOfBytesToRead,
  99. OUT LPDWORD lpdwNumberOfBytesRead
  100. );
  101. typedef BOOL
  102. (WINAPI *WinHttpCloseHandleFn)
  103. (
  104. IN HINTERNET hInternet
  105. );
  106. typedef BOOL
  107. (WINAPI *WinHttpQueryHeadersFn)
  108. (
  109. IN HINTERNET hRequest,
  110. IN DWORD dwInfoLevel,
  111. IN LPCWSTR pwszName OPTIONAL,
  112. OUT LPVOID lpBuffer OPTIONAL,
  113. IN OUT LPDWORD lpdwBufferLength,
  114. IN OUT LPDWORD lpdwIndex OPTIONAL
  115. );
  116. typedef BOOL
  117. (WINAPI *WinHttpQueryDataAvailableFn)
  118. (
  119. IN HINTERNET hRequest,
  120. OUT LPDWORD lpdwNumberOfBytesAvailable OPTIONAL
  121. );
  122. typedef BOOL
  123. (WINAPI *WinHttpQueryAuthSchemesFn)
  124. (
  125. IN HINTERNET hRequest,
  126. OUT LPDWORD lpdwSupportedSchemes,
  127. OUT LPDWORD lpdwPreferredScheme,
  128. OUT LPDWORD pdwAuthTarget
  129. );
  130. typedef BOOL
  131. (WINAPI *WinHttpSetCredentialsFn)
  132. (
  133. IN HINTERNET hRequest,
  134. IN DWORD AuthTargets,
  135. IN DWORD AuthScheme,
  136. IN LPCWSTR pwszUserName,
  137. IN LPCWSTR pwszPassword,
  138. IN LPVOID pAuthParams
  139. );
  140. typedef BOOL
  141. (WINAPI *WinHttpAddRequestHeadersFn)
  142. (
  143. IN HINTERNET hRequest,
  144. IN LPCWSTR pwszHeaders,
  145. IN DWORD dwHeadersLength,
  146. IN DWORD dwModifiers
  147. );
  148. typedef struct tagRpcWinHttpImportTableType
  149. {
  150. WinHttpOpenFn WinHttpOpenFnPtr;
  151. WinHttpSetStatusCallbackFn WinHttpSetStatusCallbackFnPtr;
  152. WinHttpSetOptionFn WinHttpSetOptionFnPtr;
  153. WinHttpConnectFn WinHttpConnectFnPtr;
  154. WinHttpOpenRequestFn WinHttpOpenRequestFnPtr;
  155. WinHttpQueryOptionFn WinHttpQueryOptionFnPtr;
  156. WinHttpSendRequestFn WinHttpSendRequestFnPtr;
  157. WinHttpWriteDataFn WinHttpWriteDataFnPtr;
  158. WinHttpReceiveResponseFn WinHttpReceiveResponseFnPtr;
  159. WinHttpReadDataFn WinHttpReadDataFnPtr;
  160. WinHttpCloseHandleFn WinHttpCloseHandleFnPtr;
  161. WinHttpQueryHeadersFn WinHttpQueryHeadersFnPtr;
  162. WinHttpQueryDataAvailableFn WinHttpQueryDataAvailableFnPtr;
  163. WinHttpQueryAuthSchemesFn WinHttpQueryAuthSchemesFnPtr;
  164. WinHttpSetCredentialsFn WinHttpSetCredentialsFnPtr;
  165. WinHttpAddRequestHeadersFn WinHttpAddRequestHeadersFnPtr;
  166. } RpcWinHttpImportTableType;
  167. extern RpcWinHttpImportTableType RpcWinHttpImportTable;
  168. RPC_STATUS InitRpcWinHttpImportTable (
  169. void
  170. );
  171. inline HINTERNET
  172. WINAPI WinHttpOpenImp (
  173. IN LPCWSTR pwszUserAgent,
  174. IN DWORD dwAccessType,
  175. IN LPCWSTR pwszProxyName OPTIONAL,
  176. IN LPCWSTR pwszProxyBypass OPTIONAL,
  177. IN DWORD dwFlags
  178. )
  179. /*++
  180. Routine Description:
  181. Stub to respective WinHttp function.
  182. --*/
  183. {
  184. return RpcWinHttpImportTable.WinHttpOpenFnPtr (
  185. pwszUserAgent,
  186. dwAccessType,
  187. pwszProxyName,
  188. pwszProxyBypass,
  189. dwFlags
  190. );
  191. }
  192. inline WINHTTP_STATUS_CALLBACK
  193. WINAPI WinHttpSetStatusCallbackImp (
  194. IN HINTERNET hInternet,
  195. IN WINHTTP_STATUS_CALLBACK lpfnInternetCallback,
  196. IN DWORD dwNotificationFlags,
  197. IN DWORD_PTR dwReserved
  198. )
  199. /*++
  200. Routine Description:
  201. Stub to respective WinHttp function.
  202. --*/
  203. {
  204. return RpcWinHttpImportTable.WinHttpSetStatusCallbackFnPtr (
  205. hInternet,
  206. lpfnInternetCallback,
  207. dwNotificationFlags,
  208. dwReserved
  209. );
  210. }
  211. inline BOOL
  212. WINAPI WinHttpSetOptionImp (
  213. IN HINTERNET hInternet,
  214. IN DWORD dwOption,
  215. IN LPVOID lpBuffer,
  216. IN DWORD dwBufferLength
  217. )
  218. /*++
  219. Routine Description:
  220. Stub to respective WinHttp function.
  221. --*/
  222. {
  223. return RpcWinHttpImportTable.WinHttpSetOptionFnPtr (
  224. hInternet,
  225. dwOption,
  226. lpBuffer,
  227. dwBufferLength
  228. );
  229. }
  230. inline HINTERNET
  231. WINAPI WinHttpConnectImp (
  232. IN HINTERNET hSession,
  233. IN LPCWSTR pswzServerName,
  234. IN INTERNET_PORT nServerPort,
  235. IN DWORD dwReserved
  236. )
  237. /*++
  238. Routine Description:
  239. Stub to respective WinHttp function.
  240. --*/
  241. {
  242. return RpcWinHttpImportTable.WinHttpConnectFnPtr (
  243. hSession,
  244. pswzServerName,
  245. nServerPort,
  246. dwReserved
  247. );
  248. }
  249. inline HINTERNET
  250. WINAPI WinHttpOpenRequestImp (
  251. IN HINTERNET hConnect,
  252. IN LPCWSTR pwszVerb,
  253. IN LPCWSTR pwszObjectName,
  254. IN LPCWSTR pwszVersion,
  255. IN LPCWSTR pwszReferrer OPTIONAL,
  256. IN LPCWSTR FAR * ppwszAcceptTypes OPTIONAL,
  257. IN DWORD dwFlags
  258. )
  259. /*++
  260. Routine Description:
  261. Stub to respective WinHttp function.
  262. --*/
  263. {
  264. return RpcWinHttpImportTable.WinHttpOpenRequestFnPtr (
  265. hConnect,
  266. pwszVerb,
  267. pwszObjectName,
  268. pwszVersion,
  269. pwszReferrer,
  270. ppwszAcceptTypes,
  271. dwFlags
  272. );
  273. }
  274. inline BOOL
  275. WINAPI WinHttpQueryOptionImp (
  276. IN HINTERNET hInternet,
  277. IN DWORD dwOption,
  278. OUT LPVOID lpBuffer OPTIONAL,
  279. IN OUT LPDWORD lpdwBufferLength
  280. )
  281. /*++
  282. Routine Description:
  283. Stub to respective WinHttp function.
  284. --*/
  285. {
  286. return RpcWinHttpImportTable.WinHttpQueryOptionFnPtr (
  287. hInternet,
  288. dwOption,
  289. lpBuffer,
  290. lpdwBufferLength
  291. );
  292. }
  293. inline BOOL
  294. WINAPI WinHttpSendRequestImp (
  295. IN HINTERNET hRequest,
  296. IN LPCWSTR pwszHeaders OPTIONAL,
  297. IN DWORD dwHeadersLength,
  298. IN LPVOID lpOptional OPTIONAL,
  299. IN DWORD dwOptionalLength,
  300. IN DWORD dwTotalLength,
  301. IN DWORD_PTR dwContext
  302. )
  303. /*++
  304. Routine Description:
  305. Stub to respective WinHttp function.
  306. --*/
  307. {
  308. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpSendRequest, HTTP2LOG_OT_WINHTTP_RAW,
  309. hRequest, dwTotalLength);
  310. return RpcWinHttpImportTable.WinHttpSendRequestFnPtr (
  311. hRequest,
  312. pwszHeaders,
  313. dwHeadersLength,
  314. lpOptional,
  315. dwOptionalLength,
  316. dwTotalLength,
  317. dwContext
  318. );
  319. }
  320. inline BOOL
  321. WINAPI WinHttpWriteDataImp (
  322. IN HINTERNET hRequest,
  323. IN LPCVOID lpBuffer,
  324. IN DWORD dwNumberOfBytesToWrite,
  325. OUT LPDWORD lpdwNumberOfBytesWritten
  326. )
  327. /*++
  328. Routine Description:
  329. Stub to respective WinHttp function.
  330. --*/
  331. {
  332. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpWriteData, HTTP2LOG_OT_WINHTTP_RAW,
  333. hRequest, dwNumberOfBytesToWrite);
  334. return RpcWinHttpImportTable.WinHttpWriteDataFnPtr (
  335. hRequest,
  336. lpBuffer,
  337. dwNumberOfBytesToWrite,
  338. lpdwNumberOfBytesWritten
  339. );
  340. }
  341. inline BOOL
  342. WINAPI WinHttpReceiveResponseImp (
  343. IN HINTERNET hRequest,
  344. IN LPVOID lpReserved
  345. )
  346. /*++
  347. Routine Description:
  348. Stub to respective WinHttp function.
  349. --*/
  350. {
  351. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpReceiveResponse, HTTP2LOG_OT_WINHTTP_RAW,
  352. hRequest, 0);
  353. return RpcWinHttpImportTable.WinHttpReceiveResponseFnPtr (
  354. hRequest,
  355. lpReserved
  356. );
  357. }
  358. inline BOOL
  359. WINAPI WinHttpReadDataImp (
  360. IN HINTERNET hRequest,
  361. IN LPVOID lpBuffer,
  362. IN DWORD dwNumberOfBytesToRead,
  363. OUT LPDWORD lpdwNumberOfBytesRead
  364. )
  365. /*++
  366. Routine Description:
  367. Stub to respective WinHttp function.
  368. --*/
  369. {
  370. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpReadData, HTTP2LOG_OT_WINHTTP_RAW,
  371. hRequest, dwNumberOfBytesToRead);
  372. return RpcWinHttpImportTable.WinHttpReadDataFnPtr (
  373. hRequest,
  374. lpBuffer,
  375. dwNumberOfBytesToRead,
  376. lpdwNumberOfBytesRead
  377. );
  378. }
  379. inline BOOL
  380. WINAPI WinHttpCloseHandleImp (
  381. IN HINTERNET hInternet
  382. )
  383. /*++
  384. Routine Description:
  385. Stub to respective WinHttp function.
  386. --*/
  387. {
  388. return RpcWinHttpImportTable.WinHttpCloseHandleFnPtr (
  389. hInternet
  390. );
  391. }
  392. inline BOOL
  393. WINAPI WinHttpQueryHeadersImp (
  394. IN HINTERNET hRequest,
  395. IN DWORD dwInfoLevel,
  396. IN LPCWSTR pwszName OPTIONAL,
  397. OUT LPVOID lpBuffer OPTIONAL,
  398. IN OUT LPDWORD lpdwBufferLength,
  399. IN OUT LPDWORD lpdwIndex OPTIONAL
  400. )
  401. /*++
  402. Routine Description:
  403. Stub to respective WinHttp function.
  404. --*/
  405. {
  406. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpQueryHeaders, HTTP2LOG_OT_WINHTTP_RAW,
  407. hRequest, dwInfoLevel);
  408. return RpcWinHttpImportTable.WinHttpQueryHeadersFnPtr (
  409. hRequest,
  410. dwInfoLevel,
  411. pwszName,
  412. lpBuffer,
  413. lpdwBufferLength,
  414. lpdwIndex
  415. );
  416. }
  417. inline BOOL
  418. WINAPI WinHttpQueryDataAvailableImp (
  419. IN HINTERNET hRequest,
  420. OUT LPDWORD lpdwNumberOfBytesAvailable OPTIONAL
  421. )
  422. /*++
  423. Routine Description:
  424. Stub to respective WinHttp function.
  425. --*/
  426. {
  427. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpQueryDataAvailable, HTTP2LOG_OT_WINHTTP_RAW,
  428. hRequest, 0);
  429. return RpcWinHttpImportTable.WinHttpQueryDataAvailableFnPtr (
  430. hRequest,
  431. lpdwNumberOfBytesAvailable
  432. );
  433. }
  434. inline BOOL
  435. WINAPI WinHttpQueryAuthSchemesImp (
  436. IN HINTERNET hRequest,
  437. OUT LPDWORD lpdwSupportedSchemes,
  438. OUT LPDWORD lpdwPreferredScheme,
  439. OUT LPDWORD pdwAuthTarget
  440. )
  441. /*++
  442. Routine Description:
  443. Stub to respective WinHttp function.
  444. --*/
  445. {
  446. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpQueryAuthSchemes, HTTP2LOG_OT_WINHTTP_RAW,
  447. hRequest, 0);
  448. return RpcWinHttpImportTable.WinHttpQueryAuthSchemesFnPtr (
  449. hRequest,
  450. lpdwSupportedSchemes,
  451. lpdwPreferredScheme,
  452. pdwAuthTarget
  453. );
  454. }
  455. inline BOOL
  456. WINAPI WinHttpSetCredentialsImp (
  457. IN HINTERNET hRequest,
  458. IN DWORD AuthTargets,
  459. IN DWORD AuthScheme,
  460. IN LPCWSTR pwszUserName,
  461. IN LPCWSTR pwszPassword,
  462. IN LPVOID pAuthParams
  463. )
  464. /*++
  465. Routine Description:
  466. Stub to respective WinHttp function.
  467. --*/
  468. {
  469. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpSetCredentials, HTTP2LOG_OT_WINHTTP_RAW,
  470. hRequest, AuthScheme);
  471. return RpcWinHttpImportTable.WinHttpSetCredentialsFnPtr (
  472. hRequest,
  473. AuthTargets,
  474. AuthScheme,
  475. pwszUserName,
  476. pwszPassword,
  477. pAuthParams
  478. );
  479. }
  480. inline BOOL
  481. WINAPI WinHttpAddRequestHeadersImp (
  482. IN HINTERNET hRequest,
  483. IN LPCWSTR pwszHeaders,
  484. IN DWORD dwHeadersLength,
  485. IN DWORD dwModifiers
  486. )
  487. /*++
  488. Routine Description:
  489. Stub to respective WinHttp function.
  490. --*/
  491. {
  492. LOG_FN_OPERATION_ENTRY2(HTTP2LOG_WHTTPRAW_WinHttpAddRequestHeaders, HTTP2LOG_OT_WINHTTP_RAW,
  493. hRequest, dwHeadersLength);
  494. return RpcWinHttpImportTable.WinHttpAddRequestHeadersFnPtr (
  495. hRequest,
  496. pwszHeaders,
  497. dwHeadersLength,
  498. dwModifiers
  499. );
  500. }
  501. extern HMODULE WinHttpLibrary;
  502. inline RPC_STATUS
  503. InitWinHttpIfNecessary (
  504. void
  505. )
  506. /*++
  507. Routine Description:
  508. Initializes WinHttp. Must
  509. be called before any WinHttp function.
  510. The function must be idempotent.
  511. Arguments:
  512. Return Value:
  513. RPC_S_OK or RPC_S_* for error.
  514. --*/
  515. {
  516. if (WinHttpLibrary)
  517. return RPC_S_OK;
  518. return InitRpcWinHttpImportTable();
  519. }
  520. #endif // __WHTTPIMP_HXX__