1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
2 | * |
---|
3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; either version 2 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
18 | * |
---|
19 | */ |
---|
20 | |
---|
21 | #include "config.h" |
---|
22 | |
---|
23 | #include <stdlib.h> |
---|
24 | #include <stdio.h> |
---|
25 | #include <unistd.h> |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | #include <glib.h> |
---|
29 | #include <glib/gi18n.h> |
---|
30 | #include <glib-object.h> |
---|
31 | #define DBUS_API_SUBJECT_TO_CHANGE |
---|
32 | #include <dbus/dbus.h> |
---|
33 | #include <dbus/dbus-glib.h> |
---|
34 | #include <dbus/dbus-glib-lowlevel.h> |
---|
35 | |
---|
36 | #include "gdm-greeter-client.h" |
---|
37 | #include "gdm-marshal.h" |
---|
38 | #include "gdm-profile.h" |
---|
39 | |
---|
40 | #define GDM_GREETER_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_GREETER_CLIENT, GdmGreeterClientPrivate)) |
---|
41 | |
---|
42 | #define GREETER_SERVER_DBUS_PATH "/org/gnome/DisplayManager/GreeterServer" |
---|
43 | #define GREETER_SERVER_DBUS_INTERFACE "org.gnome.DisplayManager.GreeterServer" |
---|
44 | |
---|
45 | #define GDM_DBUS_NAME "org.gnome.DisplayManager" |
---|
46 | #define GDM_DBUS_DISPLAY_INTERFACE "org.gnome.DisplayManager.Display" |
---|
47 | |
---|
48 | struct GdmGreeterClientPrivate |
---|
49 | { |
---|
50 | DBusConnection *connection; |
---|
51 | char *address; |
---|
52 | |
---|
53 | char *display_id; |
---|
54 | gboolean display_is_local; |
---|
55 | }; |
---|
56 | |
---|
57 | enum { |
---|
58 | PROP_0, |
---|
59 | }; |
---|
60 | |
---|
61 | enum { |
---|
62 | INFO, |
---|
63 | PROBLEM, |
---|
64 | INFO_QUERY, |
---|
65 | SECRET_INFO_QUERY, |
---|
66 | READY, |
---|
67 | RESET, |
---|
68 | SELECTED_USER_CHANGED, |
---|
69 | DEFAULT_LANGUAGE_NAME_CHANGED, |
---|
70 | DEFAULT_LAYOUT_NAME_CHANGED, |
---|
71 | DEFAULT_SESSION_NAME_CHANGED, |
---|
72 | TIMED_LOGIN_REQUESTED, |
---|
73 | USER_AUTHORIZED, |
---|
74 | LAST_SIGNAL |
---|
75 | }; |
---|
76 | |
---|
77 | static guint gdm_greeter_client_signals [LAST_SIGNAL]; |
---|
78 | |
---|
79 | static void gdm_greeter_client_class_init (GdmGreeterClientClass *klass); |
---|
80 | static void gdm_greeter_client_init (GdmGreeterClient *greeter_client); |
---|
81 | static void gdm_greeter_client_finalize (GObject *object); |
---|
82 | |
---|
83 | G_DEFINE_TYPE (GdmGreeterClient, gdm_greeter_client, G_TYPE_OBJECT) |
---|
84 | |
---|
85 | static gpointer client_object = NULL; |
---|
86 | |
---|
87 | GQuark |
---|
88 | gdm_greeter_client_error_quark (void) |
---|
89 | { |
---|
90 | static GQuark error_quark = 0; |
---|
91 | |
---|
92 | if (error_quark == 0) |
---|
93 | error_quark = g_quark_from_static_string ("gdm-greeter-client"); |
---|
94 | |
---|
95 | return error_quark; |
---|
96 | } |
---|
97 | |
---|
98 | gboolean |
---|
99 | gdm_greeter_client_get_display_is_local (GdmGreeterClient *client) |
---|
100 | { |
---|
101 | g_return_val_if_fail (GDM_IS_GREETER_CLIENT (client), FALSE); |
---|
102 | |
---|
103 | return client->priv->display_is_local; |
---|
104 | } |
---|
105 | |
---|
106 | static void |
---|
107 | emit_string_and_int_signal_for_message (GdmGreeterClient *client, |
---|
108 | const char *name, |
---|
109 | DBusMessage *message, |
---|
110 | int signal) |
---|
111 | { |
---|
112 | DBusError error; |
---|
113 | const char *text; |
---|
114 | int number; |
---|
115 | dbus_bool_t res; |
---|
116 | |
---|
117 | dbus_error_init (&error); |
---|
118 | res = dbus_message_get_args (message, |
---|
119 | &error, |
---|
120 | DBUS_TYPE_STRING, &text, |
---|
121 | DBUS_TYPE_INT32, &number, |
---|
122 | DBUS_TYPE_INVALID); |
---|
123 | if (res) { |
---|
124 | |
---|
125 | g_debug ("GdmGreeterClient: Received %s (%s %d)", name, text, number); |
---|
126 | |
---|
127 | g_signal_emit (client, |
---|
128 | gdm_greeter_client_signals[signal], |
---|
129 | 0, text, number); |
---|
130 | } else { |
---|
131 | g_warning ("Unable to get arguments: %s", error.message); |
---|
132 | dbus_error_free (&error); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | static void |
---|
137 | emit_string_signal_for_message (GdmGreeterClient *client, |
---|
138 | const char *name, |
---|
139 | DBusMessage *message, |
---|
140 | int signal) |
---|
141 | { |
---|
142 | DBusError error; |
---|
143 | const char *text; |
---|
144 | dbus_bool_t res; |
---|
145 | |
---|
146 | dbus_error_init (&error); |
---|
147 | res = dbus_message_get_args (message, |
---|
148 | &error, |
---|
149 | DBUS_TYPE_STRING, &text, |
---|
150 | DBUS_TYPE_INVALID); |
---|
151 | if (res) { |
---|
152 | |
---|
153 | g_debug ("GdmGreeterClient: Received %s (%s)", name, text); |
---|
154 | |
---|
155 | g_signal_emit (client, |
---|
156 | gdm_greeter_client_signals[signal], |
---|
157 | 0, text); |
---|
158 | } else { |
---|
159 | g_warning ("Unable to get arguments: %s", error.message); |
---|
160 | dbus_error_free (&error); |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | static void |
---|
165 | on_selected_user_changed (GdmGreeterClient *client, |
---|
166 | DBusMessage *message) |
---|
167 | { |
---|
168 | emit_string_signal_for_message (client, "SelectedUserChanged", message, SELECTED_USER_CHANGED); |
---|
169 | } |
---|
170 | |
---|
171 | static void |
---|
172 | on_default_language_name_changed (GdmGreeterClient *client, |
---|
173 | DBusMessage *message) |
---|
174 | { |
---|
175 | emit_string_signal_for_message (client, "DefaultLanguageNameChanged", message, DEFAULT_LANGUAGE_NAME_CHANGED); |
---|
176 | } |
---|
177 | |
---|
178 | static void |
---|
179 | on_default_layout_name_changed (GdmGreeterClient *client, |
---|
180 | DBusMessage *message) |
---|
181 | { |
---|
182 | emit_string_signal_for_message (client, "DefaultLayoutNameChanged", message, DEFAULT_LAYOUT_NAME_CHANGED); |
---|
183 | } |
---|
184 | |
---|
185 | static void |
---|
186 | on_default_session_name_changed (GdmGreeterClient *client, |
---|
187 | DBusMessage *message) |
---|
188 | { |
---|
189 | emit_string_signal_for_message (client, "DefaultSessionNameChanged", message, DEFAULT_SESSION_NAME_CHANGED); |
---|
190 | } |
---|
191 | |
---|
192 | static void |
---|
193 | on_timed_login_requested (GdmGreeterClient *client, |
---|
194 | DBusMessage *message) |
---|
195 | { |
---|
196 | emit_string_and_int_signal_for_message (client, "TimedLoginRequested", message, TIMED_LOGIN_REQUESTED); |
---|
197 | } |
---|
198 | |
---|
199 | static void |
---|
200 | on_user_authorized (GdmGreeterClient *client, |
---|
201 | DBusMessage *message) |
---|
202 | { |
---|
203 | g_signal_emit (client, |
---|
204 | gdm_greeter_client_signals[USER_AUTHORIZED], |
---|
205 | 0); |
---|
206 | } |
---|
207 | |
---|
208 | static void |
---|
209 | on_info_query (GdmGreeterClient *client, |
---|
210 | DBusMessage *message) |
---|
211 | { |
---|
212 | emit_string_signal_for_message (client, "InfoQuery", message, INFO_QUERY); |
---|
213 | } |
---|
214 | |
---|
215 | static void |
---|
216 | on_secret_info_query (GdmGreeterClient *client, |
---|
217 | DBusMessage *message) |
---|
218 | { |
---|
219 | emit_string_signal_for_message (client, "SecretInfoQuery", message, SECRET_INFO_QUERY); |
---|
220 | } |
---|
221 | |
---|
222 | static void |
---|
223 | on_info (GdmGreeterClient *client, |
---|
224 | DBusMessage *message) |
---|
225 | { |
---|
226 | emit_string_signal_for_message (client, "Info", message, INFO); |
---|
227 | } |
---|
228 | |
---|
229 | static void |
---|
230 | on_problem (GdmGreeterClient *client, |
---|
231 | DBusMessage *message) |
---|
232 | { |
---|
233 | emit_string_signal_for_message (client, "Problem", message, PROBLEM); |
---|
234 | } |
---|
235 | |
---|
236 | static void |
---|
237 | on_ready (GdmGreeterClient *client, |
---|
238 | DBusMessage *message) |
---|
239 | { |
---|
240 | g_debug ("GdmGreeterClient: Ready"); |
---|
241 | |
---|
242 | g_signal_emit (client, |
---|
243 | gdm_greeter_client_signals[READY], |
---|
244 | 0); |
---|
245 | } |
---|
246 | |
---|
247 | static void |
---|
248 | on_reset (GdmGreeterClient *client, |
---|
249 | DBusMessage *message) |
---|
250 | { |
---|
251 | g_debug ("GdmGreeterClient: Reset"); |
---|
252 | |
---|
253 | g_signal_emit (client, |
---|
254 | gdm_greeter_client_signals[RESET], |
---|
255 | 0); |
---|
256 | } |
---|
257 | |
---|
258 | static gboolean |
---|
259 | send_dbus_string_method (DBusConnection *connection, |
---|
260 | const char *method, |
---|
261 | const char *payload) |
---|
262 | { |
---|
263 | DBusError error; |
---|
264 | DBusMessage *message; |
---|
265 | DBusMessage *reply; |
---|
266 | DBusMessageIter iter; |
---|
267 | const char *str; |
---|
268 | |
---|
269 | if (payload != NULL) { |
---|
270 | str = payload; |
---|
271 | } else { |
---|
272 | str = ""; |
---|
273 | } |
---|
274 | |
---|
275 | g_debug ("GdmGreeterClient: Calling %s", method); |
---|
276 | message = dbus_message_new_method_call (NULL, |
---|
277 | GREETER_SERVER_DBUS_PATH, |
---|
278 | GREETER_SERVER_DBUS_INTERFACE, |
---|
279 | method); |
---|
280 | if (message == NULL) { |
---|
281 | g_warning ("Couldn't allocate the D-Bus message"); |
---|
282 | return FALSE; |
---|
283 | } |
---|
284 | |
---|
285 | dbus_message_iter_init_append (message, &iter); |
---|
286 | dbus_message_iter_append_basic (&iter, |
---|
287 | DBUS_TYPE_STRING, |
---|
288 | &str); |
---|
289 | |
---|
290 | dbus_error_init (&error); |
---|
291 | reply = dbus_connection_send_with_reply_and_block (connection, |
---|
292 | message, |
---|
293 | -1, |
---|
294 | &error); |
---|
295 | |
---|
296 | dbus_message_unref (message); |
---|
297 | |
---|
298 | if (dbus_error_is_set (&error)) { |
---|
299 | g_warning ("%s %s raised: %s\n", |
---|
300 | method, |
---|
301 | error.name, |
---|
302 | error.message); |
---|
303 | return FALSE; |
---|
304 | } |
---|
305 | if (reply != NULL) { |
---|
306 | dbus_message_unref (reply); |
---|
307 | } |
---|
308 | dbus_connection_flush (connection); |
---|
309 | |
---|
310 | return TRUE; |
---|
311 | } |
---|
312 | |
---|
313 | static gboolean |
---|
314 | send_dbus_bool_method (DBusConnection *connection, |
---|
315 | const char *method, |
---|
316 | gboolean payload) |
---|
317 | { |
---|
318 | DBusError error; |
---|
319 | DBusMessage *message; |
---|
320 | DBusMessage *reply; |
---|
321 | DBusMessageIter iter; |
---|
322 | |
---|
323 | g_debug ("GdmGreeterClient: Calling %s", method); |
---|
324 | message = dbus_message_new_method_call (NULL, |
---|
325 | GREETER_SERVER_DBUS_PATH, |
---|
326 | GREETER_SERVER_DBUS_INTERFACE, |
---|
327 | method); |
---|
328 | if (message == NULL) { |
---|
329 | g_warning ("Couldn't allocate the D-Bus message"); |
---|
330 | return FALSE; |
---|
331 | } |
---|
332 | |
---|
333 | dbus_message_iter_init_append (message, &iter); |
---|
334 | dbus_message_iter_append_basic (&iter, |
---|
335 | DBUS_TYPE_BOOLEAN, |
---|
336 | &payload); |
---|
337 | |
---|
338 | dbus_error_init (&error); |
---|
339 | reply = dbus_connection_send_with_reply_and_block (connection, |
---|
340 | message, |
---|
341 | -1, |
---|
342 | &error); |
---|
343 | |
---|
344 | dbus_message_unref (message); |
---|
345 | |
---|
346 | if (dbus_error_is_set (&error)) { |
---|
347 | g_warning ("%s %s raised: %s\n", |
---|
348 | method, |
---|
349 | error.name, |
---|
350 | error.message); |
---|
351 | return FALSE; |
---|
352 | } |
---|
353 | if (reply != NULL) { |
---|
354 | dbus_message_unref (reply); |
---|
355 | } |
---|
356 | dbus_connection_flush (connection); |
---|
357 | |
---|
358 | return TRUE; |
---|
359 | } |
---|
360 | |
---|
361 | static gboolean |
---|
362 | send_dbus_void_method (DBusConnection *connection, |
---|
363 | const char *method) |
---|
364 | { |
---|
365 | DBusError error; |
---|
366 | DBusMessage *message; |
---|
367 | DBusMessage *reply; |
---|
368 | |
---|
369 | g_debug ("GdmGreeterClient: Calling %s", method); |
---|
370 | message = dbus_message_new_method_call (NULL, |
---|
371 | GREETER_SERVER_DBUS_PATH, |
---|
372 | GREETER_SERVER_DBUS_INTERFACE, |
---|
373 | method); |
---|
374 | if (message == NULL) { |
---|
375 | g_warning ("Couldn't allocate the D-Bus message"); |
---|
376 | return FALSE; |
---|
377 | } |
---|
378 | |
---|
379 | dbus_error_init (&error); |
---|
380 | reply = dbus_connection_send_with_reply_and_block (connection, |
---|
381 | message, |
---|
382 | -1, |
---|
383 | &error); |
---|
384 | |
---|
385 | dbus_message_unref (message); |
---|
386 | |
---|
387 | if (dbus_error_is_set (&error)) { |
---|
388 | g_warning ("%s %s raised: %s\n", |
---|
389 | method, |
---|
390 | error.name, |
---|
391 | error.message); |
---|
392 | return FALSE; |
---|
393 | } |
---|
394 | if (reply != NULL) { |
---|
395 | dbus_message_unref (reply); |
---|
396 | } |
---|
397 | dbus_connection_flush (connection); |
---|
398 | |
---|
399 | return TRUE; |
---|
400 | } |
---|
401 | |
---|
402 | void |
---|
403 | gdm_greeter_client_call_begin_auto_login (GdmGreeterClient *client, |
---|
404 | const char *username) |
---|
405 | { |
---|
406 | send_dbus_string_method (client->priv->connection, |
---|
407 | "BeginAutoLogin", username); |
---|
408 | } |
---|
409 | |
---|
410 | void |
---|
411 | gdm_greeter_client_call_begin_verification (GdmGreeterClient *client) |
---|
412 | { |
---|
413 | send_dbus_void_method (client->priv->connection, |
---|
414 | "BeginVerification"); |
---|
415 | } |
---|
416 | |
---|
417 | void |
---|
418 | gdm_greeter_client_call_begin_verification_for_user (GdmGreeterClient *client, |
---|
419 | const char *username) |
---|
420 | { |
---|
421 | send_dbus_string_method (client->priv->connection, |
---|
422 | "BeginVerificationForUser", |
---|
423 | username); |
---|
424 | } |
---|
425 | |
---|
426 | void |
---|
427 | gdm_greeter_client_call_answer_query (GdmGreeterClient *client, |
---|
428 | const char *text) |
---|
429 | { |
---|
430 | send_dbus_string_method (client->priv->connection, |
---|
431 | "AnswerQuery", |
---|
432 | text); |
---|
433 | } |
---|
434 | |
---|
435 | void |
---|
436 | gdm_greeter_client_call_start_session_when_ready (GdmGreeterClient *client, |
---|
437 | gboolean should_start_session) |
---|
438 | { |
---|
439 | send_dbus_bool_method (client->priv->connection, |
---|
440 | "StartSessionWhenReady", |
---|
441 | should_start_session); |
---|
442 | } |
---|
443 | |
---|
444 | void |
---|
445 | gdm_greeter_client_call_select_session (GdmGreeterClient *client, |
---|
446 | const char *text) |
---|
447 | { |
---|
448 | send_dbus_string_method (client->priv->connection, |
---|
449 | "SelectSession", |
---|
450 | text); |
---|
451 | } |
---|
452 | |
---|
453 | void |
---|
454 | gdm_greeter_client_call_select_language (GdmGreeterClient *client, |
---|
455 | const char *text) |
---|
456 | { |
---|
457 | send_dbus_string_method (client->priv->connection, |
---|
458 | "SelectLanguage", |
---|
459 | text); |
---|
460 | } |
---|
461 | |
---|
462 | void |
---|
463 | gdm_greeter_client_call_select_layout (GdmGreeterClient *client, |
---|
464 | const char *text) |
---|
465 | { |
---|
466 | send_dbus_string_method (client->priv->connection, |
---|
467 | "SelectLayout", |
---|
468 | text); |
---|
469 | } |
---|
470 | void |
---|
471 | gdm_greeter_client_call_select_user (GdmGreeterClient *client, |
---|
472 | const char *text) |
---|
473 | { |
---|
474 | send_dbus_string_method (client->priv->connection, |
---|
475 | "SelectUser", |
---|
476 | text); |
---|
477 | } |
---|
478 | |
---|
479 | void |
---|
480 | gdm_greeter_client_call_select_hostname (GdmGreeterClient *client, |
---|
481 | const char *text) |
---|
482 | { |
---|
483 | send_dbus_string_method (client->priv->connection, |
---|
484 | "SelectHostname", |
---|
485 | text); |
---|
486 | } |
---|
487 | |
---|
488 | void |
---|
489 | gdm_greeter_client_call_cancel (GdmGreeterClient *client) |
---|
490 | { |
---|
491 | send_dbus_void_method (client->priv->connection, |
---|
492 | "Cancel"); |
---|
493 | } |
---|
494 | |
---|
495 | void |
---|
496 | gdm_greeter_client_call_disconnect (GdmGreeterClient *client) |
---|
497 | { |
---|
498 | send_dbus_void_method (client->priv->connection, |
---|
499 | "Disconnect"); |
---|
500 | } |
---|
501 | |
---|
502 | |
---|
503 | static gboolean |
---|
504 | send_get_display_id (GdmGreeterClient *client, |
---|
505 | const char *method, |
---|
506 | char **answerp) |
---|
507 | { |
---|
508 | DBusError error; |
---|
509 | DBusMessage *message; |
---|
510 | DBusMessage *reply; |
---|
511 | DBusMessageIter iter; |
---|
512 | gboolean ret; |
---|
513 | const char *answer; |
---|
514 | |
---|
515 | ret = FALSE; |
---|
516 | |
---|
517 | g_debug ("GdmGreeterClient: Calling %s", method); |
---|
518 | message = dbus_message_new_method_call (NULL, |
---|
519 | GREETER_SERVER_DBUS_PATH, |
---|
520 | GREETER_SERVER_DBUS_INTERFACE, |
---|
521 | method); |
---|
522 | if (message == NULL) { |
---|
523 | g_warning ("Couldn't allocate the D-Bus message"); |
---|
524 | return FALSE; |
---|
525 | } |
---|
526 | |
---|
527 | dbus_error_init (&error); |
---|
528 | reply = dbus_connection_send_with_reply_and_block (client->priv->connection, |
---|
529 | message, |
---|
530 | -1, |
---|
531 | &error); |
---|
532 | dbus_message_unref (message); |
---|
533 | |
---|
534 | if (dbus_error_is_set (&error)) { |
---|
535 | g_warning ("%s %s raised: %s\n", |
---|
536 | method, |
---|
537 | error.name, |
---|
538 | error.message); |
---|
539 | goto out; |
---|
540 | } |
---|
541 | |
---|
542 | dbus_message_iter_init (reply, &iter); |
---|
543 | dbus_message_iter_get_basic (&iter, &answer); |
---|
544 | if (answerp != NULL) { |
---|
545 | *answerp = g_strdup (answer); |
---|
546 | } |
---|
547 | ret = TRUE; |
---|
548 | |
---|
549 | dbus_message_unref (reply); |
---|
550 | dbus_connection_flush (client->priv->connection); |
---|
551 | |
---|
552 | out: |
---|
553 | |
---|
554 | return ret; |
---|
555 | } |
---|
556 | |
---|
557 | char * |
---|
558 | gdm_greeter_client_call_get_display_id (GdmGreeterClient *client) |
---|
559 | { |
---|
560 | char *display_id; |
---|
561 | |
---|
562 | display_id = NULL; |
---|
563 | send_get_display_id (client, |
---|
564 | "GetDisplayId", |
---|
565 | &display_id); |
---|
566 | |
---|
567 | return display_id; |
---|
568 | } |
---|
569 | |
---|
570 | static void |
---|
571 | cache_display_values (GdmGreeterClient *client) |
---|
572 | { |
---|
573 | DBusGProxy *display_proxy; |
---|
574 | DBusGConnection *connection; |
---|
575 | GError *error; |
---|
576 | gboolean res; |
---|
577 | |
---|
578 | g_free (client->priv->display_id); |
---|
579 | client->priv->display_id = gdm_greeter_client_call_get_display_id (client); |
---|
580 | if (client->priv->display_id == NULL) { |
---|
581 | return; |
---|
582 | } |
---|
583 | |
---|
584 | error = NULL; |
---|
585 | connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); |
---|
586 | if (connection == NULL) { |
---|
587 | if (error != NULL) { |
---|
588 | g_critical ("error getting system bus: %s", error->message); |
---|
589 | g_error_free (error); |
---|
590 | } |
---|
591 | return; |
---|
592 | } |
---|
593 | |
---|
594 | g_debug ("GdmGreeterClient: Creating proxy for %s", client->priv->display_id); |
---|
595 | display_proxy = dbus_g_proxy_new_for_name (connection, |
---|
596 | GDM_DBUS_NAME, |
---|
597 | client->priv->display_id, |
---|
598 | GDM_DBUS_DISPLAY_INTERFACE); |
---|
599 | /* cache some values up front */ |
---|
600 | error = NULL; |
---|
601 | res = dbus_g_proxy_call (display_proxy, |
---|
602 | "IsLocal", |
---|
603 | &error, |
---|
604 | G_TYPE_INVALID, |
---|
605 | G_TYPE_BOOLEAN, &client->priv->display_is_local, |
---|
606 | G_TYPE_INVALID); |
---|
607 | if (! res) { |
---|
608 | if (error != NULL) { |
---|
609 | g_warning ("Failed to get value: %s", error->message); |
---|
610 | g_error_free (error); |
---|
611 | } else { |
---|
612 | g_warning ("Failed to get value"); |
---|
613 | } |
---|
614 | } |
---|
615 | } |
---|
616 | |
---|
617 | static DBusHandlerResult |
---|
618 | client_dbus_handle_message (DBusConnection *connection, |
---|
619 | DBusMessage *message, |
---|
620 | void *user_data, |
---|
621 | dbus_bool_t local_interface) |
---|
622 | { |
---|
623 | GdmGreeterClient *client = GDM_GREETER_CLIENT (user_data); |
---|
624 | |
---|
625 | #if 0 |
---|
626 | g_message ("obj_path=%s interface=%s method=%s destination=%s", |
---|
627 | dbus_message_get_path (message), |
---|
628 | dbus_message_get_interface (message), |
---|
629 | dbus_message_get_member (message), |
---|
630 | dbus_message_get_destination (message)); |
---|
631 | #endif |
---|
632 | |
---|
633 | g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); |
---|
634 | g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); |
---|
635 | |
---|
636 | if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "InfoQuery")) { |
---|
637 | on_info_query (client, message); |
---|
638 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "SecretInfoQuery")) { |
---|
639 | on_secret_info_query (client, message); |
---|
640 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "Info")) { |
---|
641 | on_info (client, message); |
---|
642 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "Problem")) { |
---|
643 | on_problem (client, message); |
---|
644 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "Ready")) { |
---|
645 | on_ready (client, message); |
---|
646 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "Reset")) { |
---|
647 | on_reset (client, message); |
---|
648 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "SelectedUserChanged")) { |
---|
649 | on_selected_user_changed (client, message); |
---|
650 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "DefaultLanguageNameChanged")) { |
---|
651 | on_default_language_name_changed (client, message); |
---|
652 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "DefaultLayoutNameChanged")) { |
---|
653 | on_default_layout_name_changed (client, message); |
---|
654 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "DefaultSessionNameChanged")) { |
---|
655 | on_default_session_name_changed (client, message); |
---|
656 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "TimedLoginRequested")) { |
---|
657 | on_timed_login_requested (client, message); |
---|
658 | } else if (dbus_message_is_signal (message, GREETER_SERVER_DBUS_INTERFACE, "UserAuthorized")) { |
---|
659 | on_user_authorized (client, message); |
---|
660 | } else { |
---|
661 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
---|
662 | } |
---|
663 | |
---|
664 | return DBUS_HANDLER_RESULT_HANDLED; |
---|
665 | } |
---|
666 | |
---|
667 | static DBusHandlerResult |
---|
668 | client_dbus_filter_function (DBusConnection *connection, |
---|
669 | DBusMessage *message, |
---|
670 | void *user_data) |
---|
671 | { |
---|
672 | GdmGreeterClient *client = GDM_GREETER_CLIENT (user_data); |
---|
673 | const char *path; |
---|
674 | |
---|
675 | path = dbus_message_get_path (message); |
---|
676 | |
---|
677 | g_debug ("GdmGreeterClient: obj_path=%s interface=%s method=%s", |
---|
678 | dbus_message_get_path (message), |
---|
679 | dbus_message_get_interface (message), |
---|
680 | dbus_message_get_member (message)); |
---|
681 | |
---|
682 | if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") |
---|
683 | && strcmp (path, DBUS_PATH_LOCAL) == 0) { |
---|
684 | |
---|
685 | g_message ("Got disconnected from the session message bus"); |
---|
686 | |
---|
687 | dbus_connection_unref (connection); |
---|
688 | client->priv->connection = NULL; |
---|
689 | |
---|
690 | } else if (dbus_message_is_signal (message, |
---|
691 | DBUS_INTERFACE_DBUS, |
---|
692 | "NameOwnerChanged")) { |
---|
693 | g_debug ("GdmGreeterClient: Name owner changed?"); |
---|
694 | } else { |
---|
695 | return client_dbus_handle_message (connection, message, user_data, FALSE); |
---|
696 | } |
---|
697 | |
---|
698 | return DBUS_HANDLER_RESULT_HANDLED; |
---|
699 | } |
---|
700 | |
---|
701 | gboolean |
---|
702 | gdm_greeter_client_start (GdmGreeterClient *client, |
---|
703 | GError **error) |
---|
704 | { |
---|
705 | gboolean ret; |
---|
706 | DBusError local_error; |
---|
707 | |
---|
708 | g_return_val_if_fail (GDM_IS_GREETER_CLIENT (client), FALSE); |
---|
709 | |
---|
710 | gdm_profile_start (NULL); |
---|
711 | |
---|
712 | ret = FALSE; |
---|
713 | |
---|
714 | if (client->priv->address == NULL) { |
---|
715 | g_warning ("GDM_GREETER_DBUS_ADDRESS not set"); |
---|
716 | g_set_error (error, |
---|
717 | GDM_GREETER_CLIENT_ERROR, |
---|
718 | GDM_GREETER_CLIENT_ERROR_GENERIC, |
---|
719 | "GDM_GREETER_DBUS_ADDRESS not set"); |
---|
720 | goto out; |
---|
721 | } |
---|
722 | |
---|
723 | g_debug ("GdmGreeterClient: connecting to address: %s", client->priv->address); |
---|
724 | |
---|
725 | dbus_error_init (&local_error); |
---|
726 | client->priv->connection = dbus_connection_open (client->priv->address, &local_error); |
---|
727 | if (client->priv->connection == NULL) { |
---|
728 | if (dbus_error_is_set (&local_error)) { |
---|
729 | g_warning ("error opening connection: %s", local_error.message); |
---|
730 | g_set_error (error, |
---|
731 | GDM_GREETER_CLIENT_ERROR, |
---|
732 | GDM_GREETER_CLIENT_ERROR_GENERIC, |
---|
733 | "%s", local_error.message); |
---|
734 | dbus_error_free (&local_error); |
---|
735 | } else { |
---|
736 | g_warning ("Unable to open connection"); |
---|
737 | } |
---|
738 | goto out; |
---|
739 | } |
---|
740 | |
---|
741 | dbus_connection_setup_with_g_main (client->priv->connection, NULL); |
---|
742 | dbus_connection_set_exit_on_disconnect (client->priv->connection, TRUE); |
---|
743 | |
---|
744 | dbus_connection_add_filter (client->priv->connection, |
---|
745 | client_dbus_filter_function, |
---|
746 | client, |
---|
747 | NULL); |
---|
748 | |
---|
749 | cache_display_values (client); |
---|
750 | |
---|
751 | ret = TRUE; |
---|
752 | |
---|
753 | out: |
---|
754 | gdm_profile_end (NULL); |
---|
755 | |
---|
756 | return ret; |
---|
757 | } |
---|
758 | |
---|
759 | void |
---|
760 | gdm_greeter_client_stop (GdmGreeterClient *client) |
---|
761 | { |
---|
762 | g_return_if_fail (GDM_IS_GREETER_CLIENT (client)); |
---|
763 | |
---|
764 | } |
---|
765 | |
---|
766 | static void |
---|
767 | gdm_greeter_client_set_property (GObject *object, |
---|
768 | guint prop_id, |
---|
769 | const GValue *value, |
---|
770 | GParamSpec *pspec) |
---|
771 | { |
---|
772 | switch (prop_id) { |
---|
773 | default: |
---|
774 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
775 | break; |
---|
776 | } |
---|
777 | } |
---|
778 | |
---|
779 | static void |
---|
780 | gdm_greeter_client_get_property (GObject *object, |
---|
781 | guint prop_id, |
---|
782 | GValue *value, |
---|
783 | GParamSpec *pspec) |
---|
784 | { |
---|
785 | switch (prop_id) { |
---|
786 | default: |
---|
787 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
788 | break; |
---|
789 | } |
---|
790 | } |
---|
791 | |
---|
792 | static GObject * |
---|
793 | gdm_greeter_client_constructor (GType type, |
---|
794 | guint n_construct_properties, |
---|
795 | GObjectConstructParam *construct_properties) |
---|
796 | { |
---|
797 | GdmGreeterClient *greeter_client; |
---|
798 | |
---|
799 | greeter_client = GDM_GREETER_CLIENT (G_OBJECT_CLASS (gdm_greeter_client_parent_class)->constructor (type, |
---|
800 | n_construct_properties, |
---|
801 | construct_properties)); |
---|
802 | |
---|
803 | return G_OBJECT (greeter_client); |
---|
804 | } |
---|
805 | |
---|
806 | static void |
---|
807 | gdm_greeter_client_dispose (GObject *object) |
---|
808 | { |
---|
809 | g_debug ("GdmGreeterClient: Disposing greeter_client"); |
---|
810 | |
---|
811 | G_OBJECT_CLASS (gdm_greeter_client_parent_class)->dispose (object); |
---|
812 | } |
---|
813 | |
---|
814 | static void |
---|
815 | gdm_greeter_client_class_init (GdmGreeterClientClass *klass) |
---|
816 | { |
---|
817 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
818 | |
---|
819 | object_class->get_property = gdm_greeter_client_get_property; |
---|
820 | object_class->set_property = gdm_greeter_client_set_property; |
---|
821 | object_class->constructor = gdm_greeter_client_constructor; |
---|
822 | object_class->dispose = gdm_greeter_client_dispose; |
---|
823 | object_class->finalize = gdm_greeter_client_finalize; |
---|
824 | |
---|
825 | g_type_class_add_private (klass, sizeof (GdmGreeterClientPrivate)); |
---|
826 | |
---|
827 | gdm_greeter_client_signals[INFO_QUERY] = |
---|
828 | g_signal_new ("info-query", |
---|
829 | G_OBJECT_CLASS_TYPE (object_class), |
---|
830 | G_SIGNAL_RUN_LAST, |
---|
831 | G_STRUCT_OFFSET (GdmGreeterClientClass, info_query), |
---|
832 | NULL, |
---|
833 | NULL, |
---|
834 | g_cclosure_marshal_VOID__STRING, |
---|
835 | G_TYPE_NONE, |
---|
836 | 1, |
---|
837 | G_TYPE_STRING); |
---|
838 | |
---|
839 | gdm_greeter_client_signals[SECRET_INFO_QUERY] = |
---|
840 | g_signal_new ("secret-info-query", |
---|
841 | G_OBJECT_CLASS_TYPE (object_class), |
---|
842 | G_SIGNAL_RUN_LAST, |
---|
843 | G_STRUCT_OFFSET (GdmGreeterClientClass, secret_info_query), |
---|
844 | NULL, |
---|
845 | NULL, |
---|
846 | g_cclosure_marshal_VOID__STRING, |
---|
847 | G_TYPE_NONE, |
---|
848 | 1, |
---|
849 | G_TYPE_STRING); |
---|
850 | |
---|
851 | gdm_greeter_client_signals[INFO] = |
---|
852 | g_signal_new ("info", |
---|
853 | G_OBJECT_CLASS_TYPE (object_class), |
---|
854 | G_SIGNAL_RUN_FIRST, |
---|
855 | G_STRUCT_OFFSET (GdmGreeterClientClass, info), |
---|
856 | NULL, |
---|
857 | NULL, |
---|
858 | g_cclosure_marshal_VOID__STRING, |
---|
859 | G_TYPE_NONE, |
---|
860 | 1, |
---|
861 | G_TYPE_STRING); |
---|
862 | |
---|
863 | gdm_greeter_client_signals[PROBLEM] = |
---|
864 | g_signal_new ("problem", |
---|
865 | G_OBJECT_CLASS_TYPE (object_class), |
---|
866 | G_SIGNAL_RUN_FIRST, |
---|
867 | G_STRUCT_OFFSET (GdmGreeterClientClass, problem), |
---|
868 | NULL, |
---|
869 | NULL, |
---|
870 | g_cclosure_marshal_VOID__STRING, |
---|
871 | G_TYPE_NONE, |
---|
872 | 1, |
---|
873 | G_TYPE_STRING); |
---|
874 | |
---|
875 | gdm_greeter_client_signals[READY] = |
---|
876 | g_signal_new ("ready", |
---|
877 | G_OBJECT_CLASS_TYPE (object_class), |
---|
878 | G_SIGNAL_RUN_FIRST, |
---|
879 | G_STRUCT_OFFSET (GdmGreeterClientClass, ready), |
---|
880 | NULL, |
---|
881 | NULL, |
---|
882 | g_cclosure_marshal_VOID__VOID, |
---|
883 | G_TYPE_NONE, |
---|
884 | 0); |
---|
885 | |
---|
886 | gdm_greeter_client_signals[RESET] = |
---|
887 | g_signal_new ("reset", |
---|
888 | G_OBJECT_CLASS_TYPE (object_class), |
---|
889 | G_SIGNAL_RUN_FIRST, |
---|
890 | G_STRUCT_OFFSET (GdmGreeterClientClass, reset), |
---|
891 | NULL, |
---|
892 | NULL, |
---|
893 | g_cclosure_marshal_VOID__VOID, |
---|
894 | G_TYPE_NONE, |
---|
895 | 0); |
---|
896 | gdm_greeter_client_signals[SELECTED_USER_CHANGED] = |
---|
897 | g_signal_new ("selected-user-changed", |
---|
898 | G_OBJECT_CLASS_TYPE (object_class), |
---|
899 | G_SIGNAL_RUN_FIRST, |
---|
900 | G_STRUCT_OFFSET (GdmGreeterClientClass, selected_user_changed), |
---|
901 | NULL, |
---|
902 | NULL, |
---|
903 | g_cclosure_marshal_VOID__STRING, |
---|
904 | G_TYPE_NONE, |
---|
905 | 1, G_TYPE_STRING); |
---|
906 | gdm_greeter_client_signals[DEFAULT_LANGUAGE_NAME_CHANGED] = |
---|
907 | g_signal_new ("default-language-name-changed", |
---|
908 | G_OBJECT_CLASS_TYPE (object_class), |
---|
909 | G_SIGNAL_RUN_FIRST, |
---|
910 | G_STRUCT_OFFSET (GdmGreeterClientClass, default_language_name_changed), |
---|
911 | NULL, |
---|
912 | NULL, |
---|
913 | g_cclosure_marshal_VOID__STRING, |
---|
914 | G_TYPE_NONE, |
---|
915 | 1, G_TYPE_STRING); |
---|
916 | gdm_greeter_client_signals[DEFAULT_LAYOUT_NAME_CHANGED] = |
---|
917 | g_signal_new ("default-layout-name-changed", |
---|
918 | G_OBJECT_CLASS_TYPE (object_class), |
---|
919 | G_SIGNAL_RUN_FIRST, |
---|
920 | G_STRUCT_OFFSET (GdmGreeterClientClass, default_layout_name_changed), |
---|
921 | NULL, |
---|
922 | NULL, |
---|
923 | g_cclosure_marshal_VOID__STRING, |
---|
924 | G_TYPE_NONE, |
---|
925 | 1, G_TYPE_STRING); |
---|
926 | gdm_greeter_client_signals[DEFAULT_SESSION_NAME_CHANGED] = |
---|
927 | g_signal_new ("default-session-name-changed", |
---|
928 | G_OBJECT_CLASS_TYPE (object_class), |
---|
929 | G_SIGNAL_RUN_FIRST, |
---|
930 | G_STRUCT_OFFSET (GdmGreeterClientClass, default_session_name_changed), |
---|
931 | NULL, |
---|
932 | NULL, |
---|
933 | g_cclosure_marshal_VOID__STRING, |
---|
934 | G_TYPE_NONE, |
---|
935 | 1, G_TYPE_STRING); |
---|
936 | |
---|
937 | gdm_greeter_client_signals[TIMED_LOGIN_REQUESTED] = |
---|
938 | g_signal_new ("timed-login-requested", |
---|
939 | G_OBJECT_CLASS_TYPE (object_class), |
---|
940 | G_SIGNAL_RUN_FIRST, |
---|
941 | G_STRUCT_OFFSET (GdmGreeterClientClass, default_session_name_changed), |
---|
942 | NULL, |
---|
943 | NULL, |
---|
944 | gdm_marshal_VOID__STRING_INT, |
---|
945 | G_TYPE_NONE, |
---|
946 | 2, G_TYPE_STRING, G_TYPE_INT); |
---|
947 | |
---|
948 | gdm_greeter_client_signals[USER_AUTHORIZED] = |
---|
949 | g_signal_new ("user-authorized", |
---|
950 | G_OBJECT_CLASS_TYPE (object_class), |
---|
951 | G_SIGNAL_RUN_FIRST, |
---|
952 | G_STRUCT_OFFSET (GdmGreeterClientClass, user_authorized), |
---|
953 | NULL, |
---|
954 | NULL, |
---|
955 | g_cclosure_marshal_VOID__VOID, |
---|
956 | G_TYPE_NONE, 0); |
---|
957 | } |
---|
958 | |
---|
959 | static void |
---|
960 | gdm_greeter_client_init (GdmGreeterClient *client) |
---|
961 | { |
---|
962 | |
---|
963 | client->priv = GDM_GREETER_CLIENT_GET_PRIVATE (client); |
---|
964 | |
---|
965 | client->priv->address = g_strdup (g_getenv ("GDM_GREETER_DBUS_ADDRESS")); |
---|
966 | } |
---|
967 | |
---|
968 | static void |
---|
969 | gdm_greeter_client_finalize (GObject *object) |
---|
970 | { |
---|
971 | GdmGreeterClient *client; |
---|
972 | |
---|
973 | g_return_if_fail (object != NULL); |
---|
974 | g_return_if_fail (GDM_IS_GREETER_CLIENT (object)); |
---|
975 | |
---|
976 | client = GDM_GREETER_CLIENT (object); |
---|
977 | |
---|
978 | g_return_if_fail (client->priv != NULL); |
---|
979 | |
---|
980 | g_free (client->priv->address); |
---|
981 | |
---|
982 | G_OBJECT_CLASS (gdm_greeter_client_parent_class)->finalize (object); |
---|
983 | } |
---|
984 | |
---|
985 | GdmGreeterClient * |
---|
986 | gdm_greeter_client_new (void) |
---|
987 | { |
---|
988 | if (client_object != NULL) { |
---|
989 | g_object_ref (client_object); |
---|
990 | } else { |
---|
991 | client_object = g_object_new (GDM_TYPE_GREETER_CLIENT, NULL); |
---|
992 | g_object_add_weak_pointer (client_object, |
---|
993 | (gpointer *) &client_object); |
---|
994 | } |
---|
995 | |
---|
996 | return GDM_GREETER_CLIENT (client_object); |
---|
997 | } |
---|