Discussion:
InternetGetProxyInfo
(too old to reply)
Peter Carlson
2004-09-29 06:08:17 UTC
Permalink
Am using InternetGetProxyInfo in jsript.dll. buf always stays at NULL and
len is always 1. Any ideas?

void CMainFrame::InitProxy()
{
if (!gOptions.net.autoproxy) return;

HMODULE hModJS; // Handle for loading the DLL
pfnInternetGetProxyInfo pIGPI; // Function-pointer instance

if( !( hModJS = LoadLibrary( "jsproxy.dll" ) ) ) {
return;
}

if( !( pIGPI = (pfnInternetGetProxyInfo) GetProcAddress( hModJS,
"InternetGetProxyInfo" ) ) ) {
return;
}

CString csUrl; csUrl = "http://www.microsoft.com/windows/default.mspx";
CString csServer; csServer = "www.microsoft.com";
LPSTR buf = NULL;
DWORD len = 0;

BOOL b = pIGPI(csUrl, (unsigned long)csUrl.GetLength(), csServer,
(unsigned long)csServer.GetLength(), &buf, &len);
if( !b) {
return;
}
else {
ATLTRACE( "\n Proxy is: %s\n", buf );
free(buf);
}
}

Peter
Stephen Sulzer
2004-09-29 10:14:16 UTC
Permalink
Peter,

You are missing the call to JSPROXY.DLL's InternetInitializeAutoProxyDll
function, plus a lot of other stuff. JSPROXY computes proxy information
based on a JScript proxy-auto-config script file which you feed to JSPROXY
via InternetInitializeAutoProxyDll. Whether or not your application even
needs to bother with JSPROXY depends on additional runtime discovery
work--examining Internet Explorer's configuration settings, calling
DetectAutoProxyUrl, etc.

Using JSPROXY's auto-proxy interface is fairly complicated. See the MSDN
documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/autoproxy_support_in_wininet.asp

Stephen
Post by Peter Carlson
Am using InternetGetProxyInfo in jsript.dll. buf always stays at NULL and
len is always 1. Any ideas?
void CMainFrame::InitProxy()
{
if (!gOptions.net.autoproxy) return;
HMODULE hModJS; // Handle for loading the DLL
pfnInternetGetProxyInfo pIGPI; // Function-pointer instance
if( !( hModJS = LoadLibrary( "jsproxy.dll" ) ) ) {
return;
}
if( !( pIGPI = (pfnInternetGetProxyInfo) GetProcAddress( hModJS,
"InternetGetProxyInfo" ) ) ) {
return;
}
CString csUrl; csUrl =
"http://www.microsoft.com/windows/default.mspx";
Post by Peter Carlson
CString csServer; csServer = "www.microsoft.com";
LPSTR buf = NULL;
DWORD len = 0;
BOOL b = pIGPI(csUrl, (unsigned long)csUrl.GetLength(), csServer,
(unsigned long)csServer.GetLength(), &buf, &len);
if( !b) {
return;
}
else {
ATLTRACE( "\n Proxy is: %s\n", buf );
free(buf);
}
}
Peter
Peter Carlson
2004-10-02 05:16:51 UTC
Permalink
Thanks Stephen....I've examined MS example and am further along. As a
follow up question, is there a way to detect the proxy used for a particular
connection from within the browser (ie. Javascript). So after a page loads,
JS will print out what proxy was used to make the connection?

Peter
Post by Stephen Sulzer
Peter,
You are missing the call to JSPROXY.DLL's InternetInitializeAutoProxyDll
function, plus a lot of other stuff. JSPROXY computes proxy information
based on a JScript proxy-auto-config script file which you feed to JSPROXY
via InternetInitializeAutoProxyDll. Whether or not your application even
needs to bother with JSPROXY depends on additional runtime discovery
work--examining Internet Explorer's configuration settings, calling
DetectAutoProxyUrl, etc.
Using JSPROXY's auto-proxy interface is fairly complicated. See the MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/autoproxy_support_in_wininet.asp
Post by Stephen Sulzer
Stephen
Post by Peter Carlson
Am using InternetGetProxyInfo in jsript.dll. buf always stays at NULL and
len is always 1. Any ideas?
void CMainFrame::InitProxy()
{
if (!gOptions.net.autoproxy) return;
HMODULE hModJS; // Handle for loading the DLL
pfnInternetGetProxyInfo pIGPI; // Function-pointer instance
if( !( hModJS = LoadLibrary( "jsproxy.dll" ) ) ) {
return;
}
if( !( pIGPI = (pfnInternetGetProxyInfo) GetProcAddress( hModJS,
"InternetGetProxyInfo" ) ) ) {
return;
}
CString csUrl; csUrl =
"http://www.microsoft.com/windows/default.mspx";
Post by Peter Carlson
CString csServer; csServer = "www.microsoft.com";
LPSTR buf = NULL;
DWORD len = 0;
BOOL b = pIGPI(csUrl, (unsigned long)csUrl.GetLength(), csServer,
(unsigned long)csServer.GetLength(), &buf, &len);
if( !b) {
return;
}
else {
ATLTRACE( "\n Proxy is: %s\n", buf );
free(buf);
}
}
Peter
Stephen Sulzer
2004-10-02 06:37:22 UTC
Permalink
If the script code in the web page can get access to the HTTP response
headers, it can try querying for a "Via" header. Proxy server(s) will
identify themselves by setting a Via header.

I am not familiar with the browser's object model, but from searching for
"response headers" in the
microsoft.public.inetsdk.programming.webbrowser_ctl newsgroup, it does not
seem like there is a direct way to access the HTTP response headers. One
suggested workaround is to use the Msxml2.XmlHttp ActiveX object to send a
"HEAD" request to the server. See this posting for an example:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1&selm=3D8EFD99.8090709%40t-online.de

The format of the Via response header is described in section 14.45 of the
HTTP/1.1 specification:
http://www.ietf.org/rfc/rfc2616.txt?number=2616

You can query for a response header using XmlHttp's getResponseHeader()
method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmthgetresponseheaderixmlhttprequest.asp


Stephen
Post by Peter Carlson
Thanks Stephen....I've examined MS example and am further along. As a
follow up question, is there a way to detect the proxy used for a particular
connection from within the browser (ie. Javascript). So after a page loads,
JS will print out what proxy was used to make the connection?
Peter
Peter Carlson
2004-10-04 19:24:10 UTC
Permalink
Ok...here is what we have decided to do...although I need some help in some
of the flow.

Determine if either of the 2 automatic proxy buttons are checked
if so use the auto detection in jscript.dll
otherwise use internetqueryoption and get the static proxy info

if both result in empty proxy strings then assume a direct connection.

The problem I am having is determining if "automatically detect settings" or
"Use automatic configuration script" are checked. When I run the tests
using pfnInternetGetProxyInfo they work and successfully complete the proxy
checks and return the correct proxy info even if the checkboxes are
unchecked.

Also, since I cant verify this by unchecking "automaticall detect settings"
if it is unchecked and there is a automatic configuration script in place,
will InternetGetProxyInfo still work?

Finally, some installations use an .ini file that points to the .pac file.
Will the InternetGetProxyInfo() method work with that scenario?

Peter
Stephen Sulzer
2004-10-04 23:30:02 UTC
Permalink
You can use InternetQueryOption with INTERNET_OPTION_PER_CONNECTION_OPTION
to query Internet Explorer's proxy configuration. This option will let your
application discover what connection options are set (automatically
detect/use auto-config script/use a specific proxy server/etc.)

There is an article showing how to use this WinInet option at:
http://support.microsoft.com/default.aspx?scid=kb;en-us;226473

I do not know of ".ini" files that are used to configure IE proxy
settings--perhaps you mean ".ins"? .Ins files are "browser branding"
installation scripts that can customize IE, including the proxy
configuration. You cannot pass the contents of an .ins file to JSPROXY.DLL.
JSPROXY only understands javascript code. (Javascript proxy auto-config
script files typically have a ".pac", ".js" or ".jvs" file extension.)

.Ins files are processed by a DLL called IEDKCS32.DLL. Although IEDKCS32.DLL
implements the InternetInitializeAutoProxyDll API, it does not implement
InternetGetProxyInfo. The interface to this DLL does not appear to be
documented. I do not think that WinInet directly interacts with IEDKCS32
like it does JSPROXY. Instead, I think that the .ins file is processed once
by an IEAK Installation Wizard program, which then would configure IE's
proxy settings.

I wouldn't worry about .ins files unless querying the IE proxy configuration
(via PER_CONNECTION_OPTION) returns an .ins file. In that case, I think you
will have to parse the file yourself to get the proxy configuration (such as
a pointer to a .pac file which you would then send to JSPROXY).

.Ins files are documented in the Internet Explorer Administrator Kit (IEAK).
(http://www.microsoft.com/windows/ieak/default.mspx)

So the general flow is:

- Query the IE proxy configuration using
INTERNET_OPTION_PER_CONNECTION_OPTION. Note that IE proxy settings are
per-connection. That is, the proxy settings for the default LAN connection
can be different than the proxy config for a modem dialup or VPN connection.
Figuring out which connection is currently active is a whole other
complication. An example case where the proxy configurations could be
different would be a laptop that is used both on a corporate network and
from a home Internet connection.

- if IE is configured to "automatically detect", call DetectAutoProxyUrl to
try to get a URL to a .pac file.
- if DetectAutoProxyUrl returns a URL, then download the .pac file from
that URL

- if DetectAutoProxyUrl fails or "automatically detect" is not set, then
check if "use auto-config script" is specified in the IE proxy config.
- if yes, then download the specified .pac file

- if you have downloaded a .pac file, load JSPROXY, give it the .pac file
and use InternetGetProxyInfo to query for a proxy server

- if there is no proxy auto-config file to use, check if the IE proxy config
specifies a specific proxy server.

- if not, then access sites directly.


Finally, please note that if you only intend to support Windows XP SP1/SP2,
Windows 2000 SP3/SP4, and Windows Server 2003, you should consider using the
"autoproxy" APIs provided by WinHTTP 5.1 instead. The WinHTTP autoproxy APIs
are a lot easier to use than WinInet/JSPROXY.

Good luck.

Stephen
Post by Peter Carlson
Ok...here is what we have decided to do...although I need some help in some
of the flow.
Determine if either of the 2 automatic proxy buttons are checked
if so use the auto detection in jscript.dll
otherwise use internetqueryoption and get the static proxy info
if both result in empty proxy strings then assume a direct connection.
The problem I am having is determining if "automatically detect settings" or
"Use automatic configuration script" are checked. When I run the tests
using pfnInternetGetProxyInfo they work and successfully complete the proxy
checks and return the correct proxy info even if the checkboxes are
unchecked.
Also, since I cant verify this by unchecking "automaticall detect settings"
if it is unchecked and there is a automatic configuration script in place,
will InternetGetProxyInfo still work?
Finally, some installations use an .ini file that points to the .pac file.
Will the InternetGetProxyInfo() method work with that scenario?
Peter
Loading...