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 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>
33 #include "gdbusprivate.h"
34 #include "gdbusmessage.h"
35 #include "gdbuserror.h"
36 #include "gdbusintrospection.h"
37 #include "gasyncresult.h"
38 #include "gsimpleasyncresult.h"
39 #include "ginputstream.h"
40 #include "giostream.h"
41 #include "gsocketcontrolmessage.h"
44 #include "gunixfdmessage.h"
45 #include "gunixconnection.h"
46 #include "gunixcredentialsmessage.h"
52 /* ---------------------------------------------------------------------------------------------------- */
55 hexdump (const gchar *data, gsize len, guint indent)
60 ret = g_string_new (NULL);
62 for (n = 0; n < len; n += 16)
64 g_string_append_printf (ret, "%*s%04x: ", indent, "", n);
66 for (m = n; m < n + 16; m++)
68 if (m > n && (m%4) == 0)
69 g_string_append_c (ret, ' ');
71 g_string_append_printf (ret, "%02x ", (guchar) data[m]);
73 g_string_append (ret, " ");
76 g_string_append (ret, " ");
78 for (m = n; m < len && m < n + 16; m++)
79 g_string_append_c (ret, g_ascii_isprint (data[m]) ? data[m] : '.');
81 g_string_append_c (ret, '\n');
84 return g_string_free (ret, FALSE);
87 /* ---------------------------------------------------------------------------------------------------- */
89 /* Unfortunately ancillary messages are discarded when reading from a
90 * socket using the GSocketInputStream abstraction. So we provide a
91 * very GInputStream-ish API that uses GSocket in this case (very
92 * similar to GSocketInputStream).
98 GCancellable *cancellable;
103 GSocketControlMessage ***messages;
106 GSimpleAsyncResult *simple;
108 gboolean from_mainloop;
109 } ReadWithControlData;
112 read_with_control_data_free (ReadWithControlData *data)
114 g_object_unref (data->socket);
115 if (data->cancellable != NULL)
116 g_object_unref (data->cancellable);
121 _g_socket_read_with_control_messages_ready (GSocket *socket,
122 GIOCondition condition,
125 ReadWithControlData *data = user_data;
131 vector.buffer = data->buffer;
132 vector.size = data->count;
133 result = g_socket_receive_message (data->socket,
144 g_simple_async_result_set_op_res_gssize (data->simple, result);
148 g_assert (error != NULL);
149 g_simple_async_result_set_from_error (data->simple, error);
150 g_error_free (error);
153 if (data->from_mainloop)
154 g_simple_async_result_complete (data->simple);
156 g_simple_async_result_complete_in_idle (data->simple);
162 _g_socket_read_with_control_messages (GSocket *socket,
165 GSocketControlMessage ***messages,
168 GCancellable *cancellable,
169 GAsyncReadyCallback callback,
172 ReadWithControlData *data;
174 data = g_new0 (ReadWithControlData, 1);
175 data->socket = g_object_ref (socket);
176 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
177 data->buffer = buffer;
179 data->messages = messages;
180 data->num_messages = num_messages;
182 data->simple = g_simple_async_result_new (G_OBJECT (socket),
185 _g_socket_read_with_control_messages);
187 if (!g_socket_condition_check (socket, G_IO_IN))
190 data->from_mainloop = TRUE;
191 source = g_socket_create_source (data->socket,
192 G_IO_IN | G_IO_HUP | G_IO_ERR,
194 g_source_set_callback (source,
195 (GSourceFunc) _g_socket_read_with_control_messages_ready,
197 (GDestroyNotify) read_with_control_data_free);
198 g_source_attach (source, g_main_context_get_thread_default ());
199 g_source_unref (source);
203 _g_socket_read_with_control_messages_ready (data->socket, G_IO_IN, data);
204 read_with_control_data_free (data);
209 _g_socket_read_with_control_messages_finish (GSocket *socket,
210 GAsyncResult *result,
213 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
215 g_return_val_if_fail (G_IS_SOCKET (socket), -1);
216 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == _g_socket_read_with_control_messages);
218 if (g_simple_async_result_propagate_error (simple, error))
221 return g_simple_async_result_get_op_res_gssize (simple);
224 /* ---------------------------------------------------------------------------------------------------- */
226 G_LOCK_DEFINE_STATIC (shared_thread_lock);
232 GMainContext *context;
236 static SharedThreadData *shared_thread_data = NULL;
239 shared_thread_func (gpointer data)
241 g_main_context_push_thread_default (shared_thread_data->context);
242 g_main_loop_run (shared_thread_data->loop);
243 g_main_context_pop_thread_default (shared_thread_data->context);
247 typedef void (*GDBusSharedThreadFunc) (gpointer user_data);
251 GDBusSharedThreadFunc func;
257 invoke_caller (gpointer user_data)
259 CallerData *data = user_data;
260 data->func (data->user_data);
266 _g_dbus_shared_thread_ref (GDBusSharedThreadFunc func,
270 GSource *idle_source;
273 G_LOCK (shared_thread_lock);
275 if (shared_thread_data != NULL)
277 shared_thread_data->num_users += 1;
281 shared_thread_data = g_new0 (SharedThreadData, 1);
282 shared_thread_data->num_users = 1;
285 shared_thread_data->context = g_main_context_new ();
286 shared_thread_data->loop = g_main_loop_new (shared_thread_data->context, FALSE);
287 shared_thread_data->thread = g_thread_create (shared_thread_func,
291 g_assert_no_error (error);
295 data = g_new0 (CallerData, 1);
297 data->user_data = user_data;
300 idle_source = g_idle_source_new ();
301 g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
302 g_source_set_callback (idle_source,
306 g_source_attach (idle_source, shared_thread_data->context);
307 g_source_unref (idle_source);
309 /* wait for the user code to run.. hmm.. probably use a condition variable instead */
315 G_UNLOCK (shared_thread_lock);
319 _g_dbus_shared_thread_unref (void)
321 /* TODO: actually destroy the shared thread here */
323 G_LOCK (shared_thread_lock);
324 g_assert (shared_thread_data != NULL);
325 shared_thread_data->num_users -= 1;
326 if (shared_thread_data->num_users == 0)
328 g_main_loop_quit (shared_thread_data->loop);
329 //g_thread_join (shared_thread_data->thread);
330 g_main_loop_unref (shared_thread_data->loop);
331 g_main_context_unref (shared_thread_data->context);
332 g_free (shared_thread_data);
333 shared_thread_data = NULL;
334 G_UNLOCK (shared_thread_lock);
338 G_UNLOCK (shared_thread_lock);
343 /* ---------------------------------------------------------------------------------------------------- */
347 volatile gint ref_count;
350 GDBusCapabilityFlags capabilities;
351 GCancellable *cancellable;
352 GDBusWorkerMessageReceivedCallback message_received_callback;
353 GDBusWorkerDisconnectedCallback disconnected_callback;
358 /* if not NULL, stream is GSocketConnection */
361 /* used for reading */
364 gsize read_buffer_allocated_size;
365 gsize read_buffer_cur_size;
366 gsize read_buffer_bytes_wanted;
367 GUnixFDList *read_fd_list;
368 GSocketControlMessage **read_ancillary_messages;
369 gint read_num_ancillary_messages;
371 /* used for writing */
374 gboolean write_is_pending;
377 struct _MessageToWriteData ;
378 typedef struct _MessageToWriteData MessageToWriteData;
380 static void message_to_write_data_free (MessageToWriteData *data);
383 _g_dbus_worker_ref (GDBusWorker *worker)
385 g_atomic_int_inc (&worker->ref_count);
390 _g_dbus_worker_unref (GDBusWorker *worker)
392 if (g_atomic_int_dec_and_test (&worker->ref_count))
394 _g_dbus_shared_thread_unref ();
396 g_object_unref (worker->stream);
398 g_mutex_free (worker->read_lock);
399 g_object_unref (worker->cancellable);
400 if (worker->read_fd_list != NULL)
401 g_object_unref (worker->read_fd_list);
403 g_mutex_free (worker->write_lock);
404 g_queue_foreach (worker->write_queue,
405 (GFunc) message_to_write_data_free,
407 g_queue_free (worker->write_queue);
413 _g_dbus_worker_emit_disconnected (GDBusWorker *worker,
414 gboolean remote_peer_vanished,
417 if (!worker->stopped)
418 worker->disconnected_callback (worker, remote_peer_vanished, error, worker->user_data);
422 _g_dbus_worker_emit_message (GDBusWorker *worker,
423 GDBusMessage *message)
425 if (!worker->stopped)
426 worker->message_received_callback (worker, message, worker->user_data);
429 static void _g_dbus_worker_do_read_unlocked (GDBusWorker *worker);
431 /* called in private thread shared by all GDBusConnection instances (without read-lock held) */
433 _g_dbus_worker_do_read_cb (GInputStream *input_stream,
437 GDBusWorker *worker = user_data;
441 g_mutex_lock (worker->read_lock);
443 /* If already stopped, don't even process the reply */
448 if (worker->socket == NULL)
449 bytes_read = g_input_stream_read_finish (g_io_stream_get_input_stream (worker->stream),
453 bytes_read = _g_socket_read_with_control_messages_finish (worker->socket,
456 if (worker->read_num_ancillary_messages > 0)
459 for (n = 0; n < worker->read_num_ancillary_messages; n++)
461 GSocketControlMessage *control_message = G_SOCKET_CONTROL_MESSAGE (worker->read_ancillary_messages[n]);
467 else if (G_IS_UNIX_FD_MESSAGE (control_message))
469 GUnixFDMessage *fd_message;
473 fd_message = G_UNIX_FD_MESSAGE (control_message);
474 fds = g_unix_fd_message_steal_fds (fd_message, &num_fds);
475 if (worker->read_fd_list == NULL)
477 worker->read_fd_list = g_unix_fd_list_new_from_array (fds, num_fds);
482 for (n = 0; n < num_fds; n++)
484 /* TODO: really want a append_steal() */
485 g_unix_fd_list_append (worker->read_fd_list, fds[n], NULL);
491 else if (G_IS_UNIX_CREDENTIALS_MESSAGE (control_message))
503 "Unexpected ancillary message of type %s received from peer",
504 g_type_name (G_TYPE_FROM_INSTANCE (control_message)));
505 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
506 g_error_free (error);
507 g_object_unref (control_message);
509 while (n < worker->read_num_ancillary_messages)
510 g_object_unref (worker->read_ancillary_messages[n++]);
511 g_free (worker->read_ancillary_messages);
515 g_object_unref (control_message);
517 g_free (worker->read_ancillary_messages);
520 if (bytes_read == -1)
522 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
523 g_error_free (error);
528 g_debug ("read %d bytes (is_closed=%d blocking=%d condition=0x%02x) stream %p, %p",
530 g_socket_is_closed (g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream))),
531 g_socket_get_blocking (g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream))),
532 g_socket_condition_check (g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream)),
533 G_IO_IN | G_IO_OUT | G_IO_HUP),
538 /* TODO: hmm, hmm... */
544 "Underlying GIOStream returned 0 bytes on an async read");
545 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
546 g_error_free (error);
550 worker->read_buffer_cur_size += bytes_read;
551 if (worker->read_buffer_bytes_wanted == worker->read_buffer_cur_size)
553 /* OK, got what we asked for! */
554 if (worker->read_buffer_bytes_wanted == 16)
557 /* OK, got the header - determine how many more bytes are needed */
559 message_len = g_dbus_message_bytes_needed ((guchar *) worker->read_buffer,
562 if (message_len == -1)
564 g_warning ("_g_dbus_worker_do_read_cb: error determing bytes needed: %s", error->message);
565 _g_dbus_worker_emit_disconnected (worker, FALSE, error);
566 g_error_free (error);
570 worker->read_buffer_bytes_wanted = message_len;
571 _g_dbus_worker_do_read_unlocked (worker);
575 GDBusMessage *message;
578 /* TODO: use connection->priv->auth to decode the message */
580 message = g_dbus_message_new_from_blob ((guchar *) worker->read_buffer,
581 worker->read_buffer_cur_size,
582 worker->capabilities,
586 _g_dbus_worker_emit_disconnected (worker, FALSE, error);
587 g_error_free (error);
591 if (worker->read_fd_list != NULL)
593 g_dbus_message_set_unix_fd_list (message, worker->read_fd_list);
594 worker->read_fd_list = NULL;
597 if (G_UNLIKELY (_g_dbus_debug_message ()))
600 g_print ("========================================================================\n"
601 "GDBus-debug:Message:\n"
602 " <<<< RECEIVED D-Bus message (%" G_GSIZE_FORMAT " bytes)\n",
603 worker->read_buffer_cur_size);
604 s = g_dbus_message_print (message, 2);
607 s = hexdump (worker->read_buffer, worker->read_buffer_cur_size, 2);
612 /* yay, got a message, go deliver it */
613 _g_dbus_worker_emit_message (worker, message);
614 g_object_unref (message);
616 /* start reading another message! */
617 worker->read_buffer_bytes_wanted = 0;
618 worker->read_buffer_cur_size = 0;
619 _g_dbus_worker_do_read_unlocked (worker);
624 /* didn't get all the bytes we requested - so repeat the request... */
625 _g_dbus_worker_do_read_unlocked (worker);
629 g_mutex_unlock (worker->read_lock);
631 /* gives up the reference acquired when calling g_input_stream_read_async() */
632 _g_dbus_worker_unref (worker);
635 /* called in private thread shared by all GDBusConnection instances (with read-lock held) */
637 _g_dbus_worker_do_read_unlocked (GDBusWorker *worker)
639 /* if bytes_wanted is zero, it means start reading a message */
640 if (worker->read_buffer_bytes_wanted == 0)
642 worker->read_buffer_cur_size = 0;
643 worker->read_buffer_bytes_wanted = 16;
646 /* ensure we have a (big enough) buffer */
647 if (worker->read_buffer == NULL || worker->read_buffer_bytes_wanted > worker->read_buffer_allocated_size)
649 /* TODO: 4096 is randomly chosen; might want a better chosen default minimum */
650 worker->read_buffer_allocated_size = MAX (worker->read_buffer_bytes_wanted, 4096);
651 worker->read_buffer = g_realloc (worker->read_buffer, worker->read_buffer_allocated_size);
654 if (worker->socket == NULL)
655 g_input_stream_read_async (g_io_stream_get_input_stream (worker->stream),
656 worker->read_buffer + worker->read_buffer_cur_size,
657 worker->read_buffer_bytes_wanted - worker->read_buffer_cur_size,
660 (GAsyncReadyCallback) _g_dbus_worker_do_read_cb,
661 _g_dbus_worker_ref (worker));
664 worker->read_ancillary_messages = NULL;
665 worker->read_num_ancillary_messages = 0;
666 _g_socket_read_with_control_messages (worker->socket,
667 worker->read_buffer + worker->read_buffer_cur_size,
668 worker->read_buffer_bytes_wanted - worker->read_buffer_cur_size,
669 &worker->read_ancillary_messages,
670 &worker->read_num_ancillary_messages,
673 (GAsyncReadyCallback) _g_dbus_worker_do_read_cb,
674 _g_dbus_worker_ref (worker));
678 /* called in private thread shared by all GDBusConnection instances (without read-lock held) */
680 _g_dbus_worker_do_read (GDBusWorker *worker)
682 g_mutex_lock (worker->read_lock);
683 _g_dbus_worker_do_read_unlocked (worker);
684 g_mutex_unlock (worker->read_lock);
687 /* ---------------------------------------------------------------------------------------------------- */
689 struct _MessageToWriteData
691 GDBusMessage *message;
697 message_to_write_data_free (MessageToWriteData *data)
699 g_object_unref (data->message);
704 /* ---------------------------------------------------------------------------------------------------- */
706 /* called in private thread shared by all GDBusConnection instances (with write-lock held) */
708 write_message (GDBusWorker *worker,
709 MessageToWriteData *data,
714 g_return_val_if_fail (data->blob_size > 16, FALSE);
718 /* First, the initial 16 bytes - special case UNIX sockets here
719 * since it may involve writing an ancillary message with file
724 GOutputVector vector;
725 GSocketControlMessage *message;
726 GUnixFDList *fd_list;
727 gssize bytes_written;
729 fd_list = g_dbus_message_get_unix_fd_list (data->message);
734 if (!G_IS_UNIX_CONNECTION (worker->stream))
738 G_IO_ERROR_INVALID_ARGUMENT,
739 "Tried sending a file descriptor on unsupported stream of type %s",
740 g_type_name (G_TYPE_FROM_INSTANCE (worker->stream)));
743 else if (!(worker->capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING))
745 g_set_error_literal (error,
747 G_IO_ERROR_INVALID_ARGUMENT,
748 "Tried sending a file descriptor but remote peer does not support this capability");
751 message = g_unix_fd_message_new_with_fd_list (fd_list);
754 vector.buffer = data->blob;
757 bytes_written = g_socket_send_message (worker->socket,
761 message != NULL ? &message : NULL,
762 message != NULL ? 1 : 0,
766 if (bytes_written == -1)
768 g_prefix_error (error, _("Error writing first 16 bytes of message to socket: "));
770 g_object_unref (message);
774 g_object_unref (message);
776 if (bytes_written < 16)
778 /* TODO: I think this needs to be handled ... are we guaranteed that the ancillary
781 g_assert_not_reached ();
785 /* write the first 16 bytes (guaranteed to return an error if everything can't be written) */
786 if (!g_output_stream_write_all (g_io_stream_get_output_stream (worker->stream),
787 (const gchar *) data->blob,
789 NULL, /* bytes_written */
790 worker->cancellable, /* cancellable */
795 /* Then write the rest of the message (guaranteed to return an error if everything can't be written) */
796 if (!g_output_stream_write_all (g_io_stream_get_output_stream (worker->stream),
797 (const gchar *) data->blob + 16,
798 data->blob_size - 16,
799 NULL, /* bytes_written */
800 worker->cancellable, /* cancellable */
806 if (G_UNLIKELY (_g_dbus_debug_message ()))
809 g_print ("========================================================================\n"
810 "GDBus-debug:Message:\n"
811 " >>>> SENT D-Bus message (%" G_GSIZE_FORMAT " bytes)\n",
813 s = g_dbus_message_print (data->message, 2);
816 s = hexdump (data->blob, data->blob_size, 2);
825 /* ---------------------------------------------------------------------------------------------------- */
827 /* called in private thread shared by all GDBusConnection instances (without write-lock held) */
829 write_message_in_idle_cb (gpointer user_data)
831 GDBusWorker *worker = user_data;
832 gboolean more_writes_are_pending;
833 MessageToWriteData *data;
836 g_mutex_lock (worker->write_lock);
838 data = g_queue_pop_head (worker->write_queue);
839 g_assert (data != NULL);
842 if (!write_message (worker,
847 _g_dbus_worker_emit_disconnected (worker, TRUE, error);
848 g_error_free (error);
850 message_to_write_data_free (data);
852 more_writes_are_pending = (g_queue_get_length (worker->write_queue) > 0);
854 worker->write_is_pending = more_writes_are_pending;
855 g_mutex_unlock (worker->write_lock);
857 return more_writes_are_pending;
860 /* ---------------------------------------------------------------------------------------------------- */
862 /* can be called from any thread - steals blob */
864 _g_dbus_worker_send_message (GDBusWorker *worker,
865 GDBusMessage *message,
869 MessageToWriteData *data;
871 g_return_if_fail (G_IS_DBUS_MESSAGE (message));
872 g_return_if_fail (blob != NULL);
873 g_return_if_fail (blob_len > 16);
875 data = g_new0 (MessageToWriteData, 1);
876 data->message = g_object_ref (message);
877 data->blob = blob; /* steal! */
878 data->blob_size = blob_len;
880 g_mutex_lock (worker->write_lock);
881 g_queue_push_tail (worker->write_queue, data);
882 if (!worker->write_is_pending)
884 GSource *idle_source;
886 worker->write_is_pending = TRUE;
888 idle_source = g_idle_source_new ();
889 g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
890 g_source_set_callback (idle_source,
891 write_message_in_idle_cb,
892 _g_dbus_worker_ref (worker),
893 (GDestroyNotify) _g_dbus_worker_unref);
894 g_source_attach (idle_source, shared_thread_data->context);
895 g_source_unref (idle_source);
897 g_mutex_unlock (worker->write_lock);
900 /* ---------------------------------------------------------------------------------------------------- */
903 _g_dbus_worker_thread_begin_func (gpointer user_data)
905 GDBusWorker *worker = user_data;
907 worker->thread = g_thread_self ();
910 _g_dbus_worker_do_read (worker);
914 _g_dbus_worker_new (GIOStream *stream,
915 GDBusCapabilityFlags capabilities,
916 GDBusWorkerMessageReceivedCallback message_received_callback,
917 GDBusWorkerDisconnectedCallback disconnected_callback,
922 g_return_val_if_fail (G_IS_IO_STREAM (stream), NULL);
923 g_return_val_if_fail (message_received_callback != NULL, NULL);
924 g_return_val_if_fail (disconnected_callback != NULL, NULL);
926 worker = g_new0 (GDBusWorker, 1);
927 worker->ref_count = 1;
929 worker->read_lock = g_mutex_new ();
930 worker->message_received_callback = message_received_callback;
931 worker->disconnected_callback = disconnected_callback;
932 worker->user_data = user_data;
933 worker->stream = g_object_ref (stream);
934 worker->capabilities = capabilities;
935 worker->cancellable = g_cancellable_new ();
937 worker->write_lock = g_mutex_new ();
938 worker->write_queue = g_queue_new ();
940 if (G_IS_SOCKET_CONNECTION (worker->stream))
941 worker->socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (worker->stream));
943 _g_dbus_shared_thread_ref (_g_dbus_worker_thread_begin_func, worker);
948 /* This can be called from any thread - frees worker - guarantees no callbacks
949 * will ever be issued again
952 _g_dbus_worker_stop (GDBusWorker *worker)
954 /* If we're called in the worker thread it means we are called from
955 * a worker callback. This is fine, we just can't lock in that case since
956 * we're already holding the lock...
958 if (g_thread_self () != worker->thread)
959 g_mutex_lock (worker->read_lock);
960 worker->stopped = TRUE;
961 if (g_thread_self () != worker->thread)
962 g_mutex_unlock (worker->read_lock);
964 g_cancellable_cancel (worker->cancellable);
965 _g_dbus_worker_unref (worker);
968 #define G_DBUS_DEBUG_AUTHENTICATION (1<<0)
969 #define G_DBUS_DEBUG_MESSAGE (1<<1)
970 #define G_DBUS_DEBUG_ALL 0xffffffff
971 static gint _gdbus_debug_flags = 0;
974 _g_dbus_debug_authentication (void)
976 _g_dbus_initialize ();
977 return (_gdbus_debug_flags & G_DBUS_DEBUG_AUTHENTICATION) != 0;
981 _g_dbus_debug_message (void)
983 _g_dbus_initialize ();
984 return (_gdbus_debug_flags & G_DBUS_DEBUG_MESSAGE) != 0;
988 * _g_dbus_initialize:
990 * Does various one-time init things such as
992 * - registering the G_DBUS_ERROR error domain
993 * - parses the G_DBUS_DEBUG environment variable
996 _g_dbus_initialize (void)
998 static volatile gsize initialized = 0;
1000 if (g_once_init_enter (&initialized))
1002 volatile GQuark g_dbus_error_domain;
1005 g_dbus_error_domain = G_DBUS_ERROR;
1007 debug = g_getenv ("G_DBUS_DEBUG");
1012 tokens = g_strsplit (debug, ",", 0);
1013 for (n = 0; tokens[n] != NULL; n++)
1015 if (g_strcmp0 (tokens[n], "authentication") == 0)
1016 _gdbus_debug_flags |= G_DBUS_DEBUG_AUTHENTICATION;
1017 else if (g_strcmp0 (tokens[n], "message") == 0)
1018 _gdbus_debug_flags |= G_DBUS_DEBUG_MESSAGE;
1019 else if (g_strcmp0 (tokens[n], "all") == 0)
1020 _gdbus_debug_flags |= G_DBUS_DEBUG_ALL;
1022 g_strfreev (tokens);
1025 g_once_init_leave (&initialized, 1);
1029 /* ---------------------------------------------------------------------------------------------------- */
1032 _g_dbus_compute_complete_signature (GDBusArgInfo **args,
1033 gboolean include_parentheses)
1038 if (include_parentheses)
1039 s = g_string_new ("(");
1041 s = g_string_new ("");
1043 for (n = 0; args[n] != NULL; n++)
1044 g_string_append (s, args[n]->signature);
1046 if (include_parentheses)
1047 g_string_append_c (s, ')');
1049 return g_string_free (s, FALSE);
1052 #define __G_DBUS_PRIVATE_C__
1053 #include "gioaliasdef.c"