Commit 72032e59 authored by William Jon McCann's avatar William Jon McCann Committed by William Jon McCann

A bit more stuff for the chooser

2007-08-31  William Jon McCann  <mccann@jhu.edu>

	* gui/simple-chooser/Makefile.am:
	* gui/simple-chooser/gdm-host-chooser-widget.c: (decode_packet),
	(do_ping), (ping_try), (xdmcp_discover), (xdmcp_init),
	(gdm_host_chooser_widget_init):
	A bit more stuff for the chooser


svn path=/branches/mccann-gobject/; revision=5212
parent 8fe7bd82
2007-08-31 William Jon McCann <mccann@jhu.edu>
* gui/simple-chooser/Makefile.am:
* gui/simple-chooser/gdm-host-chooser-widget.c: (decode_packet),
(do_ping), (ping_try), (xdmcp_discover), (xdmcp_init),
(gdm_host_chooser_widget_init):
A bit more stuff for the chooser
2007-08-31 William Jon McCann <mccann@jhu.edu>
* daemon/gdm-greeter-server.c: (generate_address):
......
......@@ -2565,8 +2565,8 @@ opcode_string (int opcode)
}
static gboolean
decode_packet (GIOChannel *source,
GIOCondition cond,
decode_packet (GIOChannel *source,
GIOCondition cond,
GdmXdmcpDisplayFactory *factory)
{
struct sockaddr_storage clnt_ss;
......
......@@ -34,6 +34,7 @@ gdm_simple_chooser_LDADD = \
$(GOBJECT_LIBS) \
$(GUI_LIBS) \
$(CHOOSER_LIBS) \
$(top_builddir)/common/libgdmcommon.la \
$(NULL)
EXTRA_DIST = \
......
......@@ -24,19 +24,33 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <X11/Xmd.h>
#include <X11/Xdmcp.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "gdm-address.h"
#include "gdm-host-chooser-widget.h"
#define GDM_HOST_CHOOSER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_HOST_CHOOSER_WIDGET, GdmHostChooserWidgetPrivate))
struct GdmHostChooserWidgetPrivate
{
GtkWidget *treeview;
GtkWidget *treeview;
XdmcpBuffer buf;
gboolean have_ipv6;
int socket_fd;
guint io_watch_id;
guint scan_time_id;
guint ping_try_id;
int ping_tries;
};
enum {
......@@ -50,13 +64,201 @@ enum {
static guint signals [LAST_SIGNAL] = { 0, };
static void gdm_host_chooser_widget_class_init (GdmHostChooserWidgetClass *klass);
static void gdm_host_chooser_widget_init (GdmHostChooserWidget *host_chooser_widget);
static void gdm_host_chooser_widget_finalize (GObject *object);
G_DEFINE_TYPE (GdmHostChooserWidget, gdm_host_chooser_widget, GTK_TYPE_VBOX)
typedef struct _XdmAuth {
ARRAY8 authentication;
ARRAY8 authorization;
} XdmAuthRec, *XdmAuthPtr;
static XdmAuthRec authlist = {
{ (CARD16) 0, (CARD8 *) 0 },
{ (CARD16) 0, (CARD8 *) 0 }
};
#define GDM_XDMCP_PROTOCOL_VERSION 1001
#define SCAN_TIMEOUT 30000
#define PING_TIMEOUT 2000
#define PING_TRIES 3
static gboolean
decode_packet (GIOChannel *source,
GIOCondition condition,
GdmHostChooserWidget *widget)
{
struct sockaddr_storage clnt_ss;
GdmAddress *address;
gint ss_len;
XdmcpHeader header;
int res;
g_debug ("decode_packet: GIOCondition %d", (int)condition);
if ( ! (condition & G_IO_IN)) {
return TRUE;
}
ss_len = sizeof (clnt_ss);
res = XdmcpFill (widget->priv->socket_fd, &widget->priv->buf, (XdmcpNetaddr)&clnt_ss, &ss_len);
if G_UNLIKELY (! res) {
g_debug (_("XMCP: Could not create XDMCP buffer!"));
return TRUE;
}
res = XdmcpReadHeader (&widget->priv->buf, &header);
if G_UNLIKELY (! res) {
g_warning (_("XDMCP: Could not read XDMCP header!"));
return TRUE;
}
if G_UNLIKELY (header.version != XDM_PROTOCOL_VERSION &&
header.version != GDM_XDMCP_PROTOCOL_VERSION) {
g_warning (_("XMDCP: Incorrect XDMCP version!"));
return TRUE;
}
address = gdm_address_new_from_sockaddr_storage (&clnt_ss);
if (address == NULL) {
g_warning (_("XMDCP: Unable to parse address"));
return TRUE;
}
gdm_address_debug (address);
return TRUE;
}
static void
do_ping (GdmHostChooserWidget *widget,
gboolean full)
{
g_debug ("do ping full:%d", full);
}
static gboolean
ping_try (GdmHostChooserWidget *widget)
{
do_ping (widget, FALSE);
widget->priv->ping_tries --;
if (widget->priv->ping_tries <= 0) {
widget->priv->ping_try_id = 0;
return FALSE;
} else {
return TRUE;
}
}
static void
xdmcp_discover (GdmHostChooserWidget *widget)
{
#if 0
gtk_widget_set_sensitive (GTK_WIDGET (manage), FALSE);
gtk_widget_set_sensitive (GTK_WIDGET (rescan), FALSE);
gtk_list_store_clear (GTK_LIST_STORE (browser_model));
gtk_widget_set_sensitive (GTK_WIDGET (browser), FALSE);
gtk_label_set_label (GTK_LABEL (status_label),
_(scanning_message));
while (hl) {
gdm_chooser_host_dispose ((GdmChooserHost *) hl->data);
hl = hl->next;
}
g_list_free (chooser_hosts);
chooser_hosts = NULL;
#endif
do_ping (widget, TRUE);
#if 0
if (widget->priv->scan_time_id > 0) {
g_source_remove (widget->priv->scan_time_id);
}
widget->priv->scan_time_id = g_timeout_add (SCAN_TIMEOUT,
chooser_scan_time_update,
widget);
#endif
/* Note we already used up one try */
widget->priv->ping_tries = PING_TRIES - 1;
if (widget->priv->ping_try_id > 0) {
g_source_remove (widget->priv->ping_try_id);
}
widget->priv->ping_try_id = g_timeout_add (PING_TIMEOUT,
ping_try,
widget);
}
static void
xdmcp_init (GdmHostChooserWidget *widget)
{
static XdmcpHeader header;
int sockopts;
int res;
GIOChannel *ioc;
sockopts = 1;
widget->priv->socket_fd = -1;
/* Open socket for communication */
#ifdef ENABLE_IPV6
widget->priv->socket_fd = socket (AF_INET6, SOCK_DGRAM, 0);
if (widget->priv->socket_fd != -1) {
widget->priv->have_ipv6 = TRUE;
}
#endif
if (! widget->priv->have_ipv6) {
widget->priv->socket_fd = socket (AF_INET, SOCK_DGRAM, 0);
if (widget->priv->socket_fd == -1) {
g_critical ("Could not create socket!");
}
}
res = setsockopt (widget->priv->socket_fd,
SOL_SOCKET,
SO_BROADCAST,
(char *) &sockopts,
sizeof (sockopts));
if (res < 0) {
g_critical ("Could not set socket options!");
}
/* Assemble XDMCP BROADCAST_QUERY packet in static buffer */
header.opcode = (CARD16) BROADCAST_QUERY;
header.length = 1;
header.version = XDM_PROTOCOL_VERSION;
XdmcpWriteHeader (&widget->priv->buf, &header);
XdmcpWriteARRAY8 (&widget->priv->buf, &authlist.authentication);
/* Assemble XDMCP QUERY packet in static buffer */
header.opcode = (CARD16) QUERY;
header.length = 1;
header.version = XDM_PROTOCOL_VERSION;
XdmcpWriteHeader (&widget->priv->buf, &header);
XdmcpWriteARRAY8 (&widget->priv->buf, &authlist.authentication);
/*gdm_chooser_add_hosts (hosts);*/
ioc = g_io_channel_unix_new (widget->priv->socket_fd);
g_io_channel_set_encoding (ioc, NULL, NULL);
g_io_channel_set_buffered (ioc, FALSE);
widget->priv->io_watch_id = g_io_add_watch(ioc,
G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
(GIOFunc)decode_packet,
widget);
g_io_channel_unref (ioc);
xdmcp_discover (widget);
}
void
gdm_host_chooser_widget_refresh (GdmHostChooserWidget *widget)
{
......@@ -193,6 +395,7 @@ gdm_host_chooser_widget_init (GdmHostChooserWidget *widget)
widget);
gtk_container_add (GTK_CONTAINER (scrolled), widget->priv->treeview);
xdmcp_init (widget);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment