[134] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com> |
---|
| 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 <fcntl.h> |
---|
| 26 | #include <unistd.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <signal.h> |
---|
| 29 | #include <sys/stat.h> |
---|
| 30 | #include <sys/types.h> |
---|
| 31 | #include <sys/socket.h> |
---|
| 32 | #include <errno.h> |
---|
| 33 | |
---|
| 34 | #include <glib.h> |
---|
| 35 | #include <glib/gi18n.h> |
---|
| 36 | #include <glib-object.h> |
---|
| 37 | |
---|
| 38 | #include "gdm-display.h" |
---|
| 39 | #include "gdm-xdmcp-chooser-display.h" |
---|
| 40 | #include "gdm-xdmcp-chooser-display-glue.h" |
---|
| 41 | |
---|
| 42 | #include "gdm-common.h" |
---|
| 43 | #include "gdm-address.h" |
---|
| 44 | |
---|
| 45 | #define DEFAULT_SLAVE_COMMAND LIBEXECDIR"/gdm-xdmcp-chooser-slave" |
---|
| 46 | |
---|
| 47 | #define GDM_DBUS_NAME "/org/gnome/DisplayManager" |
---|
| 48 | #define GDM_XDMCP_CHOOSER_SLAVE_DBUS_INTERFACE "org.gnome.DisplayManager.XdmcpChooserSlave" |
---|
| 49 | |
---|
| 50 | #define GDM_XDMCP_CHOOSER_DISPLAY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_XDMCP_CHOOSER_DISPLAY, GdmXdmcpChooserDisplayPrivate)) |
---|
| 51 | |
---|
| 52 | struct GdmXdmcpChooserDisplayPrivate |
---|
| 53 | { |
---|
| 54 | DBusGProxy *slave_proxy; |
---|
| 55 | }; |
---|
| 56 | |
---|
| 57 | enum { |
---|
| 58 | PROP_0, |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | enum { |
---|
| 62 | HOSTNAME_SELECTED, |
---|
| 63 | LAST_SIGNAL |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | static guint signals [LAST_SIGNAL] = { 0, }; |
---|
| 67 | |
---|
| 68 | static void gdm_xdmcp_chooser_display_class_init (GdmXdmcpChooserDisplayClass *klass); |
---|
| 69 | static void gdm_xdmcp_chooser_display_init (GdmXdmcpChooserDisplay *xdmcp_chooser_display); |
---|
| 70 | static void gdm_xdmcp_chooser_display_finalize (GObject *object); |
---|
| 71 | |
---|
| 72 | G_DEFINE_TYPE (GdmXdmcpChooserDisplay, gdm_xdmcp_chooser_display, GDM_TYPE_XDMCP_DISPLAY) |
---|
| 73 | |
---|
| 74 | static void |
---|
| 75 | on_hostname_selected (DBusGProxy *proxy, |
---|
| 76 | const char *hostname, |
---|
| 77 | GdmXdmcpChooserDisplay *display) |
---|
| 78 | { |
---|
| 79 | g_debug ("GdmXdmcpChooserDisplay: hostname selected: %s", hostname); |
---|
| 80 | g_signal_emit (display, signals [HOSTNAME_SELECTED], 0, hostname); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | static gboolean |
---|
| 84 | gdm_xdmcp_chooser_display_set_slave_bus_name (GdmDisplay *display, |
---|
| 85 | const char *name, |
---|
| 86 | GError **error) |
---|
| 87 | { |
---|
| 88 | char *display_id; |
---|
| 89 | const char *slave_num; |
---|
| 90 | char *slave_id; |
---|
| 91 | DBusGConnection *connection; |
---|
| 92 | GError *local_error; |
---|
| 93 | GdmXdmcpChooserDisplay *chooser_display; |
---|
| 94 | |
---|
| 95 | display_id = NULL; |
---|
| 96 | slave_id = NULL; |
---|
| 97 | slave_num = NULL; |
---|
| 98 | |
---|
| 99 | chooser_display = GDM_XDMCP_CHOOSER_DISPLAY (display); |
---|
| 100 | if (chooser_display->priv->slave_proxy != NULL) { |
---|
| 101 | g_object_unref (chooser_display->priv->slave_proxy); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | g_object_get (display, "id", &display_id, NULL); |
---|
| 105 | |
---|
| 106 | if (g_str_has_prefix (display_id, "/org/gnome/DisplayManager/Display")) { |
---|
| 107 | slave_num = display_id + strlen ("/org/gnome/DisplayManager/Display"); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | slave_id = g_strdup_printf ("/org/gnome/DisplayManager/Slave%s", slave_num); |
---|
| 111 | |
---|
| 112 | local_error = NULL; |
---|
| 113 | connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &local_error); |
---|
| 114 | if (connection == NULL) { |
---|
| 115 | if (local_error != NULL) { |
---|
| 116 | g_critical ("error getting system bus: %s", local_error->message); |
---|
| 117 | g_error_free (local_error); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | g_debug ("GdmXdmcpChooserDisplay: creating proxy for %s on %s", slave_id, name); |
---|
| 122 | |
---|
| 123 | chooser_display->priv->slave_proxy = dbus_g_proxy_new_for_name (connection, |
---|
| 124 | name, |
---|
| 125 | slave_id, |
---|
| 126 | GDM_XDMCP_CHOOSER_SLAVE_DBUS_INTERFACE); |
---|
| 127 | if (chooser_display->priv->slave_proxy == NULL) { |
---|
| 128 | g_warning ("Failed to connect to the slave object"); |
---|
| 129 | goto out; |
---|
| 130 | } |
---|
| 131 | dbus_g_proxy_add_signal (chooser_display->priv->slave_proxy, |
---|
| 132 | "HostnameSelected", |
---|
| 133 | G_TYPE_STRING, |
---|
| 134 | G_TYPE_INVALID); |
---|
| 135 | dbus_g_proxy_connect_signal (chooser_display->priv->slave_proxy, |
---|
| 136 | "HostnameSelected", |
---|
| 137 | G_CALLBACK (on_hostname_selected), |
---|
| 138 | display, |
---|
| 139 | NULL); |
---|
| 140 | out: |
---|
| 141 | |
---|
| 142 | g_free (display_id); |
---|
| 143 | g_free (slave_id); |
---|
| 144 | |
---|
| 145 | return GDM_DISPLAY_CLASS (gdm_xdmcp_chooser_display_parent_class)->set_slave_bus_name (display, name, error); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | static gboolean |
---|
| 149 | gdm_xdmcp_chooser_display_manage (GdmDisplay *display) |
---|
| 150 | { |
---|
| 151 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
| 152 | |
---|
| 153 | GDM_DISPLAY_CLASS (gdm_xdmcp_chooser_display_parent_class)->manage (display); |
---|
| 154 | |
---|
| 155 | return TRUE; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | static void |
---|
| 159 | gdm_xdmcp_chooser_display_class_init (GdmXdmcpChooserDisplayClass *klass) |
---|
| 160 | { |
---|
| 161 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
| 162 | GdmDisplayClass *display_class = GDM_DISPLAY_CLASS (klass); |
---|
| 163 | |
---|
| 164 | object_class->finalize = gdm_xdmcp_chooser_display_finalize; |
---|
| 165 | |
---|
| 166 | display_class->manage = gdm_xdmcp_chooser_display_manage; |
---|
| 167 | display_class->set_slave_bus_name = gdm_xdmcp_chooser_display_set_slave_bus_name; |
---|
| 168 | |
---|
| 169 | signals [HOSTNAME_SELECTED] = |
---|
| 170 | g_signal_new ("hostname-selected", |
---|
| 171 | G_OBJECT_CLASS_TYPE (object_class), |
---|
| 172 | G_SIGNAL_RUN_FIRST, |
---|
| 173 | G_STRUCT_OFFSET (GdmXdmcpChooserDisplayClass, hostname_selected), |
---|
| 174 | NULL, |
---|
| 175 | NULL, |
---|
| 176 | g_cclosure_marshal_VOID__STRING, |
---|
| 177 | G_TYPE_NONE, |
---|
| 178 | 1, |
---|
| 179 | G_TYPE_STRING); |
---|
| 180 | |
---|
| 181 | g_type_class_add_private (klass, sizeof (GdmXdmcpChooserDisplayPrivate)); |
---|
| 182 | |
---|
| 183 | dbus_g_object_type_install_info (GDM_TYPE_XDMCP_CHOOSER_DISPLAY, &dbus_glib_gdm_xdmcp_chooser_display_object_info); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | static void |
---|
| 187 | gdm_xdmcp_chooser_display_init (GdmXdmcpChooserDisplay *xdmcp_chooser_display) |
---|
| 188 | { |
---|
| 189 | |
---|
| 190 | xdmcp_chooser_display->priv = GDM_XDMCP_CHOOSER_DISPLAY_GET_PRIVATE (xdmcp_chooser_display); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | static void |
---|
| 194 | gdm_xdmcp_chooser_display_finalize (GObject *object) |
---|
| 195 | { |
---|
| 196 | GdmXdmcpChooserDisplay *chooser_display; |
---|
| 197 | |
---|
| 198 | g_return_if_fail (object != NULL); |
---|
| 199 | g_return_if_fail (GDM_IS_XDMCP_CHOOSER_DISPLAY (object)); |
---|
| 200 | |
---|
| 201 | chooser_display = GDM_XDMCP_CHOOSER_DISPLAY (object); |
---|
| 202 | |
---|
| 203 | g_return_if_fail (chooser_display->priv != NULL); |
---|
| 204 | |
---|
| 205 | if (chooser_display->priv->slave_proxy != NULL) { |
---|
| 206 | g_object_unref (chooser_display->priv->slave_proxy); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | G_OBJECT_CLASS (gdm_xdmcp_chooser_display_parent_class)->finalize (object); |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | GdmDisplay * |
---|
| 213 | gdm_xdmcp_chooser_display_new (const char *hostname, |
---|
| 214 | int number, |
---|
| 215 | GdmAddress *address, |
---|
| 216 | gint32 session_number) |
---|
| 217 | { |
---|
| 218 | GObject *object; |
---|
| 219 | char *x11_display; |
---|
| 220 | |
---|
| 221 | x11_display = g_strdup_printf ("%s:%d", hostname, number); |
---|
| 222 | object = g_object_new (GDM_TYPE_XDMCP_CHOOSER_DISPLAY, |
---|
| 223 | "slave-command", DEFAULT_SLAVE_COMMAND, |
---|
| 224 | "remote-hostname", hostname, |
---|
| 225 | "x11-display-number", number, |
---|
| 226 | "x11-display-name", x11_display, |
---|
| 227 | "is-local", FALSE, |
---|
| 228 | "remote-address", address, |
---|
| 229 | "session-number", session_number, |
---|
| 230 | NULL); |
---|
| 231 | g_free (x11_display); |
---|
| 232 | |
---|
| 233 | return GDM_DISPLAY (object); |
---|
| 234 | } |
---|