annotate src/dbus-server.c @ 11465:448bc3b8eb63

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