2 * Copyright (C) 2004 Ewan Bhamrah Harley <code@ewan.info>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program (see the file COPYING included with this
16 * distribution); if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 LPCTSTR getIeHttpProxyError
=NULL
;
29 /* getIeHttpProxy fetches the current IE proxy settings for http */
31 LPCTSTR
getIeHttpProxy()
34 INTERNET_PROXY_INFO
*pinfo
;
40 /* first see how big a buffer we need for the IPO structure */
41 InternetQueryOption(NULL
, INTERNET_OPTION_PROXY
, NULL
, &psize
);
44 getIeHttpProxyError
="InternetQueryOption failed to return buffer size";
48 /* allocate memory for IPO */
49 pinfo
= malloc (psize
*sizeof(TCHAR
));
52 getIeHttpProxyError
="malloc failed (1)";
56 /* now run the real query */
57 if(!InternetQueryOption(NULL
, INTERNET_OPTION_PROXY
, (LPVOID
) pinfo
, &psize
))
59 getIeHttpProxyError
="InternetQueryOption() failed to find proxy info";
65 /* see what sort of result we got */
67 if(pinfo
->dwAccessType
== INTERNET_OPEN_TYPE_DIRECT
)
69 /* No proxy configured */
73 else if(pinfo
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
75 /* we have a proxy - now parse result string */
76 /* if result string does NOT contain an '=' sign then */
77 /* there is a single proxy for all protocols */
78 for (p
=(LPTSTR
)pinfo
->lpszProxy
; *p
&& *p
!= '='; p
++);
82 /* allocate a new string to return */
83 len
= 1+strlen(pinfo
->lpszProxy
);
84 proxyString
= malloc (len
*sizeof(TCHAR
));
85 if (proxyString
== NULL
)
87 getIeHttpProxyError
="malloc failed (2)";
91 strncpy(proxyString
, pinfo
->lpszProxy
,len
);
98 /* multiple space seperated proxies defined in the form */
99 /* protocol=proxyhost[:port] */
100 /* we want the one marked "http=", if any. */
101 p
=(LPTSTR
)pinfo
->lpszProxy
;
102 while(*p
&& strncmp(p
, "http=", 5))
104 for(; *p
&& *p
!= ' '; p
++);
109 /* found the proxy */
111 for(q
=p
; *q
&& *q
!= ' '; q
++);
112 /* allocate a buffer for the proxy information */
114 proxyString
=malloc(len
*sizeof(TCHAR
));
115 if(proxyString
==NULL
)
117 getIeHttpProxyError
="malloc failed (3)";
121 strncpy(proxyString
, p
, len
);
128 /* No http proxy in list */
136 /* InternetQueryOption returned a proxy type we don't know about*/
137 getIeHttpProxyError
="Unknown Proxy Type";
144 static void dummy (void) {}