-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGetProxy.h
More file actions
201 lines (154 loc) · 5.62 KB
/
GetProxy.h
File metadata and controls
201 lines (154 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
//
// Sample WinHttp application for determining the proxy for a particular URL.
// This sample demonstrates the core functionality for querying the proxy
// settings. Additional features may be added by the application/module basing
// their proxy code from this sample, including but not limited to:
// 1) Per URL proxy cache.
// 2) Network Change awareness.
// 3) Bad Proxy Filter.
//
#pragma once
#include <winhttp.h>
typedef DWORD (WINAPI *PFNWINHTTPGETPROXYFORURLEX) (HINTERNET, PCWSTR, WINHTTP_AUTOPROXY_OPTIONS *, DWORD_PTR);
typedef DWORD (WINAPI *PFNWINHTTPFREEPROXYLIST) (WINHTTP_PROXY_RESULT *);
typedef DWORD (WINAPI *PFNWINHTTPCREATEPROXYRESOLVER) (HINTERNET, HINTERNET *);
typedef DWORD (WINAPI *PFNWINHTTPGETPROXYRESULT) (HINTERNET, WINHTTP_PROXY_RESULT *);
#define USER_AGENT L"WinhttpProxyStatus"
class ProxyResolver
{
//
// m_fInit - The proxy has been resolved.
//
BOOL m_fInit;
//
// m_fReturnedFirstProxy - The first proxy in the list has been returned
// to the application.
//
BOOL m_fReturnedFirstProxy;
//
// m_fReturnedLastProxy - The end of the proxy list was reached.
//
BOOL m_fReturnedLastProxy;
//
// m_fExtendedAPI - Indicates whether extended APIs are used.
//
BOOL m_fExtendedAPI;
//
// m_dwError - WIN32 Error codes returned from call back function. It's used
// by extended APIs.
//
DWORD m_dwError;
//
// m_hEvent - The handle to the event object. It's used after calling
// WinHttpGetProxyForUrlEx to wait for proxy results.
//
HANDLE m_hEvent;
//
// m_wpiProxyInfo - The initial proxy and bypass list returned by
// calls to WinHttpGetIEProxyConfigForCurrentUser
// and WinHttpGetProxyForUrl.
//
WINHTTP_PROXY_INFO m_wpiProxyInfo;
//
// m_wprProxyResult - The structure introduced for extended APIs.
// It contains well-structured proxy results.
// Used when 1) Auto-Detect if configured.
// 2) Auto-Config URL if configured.
//
WINHTTP_PROXY_RESULT m_wprProxyResult;
//
// m_fProxyFailOverValid - Indicates whether it is valid to iterate through
// the proxy list for proxy failover. Proxy
// failover is valid for a list of proxies
// returned by executing a proxy script. This
// occurs in auto-detect and auto-config URL proxy
// detection modes. When static proxy settings
// are used fallback is not allowed.
//
BOOL m_fProxyFailOverValid;
//
// m_pwszProxyCursor - The current location in the m_wpiProxyInfo proxy list.
// Activated when WinHttpGetProxyForUrl is used.
//
PWSTR m_pwszProxyCursor;
//
// m_dwProxyCursor - The current location in the m_wprProxyResult proxy list.
// Activated when WinHttpGetProxyForUrlEx is used.
//
DWORD m_dwProxyCursor;
BOOL
IsWhitespace(
_In_ WCHAR wcChar);
BOOL
IsRecoverableAutoProxyError(
_In_ DWORD dwError);
BOOL
IsErrorValidForProxyFailover(
_In_ DWORD dwError);
DWORD
SetNextProxySettingEx(
_In_ HINTERNET hInternet,
_In_ DWORD dwRequestError);
VOID
static
CALLBACK
GetProxyCallBack(
_In_ HINTERNET hResolver,
_In_ DWORD_PTR dwContext,
_In_ DWORD dwInternetStatus,
_In_ PVOID pvStatusInformation,
_In_ DWORD dwStatusInformationLength);
DWORD
GetProxyForUrlEx(
_In_ HINTERNET hSession,
_In_z_ PCWSTR pwszUrl,
_In_ WINHTTP_AUTOPROXY_OPTIONS *pAutoProxyOptions);
_Success_(return == ERROR_SUCCESS)
DWORD
GetProxyForAutoSettings(
_In_ HINTERNET hSession,
_In_z_ PCWSTR pwszUrl,
_In_opt_z_ PCWSTR pwszAutoConfigUrl,
_Outptr_result_maybenull_ PWSTR *ppwszProxy,
_Outptr_result_maybenull_ PWSTR *ppwszProxyBypass);
//
// s_pfnWinhttpGetProxyForUrlEx - Function pointer to the new extended api
// WinHttpGetProxyForUrlEx
//
static PFNWINHTTPGETPROXYFORURLEX s_pfnWinhttpGetProxyForUrlEx;
//
// s_pfnWinhttpFreeProxyList - Function pointer to the new extended api
// WinHttpFreeProxyResult
//
static PFNWINHTTPFREEPROXYLIST s_pfnWinhttpFreeProxyList;
//
// s_pfnWinhttpCreateProxyResolver - Function pointer to the new extended api
// WinHttpCreateProxyResolver
//
static PFNWINHTTPCREATEPROXYRESOLVER s_pfnWinhttpCreateProxyResolver;
//
// s_pfnWinhttpGetProxyResult - Function pointer to the new extended api
// WinHttpGetProxyResult
//
static PFNWINHTTPGETPROXYRESULT s_pfnWinhttpGetProxyResult;
public:
ProxyResolver();
~ProxyResolver();
DWORD
ResolveProxy(
_In_ HINTERNET hSession,
_In_z_ PCWSTR pwszUrl);
VOID
ResetProxyCursor();
DWORD
SetNextProxySetting(
_In_ HINTERNET hInternet,
_In_ DWORD dwRequestError);
};