[gio] Terminate connect call when application proxy is used
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Thu, 17 Nov 2011 18:04:04 +0000 (13:04 -0500)
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Fri, 18 Nov 2011 17:32:42 +0000 (12:32 -0500)
The connect_async() calls would never terminated when an application side
proxy was being used. Note we also skip over TLS handshake in this case,
as the application may have to do some proxy handshake before.

gio/gsocketclient.c

index e65404f..d14234d 100644 (file)
@@ -804,6 +804,7 @@ g_socket_client_connect (GSocketClient       *client,
   while (connection == NULL)
     {
       GSocketAddress *address = NULL;
+      gboolean application_proxy = FALSE;
       GSocket *socket;
 
       if (g_cancellable_is_cancelled (cancellable))
@@ -897,9 +898,13 @@ g_socket_client_connect (GSocketClient       *client,
              g_object_unref (connection);
              connection = NULL;
            }
+         else
+           {
+             application_proxy = TRUE;
+           }
        }
 
-      if (connection && client->priv->tls)
+      if (!application_proxy && connection && client->priv->tls)
        {
          GIOStream *tlsconn;
 
@@ -1307,6 +1312,12 @@ g_socket_client_proxy_connect (GSocketClientAsyncConnectData *data)
 
       enumerator_next_async (data);
     }
+  else
+    {
+      /* Simply complete the connection, we don't want to do TLS handshake
+       * as the application proxy handling may need proxy handshake first */
+      g_socket_client_async_connect_complete (data);
+    }
 }
 
 static void
@@ -1715,6 +1726,10 @@ g_socket_client_connect_to_uri_finish (GSocketClient  *client,
  * proxy protocols that are reused between protocols. A good example
  * is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
  * be use as generic socket proxy through the HTTP CONNECT method.
+ *
+ * When the proxy is detected as being an application proxy, TLS handshake
+ * will be skipped. This is required to let the application do the proxy
+ * specific handshake.
  */
 void
 g_socket_client_add_application_proxy (GSocketClient *client,