Adapt migration for files
[pidgin-git.git] / libpurple / dbus-server.c
blob66b717e9121f97903d2709b9a8aeb3b7e14c9da9
1 /*
2 * purple
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
24 #ifndef DBUS_API_SUBJECT_TO_CHANGE
25 #define DBUS_API_SUBJECT_TO_CHANGE
26 #endif
28 /* Allow the code below to see deprecated functions, so we can continue to
29 * export them via DBus. */
30 #undef PURPLE_DISABLE_DEPRECATED
32 #include "internal.h"
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
38 #include "account.h"
39 #include "buddylist.h"
40 #include "conversation.h"
41 #include "dbus-purple.h"
42 #include "dbus-server.h"
43 #include "dbus-useful.h"
44 #include "dbus-bindings.h"
45 #include "debug.h"
46 #include "core.h"
47 #include "savedstatuses.h"
48 #include "smiley.h"
49 #include "smiley-list.h"
50 #include "util.h"
51 #include "xmlnode.h"
54 /**************************************************************************/
55 /* Purple DBUS pointer registration mechanism */
56 /**************************************************************************/
59 * Here we include the list of #PURPLE_DBUS_DEFINE_TYPE statements for
60 * all structs defined in purple. This file has been generated by the
61 * #dbus-analyze-types.py script.
64 #include "dbus-types.c"
67 * The following three hashtables map are used to translate between
68 * pointers (nodes) and the corresponding handles (ids).
71 static GHashTable *map_node_id;
72 static GHashTable *map_id_node;
73 static GHashTable *map_id_type;
75 static gchar *init_error;
76 static int dbus_request_name_reply = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
78 gboolean purple_dbus_is_owner(void)
80 return(DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER == dbus_request_name_reply);
84 * This function initializes the pointer-id traslation system. It
85 * creates the three above hashtables and defines parents of some types.
87 void
88 purple_dbus_init_ids(void)
90 map_id_node = g_hash_table_new(g_direct_hash, g_direct_equal);
91 map_id_type = g_hash_table_new(g_direct_hash, g_direct_equal);
92 map_node_id = g_hash_table_new(g_direct_hash, g_direct_equal);
94 PURPLE_DBUS_TYPE(PurpleBuddy)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
95 PURPLE_DBUS_TYPE(PurpleContact)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
96 PURPLE_DBUS_TYPE(PurpleChat)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
97 PURPLE_DBUS_TYPE(PurpleGroup)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
100 void
101 purple_dbus_register_pointer(gpointer node, PurpleDBusType *type)
103 static gint last_id = 0;
105 g_return_if_fail(map_node_id);
106 g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL);
108 last_id++;
109 g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id));
110 g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node);
111 g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type);
114 void
115 purple_dbus_unregister_pointer(gpointer node)
117 gpointer id = g_hash_table_lookup(map_node_id, node);
119 g_hash_table_remove(map_node_id, node);
120 g_hash_table_remove(map_id_node, GINT_TO_POINTER(id));
121 g_hash_table_remove(map_id_type, GINT_TO_POINTER(id));
124 gint
125 purple_dbus_pointer_to_id(gconstpointer node)
127 gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node));
128 if ((id == 0) && (node != NULL))
130 if (purple_debug_is_verbose())
131 purple_debug_warning("dbus",
132 "Need to register an object with the dbus subsystem."
133 " (If you are not a developer, please ignore this message.)\n");
134 return 0;
136 return id;
139 gpointer
140 purple_dbus_id_to_pointer(gint id, PurpleDBusType *type)
142 PurpleDBusType *objtype;
144 objtype = (PurpleDBusType*)g_hash_table_lookup(map_id_type,
145 GINT_TO_POINTER(id));
147 while (objtype != type && objtype != NULL)
148 objtype = objtype->parent;
150 if (objtype == type)
151 return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id));
152 else
153 return NULL;
156 gint
157 purple_dbus_pointer_to_id_error(gconstpointer ptr, DBusError *error)
159 gint id = purple_dbus_pointer_to_id(ptr);
161 if (ptr != NULL && id == 0)
162 dbus_set_error(error, "im.pidgin.purple.ObjectNotFound",
163 "The return object is not mapped (this is a Purple error)");
165 return id;
168 gpointer
169 purple_dbus_id_to_pointer_error(gint id, PurpleDBusType *type,
170 const char *typename, DBusError *error)
172 gpointer ptr = purple_dbus_id_to_pointer(id, type);
174 if (ptr == NULL && id != 0)
175 dbus_set_error(error, "im.pidgin.purple.InvalidHandle",
176 "%s object with ID = %i not found", typename, id);
178 return ptr;
182 /**************************************************************************/
183 /* Modified versions of some DBus functions */
184 /**************************************************************************/
186 dbus_bool_t
187 purple_dbus_message_get_args(DBusMessage *message,
188 DBusError *error, int first_arg_type, ...)
190 dbus_bool_t retval;
191 va_list var_args;
193 va_start(var_args, first_arg_type);
194 retval = purple_dbus_message_get_args_valist(message, error, first_arg_type, var_args);
195 va_end(var_args);
197 return retval;
200 dbus_bool_t
201 purple_dbus_message_get_args_valist(DBusMessage *message,
202 DBusError *error, int first_arg_type, va_list var_args)
204 DBusMessageIter iter;
206 dbus_message_iter_init(message, &iter);
207 return purple_dbus_message_iter_get_args_valist(&iter, error, first_arg_type, var_args);
210 dbus_bool_t
211 purple_dbus_message_iter_get_args(DBusMessageIter *iter,
212 DBusError *error, int first_arg_type, ...)
214 dbus_bool_t retval;
215 va_list var_args;
217 va_start(var_args, first_arg_type);
218 retval = purple_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args);
219 va_end(var_args);
221 return retval;
224 #define TYPE_IS_CONTAINER(typecode) \
225 ((typecode) == DBUS_TYPE_STRUCT || \
226 (typecode) == DBUS_TYPE_DICT_ENTRY || \
227 (typecode) == DBUS_TYPE_VARIANT || \
228 (typecode) == DBUS_TYPE_ARRAY)
231 dbus_bool_t
232 purple_dbus_message_iter_get_args_valist(DBusMessageIter *iter,
233 DBusError *error, int first_arg_type, va_list var_args)
235 int spec_type, msg_type, i;
237 spec_type = first_arg_type;
239 for (i = 0; spec_type != DBUS_TYPE_INVALID; i++)
241 msg_type = dbus_message_iter_get_arg_type(iter);
243 if (msg_type != spec_type)
245 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
246 "Argument %d is specified to be of type \"%i\", but "
247 "is actually of type \"%i\"\n", i,
248 spec_type, msg_type);
249 return FALSE;
252 if (!TYPE_IS_CONTAINER(spec_type))
254 gpointer ptr;
255 ptr = va_arg (var_args, gpointer);
256 dbus_message_iter_get_basic(iter, ptr);
258 else
260 DBusMessageIter *sub;
261 sub = va_arg (var_args, DBusMessageIter*);
262 dbus_message_iter_recurse(iter, sub);
263 purple_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub);
264 break; /* for testing only! */
267 spec_type = va_arg(var_args, int);
268 if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID)
270 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
271 "Message has only %d arguments, but more were expected", i);
272 return FALSE;
276 return TRUE;
281 /**************************************************************************/
282 /* Useful functions */
283 /**************************************************************************/
285 const char *purple_emptystr_to_null(const char *str)
287 if (str == NULL || str[0] == 0)
288 return NULL;
289 else
290 return str;
293 const char *
294 purple_null_to_emptystr(const char *s)
296 if (s)
297 return s;
298 else
299 return "";
302 dbus_int32_t *
303 purple_dbusify_GList(GList *list, dbus_int32_t *len)
305 dbus_int32_t *array;
306 int i;
307 GList *elem;
309 *len = g_list_length(list);
310 array = g_new0(dbus_int32_t, *len);
311 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
312 array[i] = purple_dbus_pointer_to_id(elem->data);
314 return array;
317 dbus_int32_t *
318 purple_dbusify_GSList(GSList *list, dbus_int32_t *len)
320 dbus_int32_t *array;
321 int i;
322 GSList *elem;
324 *len = g_slist_length(list);
325 array = g_new0(dbus_int32_t, *len);
326 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
327 array[i] = purple_dbus_pointer_to_id(elem->data);
329 return array;
332 gpointer *
333 purple_GList_to_array(GList *list, dbus_int32_t *len)
335 gpointer *array;
336 int i;
337 GList *elem;
339 *len = g_list_length(list);
340 array = g_new0(gpointer, *len);
341 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
342 array[i] = elem->data;
344 return array;
347 gpointer *
348 purple_GSList_to_array(GSList *list, dbus_int32_t *len)
350 gpointer *array;
351 int i;
352 GSList *elem;
354 *len = g_slist_length(list);
355 array = g_new0(gpointer, *len);
356 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
357 array[i] = elem->data;
359 return array;
362 GHashTable *
363 purple_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error)
365 GHashTable *hash;
367 /* we do not need to destroy strings because they are part of the message */
368 hash = g_hash_table_new(g_str_hash, g_str_equal);
370 do {
371 char *key, *value;
372 DBusMessageIter subiter;
374 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
375 goto error;
376 /* With all due respect to Dijkstra,
377 * this goto is for exception
378 * handling, and it is ok because it
379 * avoids duplication of the code
380 * responsible for destroying the hash
381 * table. Exceptional instructions
382 * for exceptional situations.
385 dbus_message_iter_recurse(iter, &subiter);
386 if (!purple_dbus_message_iter_get_args(&subiter, error,
387 DBUS_TYPE_STRING, &key,
388 DBUS_TYPE_STRING, &value,
389 DBUS_TYPE_INVALID))
390 goto error; /* same here */
392 g_hash_table_insert(hash, key, value);
393 } while (dbus_message_iter_next(iter));
395 return hash;
397 error:
398 g_hash_table_destroy(hash);
399 return NULL;
402 /**************************************************************/
403 /* DBus bindings ... */
404 /**************************************************************/
406 static DBusConnection *purple_dbus_connection;
408 DBusConnection *
409 purple_dbus_get_connection(void)
411 return purple_dbus_connection;
414 #include "dbus-bindings.c"
415 #include "dbus-signals.c"
417 static gboolean
418 purple_dbus_dispatch_cb(DBusConnection *connection,
419 DBusMessage *message, void *user_data)
421 const char *name;
422 PurpleDBusBinding *bindings;
423 int i;
425 bindings = (PurpleDBusBinding*) user_data;
427 if (!dbus_message_has_path(message, PURPLE_DBUS_PATH))
428 return FALSE;
430 name = dbus_message_get_member(message);
432 if (name == NULL)
433 return FALSE;
435 if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
436 return FALSE;
438 for (i = 0; bindings[i].name; i++)
439 if (!strcmp(name, bindings[i].name))
441 DBusMessage *reply;
442 DBusError error;
444 dbus_error_init(&error);
446 reply = bindings[i].handler(message, &error);
448 if (reply == NULL && dbus_error_is_set(&error))
449 reply = dbus_message_new_error (message,
450 error.name, error.message);
452 if (reply != NULL)
454 dbus_connection_send(connection, reply, NULL);
455 dbus_message_unref(reply);
458 return TRUE; /* return reply! */
461 return FALSE;
465 static const char *
466 dbus_gettext(const char **ptr)
468 const char *text = *ptr;
469 *ptr += strlen(text) + 1;
470 return text;
473 static void
474 purple_dbus_introspect_cb(GList **bindings_list, void *bindings)
476 *bindings_list = g_list_prepend(*bindings_list, bindings);
479 static DBusMessage *purple_dbus_introspect(DBusMessage *message)
481 DBusMessage *reply;
482 GString *str;
483 GList *bindings_list, *node;
484 const char *signals;
485 const char *type;
486 const char *pointer_type;
488 str = g_string_sized_new(0x1000); /* TODO: why this size? */
490 g_string_append(str, "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n");
491 g_string_append_printf(str, "<node name='%s'>\n", PURPLE_DBUS_PATH);
492 g_string_append(str, " <interface name='org.freedesktop.DBus.Introspectable'>\n <method name='Introspect'>\n <arg name='data' direction='out' type='s'/>\n </method>\n </interface>\n\n");
494 g_string_append_printf(str, " <interface name='%s'>\n", PURPLE_DBUS_INTERFACE);
496 bindings_list = NULL;
497 purple_signal_emit(purple_dbus_get_handle(), "dbus-introspect", &bindings_list);
499 for (node = bindings_list; node; node = node->next)
501 PurpleDBusBinding *bindings;
502 int i;
504 bindings = (PurpleDBusBinding*)node->data;
506 for (i = 0; bindings[i].name; i++)
508 const char *text;
510 g_string_append_printf(str, " <method name='%s'>\n", bindings[i].name);
512 text = bindings[i].parameters;
513 while (*text)
515 const char *name, *direction, *type;
517 direction = dbus_gettext(&text);
518 type = dbus_gettext(&text);
519 name = dbus_gettext(&text);
521 g_string_append_printf(str,
522 " <arg name='%s' type='%s' direction='%s'/>\n",
523 name, type, direction);
525 g_string_append(str, " </method>\n");
529 if (sizeof(int) == sizeof(dbus_int32_t))
530 pointer_type = "type='i'";
531 else
532 pointer_type = "type='x'";
534 signals = dbus_signals;
535 while ((type = strstr(signals, "type='p'")) != NULL) {
536 g_string_append_len(str, signals, type - signals);
537 g_string_append(str, pointer_type);
538 signals = type + sizeof("type='p'") - 1;
540 g_string_append(str, signals);
542 g_string_append(str, " </interface>\n</node>\n");
544 reply = dbus_message_new_method_return(message);
545 dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str),
546 DBUS_TYPE_INVALID);
547 g_string_free(str, TRUE);
548 g_list_free(bindings_list);
550 return reply;
553 static DBusHandlerResult
554 purple_dbus_dispatch(DBusConnection *connection,
555 DBusMessage *message, void *user_data)
557 if (purple_signal_emit_return_1(purple_dbus_get_handle(),
558 "dbus-method-called", connection, message))
559 return DBUS_HANDLER_RESULT_HANDLED;
561 if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect") &&
562 dbus_message_has_path(message, PURPLE_DBUS_PATH))
564 DBusMessage *reply;
565 reply = purple_dbus_introspect(message);
566 dbus_connection_send (connection, reply, NULL);
567 dbus_message_unref(reply);
568 return DBUS_HANDLER_RESULT_HANDLED;
571 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
574 void
575 purple_dbus_register_bindings(void *handle, PurpleDBusBinding *bindings)
577 purple_signal_connect(purple_dbus_get_handle(), "dbus-method-called",
578 handle,
579 PURPLE_CALLBACK(purple_dbus_dispatch_cb),
580 bindings);
581 purple_signal_connect(purple_dbus_get_handle(), "dbus-introspect",
582 handle,
583 PURPLE_CALLBACK(purple_dbus_introspect_cb),
584 bindings);
587 static void
588 purple_dbus_dispatch_init(void)
590 static DBusObjectPathVTable vtable = {NULL, &purple_dbus_dispatch, NULL, NULL, NULL, NULL};
591 DBusError error;
593 dbus_error_init(&error);
594 purple_dbus_connection = dbus_bus_get(DBUS_BUS_STARTER, &error);
596 if (purple_dbus_connection == NULL)
598 init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message);
599 dbus_error_free(&error);
600 return;
603 /* Do not allow libdbus to exit on connection failure (This may
604 work around random exit(1) on SIGPIPE errors) */
605 dbus_connection_set_exit_on_disconnect (purple_dbus_connection, FALSE);
607 if (!dbus_connection_register_object_path(purple_dbus_connection,
608 PURPLE_DBUS_PATH, &vtable, NULL))
610 init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name);
611 dbus_error_free(&error);
612 return;
615 dbus_request_name_reply = dbus_bus_request_name(purple_dbus_connection,
616 PURPLE_DBUS_SERVICE, 0, &error);
618 if (dbus_error_is_set(&error))
620 dbus_connection_unref(purple_dbus_connection);
621 purple_dbus_connection = NULL;
622 init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name);
623 dbus_error_free(&error);
624 return;
627 dbus_connection_setup_with_g_main(purple_dbus_connection, NULL);
629 purple_signal_register(purple_dbus_get_handle(), "dbus-method-called",
630 purple_marshal_BOOLEAN__POINTER_POINTER,
631 G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_POINTER);
633 purple_signal_register(purple_dbus_get_handle(), "dbus-introspect",
634 purple_marshal_VOID__POINTER, G_TYPE_NONE, 1,
635 G_TYPE_POINTER); /* pointer to a pointer */
637 PURPLE_DBUS_REGISTER_BINDINGS(purple_dbus_get_handle());
639 if (purple_debug_is_verbose())
640 purple_debug_misc("dbus", "initialized");
645 /**************************************************************************/
646 /* Signals */
647 /**************************************************************************/
651 static char *
652 purple_dbus_convert_signal_name(const char *purple_name)
654 int purple_index, g_index;
655 char *g_name = g_new(char, strlen(purple_name) + 1);
656 gboolean capitalize_next = TRUE;
658 for (purple_index = g_index = 0; purple_name[purple_index]; purple_index++)
659 if (purple_name[purple_index] != '-' && purple_name[purple_index] != '_')
661 if (capitalize_next)
662 g_name[g_index++] = g_ascii_toupper(purple_name[purple_index]);
663 else
664 g_name[g_index++] = purple_name[purple_index];
665 capitalize_next = FALSE;
666 } else
667 capitalize_next = TRUE;
669 g_name[g_index] = 0;
671 return g_name;
674 #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type))
676 static gboolean
677 purple_dbus_message_append_values(DBusMessageIter *iter,
678 int number, GType *types, va_list data)
680 int i;
681 gboolean error = FALSE;
683 for (i = 0; i < number; i++)
685 const char *str;
686 int id;
687 gint xint;
688 guint xuint;
689 gint64 xint64;
690 guint64 xuint64;
691 gboolean xboolean;
692 gpointer ptr = NULL;
693 gpointer val;
694 #if 0
695 if (purple_value_is_outgoing(purple_values[i]))
697 ptr = my_arg(gpointer);
698 g_return_val_if_fail(ptr, TRUE);
700 #endif
701 switch (types[i])
703 case G_TYPE_INT:
704 xint = my_arg(gint);
705 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
706 break;
707 case G_TYPE_UINT:
708 xuint = my_arg(guint);
709 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint);
710 break;
711 case G_TYPE_INT64:
712 xint64 = my_arg(gint64);
713 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT64, &xint64);
714 break;
715 case G_TYPE_UINT64:
716 xuint64 = my_arg(guint64);
717 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &xuint64);
718 break;
719 case G_TYPE_BOOLEAN:
720 xboolean = my_arg(gboolean);
721 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean);
722 break;
723 case G_TYPE_STRING:
724 str = purple_null_to_emptystr(my_arg(char*));
725 if (!g_utf8_validate(str, -1, NULL)) {
726 gchar *tmp;
727 purple_debug_error("dbus", "Invalid UTF-8 string passed to signal, emitting salvaged string!\n");
728 tmp = purple_utf8_salvage(str);
729 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &tmp);
730 g_free(tmp);
731 } else {
732 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
734 break;
735 default:
736 if (G_TYPE_IS_OBJECT(types[i]) ||
737 G_TYPE_IS_BOXED(types[i]) ||
738 types[i] == G_TYPE_POINTER )
740 val = my_arg(gpointer);
741 id = purple_dbus_pointer_to_id(val);
742 if (id == 0 && val != NULL)
743 error = TRUE; /* Some error happened. */
744 dbus_message_iter_append_basic(iter,
745 (sizeof(id) == sizeof(dbus_int32_t)) ? DBUS_TYPE_INT32 : DBUS_TYPE_INT64, &id);
747 else if (G_TYPE_IS_ENUM(types[i]))
749 xint = my_arg(gint);
750 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
752 else /* no conversion implemented */
754 g_return_val_if_reached(TRUE);
758 return error;
761 #undef my_arg
763 void
764 purple_dbus_signal_emit_purple(const char *name, int num_values,
765 GType *types, va_list vargs)
767 DBusMessage *signal;
768 DBusMessageIter iter;
769 char *newname;
771 #if 0 /* this is noisy with no dbus connection */
772 g_return_if_fail(purple_dbus_connection);
773 #else
774 if (purple_dbus_connection == NULL)
775 return;
776 #endif
780 * The test below is a hack that prevents our "dbus-method-called"
781 * signal from being propagated to dbus. What we really need is a
782 * flag for each signal that states whether this signal is to be
783 * dbus-propagated or not.
785 if (!strcmp(name, "dbus-method-called"))
786 return;
788 newname = purple_dbus_convert_signal_name(name);
789 signal = dbus_message_new_signal(PURPLE_DBUS_PATH, PURPLE_DBUS_INTERFACE, newname);
790 dbus_message_iter_init_append(signal, &iter);
792 if (purple_dbus_message_append_values(&iter, num_values, types, vargs))
793 if (purple_debug_is_verbose())
794 purple_debug_warning("dbus",
795 "The signal \"%s\" caused some dbus error."
796 " (If you are not a developer, please ignore this message.)\n",
797 name);
799 dbus_connection_send(purple_dbus_connection, signal, NULL);
801 g_free(newname);
802 dbus_message_unref(signal);
805 const char *
806 purple_dbus_get_init_error(void)
808 return init_error;
811 void *
812 purple_dbus_get_handle(void)
814 static int handle;
816 return &handle;
819 void
820 purple_dbus_init(void)
822 if (g_thread_supported())
823 dbus_g_thread_init();
825 purple_dbus_init_ids();
827 g_free(init_error);
828 init_error = NULL;
829 purple_dbus_dispatch_init();
830 if (init_error != NULL)
831 purple_debug_error("dbus", "%s\n", init_error);
834 void
835 purple_dbus_uninit(void)
837 DBusError error;
838 if (!purple_dbus_connection)
839 return;
841 dbus_error_init(&error);
842 dbus_connection_unregister_object_path(purple_dbus_connection, PURPLE_DBUS_PATH);
843 dbus_bus_release_name(purple_dbus_connection, PURPLE_DBUS_SERVICE, &error);
844 dbus_error_free(&error);
845 dbus_connection_unref(purple_dbus_connection);
846 purple_dbus_connection = NULL;
847 purple_signals_disconnect_by_handle(purple_dbus_get_handle());
848 g_free(init_error);
849 init_error = NULL;