Imported Upstream version 2.53.3
[platform/upstream/glib.git] / gio / gsocketclient.c
index 2cd9893..ddd1497 100644 (file)
@@ -6,7 +6,7 @@
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -489,7 +489,7 @@ g_socket_client_get_local_address (GSocketClient *client)
 /**
  * g_socket_client_set_local_address:
  * @client: a #GSocketClient.
- * @address: (allow-none): a #GSocketAddress, or %NULL
+ * @address: (nullable): a #GSocketAddress, or %NULL
  *
  * Sets the local address of the socket client.
  * The sockets created by this object will bound to the
@@ -720,7 +720,7 @@ g_socket_client_get_proxy_resolver (GSocketClient *client)
 /**
  * g_socket_client_set_proxy_resolver:
  * @client: a #GSocketClient.
- * @proxy_resolver: (allow-none): a #GProxyResolver, or %NULL for the
+ * @proxy_resolver: (nullable): a #GProxyResolver, or %NULL for the
  *   default.
  *
  * Overrides the #GProxyResolver used by @client. You can call this if
@@ -767,7 +767,7 @@ g_socket_client_class_init (GSocketClientClass *class)
    * @client: the #GSocketClient
    * @event: the event that is occurring
    * @connectable: the #GSocketConnectable that @event is occurring on
-   * @connection: the current representation of the connection
+   * @connection: (nullable): the current representation of the connection
    *
    * Emitted when @client's activity on @connectable changes state.
    * Among other things, this can be used to provide progress
@@ -939,7 +939,7 @@ g_socket_client_emit_event (GSocketClient       *client,
  * g_socket_client_connect:
  * @client: a #GSocketClient.
  * @connectable: a #GSocketConnectable specifying the remote address.
- * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
+ * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
  * @error: #GError for error reporting, or %NULL to ignore.
  *
  * Tries to resolve the @connectable and make a network connection to it.
@@ -1067,7 +1067,6 @@ g_socket_client_connect (GSocketClient       *client,
          GProxy *proxy;
 
          protocol = g_proxy_address_get_protocol (proxy_addr);
-         proxy = g_proxy_get_default_for_protocol (protocol);
 
           /* The connection should not be anything else then TCP Connection,
            * but let's put a safety guard in case
@@ -1084,7 +1083,11 @@ g_socket_client_connect (GSocketClient       *client,
              g_object_unref (connection);
              connection = NULL;
             }
-          else if (proxy)
+         else if (g_hash_table_contains (client->priv->app_proxies, protocol))
+           {
+             application_proxy = TRUE;
+           }
+          else if ((proxy = g_proxy_get_default_for_protocol (protocol)))
            {
              GIOStream *proxy_connection;
 
@@ -1101,19 +1104,14 @@ g_socket_client_connect (GSocketClient       *client,
              if (connection)
                g_socket_client_emit_event (client, G_SOCKET_CLIENT_PROXY_NEGOTIATED, connectable, connection);
            }
-         else if (!g_hash_table_lookup_extended (client->priv->app_proxies,
-                                                 protocol, NULL, NULL))
+         else
            {
              g_set_error (&last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
-                          _("Proxy protocol '%s' is not supported."),
+                          _("Proxy protocol ā€œ%sā€ is not supported."),
                           protocol);
              g_object_unref (connection);
              connection = NULL;
            }
-         else
-           {
-             application_proxy = TRUE;
-           }
        }
 
       if (!application_proxy && connection && client->priv->tls)
@@ -1165,7 +1163,7 @@ g_socket_client_connect (GSocketClient       *client,
  * @client: a #GSocketClient
  * @host_and_port: the name and optionally port of the host to connect to
  * @default_port: the default port to connect to
- * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @cancellable: (nullable): a #GCancellable, or %NULL
  * @error: a pointer to a #GError, or %NULL
  *
  * This is a helper function for g_socket_client_connect().
@@ -1229,7 +1227,7 @@ g_socket_client_connect_to_host (GSocketClient  *client,
  * @client: a #GSocketConnection
  * @domain: a domain name
  * @service: the name of the service to connect to
- * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @cancellable: (nullable): a #GCancellable, or %NULL
  * @error: a pointer to a #GError, or %NULL
  *
  * Attempts to create a TCP connection to a service.
@@ -1272,7 +1270,7 @@ g_socket_client_connect_to_service (GSocketClient  *client,
  * @client: a #GSocketClient
  * @uri: A network URI
  * @default_port: the default port to connect to
- * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @cancellable: (nullable): a #GCancellable, or %NULL
  * @error: a pointer to a #GError, or %NULL
  *
  * This is a helper function for g_socket_client_connect().
@@ -1523,7 +1521,6 @@ g_socket_client_connected_callback (GObject      *source,
     }
 
   protocol = g_proxy_address_get_protocol (data->proxy_addr);
-  proxy = g_proxy_get_default_for_protocol (protocol);
 
   /* The connection should not be anything other than TCP,
    * but let's put a safety guard in case
@@ -1539,7 +1536,13 @@ g_socket_client_connected_callback (GObject      *source,
 
       enumerator_next_async (data);
     }
-  else if (proxy)
+  else if (g_hash_table_contains (data->client->priv->app_proxies, protocol))
+    {
+      /* 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);
+    }
+  else if ((proxy = g_proxy_get_default_for_protocol (protocol)))
     {
       g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_PROXY_NEGOTIATING, data->connectable, data->connection);
       g_proxy_connect_async (proxy,
@@ -1550,23 +1553,16 @@ g_socket_client_connected_callback (GObject      *source,
                              data);
       g_object_unref (proxy);
     }
-  else if (!g_hash_table_lookup_extended (data->client->priv->app_proxies,
-                                         protocol, NULL, NULL))
+  else
     {
       g_clear_error (&data->last_error);
 
       g_set_error (&data->last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
-          _("Proxy protocol '%s' is not supported."),
+          _("Proxy protocol ā€œ%sā€ is not supported."),
           protocol);
 
       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
@@ -1641,7 +1637,7 @@ g_socket_client_enumerator_callback (GObject      *object,
  * g_socket_client_connect_async:
  * @client: a #GSocketClient
  * @connectable: a #GSocketConnectable specifying the remote address.
- * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @cancellable: (nullable): a #GCancellable, or %NULL
  * @callback: (scope async): a #GAsyncReadyCallback
  * @user_data: (closure): user data for the callback
  *
@@ -1683,6 +1679,7 @@ g_socket_client_connect_async (GSocketClient       *client,
     data->enumerator = g_socket_connectable_enumerate (connectable);
 
   data->task = g_task_new (client, cancellable, callback, user_data);
+  g_task_set_source_tag (data->task, g_socket_client_connect_async);
   g_task_set_task_data (data->task, data, (GDestroyNotify)g_socket_client_async_connect_data_free);
 
   enumerator_next_async (data);
@@ -1693,7 +1690,7 @@ g_socket_client_connect_async (GSocketClient       *client,
  * @client: a #GSocketClient
  * @host_and_port: the name and optionally the port of the host to connect to
  * @default_port: the default port to connect to
- * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @cancellable: (nullable): a #GCancellable, or %NULL
  * @callback: (scope async): a #GAsyncReadyCallback
  * @user_data: (closure): user data for the callback
  *
@@ -1739,7 +1736,7 @@ g_socket_client_connect_to_host_async (GSocketClient        *client,
  * @client: a #GSocketClient
  * @domain: a domain name
  * @service: the name of the service to connect to
- * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @cancellable: (nullable): a #GCancellable, or %NULL
  * @callback: (scope async): a #GAsyncReadyCallback
  * @user_data: (closure): user data for the callback
  *
@@ -1770,7 +1767,7 @@ g_socket_client_connect_to_service_async (GSocketClient       *client,
  * @client: a #GSocketClient
  * @uri: a network uri
  * @default_port: the default port to connect to
- * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @cancellable: (nullable): a #GCancellable, or %NULL
  * @callback: (scope async): a #GAsyncReadyCallback
  * @user_data: (closure): user data for the callback
  *
@@ -1926,5 +1923,5 @@ void
 g_socket_client_add_application_proxy (GSocketClient *client,
                                       const gchar   *protocol)
 {
-  g_hash_table_insert (client->priv->app_proxies, g_strdup (protocol), NULL);
+  g_hash_table_add (client->priv->app_proxies, g_strdup (protocol));
 }