Bug 578053 - Gnome proxy support does not work with default gsettings

Fixes some problems with proxy configuration from gsettings:

* Avoid querying deprecated/unused keys:
    org.gnome.system.proxy/use-same-proxy
    org.gnome.system.proxy.http/enabled
* Honour enablement of all proxy types by always checking the presence
  of host name and valid port number
* Avoid populating manual "no proxy" list when the system proxy mode is
  not set to manual

Signed-off-by: Mat Booth <mat.booth@gmail.com>
Change-Id: Iccb7ad5f04b27479e97028e50541479ee97dfe9f
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.team/+/189301
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.core.net.linux/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.net.linux/META-INF/MANIFEST.MF
index 749024a..1daa675 100644
--- a/bundles/org.eclipse.core.net.linux/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.core.net.linux/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@
 Bundle-Vendor: %providerName
 Bundle-Localization: fragment
 Bundle-SymbolicName: org.eclipse.core.net.linux;singleton:=true
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.0.100.qualifier
 Fragment-Host: org.eclipse.core.net;bundle-version="1.1.0"
 Eclipse-PlatformFilter: (osgi.os=linux)
 Bundle-RequiredExecutionEnvironment: JavaSE-11
diff --git a/bundles/org.eclipse.core.net.linux/pom.xml b/bundles/org.eclipse.core.net.linux/pom.xml
index 29baca1..394295d 100644
--- a/bundles/org.eclipse.core.net.linux/pom.xml
+++ b/bundles/org.eclipse.core.net.linux/pom.xml
@@ -20,7 +20,7 @@
   </parent>
   <groupId>org.eclipse.core</groupId>
   <artifactId>org.eclipse.core.net.linux</artifactId>
-  <version>1.0.0-SNAPSHOT</version>
+  <version>1.0.100-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
   <properties>
diff --git a/bundles/org.eclipse.core.net.linux/src/org/eclipse/core/net/ProxyProvider.java b/bundles/org.eclipse.core.net.linux/src/org/eclipse/core/net/ProxyProvider.java
index e9e4992..c299358 100644
--- a/bundles/org.eclipse.core.net.linux/src/org/eclipse/core/net/ProxyProvider.java
+++ b/bundles/org.eclipse.core.net.linux/src/org/eclipse/core/net/ProxyProvider.java
@@ -300,35 +300,8 @@
 			initializeSettings();
 		}
 
-		ProxyData proxyData = new ProxyData(protocol);
-		boolean useSame = fLibGio.g_settings_get_boolean(proxySettings, "use-same-proxy"); //$NON-NLS-1$
-
-		if (protocol.equalsIgnoreCase("http") || useSame) { //$NON-NLS-1$
-			boolean useProxy = fLibGio.g_settings_get_boolean(httpProxySettings, "enabled"); //$NON-NLS-1$
-			if (!useProxy) {
-				return null;
-			}
-			Pointer host = fLibGio.g_settings_get_string(httpProxySettings, "host"); //$NON-NLS-1$
-			proxyData.setHost(host.getString(0));
-			fLibGio.g_free(host);
-
-			int port = fLibGio.g_settings_get_int(httpProxySettings, "port"); //$NON-NLS-1$
-			proxyData.setPort(port);
-
-			boolean reqAuth = fLibGio.g_settings_get_boolean(httpProxySettings, "use-authentication"); //$NON-NLS-1$
-			if (reqAuth) {
-				Pointer user = fLibGio.g_settings_get_string(httpProxySettings,	"authentication-user"); //$NON-NLS-1$
-				proxyData.setUserid(user.getString(0));
-				fLibGio.g_free(user);
-
-				Pointer password = fLibGio.g_settings_get_string(httpProxySettings,	"authentication-password"); //$NON-NLS-1$
-				proxyData.setPassword(password.getString(0));
-				fLibGio.g_free(password);
-			}
-			return proxyData;
-		}
-
 		// Everything else applies only if the system proxy mode is manual
+		// Auto-configuration is not supported
 		Pointer mode = fLibGio.g_settings_get_string(proxySettings, "mode"); //$NON-NLS-1$
 		if (!mode.getString(0).equalsIgnoreCase("manual")) { //$NON-NLS-1$
 			fLibGio.g_free(mode);
@@ -339,23 +312,52 @@
 		Pointer host;
 		int port;
 
-		if (protocol.equalsIgnoreCase("https")) { //$NON-NLS-1$
+		switch (protocol.toLowerCase()) {
+		case "http": //$NON-NLS-1$
+			host = fLibGio.g_settings_get_string(httpProxySettings, "host"); //$NON-NLS-1$
+			port = fLibGio.g_settings_get_int(httpProxySettings, "port"); //$NON-NLS-1$
+			break;
+		case "https": //$NON-NLS-1$
 			host = fLibGio.g_settings_get_string(httpsProxySettings, "host"); //$NON-NLS-1$
 			port = fLibGio.g_settings_get_int(httpsProxySettings, "port"); //$NON-NLS-1$
-		} else if (protocol.equalsIgnoreCase("socks")) { //$NON-NLS-1$
-			host = fLibGio.g_settings_get_string(socksProxySettings, "host"); //$NON-NLS-1$
-			port = fLibGio.g_settings_get_int(socksProxySettings, "port"); //$NON-NLS-1$
-		} else if (protocol.equalsIgnoreCase("ftp")) { //$NON-NLS-1$
+			break;
+		case "ftp": //$NON-NLS-1$
 			host = fLibGio.g_settings_get_string(ftpProxySettings, "host"); //$NON-NLS-1$
 			port = fLibGio.g_settings_get_int(ftpProxySettings, "port"); //$NON-NLS-1$
-		} else {
+			break;
+		case "socks": //$NON-NLS-1$
+			host = fLibGio.g_settings_get_string(socksProxySettings, "host"); //$NON-NLS-1$
+			port = fLibGio.g_settings_get_int(socksProxySettings, "port"); //$NON-NLS-1$
+			break;
+		default:
+			// Unknown/invalid proxy type
 			return null;
 		}
 
+		ProxyData proxyData = new ProxyData(protocol);
 		proxyData.setHost(host.getString(0));
 		fLibGio.g_free(host);
 		proxyData.setPort(port);
 
+		// Each proxy type is enabled only if the "host" key is non-empty and its "port" key is non-0
+		if (proxyData.getHost() == null || proxyData.getPort() == 0) {
+			return null;
+		}
+
+		if (protocol.equalsIgnoreCase("http")) { //$NON-NLS-1$
+			// Authentication applies only to http proxies
+			boolean reqAuth = fLibGio.g_settings_get_boolean(httpProxySettings, "use-authentication"); //$NON-NLS-1$
+			if (reqAuth) {
+				Pointer user = fLibGio.g_settings_get_string(httpProxySettings,	"authentication-user"); //$NON-NLS-1$
+				proxyData.setUserid(user.getString(0));
+				fLibGio.g_free(user);
+
+				Pointer password = fLibGio.g_settings_get_string(httpProxySettings,	"authentication-password"); //$NON-NLS-1$
+				proxyData.setPassword(password.getString(0));
+				fLibGio.g_free(password);
+			}
+		}
+
 		return proxyData;
 	}
 
@@ -364,6 +366,15 @@
 			initializeSettings();
 		}
 
+		// Everything else applies only if the system proxy mode is manual
+		// Auto-configuration is not supported
+		Pointer mode = fLibGio.g_settings_get_string(proxySettings, "mode"); //$NON-NLS-1$
+		if (!mode.getString(0).equalsIgnoreCase("manual")) { //$NON-NLS-1$
+			fLibGio.g_free(mode);
+			return null;
+		}
+		fLibGio.g_free(mode);
+
 		PointerByReference npHostsArray = fLibGio.g_settings_get_strv(proxySettings, "ignore-hosts"); //$NON-NLS-1$
 		String[] npHosts = npHostsArray.getPointer().getStringArray(0);