Imported Upstream version 2.72.3
[platform/upstream/glib.git] / gio / gsimpleproxyresolver.c
index 8610e2b..f19d567 100644 (file)
@@ -5,7 +5,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
@@ -50,7 +50,7 @@
 
 typedef struct {
   gchar        *name;
-  gint          length;
+  gsize          length;
   gushort       port;
 } GSimpleProxyResolverDomain;
 
@@ -259,7 +259,8 @@ ignore_host (GSimpleProxyResolver *resolver,
   GSimpleProxyResolverPrivate *priv = resolver->priv;
   gchar *ascii_host = NULL;
   gboolean ignore = FALSE;
-  gint i, length, offset;
+  gsize offset, length;
+  guint i;
 
   if (priv->ignore_ips)
     {
@@ -287,14 +288,19 @@ ignore_host (GSimpleProxyResolver *resolver,
 
   if (priv->ignore_domains)
     {
+      length = 0;
       if (g_hostname_is_non_ascii (host))
         host = ascii_host = g_hostname_to_ascii (host);
-      length = strlen (host);
+      if (host)
+        length = strlen (host);
 
-      for (i = 0; priv->ignore_domains[i].length; i++)
+      for (i = 0; length > 0 && priv->ignore_domains[i].length; i++)
        {
          GSimpleProxyResolverDomain *domain = &priv->ignore_domains[i];
 
+          if (domain->length > length)
+            continue;
+
          offset = length - domain->length;
          if ((domain->port == 0 || domain->port == port) &&
              (offset == 0 || (offset > 0 && host[offset - 1] == '.')) &&
@@ -325,10 +331,11 @@ g_simple_proxy_resolver_lookup (GProxyResolver  *proxy_resolver,
   if (priv->ignore_ips || priv->ignore_domains)
     {
       gchar *host = NULL;
-      gushort port;
+      gint port;
 
-      if (_g_uri_parse_authority (uri, &host, &port, NULL) &&
-          ignore_host (resolver, host, port))
+      if (g_uri_split_network (uri, G_URI_FLAGS_NONE, NULL,
+                               &host, &port, NULL) &&
+          ignore_host (resolver, host, port > 0 ? port : 0))
         proxy = "direct://";
 
       g_free (host);
@@ -377,6 +384,7 @@ g_simple_proxy_resolver_lookup_async (GProxyResolver      *proxy_resolver,
   char **proxies;
 
   task = g_task_new (resolver, cancellable, callback, user_data);
+  g_task_set_source_tag (task, g_simple_proxy_resolver_lookup_async);
 
   proxies = g_simple_proxy_resolver_lookup (proxy_resolver, uri,
                                             cancellable, &error);
@@ -483,9 +491,9 @@ g_simple_proxy_resolver_iface_init (GProxyResolverInterface *iface)
 
 /**
  * g_simple_proxy_resolver_new:
- * @default_proxy: (allow-none): the default proxy to use, eg
+ * @default_proxy: (nullable): the default proxy to use, eg
  *     "socks://192.168.1.1"
- * @ignore_hosts: (allow-none): an optional list of hosts/IP addresses
+ * @ignore_hosts: (array zero-terminated=1) (nullable): an optional list of hosts/IP addresses
  *     to not use a proxy for.
  *
  * Creates a new #GSimpleProxyResolver. See
@@ -536,7 +544,7 @@ g_simple_proxy_resolver_set_default_proxy (GSimpleProxyResolver *resolver,
 /**
  * g_simple_proxy_resolver_set_ignore_hosts:
  * @resolver: a #GSimpleProxyResolver
- * @ignore_hosts: %NULL-terminated list of hosts/IP addresses
+ * @ignore_hosts: (array zero-terminated=1): %NULL-terminated list of hosts/IP addresses
  *     to not use a proxy for
  *
  * Sets the list of ignored hosts.