Back to index

lightdm  1.3.2
seat-xvnc.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2011 Robert Ancell.
00003  * Author: Robert Ancell <robert.ancell@canonical.com>
00004  * 
00005  * This program is free software: you can redistribute it and/or modify it under
00006  * the terms of the GNU General Public License as published by the Free Software
00007  * Foundation, either version 3 of the License, or (at your option) any later
00008  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
00009  * license.
00010  */
00011 
00012 #include "seat-xvnc.h"
00013 #include "xserver-xvnc.h"
00014 #include "xsession.h"
00015 #include "configuration.h"
00016 
00017 G_DEFINE_TYPE (SeatXVNC, seat_xvnc, SEAT_TYPE);
00018 
00019 struct SeatXVNCPrivate
00020 {
00021     /* VNC connection */
00022     GSocket *connection;
00023 };
00024 
00025 SeatXVNC *seat_xvnc_new (GSocket *connection)
00026 {
00027     SeatXVNC *seat;
00028 
00029     seat = g_object_new (SEAT_XVNC_TYPE, NULL);
00030     seat->priv->connection = g_object_ref (connection);
00031 
00032     return seat;
00033 }
00034 
00035 static DisplayServer *
00036 seat_xvnc_create_display_server (Seat *seat)
00037 {
00038     XServerXVNC *xserver;
00039 
00040     xserver = xserver_xvnc_new ();
00041     xserver_xvnc_set_socket (xserver, g_socket_get_fd (SEAT_XVNC (seat)->priv->connection));
00042 
00043     if (config_has_key (config_get_instance (), "VNCServer", "width") &&
00044         config_has_key (config_get_instance (), "VNCServer", "height"))
00045     {
00046         gint width, height;
00047         width = config_get_integer (config_get_instance (), "VNCServer", "width");
00048         height = config_get_integer (config_get_instance (), "VNCServer", "height");
00049         if (height > 0 && width > 0)
00050             xserver_xvnc_set_geometry (xserver, width, height);
00051     }
00052     if (config_has_key (config_get_instance (), "VNCServer", "depth"))
00053     {
00054         gint depth;
00055         depth = config_get_integer (config_get_instance (), "VNCServer", "depth");
00056         if (depth == 8 || depth == 16 || depth == 24 || depth == 32)
00057             xserver_xvnc_set_depth (xserver, depth);
00058     }
00059 
00060     return DISPLAY_SERVER (xserver);
00061 }
00062 
00063 static Session *
00064 seat_xvnc_create_session (Seat *seat, Display *display)
00065 {
00066     XServerXVNC *xserver;
00067     XSession *session;
00068     GInetSocketAddress *address;
00069     gchar *hostname;
00070 
00071     xserver = XSERVER_XVNC (display_get_display_server (display));
00072 
00073     session = xsession_new (XSERVER (xserver));
00074     address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
00075     hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
00076     session_set_remote_host_name (SESSION (session), hostname);
00077     g_free (hostname);
00078 
00079     return SESSION (session);
00080 }
00081 
00082 static void
00083 seat_xvnc_run_script (Seat *seat, Display *display, Process *script)
00084 {
00085     XServerXVNC *xserver;
00086     GInetSocketAddress *address;
00087     gchar *hostname;
00088     gchar *path;
00089 
00090     xserver = XSERVER_XVNC (display_get_display_server (display));
00091 
00092     address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (SEAT_XVNC (seat)->priv->connection, NULL));
00093     hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
00094     path = xserver_xvnc_get_authority_file_path (xserver);
00095 
00096     process_set_env (script, "REMOTE_HOST", hostname);
00097     process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
00098     process_set_env (script, "XAUTHORITY", path);
00099 
00100     g_free (hostname);
00101     g_free (path);
00102 
00103     SEAT_CLASS (seat_xvnc_parent_class)->run_script (seat, display, script);
00104 }
00105 
00106 static void
00107 seat_xvnc_display_removed (Seat *seat, Display *display)
00108 {
00109     seat_stop (seat);
00110 }
00111 
00112 static void
00113 seat_xvnc_init (SeatXVNC *seat)
00114 {
00115     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_XVNC_TYPE, SeatXVNCPrivate);
00116 }
00117 
00118 static void
00119 seat_xdmcp_session_finalize (GObject *object)
00120 {
00121     SeatXVNC *self;
00122 
00123     self = SEAT_XVNC (object);
00124 
00125     g_object_unref (self->priv->connection);
00126 
00127     G_OBJECT_CLASS (seat_xvnc_parent_class)->finalize (object);
00128 }
00129 
00130 static void
00131 seat_xvnc_class_init (SeatXVNCClass *klass)
00132 {
00133     SeatClass *seat_class = SEAT_CLASS (klass);
00134     GObjectClass *object_class = G_OBJECT_CLASS (klass);
00135 
00136     seat_class->create_display_server = seat_xvnc_create_display_server;
00137     seat_class->create_session = seat_xvnc_create_session;
00138     seat_class->run_script = seat_xvnc_run_script;
00139     seat_class->display_removed = seat_xvnc_display_removed;
00140     object_class->finalize = seat_xdmcp_session_finalize;
00141 
00142     g_type_class_add_private (klass, sizeof (SeatXVNCPrivate));
00143 }