1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2009 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 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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
29 #include <gio/gunixconnection.h>
30 #include <gio/gunixfdmessage.h>
31 #include "gunixcredentialsmessage.h"
37 #include "gdbusprivate.h"
38 #include "gdbusmessage.h"
39 #include "gdbuserror.h"
40 #include "gdbusintrospection.h"
41 #include "gasyncresult.h"
42 #include "gsimpleasyncresult.h"
43 #include "ginputstream.h"
44 #include "giostream.h"
45 #include "gsocketcontrolmessage.h"
49 #include "gunixfdmessage.h"
50 #include "gunixconnection.h"
56 /* ---------------------------------------------------------------------------------------------------- */
59 hexdump (const gchar *data, gsize len, guint indent)
64 ret = g_string_new (NULL);
66 for (n = 0; n < len; n += 16)
68 g_string_append_printf (ret, "%*s%04x: ", indent, "", n);
70 for (m = n; m < n + 16; m++)
72 if (m > n && (m%4) == 0)
73 g_string_append_c (ret, ' ');
75 g_string_append_printf (ret, "%02x ", (guchar) data[m]);
77 g_string_append (ret, " ");
80 g_string_append (ret, " ");
82 for (m = n; m < len && m < n + 16; m++)
83 g_string_append_c (ret, g_ascii_isprint (data[m]) ? data[m] : '.');
85 g_string_append_c (ret, '\n');
88 return g_string_free (ret, FALSE);
91 /* ---------------------------------------------------------------------------------------------------- */
93 /* Unfortunately ancillary messages are discarded when reading from a
94 * socket using the GSocketInputStream abstraction. So we provide a
95 * very GInputStream-ish API that uses GSocket in this case (very
96 * similar to GSocketInputStream).
102 GCancellable *cancellable;
107 GSocketControlMessage ***messages;
110 GSimpleAsyncResult *simple;
112 gboolean from_mainloop;
113 } ReadWithControlData;
116 read_with_control_data_free (ReadWithControlData *data)
118 g_object_unref (data->socket);
119 if (data->cancellable != NULL)
120 g_object_unref (data->cancellable);
125 _g_socket_read_with_control_messages_ready (GSocket *socket,
126 GIOCondition condition,
129 ReadWithControlData *data = user_data;
135 vector.buffer = data->buffer;
136 vector.size = data->count;
137 result = g_socket_receive_message (data->socket,
148 g_simple_async_result_set_op_res_gssize (data->simple, result);
152 g_assert (error != NULL);
153 g_simple_async_result_set_from_error (data->simple, error);
154 g_error_free (error);
157 if (data->from_mainloop)
158 g_simple_async_result_complete (data->simple);
160 g_simple_async_result_complete_in_idle (data->simple);
166 _g_socket_read_with_control_messages (GSocket *socket,
169 GSocketControlMessage ***messages,
172 GCancellable *cancellable,
173 GAsyncReadyCallback callback,
176 ReadWithControlData *data;
178 data = g_new0 (ReadWithControlData, 1);
179 data->socket = g_object_ref (socket);
180 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
181 data->buffer = buffer;
183 data->messages = messages;
184 data->num_messages = num_messages;
186 data->simple = g_simple_async_result_new (G_OBJECT (socket),
189 _g_socket_read_with_control_messages);
191 if (!g_socket_condition_check (socket, G_IO_IN))
194 data->from_mainloop = TRUE;
195 source = g_socket_create_source (data->socket,
196 G_IO_IN | G_IO_HUP | G_IO_ERR,
198 g_source_set_callback (source,
199 (GSourceFunc) _g_socket_read_with_control_messages_ready,
201 (GDestroyNotify) read_with_control_data_free);
202 g_source_attach (source, g_main_context_get_thread_default ());
203 g_source_unref (source);
207 _g_socket_read_with_control_messages_ready (data->socket, G_IO_IN, data);
208 read_with_control_data_free (data);
213 _g_socket_read_with_control_messages_finish (GSocket *socket,
214 GAsyncResult *result,
217 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
219 g_return_val_if_fail (G_IS_SOCKET (socket), -1);
220 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == _g_socket_read_with_control_messages);
222 if (g_simple_async_result_propagate_error (simple, error))
225 return g_simple_async_result_get_op_res_gssize (simple);
228 /* ---------------------------------------------------------------------------------------------------- */
230 G_LOCK_DEFINE_STATIC (shared_thread_lock);
236 GMainContext *context;
240 static SharedThreadData *shared_thread_data = NULL;
243 shared_thread_func (gpointer data)
245 g_main_context_push_thread_default (shared_thread_data->context);
246 g_main_loop_run (shared_thread_data->loop);
247 g_main_context_pop_thread_default (shared_thread_data->context);
251 typedef void (*GDBusSharedThreadFunc) (gpointer user_data);
255 GDBusSharedThreadFunc func;
261 invoke_caller (gpointer user_data)
263 CallerData *data = user_data;
264 data->func (data->user_data);
270 _g_dbus_shared_thread_ref (GDBusSharedThreadFunc func,
274 GSource *idle_source;
277 G_LOCK (shared_thread_lock);
279 if (shared_thread_data != NULL)
281 shared_thread_data->num_users += 1;
285 shared_thread_data = g_new0 (SharedThreadData, 1);
286 shared_thread_data->num_users = 1;
289 shared_thread_data->context = g_main_context_new ();
290 shared_thread_data->loop = g_main_loop_new (shared_thread_data->context, FALSE);
291 shared_thread_data->thread = g_thread_create (shared_thread_func,
295 g_assert_no_error (error);
299 data = g_new0 (CallerData, 1);
301 data->user_data = user_data;
304 idle_source = g_idle_source_new ();
305 g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
306 g_source_set_callback (idle_source,
310 g_source_attach (idle_source, shared_thread_data->context);
311 g_source_unref (idle_source);
313 /* wait for the user code to run.. hmm.. probably use a condition variable instead */
319 G_UNLOCK (shared_thread_lock);
323 _g_dbus_shared_thread_unref (void)
325 /* TODO: actually destroy the shared thread here */
327 G_LOCK (shared_thread_lock);
328 g_assert (shared_thread_data != NULL);
329 shared_thread_data->num_users -= 1;
330 if (shared_thread_data->num_users == 0)
332 g_main_loop_quit (shared_thread_data->loop);
333 //g_thread_join (shared_thread_data->thread);
334 g_main_loop_unref (shared_thread_data->loop);
335 g_main_context_unref (shared_thread_data->context);
336 g_free (shared_thread_data);
337 shared_thread_data = NULL;
338 G_UNLOCK (shared_thread_lock);
342 G_UNLOCK (shared_thread_lock);
347 /* ---------------------------------------------------------------------------------------------------- */
351 volatile gint ref_count;
354 GDBusCapabilityFlags capabilities;
355 GCancellable *cancellable;
356 GDBusWorkerMessageReceivedCallback message_received_callback;
357 GDBusWorkerDisconnectedCallback disconnected_callback;
362 /* if not NULL, stream is GSocketConnection */
365 /* used for reading */
368 gsize read_buffer_allocated_size;
369 gsize read_buffer_cur_size;
370 gsize read_buffer_bytes_wanted;
371 GUnixFDList *read_fd_list;
372 GSocketControlMessage **read_ancillary_messages;
373 gint read_num_ancillary_messages;
375 /* used for writing */
378 gboolean write_is_pending;
381 struct _MessageToWriteData ;
382 typedef struct _MessageToWriteData MessageToWriteData;
384 static void message_to_write_data_free (MessageToWriteData *data);
387 _g_dbus_worker_ref (GDBusWorker *worker)
389 g_atomic_int_inc (&worker->ref_count);
394 _g_dbus_worker_unref (GDBusWorker *worker)
396 if (g_atomic_int_dec_and_test (&worker->ref_count))
398 _g_dbus_shared_thread_unref ();
400 g_object_unref (worker->stream);
402 g_mutex_free (worker->read_lock);
403 g_object_unref (worker->cancellable);
404 if (worker->read_fd_list != NULL)
405 g_object_unref (worker->read_fd_list);
407 g_mutex_free (worker->write_lock);
408 g_queue_foreach (worker->write_queue,
409 (GFunc) message_to_write_data_free,
411 g_queue_free (worker->write_queue);
417 _g_dbus_worker_emit_disconnected (GDBusWorker *worker,
418 gboolean remote_peer_vanished,
421 if (!worker->stopped)
422 worker->disconnected_callback (worker, remote_peer_vanished, error, worker->user_data);
426 _g_dbus_worker_emit_message (GDBusWorker *worker,
427 GDBusMessage *message)
429 if (!worker->stopped)
430 worker->message_received_callback (worker, message, worker->user_data);
433 static void _g_dbus_worker_do_read_unlocked (GDBusWorker *worker);
435 /* called in private thread shared by all GDBusConnection instances (without read-lock held) */
437 _g_dbus_worker_do_read_cb (GInputStream *input_stream,
441 GDBusWorker *worker = user_data;
445 g_mutex_lock (worker->read_lock);
447 /* If already stopped, don't even process the reply */
452 if (worker->socket == NULL)
453 bytes_read = g_input_stream_read_finish (g_io_stream_get_input_stream (worker->stream),
457 bytes_read = _g_socket_read_with_control_messages_finish (worker->socket,
460 if (worker->read_num_ancillary_messages > 0)
463 for (n = 0; n < worker->read_num_ancillary_messages; n++)
465 GSocketControlMessage *control_message = G_SOCKET_CONTROL_MESSAGE (worker->read_ancillary_messages[n]);
471 else if (G_IS_UNIX_FD_MESSAGE (control_message))
473 GUnixFDMessage *fd_message;
477 fd_message = G_UNIX_FD_MESSAGE (control_message);
478 fds = g_unix_fd_message_steal_fds (fd_message, &num_fds);
479 if (worker->read_fd_list == NULL)
481 worker->read_fd_list = g_unix_fd_list_new_from_array (fds, num_fds);
486 for (n = 0; n < num_fds; n++)
488 /* TODO: really want a append_steal() */
489 g_unix_fd_list_append (worker->read_fd_list, fds[n], NULL);
495 else if (G_IS_UNIX_CREDENTIALS_MESSAGE (control_message))
507 "Unexpected ancillary message of type %s received from peer",
508 g_type_name (G_TYPE_FROM_INSTANCE (control_message)));
509 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
510 g_error_free (error);
511 g_object_unref (control_message);
513 while (n < worker->read_num_ancillary_messages)
514 g_object_unref (worker->read_ancillary_messages[n++]);
515 g_free (worker->read_ancillary_messages);
519 g_object_unref (control_message);
521 g_free (worker->read_ancillary_messages);
524 if (bytes_read == -1)
526 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
527 g_error_free (error);
532 g_debug ("read %d bytes (is_closed=%d blocking=%d condition=0x%02x) stream %p, %p",
534 g_socket_is_closed (g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream))),
535 g_socket_get_blocking (g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream))),
536 g_socket_condition_check (g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream)),
537 G_IO_IN | G_IO_OUT | G_IO_HUP),
542 /* TODO: hmm, hmm... */
548 "Underlying GIOStream returned 0 bytes on an async read");
549 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
550 g_error_free (error);
554 worker->read_buffer_cur_size += bytes_read;
555 if (worker->read_buffer_bytes_wanted == worker->read_buffer_cur_size)
557 /* OK, got what we asked for! */
558 if (worker->read_buffer_bytes_wanted == 16)
561 /* OK, got the header - determine how many more bytes are needed */
563 message_len = g_dbus_message_bytes_needed ((guchar *) worker->read_buffer,
566 if (message_len == -1)
568 g_warning ("_g_dbus_worker_do_read_cb: error determing bytes needed: %s", error->message);
569 _g_dbus_worker_emit_disconnected (worker, FALSE, error);
570 g_error_free (error);
574 worker->read_buffer_bytes_wanted = message_len;
575 _g_dbus_worker_do_read_unlocked (worker);
579 GDBusMessage *message;
582 /* TODO: use connection->priv->auth to decode the message */
584 message = g_dbus_message_new_from_blob ((guchar *) worker->read_buffer,
585 worker->read_buffer_cur_size,
589 _g_dbus_worker_emit_disconnected (worker, FALSE, error);
590 g_error_free (error);
594 if (worker->read_fd_list != NULL)
596 g_dbus_message_set_unix_fd_list (message, worker->read_fd_list);
597 worker->read_fd_list = NULL;
600 if (G_UNLIKELY (_g_dbus_debug_message ()))
603 g_print ("========================================================================\n"
604 "GDBus-debug:Message:\n"
605 " <<<< RECEIVED D-Bus message (%" G_GSIZE_FORMAT " bytes)\n",
606 worker->read_buffer_cur_size);
607 s = g_dbus_message_print (message, 2);
610 s = hexdump (worker->read_buffer, worker->read_buffer_cur_size, 2);
615 /* yay, got a message, go deliver it */
616 _g_dbus_worker_emit_message (worker, message);
617 g_object_unref (message);
619 /* start reading another message! */
620 worker->read_buffer_bytes_wanted = 0;
621 worker->read_buffer_cur_size = 0;
622 _g_dbus_worker_do_read_unlocked (worker);
627 /* didn't get all the bytes we requested - so repeat the request... */
628 _g_dbus_worker_do_read_unlocked (worker);
632 g_mutex_unlock (worker->read_lock);
634 /* gives up the reference acquired when calling g_input_stream_read_async() */
635 _g_dbus_worker_unref (worker);
638 /* called in private thread shared by all GDBusConnection instances (with read-lock held) */
640 _g_dbus_worker_do_read_unlocked (GDBusWorker *worker)
642 /* if bytes_wanted is zero, it means start reading a message */
643 if (worker->read_buffer_bytes_wanted == 0)
645 worker->read_buffer_cur_size = 0;
646 worker->read_buffer_bytes_wanted = 16;
649 /* ensure we have a (big enough) buffer */
650 if (worker->read_buffer == NULL || worker->read_buffer_bytes_wanted > worker->read_buffer_allocated_size)
652 /* TODO: 4096 is randomly chosen; might want a better chosen default minimum */
653 worker->read_buffer_allocated_size = MAX (worker->read_buffer_bytes_wanted, 4096);
654 worker->read_buffer = g_realloc (worker->read_buffer, worker->read_buffer_allocated_size);
657 if (worker->socket == NULL)
658 g_input_stream_read_async (g_io_stream_get_input_stream (worker->stream),
659 worker->read_buffer + worker->read_buffer_cur_size,
660 worker->read_buffer_bytes_wanted - worker->read_buffer_cur_size,
663 (GAsyncReadyCallback) _g_dbus_worker_do_read_cb,
664 _g_dbus_worker_ref (worker));
667 worker->read_ancillary_messages = NULL;
668 worker->read_num_ancillary_messages = 0;
669 _g_socket_read_with_control_messages (worker->socket,
670 worker->read_buffer + worker->read_buffer_cur_size,
671 worker->read_buffer_bytes_wanted - worker->read_buffer_cur_size,
672 &worker->read_ancillary_messages,
673 &worker->read_num_ancillary_messages,
676 (GAsyncReadyCallback) _g_dbus_worker_do_read_cb,
677 _g_dbus_worker_ref (worker));
681 /* called in private thread shared by all GDBusConnection instances (without read-lock held) */
683 _g_dbus_worker_do_read (GDBusWorker *worker)
685 g_mutex_lock (worker->read_lock);
686 _g_dbus_worker_do_read_unlocked (worker);
687 g_mutex_unlock (worker->read_lock);
690 /* ---------------------------------------------------------------------------------------------------- */
692 struct _MessageToWriteData
694 GDBusMessage *message;
700 message_to_write_data_free (MessageToWriteData *data)
702 g_object_unref (data->message);
707 /* ---------------------------------------------------------------------------------------------------- */
709 /* called in private thread shared by all GDBusConnection instances (with write-lock held) */
711 write_message (GDBusWorker *worker,
712 MessageToWriteData *data,
717 g_return_val_if_fail (data->blob_size > 16, FALSE);
721 /* First, the initial 16 bytes - special case UNIX sockets here
722 * since it may involve writing an ancillary message with file
727 GOutputVector vector;
728 GSocketControlMessage *message;
729 GUnixFDList *fd_list;
730 gssize bytes_written;
732 fd_list = g_dbus_message_get_unix_fd_list (data->message);
737 if (!G_IS_UNIX_CONNECTION (worker->stream))
741 G_IO_ERROR_INVALID_ARGUMENT,
742 "Tried sending a file descriptor on unsupported stream of type %s",
743 g_type_name (G_TYPE_FROM_INSTANCE (worker->stream)));
746 else if (!(worker->capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING))
748 g_set_error_literal (error,
750 G_IO_ERROR_INVALID_ARGUMENT,
751 "Tried sending a file descriptor but remote peer does not support this capability");
754 message = g_unix_fd_message_new_with_fd_list (fd_list);
757 vector.buffer = data->blob;
760 bytes_written = g_socket_send_message (worker->socket,
764 message != NULL ? &message : NULL,
765 message != NULL ? 1 : 0,
769 if (bytes_written == -1)
771 g_prefix_error (error, _("Error writing first 16 bytes of message to socket: "));
773 g_object_unref (message);
777 g_object_unref (message);
779 if (bytes_written < 16)
781 /* TODO: I think this needs to be handled ... are we guaranteed that the ancillary
784 g_assert_not_reached ();
788 /* write the first 16 bytes (guaranteed to return an error if everything can't be written) */
789 if (!g_output_stream_write_all (g_io_stream_get_output_stream (worker->stream),
790 (const gchar *) data->blob,
792 NULL, /* bytes_written */
793 worker->cancellable, /* cancellable */
798 /* Then write the rest of the message (guaranteed to return an error if everything can't be written) */
799 if (!g_output_stream_write_all (g_io_stream_get_output_stream (worker->stream),
800 (const gchar *) data->blob + 16,
801 data->blob_size - 16,
802 NULL, /* bytes_written */
803 worker->cancellable, /* cancellable */
809 if (G_UNLIKELY (_g_dbus_debug_message ()))
812 g_print ("========================================================================\n"
813 "GDBus-debug:Message:\n"
814 " >>>> SENT D-Bus message (%" G_GSIZE_FORMAT " bytes)\n",
816 s = g_dbus_message_print (data->message, 2);
819 s = hexdump (data->blob, data->blob_size, 2);
828 /* ---------------------------------------------------------------------------------------------------- */
830 /* called in private thread shared by all GDBusConnection instances (without write-lock held) */
832 write_message_in_idle_cb (gpointer user_data)
834 GDBusWorker *worker = user_data;
835 gboolean more_writes_are_pending;
836 MessageToWriteData *data;
839 g_mutex_lock (worker->write_lock);
841 data = g_queue_pop_head (worker->write_queue);
842 g_assert (data != NULL);
845 if (!write_message (worker,
850 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
851 g_error_free (error);
853 message_to_write_data_free (data);
855 more_writes_are_pending = (g_queue_get_length (worker->write_queue) > 0);
857 worker->write_is_pending = more_writes_are_pending;
858 g_mutex_unlock (worker->write_lock);
860 return more_writes_are_pending;
863 /* ---------------------------------------------------------------------------------------------------- */
865 /* can be called from any thread - steals blob */
867 _g_dbus_worker_send_message (GDBusWorker *worker,
868 GDBusMessage *message,
872 MessageToWriteData *data;
874 g_return_if_fail (G_IS_DBUS_MESSAGE (message));
875 g_return_if_fail (blob != NULL);
876 g_return_if_fail (blob_len > 16);
878 data = g_new0 (MessageToWriteData, 1);
879 data->message = g_object_ref (message);
880 data->blob = blob; /* steal! */
881 data->blob_size = blob_len;
883 g_mutex_lock (worker->write_lock);
884 g_queue_push_tail (worker->write_queue, data);
885 if (!worker->write_is_pending)
887 GSource *idle_source;
889 worker->write_is_pending = TRUE;
891 idle_source = g_idle_source_new ();
892 g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
893 g_source_set_callback (idle_source,
894 write_message_in_idle_cb,
895 _g_dbus_worker_ref (worker),
896 (GDestroyNotify) _g_dbus_worker_unref);
897 g_source_attach (idle_source, shared_thread_data->context);
898 g_source_unref (idle_source);
900 g_mutex_unlock (worker->write_lock);
903 /* ---------------------------------------------------------------------------------------------------- */
906 _g_dbus_worker_thread_begin_func (gpointer user_data)
908 GDBusWorker *worker = user_data;
910 worker->thread = g_thread_self ();
913 _g_dbus_worker_do_read (worker);
917 _g_dbus_worker_new (GIOStream *stream,
918 GDBusCapabilityFlags capabilities,
919 GDBusWorkerMessageReceivedCallback message_received_callback,
920 GDBusWorkerDisconnectedCallback disconnected_callback,
925 g_return_val_if_fail (G_IS_IO_STREAM (stream), NULL);
926 g_return_val_if_fail (message_received_callback != NULL, NULL);
927 g_return_val_if_fail (disconnected_callback != NULL, NULL);
929 worker = g_new0 (GDBusWorker, 1);
930 worker->ref_count = 1;
932 worker->read_lock = g_mutex_new ();
933 worker->message_received_callback = message_received_callback;
934 worker->disconnected_callback = disconnected_callback;
935 worker->user_data = user_data;
936 worker->stream = g_object_ref (stream);
937 worker->capabilities = capabilities;
938 worker->cancellable = g_cancellable_new ();
940 worker->write_lock = g_mutex_new ();
941 worker->write_queue = g_queue_new ();
943 if (G_IS_SOCKET_CONNECTION (worker->stream))
944 worker->socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream));
946 _g_dbus_shared_thread_ref (_g_dbus_worker_thread_begin_func, worker);
951 /* This can be called from any thread - frees worker - guarantees no callbacks
952 * will ever be issued again
955 _g_dbus_worker_stop (GDBusWorker *worker)
957 /* If we're called in the worker thread it means we are called from
958 * a worker callback. This is fine, we just can't lock in that case since
959 * we're already holding the lock...
961 if (g_thread_self () != worker->thread)
962 g_mutex_lock (worker->read_lock);
963 worker->stopped = TRUE;
964 if (g_thread_self () != worker->thread)
965 g_mutex_unlock (worker->read_lock);
967 g_cancellable_cancel (worker->cancellable);
968 _g_dbus_worker_unref (worker);
971 #define G_DBUS_DEBUG_AUTHENTICATION (1<<0)
972 #define G_DBUS_DEBUG_MESSAGE (1<<1)
973 #define G_DBUS_DEBUG_ALL 0xffffffff
974 static gint _gdbus_debug_flags = 0;
977 _g_dbus_debug_authentication (void)
979 _g_dbus_initialize ();
980 return (_gdbus_debug_flags & G_DBUS_DEBUG_AUTHENTICATION) != 0;
984 _g_dbus_debug_message (void)
986 _g_dbus_initialize ();
987 return (_gdbus_debug_flags & G_DBUS_DEBUG_MESSAGE) != 0;
991 * _g_dbus_initialize:
993 * Does various one-time init things such as
995 * - registering the G_DBUS_ERROR error domain
996 * - parses the G_DBUS_DEBUG environment variable
999 _g_dbus_initialize (void)
1001 static volatile gsize initialized = 0;
1003 if (g_once_init_enter (&initialized))
1005 volatile GQuark g_dbus_error_domain;
1008 g_dbus_error_domain = G_DBUS_ERROR;
1010 debug = g_getenv ("G_DBUS_DEBUG");
1015 tokens = g_strsplit (debug, ",", 0);
1016 for (n = 0; tokens[n] != NULL; n++)
1018 if (g_strcmp0 (tokens[n], "authentication") == 0)
1019 _gdbus_debug_flags |= G_DBUS_DEBUG_AUTHENTICATION;
1020 else if (g_strcmp0 (tokens[n], "message") == 0)
1021 _gdbus_debug_flags |= G_DBUS_DEBUG_MESSAGE;
1022 else if (g_strcmp0 (tokens[n], "all") == 0)
1023 _gdbus_debug_flags |= G_DBUS_DEBUG_ALL;
1025 g_strfreev (tokens);
1028 g_once_init_leave (&initialized, 1);
1032 /* ---------------------------------------------------------------------------------------------------- */
1035 _g_dbus_compute_complete_signature (GDBusArgInfo **args,
1036 gboolean include_parentheses)
1041 if (include_parentheses)
1042 s = g_string_new ("(");
1044 s = g_string_new ("");
1046 for (n = 0; args[n] != NULL; n++)
1047 g_string_append (s, args[n]->signature);
1049 if (include_parentheses)
1050 g_string_append_c (s, ')');
1052 return g_string_free (s, FALSE);
1055 #define __G_DBUS_PRIVATE_C__
1056 #include "gioaliasdef.c"