annotate src/dbus-server.c @ 13925:60f39c405dff

[gaim-migrate @ 16442] It is currently possible for yourself to not show up in your own buddy list at signon with Jabber. To reproduce: 1. Sign on and add yourself to your buddy list 2. Sign off and exit Gaim 3. Delete your blist.xml 4. Sign on The same bug would also appear when signing into your Jabber account using Gaim for the first time. Normally this works because the Jabber PRPL fakes showing your status whenever jabber_presence_send() is called. However, the call to jabber_presence_send() can happen BEFORE we receive the roster from the server (it usually does, I think) so the PRPL tries to set the status for yourself, but your GaimBuddy node doesn't exist yet. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 06 Jul 2006 08:24:26 +0000
parents fd708f52defd
children 2d6f7ac4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
1 /*
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
2 * gaim
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
3 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
6 * source distribution.
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
7 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
11 * (at your option) any later version.
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
12 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
16 * GNU General Public License for more details.
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
17 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
21 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
22 */
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
23
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
24 #define DBUS_API_SUBJECT_TO_CHANGE
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
25
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
26 #include <stdio.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
27 #include <stdlib.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
28 #include <string.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
29
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
30 #include "account.h"
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
31 #include "blist.h"
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
32 #include "conversation.h"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
33 #include "dbus-gaim.h"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
34 #include "dbus-server.h"
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
35 #include "dbus-useful.h"
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
36 #include "dbus-bindings.h"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
37 #include "debug.h"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
38 #include "core.h"
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13759
diff changeset
39 #include "savedstatuses.h"
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
40 #include "value.h"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
41
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
42
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
43 /**************************************************************************/
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
44 /** @name Gaim DBUS pointer registration mechanism */
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
45 /**************************************************************************/
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
46
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
47 /*
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
48 Here we include the list of #GAIM_DBUS_DEFINE_TYPE statements for
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
49 all structs defined in gaim. This file has been generated by the
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
50 #dbus-analize-types.py script.
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
51 */
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
52
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
53 #include "dbus-types.c"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
54
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
55 /* The following three hashtables map are used to translate between
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
56 pointers (nodes) and the corresponding handles (ids). */
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
57
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
58 static GHashTable *map_node_id;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
59 static GHashTable *map_id_node;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
60 static GHashTable *map_id_type;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
61
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
62
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
63 /* This function initializes the pointer-id traslation system. It
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
64 creates the three above hashtables and defines parents of some types.
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
65 */
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
66 void gaim_dbus_init_ids(void) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
67 map_id_node = g_hash_table_new (g_direct_hash, g_direct_equal);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
68 map_id_type = g_hash_table_new (g_direct_hash, g_direct_equal);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
69 map_node_id = g_hash_table_new (g_direct_hash, g_direct_equal);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
70
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
71 GAIM_DBUS_TYPE(GaimBuddy)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
72 GAIM_DBUS_TYPE(GaimContact)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
73 GAIM_DBUS_TYPE(GaimChat)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
74 GAIM_DBUS_TYPE(GaimGroup)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
75 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
76
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
77 void gaim_dbus_register_pointer(gpointer node, GaimDBusType *type)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
78 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
79 static gint last_id = 0;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
80
11291
57fccea36e36 [gaim-migrate @ 13491]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
81 g_return_if_fail(map_node_id);
57fccea36e36 [gaim-migrate @ 13491]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
82 g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
83
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
84 last_id++;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
85 g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
86 g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
87 g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
88 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
89
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
90 void gaim_dbus_unregister_pointer(gpointer node) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
91 gpointer id = g_hash_table_lookup(map_node_id, node);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
92
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
93 g_hash_table_remove(map_node_id, node);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
94 g_hash_table_remove(map_id_node, GINT_TO_POINTER(id));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
95 g_hash_table_remove(map_id_type, GINT_TO_POINTER(id));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
96 }
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
97
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
98 gint gaim_dbus_pointer_to_id(gpointer node) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
99 gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node));
13759
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
100 if ((id == 0) && (node != NULL))
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
101 {
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
102 gaim_debug_warning("dbus",
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
103 "Need to register an object with the dbus subsystem.\n");
13763
fd708f52defd [gaim-migrate @ 16175]
Richard Laager <rlaager@wiktel.com>
parents: 13761
diff changeset
104 g_return_val_if_reached(0);
13759
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
105 }
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
106 return id;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
107 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
108
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
109 gpointer gaim_dbus_id_to_pointer(gint id, GaimDBusType *type) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
110 GaimDBusType *objtype =
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
111 (GaimDBusType*) g_hash_table_lookup(map_id_type,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
112 GINT_TO_POINTER(id));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
113
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
114 while (objtype != type && objtype != NULL)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
115 objtype = objtype->parent;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
116
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
117 if (objtype == type)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
118 return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
119 else
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
120 return NULL;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
121 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
122
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
123 gint gaim_dbus_pointer_to_id_error(gpointer ptr, DBusError *error)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
124 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
125 gint id = gaim_dbus_pointer_to_id(ptr);
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
126
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
127 if (ptr != NULL && id == 0)
13220
ac5bc9a7b603 [gaim-migrate @ 15584]
Richard Laager <rlaager@wiktel.com>
parents: 13134
diff changeset
128 dbus_set_error(error, "net.sf.gaim.ObjectNotFound",
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
129 "The return object is not mapped (this is a Gaim error)");
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
130
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
131 return id;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
132 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
133
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
134 gpointer gaim_dbus_id_to_pointer_error(gint id, GaimDBusType *type,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
135 const char *typename, DBusError *error)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
136 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
137 gpointer ptr = gaim_dbus_id_to_pointer(id, type);
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
138
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
139 if (ptr == NULL && id != 0)
13220
ac5bc9a7b603 [gaim-migrate @ 15584]
Richard Laager <rlaager@wiktel.com>
parents: 13134
diff changeset
140 dbus_set_error(error, "net.sf.gaim.InvalidHandle",
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
141 "%s object with ID = %i not found", typename, id);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
142
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
143 return ptr;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
144 }
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
145
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
146
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
147 /**************************************************************************/
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
148 /** @name Modified versions of some DBus functions */
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
149 /**************************************************************************/
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
150
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
151 dbus_bool_t
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
152 gaim_dbus_message_get_args (DBusMessage *message,
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
153 DBusError *error,
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
154 int first_arg_type,
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
155 ...)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
156 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
157 dbus_bool_t retval;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
158 va_list var_args;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
159
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
160 va_start (var_args, first_arg_type);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
161 retval = gaim_dbus_message_get_args_valist (message, error, first_arg_type, var_args);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
162 va_end (var_args);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
163
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
164 return retval;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
165 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
166
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
167 dbus_bool_t
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
168 gaim_dbus_message_get_args_valist (DBusMessage *message,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
169 DBusError *error,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
170 int first_arg_type,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
171 va_list var_args)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
172 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
173 DBusMessageIter iter;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
174
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
175 dbus_message_iter_init (message, &iter);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
176 return gaim_dbus_message_iter_get_args_valist (&iter, error, first_arg_type, var_args);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
177 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
178
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
179 dbus_bool_t
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
180 gaim_dbus_message_iter_get_args(DBusMessageIter *iter,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
181 DBusError *error,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
182 int first_arg_type,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
183 ...)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
184 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
185 dbus_bool_t retval;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
186 va_list var_args;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
188 va_start (var_args, first_arg_type);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
189 retval = gaim_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
190 va_end (var_args);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
191
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
192 return retval;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
193 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
194
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
195 #define TYPE_IS_CONTAINER(typecode) \
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
196 ((typecode) == DBUS_TYPE_STRUCT || \
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
197 (typecode) == DBUS_TYPE_DICT_ENTRY || \
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
198 (typecode) == DBUS_TYPE_VARIANT || \
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
199 (typecode) == DBUS_TYPE_ARRAY)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
200
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
201
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
202 dbus_bool_t
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
203 gaim_dbus_message_iter_get_args_valist (DBusMessageIter *iter,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
204 DBusError *error,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
205 int first_arg_type,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
206 va_list var_args)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
207 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
208 int spec_type, msg_type, i;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
209
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
210 spec_type = first_arg_type;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
211
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
212 for(i=0; spec_type != DBUS_TYPE_INVALID; i++) {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
213 msg_type = dbus_message_iter_get_arg_type (iter);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
214
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
215 if (msg_type != spec_type) {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
216 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
217 "Argument %d is specified to be of type \"%i\", but "
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
218 "is actually of type \"%i\"\n", i,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
219 spec_type, msg_type);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
220 return FALSE;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
221 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
222
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
223 if (!TYPE_IS_CONTAINER(spec_type)) {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
224 gpointer ptr;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
225 ptr = va_arg (var_args, gpointer);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
226 dbus_message_iter_get_basic(iter, ptr);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
227 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
228 else {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
229 DBusMessageIter *sub;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
230 sub = va_arg (var_args, DBusMessageIter*);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
231 dbus_message_iter_recurse(iter, sub);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
232 g_print("subiter %i:%i\n", (int) sub, * (int*) sub);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
233 break; /* for testing only! */
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
234 }
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
235
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
236 spec_type = va_arg (var_args, int);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
237 if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
238 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
239 "Message has only %d arguments, but more were expected", i);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
240 return FALSE;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
241 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
242 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
243 return TRUE;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
244 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
245
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
246
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
247
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
248 /**************************************************************************/
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
249 /** @name Useful functions */
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
250 /**************************************************************************/
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
251
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
252 const char* empty_to_null(const char *str) {
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
253 if (str == NULL || str[0] == 0)
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
254 return NULL;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
255 else
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
256 return str;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
257 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
258
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
259 const char* null_to_empty(const char *s) {
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
260 if (s)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
261 return s;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
262 else
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
263 return "";
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
264 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
265
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
266 dbus_int32_t* gaim_dbusify_GList(GList *list, gboolean free_memory,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
267 dbus_int32_t *len)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
268 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
269 dbus_int32_t *array;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
270 int i;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
271 GList *elem;
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
272
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
273 *len = g_list_length(list);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
274 array = g_new0(dbus_int32_t, g_list_length(list));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
275 for(i = 0, elem = list; elem != NULL; elem = elem->next, i++)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
276 array[i] = gaim_dbus_pointer_to_id(elem->data);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
277
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
278 if (free_memory)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
279 g_list_free(list);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
280
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
281 return array;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
282 }
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
283
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
284 dbus_int32_t* gaim_dbusify_GSList(GSList *list, gboolean free_memory,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
285 dbus_int32_t *len)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
286 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
287 dbus_int32_t *array;
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
288 int i;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
289 GSList *elem;
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
290
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
291 *len = g_slist_length(list);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
292 array = g_new0(dbus_int32_t, g_slist_length(list));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
293 for(i = 0, elem = list; elem != NULL; elem = elem->next, i++)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
294 array[i] = gaim_dbus_pointer_to_id(elem->data);
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
295
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
296 if (free_memory)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
297 g_slist_free(list);
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
298
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
299 return array;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
300 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
301
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
302 gpointer* gaim_GList_to_array(GList *list, gboolean free_memory,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
303 dbus_int32_t *len)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
304 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
305 gpointer *array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
306 int i;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
307 GList *elem;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
308
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
309 *len = g_list_length(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
310 array = g_new0(gpointer, g_list_length(list));
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
311 for(i = 0, elem = list; elem != NULL; elem = elem->next, i++)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
312 array[i] = elem->data;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
313
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
314 if (free_memory)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
315 g_list_free(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
316
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
317 return array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
318 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
319
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
320 gpointer* gaim_GSList_to_array(GSList *list, gboolean free_memory,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
321 dbus_int32_t *len)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
322 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
323 gpointer *array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
324 int i;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
325 GSList *elem;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
326
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
327 *len = g_slist_length(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
328 array = g_new0(gpointer, g_slist_length(list));
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
329 for(i = 0, elem = list; elem != NULL; elem = elem->next, i++)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
330 array[i] = elem->data;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
331
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
332 if (free_memory)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
333 g_slist_free(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
334
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
335 return array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
336 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
337
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
338 GHashTable *gaim_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error) {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
339 GHashTable *hash;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
340
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
341 /* we do not need to destroy strings because they are part of the message */
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
342 hash = g_hash_table_new(g_str_hash, g_str_equal);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
343
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
344 do {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
345 char *key, *value;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
346 DBusMessageIter subiter;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
347
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
348 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
349 goto error; /* With all due respect to Dijkstra,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
350 this goto is for exception
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
351 handling, and it is ok because it
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
352 avoids duplication of the code
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
353 responsible for destroying the hash
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
354 table. Exceptional instructions
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
355 for exceptional situations. */
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
356
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
357 dbus_message_iter_recurse(iter, &subiter);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
358 if (!gaim_dbus_message_iter_get_args(&subiter, error,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
359 DBUS_TYPE_STRING, &key,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
360 DBUS_TYPE_STRING, &value,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
361 DBUS_TYPE_INVALID))
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
362 goto error; /* same here */
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
363
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
364 g_hash_table_insert(hash, key, value);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
365 } while (dbus_message_iter_next(iter));
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
366
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
367 return hash;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
368
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
369 error:
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
370 g_hash_table_destroy(hash);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
371 return NULL;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
372 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
373
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
374 /**************************************************************/
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
375 /* DBus bindings ... */
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
376 /**************************************************************/
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
377
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
378 static DBusConnection *gaim_dbus_connection;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
379
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
380 DBusConnection *gaim_dbus_get_connection(void) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
381 return gaim_dbus_connection;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
382 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
383
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
384 #include "dbus-bindings.c"
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
385
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
386 void *gaim_dbus_get_handle(void) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
387 static int handle;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
388
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
389 return &handle;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
390 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
391
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
392 static gboolean
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
393 gaim_dbus_dispatch_cb(DBusConnection *connection,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
394 DBusMessage *message,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
395 void *user_data)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
396 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
397 const char *name;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
398 GaimDBusBinding *bindings;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
399 int i;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
400
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
401 bindings = (GaimDBusBinding*) user_data;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
402
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
403 if (!dbus_message_has_path(message, DBUS_PATH_GAIM))
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
404 return FALSE;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
405
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
406 name = dbus_message_get_member(message);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
407
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
408 if (name == NULL)
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
409 return FALSE;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
410
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
411 if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
412 return FALSE;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
413
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
414 for(i=0; bindings[i].name; i++)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
415 if (!strcmp(name, bindings[i].name)) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
416 DBusMessage *reply;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
417 DBusError error;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
418
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
419 dbus_error_init(&error);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
420
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
421 reply = bindings[i].handler(message, &error);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
422
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
423 if (reply == NULL && dbus_error_is_set(&error))
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
424 reply = dbus_message_new_error (message,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
425 error.name,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
426 error.message);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
427
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
428 if (reply != NULL) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
429 dbus_connection_send (connection, reply, NULL);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
430 dbus_message_unref(reply);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
431 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
432
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
433 return TRUE; /* return reply! */
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
434 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
435
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
436 return FALSE;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
437 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
438
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
439
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
440 static const char *gettext(const char **ptr) {
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
441 const char *text = *ptr;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
442 *ptr += strlen(text) + 1;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
443 return text;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
444 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
445
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
446 static void
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
447 gaim_dbus_introspect_cb(GList **bindings_list, void *bindings) {
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
448 *bindings_list = g_list_prepend(*bindings_list, bindings);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
449 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
450
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
451 static DBusMessage *gaim_dbus_introspect(DBusMessage *message)
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
452 {
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
453 DBusMessage *reply;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
454 GString *str;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
455 GList *bindings_list, *node;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
456
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
457 str = g_string_sized_new(0x1000); /* fixme: why this size? */
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
458
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
459 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");
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
460 g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_GAIM);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
461 g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_GAIM);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
462
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
463 bindings_list = NULL;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
464 gaim_signal_emit(gaim_dbus_get_handle(), "dbus-introspect", &bindings_list);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
465
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
466 for(node = bindings_list; node; node = node->next) {
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
467 GaimDBusBinding *bindings;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
468 int i;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
469
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
470 bindings = (GaimDBusBinding*) node->data;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
471
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
472 for(i=0; bindings[i].name; i++) {
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
473 const char *text;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
474
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
475 g_string_append_printf(str, "<method name='%s'>\n", bindings[i].name);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
476
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
477 text = bindings[i].parameters;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
478 while (*text) {
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
479 const char *name, *direction, *type;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
480
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
481 direction = gettext(&text);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
482 type = gettext(&text);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
483 name = gettext(&text);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
484
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
485 g_string_append_printf(str,
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
486 "<arg name='%s' type='%s' direction='%s'/>\n",
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
487 name, type, direction);
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
488 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
489 g_string_append(str, "</method>\n");
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
490 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
491 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
492
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
493 g_string_append(str, "</interface>\n</node>\n");
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
494
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
495 reply = dbus_message_new_method_return (message);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
496 dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str),
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
497 DBUS_TYPE_INVALID);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
498 g_string_free(str, TRUE);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
499 g_list_free(bindings_list);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
500
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
501 return reply;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
502
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
503 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
504
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
505 static DBusHandlerResult gaim_dbus_dispatch(DBusConnection *connection,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
506 DBusMessage *message,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
507 void *user_data)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
508 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
509 if (gaim_signal_emit_return_1(gaim_dbus_get_handle(),
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
510 "dbus-method-called",
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
511 connection, message))
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
512 return DBUS_HANDLER_RESULT_HANDLED;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
513
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
514 if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL &&
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
515 dbus_message_has_path(message, DBUS_PATH_GAIM) &&
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
516 dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) &&
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
517 dbus_message_has_member(message, "Introspect"))
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
518 {
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
519 DBusMessage *reply;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
520 reply = gaim_dbus_introspect(message);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
521 dbus_connection_send (connection, reply, NULL);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
522 dbus_message_unref(reply);
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
523 return DBUS_HANDLER_RESULT_HANDLED;
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
524 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
525
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
526 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
527 }
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
528
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
529 void gaim_dbus_register_bindings(void *handle, GaimDBusBinding *bindings) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
530 gaim_signal_connect(gaim_dbus_get_handle(), "dbus-method-called",
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
531 handle,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
532 GAIM_CALLBACK(gaim_dbus_dispatch_cb),
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
533 bindings);
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
534 gaim_signal_connect(gaim_dbus_get_handle(), "dbus-introspect",
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
535 handle,
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
536 GAIM_CALLBACK(gaim_dbus_introspect_cb),
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
537 bindings);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
538 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
539
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
540
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
541
12627
2078f65a8e98 [gaim-migrate @ 14963]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11903
diff changeset
542 static gboolean gaim_dbus_dispatch_init(void)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
543 {
12627
2078f65a8e98 [gaim-migrate @ 14963]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11903
diff changeset
544 static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL};
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
545
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
546 DBusError error;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
547 int result;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
548
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
549 dbus_error_init (&error);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
550 gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
551
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
552 if (gaim_dbus_connection == NULL) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
553 gaim_debug_error("dbus", "Failed to get connection\n");
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
554 dbus_error_free(&error);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
555 return FALSE;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
556 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
557
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
558 if (!dbus_connection_register_object_path (gaim_dbus_connection,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
559 DBUS_PATH_GAIM, &vtable, NULL))
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
560 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
561 gaim_debug_error("dbus", "Failed to get name: %s\n", error.name);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
562 dbus_error_free(&error);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
563 return FALSE;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
564 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
565
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
566
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
567 result = dbus_bus_request_name (gaim_dbus_connection, DBUS_SERVICE_GAIM,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
568 0, &error);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
569
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
570 if (dbus_error_is_set (&error)) {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
571 dbus_connection_unref(gaim_dbus_connection);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
572 dbus_error_free(&error);
11903
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
573 gaim_dbus_connection = NULL;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
574 gaim_debug_error("dbus", "Failed to get serv name: %s\n", error.name);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
575 return FALSE;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
576 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
577
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
578 dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
579
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
580 gaim_debug_misc ("dbus", "okkk\n");
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
581
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
582 gaim_signal_register(gaim_dbus_get_handle(), "dbus-method-called",
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
583 gaim_marshal_BOOLEAN__POINTER_POINTER,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
584 gaim_value_new(GAIM_TYPE_BOOLEAN), 2,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
585 gaim_value_new(GAIM_TYPE_POINTER),
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
586 gaim_value_new(GAIM_TYPE_POINTER));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
587
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
588 gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect",
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
589 gaim_marshal_VOID__POINTER, NULL, 1,
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
590 gaim_value_new_outgoing(GAIM_TYPE_POINTER));
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
591
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
592 GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle());
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
593
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
594 return TRUE;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
595 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
596
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
597
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
598
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
599 /**************************************************************************/
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
600 /** @name Signals */
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
601 /**************************************************************************/
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
602
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
603
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
604
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
605 static char *gaim_dbus_convert_signal_name(const char *gaim_name)
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
606 {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
607 int gaim_index, g_index;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
608 char *g_name = g_new(char, strlen(gaim_name)+1);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
609 gboolean capitalize_next = TRUE;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
610
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
611 for(gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++)
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
612 if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_') {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
613 if (capitalize_next)
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
614 g_name[g_index++] = g_ascii_toupper(gaim_name[gaim_index]);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
615 else
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
616 g_name[g_index++] = gaim_name[gaim_index];
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
617 capitalize_next = FALSE;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
618 } else
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
619 capitalize_next = TRUE;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
620 g_name[g_index] = 0;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
621
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
622 return g_name;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
623 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
624
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
625 #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type))
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
626
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
627 static void gaim_dbus_message_append_gaim_values(DBusMessageIter *iter,
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
628 int number,
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
629 GaimValue **gaim_values,
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
630 va_list data)
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
631 {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
632 int i;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
633
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
634 for(i=0; i<number; i++) {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
635 const char *str;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
636 int id;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
637 gint xint;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
638 guint xuint;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
639 gboolean xboolean;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
640 gpointer ptr = NULL;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
641 if (gaim_value_is_outgoing(gaim_values[i])) {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
642 ptr = my_arg(gpointer);
11291
57fccea36e36 [gaim-migrate @ 13491]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
643 g_return_if_fail(ptr);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
644 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
645
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
646 switch(gaim_values[i]->type) {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
647 case GAIM_TYPE_INT:
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
648 xint = my_arg(gint);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
649 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
650 break;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
651 case GAIM_TYPE_UINT:
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
652 xuint = my_arg(guint);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
653 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
654 break;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
655 case GAIM_TYPE_BOOLEAN:
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
656 xboolean = my_arg(gboolean);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
657 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
658 break;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
659 case GAIM_TYPE_STRING:
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
660 str = null_to_empty(my_arg(char*));
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
661 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
662 break;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
663 case GAIM_TYPE_SUBTYPE: /* registered pointers only! */
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
664 case GAIM_TYPE_POINTER:
13134
b2d838b7eb00 [gaim-migrate @ 15496]
Richard Laager <rlaager@wiktel.com>
parents: 12627
diff changeset
665 case GAIM_TYPE_OBJECT:
b2d838b7eb00 [gaim-migrate @ 15496]
Richard Laager <rlaager@wiktel.com>
parents: 12627
diff changeset
666 case GAIM_TYPE_BOXED:
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
667 id = gaim_dbus_pointer_to_id(my_arg(gpointer));
13134
b2d838b7eb00 [gaim-migrate @ 15496]
Richard Laager <rlaager@wiktel.com>
parents: 12627
diff changeset
668 dbus_message_iter_append_basic(iter, (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
669 break;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
670 default: /* no conversion implemented */
11291
57fccea36e36 [gaim-migrate @ 13491]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
671 g_return_if_reached();
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
672 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
673 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
674 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
675
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
676 #undef my_arg
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
677
11903
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
678 void gaim_dbus_signal_emit_gaim(const char *name, int num_values,
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
679 GaimValue **values, va_list vargs)
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
680 {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
681 DBusMessage *signal;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
682 DBusMessageIter iter;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
683 char *newname;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
684
11903
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
685 #if 0 /* this is noisy with no dbus connection */
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
686 g_return_if_fail(gaim_dbus_connection);
11903
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
687 #else
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
688 if (gaim_dbus_connection == NULL)
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
689 return;
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
690 #endif
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
691
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
692
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
693 /* The test below is a hack that prevents our "dbus-method-called"
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
694 signal from being propagated to dbus. What we really need is a
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
695 flag for each signal that states whether this signal is to be
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
696 dbus-propagated or not. */
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
697 if (!strcmp(name, "dbus-method-called"))
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
698 return;
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
699
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
700 newname = gaim_dbus_convert_signal_name(name);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
701 signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
702 dbus_message_iter_init_append(signal, &iter);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
703
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
704 gaim_dbus_message_append_gaim_values(&iter, num_values, values, vargs);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
705
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
706 dbus_connection_send(gaim_dbus_connection, signal, NULL);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
707
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
708 g_free(newname);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
709 dbus_message_unref(signal);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
710 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
711
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
712
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
713
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
714
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
715
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
716
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
717 gboolean gaim_dbus_init(void)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
718 {
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
719 gaim_dbus_init_ids();
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
720 return gaim_dbus_dispatch_init() ;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
721 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
722
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
723