Added UG translation
[platform/upstream/glib.git] / gio / gnetworkservice.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2
3 /* GIO - GLib Input, Output and Streaming Library
4  *
5  * Copyright (C) 2008 Red Hat, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General
18  * Public License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "config.h"
24 #include <glib.h>
25 #include "glibintl.h"
26
27 #include "gnetworkservice.h"
28
29 #include "gcancellable.h"
30 #include "ginetaddress.h"
31 #include "ginetsocketaddress.h"
32 #include "gioerror.h"
33 #include "gnetworkaddress.h"
34 #include "gnetworkingprivate.h"
35 #include "gresolver.h"
36 #include "gsimpleasyncresult.h"
37 #include "gsocketaddressenumerator.h"
38 #include "gsocketconnectable.h"
39 #include "gsrvtarget.h"
40
41 #include <stdlib.h>
42 #include <string.h>
43
44
45 /**
46  * SECTION:gnetworkservice
47  * @short_description: A GSocketConnectable for resolving SRV records
48  * @include: gio/gio.h
49  *
50  * Like #GNetworkAddress does with hostnames, #GNetworkService
51  * provides an easy way to resolve a SRV record, and then attempt to
52  * connect to one of the hosts that implements that service, handling
53  * service priority/weighting, multiple IP addresses, and multiple
54  * address families.
55  *
56  * See #GSrvTarget for more information about SRV records, and see
57  * #GSocketConnectable for and example of using the connectable
58  * interface.
59  */
60
61 /**
62  * GNetworkService:
63  *
64  * A #GSocketConnectable for resolving a SRV record and connecting to
65  * that service.
66  */
67
68 struct _GNetworkServicePrivate
69 {
70   gchar *service, *protocol, *domain, *scheme;
71   GList *targets;
72 };
73
74 enum {
75   PROP_0,
76   PROP_SERVICE,
77   PROP_PROTOCOL,
78   PROP_DOMAIN,
79   PROP_SCHEME
80 };
81
82 static void g_network_service_set_property (GObject      *object,
83                                             guint         prop_id,
84                                             const GValue *value,
85                                             GParamSpec   *pspec);
86 static void g_network_service_get_property (GObject      *object,
87                                             guint         prop_id,
88                                             GValue       *value,
89                                             GParamSpec   *pspec);
90
91 static void                      g_network_service_connectable_iface_init       (GSocketConnectableIface *iface);
92 static GSocketAddressEnumerator *g_network_service_connectable_enumerate        (GSocketConnectable      *connectable);
93 static GSocketAddressEnumerator *g_network_service_connectable_proxy_enumerate  (GSocketConnectable      *connectable);
94
95 G_DEFINE_TYPE_WITH_CODE (GNetworkService, g_network_service, G_TYPE_OBJECT,
96                          G_IMPLEMENT_INTERFACE (G_TYPE_SOCKET_CONNECTABLE,
97                                                 g_network_service_connectable_iface_init))
98
99 static void
100 g_network_service_finalize (GObject *object)
101 {
102   GNetworkService *srv = G_NETWORK_SERVICE (object);
103
104   g_free (srv->priv->service);
105   g_free (srv->priv->protocol);
106   g_free (srv->priv->domain);
107   g_free (srv->priv->scheme);
108
109   if (srv->priv->targets)
110     g_resolver_free_targets (srv->priv->targets);
111
112   G_OBJECT_CLASS (g_network_service_parent_class)->finalize (object);
113 }
114
115 static void
116 g_network_service_class_init (GNetworkServiceClass *klass)
117 {
118   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
119
120   g_type_class_add_private (klass, sizeof (GNetworkServicePrivate));
121
122   gobject_class->set_property = g_network_service_set_property;
123   gobject_class->get_property = g_network_service_get_property;
124   gobject_class->finalize = g_network_service_finalize;
125
126   g_object_class_install_property (gobject_class, PROP_SERVICE,
127                                    g_param_spec_string ("service",
128                                                         P_("Service"),
129                                                         P_("Service name, eg \"ldap\""),
130                                                         NULL,
131                                                         G_PARAM_READWRITE |
132                                                         G_PARAM_CONSTRUCT_ONLY |
133                                                         G_PARAM_STATIC_STRINGS));
134   g_object_class_install_property (gobject_class, PROP_PROTOCOL,
135                                    g_param_spec_string ("protocol",
136                                                         P_("Protocol"),
137                                                         P_("Network protocol, eg \"tcp\""),
138                                                         NULL,
139                                                         G_PARAM_READWRITE |
140                                                         G_PARAM_CONSTRUCT_ONLY |
141                                                         G_PARAM_STATIC_STRINGS));
142   g_object_class_install_property (gobject_class, PROP_DOMAIN,
143                                    g_param_spec_string ("domain",
144                                                         P_("Domain"),
145                                                         P_("Network domain, eg, \"example.com\""),
146                                                         NULL,
147                                                         G_PARAM_READWRITE |
148                                                         G_PARAM_CONSTRUCT_ONLY |
149                                                         G_PARAM_STATIC_STRINGS));
150   g_object_class_install_property (gobject_class, PROP_DOMAIN,
151                                    g_param_spec_string ("scheme",
152                                                         P_("Scheme"),
153                                                         P_("Network scheme (default is to use service)"),
154                                                         NULL,
155                                                         G_PARAM_READWRITE |
156                                                         G_PARAM_STATIC_STRINGS));
157
158 }
159
160 static void
161 g_network_service_connectable_iface_init (GSocketConnectableIface *connectable_iface)
162 {
163   connectable_iface->enumerate = g_network_service_connectable_enumerate;
164   connectable_iface->proxy_enumerate = g_network_service_connectable_proxy_enumerate;
165 }
166
167 static void
168 g_network_service_init (GNetworkService *srv)
169 {
170   srv->priv = G_TYPE_INSTANCE_GET_PRIVATE (srv, G_TYPE_NETWORK_SERVICE,
171                                            GNetworkServicePrivate);
172 }
173
174 static void
175 g_network_service_set_property (GObject      *object,
176                                 guint         prop_id,
177                                 const GValue *value,
178                                 GParamSpec   *pspec)
179 {
180   GNetworkService *srv = G_NETWORK_SERVICE (object);
181
182   switch (prop_id)
183     {
184     case PROP_SERVICE:
185       srv->priv->service = g_value_dup_string (value);
186       break;
187
188     case PROP_PROTOCOL:
189       srv->priv->protocol = g_value_dup_string (value);
190       break;
191
192     case PROP_DOMAIN:
193       srv->priv->domain = g_value_dup_string (value);
194       break;
195
196     case PROP_SCHEME:
197       g_network_service_set_scheme (srv, g_value_get_string (value));
198       break;
199
200     default:
201       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
202       break;
203     }
204 }
205
206 static void
207 g_network_service_get_property (GObject    *object,
208                                 guint       prop_id,
209                                 GValue     *value,
210                                 GParamSpec *pspec)
211 {
212   GNetworkService *srv = G_NETWORK_SERVICE (object);
213
214   switch (prop_id)
215     {
216     case PROP_SERVICE:
217       g_value_set_string (value, g_network_service_get_service (srv));
218       break;
219
220     case PROP_PROTOCOL:
221       g_value_set_string (value, g_network_service_get_protocol (srv));
222       break;
223
224     case PROP_DOMAIN:
225       g_value_set_string (value, g_network_service_get_domain (srv));
226       break;
227
228     case PROP_SCHEME:
229       g_value_set_string (value, g_network_service_get_scheme (srv));
230       break;
231
232     default:
233       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234       break;
235     }
236 }
237
238 /**
239  * g_network_service_new:
240  * @service: the service type to look up (eg, "ldap")
241  * @protocol: the networking protocol to use for @service (eg, "tcp")
242  * @domain: the DNS domain to look up the service in
243  *
244  * Creates a new #GNetworkService representing the given @service,
245  * @protocol, and @domain. This will initially be unresolved; use the
246  * #GSocketConnectable interface to resolve it.
247  *
248  * Return value: (transfer full): a new #GNetworkService
249  *
250  * Since: 2.22
251  */
252 GSocketConnectable *
253 g_network_service_new (const gchar *service,
254                        const gchar *protocol,
255                        const gchar *domain)
256 {
257   return g_object_new (G_TYPE_NETWORK_SERVICE,
258                        "service", service,
259                        "protocol", protocol,
260                        "domain", domain,
261                        NULL);
262 }
263
264 /**
265  * g_network_service_get_service:
266  * @srv: a #GNetworkService
267  *
268  * Gets @srv's service name (eg, "ldap").
269  *
270  * Return value: @srv's service name
271  *
272  * Since: 2.22
273  */
274 const gchar *
275 g_network_service_get_service (GNetworkService *srv)
276 {
277   g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);
278
279   return srv->priv->service;
280 }
281
282 /**
283  * g_network_service_get_protocol:
284  * @srv: a #GNetworkService
285  *
286  * Gets @srv's protocol name (eg, "tcp").
287  *
288  * Return value: @srv's protocol name
289  *
290  * Since: 2.22
291  */
292 const gchar *
293 g_network_service_get_protocol (GNetworkService *srv)
294 {
295   g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);
296
297   return srv->priv->protocol;
298 }
299
300 /**
301  * g_network_service_get_domain:
302  * @srv: a #GNetworkService
303  *
304  * Gets the domain that @srv serves. This might be either UTF-8 or
305  * ASCII-encoded, depending on what @srv was created with.
306  *
307  * Return value: @srv's domain name
308  *
309  * Since: 2.22
310  */
311 const gchar *
312 g_network_service_get_domain (GNetworkService *srv)
313 {
314   g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);
315
316   return srv->priv->domain;
317 }
318
319 /**
320  * g_network_service_get_scheme:
321  * @srv: a #GNetworkService
322  *
323  * Get's the URI scheme used to resolve proxies. By default, the service name
324  * is used as scheme.
325  *
326  * Return value: @srv's scheme name
327  *
328  * Since: 2.26
329  */
330 const gchar *
331 g_network_service_get_scheme (GNetworkService *srv)
332 {
333   g_return_val_if_fail (G_IS_NETWORK_SERVICE (srv), NULL);
334
335   if (srv->priv->scheme)
336     return srv->priv->scheme;
337   else
338     return srv->priv->service;
339 }
340
341 /**
342  * g_network_service_set_scheme:
343  * @srv: a #GNetworkService
344  * @scheme: a URI scheme
345  *
346  * Set's the URI scheme used to resolve proxies. By default, the service name
347  * is used as scheme.
348  *
349  * Since: 2.26
350  */
351 void
352 g_network_service_set_scheme (GNetworkService *srv,
353                               const gchar     *scheme)
354 {
355   g_return_if_fail (G_IS_NETWORK_SERVICE (srv));
356
357   if (srv->priv->scheme)
358     g_free (srv->priv->scheme);
359   srv->priv->scheme = g_strdup (scheme);
360
361   g_object_notify (G_OBJECT (srv), "scheme");
362 }
363
364 static GList *
365 g_network_service_fallback_targets (GNetworkService *srv)
366 {
367   GSrvTarget *target;
368   struct servent *entry;
369   guint16 port;
370
371   entry = getservbyname (srv->priv->service, "tcp");
372   port = entry ? g_ntohs (entry->s_port) : 0;
373 #ifdef HAVE_ENDSERVENT
374   endservent ();
375 #endif
376
377   if (entry == NULL)
378       return NULL;
379
380   target = g_srv_target_new (srv->priv->domain, port, 0, 0);
381   return g_list_append (NULL, target);
382 }
383
384 #define G_TYPE_NETWORK_SERVICE_ADDRESS_ENUMERATOR (_g_network_service_address_enumerator_get_type ())
385 #define G_NETWORK_SERVICE_ADDRESS_ENUMERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_NETWORK_SERVICE_ADDRESS_ENUMERATOR, GNetworkServiceAddressEnumerator))
386
387 typedef struct {
388   GSocketAddressEnumerator parent_instance;
389
390   GResolver *resolver;
391   GNetworkService *srv;
392   GSocketAddressEnumerator *addr_enum;
393   GList *t;
394   gboolean use_proxy;
395
396   GError *error;
397
398   /* For async operation */
399   GCancellable *cancellable;
400   GSimpleAsyncResult *result;
401 } GNetworkServiceAddressEnumerator;
402
403 typedef struct {
404   GSocketAddressEnumeratorClass parent_class;
405
406 } GNetworkServiceAddressEnumeratorClass;
407
408 G_DEFINE_TYPE (GNetworkServiceAddressEnumerator, _g_network_service_address_enumerator, G_TYPE_SOCKET_ADDRESS_ENUMERATOR)
409
410 static GSocketAddress *
411 g_network_service_address_enumerator_next (GSocketAddressEnumerator  *enumerator,
412                                            GCancellable              *cancellable,
413                                            GError                   **error)
414 {
415   GNetworkServiceAddressEnumerator *srv_enum =
416     G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (enumerator);
417   GSocketAddress *ret = NULL;
418
419   /* If we haven't yet resolved srv, do that */
420   if (!srv_enum->srv->priv->targets)
421     {
422       GList *targets;
423       GError *my_error = NULL;
424
425       targets = g_resolver_lookup_service (srv_enum->resolver,
426                                            srv_enum->srv->priv->service,
427                                            srv_enum->srv->priv->protocol,
428                                            srv_enum->srv->priv->domain,
429                                            cancellable, &my_error);
430       if (!targets && g_error_matches (my_error, G_RESOLVER_ERROR,
431                                        G_RESOLVER_ERROR_NOT_FOUND))
432         {
433           targets = g_network_service_fallback_targets (srv_enum->srv);
434           if (targets)
435             g_clear_error (&my_error);
436         }
437
438       if (my_error)
439         {
440           g_propagate_error (error, my_error);
441           return NULL;
442         }
443
444       srv_enum->srv->priv->targets = targets;
445       srv_enum->t = srv_enum->srv->priv->targets;
446     }
447
448   /* Delegate to GNetworkAddress */
449   do
450     {
451       if (srv_enum->addr_enum == NULL && srv_enum->t)
452         {
453           GError *error = NULL;
454           gchar *uri;
455           gchar *hostname;
456           GSocketConnectable *addr;
457           GSrvTarget *target = srv_enum->t->data;
458
459           srv_enum->t = g_list_next (srv_enum->t);
460
461           hostname = g_hostname_to_ascii (g_srv_target_get_hostname (target));
462
463           if (hostname == NULL)
464             {
465               if (srv_enum->error == NULL)
466                 srv_enum->error =
467                   g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
468                                "Received invalid hostname '%s' from GSrvTarget",
469                                g_srv_target_get_hostname (target));
470               continue;
471             }
472
473           uri = _g_uri_from_authority (g_network_service_get_scheme (srv_enum->srv),
474                                        hostname,
475                                        g_srv_target_get_port (target),
476                                        NULL);
477           g_free (hostname);
478
479           addr = g_network_address_parse_uri (uri,
480                                               g_srv_target_get_port (target),
481                                               &error);
482           g_free (uri);
483
484           if (addr == NULL)
485             {
486               if (srv_enum->error == NULL)
487                 srv_enum->error = error;
488               continue;
489             }
490
491           if (srv_enum->use_proxy)
492             srv_enum->addr_enum = g_socket_connectable_proxy_enumerate (addr);
493           else
494             srv_enum->addr_enum = g_socket_connectable_enumerate (addr);
495           g_object_unref (addr);
496         }
497
498       if (srv_enum->addr_enum)
499         {
500           GError *error = NULL;
501
502           ret = g_socket_address_enumerator_next (srv_enum->addr_enum,
503                                                   cancellable,
504                                                   &error);
505
506           if (error)
507             {
508               if (srv_enum->error == NULL)
509                 srv_enum->error = error;
510               else
511                 g_error_free (error);
512             }
513
514           if (!ret)
515             {
516               g_object_unref (srv_enum->addr_enum);
517               srv_enum->addr_enum = NULL;
518             }
519         }
520     }
521   while (srv_enum->addr_enum == NULL && srv_enum->t);
522
523   if (ret == NULL && srv_enum->error)
524     {
525       g_propagate_error (error, srv_enum->error);
526       srv_enum->error = NULL;
527     }
528
529   return ret;
530 }
531
532 static void next_async_resolved_targets   (GObject                          *source_object,
533                                            GAsyncResult                     *result,
534                                            gpointer                          user_data);
535 static void next_async_have_targets       (GNetworkServiceAddressEnumerator *srv_enum);
536 static void next_async_have_address       (GObject                          *source_object,
537                                            GAsyncResult                     *result,
538                                            gpointer                          user_data);
539
540 static void
541 g_network_service_address_enumerator_next_async (GSocketAddressEnumerator  *enumerator,
542                                                  GCancellable              *cancellable,
543                                                  GAsyncReadyCallback        callback,
544                                                  gpointer                   user_data)
545 {
546   GNetworkServiceAddressEnumerator *srv_enum =
547     G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (enumerator);
548
549   g_return_if_fail (srv_enum->result == NULL);
550
551   srv_enum->result = g_simple_async_result_new (G_OBJECT (enumerator),
552                                                 callback, user_data,
553                                                 g_network_service_address_enumerator_next_async);
554
555   if (cancellable)
556     srv_enum->cancellable = g_object_ref (cancellable);
557
558   /* If we haven't yet resolved srv, do that */
559   if (!srv_enum->srv->priv->targets)
560     {
561       g_resolver_lookup_service_async (srv_enum->resolver,
562                                        srv_enum->srv->priv->service,
563                                        srv_enum->srv->priv->protocol,
564                                        srv_enum->srv->priv->domain,
565                                        cancellable,
566                                        next_async_resolved_targets,
567                                        srv_enum);
568     }
569   else
570     next_async_have_targets (srv_enum);
571 }
572
573 static void
574 next_async_resolved_targets (GObject      *source_object,
575                              GAsyncResult *result,
576                              gpointer      user_data)
577 {
578   GNetworkServiceAddressEnumerator *srv_enum = user_data;
579   GError *error = NULL;
580   GList *targets;
581
582   targets = g_resolver_lookup_service_finish (srv_enum->resolver,
583                                               result, &error);
584
585   if (!targets && g_error_matches (error, G_RESOLVER_ERROR,
586                                    G_RESOLVER_ERROR_NOT_FOUND))
587     {
588       targets = g_network_service_fallback_targets (srv_enum->srv);
589       if (targets)
590         g_clear_error (&error);
591     }
592
593   if (error)
594     {
595       GSimpleAsyncResult *simple = srv_enum->result;
596
597       srv_enum->result = NULL;
598       g_simple_async_result_take_error (simple, error);
599       g_simple_async_result_complete (simple);
600       g_object_unref (simple);
601     }
602   else
603     {
604       srv_enum->t = srv_enum->srv->priv->targets = targets;
605       next_async_have_targets (srv_enum);
606     }
607 }
608
609 static void
610 next_async_have_targets (GNetworkServiceAddressEnumerator *srv_enum)
611 {
612   /* Delegate to GNetworkAddress */
613   if (srv_enum->addr_enum == NULL && srv_enum->t)
614     {
615       GSocketConnectable *addr;
616       GSrvTarget *target = srv_enum->t->data;
617
618       srv_enum->t = g_list_next (srv_enum->t);
619       addr = g_network_address_new (g_srv_target_get_hostname (target),
620                                     (guint16) g_srv_target_get_port (target));
621
622       if (srv_enum->use_proxy)
623         srv_enum->addr_enum = g_socket_connectable_proxy_enumerate (addr);
624       else
625         srv_enum->addr_enum = g_socket_connectable_enumerate (addr);
626
627       g_object_unref (addr);
628     }
629
630   if (srv_enum->addr_enum)
631     {
632       g_socket_address_enumerator_next_async (srv_enum->addr_enum,
633                                               srv_enum->cancellable,
634                                               next_async_have_address,
635                                               srv_enum);
636     }
637   else
638     {
639       GSimpleAsyncResult *simple = srv_enum->result;
640       srv_enum->result = NULL;
641
642       if (srv_enum->error)
643         {
644           g_simple_async_result_take_error (simple, srv_enum->error);
645           srv_enum->error = NULL;
646         }
647
648       g_simple_async_result_complete (simple);
649       g_object_unref (simple);
650     }
651 }
652
653 static void
654 next_async_have_address (GObject      *source_object,
655                          GAsyncResult *result,
656                          gpointer      user_data)
657 {
658   GNetworkServiceAddressEnumerator *srv_enum = user_data;
659   GSocketAddress *address;
660   GError *error = NULL;
661   
662   address = g_socket_address_enumerator_next_finish (srv_enum->addr_enum,
663                                                      result,
664                                                      &error);
665
666   if (error)
667     {
668       if (srv_enum->error == NULL)
669         srv_enum->error = error;
670       else
671         g_error_free (error);
672     }
673
674   if (!address)
675     {
676       g_object_unref (srv_enum->addr_enum);
677       srv_enum->addr_enum = NULL;
678
679       next_async_have_targets (srv_enum);
680     }
681   else
682     {
683       GSimpleAsyncResult *simple = srv_enum->result;
684
685       srv_enum->result = NULL;
686
687       if (address)
688         g_simple_async_result_set_op_res_gpointer (simple,
689                                                    address, g_object_unref);
690
691       g_simple_async_result_complete (simple);
692       g_object_unref (simple);
693     }
694 }
695
696 static GSocketAddress *
697 g_network_service_address_enumerator_next_finish (GSocketAddressEnumerator  *enumerator,
698                                                   GAsyncResult              *result,
699                                                   GError                   **error)
700 {
701   GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
702   GSocketAddress *sockaddr;
703
704   if (g_simple_async_result_propagate_error (simple, error))
705     return NULL;
706
707   sockaddr = g_simple_async_result_get_op_res_gpointer (simple);
708   return sockaddr ? g_object_ref (sockaddr) : NULL;
709 }
710
711 static void
712 _g_network_service_address_enumerator_init (GNetworkServiceAddressEnumerator *enumerator)
713 {
714 }
715
716 static void
717 g_network_service_address_enumerator_finalize (GObject *object)
718 {
719   GNetworkServiceAddressEnumerator *srv_enum =
720     G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (object);
721
722   if (srv_enum->srv)
723     g_object_unref (srv_enum->srv);
724
725   if (srv_enum->addr_enum)
726     g_object_unref (srv_enum->addr_enum);
727
728   if (srv_enum->resolver)
729     g_object_unref (srv_enum->resolver);
730
731   if (srv_enum->result)
732     g_object_unref (srv_enum->result);
733
734   if (srv_enum->cancellable)
735     g_object_unref (srv_enum->cancellable);
736
737   if (srv_enum->error)
738     g_error_free (srv_enum->error);
739
740   G_OBJECT_CLASS (_g_network_service_address_enumerator_parent_class)->finalize (object);
741 }
742
743 static void
744 _g_network_service_address_enumerator_class_init (GNetworkServiceAddressEnumeratorClass *srvenum_class)
745 {
746   GObjectClass *object_class = G_OBJECT_CLASS (srvenum_class);
747   GSocketAddressEnumeratorClass *enumerator_class =
748     G_SOCKET_ADDRESS_ENUMERATOR_CLASS (srvenum_class);
749
750   enumerator_class->next        = g_network_service_address_enumerator_next;
751   enumerator_class->next_async  = g_network_service_address_enumerator_next_async;
752   enumerator_class->next_finish = g_network_service_address_enumerator_next_finish;
753
754   object_class->finalize = g_network_service_address_enumerator_finalize;
755 }
756
757 static GSocketAddressEnumerator *
758 g_network_service_connectable_enumerate (GSocketConnectable *connectable)
759 {
760   GNetworkServiceAddressEnumerator *srv_enum;
761
762   srv_enum = g_object_new (G_TYPE_NETWORK_SERVICE_ADDRESS_ENUMERATOR, NULL);
763   srv_enum->srv = g_object_ref (connectable);
764   srv_enum->resolver = g_resolver_get_default ();
765   srv_enum->use_proxy = FALSE;
766
767   return G_SOCKET_ADDRESS_ENUMERATOR (srv_enum);
768 }
769
770 static GSocketAddressEnumerator *
771 g_network_service_connectable_proxy_enumerate (GSocketConnectable *connectable)
772 {
773   GSocketAddressEnumerator *addr_enum;
774   GNetworkServiceAddressEnumerator *srv_enum;
775
776   addr_enum = g_network_service_connectable_enumerate (connectable);
777   srv_enum = G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (addr_enum);
778   srv_enum->use_proxy = TRUE;
779
780   return addr_enum;
781 }