1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: David Zeuthen <davidz@redhat.com>
29 #include "gdbusaddress.h"
30 #include "gdbusutils.h"
31 #include "gdbusconnection.h"
32 #include "gdbusserver.h"
33 #include "gioenumtypes.h"
34 #include "gdbusprivate.h"
35 #include "gdbusauthobserver.h"
36 #include "ginitable.h"
37 #include "gsocketservice.h"
38 #include "gthreadedsocketservice.h"
39 #include "gresolver.h"
40 #include "glib/gstdio.h"
41 #include "ginetaddress.h"
42 #include "ginetsocketaddress.h"
43 #include "ginputstream.h"
44 #include "giostream.h"
45 #include "gmarshal-internal.h"
55 #include "gunixsocketaddress.h"
62 * @short_description: Helper for accepting connections
65 * #GDBusServer is a helper for listening to and accepting D-Bus
66 * connections. This can be used to create a new D-Bus server, allowing two
67 * peers to use the D-Bus protocol for their own specialized communication.
68 * A server instance provided in this way will not perform message routing or
69 * implement the org.freedesktop.DBus interface.
71 * To just export an object on a well-known name on a message bus, such as the
72 * session or system bus, you should instead use g_bus_own_name().
74 * An example of peer-to-peer communication with G-DBus can be found
75 * in [gdbus-example-peer.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-peer.c).
77 * Note that a minimal #GDBusServer will accept connections from any
78 * peer. In many use-cases it will be necessary to add a #GDBusAuthObserver
79 * that only accepts connections that have successfully authenticated
80 * as the same user that is running the #GDBusServer.
86 * The #GDBusServer structure contains only private data and
87 * should only be accessed using the provided API.
94 GObject parent_instance;
96 GDBusServerFlags flags;
103 gchar *client_address;
105 gchar *unix_socket_path;
106 GSocketListener *listener;
107 gboolean is_using_listener;
108 gulong run_signal_handler_id;
110 /* The result of g_main_context_ref_thread_default() when the object
111 * was created (the GObject _init() function) - this is used for delivery
112 * of the :new-connection GObject signal.
114 GMainContext *main_context_at_construction;
118 GDBusAuthObserver *authentication_observer;
121 typedef struct _GDBusServerClass GDBusServerClass;
125 * @new_connection: Signal class handler for the #GDBusServer::new-connection signal.
127 * Class structure for #GDBusServer.
131 struct _GDBusServerClass
134 GObjectClass parent_class;
138 gboolean (*new_connection) (GDBusServer *server,
139 GDBusConnection *connection);
150 PROP_AUTHENTICATION_OBSERVER,
155 NEW_CONNECTION_SIGNAL,
159 static guint _signals[LAST_SIGNAL] = {0};
161 static void initable_iface_init (GInitableIface *initable_iface);
163 G_DEFINE_TYPE_WITH_CODE (GDBusServer, g_dbus_server, G_TYPE_OBJECT,
164 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init))
167 g_dbus_server_dispose (GObject *object)
169 GDBusServer *server = G_DBUS_SERVER (object);
172 g_dbus_server_stop (server);
174 G_OBJECT_CLASS (g_dbus_server_parent_class)->dispose (object);
178 g_dbus_server_finalize (GObject *object)
180 GDBusServer *server = G_DBUS_SERVER (object);
182 g_assert (!server->active);
184 if (server->authentication_observer != NULL)
185 g_object_unref (server->authentication_observer);
187 if (server->run_signal_handler_id > 0)
188 g_signal_handler_disconnect (server->listener, server->run_signal_handler_id);
190 if (server->listener != NULL)
191 g_object_unref (server->listener);
193 g_free (server->address);
194 g_free (server->guid);
195 g_free (server->client_address);
196 if (server->nonce != NULL)
198 memset (server->nonce, '\0', 16);
199 g_free (server->nonce);
202 g_free (server->unix_socket_path);
203 g_free (server->nonce_file);
205 g_main_context_unref (server->main_context_at_construction);
207 G_OBJECT_CLASS (g_dbus_server_parent_class)->finalize (object);
211 g_dbus_server_get_property (GObject *object,
216 GDBusServer *server = G_DBUS_SERVER (object);
221 g_value_set_flags (value, server->flags);
225 g_value_set_string (value, server->guid);
229 g_value_set_string (value, server->address);
232 case PROP_CLIENT_ADDRESS:
233 g_value_set_string (value, server->client_address);
237 g_value_set_boolean (value, server->active);
240 case PROP_AUTHENTICATION_OBSERVER:
241 g_value_set_object (value, server->authentication_observer);
245 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
251 g_dbus_server_set_property (GObject *object,
256 GDBusServer *server = G_DBUS_SERVER (object);
261 server->flags = g_value_get_flags (value);
265 server->guid = g_value_dup_string (value);
269 server->address = g_value_dup_string (value);
272 case PROP_AUTHENTICATION_OBSERVER:
273 server->authentication_observer = g_value_dup_object (value);
277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
283 g_dbus_server_class_init (GDBusServerClass *klass)
285 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
287 gobject_class->dispose = g_dbus_server_dispose;
288 gobject_class->finalize = g_dbus_server_finalize;
289 gobject_class->set_property = g_dbus_server_set_property;
290 gobject_class->get_property = g_dbus_server_get_property;
295 * Flags from the #GDBusServerFlags enumeration.
299 g_object_class_install_property (gobject_class,
301 g_param_spec_flags ("flags",
303 P_("Flags for the server"),
304 G_TYPE_DBUS_SERVER_FLAGS,
305 G_DBUS_SERVER_FLAGS_NONE,
308 G_PARAM_CONSTRUCT_ONLY |
309 G_PARAM_STATIC_NAME |
310 G_PARAM_STATIC_BLURB |
311 G_PARAM_STATIC_NICK));
316 * The guid of the server.
320 g_object_class_install_property (gobject_class,
322 g_param_spec_string ("guid",
324 P_("The guid of the server"),
328 G_PARAM_CONSTRUCT_ONLY |
329 G_PARAM_STATIC_NAME |
330 G_PARAM_STATIC_BLURB |
331 G_PARAM_STATIC_NICK));
334 * GDBusServer:address:
336 * The D-Bus address to listen on.
340 g_object_class_install_property (gobject_class,
342 g_param_spec_string ("address",
344 P_("The address to listen on"),
348 G_PARAM_CONSTRUCT_ONLY |
349 G_PARAM_STATIC_NAME |
350 G_PARAM_STATIC_BLURB |
351 G_PARAM_STATIC_NICK));
354 * GDBusServer:client-address:
356 * The D-Bus address that clients can use.
360 g_object_class_install_property (gobject_class,
362 g_param_spec_string ("client-address",
363 P_("Client Address"),
364 P_("The address clients can use"),
367 G_PARAM_STATIC_NAME |
368 G_PARAM_STATIC_BLURB |
369 G_PARAM_STATIC_NICK));
372 * GDBusServer:active:
374 * Whether the server is currently active.
378 g_object_class_install_property (gobject_class,
380 g_param_spec_boolean ("active",
382 P_("Whether the server is currently active"),
385 G_PARAM_STATIC_NAME |
386 G_PARAM_STATIC_BLURB |
387 G_PARAM_STATIC_NICK));
390 * GDBusServer:authentication-observer:
392 * A #GDBusAuthObserver object to assist in the authentication process or %NULL.
396 g_object_class_install_property (gobject_class,
397 PROP_AUTHENTICATION_OBSERVER,
398 g_param_spec_object ("authentication-observer",
399 P_("Authentication Observer"),
400 P_("Object used to assist in the authentication process"),
401 G_TYPE_DBUS_AUTH_OBSERVER,
404 G_PARAM_CONSTRUCT_ONLY |
405 G_PARAM_STATIC_NAME |
406 G_PARAM_STATIC_BLURB |
407 G_PARAM_STATIC_NICK));
410 * GDBusServer::new-connection:
411 * @server: The #GDBusServer emitting the signal.
412 * @connection: A #GDBusConnection for the new connection.
414 * Emitted when a new authenticated connection has been made. Use
415 * g_dbus_connection_get_peer_credentials() to figure out what
416 * identity (if any), was authenticated.
418 * If you want to accept the connection, take a reference to the
419 * @connection object and return %TRUE. When you are done with the
420 * connection call g_dbus_connection_close() and give up your
421 * reference. Note that the other peer may disconnect at any time -
422 * a typical thing to do when accepting a connection is to listen to
423 * the #GDBusConnection::closed signal.
425 * If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD
426 * then the signal is emitted in a new thread dedicated to the
427 * connection. Otherwise the signal is emitted in the
428 * [thread-default main context][g-main-context-push-thread-default]
429 * of the thread that @server was constructed in.
431 * You are guaranteed that signal handlers for this signal runs
432 * before incoming messages on @connection are processed. This means
433 * that it's suitable to call g_dbus_connection_register_object() or
434 * similar from the signal handler.
436 * Returns: %TRUE to claim @connection, %FALSE to let other handlers
441 _signals[NEW_CONNECTION_SIGNAL] = g_signal_new (I_("new-connection"),
444 G_STRUCT_OFFSET (GDBusServerClass, new_connection),
445 g_signal_accumulator_true_handled,
446 NULL, /* accu_data */
447 _g_cclosure_marshal_BOOLEAN__OBJECT,
450 G_TYPE_DBUS_CONNECTION);
451 g_signal_set_va_marshaller (_signals[NEW_CONNECTION_SIGNAL],
452 G_TYPE_FROM_CLASS (klass),
453 _g_cclosure_marshal_BOOLEAN__OBJECTv);
457 g_dbus_server_init (GDBusServer *server)
459 server->main_context_at_construction = g_main_context_ref_thread_default ();
463 on_run (GSocketService *service,
464 GSocketConnection *socket_connection,
465 GObject *source_object,
469 * g_dbus_server_new_sync:
470 * @address: A D-Bus address.
471 * @flags: Flags from the #GDBusServerFlags enumeration.
472 * @guid: A D-Bus GUID.
473 * @observer: (nullable): A #GDBusAuthObserver or %NULL.
474 * @cancellable: (nullable): A #GCancellable or %NULL.
475 * @error: Return location for server or %NULL.
477 * Creates a new D-Bus server that listens on the first address in
478 * @address that works.
480 * Once constructed, you can use g_dbus_server_get_client_address() to
481 * get a D-Bus address string that clients can use to connect.
483 * To have control over the available authentication mechanisms and
484 * the users that are authorized to connect, it is strongly recommended
485 * to provide a non-%NULL #GDBusAuthObserver.
487 * Connect to the #GDBusServer::new-connection signal to handle
488 * incoming connections.
490 * The returned #GDBusServer isn't active - you have to start it with
491 * g_dbus_server_start().
493 * #GDBusServer is used in this [example][gdbus-peer-to-peer].
495 * This is a synchronous failable constructor. There is currently no
496 * asynchronous version.
498 * Returns: A #GDBusServer or %NULL if @error is set. Free with
504 g_dbus_server_new_sync (const gchar *address,
505 GDBusServerFlags flags,
507 GDBusAuthObserver *observer,
508 GCancellable *cancellable,
513 g_return_val_if_fail (address != NULL, NULL);
514 g_return_val_if_fail (g_dbus_is_guid (guid), NULL);
515 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
517 server = g_initable_new (G_TYPE_DBUS_SERVER,
523 "authentication-observer", observer,
530 * g_dbus_server_get_client_address:
531 * @server: A #GDBusServer.
534 * [D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses)
535 * string that can be used by clients to connect to @server.
537 * Returns: A D-Bus address string. Do not free, the string is owned
543 g_dbus_server_get_client_address (GDBusServer *server)
545 g_return_val_if_fail (G_IS_DBUS_SERVER (server), NULL);
546 return server->client_address;
550 * g_dbus_server_get_guid:
551 * @server: A #GDBusServer.
553 * Gets the GUID for @server.
555 * Returns: A D-Bus GUID. Do not free this string, it is owned by @server.
560 g_dbus_server_get_guid (GDBusServer *server)
562 g_return_val_if_fail (G_IS_DBUS_SERVER (server), NULL);
567 * g_dbus_server_get_flags:
568 * @server: A #GDBusServer.
570 * Gets the flags for @server.
572 * Returns: A set of flags from the #GDBusServerFlags enumeration.
577 g_dbus_server_get_flags (GDBusServer *server)
579 g_return_val_if_fail (G_IS_DBUS_SERVER (server), G_DBUS_SERVER_FLAGS_NONE);
580 return server->flags;
584 * g_dbus_server_is_active:
585 * @server: A #GDBusServer.
587 * Gets whether @server is active.
589 * Returns: %TRUE if server is active, %FALSE otherwise.
594 g_dbus_server_is_active (GDBusServer *server)
596 g_return_val_if_fail (G_IS_DBUS_SERVER (server), G_DBUS_SERVER_FLAGS_NONE);
597 return server->active;
601 * g_dbus_server_start:
602 * @server: A #GDBusServer.
609 g_dbus_server_start (GDBusServer *server)
611 g_return_if_fail (G_IS_DBUS_SERVER (server));
614 /* Right now we don't have any transport not using the listener... */
615 g_assert (server->is_using_listener);
616 server->run_signal_handler_id = g_signal_connect_data (G_SOCKET_SERVICE (server->listener),
619 g_object_ref (server),
620 (GClosureNotify) g_object_unref,
622 g_socket_service_start (G_SOCKET_SERVICE (server->listener));
623 server->active = TRUE;
624 g_object_notify (G_OBJECT (server), "active");
628 * g_dbus_server_stop:
629 * @server: A #GDBusServer.
636 g_dbus_server_stop (GDBusServer *server)
638 g_return_if_fail (G_IS_DBUS_SERVER (server));
641 /* Right now we don't have any transport not using the listener... */
642 g_assert (server->is_using_listener);
643 g_assert (server->run_signal_handler_id > 0);
644 g_clear_signal_handler (&server->run_signal_handler_id, server->listener);
645 g_socket_service_stop (G_SOCKET_SERVICE (server->listener));
646 server->active = FALSE;
647 g_object_notify (G_OBJECT (server), "active");
649 if (server->unix_socket_path)
651 if (g_unlink (server->unix_socket_path) != 0)
652 g_warning ("Failed to delete %s: %s", server->unix_socket_path, g_strerror (errno));
655 if (server->nonce_file)
657 if (g_unlink (server->nonce_file) != 0)
658 g_warning ("Failed to delete %s: %s", server->nonce_file, g_strerror (errno));
662 /* ---------------------------------------------------------------------------------------------------- */
670 ret = g_random_int_range (0, 60);
680 /* note that address_entry has already been validated => exactly one of path, dir, tmpdir, or abstract keys are set */
682 try_unix (GDBusServer *server,
683 const gchar *address_entry,
684 GHashTable *key_value_pairs,
691 const gchar *abstract;
692 GSocketAddress *address;
697 path = g_hash_table_lookup (key_value_pairs, "path");
698 dir = g_hash_table_lookup (key_value_pairs, "dir");
699 tmpdir = g_hash_table_lookup (key_value_pairs, "tmpdir");
700 abstract = g_hash_table_lookup (key_value_pairs, "abstract");
704 address = g_unix_socket_address_new (path);
706 else if (dir != NULL || tmpdir != NULL)
713 s = g_string_new (tmpdir != NULL ? tmpdir : dir);
714 g_string_append (s, "/dbus-");
715 for (n = 0; n < 8; n++)
716 g_string_append_c (s, random_ascii ());
718 /* prefer abstract namespace if available for tmpdir: addresses
719 * abstract namespace is disallowed for dir: addresses */
720 if (tmpdir != NULL && g_unix_socket_address_abstract_names_supported ())
721 address = g_unix_socket_address_new_with_type (s->str,
723 G_UNIX_SOCKET_ADDRESS_ABSTRACT);
725 address = g_unix_socket_address_new (s->str);
726 g_string_free (s, TRUE);
729 if (!g_socket_listener_add_address (server->listener,
731 G_SOCKET_TYPE_STREAM,
732 G_SOCKET_PROTOCOL_DEFAULT,
733 NULL, /* source_object */
734 NULL, /* effective_address */
737 if (local_error->domain == G_IO_ERROR && local_error->code == G_IO_ERROR_ADDRESS_IN_USE)
739 g_error_free (local_error);
742 g_propagate_error (error, local_error);
748 else if (abstract != NULL)
750 if (!g_unix_socket_address_abstract_names_supported ())
752 g_set_error_literal (error,
754 G_IO_ERROR_NOT_SUPPORTED,
755 _("Abstract namespace not supported"));
758 address = g_unix_socket_address_new_with_type (abstract,
760 G_UNIX_SOCKET_ADDRESS_ABSTRACT);
764 g_assert_not_reached ();
767 if (!g_socket_listener_add_address (server->listener,
769 G_SOCKET_TYPE_STREAM,
770 G_SOCKET_PROTOCOL_DEFAULT,
771 NULL, /* source_object */
772 NULL, /* effective_address */
782 /* Fill out client_address if the connection attempt worked */
785 const char *address_path;
788 server->is_using_listener = TRUE;
789 address_path = g_unix_socket_address_get_path (G_UNIX_SOCKET_ADDRESS (address));
790 escaped_path = g_dbus_address_escape_value (address_path);
792 switch (g_unix_socket_address_get_address_type (G_UNIX_SOCKET_ADDRESS (address)))
794 case G_UNIX_SOCKET_ADDRESS_ABSTRACT:
795 server->client_address = g_strdup_printf ("unix:abstract=%s", escaped_path);
798 case G_UNIX_SOCKET_ADDRESS_PATH:
799 server->client_address = g_strdup_printf ("unix:path=%s", escaped_path);
800 server->unix_socket_path = g_strdup (address_path);
804 g_assert_not_reached ();
808 g_free (escaped_path);
810 g_object_unref (address);
816 /* ---------------------------------------------------------------------------------------------------- */
818 /* note that address_entry has already been validated =>
819 * both host and port (guaranteed to be a number in [0, 65535]) are set (family is optional)
822 try_tcp (GDBusServer *server,
823 const gchar *address_entry,
824 GHashTable *key_value_pairs,
833 GList *resolved_addresses;
838 resolved_addresses = NULL;
840 host = g_hash_table_lookup (key_value_pairs, "host");
841 port = g_hash_table_lookup (key_value_pairs, "port");
842 /* family = g_hash_table_lookup (key_value_pairs, "family"); */
843 if (g_hash_table_lookup (key_value_pairs, "noncefile") != NULL)
845 g_set_error_literal (error,
847 G_IO_ERROR_INVALID_ARGUMENT,
848 _("Cannot specify nonce file when creating a server"));
856 port_num = strtol (port, NULL, 10);
858 resolver = g_resolver_get_default ();
859 resolved_addresses = g_resolver_lookup_by_name (resolver,
863 if (resolved_addresses == NULL)
866 /* TODO: handle family */
867 for (l = resolved_addresses; l != NULL; l = l->next)
869 GInetAddress *address = G_INET_ADDRESS (l->data);
870 GSocketAddress *socket_address;
871 GSocketAddress *effective_address;
873 socket_address = g_inet_socket_address_new (address, port_num);
874 if (!g_socket_listener_add_address (server->listener,
876 G_SOCKET_TYPE_STREAM,
877 G_SOCKET_PROTOCOL_TCP,
878 NULL, /* GObject *source_object */
882 g_object_unref (socket_address);
886 /* make sure we allocate the same port number for other listeners */
887 port_num = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (effective_address));
889 g_object_unref (effective_address);
890 g_object_unref (socket_address);
898 gsize bytes_remaining;
902 server->nonce = g_new0 (guchar, 16);
903 for (n = 0; n < 16; n++)
904 server->nonce[n] = g_random_int_range (0, 256);
905 fd = g_file_open_tmp ("gdbus-nonce-file-XXXXXX",
910 g_socket_listener_close (server->listener);
915 bytes_remaining = 16;
916 while (bytes_remaining > 0)
921 ret = write (fd, server->nonce + bytes_written, bytes_remaining);
929 g_io_error_from_errno (errsv),
930 _("Error writing nonce file at ā%sā: %s"),
935 bytes_written += ret;
936 bytes_remaining -= ret;
938 if (!g_close (fd, error))
940 host_escaped = g_dbus_address_escape_value (host);
941 file_escaped = g_dbus_address_escape_value (server->nonce_file);
942 server->client_address = g_strdup_printf ("nonce-tcp:host=%s,port=%d,noncefile=%s",
946 g_free (host_escaped);
947 g_free (file_escaped);
951 server->client_address = g_strdup_printf ("tcp:host=%s,port=%d", host, port_num);
953 server->is_using_listener = TRUE;
957 g_list_free_full (resolved_addresses, g_object_unref);
959 g_object_unref (resolver);
963 /* ---------------------------------------------------------------------------------------------------- */
968 GDBusConnection *connection;
972 emit_idle_data_free (EmitIdleData *data)
974 g_object_unref (data->server);
975 g_object_unref (data->connection);
980 emit_new_connection_in_idle (gpointer user_data)
982 EmitIdleData *data = user_data;
986 g_signal_emit (data->server,
987 _signals[NEW_CONNECTION_SIGNAL],
993 g_dbus_connection_start_message_processing (data->connection);
994 g_object_unref (data->connection);
999 /* Called in new thread */
1001 on_run (GSocketService *service,
1002 GSocketConnection *socket_connection,
1003 GObject *source_object,
1006 GDBusServer *server = G_DBUS_SERVER (user_data);
1007 GDBusConnection *connection;
1008 GDBusConnectionFlags connection_flags;
1010 if (server->nonce != NULL)
1015 if (!g_input_stream_read_all (g_io_stream_get_input_stream (G_IO_STREAM (socket_connection)),
1019 NULL, /* GCancellable */
1023 if (bytes_read != 16)
1026 if (memcmp (buf, server->nonce, 16) != 0)
1031 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER |
1032 G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING;
1033 if (server->flags & G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS)
1034 connection_flags |= G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
1036 connection = g_dbus_connection_new_sync (G_IO_STREAM (socket_connection),
1039 server->authentication_observer,
1040 NULL, /* GCancellable */
1042 if (connection == NULL)
1045 if (server->flags & G_DBUS_SERVER_FLAGS_RUN_IN_THREAD)
1050 g_signal_emit (server,
1051 _signals[NEW_CONNECTION_SIGNAL],
1056 g_dbus_connection_start_message_processing (connection);
1057 g_object_unref (connection);
1061 GSource *idle_source;
1064 data = g_new0 (EmitIdleData, 1);
1065 data->server = g_object_ref (server);
1066 data->connection = g_object_ref (connection);
1068 idle_source = g_idle_source_new ();
1069 g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
1070 g_source_set_callback (idle_source,
1071 emit_new_connection_in_idle,
1073 (GDestroyNotify) emit_idle_data_free);
1074 g_source_set_name (idle_source, "[gio] emit_new_connection_in_idle");
1075 g_source_attach (idle_source, server->main_context_at_construction);
1076 g_source_unref (idle_source);
1084 initable_init (GInitable *initable,
1085 GCancellable *cancellable,
1088 GDBusServer *server = G_DBUS_SERVER (initable);
1098 if (!g_dbus_is_guid (server->guid))
1100 g_set_error (&last_error,
1102 G_IO_ERROR_INVALID_ARGUMENT,
1103 _("The string ā%sā is not a valid D-Bus GUID"),
1108 server->listener = G_SOCKET_LISTENER (g_threaded_socket_service_new (-1));
1110 addr_array = g_strsplit (server->address, ";", 0);
1112 for (n = 0; addr_array != NULL && addr_array[n] != NULL; n++)
1114 const gchar *address_entry = addr_array[n];
1115 GHashTable *key_value_pairs;
1116 gchar *transport_name;
1120 if (g_dbus_is_supported_address (address_entry,
1122 _g_dbus_address_parse_entry (address_entry,
1132 else if (g_strcmp0 (transport_name, "unix") == 0)
1133 ret = try_unix (server, address_entry, key_value_pairs, &this_error);
1135 else if (g_strcmp0 (transport_name, "tcp") == 0)
1136 ret = try_tcp (server, address_entry, key_value_pairs, FALSE, &this_error);
1137 else if (g_strcmp0 (transport_name, "nonce-tcp") == 0)
1138 ret = try_tcp (server, address_entry, key_value_pairs, TRUE, &this_error);
1140 g_set_error (&this_error,
1142 G_IO_ERROR_INVALID_ARGUMENT,
1143 _("Cannot listen on unsupported transport ā%sā"),
1146 g_free (transport_name);
1147 if (key_value_pairs != NULL)
1148 g_hash_table_unref (key_value_pairs);
1152 g_assert (this_error == NULL);
1157 if (this_error != NULL)
1159 if (last_error != NULL)
1160 g_error_free (last_error);
1161 last_error = this_error;
1167 g_strfreev (addr_array);
1171 g_clear_error (&last_error);
1175 g_assert (last_error != NULL);
1176 g_propagate_error (error, last_error);
1183 initable_iface_init (GInitableIface *initable_iface)
1185 initable_iface->init = initable_init;
1188 /* ---------------------------------------------------------------------------------------------------- */