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.

116 lines
2.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2001
  3. Module Name:
  4. WHttpImp.cxx
  5. Abstract:
  6. HTTP2 WinHttp import functionality.
  7. Author:
  8. KamenM 10-30-01 Created
  9. Revision History:
  10. --*/
  11. #include <precomp.hxx>
  12. #include <Http2Log.hxx>
  13. #include <WHttpImp.hxx>
  14. RpcWinHttpImportTableType RpcWinHttpImportTable = {NULL};
  15. HMODULE WinHttpLibrary = NULL;
  16. const char *RpcWinHttpImportTableFunctionNames[] = {
  17. "WinHttpOpen",
  18. "WinHttpSetStatusCallback",
  19. "WinHttpSetOption",
  20. "WinHttpConnect",
  21. "WinHttpOpenRequest",
  22. "WinHttpQueryOption",
  23. "WinHttpSendRequest",
  24. "WinHttpWriteData",
  25. "WinHttpReceiveResponse",
  26. "WinHttpReadData",
  27. "WinHttpCloseHandle",
  28. "WinHttpQueryHeaders",
  29. "WinHttpQueryDataAvailable",
  30. "WinHttpQueryAuthSchemes",
  31. "WinHttpSetCredentials",
  32. "WinHttpAddRequestHeaders"
  33. };
  34. RPC_STATUS InitRpcWinHttpImportTable (
  35. void
  36. )
  37. /*++
  38. Routine Description:
  39. Initializes the Rpc WinHttp import table. Must
  40. be called before any WinHttp function.
  41. The function must be idempotent.
  42. Arguments:
  43. Return Value:
  44. RPC_S_OK or RPC_S_* for error.
  45. --*/
  46. {
  47. RPC_STATUS RpcStatus;
  48. int i;
  49. int FunctionsCount;
  50. FARPROC *CurrentFunction;
  51. HMODULE LocalWinHttpLibrary;
  52. GlobalMutexRequest();
  53. if (WinHttpLibrary == NULL)
  54. {
  55. WinHttpLibrary = LoadLibrary(L"WinHttp.dll");
  56. if (WinHttpLibrary == NULL)
  57. {
  58. RpcStatus = GetLastError();
  59. GlobalMutexClear();
  60. if (RpcStatus == ERROR_FILE_NOT_FOUND)
  61. RpcStatus = RPC_S_CANNOT_SUPPORT;
  62. else
  63. RpcStatus = RPC_S_OUT_OF_MEMORY;
  64. return RpcStatus;
  65. }
  66. }
  67. FunctionsCount = sizeof(RpcWinHttpImportTableFunctionNames)
  68. / sizeof(RpcWinHttpImportTableFunctionNames[0]);
  69. CurrentFunction = (FARPROC *) &RpcWinHttpImportTable;
  70. for (i = 0; i < FunctionsCount; i ++)
  71. {
  72. *CurrentFunction = GetProcAddress(WinHttpLibrary,
  73. RpcWinHttpImportTableFunctionNames[i]
  74. );
  75. if (*CurrentFunction == NULL)
  76. {
  77. LocalWinHttpLibrary = WinHttpLibrary;
  78. WinHttpLibrary = NULL;
  79. GlobalMutexClear();
  80. FreeLibrary(LocalWinHttpLibrary);
  81. return RPC_S_CANNOT_SUPPORT;
  82. }
  83. CurrentFunction ++;
  84. }
  85. GlobalMutexClear();
  86. return RPC_S_OK;
  87. }