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.

185 lines
3.6 KiB

  1. inline DWORD
  2. ProxyUsageFromJobProxyUsage(
  3. BG_JOB_PROXY_USAGE JobUsage
  4. )
  5. {
  6. switch( JobUsage )
  7. {
  8. case BG_JOB_PROXY_USAGE_PRECONFIG: return INTERNET_OPEN_TYPE_PRECONFIG;
  9. case BG_JOB_PROXY_USAGE_NO_PROXY: return INTERNET_OPEN_TYPE_DIRECT;
  10. case BG_JOB_PROXY_USAGE_OVERRIDE: return INTERNET_OPEN_TYPE_PROXY;
  11. default: ASSERT( 0 ); return INTERNET_OPEN_TYPE_DIRECT;
  12. }
  13. }
  14. struct PROXY_SETTINGS
  15. {
  16. BG_JOB_PROXY_USAGE ProxyUsage;
  17. LPTSTR ProxyList;
  18. LPTSTR ProxyBypassList;
  19. PROXY_SETTINGS()
  20. {
  21. ProxyUsage = BG_JOB_PROXY_USAGE_PRECONFIG;
  22. ProxyList = NULL;
  23. ProxyBypassList = NULL;
  24. }
  25. ~PROXY_SETTINGS()
  26. {
  27. delete ProxyList;
  28. delete ProxyBypassList;
  29. }
  30. };
  31. class PROXY_SETTINGS_CONTAINER
  32. {
  33. DWORD m_ProxyUsage;
  34. StringHandle m_BypassList;
  35. StringHandle m_MasterProxyList;
  36. DWORD m_AccessType;
  37. StringHandle m_ProxyList;
  38. LPWSTR m_CurrentProxy;
  39. LPWSTR m_TokenCursor;
  40. public:
  41. PROXY_SETTINGS_CONTAINER(
  42. LPCWSTR Url,
  43. const PROXY_SETTINGS * ProxySettings
  44. );
  45. bool UseNextProxy()
  46. {
  47. m_CurrentProxy = m_ProxyList.GetToken( m_TokenCursor, _T("; "), &m_TokenCursor );
  48. if (m_CurrentProxy == NULL)
  49. {
  50. return false;
  51. }
  52. return true;
  53. }
  54. void ResetCurrentProxy()
  55. {
  56. m_ProxyList = m_MasterProxyList.Copy();
  57. m_CurrentProxy = m_ProxyList.GetToken( NULL, _T(";"), &m_TokenCursor );
  58. }
  59. DWORD GetProxyUsage()
  60. {
  61. return m_ProxyUsage;
  62. }
  63. LPCWSTR GetCurrentProxy()
  64. {
  65. return m_CurrentProxy;
  66. }
  67. LPCWSTR GetProxyList()
  68. {
  69. return m_MasterProxyList;
  70. }
  71. LPCWSTR GetBypassList()
  72. {
  73. if (static_cast<LPCWSTR>(m_BypassList)[0] == 0)
  74. {
  75. return NULL;
  76. }
  77. return m_BypassList;
  78. }
  79. };
  80. class CACHED_AUTOPROXY
  81. {
  82. public:
  83. // a cache entry lasts for 5 minutes.
  84. //
  85. const static CACHED_PROXY_LIFETIME_IN_MSEC = (5 * 60 * 1000);
  86. //----------------------------------------------------------
  87. inline CACHED_AUTOPROXY()
  88. {
  89. m_fValid = false;
  90. m_TimeStamp = 0;
  91. m_hInternet = 0;
  92. ZeroMemory(&m_ProxyInfo, sizeof(m_ProxyInfo));
  93. m_hInternet = InternetOpen( C_BITS_USER_AGENT,
  94. INTERNET_OPEN_TYPE_PRECONFIG,
  95. NULL, // proxy list
  96. NULL, // proxy bypass list
  97. 0 );
  98. if (!m_hInternet)
  99. {
  100. ThrowLastError();
  101. }
  102. }
  103. inline ~CACHED_AUTOPROXY()
  104. {
  105. Clear();
  106. if (m_hInternet)
  107. {
  108. InternetCloseHandle( m_hInternet );
  109. }
  110. }
  111. void Clear();
  112. HRESULT
  113. Generate(
  114. const TCHAR Host[]
  115. );
  116. LPCWSTR GetProxyList()
  117. {
  118. return m_ProxyInfo.lpszProxy;
  119. }
  120. LPCWSTR GetBypassList()
  121. {
  122. return m_ProxyInfo.lpszProxyBypass;
  123. }
  124. DWORD GetAccessType()
  125. {
  126. return m_ProxyInfo.dwAccessType;
  127. }
  128. protected:
  129. //
  130. // m_ProxyInfo contains valid data.
  131. //
  132. bool m_fValid;
  133. //
  134. // The host used to calculate the proxy value.
  135. //
  136. StringHandleT m_HostName;
  137. //
  138. // The results of the proxy calculation.
  139. //
  140. WINHTTP_PROXY_INFO m_ProxyInfo;
  141. //
  142. // Time of last update.
  143. //
  144. long m_TimeStamp;
  145. HINTERNET m_hInternet;
  146. };