comparison libpurple/dbus-server.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 5fe8042783c1
children 598b1b15b199
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /* 1 /*
2 * gaim 2 * purple
3 * 3 *
4 * Gaim is the legal property of its developers, whose names are too numerous 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 5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution. 6 * source distribution.
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License as published by
28 #include <string.h> 28 #include <string.h>
29 29
30 #include "account.h" 30 #include "account.h"
31 #include "blist.h" 31 #include "blist.h"
32 #include "conversation.h" 32 #include "conversation.h"
33 #include "dbus-gaim.h" 33 #include "dbus-purple.h"
34 #include "dbus-server.h" 34 #include "dbus-server.h"
35 #include "dbus-useful.h" 35 #include "dbus-useful.h"
36 #include "dbus-bindings.h" 36 #include "dbus-bindings.h"
37 #include "debug.h" 37 #include "debug.h"
38 #include "core.h" 38 #include "core.h"
42 #include "value.h" 42 #include "value.h"
43 #include "xmlnode.h" 43 #include "xmlnode.h"
44 44
45 45
46 /**************************************************************************/ 46 /**************************************************************************/
47 /** @name Gaim DBUS pointer registration mechanism */ 47 /** @name Purple DBUS pointer registration mechanism */
48 /**************************************************************************/ 48 /**************************************************************************/
49 49
50 /* 50 /*
51 * Here we include the list of #GAIM_DBUS_DEFINE_TYPE statements for 51 * Here we include the list of #PURPLE_DBUS_DEFINE_TYPE statements for
52 * all structs defined in gaim. This file has been generated by the 52 * all structs defined in purple. This file has been generated by the
53 * #dbus-analyze-types.py script. 53 * #dbus-analyze-types.py script.
54 */ 54 */
55 55
56 #include "dbus-types.c" 56 #include "dbus-types.c"
57 57
69 /** 69 /**
70 * This function initializes the pointer-id traslation system. It 70 * This function initializes the pointer-id traslation system. It
71 * creates the three above hashtables and defines parents of some types. 71 * creates the three above hashtables and defines parents of some types.
72 */ 72 */
73 void 73 void
74 gaim_dbus_init_ids(void) 74 purple_dbus_init_ids(void)
75 { 75 {
76 map_id_node = g_hash_table_new(g_direct_hash, g_direct_equal); 76 map_id_node = g_hash_table_new(g_direct_hash, g_direct_equal);
77 map_id_type = g_hash_table_new(g_direct_hash, g_direct_equal); 77 map_id_type = g_hash_table_new(g_direct_hash, g_direct_equal);
78 map_node_id = g_hash_table_new(g_direct_hash, g_direct_equal); 78 map_node_id = g_hash_table_new(g_direct_hash, g_direct_equal);
79 79
80 GAIM_DBUS_TYPE(GaimBuddy)->parent = GAIM_DBUS_TYPE(GaimBlistNode); 80 PURPLE_DBUS_TYPE(PurpleBuddy)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
81 GAIM_DBUS_TYPE(GaimContact)->parent = GAIM_DBUS_TYPE(GaimBlistNode); 81 PURPLE_DBUS_TYPE(PurpleContact)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
82 GAIM_DBUS_TYPE(GaimChat)->parent = GAIM_DBUS_TYPE(GaimBlistNode); 82 PURPLE_DBUS_TYPE(PurpleChat)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
83 GAIM_DBUS_TYPE(GaimGroup)->parent = GAIM_DBUS_TYPE(GaimBlistNode); 83 PURPLE_DBUS_TYPE(PurpleGroup)->parent = PURPLE_DBUS_TYPE(PurpleBlistNode);
84 } 84 }
85 85
86 void 86 void
87 gaim_dbus_register_pointer(gpointer node, GaimDBusType *type) 87 purple_dbus_register_pointer(gpointer node, PurpleDBusType *type)
88 { 88 {
89 static gint last_id = 0; 89 static gint last_id = 0;
90 90
91 g_return_if_fail(map_node_id); 91 g_return_if_fail(map_node_id);
92 g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL); 92 g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL);
96 g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node); 96 g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node);
97 g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type); 97 g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type);
98 } 98 }
99 99
100 void 100 void
101 gaim_dbus_unregister_pointer(gpointer node) 101 purple_dbus_unregister_pointer(gpointer node)
102 { 102 {
103 gpointer id = g_hash_table_lookup(map_node_id, node); 103 gpointer id = g_hash_table_lookup(map_node_id, node);
104 104
105 g_hash_table_remove(map_node_id, node); 105 g_hash_table_remove(map_node_id, node);
106 g_hash_table_remove(map_id_node, GINT_TO_POINTER(id)); 106 g_hash_table_remove(map_id_node, GINT_TO_POINTER(id));
107 g_hash_table_remove(map_id_type, GINT_TO_POINTER(id)); 107 g_hash_table_remove(map_id_type, GINT_TO_POINTER(id));
108 } 108 }
109 109
110 gint 110 gint
111 gaim_dbus_pointer_to_id(gpointer node) 111 purple_dbus_pointer_to_id(gpointer node)
112 { 112 {
113 gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node)); 113 gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node));
114 if ((id == 0) && (node != NULL)) 114 if ((id == 0) && (node != NULL))
115 { 115 {
116 gaim_debug_warning("dbus", 116 purple_debug_warning("dbus",
117 "Need to register an object with the dbus subsystem.\n"); 117 "Need to register an object with the dbus subsystem.\n");
118 g_return_val_if_reached(0); 118 g_return_val_if_reached(0);
119 } 119 }
120 return id; 120 return id;
121 } 121 }
122 122
123 gpointer 123 gpointer
124 gaim_dbus_id_to_pointer(gint id, GaimDBusType *type) 124 purple_dbus_id_to_pointer(gint id, PurpleDBusType *type)
125 { 125 {
126 GaimDBusType *objtype; 126 PurpleDBusType *objtype;
127 127
128 objtype = (GaimDBusType*)g_hash_table_lookup(map_id_type, 128 objtype = (PurpleDBusType*)g_hash_table_lookup(map_id_type,
129 GINT_TO_POINTER(id)); 129 GINT_TO_POINTER(id));
130 130
131 while (objtype != type && objtype != NULL) 131 while (objtype != type && objtype != NULL)
132 objtype = objtype->parent; 132 objtype = objtype->parent;
133 133
136 else 136 else
137 return NULL; 137 return NULL;
138 } 138 }
139 139
140 gint 140 gint
141 gaim_dbus_pointer_to_id_error(gpointer ptr, DBusError *error) 141 purple_dbus_pointer_to_id_error(gpointer ptr, DBusError *error)
142 { 142 {
143 gint id = gaim_dbus_pointer_to_id(ptr); 143 gint id = purple_dbus_pointer_to_id(ptr);
144 144
145 if (ptr != NULL && id == 0) 145 if (ptr != NULL && id == 0)
146 dbus_set_error(error, "net.sf.gaim.ObjectNotFound", 146 dbus_set_error(error, "net.sf.purple.ObjectNotFound",
147 "The return object is not mapped (this is a Gaim error)"); 147 "The return object is not mapped (this is a Purple error)");
148 148
149 return id; 149 return id;
150 } 150 }
151 151
152 gpointer 152 gpointer
153 gaim_dbus_id_to_pointer_error(gint id, GaimDBusType *type, 153 purple_dbus_id_to_pointer_error(gint id, PurpleDBusType *type,
154 const char *typename, DBusError *error) 154 const char *typename, DBusError *error)
155 { 155 {
156 gpointer ptr = gaim_dbus_id_to_pointer(id, type); 156 gpointer ptr = purple_dbus_id_to_pointer(id, type);
157 157
158 if (ptr == NULL && id != 0) 158 if (ptr == NULL && id != 0)
159 dbus_set_error(error, "net.sf.gaim.InvalidHandle", 159 dbus_set_error(error, "net.sf.purple.InvalidHandle",
160 "%s object with ID = %i not found", typename, id); 160 "%s object with ID = %i not found", typename, id);
161 161
162 return ptr; 162 return ptr;
163 } 163 }
164 164
166 /**************************************************************************/ 166 /**************************************************************************/
167 /** @name Modified versions of some DBus functions */ 167 /** @name Modified versions of some DBus functions */
168 /**************************************************************************/ 168 /**************************************************************************/
169 169
170 dbus_bool_t 170 dbus_bool_t
171 gaim_dbus_message_get_args(DBusMessage *message, 171 purple_dbus_message_get_args(DBusMessage *message,
172 DBusError *error, int first_arg_type, ...) 172 DBusError *error, int first_arg_type, ...)
173 { 173 {
174 dbus_bool_t retval; 174 dbus_bool_t retval;
175 va_list var_args; 175 va_list var_args;
176 176
177 va_start(var_args, first_arg_type); 177 va_start(var_args, first_arg_type);
178 retval = gaim_dbus_message_get_args_valist(message, error, first_arg_type, var_args); 178 retval = purple_dbus_message_get_args_valist(message, error, first_arg_type, var_args);
179 va_end(var_args); 179 va_end(var_args);
180 180
181 return retval; 181 return retval;
182 } 182 }
183 183
184 dbus_bool_t 184 dbus_bool_t
185 gaim_dbus_message_get_args_valist(DBusMessage *message, 185 purple_dbus_message_get_args_valist(DBusMessage *message,
186 DBusError *error, int first_arg_type, va_list var_args) 186 DBusError *error, int first_arg_type, va_list var_args)
187 { 187 {
188 DBusMessageIter iter; 188 DBusMessageIter iter;
189 189
190 dbus_message_iter_init(message, &iter); 190 dbus_message_iter_init(message, &iter);
191 return gaim_dbus_message_iter_get_args_valist(&iter, error, first_arg_type, var_args); 191 return purple_dbus_message_iter_get_args_valist(&iter, error, first_arg_type, var_args);
192 } 192 }
193 193
194 dbus_bool_t 194 dbus_bool_t
195 gaim_dbus_message_iter_get_args(DBusMessageIter *iter, 195 purple_dbus_message_iter_get_args(DBusMessageIter *iter,
196 DBusError *error, int first_arg_type, ...) 196 DBusError *error, int first_arg_type, ...)
197 { 197 {
198 dbus_bool_t retval; 198 dbus_bool_t retval;
199 va_list var_args; 199 va_list var_args;
200 200
201 va_start(var_args, first_arg_type); 201 va_start(var_args, first_arg_type);
202 retval = gaim_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args); 202 retval = purple_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args);
203 va_end(var_args); 203 va_end(var_args);
204 204
205 return retval; 205 return retval;
206 } 206 }
207 207
211 (typecode) == DBUS_TYPE_VARIANT || \ 211 (typecode) == DBUS_TYPE_VARIANT || \
212 (typecode) == DBUS_TYPE_ARRAY) 212 (typecode) == DBUS_TYPE_ARRAY)
213 213
214 214
215 dbus_bool_t 215 dbus_bool_t
216 gaim_dbus_message_iter_get_args_valist(DBusMessageIter *iter, 216 purple_dbus_message_iter_get_args_valist(DBusMessageIter *iter,
217 DBusError *error, int first_arg_type, va_list var_args) 217 DBusError *error, int first_arg_type, va_list var_args)
218 { 218 {
219 int spec_type, msg_type, i; 219 int spec_type, msg_type, i;
220 220
221 spec_type = first_arg_type; 221 spec_type = first_arg_type;
242 else 242 else
243 { 243 {
244 DBusMessageIter *sub; 244 DBusMessageIter *sub;
245 sub = va_arg (var_args, DBusMessageIter*); 245 sub = va_arg (var_args, DBusMessageIter*);
246 dbus_message_iter_recurse(iter, sub); 246 dbus_message_iter_recurse(iter, sub);
247 gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); 247 purple_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub);
248 break; /* for testing only! */ 248 break; /* for testing only! */
249 } 249 }
250 250
251 spec_type = va_arg(var_args, int); 251 spec_type = va_arg(var_args, int);
252 if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) 252 if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID)
282 else 282 else
283 return ""; 283 return "";
284 } 284 }
285 285
286 dbus_int32_t * 286 dbus_int32_t *
287 gaim_dbusify_GList(GList *list, gboolean free_memory, dbus_int32_t *len) 287 purple_dbusify_GList(GList *list, gboolean free_memory, dbus_int32_t *len)
288 { 288 {
289 dbus_int32_t *array; 289 dbus_int32_t *array;
290 int i; 290 int i;
291 GList *elem; 291 GList *elem;
292 292
293 *len = g_list_length(list); 293 *len = g_list_length(list);
294 array = g_new0(dbus_int32_t, g_list_length(list)); 294 array = g_new0(dbus_int32_t, g_list_length(list));
295 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) 295 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
296 array[i] = gaim_dbus_pointer_to_id(elem->data); 296 array[i] = purple_dbus_pointer_to_id(elem->data);
297 297
298 if (free_memory) 298 if (free_memory)
299 g_list_free(list); 299 g_list_free(list);
300 300
301 return array; 301 return array;
302 } 302 }
303 303
304 dbus_int32_t * 304 dbus_int32_t *
305 gaim_dbusify_GSList(GSList *list, gboolean free_memory, dbus_int32_t *len) 305 purple_dbusify_GSList(GSList *list, gboolean free_memory, dbus_int32_t *len)
306 { 306 {
307 dbus_int32_t *array; 307 dbus_int32_t *array;
308 int i; 308 int i;
309 GSList *elem; 309 GSList *elem;
310 310
311 *len = g_slist_length(list); 311 *len = g_slist_length(list);
312 array = g_new0(dbus_int32_t, g_slist_length(list)); 312 array = g_new0(dbus_int32_t, g_slist_length(list));
313 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++) 313 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
314 array[i] = gaim_dbus_pointer_to_id(elem->data); 314 array[i] = purple_dbus_pointer_to_id(elem->data);
315 315
316 if (free_memory) 316 if (free_memory)
317 g_slist_free(list); 317 g_slist_free(list);
318 318
319 return array; 319 return array;
320 } 320 }
321 321
322 gpointer * 322 gpointer *
323 gaim_GList_to_array(GList *list, gboolean free_memory, dbus_int32_t *len) 323 purple_GList_to_array(GList *list, gboolean free_memory, dbus_int32_t *len)
324 { 324 {
325 gpointer *array; 325 gpointer *array;
326 int i; 326 int i;
327 GList *elem; 327 GList *elem;
328 328
336 336
337 return array; 337 return array;
338 } 338 }
339 339
340 gpointer * 340 gpointer *
341 gaim_GSList_to_array(GSList *list, gboolean free_memory, dbus_int32_t *len) 341 purple_GSList_to_array(GSList *list, gboolean free_memory, dbus_int32_t *len)
342 { 342 {
343 gpointer *array; 343 gpointer *array;
344 int i; 344 int i;
345 GSList *elem; 345 GSList *elem;
346 346
354 354
355 return array; 355 return array;
356 } 356 }
357 357
358 GHashTable * 358 GHashTable *
359 gaim_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error) 359 purple_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error)
360 { 360 {
361 GHashTable *hash; 361 GHashTable *hash;
362 362
363 /* we do not need to destroy strings because they are part of the message */ 363 /* we do not need to destroy strings because they are part of the message */
364 hash = g_hash_table_new(g_str_hash, g_str_equal); 364 hash = g_hash_table_new(g_str_hash, g_str_equal);
377 * table. Exceptional instructions 377 * table. Exceptional instructions
378 * for exceptional situations. 378 * for exceptional situations.
379 */ 379 */
380 380
381 dbus_message_iter_recurse(iter, &subiter); 381 dbus_message_iter_recurse(iter, &subiter);
382 if (!gaim_dbus_message_iter_get_args(&subiter, error, 382 if (!purple_dbus_message_iter_get_args(&subiter, error,
383 DBUS_TYPE_STRING, &key, 383 DBUS_TYPE_STRING, &key,
384 DBUS_TYPE_STRING, &value, 384 DBUS_TYPE_STRING, &value,
385 DBUS_TYPE_INVALID)) 385 DBUS_TYPE_INVALID))
386 goto error; /* same here */ 386 goto error; /* same here */
387 387
397 397
398 /**************************************************************/ 398 /**************************************************************/
399 /* DBus bindings ... */ 399 /* DBus bindings ... */
400 /**************************************************************/ 400 /**************************************************************/
401 401
402 static DBusConnection *gaim_dbus_connection; 402 static DBusConnection *purple_dbus_connection;
403 403
404 DBusConnection * 404 DBusConnection *
405 gaim_dbus_get_connection(void) 405 purple_dbus_get_connection(void)
406 { 406 {
407 return gaim_dbus_connection; 407 return purple_dbus_connection;
408 } 408 }
409 409
410 #include "dbus-bindings.c" 410 #include "dbus-bindings.c"
411 411
412 static gboolean 412 static gboolean
413 gaim_dbus_dispatch_cb(DBusConnection *connection, 413 purple_dbus_dispatch_cb(DBusConnection *connection,
414 DBusMessage *message, void *user_data) 414 DBusMessage *message, void *user_data)
415 { 415 {
416 const char *name; 416 const char *name;
417 GaimDBusBinding *bindings; 417 PurpleDBusBinding *bindings;
418 int i; 418 int i;
419 419
420 bindings = (GaimDBusBinding*) user_data; 420 bindings = (PurpleDBusBinding*) user_data;
421 421
422 if (!dbus_message_has_path(message, DBUS_PATH_GAIM)) 422 if (!dbus_message_has_path(message, DBUS_PATH_PURPLE))
423 return FALSE; 423 return FALSE;
424 424
425 name = dbus_message_get_member(message); 425 name = dbus_message_get_member(message);
426 426
427 if (name == NULL) 427 if (name == NULL)
464 *ptr += strlen(text) + 1; 464 *ptr += strlen(text) + 1;
465 return text; 465 return text;
466 } 466 }
467 467
468 static void 468 static void
469 gaim_dbus_introspect_cb(GList **bindings_list, void *bindings) 469 purple_dbus_introspect_cb(GList **bindings_list, void *bindings)
470 { 470 {
471 *bindings_list = g_list_prepend(*bindings_list, bindings); 471 *bindings_list = g_list_prepend(*bindings_list, bindings);
472 } 472 }
473 473
474 static DBusMessage *gaim_dbus_introspect(DBusMessage *message) 474 static DBusMessage *purple_dbus_introspect(DBusMessage *message)
475 { 475 {
476 DBusMessage *reply; 476 DBusMessage *reply;
477 GString *str; 477 GString *str;
478 GList *bindings_list, *node; 478 GList *bindings_list, *node;
479 479
480 str = g_string_sized_new(0x1000); /* TODO: why this size? */ 480 str = g_string_sized_new(0x1000); /* TODO: why this size? */
481 481
482 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"); 482 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");
483 g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_GAIM); 483 g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_PURPLE);
484 g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_GAIM); 484 g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_PURPLE);
485 485
486 bindings_list = NULL; 486 bindings_list = NULL;
487 gaim_signal_emit(gaim_dbus_get_handle(), "dbus-introspect", &bindings_list); 487 purple_signal_emit(purple_dbus_get_handle(), "dbus-introspect", &bindings_list);
488 488
489 for (node = bindings_list; node; node = node->next) 489 for (node = bindings_list; node; node = node->next)
490 { 490 {
491 GaimDBusBinding *bindings; 491 PurpleDBusBinding *bindings;
492 int i; 492 int i;
493 493
494 bindings = (GaimDBusBinding*)node->data; 494 bindings = (PurpleDBusBinding*)node->data;
495 495
496 for (i = 0; bindings[i].name; i++) 496 for (i = 0; bindings[i].name; i++)
497 { 497 {
498 const char *text; 498 const char *text;
499 499
526 526
527 return reply; 527 return reply;
528 } 528 }
529 529
530 static DBusHandlerResult 530 static DBusHandlerResult
531 gaim_dbus_dispatch(DBusConnection *connection, 531 purple_dbus_dispatch(DBusConnection *connection,
532 DBusMessage *message, void *user_data) 532 DBusMessage *message, void *user_data)
533 { 533 {
534 if (gaim_signal_emit_return_1(gaim_dbus_get_handle(), 534 if (purple_signal_emit_return_1(purple_dbus_get_handle(),
535 "dbus-method-called", connection, message)) 535 "dbus-method-called", connection, message))
536 return DBUS_HANDLER_RESULT_HANDLED; 536 return DBUS_HANDLER_RESULT_HANDLED;
537 537
538 if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL && 538 if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL &&
539 dbus_message_has_path(message, DBUS_PATH_GAIM) && 539 dbus_message_has_path(message, DBUS_PATH_PURPLE) &&
540 dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) && 540 dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) &&
541 dbus_message_has_member(message, "Introspect")) 541 dbus_message_has_member(message, "Introspect"))
542 { 542 {
543 DBusMessage *reply; 543 DBusMessage *reply;
544 reply = gaim_dbus_introspect(message); 544 reply = purple_dbus_introspect(message);
545 dbus_connection_send (connection, reply, NULL); 545 dbus_connection_send (connection, reply, NULL);
546 dbus_message_unref(reply); 546 dbus_message_unref(reply);
547 return DBUS_HANDLER_RESULT_HANDLED; 547 return DBUS_HANDLER_RESULT_HANDLED;
548 } 548 }
549 549
550 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 550 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
551 } 551 }
552 552
553 void 553 void
554 gaim_dbus_register_bindings(void *handle, GaimDBusBinding *bindings) 554 purple_dbus_register_bindings(void *handle, PurpleDBusBinding *bindings)
555 { 555 {
556 gaim_signal_connect(gaim_dbus_get_handle(), "dbus-method-called", 556 purple_signal_connect(purple_dbus_get_handle(), "dbus-method-called",
557 handle, 557 handle,
558 GAIM_CALLBACK(gaim_dbus_dispatch_cb), 558 PURPLE_CALLBACK(purple_dbus_dispatch_cb),
559 bindings); 559 bindings);
560 gaim_signal_connect(gaim_dbus_get_handle(), "dbus-introspect", 560 purple_signal_connect(purple_dbus_get_handle(), "dbus-introspect",
561 handle, 561 handle,
562 GAIM_CALLBACK(gaim_dbus_introspect_cb), 562 PURPLE_CALLBACK(purple_dbus_introspect_cb),
563 bindings); 563 bindings);
564 } 564 }
565 565
566 static void 566 static void
567 gaim_dbus_dispatch_init(void) 567 purple_dbus_dispatch_init(void)
568 { 568 {
569 static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; 569 static DBusObjectPathVTable vtable = {NULL, &purple_dbus_dispatch, NULL, NULL, NULL, NULL};
570 DBusError error; 570 DBusError error;
571 int result; 571 int result;
572 572
573 dbus_error_init(&error); 573 dbus_error_init(&error);
574 gaim_dbus_connection = dbus_bus_get(DBUS_BUS_STARTER, &error); 574 purple_dbus_connection = dbus_bus_get(DBUS_BUS_STARTER, &error);
575 575
576 if (gaim_dbus_connection == NULL) 576 if (purple_dbus_connection == NULL)
577 { 577 {
578 init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); 578 init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message);
579 dbus_error_free(&error); 579 dbus_error_free(&error);
580 return; 580 return;
581 } 581 }
582 582
583 /* Do not allow libdbus to exit on connection failure (This may 583 /* Do not allow libdbus to exit on connection failure (This may
584 work around random exit(1) on SIGPIPE errors) */ 584 work around random exit(1) on SIGPIPE errors) */
585 dbus_connection_set_exit_on_disconnect (gaim_dbus_connection, FALSE); 585 dbus_connection_set_exit_on_disconnect (purple_dbus_connection, FALSE);
586 586
587 if (!dbus_connection_register_object_path(gaim_dbus_connection, 587 if (!dbus_connection_register_object_path(purple_dbus_connection,
588 DBUS_PATH_GAIM, &vtable, NULL)) 588 DBUS_PATH_PURPLE, &vtable, NULL))
589 { 589 {
590 init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); 590 init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name);
591 dbus_error_free(&error); 591 dbus_error_free(&error);
592 return; 592 return;
593 } 593 }
594 594
595 result = dbus_bus_request_name(gaim_dbus_connection, 595 result = dbus_bus_request_name(purple_dbus_connection,
596 DBUS_SERVICE_GAIM, 0, &error); 596 DBUS_SERVICE_PURPLE, 0, &error);
597 597
598 if (dbus_error_is_set(&error)) 598 if (dbus_error_is_set(&error))
599 { 599 {
600 dbus_connection_unref(gaim_dbus_connection); 600 dbus_connection_unref(purple_dbus_connection);
601 dbus_error_free(&error); 601 dbus_error_free(&error);
602 gaim_dbus_connection = NULL; 602 purple_dbus_connection = NULL;
603 init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); 603 init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name);
604 return; 604 return;
605 } 605 }
606 606
607 dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); 607 dbus_connection_setup_with_g_main(purple_dbus_connection, NULL);
608 608
609 gaim_debug_misc("dbus", "okkk\n"); 609 purple_debug_misc("dbus", "okkk\n");
610 610
611 gaim_signal_register(gaim_dbus_get_handle(), "dbus-method-called", 611 purple_signal_register(purple_dbus_get_handle(), "dbus-method-called",
612 gaim_marshal_BOOLEAN__POINTER_POINTER, 612 purple_marshal_BOOLEAN__POINTER_POINTER,
613 gaim_value_new(GAIM_TYPE_BOOLEAN), 2, 613 purple_value_new(PURPLE_TYPE_BOOLEAN), 2,
614 gaim_value_new(GAIM_TYPE_POINTER), 614 purple_value_new(PURPLE_TYPE_POINTER),
615 gaim_value_new(GAIM_TYPE_POINTER)); 615 purple_value_new(PURPLE_TYPE_POINTER));
616 616
617 gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect", 617 purple_signal_register(purple_dbus_get_handle(), "dbus-introspect",
618 gaim_marshal_VOID__POINTER, NULL, 1, 618 purple_marshal_VOID__POINTER, NULL, 1,
619 gaim_value_new_outgoing(GAIM_TYPE_POINTER)); 619 purple_value_new_outgoing(PURPLE_TYPE_POINTER));
620 620
621 GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); 621 PURPLE_DBUS_REGISTER_BINDINGS(purple_dbus_get_handle());
622 } 622 }
623 623
624 624
625 625
626 /**************************************************************************/ 626 /**************************************************************************/
628 /**************************************************************************/ 628 /**************************************************************************/
629 629
630 630
631 631
632 static char * 632 static char *
633 gaim_dbus_convert_signal_name(const char *gaim_name) 633 purple_dbus_convert_signal_name(const char *purple_name)
634 { 634 {
635 int gaim_index, g_index; 635 int purple_index, g_index;
636 char *g_name = g_new(char, strlen(gaim_name) + 1); 636 char *g_name = g_new(char, strlen(purple_name) + 1);
637 gboolean capitalize_next = TRUE; 637 gboolean capitalize_next = TRUE;
638 638
639 for (gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++) 639 for (purple_index = g_index = 0; purple_name[purple_index]; purple_index++)
640 if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_') 640 if (purple_name[purple_index] != '-' && purple_name[purple_index] != '_')
641 { 641 {
642 if (capitalize_next) 642 if (capitalize_next)
643 g_name[g_index++] = g_ascii_toupper(gaim_name[gaim_index]); 643 g_name[g_index++] = g_ascii_toupper(purple_name[purple_index]);
644 else 644 else
645 g_name[g_index++] = gaim_name[gaim_index]; 645 g_name[g_index++] = purple_name[purple_index];
646 capitalize_next = FALSE; 646 capitalize_next = FALSE;
647 } else 647 } else
648 capitalize_next = TRUE; 648 capitalize_next = TRUE;
649 649
650 g_name[g_index] = 0; 650 g_name[g_index] = 0;
653 } 653 }
654 654
655 #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type)) 655 #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type))
656 656
657 static void 657 static void
658 gaim_dbus_message_append_gaim_values(DBusMessageIter *iter, 658 purple_dbus_message_append_purple_values(DBusMessageIter *iter,
659 int number, GaimValue **gaim_values, va_list data) 659 int number, PurpleValue **purple_values, va_list data)
660 { 660 {
661 int i; 661 int i;
662 662
663 for (i = 0; i < number; i++) 663 for (i = 0; i < number; i++)
664 { 664 {
667 gint xint; 667 gint xint;
668 guint xuint; 668 guint xuint;
669 gboolean xboolean; 669 gboolean xboolean;
670 gpointer ptr = NULL; 670 gpointer ptr = NULL;
671 671
672 if (gaim_value_is_outgoing(gaim_values[i])) 672 if (purple_value_is_outgoing(purple_values[i]))
673 { 673 {
674 ptr = my_arg(gpointer); 674 ptr = my_arg(gpointer);
675 g_return_if_fail(ptr); 675 g_return_if_fail(ptr);
676 } 676 }
677 677
678 switch (gaim_values[i]->type) 678 switch (purple_values[i]->type)
679 { 679 {
680 case GAIM_TYPE_INT: 680 case PURPLE_TYPE_INT:
681 xint = my_arg(gint); 681 xint = my_arg(gint);
682 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint); 682 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
683 break; 683 break;
684 case GAIM_TYPE_UINT: 684 case PURPLE_TYPE_UINT:
685 xuint = my_arg(guint); 685 xuint = my_arg(guint);
686 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint); 686 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint);
687 break; 687 break;
688 case GAIM_TYPE_BOOLEAN: 688 case PURPLE_TYPE_BOOLEAN:
689 xboolean = my_arg(gboolean); 689 xboolean = my_arg(gboolean);
690 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean); 690 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean);
691 break; 691 break;
692 case GAIM_TYPE_STRING: 692 case PURPLE_TYPE_STRING:
693 str = null_to_empty(my_arg(char*)); 693 str = null_to_empty(my_arg(char*));
694 if (!g_utf8_validate(str, -1, NULL)) { 694 if (!g_utf8_validate(str, -1, NULL)) {
695 gchar *tmp; 695 gchar *tmp;
696 gaim_debug_error("dbus", "Invalid UTF-8 string passed to signal, emitting salvaged string!\n"); 696 purple_debug_error("dbus", "Invalid UTF-8 string passed to signal, emitting salvaged string!\n");
697 tmp = gaim_utf8_salvage(str); 697 tmp = purple_utf8_salvage(str);
698 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &tmp); 698 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &tmp);
699 g_free(tmp); 699 g_free(tmp);
700 } else { 700 } else {
701 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str); 701 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
702 } 702 }
703 break; 703 break;
704 case GAIM_TYPE_SUBTYPE: /* registered pointers only! */ 704 case PURPLE_TYPE_SUBTYPE: /* registered pointers only! */
705 case GAIM_TYPE_POINTER: 705 case PURPLE_TYPE_POINTER:
706 case GAIM_TYPE_OBJECT: 706 case PURPLE_TYPE_OBJECT:
707 case GAIM_TYPE_BOXED: 707 case PURPLE_TYPE_BOXED:
708 id = gaim_dbus_pointer_to_id(my_arg(gpointer)); 708 id = purple_dbus_pointer_to_id(my_arg(gpointer));
709 dbus_message_iter_append_basic(iter, 709 dbus_message_iter_append_basic(iter,
710 (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id); 710 (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id);
711 break; 711 break;
712 default: /* no conversion implemented */ 712 default: /* no conversion implemented */
713 g_return_if_reached(); 713 g_return_if_reached();
716 } 716 }
717 717
718 #undef my_arg 718 #undef my_arg
719 719
720 void 720 void
721 gaim_dbus_signal_emit_gaim(const char *name, int num_values, 721 purple_dbus_signal_emit_purple(const char *name, int num_values,
722 GaimValue **values, va_list vargs) 722 PurpleValue **values, va_list vargs)
723 { 723 {
724 DBusMessage *signal; 724 DBusMessage *signal;
725 DBusMessageIter iter; 725 DBusMessageIter iter;
726 char *newname; 726 char *newname;
727 727
728 #if 0 /* this is noisy with no dbus connection */ 728 #if 0 /* this is noisy with no dbus connection */
729 g_return_if_fail(gaim_dbus_connection); 729 g_return_if_fail(purple_dbus_connection);
730 #else 730 #else
731 if (gaim_dbus_connection == NULL) 731 if (purple_dbus_connection == NULL)
732 return; 732 return;
733 #endif 733 #endif
734 734
735 735
736 /* 736 /*
740 * dbus-propagated or not. 740 * dbus-propagated or not.
741 */ 741 */
742 if (!strcmp(name, "dbus-method-called")) 742 if (!strcmp(name, "dbus-method-called"))
743 return; 743 return;
744 744
745 newname = gaim_dbus_convert_signal_name(name); 745 newname = purple_dbus_convert_signal_name(name);
746 signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname); 746 signal = dbus_message_new_signal(DBUS_PATH_PURPLE, DBUS_INTERFACE_PURPLE, newname);
747 dbus_message_iter_init_append(signal, &iter); 747 dbus_message_iter_init_append(signal, &iter);
748 748
749 gaim_dbus_message_append_gaim_values(&iter, num_values, values, vargs); 749 purple_dbus_message_append_purple_values(&iter, num_values, values, vargs);
750 750
751 dbus_connection_send(gaim_dbus_connection, signal, NULL); 751 dbus_connection_send(purple_dbus_connection, signal, NULL);
752 752
753 g_free(newname); 753 g_free(newname);
754 dbus_message_unref(signal); 754 dbus_message_unref(signal);
755 } 755 }
756 756
757 const char * 757 const char *
758 gaim_dbus_get_init_error(void) 758 purple_dbus_get_init_error(void)
759 { 759 {
760 return init_error; 760 return init_error;
761 } 761 }
762 762
763 void * 763 void *
764 gaim_dbus_get_handle(void) 764 purple_dbus_get_handle(void)
765 { 765 {
766 static int handle; 766 static int handle;
767 767
768 return &handle; 768 return &handle;
769 } 769 }
770 770
771 void 771 void
772 gaim_dbus_init(void) 772 purple_dbus_init(void)
773 { 773 {
774 gaim_dbus_init_ids(); 774 purple_dbus_init_ids();
775 775
776 g_free(init_error); 776 g_free(init_error);
777 init_error = NULL; 777 init_error = NULL;
778 gaim_dbus_dispatch_init(); 778 purple_dbus_dispatch_init();
779 if (init_error != NULL) 779 if (init_error != NULL)
780 gaim_debug_error("dbus", "%s\n", init_error); 780 purple_debug_error("dbus", "%s\n", init_error);
781 } 781 }
782 782
783 void 783 void
784 gaim_dbus_uninit(void) 784 purple_dbus_uninit(void)
785 { 785 {
786 /* Surely we must do SOME kind of uninitialization? */ 786 /* Surely we must do SOME kind of uninitialization? */
787 787
788 g_free(init_error); 788 g_free(init_error);
789 init_error = NULL; 789 init_error = NULL;