]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/seat-xvnc.c
Merge in VNC tests
[sojka/lightdm.git] / src / seat-xvnc.c
1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  * 
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11
12 #include "seat-xvnc.h"
13 #include "xserver-xvnc.h"
14 #include "xsession.h"
15
16 G_DEFINE_TYPE (SeatXVNC, seat_xvnc, SEAT_TYPE);
17
18 struct SeatXVNCPrivate
19 {
20     /* VNC connection */
21     GSocket *connection;
22 };
23
24 SeatXVNC *seat_xvnc_new (GSocket *connection)
25 {
26     SeatXVNC *seat;
27
28     seat = g_object_new (SEAT_XVNC_TYPE, NULL);
29     seat->priv->connection = g_object_ref (connection);
30
31     return seat;
32 }
33
34 static DisplayServer *
35 seat_xvnc_create_display_server (Seat *seat)
36 {
37     XServerXVNC *xserver;
38
39     xserver = xserver_xvnc_new ();
40     xserver_xvnc_set_socket (xserver, g_socket_get_fd (SEAT_XVNC (seat)->priv->connection));
41
42     return DISPLAY_SERVER (xserver);
43 }
44
45 static Session *
46 seat_xvnc_create_session (Seat *seat, Display *display)
47 {
48     XServerXVNC *xserver;
49     XSession *session;
50     GInetSocketAddress *address;
51     gchar *hostname;
52
53     xserver = XSERVER_XVNC (display_get_display_server (display));
54
55     session = xsession_new (XSERVER (xserver));
56     address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
57     hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
58     session_set_console_kit_parameter (SESSION (session), "remote-host-name", g_variant_new_string (hostname));
59     g_free (hostname);
60     session_set_console_kit_parameter (SESSION (session), "is-local", g_variant_new_boolean (FALSE));
61
62     return SESSION (session);
63 }
64
65 static void
66 seat_xvnc_run_script (Seat *seat, Display *display, Process *script)
67 {
68     XServerXVNC *xserver;
69     GInetSocketAddress *address;
70     gchar *hostname;
71     gchar *path;
72
73     xserver = XSERVER_XVNC (display_get_display_server (display));
74
75     address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
76     hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
77     path = xserver_xvnc_get_authority_file_path (xserver);
78
79     process_set_env (script, "REMOTE_HOST", hostname);
80     process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
81     process_set_env (script, "XAUTHORITY", path);
82
83     g_free (hostname);
84     g_free (path);
85
86     SEAT_CLASS (seat_xvnc_parent_class)->run_script (seat, display, script);
87 }
88
89 static void
90 seat_xvnc_display_removed (Seat *seat, Display *display)
91 {
92     seat_stop (seat);
93 }
94
95 static void
96 seat_xvnc_init (SeatXVNC *seat)
97 {
98     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_XVNC_TYPE, SeatXVNCPrivate);
99 }
100
101 static void
102 seat_xdmcp_session_finalize (GObject *object)
103 {
104     SeatXVNC *self;
105
106     self = SEAT_XVNC (object);
107
108     g_object_unref (self->priv->connection);
109
110     G_OBJECT_CLASS (seat_xvnc_parent_class)->finalize (object);
111 }
112
113 static void
114 seat_xvnc_class_init (SeatXVNCClass *klass)
115 {
116     SeatClass *seat_class = SEAT_CLASS (klass);
117     GObjectClass *object_class = G_OBJECT_CLASS (klass);
118
119     seat_class->create_display_server = seat_xvnc_create_display_server;
120     seat_class->create_session = seat_xvnc_create_session;
121     seat_class->run_script = seat_xvnc_run_script;
122     seat_class->display_removed = seat_xvnc_display_removed;
123     object_class->finalize = seat_xdmcp_session_finalize;
124
125     g_type_class_add_private (klass, sizeof (SeatXVNCPrivate));
126 }