46 userName[ msgData.
length ] =
'\0';
79 *bufPtr++ = 4; *bufPtr++ = 1;
80 mputWord( bufPtr, netStream->port );
81 status = getIPAddress( stream, bufPtr, netStream->host );
83 length = 1 + 1 + 2 + 4 + strlen( userName ) + 1;
86 netStream->transportDisconnectFunction( stream,
TRUE );
91 status = netStream->transportWriteFunction( stream, socksBuffer, length,
94 status = netStream->transportReadFunction( stream, socksBuffer, 8,
105 netStream->transportDisconnectFunction( stream,
TRUE );
115 if( socksBuffer[ 1 ] != 90 )
119 netStream->transportDisconnectFunction( stream,
TRUE );
121 "Socks proxy returned" );
122 for( i = 0; i < 8; i++ )
124 sprintf_s( netStream->errorInfo->errorString + 20 + ( i * 3 ),
129 netStream->errorCode = socksBuffer[ 1 ];
164 setStreamLayerHTTP( netStream );
165 status = netStream->writeFunction( stream,
"", 0, &length );
167 status = netStream->readFunction( stream,
buffer, 64, &length );
168 setStreamLayerDirect( netStream );
180 netStream->transportDisconnectFunction( netStream,
TRUE );
195 #if defined( __WIN32__ )
200 #ifndef WINHTTP_ACCESS_TYPE_DEFAULT_PROXY
202 #define HINTERNET HANDLE
206 DWORD dwAutoDetectFlags;
207 LPCWSTR lpszAutoConfigUrl;
210 BOOL fAutoLogonIfChallenged;
211 } WINHTTP_AUTOPROXY_OPTIONS;
216 LPWSTR lpszProxyBypass;
217 } WINHTTP_PROXY_INFO;
221 LPWSTR lpszAutoConfigUrl;
223 LPWSTR lpszProxyBypass;
224 } WINHTTP_CURRENT_USER_IE_PROXY_CONFIG;
226 #define WINHTTP_AUTOPROXY_AUTO_DETECT 1
227 #define WINHTTP_AUTO_DETECT_TYPE_DHCP 1
228 #define WINHTTP_AUTO_DETECT_TYPE_DNS_A 2
229 #define WINHTTP_ACCESS_TYPE_NO_PROXY 1
230 #define WINHTTP_NO_PROXY_NAME NULL
231 #define WINHTTP_NO_PROXY_BYPASS NULL
235 typedef HINTERNET ( *WINHTTPOPEN )( LPCWSTR pwszUserAgent,
DWORD dwAccessType,
236 LPCWSTR pwszProxyName, LPCWSTR pwszProxyBypass,
238 typedef BOOL ( *WINHTTPGETDEFAULTPROXYCONFIGURATION )( WINHTTP_PROXY_INFO* pProxyInfo );
239 typedef BOOL ( *WINHTTPGETIEPROXYCONFIGFORCURRENTUSER )(
240 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *pProxyConfig );
241 typedef BOOL ( *WINHTTPGETPROXYFORURL )( HINTERNET hSession, LPCWSTR lpcwszUrl,
242 WINHTTP_AUTOPROXY_OPTIONS *pAutoProxyOptions,
243 WINHTTP_PROXY_INFO *pProxyInfo );
244 typedef BOOL ( *WINHTTPCLOSEHANDLE )( HINTERNET hInternet );
253 static HMODULE hWinHTTP = NULL;
254 static WINHTTPOPEN pWinHttpOpen = NULL;
255 static WINHTTPGETDEFAULTPROXYCONFIGURATION pWinHttpGetDefaultProxyConfiguration = NULL;
256 static WINHTTPGETIEPROXYCONFIGFORCURRENTUSER pWinHttpGetIEProxyConfigForCurrentUser = NULL;
257 static WINHTTPGETPROXYFORURL pWinHttpGetProxyForUrl = NULL;
258 static WINHTTPCLOSEHANDLE pWinHttpCloseHandle = NULL;
259 WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions = \
260 { WINHTTP_AUTOPROXY_AUTO_DETECT,
261 WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A,
262 NULL, NULL, 0,
FALSE };
263 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyInfo;
264 WINHTTP_PROXY_INFO proxyInfo;
268 size_t unicodeUrlLen, wcsProxyLen;
272 assert(
isWritePtr( proxyLen,
sizeof(
int ) ) );
291 if( hWinHTTP == NULL )
293 if( ( hWinHTTP = DynamicLoad(
"WinHTTP.dll" ) ) == NULL )
296 pWinHttpOpen = ( WINHTTPOPEN ) \
297 GetProcAddress( hWinHTTP,
"WinHttpOpen" );
298 pWinHttpGetDefaultProxyConfiguration = ( WINHTTPGETDEFAULTPROXYCONFIGURATION ) \
299 GetProcAddress( hWinHTTP,
"WinHttpGetDefaultProxyConfiguration" );
300 pWinHttpGetIEProxyConfigForCurrentUser = ( WINHTTPGETIEPROXYCONFIGFORCURRENTUSER ) \
301 GetProcAddress( hWinHTTP,
"WinHttpGetIEProxyConfigForCurrentUser" );
302 pWinHttpGetProxyForUrl = ( WINHTTPGETPROXYFORURL ) \
303 GetProcAddress( hWinHTTP,
"WinHttpGetProxyForUrl" );
304 pWinHttpCloseHandle = ( WINHTTPCLOSEHANDLE ) \
305 GetProcAddress( hWinHTTP,
"WinHttpCloseHandle" );
306 if( pWinHttpOpen == NULL || pWinHttpGetProxyForUrl == NULL || \
307 pWinHttpCloseHandle == NULL )
309 DynamicUnload( hWinHTTP );
323 if( pWinHttpGetDefaultProxyConfiguration != NULL && \
324 pWinHttpGetDefaultProxyConfiguration( &proxyInfo ) && \
325 proxyInfo.lpszProxy != NULL )
327 proxyStatus =
wcstombs_s( &wcsProxyLen, proxy, proxyMaxLen,
329 GlobalFree( proxyInfo.lpszProxy );
330 if( proxyInfo.lpszProxyBypass != NULL )
331 GlobalFree( proxyInfo.lpszProxyBypass );
332 if( proxyStatus == 0 )
334 *proxyLen = wcsProxyLen;
346 if( pWinHttpGetIEProxyConfigForCurrentUser != NULL && \
347 pWinHttpGetIEProxyConfigForCurrentUser( &ieProxyInfo ) )
349 proxyStatus =
wcstombs_s( &wcsProxyLen, proxy, proxyMaxLen,
351 if( ieProxyInfo.lpszAutoConfigUrl != NULL )
352 GlobalFree( ieProxyInfo.lpszAutoConfigUrl );
353 if( ieProxyInfo.lpszProxy != NULL )
354 GlobalFree( ieProxyInfo.lpszProxy );
355 if( ieProxyInfo.lpszProxyBypass != NULL )
356 GlobalFree( ieProxyInfo.lpszProxyBypass );
357 if( proxyStatus == 0 )
359 *proxyLen = wcsProxyLen;
381 memcpy( urlBuffer + offset, url, length );
382 urlBuffer[ offset +
length ] =
'\0';
395 hSession = pWinHttpOpen( L
"cryptlib/1.0",
396 WINHTTP_ACCESS_TYPE_NO_PROXY,
397 WINHTTP_NO_PROXY_NAME,
398 WINHTTP_NO_PROXY_BYPASS, 0 );
399 if( hSession == NULL )
404 pWinHttpCloseHandle( hSession );
407 unicodeURL[ unicodeUrlLen ] = L
'\0';
408 memset( &proxyInfo, 0,
sizeof( WINHTTP_PROXY_INFO ) );
409 if( pWinHttpGetProxyForUrl( hSession, unicodeURL, &autoProxyOptions,
410 &proxyInfo ) !=
TRUE )
412 pWinHttpCloseHandle( hSession );
415 proxyStatus =
wcstombs_s( &wcsProxyLen, proxy, proxyMaxLen,
417 GlobalFree( proxyInfo.lpszProxy );
418 if( proxyInfo.lpszProxyBypass != NULL )
419 GlobalFree( proxyInfo.lpszProxyBypass );
420 pWinHttpCloseHandle( hSession );
421 if( proxyStatus != 0 )
423 *proxyLen = wcsProxyLen;
430 typedef BOOL ( WINAPI *INTERNETGETPROXYINFO )( LPCSTR lpszUrl,
DWORD dwUrlLength,
431 LPSTR lpszUrlHostName,
DWORD dwUrlHostNameLength,
432 LPSTR* lplpszProxyHostName,
433 LPDWORD lpdwProxyHostNameLength );
434 typedef BOOL ( WINAPI *INTERNETINITIALIZEAUTOPROXYDLL )(
DWORD dwVersion,
435 LPSTR lpszDownloadedTempFile, LPSTR lpszMime,
436 AutoProxyHelperFunctions* lpAutoProxyCallbacks,
437 LPAUTO_PROXY_SCRIPT_BUFFER lpAutoProxyScriptBuffer );
439 static int findProxyUrl(
char *proxy,
const int proxyMaxLen,
440 const char *url,
const int urlLen )
442 static INTERNETGETPROXYINFO pInternetGetProxyInfo = NULL;
443 static INTERNETINITIALIZEAUTOPROXYDLL pInternetInitializeAutoProxyDll = NULL;
446 char *proxyHost = NULL;
472 if( pInternetGetProxyInfo == NULL )
476 if( ( hModJS = DynamicLoad(
"JSProxy.dll" ) ) == NULL )
479 pInternetGetProxyInfo = ( INTERNETGETPROXYINFO ) \
480 GetProcAddress( hModJS,
"InternetGetProxyInfo" );
481 pInternetInitializeAutoProxyDll = ( INTERNETINITIALIZEAUTOPROXYDLL ) \
482 GetProcAddress( hModJS,
"InternetInitializeAutoProxyDll" );
483 if( pInternetGetProxyInfo == NULL || \
484 pInternetInitializeAutoProxyDll == NULL )
486 DynamicUnload( hModJS );
490 pInternetInitializeAutoProxyDll( 0, TempFile, NULL,
491 &HelperFunctions, NULL )
505 status = parseURL( &urlInfo, url, strlen( url ), 80,
URL_TYPE_HTTP );
510 memcpy( urlHost, urlInfo.host, urlInfo.
hostLen );
511 urlHost[ urlInfo.
hostLen ] =
'\0';
512 if( !pInternetGetProxyInfo( url, strlen( url ), urlHost, urlInfo.
hostLen,
513 &proxyHost, &proxyHostLen ) )
515 memcpy( proxy, proxyHost, proxyHostLen );
516 proxy[ proxyHostLen ] =
'\0';
517 GlobalFree( proxyHost );