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.

170 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. inetapi.cpp
  5. Abstract:
  6. wininet.dll wrapper class implementation.
  7. Author:
  8. Michael Cheuk (mcheuk)
  9. Project:
  10. Link Checker
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "inetapi.h"
  15. // Diable the warning C4706: assignment within conditional expression
  16. // for LOAD_ENTRY macro
  17. #pragma warning( disable : 4706)
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. // Initialize the static members
  24. HMODULE CWininet::sm_hWininet = NULL;
  25. int CWininet::sm_iInstanceCount = 0;
  26. pfnInternetOpenA CWininet::InternetOpenA = NULL;
  27. pfnInternetSetStatusCallback CWininet::InternetSetStatusCallback = NULL;
  28. pfnInternetConnectA CWininet::InternetConnectA = NULL;
  29. pfnHttpOpenRequestA CWininet::HttpOpenRequestA = NULL;
  30. pfnHttpAddRequestHeadersA CWininet::HttpAddRequestHeadersA = NULL;
  31. pfnHttpSendRequestA CWininet::HttpSendRequestA = NULL;
  32. pfnHttpQueryInfoA CWininet::HttpQueryInfoA = NULL;
  33. pfnInternetCloseHandle CWininet::InternetCloseHandle = NULL;
  34. pfnInternetReadFile CWininet::InternetReadFile = NULL;
  35. pfnInternetCrackUrlA CWininet::InternetCrackUrlA = NULL;
  36. pfnInternetCombineUrlA CWininet::InternetCombineUrlA = NULL;
  37. pfnInternetOpenUrlA CWininet::InternetOpenUrlA = NULL;
  38. CWininet::CWininet(
  39. )
  40. /*++
  41. Routine Description:
  42. Constructor. It increases the static instance count.
  43. Arguments:
  44. N/A
  45. Return Value:
  46. N/A
  47. --*/
  48. {
  49. // Increment the instance count
  50. ++sm_iInstanceCount;
  51. } // CWininet::CWininet
  52. CWininet::~CWininet(
  53. )
  54. /*++
  55. Routine Description:
  56. Destructor. It decrease the static instance count and/or
  57. free wininet.dll from memory.
  58. Arguments:
  59. N/A
  60. Return Value:
  61. N/A
  62. --*/
  63. {
  64. // If the instance count is zero, free wininet.dll
  65. // from memory
  66. if(--sm_iInstanceCount == 0 && sm_hWininet)
  67. {
  68. VERIFY(FreeLibrary(sm_hWininet));
  69. sm_hWininet = NULL;
  70. InternetOpenA = NULL;
  71. InternetSetStatusCallback = NULL;
  72. InternetConnectA = NULL;
  73. HttpOpenRequestA = NULL;
  74. HttpAddRequestHeadersA = NULL;
  75. HttpSendRequestA = NULL;
  76. HttpQueryInfoA = NULL;
  77. InternetCloseHandle = NULL;
  78. InternetReadFile = NULL;
  79. InternetCrackUrlA = NULL;
  80. InternetCombineUrlA = NULL;
  81. InternetOpenUrlA = NULL;
  82. }
  83. } // CWininet::~CWininet
  84. BOOL
  85. CWininet::Load(
  86. )
  87. /*++
  88. Routine Description:
  89. Load the wininet.dll onto memory Or increase the wininet.dll
  90. system reference count by one.
  91. Arguments:
  92. N/A
  93. Return Value:
  94. BOOL - TRUE if wininet.dll loaded. FALSE otherwise.
  95. --*/
  96. {
  97. if ( !(sm_hWininet = LoadLibrary( _T("wininet.dll") )) )
  98. {
  99. TRACE(_T("CWininet::Load() - Failed to load wininet.dll\n"));
  100. return FALSE;
  101. }
  102. if ( !LOAD_ENTRY( sm_hWininet, InternetOpenA ) ||
  103. !LOAD_ENTRY( sm_hWininet, InternetSetStatusCallback ) ||
  104. !LOAD_ENTRY( sm_hWininet, InternetConnectA ) ||
  105. !LOAD_ENTRY( sm_hWininet, HttpOpenRequestA ) ||
  106. !LOAD_ENTRY( sm_hWininet, HttpAddRequestHeadersA ) ||
  107. !LOAD_ENTRY( sm_hWininet, HttpSendRequestA ) ||
  108. !LOAD_ENTRY( sm_hWininet, HttpQueryInfoA ) ||
  109. !LOAD_ENTRY( sm_hWininet, InternetCloseHandle ) ||
  110. !LOAD_ENTRY( sm_hWininet, InternetReadFile ) ||
  111. !LOAD_ENTRY( sm_hWininet, InternetCrackUrlA) ||
  112. !LOAD_ENTRY( sm_hWininet, InternetCombineUrlA) ||
  113. !LOAD_ENTRY( sm_hWininet, InternetOpenUrlA) )
  114. {
  115. return FALSE;
  116. }
  117. return TRUE;
  118. } // CWininet::Load