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.

89 lines
2.1 KiB

  1. // proxy.cpp
  2. //
  3. #include "stdafx.h"
  4. #include "Wininet.h"
  5. const TCHAR szFileVersion[] = TEXT("FileVersion");
  6. BOOL GetIEProxy(LPWSTR pwszProxy, LONG ProxyLen, LPDWORD pdwPort, LPDWORD pdwEnabled)
  7. {
  8. unsigned long nSize = 4096;
  9. INTERNET_PROXY_INFO* pInfo;
  10. LONG i;
  11. LONG j;
  12. pwszProxy[0] = L'\0';
  13. *pdwPort = 0;
  14. *pdwEnabled = FALSE;
  15. pInfo = (INTERNET_PROXY_INFO*)HeapAlloc(GetProcessHeap(),0,nSize);
  16. if( !pInfo )
  17. {
  18. return FALSE;
  19. }
  20. do
  21. {
  22. if(!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, pInfo, &nSize))
  23. {
  24. if( GetLastError() == ERROR_INSUFFICIENT_BUFFER )
  25. {
  26. LPVOID pTmp;
  27. pTmp = HeapReAlloc(GetProcessHeap(),0,pInfo,nSize);
  28. if( !pTmp )
  29. {
  30. HeapFree(GetProcessHeap(),0,pInfo);
  31. return FALSE;
  32. }
  33. pInfo = (INTERNET_PROXY_INFO*)pTmp;
  34. continue;
  35. }
  36. }
  37. }
  38. while(FALSE);
  39. if( pInfo->lpszProxy )
  40. {
  41. PCHAR psz = (PCHAR) pInfo->lpszProxy;
  42. PCHAR EndPtr = NULL;
  43. LONG Len = 0;
  44. //
  45. // Get the port Number from the string
  46. //
  47. for(i=strlen(psz)-1; i>=0 && psz[i] != ':'; i--)
  48. ;
  49. if( psz[i] == ':' )
  50. {
  51. *pdwPort = strtoul((CHAR *)&psz[i+1],&EndPtr,10);
  52. if( *EndPtr != L'\0' )
  53. {
  54. *pdwPort = 0;
  55. }
  56. i--;
  57. }
  58. //
  59. // Get the URL or IP Address. This is right after http://
  60. //
  61. for(i=i; i>=0 && psz[i] != '/'; i--, Len++)
  62. ;
  63. //
  64. // Copy the URL or IP address into our buffer
  65. //
  66. for(i=i+1, j=0; j<Len; i++, j++)
  67. {
  68. pwszProxy[j] = (WCHAR)psz[i];
  69. }
  70. pwszProxy[j] = L'\0';
  71. *pdwEnabled = TRUE;
  72. }
  73. HeapFree(GetProcessHeap(),0,pInfo);
  74. return TRUE;
  75. }