changeset 7892:9702c7936ed8 icedtea-2.6pre08

PR1992, RH735336: Support retrieving proxy settings on GNOME 3.12.2
author andrew
date Wed, 10 Sep 2014 17:12:24 +0100
parents e97e34bd3cc9
children 6923000c68ee
files src/solaris/native/sun/net/spi/DefaultProxySelector.c
diffstat 1 files changed, 62 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/sun/net/spi/DefaultProxySelector.c	Mon Sep 08 18:46:06 2014 +0100
+++ b/src/solaris/native/sun/net/spi/DefaultProxySelector.c	Wed Sep 10 17:12:24 2014 +0100
@@ -149,7 +149,6 @@
   if (use_gio == JNI_TRUE || gconf_ver > 0) {
     jstring jhost;
     const char *cproto;
-    char *used_proto;
 
     cproto = (*env)->GetStringUTFChars(env, proto, &isCopy);
 
@@ -159,49 +158,75 @@
 
       settings = g_settings_new ("org.gnome.system.proxy");
 
-      use_same_proxy = g_settings_get_boolean (settings, "use-same-proxy");
-      if (use_same_proxy) {
-	used_proto = "http";
-      } else {
-	used_proto = (char*) cproto;
-      }
-
-      mode = g_settings_get_string (settings, "mode");
-      use_proxy = (mode != NULL && strcasecmp (mode, "manual") == 0);
-
-      child_settings = g_settings_get_child (settings, used_proto);
-      if (use_proxy && strcasecmp (used_proto, "http") == 0) {
-	use_proxy = g_settings_get_boolean (child_settings, "enabled");
-      }
+      if (settings != NULL) {
+	mode = g_settings_get_string (settings, "mode");
+	use_proxy = (mode != NULL && strcasecmp (mode, "manual") == 0);
 
-      if (use_proxy) {
-	phost = g_settings_get_string (child_settings, "host");
-	pport = g_settings_get_int (child_settings, "port");
-      }
+	if (use_proxy) {
+	  child_settings = g_settings_get_child (settings, cproto);
+	  if (child_settings != NULL) {
+	    phost = g_settings_get_string (child_settings, "host");
+	    pport = g_settings_get_int (child_settings, "port");
+	    g_object_unref (child_settings);
+	  }
 
-      ignored = g_settings_get_strv (settings, "ignore-hosts");
-      if (ignored != NULL) {
-	char **ptr;
-	size_t urlhost_len, s_len;
-	
-	urlhost = (*env)->GetStringUTFChars(env, host, &isCopy);
-	urlhost_len = strlen (urlhost);
-	if (urlhost != NULL) {
-	  for (ptr = ignored; *ptr != NULL; ++ptr) {
-	    s_len = strlen (*ptr);
-	    if (s_len <= urlhost_len) {
-	      if (strcasecmp (urlhost + (urlhost_len - s_len), *ptr) == 0) {
-		use_proxy = 0;
-		break;
+	  /** No specific proxy specified; check fallbacks **/
+
+	  /** A http proxy is used for https if https is not set **/
+	  if (phost == NULL || strlen(phost) == 0 || pport == 0) {
+	    if (strcasecmp(cproto, "https") == 0) {
+	      child_settings = g_settings_get_child (settings, "http");
+	      if (child_settings != NULL) {
+		phost = g_settings_get_string (child_settings, "host");
+		pport = g_settings_get_int (child_settings, "port");
+		g_object_unref (child_settings);
 	      }
 	    }
 	  }
-	  if (isCopy == JNI_TRUE)
-	    (*env)->ReleaseStringUTFChars(env, host, urlhost);
+
+	  /** If we requested something else, but have SOCKS, use that **/
+	  if (phost == NULL || strlen(phost) == 0 || pport == 0) {
+	    if (strcasecmp(cproto, "socks") != 0) {
+	      child_settings = g_settings_get_child (settings, "socks");
+	      if (child_settings != NULL) {
+		phost = g_settings_get_string (child_settings, "host");
+		pport = g_settings_get_int (child_settings, "port");
+		g_object_unref (child_settings);
+	      }
+	    }
+	  }
+
+	  /** No proxy set at all **/
+	  if (phost == NULL || strlen(phost) == 0 || pport == 0) {
+	    use_proxy = 0;
+	  }
 	}
+
+	/** Disable proxy if this is listed as an ignored host **/
+	ignored = g_settings_get_strv (settings, "ignore-hosts");
+	if (ignored != NULL) {
+	  char **ptr;
+	  size_t urlhost_len, s_len;
+	  
+	  urlhost = (*env)->GetStringUTFChars(env, host, &isCopy);
+	  urlhost_len = strlen (urlhost);
+	  if (urlhost != NULL) {
+	    for (ptr = ignored; *ptr != NULL; ++ptr) {
+	      s_len = strlen (*ptr);
+	      if (s_len <= urlhost_len) {
+		if (strcasecmp (urlhost + (urlhost_len - s_len), *ptr) == 0) {
+		  use_proxy = 0;
+		  break;
+		}
+	      }
+	    }
+	    if (isCopy == JNI_TRUE)
+	      (*env)->ReleaseStringUTFChars(env, host, urlhost);
+	  }
 	
-	g_strfreev (ignored);
-	g_object_unref (child_settings);
+	  g_strfreev (ignored);
+	}
+
 	g_object_unref (settings);
       }
     } else {