Doh. Upon further investigation I think these translations were made
[pidgin-git.git] / libpurple / dbus-server.c
blob86b8f5e1225566681df6637b3208d31f613c4a9f
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 "blist.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 "util.h"
50 #include "value.h"
51 #include "xmlnode.h"
54 /**************************************************************************/
55 /** @name 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);
83 /**
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 /** @name 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 /** @name Useful functions */
283 /**************************************************************************/
285 const char *empty_to_null(const char *str)
287 if (str == NULL || str[0] == 0)
288 return NULL;
289 else
290 return str;
293 const char *
294 null_to_empty(const char *s)
296 if (s)
297 return s;
298 else
299 return "";
302 dbus_int32_t *
303 purple_dbusify_GList(GList *list, gboolean free_memory, 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 if (free_memory)
315 g_list_free(list);
317 return array;
320 dbus_int32_t *
321 purple_dbusify_GSList(GSList *list, gboolean free_memory, dbus_int32_t *len)
323 dbus_int32_t *array;
324 int i;
325 GSList *elem;
327 *len = g_slist_length(list);
328 array = g_new0(dbus_int32_t, *len);
329 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
330 array[i] = purple_dbus_pointer_to_id(elem->data);
332 if (free_memory)
333 g_slist_free(list);
335 return array;
338 gpointer *
339 purple_GList_to_array(GList *list, gboolean free_memory, dbus_int32_t *len)
341 gpointer *array;
342 int i;
343 GList *elem;
345 *len = g_list_length(list);
346 array = g_new0(gpointer, *len);
347 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
348 array[i] = elem->data;
350 if (free_memory)
351 g_list_free(list);
353 return array;
356 gpointer *
357 purple_GSList_to_array(GSList *list, gboolean free_memory, dbus_int32_t *len)
359 gpointer *array;
360 int i;
361 GSList *elem;
363 *len = g_slist_length(list);
364 array = g_new0(gpointer, *len);
365 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
366 array[i] = elem->data;
368 if (free_memory)
369 g_slist_free(list);
371 return array;
374 GHashTable *
375 purple_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error)
377 GHashTable *hash;
379 /* we do not need to destroy strings because they are part of the message */
380 hash = g_hash_table_new(g_str_hash, g_str_equal);
382 do {
383 char *key, *value;
384 DBusMessageIter subiter;
386 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
387 goto error;
388 /* With all due respect to Dijkstra,
389 * this goto is for exception
390 * handling, and it is ok because it
391 * avoids duplication of the code
392 * responsible for destroying the hash
393 * table. Exceptional instructions
394 * for exceptional situations.
397 dbus_message_iter_recurse(iter, &subiter);
398 if (!purple_dbus_message_iter_get_args(&subiter, error,
399 DBUS_TYPE_STRING, &key,
400 DBUS_TYPE_STRING, &value,
401 DBUS_TYPE_INVALID))
402 goto error; /* same here */
404 g_hash_table_insert(hash, key, value);
405 } while (dbus_message_iter_next(iter));
407 return hash;
409 error:
410 g_hash_table_destroy(hash);
411 return NULL;
414 /**************************************************************/
415 /* DBus bindings ... */
416 /**************************************************************/
418 static DBusConnection *purple_dbus_connection;
420 DBusConnection *
421 purple_dbus_get_connection(void)
423 return purple_dbus_connection;
426 #include "dbus-bindings.c"
427 #include "dbus-signals.c"
429 static gboolean
430 purple_dbus_dispatch_cb(DBusConnection *connection,
431 DBusMessage *message, void *user_data)
433 const char *name;
434 PurpleDBusBinding *bindings;
435 int i;
437 bindings = (PurpleDBusBinding*) user_data;
439 if (!dbus_message_has_path(message, DBUS_PATH_PURPLE))
440 return FALSE;
442 name = dbus_message_get_member(message);
444 if (name == NULL)
445 return FALSE;
447 if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
448 return FALSE;
450 for (i = 0; bindings[i].name; i++)
451 if (!strcmp(name, bindings[i].name))
453 DBusMessage *reply;
454 DBusError error;
456 dbus_error_init(&error);
458 reply = bindings[i].handler(message, &error);
460 if (reply == NULL && dbus_error_is_set(&error))
461 reply = dbus_message_new_error (message,
462 error.name, error.message);
464 if (reply != NULL)
466 dbus_connection_send(connection, reply, NULL);
467 dbus_message_unref(reply);
470 return TRUE; /* return reply! */
473 return FALSE;
477 static const char *
478 dbus_gettext(const char **ptr)
480 const char *text = *ptr;
481 *ptr += strlen(text) + 1;
482 return text;
485 static void
486 purple_dbus_introspect_cb(GList **bindings_list, void *bindings)
488 *bindings_list = g_list_prepend(*bindings_list, bindings);
491 static DBusMessage *purple_dbus_introspect(DBusMessage *message)
493 DBusMessage *reply;
494 GString *str;
495 GList *bindings_list, *node;
496 const char *signals;
497 const char *type;
498 const char *pointer_type;
500 str = g_string_sized_new(0x1000); /* TODO: why this size? */
502 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");
503 g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_PURPLE);
504 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");
506 g_string_append_printf(str, " <interface name='%s'>\n", DBUS_INTERFACE_PURPLE);
508 bindings_list = NULL;
509 purple_signal_emit(purple_dbus_get_handle(), "dbus-introspect", &bindings_list);
511 for (node = bindings_list; node; node = node->next)
513 PurpleDBusBinding *bindings;
514 int i;
516 bindings = (PurpleDBusBinding*)node->data;
518 for (i = 0; bindings[i].name; i++)
520 const char *text;
522 g_string_append_printf(str, " <method name='%s'>\n", bindings[i].name);
524 text = bindings[i].parameters;
525 while (*text)
527 const char *name, *direction, *type;
529 direction = dbus_gettext(&text);
530 type = dbus_gettext(&text);
531 name = dbus_gettext(&text);
533 g_string_append_printf(str,
534 " <arg name='%s' type='%s' direction='%s'/>\n",
535 name, type, direction);
537 g_string_append(str, " </method>\n");
541 if (sizeof(int) == sizeof(dbus_int32_t))
542 pointer_type = "type='i'";
543 else
544 pointer_type = "type='x'";
546 signals = dbus_signals;
547 while ((type = strstr(signals, "type='p'")) != NULL) {
548 g_string_append_len(str, signals, type - signals);
549 g_string_append(str, pointer_type);
550 signals = type + sizeof("type='p'") - 1;
552 g_string_append(str, signals);
554 g_string_append(str, " </interface>\n</node>\n");
556 reply = dbus_message_new_method_return(message);
557 dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str),
558 DBUS_TYPE_INVALID);
559 g_string_free(str, TRUE);
560 g_list_free(bindings_list);
562 return reply;
565 static DBusHandlerResult
566 purple_dbus_dispatch(DBusConnection *connection,
567 DBusMessage *message, void *user_data)
569 if (purple_signal_emit_return_1(purple_dbus_get_handle(),
570 "dbus-method-called", connection, message))
571 return DBUS_HANDLER_RESULT_HANDLED;
573 if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect") &&
574 dbus_message_has_path(message, DBUS_PATH_PURPLE))
576 DBusMessage *reply;
577 reply = purple_dbus_introspect(message);
578 dbus_connection_send (connection, reply, NULL);
579 dbus_message_unref(reply);
580 return DBUS_HANDLER_RESULT_HANDLED;
583 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
586 void
587 purple_dbus_register_bindings(void *handle, PurpleDBusBinding *bindings)
589 purple_signal_connect(purple_dbus_get_handle(), "dbus-method-called",
590 handle,
591 PURPLE_CALLBACK(purple_dbus_dispatch_cb),
592 bindings);
593 purple_signal_connect(purple_dbus_get_handle(), "dbus-introspect",
594 handle,
595 PURPLE_CALLBACK(purple_dbus_introspect_cb),
596 bindings);
599 static void
600 purple_dbus_dispatch_init(void)
602 static DBusObjectPathVTable vtable = {NULL, &purple_dbus_dispatch, NULL, NULL, NULL, NULL};
603 DBusError error;
605 dbus_error_init(&error);
606 purple_dbus_connection = dbus_bus_get(DBUS_BUS_STARTER, &error);
608 if (purple_dbus_connection == NULL)
610 init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message);
611 dbus_error_free(&error);
612 return;
615 /* Do not allow libdbus to exit on connection failure (This may
616 work around random exit(1) on SIGPIPE errors) */
617 dbus_connection_set_exit_on_disconnect (purple_dbus_connection, FALSE);
619 if (!dbus_connection_register_object_path(purple_dbus_connection,
620 DBUS_PATH_PURPLE, &vtable, NULL))
622 init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name);
623 dbus_error_free(&error);
624 return;
627 dbus_request_name_reply = dbus_bus_request_name(purple_dbus_connection,
628 DBUS_SERVICE_PURPLE, 0, &error);
630 if (dbus_error_is_set(&error))
632 dbus_connection_unref(purple_dbus_connection);
633 purple_dbus_connection = NULL;
634 init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name);
635 dbus_error_free(&error);
636 return;
639 dbus_connection_setup_with_g_main(purple_dbus_connection, NULL);
641 purple_debug_misc("dbus", "okkk\n");
643 purple_signal_register(purple_dbus_get_handle(), "dbus-method-called",
644 purple_marshal_BOOLEAN__POINTER_POINTER,
645 purple_value_new(PURPLE_TYPE_BOOLEAN), 2,
646 purple_value_new(PURPLE_TYPE_POINTER),
647 purple_value_new(PURPLE_TYPE_POINTER));
649 purple_signal_register(purple_dbus_get_handle(), "dbus-introspect",
650 purple_marshal_VOID__POINTER, NULL, 1,
651 purple_value_new_outgoing(PURPLE_TYPE_POINTER));
653 PURPLE_DBUS_REGISTER_BINDINGS(purple_dbus_get_handle());
658 /**************************************************************************/
659 /** @name Signals */
660 /**************************************************************************/
664 static char *
665 purple_dbus_convert_signal_name(const char *purple_name)
667 int purple_index, g_index;
668 char *g_name = g_new(char, strlen(purple_name) + 1);
669 gboolean capitalize_next = TRUE;
671 for (purple_index = g_index = 0; purple_name[purple_index]; purple_index++)
672 if (purple_name[purple_index] != '-' && purple_name[purple_index] != '_')
674 if (capitalize_next)
675 g_name[g_index++] = g_ascii_toupper(purple_name[purple_index]);
676 else
677 g_name[g_index++] = purple_name[purple_index];
678 capitalize_next = FALSE;
679 } else
680 capitalize_next = TRUE;
682 g_name[g_index] = 0;
684 return g_name;
687 #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type))
689 static gboolean
690 purple_dbus_message_append_purple_values(DBusMessageIter *iter,
691 int number, PurpleValue **purple_values, va_list data)
693 int i;
694 gboolean error = FALSE;
696 for (i = 0; i < number; i++)
698 const char *str;
699 int id;
700 gint xint;
701 guint xuint;
702 gint64 xint64;
703 guint64 xuint64;
704 gboolean xboolean;
705 gpointer ptr = NULL;
706 gpointer val;
708 if (purple_value_is_outgoing(purple_values[i]))
710 ptr = my_arg(gpointer);
711 g_return_val_if_fail(ptr, TRUE);
714 switch (purple_values[i]->type)
716 case PURPLE_TYPE_INT:
717 case PURPLE_TYPE_ENUM:
718 xint = my_arg(gint);
719 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
720 break;
721 case PURPLE_TYPE_UINT:
722 xuint = my_arg(guint);
723 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint);
724 break;
725 case PURPLE_TYPE_INT64:
726 xint64 = my_arg(gint64);
727 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT64, &xint64);
728 break;
729 case PURPLE_TYPE_UINT64:
730 xuint64 = my_arg(guint64);
731 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &xuint64);
732 break;
733 case PURPLE_TYPE_BOOLEAN:
734 xboolean = my_arg(gboolean);
735 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean);
736 break;
737 case PURPLE_TYPE_STRING:
738 str = null_to_empty(my_arg(char*));
739 if (!g_utf8_validate(str, -1, NULL)) {
740 gchar *tmp;
741 purple_debug_error("dbus", "Invalid UTF-8 string passed to signal, emitting salvaged string!\n");
742 tmp = purple_utf8_salvage(str);
743 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &tmp);
744 g_free(tmp);
745 } else {
746 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
748 break;
749 case PURPLE_TYPE_SUBTYPE: /* registered pointers only! */
750 case PURPLE_TYPE_POINTER:
751 case PURPLE_TYPE_OBJECT:
752 case PURPLE_TYPE_BOXED:
753 val = my_arg(gpointer);
754 id = purple_dbus_pointer_to_id(val);
755 if (id == 0 && val != NULL)
756 error = TRUE; /* Some error happened. */
757 dbus_message_iter_append_basic(iter,
758 (sizeof(id) == sizeof(dbus_int32_t)) ? DBUS_TYPE_INT32 : DBUS_TYPE_INT64, &id);
759 break;
760 default: /* no conversion implemented */
761 g_return_val_if_reached(TRUE);
764 return error;
767 #undef my_arg
769 void
770 purple_dbus_signal_emit_purple(const char *name, int num_values,
771 PurpleValue **values, va_list vargs)
773 DBusMessage *signal;
774 DBusMessageIter iter;
775 char *newname;
777 #if 0 /* this is noisy with no dbus connection */
778 g_return_if_fail(purple_dbus_connection);
779 #else
780 if (purple_dbus_connection == NULL)
781 return;
782 #endif
786 * The test below is a hack that prevents our "dbus-method-called"
787 * signal from being propagated to dbus. What we really need is a
788 * flag for each signal that states whether this signal is to be
789 * dbus-propagated or not.
791 if (!strcmp(name, "dbus-method-called"))
792 return;
794 newname = purple_dbus_convert_signal_name(name);
795 signal = dbus_message_new_signal(DBUS_PATH_PURPLE, DBUS_INTERFACE_PURPLE, newname);
796 dbus_message_iter_init_append(signal, &iter);
798 if (purple_dbus_message_append_purple_values(&iter, num_values, values, vargs))
799 if (purple_debug_is_verbose())
800 purple_debug_warning("dbus",
801 "The signal \"%s\" caused some dbus error."
802 " (If you are not a developer, please ignore this message.)\n",
803 name);
805 dbus_connection_send(purple_dbus_connection, signal, NULL);
807 g_free(newname);
808 dbus_message_unref(signal);
811 const char *
812 purple_dbus_get_init_error(void)
814 return init_error;
817 void *
818 purple_dbus_get_handle(void)
820 static int handle;
822 return &handle;
825 void
826 purple_dbus_init(void)
828 if (g_thread_supported())
829 dbus_g_thread_init();
831 purple_dbus_init_ids();
833 g_free(init_error);
834 init_error = NULL;
835 purple_dbus_dispatch_init();
836 if (init_error != NULL)
837 purple_debug_error("dbus", "%s\n", init_error);
840 void
841 purple_dbus_uninit(void)
843 DBusError error;
844 if (!purple_dbus_connection)
845 return;
847 dbus_error_init(&error);
848 dbus_connection_unregister_object_path(purple_dbus_connection, DBUS_PATH_PURPLE);
849 dbus_bus_release_name(purple_dbus_connection, DBUS_SERVICE_PURPLE, &error);
850 dbus_error_free(&error);
851 dbus_connection_unref(purple_dbus_connection);
852 purple_dbus_connection = NULL;
853 purple_signals_disconnect_by_handle(purple_dbus_get_handle());
854 g_free(init_error);
855 init_error = NULL;