Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 94535 Details for
Bug 180921
[Proxy] Use system values for proxy settings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Win32 ProxyProvider
core.net+tests.patch (text/plain), 70.08 KB, created by
Stefan Liebig
on 2008-04-02 09:59:40 EDT
(
hide
)
Description:
Win32 ProxyProvider
Filename:
MIME Type:
Creator:
Stefan Liebig
Created:
2008-04-02 09:59:40 EDT
Size:
70.08 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.tests.net >Index: src/org/eclipse/core/tests/net/NetTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/NetTest.java,v >retrieving revision 1.3 >diff -u -r1.3 NetTest.java >--- src/org/eclipse/core/tests/net/NetTest.java 11 Apr 2007 13:25:49 -0000 1.3 >+++ src/org/eclipse/core/tests/net/NetTest.java 2 Apr 2008 13:41:43 -0000 >@@ -1,26 +1,33 @@ > /******************************************************************************* >- * Copyright (c) 2007 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >+ * Copyright (c) 2007 IBM Corporation and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: IBM Corporation - initial API and implementation >+ ******************************************************************************/ > package org.eclipse.core.tests.net; > >-import java.util.*; >- >-import junit.framework.*; >+import java.net.URI; >+import java.net.URISyntaxException; >+import java.util.HashMap; >+import java.util.Map; >+import java.util.Properties; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; > >+import org.eclipse.core.internal.net.AbstractProxyProvider; > import org.eclipse.core.internal.net.ProxyType; >+import org.eclipse.core.internal.net.UnixProxyProvider; >+import org.eclipse.core.internal.net.WindowsProxyProvider; > import org.eclipse.core.net.proxy.IProxyData; > import org.eclipse.core.net.proxy.IProxyService; > import org.eclipse.core.runtime.CoreException; > > public class NetTest extends TestCase { >- >+ > private boolean isSetEnabled; > private Map dataCache = new HashMap(); > >@@ -31,7 +38,7 @@ > public NetTest(String name) { > super(name); > } >- >+ > public static Test suite() { > return new TestSuite(NetTest.class); > } >@@ -43,7 +50,7 @@ > dataCache.clear(); > ProxyType.socksSystemPropertySetting = ProxyType.ALWAYS_SET; > } >- >+ > protected void tearDown() throws Exception { > super.tearDown(); > setProxiesEnabled(false); >@@ -54,22 +61,24 @@ > } > getProxyManager().setProxyData(data); > } >- >+ > private IProxyService getProxyManager() { > return Activator.getDefault().getProxyService(); > } > > private void assertProxyDataEqual(IProxyData expectedData) { >- IProxyData data = getProxyManager().getProxyData(expectedData.getType()); >+ IProxyData data = getProxyManager() >+ .getProxyData(expectedData.getType()); > assertEquals(expectedData.getType(), data.getType()); > assertEquals(expectedData.getHost(), data.getHost()); > assertEquals(expectedData.getPort(), data.getPort()); > assertEquals(expectedData.getUserId(), data.getUserId()); > assertEquals(expectedData.getPassword(), data.getPassword()); >- assertEquals(expectedData.isRequiresAuthentication(), data.isRequiresAuthentication()); >+ assertEquals(expectedData.isRequiresAuthentication(), data >+ .isRequiresAuthentication()); > assertSystemPropertiesMatch(data); > } >- >+ > public void assertSystemPropertiesMatch(IProxyData proxyData) { > if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { > assertHttpSystemProperties(proxyData, "http"); >@@ -80,25 +89,32 @@ > } > } > >- private void assertHttpSystemProperties(IProxyData proxyData, String keyPrefix) { >+ private void assertHttpSystemProperties(IProxyData proxyData, >+ String keyPrefix) { > Properties sysProps = System.getProperties(); >- >+ > if (this.getProxyManager().isProxiesEnabled()) { > boolean isSet = Boolean.getBoolean(keyPrefix + ".proxySet"); > assertEquals(proxyData.getHost() != null, isSet); //$NON-NLS-1$ >- assertEquals(proxyData.getHost(), sysProps.get(keyPrefix + ".proxyHost")); //$NON-NLS-1$ >- String portString = (String)sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$ >+ assertEquals(proxyData.getHost(), sysProps.get(keyPrefix >+ + ".proxyHost")); //$NON-NLS-1$ >+ String portString = (String) sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$ > int port = -1; > if (portString != null) > port = Integer.parseInt(portString); > assertEquals(proxyData.getPort(), port); > if (isSet) >- assertEquals(ProxyType.convertHostsToPropertyString(this.getProxyManager().getNonProxiedHosts()), sysProps.get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$ >- else >+ assertEquals(ProxyType.convertHostsToPropertyString(this >+ .getProxyManager().getNonProxiedHosts()), sysProps >+ .get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$ >+ else > assertNull(sysProps.get(keyPrefix + ".nonProxyHosts")); >- assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix + ".proxyUser")); //$NON-NLS-1$ >- assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix + ".proxyUserName")); //$NON-NLS-1$ >- assertEquals(proxyData.getPassword(), sysProps.get(keyPrefix + ".proxyPassword")); //$NON-NLS-1$ >+ assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix >+ + ".proxyUser")); //$NON-NLS-1$ >+ assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix >+ + ".proxyUserName")); //$NON-NLS-1$ >+ assertEquals(proxyData.getPassword(), sysProps.get(keyPrefix >+ + ".proxyPassword")); //$NON-NLS-1$ > } else { > assertNull(sysProps.get(keyPrefix + ".proxySet")); > assertNull(sysProps.get(keyPrefix + ".proxyHost")); >@@ -114,7 +130,7 @@ > Properties sysProps = System.getProperties(); > if (this.getProxyManager().isProxiesEnabled()) { > assertEquals(proxyData.getHost(), sysProps.get("socksProxyHost")); //$NON-NLS-1$ >- String portString = (String)sysProps.get("socksProxyPort"); //$NON-NLS-1$ >+ String portString = (String) sysProps.get("socksProxyPort"); //$NON-NLS-1$ > int port = -1; > if (portString != null) > port = Integer.parseInt(portString); >@@ -124,16 +140,16 @@ > assertNull(sysProps.get("socksProxyPort")); > } > } >- >+ > private IProxyData getProxyData(String type) { >- IProxyData data = (IProxyData)dataCache.get(type); >+ IProxyData data = (IProxyData) dataCache.get(type); > if (data == null) { > data = this.getProxyManager().getProxyData(type); > assertProxyDataEqual(data); > } > return data; > } >- >+ > private void setProxyData(IProxyData data) throws CoreException { > if (isSetEnabled) { > this.getProxyManager().setProxyData(new IProxyData[] { data }); >@@ -142,12 +158,12 @@ > dataCache.put(data.getType(), data); > } > } >- >+ > private void disableProxy(IProxyData proxyData) throws CoreException { > proxyData.disable(); > setProxyData(proxyData); > } >- >+ > private void changeProxyData(IProxyData oldData, IProxyData data) > throws CoreException { > // Make sure that setting the host doesn't change the persisted settings >@@ -156,7 +172,7 @@ > // Now set it in the manager and assert that it is set > setProxyData(data); > } >- >+ > private void setHost(String type) throws CoreException { > String host = "www.eclipse.org"; > setHost(type, host); >@@ -168,39 +184,41 @@ > data.setHost(host); > changeProxyData(oldData, data); > } >- >+ > private void setPort(String type, int port) throws CoreException { > IProxyData data = getProxyData(type); > IProxyData oldData = getProxyData(type); > data.setPort(port); > changeProxyData(oldData, data); > } >- >- private void setUser(String type, String user, String password) throws CoreException { >+ >+ private void setUser(String type, String user, String password) >+ throws CoreException { > IProxyData data = getProxyData(type); > IProxyData oldData = getProxyData(type); > data.setUserid(user); > data.setPassword(password); > changeProxyData(oldData, data); > } >- >+ > private void setDataTest(String type) throws CoreException { > setHost(type, "www.eclipse.org"); > setPort(type, 1024); > setUser(type, "me", "passw0rd"); > } >- >+ > private void setProxiesEnabled(boolean enabled) { > this.getProxyManager().setProxiesEnabled(enabled); > assertEquals(enabled, this.getProxyManager().isProxiesEnabled()); > } >- >+ > private void delaySettingData() { > isSetEnabled = false; > } >- >+ > private void performSettingData() throws CoreException { >- IProxyData[] data = (IProxyData[]) dataCache.values().toArray(new IProxyData[dataCache.size()]); >+ IProxyData[] data = (IProxyData[]) dataCache.values().toArray( >+ new IProxyData[dataCache.size()]); > this.getProxyManager().setProxyData(data); > for (int i = 0; i < data.length; i++) { > IProxyData proxyData = data[i]; >@@ -209,7 +227,7 @@ > isSetEnabled = true; > dataCache.clear(); > } >- >+ > public void testIndividualSetAndClear() throws CoreException { > setDataTest(IProxyData.HTTP_PROXY_TYPE); > setDataTest(IProxyData.HTTPS_PROXY_TYPE); >@@ -220,14 +238,14 @@ > disableProxy(proxyData); > } > } >- >+ > public void testAllSetAndClear() throws CoreException { > delaySettingData(); > setDataTest(IProxyData.HTTP_PROXY_TYPE); > setDataTest(IProxyData.HTTPS_PROXY_TYPE); > setDataTest(IProxyData.SOCKS_PROXY_TYPE); > performSettingData(); >- >+ > delaySettingData(); > IProxyData[] data = this.getProxyManager().getProxyData(); > for (int i = 0; i < data.length; i++) { >@@ -250,52 +268,181 @@ > setProxiesEnabled(false); > assertProxyDataEqual(data); > } >- >+ > public void testSimpleHost() throws CoreException { > setDataTest(IProxyData.HTTP_PROXY_TYPE); > setDataTest(IProxyData.HTTPS_PROXY_TYPE); > setDataTest(IProxyData.SOCKS_PROXY_TYPE); >- >- IProxyData[] allData = this.getProxyManager().getProxyDataForHost("www.randomhot.com"); >+ >+ IProxyData[] allData = this.getProxyManager().getProxyDataForHost( >+ "www.randomhot.com"); > assertEquals(3, allData.length); >- >- IProxyData data = this.getProxyManager().getProxyDataForHost("www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); >+ >+ IProxyData data = this.getProxyManager().getProxyDataForHost( >+ "www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); > assertNotNull(data); >- >+ > allData = this.getProxyManager().getProxyDataForHost("localhost"); > assertEquals(0, allData.length); >- >- data = this.getProxyManager().getProxyDataForHost("localhost", IProxyData.HTTP_PROXY_TYPE); >+ >+ data = this.getProxyManager().getProxyDataForHost("localhost", >+ IProxyData.HTTP_PROXY_TYPE); > assertNull(data); > } >- >+ > public void testHostPattern() throws CoreException { > setDataTest(IProxyData.HTTP_PROXY_TYPE); > setDataTest(IProxyData.HTTPS_PROXY_TYPE); > setDataTest(IProxyData.SOCKS_PROXY_TYPE); >- >+ > String[] oldHosts = this.getProxyManager().getNonProxiedHosts(); >- this.getProxyManager().setNonProxiedHosts(new String[] { "*ignore.com" }); >- >- IProxyData[] allData = this.getProxyManager().getProxyDataForHost("www.randomhot.com"); >+ this.getProxyManager().setNonProxiedHosts( >+ new String[] { "*ignore.com" }); >+ >+ IProxyData[] allData = this.getProxyManager().getProxyDataForHost( >+ "www.randomhot.com"); > assertEquals(3, allData.length); >- >- IProxyData data = this.getProxyManager().getProxyDataForHost("www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); >+ >+ IProxyData data = this.getProxyManager().getProxyDataForHost( >+ "www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); > assertNotNull(data); >- >+ > allData = this.getProxyManager().getProxyDataForHost("www.ignore.com"); > assertEquals(0, allData.length); >- >- data = this.getProxyManager().getProxyDataForHost("www.ignore.com", IProxyData.HTTP_PROXY_TYPE); >+ >+ data = this.getProxyManager().getProxyDataForHost("www.ignore.com", >+ IProxyData.HTTP_PROXY_TYPE); > assertNull(data); >- >+ > allData = this.getProxyManager().getProxyDataForHost("ignore.com"); > assertEquals(0, allData.length); >- >- data = this.getProxyManager().getProxyDataForHost("ignore.com", IProxyData.HTTP_PROXY_TYPE); >+ >+ data = this.getProxyManager().getProxyDataForHost("ignore.com", >+ IProxyData.HTTP_PROXY_TYPE); > assertNull(data); >- >+ > this.getProxyManager().setNonProxiedHosts(oldHosts); > } > >+ // This test case has to be manually setup and run because it depends on >+ // whether the proxy is set in the native environment. It is here as >+ // a convenience to test the native support. >+ public void testNativeLinux() throws Exception { >+ >+ // Leave this test off for the automatic test runs so we don't >+ // get confused by the settings that happen to be on the test machine >+ if (true) >+ return; >+ >+ AbstractProxyProvider pp = new UnixProxyProvider(); >+ >+ IProxyData[] pd; >+ >+ // Test the following cases >+ // 1) No proxy set anywhere >+ // 2) http_proxy environment variable (use proxyIsSet) >+ // 3) gconf-edit proxy (use proxyIsSet and proxyAuthIsSet) >+ // 4) KDE proxy (use proxyIsSet and proxyAuthIsSet) >+ >+ // Toggle this if you have the proxy set up in the native environment >+ boolean proxyIsSet = true; >+ >+ // Toggle this if you have the proxy authentication information setup >+ boolean proxyAuthIsSet = true; >+ >+ String proxyHost = null; >+ String proxyUser = null; >+ String proxyPassword = null; >+ boolean proxyReqAuth = false; >+ int proxyPort = 0; >+ >+ if (proxyIsSet) { >+ proxyHost = "berlioz"; >+ proxyPort = 3128; >+ if (proxyAuthIsSet) { >+ proxyUser = "user"; >+ proxyPassword = "password"; >+ proxyReqAuth = true; >+ } >+ } >+ >+ // Test HTTP >+ pd = pp.select(new URI("http://bbc.com")); >+ if (proxyIsSet) { >+ assertEquals(1, pd.length); >+ assertEquals(proxyHost, pd[0].getHost()); >+ assertEquals(proxyPort, pd[0].getPort()); >+ if (proxyAuthIsSet) { >+ assertEquals(proxyUser, pd[0].getUserId()); >+ assertEquals(proxyPassword, pd[0].getPassword()); >+ assertEquals(proxyReqAuth, pd[0].isRequiresAuthentication()); >+ } >+ >+ } else { >+ assertEquals(0, pd.length); >+ } >+ >+ // Test HTTPS >+ pd = pp.select(new URI("https://bbc.com")); >+ if (proxyIsSet) { >+ assertEquals(1, pd.length); >+ assertEquals("https_" + proxyHost, pd[0].getHost()); >+ assertEquals(1 + proxyPort, pd[0].getPort()); >+ } else { >+ assertEquals(0, pd.length); >+ } >+ >+ // Test SOCKS >+ pd = pp.select(new URI("SOCKS://bbc.com")); >+ if (proxyIsSet) { >+ assertEquals(1, pd.length); >+ assertEquals("socks_" + proxyHost, pd[0].getHost()); >+ assertEquals(2 + proxyPort, pd[0].getPort()); >+ } else { >+ assertEquals(0, pd.length); >+ } >+ >+ // Test FTP >+ pd = pp.select(new URI("FTP://bbc.com")); >+ if (proxyIsSet) { >+ assertEquals(1, pd.length); >+ assertEquals("ftp_" + proxyHost, pd[0].getHost()); >+ assertEquals(3 + proxyPort, pd[0].getPort()); >+ } else { >+ assertEquals(0, pd.length); >+ } >+ >+ // Assume that localhost is a non-proxy host >+ pd = pp.select(new URI("http://localhost")); >+ assertEquals(0, pd.length); >+ } >+ >+ // This test case has to be manually setup and run because it depends on >+ // whether the proxy is set in the native environment. It is here as >+ // a convenience to test the native support. >+ public void testNativeWin32() throws Exception { >+ >+ // Leave this test off for the automatic test runs so we don't >+ // get confused by the settings that happen to be on the test machine >+ if (false) >+ return; >+ >+ AbstractProxyProvider pp = new WindowsProxyProvider(); >+ >+ // loop here - while looping play with the internet options ;-) >+ while (true) { >+ proxiesFor(pp,"http://www.eclipse.org"); >+ proxiesFor(pp,"https://www.eclipse.org"); >+ proxiesFor(pp,"ftp://www.eclipse.org"); >+ proxiesFor(pp,"socks://www.eclipse.org"); >+ } >+ } >+ >+ public void proxiesFor( AbstractProxyProvider pp,String url ) throws URISyntaxException{ >+ IProxyData[] pd = pp.select(new URI(url)); >+ System.out.println("Url: "+ url + ":"); >+ for (int i = 0; i < pd.length; i++) { >+ System.out.println("\t"+pd[i]); >+ } >+ } > } >#P org.eclipse.core.net >Index: src/org/eclipse/core/internal/net/ProxyData.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyData.java,v >retrieving revision 1.2 >diff -u -r1.2 ProxyData.java >--- src/org/eclipse/core/internal/net/ProxyData.java 9 Apr 2007 19:21:02 -0000 1.2 >+++ src/org/eclipse/core/internal/net/ProxyData.java 2 Apr 2008 13:41:44 -0000 >@@ -74,6 +74,10 @@ > public boolean isRequiresAuthentication() { > return requiresAuthentication; > } >+ >+ public void setRequiresAuthentication(boolean requires) { >+ requiresAuthentication = requires; >+ } > > public void disable() { > host = null; >@@ -83,4 +87,19 @@ > requiresAuthentication = false; > } > >+ public String toString() { >+ StringBuffer stringBuffer = new StringBuffer(); >+ stringBuffer.append("host: "); //$NON-NLS-1$ >+ stringBuffer.append(host); >+ stringBuffer.append(" port: "); //$NON-NLS-1$ >+ stringBuffer.append(port); >+ stringBuffer.append(" user: "); //$NON-NLS-1$ >+ stringBuffer.append(user); >+ stringBuffer.append(" password: "); //$NON-NLS-1$ >+ stringBuffer.append(password); >+ stringBuffer.append(" reqAuth: "); //$NON-NLS-1$ >+ stringBuffer.append(requiresAuthentication); >+ return stringBuffer.toString(); >+ } >+ > } >Index: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,73 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.winhttp; >+ >+import org.eclipse.core.internal.net.proxy.win32.util.StringUtils; >+ >+/** >+ * Wrapper for Win32 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure >+ */ >+public class WinHttpCurrentUserIEProxyConfig { >+ >+ private boolean isAutoDetect; >+ private String autoConfigUrl; >+ private String proxy; >+ private String proxyBypass; >+ >+ /** >+ * @return the autoConfigUrl >+ */ >+ public String getAutoConfigUrl() { >+ return autoConfigUrl; >+ } >+ >+ /** >+ * @return the isAutoDetect >+ */ >+ public boolean isAutoDetect() { >+ return isAutoDetect; >+ } >+ >+ /** >+ * @return the proxy >+ */ >+ public String getProxy() { >+ return proxy; >+ } >+ >+ /** >+ * @return the proxyBypass >+ */ >+ public String getProxyBypass() { >+ return proxyBypass; >+ } >+ >+ /** >+ * @see java.lang.Object#equals(java.lang.Object) >+ */ >+ public boolean equals( Object obj ) { >+ if ( obj instanceof WinHttpCurrentUserIEProxyConfig ) { >+ WinHttpCurrentUserIEProxyConfig that = (WinHttpCurrentUserIEProxyConfig) obj; >+ return ( this.isAutoDetect == that.isAutoDetect ) && StringUtils.equals( this.autoConfigUrl, that.autoConfigUrl ) >+ && StringUtils.equals( this.proxy, that.proxy ) && StringUtils.equals( this.proxyBypass, that.proxyBypass ); >+ } >+ >+ return false; >+ } >+ >+ /** >+ * @see java.lang.Object#hashCode() >+ */ >+ public int hashCode() { >+ return ( autoConfigUrl + proxy ).hashCode(); >+ } >+ >+} >Index: src/org/eclipse/core/internal/net/proxy/win32/util/StringUtils.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/util/StringUtils.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/util/StringUtils.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/util/StringUtils.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,105 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.util; >+ >+/** >+ * Collection of String/CharSequence utilities. >+ */ >+public final class StringUtils { >+ >+ private StringUtils() { >+ // Utility class >+ } >+ >+ /** >+ * Tests ´simple´ emptiness. A character sequence is empty either if it is >+ * null or it has a zero length. >+ * >+ * @param sequence >+ * @return true if null or zero length >+ */ >+ public static final boolean isEmpty(final CharSequence sequence) { >+ return sequence == null || sequence.length() == 0; >+ } >+ >+ /** >+ * Tests whether the char sequence has content. A character sequence is >+ * given either if it is not null and it has a none zero length. >+ * >+ * @param sequence >+ * @return true if not null and not zero length >+ */ >+ public static final boolean isGiven(final CharSequence sequence) { >+ return sequence != null && sequence.length() != 0; >+ } >+ >+ /** >+ * Tests ´deep´ emptiness. A string is empty if it is either null or its >+ * trimmed version has a zero length. >+ * >+ * @param string >+ * @return true if null or the trimmed string length is zero >+ */ >+ public static final boolean isDeepEmpty(final String string) { >+ return string == null || string.trim().length() == 0; >+ } >+ >+ /** >+ * Tests equality of the given strings. >+ * >+ * @param sequence1 >+ * candidate 1, may be null >+ * @param sequence2 >+ * candidate 2, may be null >+ * @return true if both sequences are null or the sequences are equal >+ */ >+ public static final boolean equals(final CharSequence sequence1, >+ final CharSequence sequence2) { >+ if (sequence1 == sequence2) { >+ return true; >+ } else if (sequence1 == null || sequence2 == null) { >+ return false; >+ } else { >+ return sequence1.equals(sequence2); >+ } >+ } >+ >+ /** >+ * Replace within <code>source</code> the occurrences of <code>from</code> with <code>to</code>. >+ * @param source >+ * @param from >+ * @param to >+ * @return the substituted string >+ */ >+ public static String replace(String source, String from, String to) { >+ if (from.length() == 0 ) >+ return source; >+ StringBuffer buffer = new StringBuffer(); >+ int current = 0; >+ int pos = 0; >+ while (pos != -1) { >+ pos = source.indexOf(from, current); >+ if (pos == -1) { >+ buffer.append(source.substring(current)); >+ } else { >+ buffer.append(source.substring(current, pos)); >+ buffer.append(to); >+ current = pos + from.length(); >+ } >+ } >+ return buffer.toString(); >+ } >+ >+ // TODO convert to unit test >+ public static void main(String[] args) { >+ System.out.println(replace("xaaaaa", "aa", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ } >+} >Index: natives/unix/README.txt >=================================================================== >RCS file: natives/unix/README.txt >diff -N natives/unix/README.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ natives/unix/README.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+The source for getting the native proxy info is in the top level unix directory. If >+there are more specific compile options, makefiles, etc, then they should be moved >+to subdirectories, like in org.eclipse.core.filesystem. >+ >+The Debug directory actually has the make file; this is the makefile as generated by the CDT. >+ >+To build this, go into Debug and type "make", the library will be built in that same >+directory. Then you will need to copy the library to the correct org.eclipse.core.net.* >+fragment. >+ >+There is no automatic build process for building the native code, instead the binary >+shared libraries are checked in for each fragment, just like in org.eclipse.code.filesystem. >Index: src/org/eclipse/core/internal/net/WindowsProxyProvider.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/WindowsProxyProvider.java >diff -N src/org/eclipse/core/internal/net/WindowsProxyProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/WindowsProxyProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+package org.eclipse.core.internal.net; >+ >+import java.net.URI; >+import java.util.List; >+ >+import org.eclipse.core.internal.net.proxy.win32.winhttp.WinHttpProxySelector; >+import org.eclipse.core.net.proxy.IProxyData; >+ >+ >+public class WindowsProxyProvider extends AbstractProxyProvider { >+ >+ static { >+ System.loadLibrary("jWinHttp"); //$NON-NLS-1$ >+ } >+ >+ private WinHttpProxySelector winHttpProxySelector; >+ >+ public WindowsProxyProvider() { >+ Activator.logInfo("winProxyProvider initialized", null); //$NON-NLS-1$ >+ winHttpProxySelector = new WinHttpProxySelector(); >+ } >+ >+ protected IProxyData[] getProxyData(URI uri) { >+ List proxies = winHttpProxySelector.select(uri); >+ return (IProxyData[]) proxies.toArray(new IProxyData[proxies.size()]); >+ } >+ >+} >Index: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttp.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttp.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttp.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttp.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,83 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.winhttp; >+ >+ >+/** >+ * This is the Win32 WinHttp wrapper. >+ * (Not complete, but offers what we currently need!) >+ */ >+public final class WinHttp { >+ >+ /** >+ * WinHttpOpen prettifiers for optional proxy name parameter >+ */ >+ static final String NO_PROXY_NAME = null; >+ >+ /** >+ * WinHttpOpen prettifiers for optional proxy bypass parameter >+ */ >+ static final String NO_PROXY_BYPASS = null; >+ >+ /** >+ * WinHttpOpen - see Microsoft SDK Documentation >+ * >+ * @param userAgent >+ * @param accessType >+ * @param proxyName >+ * @param proxyBypass >+ * @param flags >+ * @return the handle >+ */ >+ public static native int open( String userAgent, int accessType, String proxyName, String proxyBypass, int flags ); >+ >+ /** >+ * WinHttpCloseHandle - see Microsoft SDK Documentation >+ * >+ * @param hInternet >+ * @return true on success >+ */ >+ public static native boolean closeHandle( int hInternet ); >+ >+ /** >+ * WinHttpGetIEProxyConfigForCurrentUser - see Microsoft SDK Documentation >+ * >+ * @param proxyConfig >+ * @return true on success >+ */ >+ public static native boolean getIEProxyConfigForCurrentUser( WinHttpCurrentUserIEProxyConfig proxyConfig ); >+ >+ /** >+ * WinHttpGetProxyForUrl - see Microsoft SDK Documentation >+ * >+ * @param hSession >+ * @param url >+ * @param autoProxyOptions >+ * @param proxyInfo >+ * @return true on success >+ */ >+ public static native boolean getProxyForUrl( int hSession, String url, WinHttpAutoProxyOptions autoProxyOptions, WinHttpProxyInfo proxyInfo ); >+ >+ /** >+ * GetLastError - see Microsoft SDK Documentation >+ * >+ * @return the last error code (win32) >+ */ >+ public static native int getLastError(); >+ >+ /** >+ * GetLastErrorMessage - formats the last error >+ * >+ * @return the readable last error code >+ */ >+ public static native String getLastErrorMessage(); >+ >+} >Index: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxySelector.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxySelector.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxySelector.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxySelector.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,170 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.winhttp; >+ >+import java.net.URI; >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.core.internal.net.Activator; >+import org.eclipse.core.internal.net.proxy.win32.util.ProxyBypass; >+import org.eclipse.core.internal.net.proxy.win32.util.ProxySelectorPACUtils; >+import org.eclipse.core.internal.net.proxy.win32.util.StringUtils; >+ >+ >+/** >+ * ProxySelector that gets its settings from the "internet options >> connection >+ * settings" >+ */ >+public class WinHttpProxySelector { >+ >+ private WinHttpCurrentUserIEProxyConfig proxyConfig = null; >+ private WinHttpConfig winHttpConfig; >+ private boolean pacFailed = false; >+ private boolean wpadFailed = false; >+ private List wpadProxies = null; >+ >+ private final static int ERROR_WINHTTP_AUTODETECTION_FAILED = 12180; >+ private static final String MY_NAME = WinHttpProxySelector.class.getName(); >+ >+ public List select(URI uri) { >+ WinHttpCurrentUserIEProxyConfig newProxyConfig = new WinHttpCurrentUserIEProxyConfig(); >+ if (!WinHttp.getIEProxyConfigForCurrentUser(newProxyConfig)) { >+ Activator >+ .logError( >+ "WinHttp.GetIEProxyConfigForCurrentUser failed with error '" + WinHttp.getLastErrorMessage() + "' #" + WinHttp.getLastError() + ".", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ return Collections.EMPTY_LIST; >+ } >+ >+ // Let´s see if we are still up-to-date. >+ boolean proxyConfigChanged = !newProxyConfig.equals(proxyConfig); >+ if (proxyConfigChanged) { >+ proxyConfig = newProxyConfig; >+ // Retry pac and wpad >+ pacFailed = false; >+ wpadFailed = false; >+ wpadProxies = Collections.EMPTY_LIST; >+ } >+ >+ List proxies = new ArrayList(); >+ >+ // Explicit proxies defined? >+ if (StringUtils.isGiven(proxyConfig.getProxy())) { >+ // Yes, let´s see if we are still up-to-date or not yet initialized. >+ if (proxyConfigChanged || winHttpConfig == null) { >+ winHttpConfig = new WinHttpConfig(proxyConfig); >+ } >+ >+ if (!winHttpConfig.bypassProxyFor(uri)) { >+ if (winHttpConfig.useProtocolSpecificProxies()) { >+ proxies.addAll(winHttpConfig >+ .getProtocolSpecificProxies(uri)); >+ } else { >+ proxies.addAll(winHttpConfig.getUniversalProxies()); >+ } >+ } >+ } >+ >+ boolean isPac = proxyConfig.getAutoConfigUrl() != null; >+ boolean isWpad = proxyConfig.isAutoDetect(); >+ >+ if (isPac || isWpad) { >+ // Create the WinHTTP session. >+ int hHttpSession = WinHttp.open(MY_NAME, >+ WinHttpProxyInfo.WINHTTP_ACCESS_TYPE_NO_PROXY, >+ WinHttp.NO_PROXY_NAME, WinHttp.NO_PROXY_BYPASS, 0); >+ if (hHttpSession == 0) { >+ Activator >+ .logError( >+ "WinHttp.Open failed with error'" + WinHttp.getLastErrorMessage() + "' #" + WinHttp.getLastError() + ".", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ } else { >+ try { >+ // PAC file? >+ if (isPac && !pacFailed) { >+ proxies.addAll(pacSelect(hHttpSession, uri)); >+ } >+ >+ // WPAD? >+ if (isWpad && !wpadFailed) { >+ if (wpadProxies == null || wpadProxies.size() == 0) { >+ wpadProxies = wpadSelect(hHttpSession, uri); >+ } >+ proxies.addAll(wpadProxies); >+ } >+ } finally { >+ WinHttp.closeHandle(hHttpSession); >+ } >+ } >+ } >+ >+ // resort(proxies); >+ return proxies; >+ } >+ >+ protected List pacSelect(int hHttpSession, URI uri) { >+ // Set up the autoproxy call. >+ WinHttpAutoProxyOptions autoProxyOptions = new WinHttpAutoProxyOptions(); >+ autoProxyOptions >+ .setFlags(WinHttpAutoProxyOptions.WINHTTP_AUTOPROXY_CONFIG_URL); >+ autoProxyOptions.setAutoConfigUrl(proxyConfig.getAutoConfigUrl()); >+ autoProxyOptions.setAutoLogonIfChallenged(true); >+ WinHttpProxyInfo proxyInfo = new WinHttpProxyInfo(); >+ >+ boolean ok = WinHttp.getProxyForUrl(hHttpSession, uri.toString(), >+ autoProxyOptions, proxyInfo); >+ if (!ok) { >+ pacFailed = true; >+ Activator >+ .logError( >+ "WinHttp.GetProxyForUrl for pac failed with error '" + WinHttp.getLastErrorMessage() + "' #" + WinHttp.getLastError() + ".", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ return Collections.EMPTY_LIST; >+ } >+ ProxyBypass proxyBypass = new ProxyBypass(proxyInfo.getProxyBypass()); >+ if (proxyBypass.bypassProxyFor(uri)) >+ return Collections.EMPTY_LIST; >+ return ProxySelectorPACUtils.getProxies(proxyInfo.getProxy()); >+ } >+ >+ protected List wpadSelect(int hHttpSession, URI uri) { >+ // Set up the autoproxy call. >+ WinHttpAutoProxyOptions autoProxyOptions = new WinHttpAutoProxyOptions(); >+ autoProxyOptions >+ .setFlags(WinHttpAutoProxyOptions.WINHTTP_AUTOPROXY_AUTO_DETECT); >+ autoProxyOptions >+ .setAutoDetectFlags(WinHttpAutoProxyOptions.WINHTTP_AUTO_DETECT_TYPE_DHCP >+ | WinHttpAutoProxyOptions.WINHTTP_AUTO_DETECT_TYPE_DNS_A); >+ autoProxyOptions.setAutoLogonIfChallenged(true); >+ WinHttpProxyInfo proxyInfo = new WinHttpProxyInfo(); >+ >+ boolean ok = WinHttp.getProxyForUrl(hHttpSession, uri.toString(), >+ autoProxyOptions, proxyInfo); >+ if (!ok) { >+ wpadFailed = WinHttp.getLastError() == ERROR_WINHTTP_AUTODETECTION_FAILED; >+ Activator >+ .logError( >+ "WinHttp.GetProxyForUrl for wpad failed with error '" + WinHttp.getLastErrorMessage() + "' #" + WinHttp.getLastError() + ".", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ return Collections.EMPTY_LIST; >+ } >+ ProxyBypass proxyBypass = new ProxyBypass(proxyInfo.getProxyBypass()); >+ if (proxyBypass.bypassProxyFor(uri)) >+ return Collections.EMPTY_LIST; >+ return ProxySelectorPACUtils.getProxies(proxyInfo.getProxy()); >+ } >+ >+ /** >+ * @see java.lang.Object#toString() >+ */ >+ public String toString() { >+ return MY_NAME; >+ } >+ >+} >Index: src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorUtils.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorUtils.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorUtils.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorUtils.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,157 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.util; >+ >+import java.net.URI; >+import java.util.ArrayList; >+import java.util.List; >+import java.util.Map; >+import java.util.StringTokenizer; >+ >+import org.eclipse.core.internal.net.Activator; >+import org.eclipse.core.internal.net.ProxyData; >+import org.eclipse.core.net.proxy.IProxyData; >+ >+/** >+ * >+ */ >+public final class ProxySelectorUtils { >+ >+ static private int PROXY_DEFAULT_PORT = 80; >+ static private int HTTPPROXY_DEFAULT_PORT = PROXY_DEFAULT_PORT; >+ static private int HTTPSPROXY_DEFAULT_PORT = 443; >+ static private int SOCKSPROXY_DEFAULT_PORT = 1080; >+ >+// private static final List emptyProxyList = Collections.EMPTY_LIST; >+ >+ private ProxySelectorUtils() { >+ super(); >+ } >+ >+ /** >+ * Scan the proxy list string and fill this information in the correct list >+ * or map. <br> >+ * The proxy list contains one or more of the following strings separated by >+ * semicolons:<br> >+ * <code><pre> >+ * ([<scheme>=][<scheme> "://" ]<server>[ ":" <port>]) >+ * </pre></code> >+ * >+ * @param proxyList the proxy list as a string >+ * @param universalProxies the list of proxies receiving the universal proxies >+ * @param protocolSpecificProxies a map from http schemes to the list of scheme specific proxies >+ */ >+ public static void fillProxyLists(String proxyList, List universalProxies, >+ Map protocolSpecificProxies) { >+ StringTokenizer tokenizer = new StringTokenizer(proxyList, ";"); //$NON-NLS-1$ >+ while (tokenizer.hasMoreTokens()) { >+ createProxy(tokenizer.nextToken(), universalProxies, >+ protocolSpecificProxies); >+ } >+ } >+ >+ private static void createProxy(final String proxyDefinition, >+ List universalProxies, Map protocolSpecificProxies) { >+ String protocol = null; >+ String host = null; >+ int port = 0; >+ >+ int urlStart = 0; >+ // if there is no '=' character within the proxy definition we have a >+ // proxy >+ // definition that serves all protocols. In this case we MUST ignore the >+ // protocol, >+ // otherwise the protocol MUST be used to determine the specific proxy >+ // settings >+ if (proxyDefinition.indexOf("=") != -1) { //$NON-NLS-1$ >+ protocol = proxyDefinition.substring(0, proxyDefinition >+ .indexOf("=")); //$NON-NLS-1$ >+ urlStart = proxyDefinition.indexOf("=") + 1; //$NON-NLS-1$ >+ } >+ >+ try { >+ // The scheme of the uri is irrelevant. We add the http:// >+ // scheme to enable class URI to parse the stuff >+ String augmentedURI = proxyDefinition.substring(urlStart); >+ if (augmentedURI.indexOf("://") == -1) { //$NON-NLS-1$ >+ augmentedURI = "http://" + augmentedURI; //$NON-NLS-1$ >+ } >+ URI uri = new URI(augmentedURI); >+ host = uri.getHost(); >+ port = uri.getPort() > 0 ? uri.getPort() >+ : getProxyDefaultPort(protocol); >+ } catch (Exception ex) { >+ Activator >+ .logError( >+ "not a valid proxy definition: '" + proxyDefinition + "'.", ex); //$NON-NLS-1$ //$NON-NLS-2$ >+ return; >+ } >+ >+ if (host == null) { >+ Activator >+ .logError( >+ "not a valid proxy definition: '" + proxyDefinition + "'.", null); //$NON-NLS-1$ //$NON-NLS-2$ >+ return; >+ } >+ >+ if (protocol == null) { >+ universalProxies.add(createProxy(IProxyData.HTTP_PROXY_TYPE, host, >+ port)); >+ } else { >+ addProtocolSpecificProxy(protocolSpecificProxies, protocol, >+ createProxy(resolveProxyType(protocol), host, port)); >+ } >+ } >+ >+ private static int getProxyDefaultPort(String protocol) { >+ if (protocol == null) >+ return PROXY_DEFAULT_PORT; >+ if ("http".equalsIgnoreCase(protocol)) //$NON-NLS-1$ >+ return HTTPPROXY_DEFAULT_PORT; >+ if ("https".equalsIgnoreCase(protocol)) //$NON-NLS-1$ >+ return HTTPSPROXY_DEFAULT_PORT; >+ if ("socks".equalsIgnoreCase(protocol)) //$NON-NLS-1$ >+ return SOCKSPROXY_DEFAULT_PORT; >+ if ("socket".equalsIgnoreCase(protocol)) //$NON-NLS-1$ >+ return SOCKSPROXY_DEFAULT_PORT; >+ >+ return PROXY_DEFAULT_PORT; >+ } >+ >+ private static void addProtocolSpecificProxy(Map protocolSpecificProxies, >+ String protocol, IProxyData proxy) { >+ List list = (List) protocolSpecificProxies.get(protocol); >+ if (list == null) { >+ list = new ArrayList(); >+ protocolSpecificProxies.put(protocol, list); >+ } >+ >+ list.add(proxy); >+ } >+ >+ private static String resolveProxyType(String protocol) { >+ // TODO: return HTTP proxy for well-known high level protocols only? >+ if (protocol.equalsIgnoreCase("socks") || protocol.equalsIgnoreCase("socket")) //$NON-NLS-1$ //$NON-NLS-2$ >+ return IProxyData.SOCKS_PROXY_TYPE; >+ if (protocol.equalsIgnoreCase("https")) //$NON-NLS-1$ >+ return IProxyData.HTTPS_PROXY_TYPE; >+ return IProxyData.HTTP_PROXY_TYPE; >+ } >+ >+ private static IProxyData createProxy(String scheme, String host, int port) { >+ String type = resolveProxyType(scheme); >+ IProxyData proxy = new ProxyData(type); >+ proxy.setHost(host); >+ proxy.setPort(port); >+ return proxy; >+ } >+ >+} >Index: natives/unix/Debug/subdir.mk >=================================================================== >RCS file: natives/unix/Debug/subdir.mk >diff -N natives/unix/Debug/subdir.mk >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ natives/unix/Debug/subdir.mk 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,24 @@ >+################################################################################ >+# Automatically-generated file. Do not edit! >+################################################################################ >+ >+# Add inputs and outputs from these tool invocations to the build variables >+C_SRCS += \ >+../getsystemproxy.c >+ >+OBJS += \ >+./getsystemproxy.o >+ >+C_DEPS += \ >+./getsystemproxy.d >+ >+ >+# Each subdirectory must supply rules for building sources it contributes >+%.o: ../%.c >+ @echo 'Building file: $<' >+ @echo 'Invoking: GCC C Compiler' >+ gcc -I/usr/include/gconf/2 -I/usr/include/orbit-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include/ -O0 -fPIC -g3 -Wall -c -fmessage-length=0 -m32 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" >+ @echo 'Finished building: $<' >+ @echo ' ' >+ >+ >Index: natives/unix/Debug/sources.mk >=================================================================== >RCS file: natives/unix/Debug/sources.mk >diff -N natives/unix/Debug/sources.mk >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ natives/unix/Debug/sources.mk 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,17 @@ >+################################################################################ >+# Automatically-generated file. Do not edit! >+################################################################################ >+ >+O_SRCS := >+C_SRCS := >+S_SRCS := >+OBJ_SRCS := >+ASM_SRCS := >+OBJS := >+C_DEPS := >+LIBRARIES := >+ >+# Every subdirectory with source files must be described here >+SUBDIRS := \ >+. \ >+ >Index: src/org/eclipse/core/internal/net/proxy/win32/util/ProxyBypass.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/util/ProxyBypass.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/util/ProxyBypass.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/util/ProxyBypass.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,86 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.util; >+ >+import java.net.URI; >+import java.util.regex.Pattern; >+ >+/** >+ * Encapsulates the proxy bypass list. >+ * >+ * For more information see >+ * {@link "http://msdn2.microsoft.com/en-us/library/aa383912(VS.85).aspx"} >+ */ >+public class ProxyBypass { >+ >+ private final String proxyBypass; >+ private final Pattern proxyBypassPattern; >+ >+ private final static String BYPASS_LOCAL_ADDESSES_TOKEN = "<local>"; //$NON-NLS-1$ >+ >+ /** >+ * Create a ProxyBypass instance from the proxy bypass list string. >+ * >+ * @param proxyBypass >+ */ >+ public ProxyBypass(String proxyBypass) { >+ this.proxyBypass = proxyBypass != null ? proxyBypass : ""; //$NON-NLS-1$ >+ >+ if (proxyBypass != null) { >+ String regExp = StringUtils.replace(proxyBypass, ";", "|"); //$NON-NLS-1$ //$NON-NLS-2$ >+ regExp = StringUtils.replace(regExp, ".", "\\."); //$NON-NLS-1$ //$NON-NLS-2$ >+ regExp = StringUtils.replace(regExp, "*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$ >+ this.proxyBypassPattern = Pattern.compile(regExp); >+ } else { >+ this.proxyBypassPattern = Pattern.compile(""); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * Check whether the given uri should bypass the proxy. >+ * >+ * @param uri >+ * @return true if the the uri should bypass the proxy; otherwise false >+ */ >+ public boolean bypassProxyFor(URI uri) { >+ final String host = uri.getHost(); >+ if (host == null) >+ return false; >+ return (isLocal(host) && isBypassLocalAddresses(proxyBypass)) >+ || isInBypassList(host); >+ } >+ >+ /** >+ * @param proxyBypass >+ * @param uri >+ * @return >+ */ >+ private boolean isInBypassList(String host) { >+ return proxyBypassPattern.matcher(host).matches(); >+ } >+ >+ /** >+ * @param uri >+ * @return >+ */ >+ private static boolean isLocal(String host) { >+ return host.indexOf(".") == -1; //$NON-NLS-1$ >+ } >+ >+ /** >+ * @param addressListString >+ * @return >+ */ >+ private static boolean isBypassLocalAddresses(String proxyBypass) { >+ return proxyBypass.indexOf(BYPASS_LOCAL_ADDESSES_TOKEN) != -1; >+ } >+ >+} >Index: natives/unix/Debug/makefile >=================================================================== >RCS file: natives/unix/Debug/makefile >diff -N natives/unix/Debug/makefile >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ natives/unix/Debug/makefile 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,43 @@ >+################################################################################ >+# Automatically-generated file. Do not edit! >+################################################################################ >+ >+-include ../makefile.init >+ >+RM := rm -rf >+ >+# All of the sources participating in the build are defined here >+-include sources.mk >+-include subdir.mk >+-include objects.mk >+ >+ifneq ($(MAKECMDGOALS),clean) >+ifneq ($(strip $(C_DEPS)),) >+-include $(C_DEPS) >+endif >+endif >+ >+-include ../makefile.defs >+ >+# Add inputs and outputs from these tool invocations to the build variables >+ >+# All Target >+all: libproxysupport.so >+ >+# Tool invocations >+libproxysupport.so: $(OBJS) $(USER_OBJS) >+ @echo 'Building target: $@' >+ @echo 'Invoking: GCC C Linker' >+ gcc -m32 -shared -o"libproxysupport.so" $(OBJS) $(USER_OBJS) $(LIBS) >+ @echo 'Finished building target: $@' >+ @echo ' ' >+ >+# Other Targets >+clean: >+ -$(RM) $(OBJS)$(C_DEPS)$(LIBRARIES) libproxysupport.so >+ -@echo ' ' >+ >+.PHONY: all clean dependents >+.SECONDARY: >+ >+-include ../makefile.targets >Index: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxyInfo.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxyInfo.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxyInfo.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpProxyInfo.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,48 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.winhttp; >+ >+/** >+ * Wrapper for Win32 WINHTTP_PROXY_INFO Structure >+ */ >+public class WinHttpProxyInfo { >+ >+ // WinHttpOpen dwAccessType values (also for WINHTTP_PROXY_INFO::dwAccessType) >+ public static final int WINHTTP_ACCESS_TYPE_DEFAULT_PROXY = 0; >+ public static final int WINHTTP_ACCESS_TYPE_NO_PROXY = 1; >+ public static final int WINHTTP_ACCESS_TYPE_NAMED_PROXY = 3; >+ >+ private int accessType; >+ private String proxy; >+ private String proxyBypass; >+ >+ /** >+ * @return the accessType >+ */ >+ public int getAccessType() { >+ return accessType; >+ } >+ >+ /** >+ * @return the proxy >+ */ >+ public String getProxy() { >+ return proxy; >+ } >+ >+ /** >+ * @return the proxyBypass >+ */ >+ public String getProxyBypass() { >+ return proxyBypass; >+ } >+ >+} >Index: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpConfig.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpConfig.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpConfig.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpConfig.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,60 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.winhttp; >+ >+import java.net.URI; >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.core.internal.net.proxy.win32.util.ProxyBypass; >+import org.eclipse.core.internal.net.proxy.win32.util.ProxySelectorUtils; >+ >+ >+/** >+ * WinHttpConfig unwraps the information from WinHttpCurrentIEProxyConfig >+ */ >+public class WinHttpConfig { >+ >+ private List universalProxies = new ArrayList(); >+ private Map protocolSpecificProxies = new HashMap(); >+ private ProxyBypass proxyBypass; >+ >+ /** >+ * @param proxyConfig >+ */ >+ public WinHttpConfig(WinHttpCurrentUserIEProxyConfig proxyConfig) { >+ ProxySelectorUtils.fillProxyLists(proxyConfig.getProxy(), >+ universalProxies, protocolSpecificProxies); >+ proxyBypass = new ProxyBypass(proxyConfig.getProxyBypass()); >+ } >+ >+ public boolean useUniversalProxy() { >+ return !universalProxies.isEmpty(); >+ } >+ >+ public boolean useProtocolSpecificProxies() { >+ return !protocolSpecificProxies.isEmpty(); >+ } >+ >+ public List getProtocolSpecificProxies(URI uri) { >+ return (List)protocolSpecificProxies.get(uri.getScheme()); >+ } >+ >+ public List getUniversalProxies() { >+ return universalProxies; >+ } >+ >+ public boolean bypassProxyFor(URI uri) { >+ return proxyBypass.bypassProxyFor(uri); >+ } >+} >Index: natives/unix/getsystemproxy.c >=================================================================== >RCS file: natives/unix/getsystemproxy.c >diff -N natives/unix/getsystemproxy.c >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ natives/unix/getsystemproxy.c 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,237 @@ >+/* >+ * Copyright 2008 Oakland Software Incorporated and others >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Oakland Software Incorporated - initial API and implementation >+ */ >+ >+#include <jni.h> >+ >+#include <glib.h> >+#include <glib/gslist.h> >+#include <gconf/gconf-value.h> >+#include <gconf/gconf-client.h> >+ >+#ifdef __linux__ >+#include <string.h> >+#else >+#include <strings.h> >+#endif >+ >+static GConfClient *client= NULL; >+ >+static jclass proxyInfoClass; >+static jclass stringClass; >+static jmethodID proxyInfoConstructor; >+static jmethodID toString; >+ >+static jmethodID hostMethod; >+static jmethodID portMethod; >+static jmethodID requiresAuthenticationMethod; >+static jmethodID userMethod; >+static jmethodID passwordMethod; >+ >+#define CHECK_NULL(X) { if ((X) == NULL) fprintf (stderr,"JNI error at line %d\n", __LINE__); } >+ >+static void gconfInit(JNIEnv *env) { >+ client = gconf_client_get_default(); >+ jclass cls= NULL; >+ CHECK_NULL(cls = (*env)->FindClass(env, "org/eclipse/core/internal/net/ProxyData")); >+ proxyInfoClass = (*env)->NewGlobalRef(env, cls); >+ >+ CHECK_NULL(cls = (*env)->FindClass(env, "java/lang/String")); >+ stringClass = (*env)->NewGlobalRef(env, cls); >+ >+ CHECK_NULL(proxyInfoConstructor = (*env)->GetMethodID(env, proxyInfoClass, "<init>", "(Ljava/lang/String;)V")); >+ >+ CHECK_NULL(toString = (*env)->GetMethodID(env, proxyInfoClass, "toString", "()Ljava/lang/String;")); >+ >+ CHECK_NULL(hostMethod = (*env)->GetMethodID(env, proxyInfoClass, "setHost", >+ "(Ljava/lang/String;)V")); >+ CHECK_NULL(portMethod = (*env)->GetMethodID(env, proxyInfoClass, "setPort", >+ "(I)V")); >+ CHECK_NULL(requiresAuthenticationMethod= (*env)->GetMethodID(env, proxyInfoClass, "setRequiresAuthentication", >+ "(Z)V")); >+ CHECK_NULL(userMethod = (*env)->GetMethodID(env, proxyInfoClass, "setUserid", >+ "(Ljava/lang/String;)V")); >+ CHECK_NULL(passwordMethod = (*env)->GetMethodID(env, proxyInfoClass, "setPassword", >+ "(Ljava/lang/String;)V")); >+} >+ >+/* >+ * Class: org_eclipse_core_internal_net_UnixProxyProvider >+ * Method: getGConfProxyInfo >+ * Signature: ([Ljava/lang/String); >+ */ >+JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getGConfProxyInfo( >+ JNIEnv *env, jclass clazz, jstring protocol) { >+ >+ jboolean isCopy; >+ const char *cprotocol; >+ >+ jobject proxyInfo= NULL; >+ >+ if (client == NULL) { >+ gconfInit(env); >+ } >+ >+ CHECK_NULL(proxyInfo = (*env)->NewObject(env, proxyInfoClass, proxyInfoConstructor, protocol)); >+ >+ cprotocol = (*env)->GetStringUTFChars(env, protocol, &isCopy); >+ if (cprotocol == NULL) >+ return NULL; >+ >+ //printf("cprotocol: %s\n", cprotocol); >+ >+ if (strcasecmp(cprotocol, "http") == 0) { >+ gboolean useProxy = gconf_client_get_bool(client, >+ "/system/http_proxy/use_http_proxy", NULL); >+ if (!useProxy) { >+ proxyInfo = NULL; >+ goto exit; >+ } >+ >+ gchar *host = gconf_client_get_string(client, >+ "/system/http_proxy/host", NULL); >+ jobject jhost = (*env)->NewStringUTF(env, host); >+ (*env)->CallVoidMethod(env, proxyInfo, hostMethod, jhost); >+ >+ gint port = gconf_client_get_int(client, "/system/http_proxy/port", >+ NULL); >+ (*env)->CallVoidMethod(env, proxyInfo, portMethod, port); >+ >+ gboolean reqAuth = gconf_client_get_bool(client, >+ "/system/http_proxy/use_authentication", NULL); >+ (*env)->CallVoidMethod(env, proxyInfo, >+ requiresAuthenticationMethod, reqAuth); >+ if (reqAuth) { >+ >+ gchar *user = gconf_client_get_string(client, >+ "/system/http_proxy/authentication_user", NULL); >+ jobject juser = (*env)->NewStringUTF(env, user); >+ (*env)->CallVoidMethod(env, proxyInfo, userMethod, juser); >+ >+ gchar *password = gconf_client_get_string(client, >+ "/system/http_proxy/authentication_password", NULL); >+ jobject jpassword = (*env)->NewStringUTF(env, password); >+ (*env)->CallVoidMethod(env, proxyInfo, passwordMethod, >+ jpassword); >+ } >+ goto exit; >+ } >+ >+ // Everything else applies only if the system proxy mode is manual >+ gchar *mode = gconf_client_get_string(client, "/system/proxy/mode", NULL); >+ if (strcasecmp(mode, "manual") != 0) { >+ proxyInfo = NULL; >+ goto exit; >+ } >+ >+ char selector[100]; >+ >+ if (strcasecmp(cprotocol, "https") == 0) { >+ strcpy(selector, "/system/proxy/secure_"); >+ } else if (strcasecmp(cprotocol, "socks") == 0) { >+ strcpy(selector, "/system/proxy/socks_"); >+ } else if (strcasecmp(cprotocol, "ftp") == 0) { >+ strcpy(selector, "/system/proxy/ftp_"); >+ } else { >+ proxyInfo = NULL; >+ goto exit; >+ } >+ >+ char useSelector[100]; >+ strcpy(useSelector, selector); >+ >+ gchar *host = gconf_client_get_string(client, strcat(useSelector, "host"), >+ NULL); >+ jobject jhost = (*env)->NewStringUTF(env, host); >+ (*env)->CallVoidMethod(env, proxyInfo, hostMethod, jhost); >+ >+ strcpy(useSelector, selector); >+ gint port = gconf_client_get_int(client, strcat(useSelector, "port"), NULL); >+ (*env)->CallVoidMethod(env, proxyInfo, portMethod, port); >+ >+ exit: if (isCopy == JNI_TRUE) >+ (*env)->ReleaseStringUTFChars(env, protocol, cprotocol); >+ return proxyInfo; >+} >+ >+typedef struct { >+ jobjectArray npHostArray; >+ JNIEnv *env; >+ int index; >+} ListProcContext; >+ >+// user_data is the ListProcContext >+void listProc(gpointer data, gpointer user_data) { >+ ListProcContext *lpc = user_data; >+ jobject jnpHost = (*lpc->env)->NewStringUTF(lpc->env, (char *)data); >+ (*lpc->env)->SetObjectArrayElement(lpc->env, lpc->npHostArray, >+ lpc->index++, jnpHost); >+} >+ >+/* >+ * Class: org_eclipse_core_internal_net_UnixProxyProvider >+ * Method: getGConfNonProxyHosts >+ * Signature: ()[Ljava/lang/String; >+ */ >+JNIEXPORT jobjectArray JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getGConfNonProxyHosts( >+ JNIEnv *env, jclass clazz) { >+ >+ if (client == NULL) { >+ gconfInit(env); >+ } >+ >+ GSList *npHosts; >+ int size; >+ >+ npHosts = gconf_client_get_list(client, "/system/http_proxy/ignore_hosts", >+ GCONF_VALUE_STRING, NULL); >+ size = g_slist_length(npHosts); >+ >+ // TODO - I'm not sure this is really valid, it's from the JVM implementation >+ // of ProxySelector >+ if (size == 0) { >+ npHosts = gconf_client_get_list(client, "/system/proxy/no_proxy_for", >+ GCONF_VALUE_STRING, NULL); >+ } >+ size = g_slist_length(npHosts); >+ >+ jobjectArray ret = (*env)->NewObjectArray(env, size, stringClass, NULL); >+ >+ ListProcContext lpc; >+ lpc.env = env; >+ lpc.npHostArray = ret; >+ lpc.index = 0; >+ >+ g_slist_foreach(npHosts, listProc, &lpc); >+ return ret; >+} >+ >+/* >+ * Class: org_eclipse_core_internal_net_UnixProxyProvider >+ * Method: getKdeProxyInfo >+ * Signature: ([Ljava/lang/String); >+ */ >+JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getKdeProxyInfo( >+ JNIEnv *env, jclass clazz, jstring protocol) { >+ //printf("getKdeProxyInfo - not implemented\n"); >+ return NULL; >+} >+ >+/* >+ * Class: org_eclipse_core_internal_net_UnixProxyProvider >+ * Method: getKdeNonProxyHosts >+ * Signature: ()Ljava/lang/String; >+ */ >+JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getKdeNonProxyHosts( >+ JNIEnv *env, jclass clazz) { >+ //printf("getKdeNonProxyHosts - not implemented\n"); >+ return NULL; >+} >+ >Index: src/org/eclipse/core/internal/net/UnixProxyProvider.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/UnixProxyProvider.java >diff -N src/org/eclipse/core/internal/net/UnixProxyProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/UnixProxyProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,80 @@ >+package org.eclipse.core.internal.net; >+ >+import java.net.URI; >+import java.net.URISyntaxException; >+ >+import org.eclipse.core.net.proxy.IProxyData; >+ >+public class UnixProxyProvider extends AbstractProxyProvider { >+ >+ static { >+ System.loadLibrary("proxysupport"); //$NON-NLS-1$ >+ } >+ >+ public UnixProxyProvider() { >+ Activator.logInfo("linuxProxyProvider initialized", null); //$NON-NLS-1$ >+ } >+ >+ public IProxyData[] getProxyData(URI uri) { >+ String protocol = uri.getScheme(); >+ >+ ProxyData pd = getSystemProxyInfo(protocol); >+ >+ if (pd != null) { >+ IProxyData[] pds = new IProxyData[1]; >+ pds[0] = pd; >+ return pds; >+ } >+ >+ return new IProxyData[0]; >+ } >+ >+ protected String[] getNonProxiedHosts() { >+ String[] npHosts = getGConfNonProxyHosts(); >+ if (npHosts != null && npHosts.length > 0) >+ return npHosts; >+ return getKdeNonProxyHosts(); >+ } >+ >+ // Returns null if something wrong or there is no proxy for the protocol >+ protected ProxyData getSystemProxyInfo(String protocol) { >+ ProxyData pd; >+ >+ // First try the environment variable which is a URL >+ String sysHttp = System.getenv(protocol.toLowerCase() + "_proxy"); //$NON-NLS-1$ >+ if (sysHttp != null) { >+ URI uri = null; >+ try { >+ uri = new URI(sysHttp); >+ } catch (URISyntaxException e) { >+ return null; >+ } >+ >+ pd = new ProxyData(protocol); >+ pd.setHost(uri.getHost()); >+ pd.setPort(uri.getPort()); >+ return pd; >+ } >+ >+ // Then ask Gnome >+ pd = getGConfProxyInfo(protocol); >+ if (pd != null) >+ return pd; >+ >+ // Then ask KDE >+ pd = getKdeProxyInfo(protocol); >+ if (pd != null) >+ return pd; >+ >+ return null; >+ } >+ >+ protected static native ProxyData getGConfProxyInfo(String protocol); >+ >+ protected static native String[] getGConfNonProxyHosts(); >+ >+ protected static native ProxyData getKdeProxyInfo(String protocol); >+ >+ protected static native String[] getKdeNonProxyHosts(); >+ >+} >Index: src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorPACUtils.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorPACUtils.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorPACUtils.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/util/ProxySelectorPACUtils.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,136 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.util; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+import java.util.StringTokenizer; >+ >+import org.eclipse.core.internal.net.ProxyData; >+import org.eclipse.core.net.proxy.IProxyData; >+ >+/** >+ * >+ */ >+public final class ProxySelectorPACUtils { >+ >+ >+ private static final Map PROXY_TYPE_MAP; >+ >+ /* >+ * @see "http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html" >+ */ >+ private static final String PAC_PROXY_TYPE_DIRECT = "DIRECT"; //$NON-NLS-1$ >+ private static final String PAC_PROXY_TYPE_PROXY = "PROXY"; //$NON-NLS-1$ >+ private static final String PAC_PROXY_TYPE_SOCKS = "SOCKS"; //$NON-NLS-1$ >+ >+ private static final String NO_PROXY = "DIRECT"; //$NON-NLS-1$ >+ >+ static { >+ // mapping of pacProgram proxy type names to java proxy types: >+ final Map temp = new HashMap(); >+ temp.put(PAC_PROXY_TYPE_DIRECT, NO_PROXY); >+ temp.put(PAC_PROXY_TYPE_PROXY, IProxyData.HTTP_PROXY_TYPE); >+ temp.put(PAC_PROXY_TYPE_SOCKS, IProxyData.SOCKS_PROXY_TYPE); >+ PROXY_TYPE_MAP = Collections.unmodifiableMap(temp); >+ } >+ >+ private ProxySelectorPACUtils() { >+ // utility >+ } >+ >+ /** >+ * @param pacFindProxyForUrlResult >+ * @return a list of IProxyData objects >+ */ >+ public static List getProxies(String pacFindProxyForUrlResult) { >+ if (StringUtils.isDeepEmpty(pacFindProxyForUrlResult)) { >+ return Collections.EMPTY_LIST; >+ } >+ >+ // final List<Proxy> result = new ArrayList<Proxy>(); >+ final List result = new ArrayList(); >+ final StringTokenizer scanner = new StringTokenizer( >+ pacFindProxyForUrlResult, ";"); //$NON-NLS-1$ >+ while (scanner.hasMoreTokens()) { >+ final String pacProxy = scanner.nextToken().trim(); >+ final IProxyData proxy = getProxy(pacProxy); >+ if (proxy != null) { >+ result.add(proxy); >+ } >+ } >+ >+ return result; >+ } >+ >+ private static IProxyData getProxy(String pacProxy) { >+ >+ if (StringUtils.isEmpty(pacProxy)) { >+ return null; >+ } >+ >+ if (!startsWithProxyType(pacProxy)) { >+ // Assume "PROXY" type! >+ pacProxy = "PROXY " + pacProxy; //$NON-NLS-1$ >+ } >+ StringTokenizer scanner = new StringTokenizer(pacProxy); >+ String pacProxyType = scanner.nextToken(); >+ String proxyType = (String) PROXY_TYPE_MAP.get(pacProxyType); >+ if (proxyType == null || proxyType.equals(NO_PROXY)) >+ return null; >+ >+ String pacHostnameAndPort = null; >+ if (scanner.hasMoreTokens()) { >+ pacHostnameAndPort = scanner.nextToken(); >+ } >+ String hostname = getHostname(pacHostnameAndPort); >+ if (hostname != null) { >+ int port = getPort(pacHostnameAndPort); >+ IProxyData proxy = new ProxyData(proxyType); >+ proxy.setHost(hostname); >+ proxy.setPort(port); >+ return proxy; >+ } >+ return null; >+ } >+ >+ private static boolean startsWithProxyType(String pacProxy) { >+ Iterator iter = PROXY_TYPE_MAP.keySet().iterator(); >+ while (iter.hasNext()) { >+ if (pacProxy.startsWith((String) iter.next())) { >+ return true; >+ } >+ } >+ >+ return false; >+ } >+ >+ static String getHostname(String pacHostnameAndPort) { >+ if (pacHostnameAndPort != null) { >+ return pacHostnameAndPort.substring(0, pacHostnameAndPort >+ .indexOf(':')); >+ } >+ return null; >+ } >+ >+ static int getPort(String pacHostnameAndPort) { >+ if (pacHostnameAndPort != null && pacHostnameAndPort.indexOf(':') > -1) { >+ return Integer.parseInt(pacHostnameAndPort >+ .substring(pacHostnameAndPort.indexOf(':') + 1)); >+ } >+ return 0; >+ } >+ >+} >Index: natives/unix/Debug/objects.mk >=================================================================== >RCS file: natives/unix/Debug/objects.mk >diff -N natives/unix/Debug/objects.mk >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ natives/unix/Debug/objects.mk 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,7 @@ >+################################################################################ >+# Automatically-generated file. Do not edit! >+################################################################################ >+ >+USER_OBJS := >+ >+LIBS := -lgconf-2 -lORBit-2 -lgthread-2.0 -lrt -lgobject-2.0 -lglib-2.0 >Index: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpAutoProxyOptions.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpAutoProxyOptions.java >diff -N src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpAutoProxyOptions.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpAutoProxyOptions.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,63 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 2008 compeople AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * compeople AG (Stefan Liebig) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net.proxy.win32.winhttp; >+ >+/** >+ * Wrapper for Win32 WINHTTP_AUTOPROXY_OPTIONS Structure >+ */ >+public class WinHttpAutoProxyOptions { >+ >+ // Flags for WINHTTP_AUTOPROXY_OPTIONS::dwFlags >+ public static final int WINHTTP_AUTOPROXY_AUTO_DETECT = 0x00000001; >+ public static final int WINHTTP_AUTOPROXY_CONFIG_URL = 0x00000002; >+ public static final int WINHTTP_AUTOPROXY_RUN_INPROCESS = 0x00010000; >+ public static final int WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY = 0x00020000; >+ >+ // Flags for WINHTTP_AUTOPROXY_OPTIONS::dwAutoDetectFlags >+ public static final int WINHTTP_AUTO_DETECT_TYPE_DHCP = 0x00000001; >+ public static final int WINHTTP_AUTO_DETECT_TYPE_DNS_A = 0x00000002; >+ >+ int flags; >+ int autoDetectFlags; >+ String autoConfigUrl; >+ String reservedPointer; >+ int reservedInt; >+ boolean autoLogonIfChallenged; >+ >+ /** >+ * @param autoConfigUrl the autoConfigUrl to set >+ */ >+ public void setAutoConfigUrl( String autoConfigUrl ) { >+ this.autoConfigUrl = autoConfigUrl; >+ } >+ >+ /** >+ * @param autoDetectFlags the autoDetectFlags to set >+ */ >+ public void setAutoDetectFlags( int autoDetectFlags ) { >+ this.autoDetectFlags = autoDetectFlags; >+ } >+ >+ /** >+ * @param autoLogonIfChallenged the autoLogonIfChallenged to set >+ */ >+ public void setAutoLogonIfChallenged( boolean autoLogonIfChallenged ) { >+ this.autoLogonIfChallenged = autoLogonIfChallenged; >+ } >+ >+ /** >+ * @param flags the flags to set >+ */ >+ public void setFlags( int flags ) { >+ this.flags = flags; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 180921
:
88543
|
90245
|
90246
|
91640
|
91641
|
91739
|
91958
|
91959
|
92027
|
92028
|
92325
|
92545
|
93183
|
93367
|
94535
|
94536
|
94712
|
94713
|
95020
|
95021
|
95030
|
95187
|
95337
|
95343
|
96393