gnetworkservice.c 23.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

/* GIO - GLib Input, Output and Streaming Library
 *
 * Copyright (C) 2008 Red Hat, Inc.
 *
 * 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
10
 * version 2.1 of the License, or (at your option) any later version.
11 12 13 14 15 16 17
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
18
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 20 21 22 23 24 25
 */

#include "config.h"
#include <glib.h>
#include "glibintl.h"

#include "gnetworkservice.h"
26

27 28 29
#include "gcancellable.h"
#include "ginetaddress.h"
#include "ginetsocketaddress.h"
30 31
#include "gioerror.h"
#include "gnetworkaddress.h"
32
#include "gnetworkingprivate.h"
33
#include "gresolver.h"
34
#include "gtask.h"
35 36 37 38 39 40 41 42 43 44
#include "gsocketaddressenumerator.h"
#include "gsocketconnectable.h"
#include "gsrvtarget.h"

#include <stdlib.h>
#include <string.h>


/**
 * SECTION:gnetworkservice
Matthias Clasen's avatar
Matthias Clasen committed
45
 * @short_description: A GSocketConnectable for resolving SRV records
46 47 48 49 50 51 52 53 54
 * @include: gio/gio.h
 *
 * Like #GNetworkAddress does with hostnames, #GNetworkService
 * provides an easy way to resolve a SRV record, and then attempt to
 * connect to one of the hosts that implements that service, handling
 * service priority/weighting, multiple IP addresses, and multiple
 * address families.
 *
 * See #GSrvTarget for more information about SRV records, and see
55
 * #GSocketConnectable for an example of using the connectable
56
 * interface.
57
 */
58 59 60 61 62 63

/**
 * GNetworkService:
 *
 * A #GSocketConnectable for resolving a SRV record and connecting to
 * that service.
64
 */
65 66 67

struct _GNetworkServicePrivate
{
68
  gchar *service, *protocol, *domain, *scheme;
69 70 71 72 73 74 75 76
  GList *targets;
};

enum {
  PROP_0,
  PROP_SERVICE,
  PROP_PROTOCOL,
  PROP_DOMAIN,
77
  PROP_SCHEME
78 79 80 81 82 83 84 85 86 87 88
};

static void g_network_service_set_property (GObject      *object,
                                            guint         prop_id,
                                            const GValue *value,
                                            GParamSpec   *pspec);
static void g_network_service_get_property (GObject      *object,
                                            guint         prop_id,
                                            GValue       *value,
                                            GParamSpec   *pspec);

89 90 91
static void                      g_network_service_connectable_iface_init       (GSocketConnectableIface *iface);
static GSocketAddressEnumerator *g_network_service_connectable_enumerate        (GSocketConnectable      *connectable);
static GSocketAddressEnumerator *g_network_service_connectable_proxy_enumerate  (GSocketConnectable      *connectable);
92
static gchar                    *g_network_service_connectable_to_string        (GSocketConnectable      *connectable);
93 94

G_DEFINE_TYPE_WITH_CODE (GNetworkService, g_network_service, G_TYPE_OBJECT,
95
                         G_ADD_PRIVATE (GNetworkService)
96 97 98 99 100 101 102 103 104 105 106
                         G_IMPLEMENT_INTERFACE (G_TYPE_SOCKET_CONNECTABLE,
                                                g_network_service_connectable_iface_init))

static void
g_network_service_finalize (GObject *object)
{
  GNetworkService *srv = G_NETWORK_SERVICE (object);

  g_free (srv->priv->service);
  g_free (srv->priv->protocol);
  g_free (srv->priv->domain);
107
  g_free (srv->priv->scheme);
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

  if (srv->priv->targets)
    g_resolver_free_targets (srv->priv->targets);

  G_OBJECT_CLASS (g_network_service_parent_class)->finalize (object);
}

static void
g_network_service_class_init (GNetworkServiceClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  gobject_class->set_property = g_network_service_set_property;
  gobject_class->get_property = g_network_service_get_property;
  gobject_class->finalize = g_network_service_finalize;

  g_object_class_install_property (gobject_class, PROP_SERVICE,
                                   g_param_spec_string ("service",
                                                        P_("Service"),
                                                        P_("Service name, eg \"ldap\""),
                                                        NULL,
129 130 131
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY |
                                                        G_PARAM_STATIC_STRINGS));
132 133 134 135 136
  g_object_class_install_property (gobject_class, PROP_PROTOCOL,
                                   g_param_spec_string ("protocol",
                                                        P_("Protocol"),
                                                        P_("Network protocol, eg \"tcp\""),
                                                        NULL,
137 138 139
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY |
                                                        G_PARAM_STATIC_STRINGS));
140 141
  g_object_class_install_property (gobject_class, PROP_DOMAIN,
                                   g_param_spec_string ("domain",
142
                                                        P_("Domain"),
143 144
                                                        P_("Network domain, eg, \"example.com\""),
                                                        NULL,
145 146 147
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY |
                                                        G_PARAM_STATIC_STRINGS));
148 149 150 151 152 153 154 155
  g_object_class_install_property (gobject_class, PROP_DOMAIN,
                                   g_param_spec_string ("scheme",
                                                        P_("Scheme"),
                                                        P_("Network scheme (default is to use service)"),
                                                        NULL,
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_STATIC_STRINGS));

156 157 158 159 160 161
}

static void
g_network_service_connectable_iface_init (GSocketConnectableIface *connectable_iface)
{
  connectable_iface->enumerate = g_network_service_connectable_enumerate;
162
  connectable_iface->proxy_enumerate = g_network_service_connectable_proxy_enumerate;
163
  connectable_iface->to_string = g_network_service_connectable_to_string;
164 165 166 167 168
}

static void
g_network_service_init (GNetworkService *srv)
{
169
  srv->priv = g_network_service_get_instance_private (srv);
170 171 172 173 174 175 176 177 178 179
}

static void
g_network_service_set_property (GObject      *object,
                                guint         prop_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
  GNetworkService *srv = G_NETWORK_SERVICE (object);

180
  switch (prop_id)
181 182 183 184 185 186 187 188 189 190 191 192 193
    {
    case PROP_SERVICE:
      srv->priv->service = g_value_dup_string (value);
      break;

    case PROP_PROTOCOL:
      srv->priv->protocol = g_value_dup_string (value);
      break;

    case PROP_DOMAIN:
      srv->priv->domain = g_value_dup_string (value);
      break;

194 195 196 197
    case PROP_SCHEME:
      g_network_service_set_scheme (srv, g_value_get_string (value));
      break;

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
g_network_service_get_property (GObject    *object,
                                guint       prop_id,
                                GValue     *value,
                                GParamSpec *pspec)
{
  GNetworkService *srv = G_NETWORK_SERVICE (object);

  switch (prop_id)
213
    {
214 215 216 217 218 219 220 221 222 223 224 225
    case PROP_SERVICE:
      g_value_set_string (value, g_network_service_get_service (srv));
      break;

    case PROP_PROTOCOL:
      g_value_set_string (value, g_network_service_get_protocol (srv));
      break;

    case PROP_DOMAIN:
      g_value_set_string (value, g_network_service_get_domain (srv));
      break;

226 227 228 229
    case PROP_SCHEME:
      g_value_set_string (value, g_network_service_get_scheme (srv));
      break;

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

/**
 * g_network_service_new:
 * @service: the service type to look up (eg, "ldap")
 * @protocol: the networking protocol to use for @service (eg, "tcp")
 * @domain: the DNS domain to look up the service in
 *
 * Creates a new #GNetworkService representing the given @service,
 * @protocol, and @domain. This will initially be unresolved; use the
 * #GSocketConnectable interface to resolve it.
 *
246
 * Returns: (transfer full) (type GNetworkService): a new #GNetworkService
247 248
 *
 * Since: 2.22
249
 */
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
GSocketConnectable *
g_network_service_new (const gchar *service,
                       const gchar *protocol,
                       const gchar *domain)
{
  return g_object_new (G_TYPE_NETWORK_SERVICE,
                       "service", service,
                       "protocol", protocol,
                       "domain", domain,
                       NULL);
}

/**
 * g_network_service_get_service:
 * @srv: a #GNetworkService
 *
 * Gets @srv's service name (eg, "ldap").
 *
268
 * Returns: @srv's service name
269 270
 *
 * Since: 2.22
271
 */
272 273 274 275 276 277 278 279 280 281 282 283 284 285
const gchar *
g_network_service_get_service (GNetworkService *srv)
{
  g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);

  return srv->priv->service;
}

/**
 * g_network_service_get_protocol:
 * @srv: a #GNetworkService
 *
 * Gets @srv's protocol name (eg, "tcp").
 *
286
 * Returns: @srv's protocol name
287 288
 *
 * Since: 2.22
289
 */
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
const gchar *
g_network_service_get_protocol (GNetworkService *srv)
{
  g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);

  return srv->priv->protocol;
}

/**
 * g_network_service_get_domain:
 * @srv: a #GNetworkService
 *
 * Gets the domain that @srv serves. This might be either UTF-8 or
 * ASCII-encoded, depending on what @srv was created with.
 *
305
 * Returns: @srv's domain name
306 307
 *
 * Since: 2.22
308
 */
309 310 311 312 313 314 315 316
const gchar *
g_network_service_get_domain (GNetworkService *srv)
{
  g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);

  return srv->priv->domain;
}

317 318 319 320 321 322 323
/**
 * g_network_service_get_scheme:
 * @srv: a #GNetworkService
 *
 * Get's the URI scheme used to resolve proxies. By default, the service name
 * is used as scheme.
 *
324
 * Returns: @srv's scheme name
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
 *
 * Since: 2.26
 */
const gchar *
g_network_service_get_scheme (GNetworkService *srv)
{
  g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);

  if (srv->priv->scheme)
    return srv->priv->scheme;
  else
    return srv->priv->service;
}

/**
 * g_network_service_set_scheme:
 * @srv: a #GNetworkService
342
 * @scheme: a URI scheme
343 344 345 346 347 348 349
 *
 * Set's the URI scheme used to resolve proxies. By default, the service name
 * is used as scheme.
 *
 * Since: 2.26
 */
void
350 351
g_network_service_set_scheme (GNetworkService *srv,
                              const gchar     *scheme)
352 353 354
{
  g_return_if_fail (G_IS_NETWORK_SERVICE (srv));

355
  g_free (srv->priv->scheme);
356 357 358 359 360
  srv->priv->scheme = g_strdup (scheme);

  g_object_notify (G_OBJECT (srv), "scheme");
}

361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
static GList *
g_network_service_fallback_targets (GNetworkService *srv)
{
  GSrvTarget *target;
  struct servent *entry;
  guint16 port;

  entry = getservbyname (srv->priv->service, "tcp");
  port = entry ? g_ntohs (entry->s_port) : 0;
#ifdef HAVE_ENDSERVENT
  endservent ();
#endif

  if (entry == NULL)
      return NULL;

  target = g_srv_target_new (srv->priv->domain, port, 0, 0);
  return g_list_append (NULL, target);
}
380

381 382 383 384 385 386 387 388
#define G_TYPE_NETWORK_SERVICE_ADDRESS_ENUMERATOR (_g_network_service_address_enumerator_get_type ())
#define G_NETWORK_SERVICE_ADDRESS_ENUMERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_NETWORK_SERVICE_ADDRESS_ENUMERATOR, GNetworkServiceAddressEnumerator))

typedef struct {
  GSocketAddressEnumerator parent_instance;

  GResolver *resolver;
  GNetworkService *srv;
389 390 391
  GSocketAddressEnumerator *addr_enum;
  GList *t;
  gboolean use_proxy;
392 393 394 395 396 397 398 399 400 401

  GError *error;

} GNetworkServiceAddressEnumerator;

typedef struct {
  GSocketAddressEnumeratorClass parent_class;

} GNetworkServiceAddressEnumeratorClass;

Allison Karlitskaya's avatar
Allison Karlitskaya committed
402
static GType _g_network_service_address_enumerator_get_type (void);
403 404 405 406 407 408 409 410 411
G_DEFINE_TYPE (GNetworkServiceAddressEnumerator, _g_network_service_address_enumerator, G_TYPE_SOCKET_ADDRESS_ENUMERATOR)

static GSocketAddress *
g_network_service_address_enumerator_next (GSocketAddressEnumerator  *enumerator,
                                           GCancellable              *cancellable,
                                           GError                   **error)
{
  GNetworkServiceAddressEnumerator *srv_enum =
    G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (enumerator);
412
  GSocketAddress *ret = NULL;
413 414 415 416 417

  /* If we haven't yet resolved srv, do that */
  if (!srv_enum->srv->priv->targets)
    {
      GList *targets;
418
      GError *my_error = NULL;
419 420 421 422 423

      targets = g_resolver_lookup_service (srv_enum->resolver,
                                           srv_enum->srv->priv->service,
                                           srv_enum->srv->priv->protocol,
                                           srv_enum->srv->priv->domain,
424 425 426 427 428 429 430 431 432
                                           cancellable, &my_error);
      if (!targets && g_error_matches (my_error, G_RESOLVER_ERROR,
                                       G_RESOLVER_ERROR_NOT_FOUND))
        {
          targets = g_network_service_fallback_targets (srv_enum->srv);
          if (targets)
            g_clear_error (&my_error);
        }

433
      if (my_error)
434 435 436 437
        {
          g_propagate_error (error, my_error);
          return NULL;
        }
438

439
      srv_enum->srv->priv->targets = targets;
440 441 442
      srv_enum->t = srv_enum->srv->priv->targets;
    }

443
  /* Delegate to GNetworkAddress */
444 445
  do
    {
446
      if (srv_enum->addr_enum == NULL && srv_enum->t)
447
        {
448 449 450 451 452 453 454 455 456 457 458
          GError *error = NULL;
          gchar *uri;
          gchar *hostname;
          GSocketConnectable *addr;
          GSrvTarget *target = srv_enum->t->data;

          srv_enum->t = g_list_next (srv_enum->t);

          hostname = g_hostname_to_ascii (g_srv_target_get_hostname (target));

          if (hostname == NULL)
459
            {
460 461 462 463 464 465
              if (srv_enum->error == NULL)
                srv_enum->error =
                  g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
                               "Received invalid hostname '%s' from GSrvTarget",
                               g_srv_target_get_hostname (target));
              continue;
466 467
            }

468 469 470 471
          uri = _g_uri_from_authority (g_network_service_get_scheme (srv_enum->srv),
                                       hostname,
                                       g_srv_target_get_port (target),
                                       NULL);
472
          g_free (hostname);
473

474 475 476 477
          addr = g_network_address_parse_uri (uri,
                                              g_srv_target_get_port (target),
                                              &error);
          g_free (uri);
478

479
          if (addr == NULL)
480
            {
481 482
              if (srv_enum->error == NULL)
                srv_enum->error = error;
483 484
              else
                g_error_free (error);
485
              continue;
486
            }
487 488 489

          if (srv_enum->use_proxy)
            srv_enum->addr_enum = g_socket_connectable_proxy_enumerate (addr);
490
          else
491 492 493 494 495 496 497 498 499 500 501 502 503
            srv_enum->addr_enum = g_socket_connectable_enumerate (addr);
          g_object_unref (addr);
        }

      if (srv_enum->addr_enum)
        {
          GError *error = NULL;

          ret = g_socket_address_enumerator_next (srv_enum->addr_enum,
                                                  cancellable,
                                                  &error);

          if (error)
504
            {
505 506 507 508
              if (srv_enum->error == NULL)
                srv_enum->error = error;
              else
                g_error_free (error);
509
            }
510

511 512
          if (!ret)
            {
513 514
              g_object_unref (srv_enum->addr_enum);
              srv_enum->addr_enum = NULL;
515 516 517
            }
        }
    }
518
  while (srv_enum->addr_enum == NULL && srv_enum->t);
519

520
  if (ret == NULL && srv_enum->error)
521
    {
522 523
      g_propagate_error (error, srv_enum->error);
      srv_enum->error = NULL;
524 525
    }

526
  return ret;
527 528
}

529 530 531 532 533 534 535
static void next_async_resolved_targets   (GObject      *source_object,
                                           GAsyncResult *result,
                                           gpointer      user_data);
static void next_async_have_targets       (GTask        *srv_enum);
static void next_async_have_address       (GObject      *source_object,
                                           GAsyncResult *result,
                                           gpointer      user_data);
536 537 538 539 540 541 542 543 544

static void
g_network_service_address_enumerator_next_async (GSocketAddressEnumerator  *enumerator,
                                                 GCancellable              *cancellable,
                                                 GAsyncReadyCallback        callback,
                                                 gpointer                   user_data)
{
  GNetworkServiceAddressEnumerator *srv_enum =
    G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (enumerator);
545
  GTask *task;
546

547
  task = g_task_new (enumerator, cancellable, callback, user_data);
548
  g_task_set_source_tag (task, g_network_service_address_enumerator_next_async);
549 550 551 552 553 554 555 556 557 558

  /* If we haven't yet resolved srv, do that */
  if (!srv_enum->srv->priv->targets)
    {
      g_resolver_lookup_service_async (srv_enum->resolver,
                                       srv_enum->srv->priv->service,
                                       srv_enum->srv->priv->protocol,
                                       srv_enum->srv->priv->domain,
                                       cancellable,
                                       next_async_resolved_targets,
559
                                       task);
560 561
    }
  else
562
    next_async_have_targets (task);
563 564 565 566 567 568 569
}

static void
next_async_resolved_targets (GObject      *source_object,
                             GAsyncResult *result,
                             gpointer      user_data)
{
570 571
  GTask *task = user_data;
  GNetworkServiceAddressEnumerator *srv_enum = g_task_get_source_object (task);
572
  GError *error = NULL;
573
  GList *targets;
574

575 576 577 578 579 580 581 582 583 584
  targets = g_resolver_lookup_service_finish (srv_enum->resolver,
                                              result, &error);

  if (!targets && g_error_matches (error, G_RESOLVER_ERROR,
                                   G_RESOLVER_ERROR_NOT_FOUND))
    {
      targets = g_network_service_fallback_targets (srv_enum->srv);
      if (targets)
        g_clear_error (&error);
    }
585 586

  if (error)
587
    {
588 589
      g_task_return_error (task, error);
      g_object_unref (task);
590 591 592
    }
  else
    {
593
      srv_enum->t = srv_enum->srv->priv->targets = targets;
594
      next_async_have_targets (task);
595 596 597 598
    }
}

static void
599
next_async_have_targets (GTask *task)
600
{
601 602
  GNetworkServiceAddressEnumerator *srv_enum = g_task_get_source_object (task);

603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
  /* Delegate to GNetworkAddress */
  if (srv_enum->addr_enum == NULL && srv_enum->t)
    {
      GSocketConnectable *addr;
      GSrvTarget *target = srv_enum->t->data;

      srv_enum->t = g_list_next (srv_enum->t);
      addr = g_network_address_new (g_srv_target_get_hostname (target),
                                    (guint16) g_srv_target_get_port (target));

      if (srv_enum->use_proxy)
        srv_enum->addr_enum = g_socket_connectable_proxy_enumerate (addr);
      else
        srv_enum->addr_enum = g_socket_connectable_enumerate (addr);

      g_object_unref (addr);
    }
620

621
  if (srv_enum->addr_enum)
622
    {
623
      g_socket_address_enumerator_next_async (srv_enum->addr_enum,
624
                                              g_task_get_cancellable (task),
625
                                              next_async_have_address,
626
                                              task);
627 628 629
    }
  else
    {
630 631
      if (srv_enum->error)
        {
632
          g_task_return_error (task, srv_enum->error);
633 634
          srv_enum->error = NULL;
        }
635 636
      else
        g_task_return_pointer (task, NULL, NULL);
637

638
      g_object_unref (task);
639 640 641 642
    }
}

static void
643 644 645
next_async_have_address (GObject      *source_object,
                         GAsyncResult *result,
                         gpointer      user_data)
646
{
647 648
  GTask *task = user_data;
  GNetworkServiceAddressEnumerator *srv_enum = g_task_get_source_object (task);
649
  GSocketAddress *address;
650
  GError *error = NULL;
651 652 653 654
  
  address = g_socket_address_enumerator_next_finish (srv_enum->addr_enum,
                                                     result,
                                                     &error);
655

656
  if (error)
657
    {
658 659
      if (srv_enum->error == NULL)
        srv_enum->error = error;
660
      else
661
        g_error_free (error);
662
    }
663

664 665
  if (!address)
    {
666 667 668
      g_object_unref (srv_enum->addr_enum);
      srv_enum->addr_enum = NULL;

669
      next_async_have_targets (task);
670
    }
671 672
  else
    {
673 674
      g_task_return_pointer (task, address, g_object_unref);
      g_object_unref (task);
675 676 677 678 679 680 681 682
    }
}

static GSocketAddress *
g_network_service_address_enumerator_next_finish (GSocketAddressEnumerator  *enumerator,
                                                  GAsyncResult              *result,
                                                  GError                   **error)
{
683
  return g_task_propagate_pointer (G_TASK (result), error);
684 685 686 687 688 689 690 691
}

static void
_g_network_service_address_enumerator_init (GNetworkServiceAddressEnumerator *enumerator)
{
}

static void
692
g_network_service_address_enumerator_finalize (GObject *object)
693
{
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
  GNetworkServiceAddressEnumerator *srv_enum =
    G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (object);

  if (srv_enum->srv)
    g_object_unref (srv_enum->srv);

  if (srv_enum->addr_enum)
    g_object_unref (srv_enum->addr_enum);

  if (srv_enum->resolver)
    g_object_unref (srv_enum->resolver);

  if (srv_enum->error)
    g_error_free (srv_enum->error);

  G_OBJECT_CLASS (_g_network_service_address_enumerator_parent_class)->finalize (object);
}

static void
_g_network_service_address_enumerator_class_init (GNetworkServiceAddressEnumeratorClass *srvenum_class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (srvenum_class);
716
  GSocketAddressEnumeratorClass *enumerator_class =
717
    G_SOCKET_ADDRESS_ENUMERATOR_CLASS (srvenum_class);
718

719 720
  enumerator_class->next        = g_network_service_address_enumerator_next;
  enumerator_class->next_async  = g_network_service_address_enumerator_next_async;
721
  enumerator_class->next_finish = g_network_service_address_enumerator_next_finish;
722

723 724 725 726 727 728 729 730 731
  object_class->finalize = g_network_service_address_enumerator_finalize;
}

static GSocketAddressEnumerator *
g_network_service_connectable_enumerate (GSocketConnectable *connectable)
{
  GNetworkServiceAddressEnumerator *srv_enum;

  srv_enum = g_object_new (G_TYPE_NETWORK_SERVICE_ADDRESS_ENUMERATOR, NULL);
732
  srv_enum->srv = g_object_ref (G_NETWORK_SERVICE (connectable));
733
  srv_enum->resolver = g_resolver_get_default ();
734 735 736 737 738 739 740 741 742 743 744 745 746 747
  srv_enum->use_proxy = FALSE;

  return G_SOCKET_ADDRESS_ENUMERATOR (srv_enum);
}

static GSocketAddressEnumerator *
g_network_service_connectable_proxy_enumerate (GSocketConnectable *connectable)
{
  GSocketAddressEnumerator *addr_enum;
  GNetworkServiceAddressEnumerator *srv_enum;

  addr_enum = g_network_service_connectable_enumerate (connectable);
  srv_enum = G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (addr_enum);
  srv_enum->use_proxy = TRUE;
748

749
  return addr_enum;
750
}
751 752 753 754 755 756 757 758 759 760 761 762

static gchar *
g_network_service_connectable_to_string (GSocketConnectable *connectable)
{
  GNetworkService *service;

  service = G_NETWORK_SERVICE (connectable);

  return g_strdup_printf ("(%s, %s, %s, %s)", service->priv->service,
                          service->priv->protocol, service->priv->domain,
                          service->priv->scheme);
}