diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2015-11-20 13:03:36 +1300 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2015-11-20 13:03:36 +1300 |
commit | 0197e0c37094638d0d6d646aa44ca6e8ce1775cf (patch) | |
tree | 8a50dc8e98bdb7dd93cc1f05748f3f8bf310a5f9 /tests/src | |
parent | 3d160784fd90f82be10ba2cb7d5e15521fff96c4 (diff) | |
download | lightdm-git-0197e0c37094638d0d6d646aa44ca6e8ce1775cf.tar.gz |
Check LightDM responds to XDMCP KeepAlive packets
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/X.c | 23 | ||||
-rw-r--r-- | tests/src/xdmcp-client.c | 47 | ||||
-rw-r--r-- | tests/src/xdmcp-client.h | 10 |
3 files changed, 80 insertions, 0 deletions
diff --git a/tests/src/X.c b/tests/src/X.c index ca25c532..a367a9d4 100644 --- a/tests/src/X.c +++ b/tests/src/X.c @@ -170,6 +170,12 @@ xdmcp_failed_cb (XDMCPClient *client, XDMCPFailed *message) } static void +xdmcp_alive_cb (XDMCPClient *client, XDMCPAlive *message) +{ + status_notify ("%s GOT-ALIVE SESSION-RUNNING=%s SESSION-ID=%d", id, message->session_running ? "TRUE" : "FALSE", message->session_id); +} + +static void client_connected_cb (XServer *server, XClient *client) { status_notify ("%s ACCEPT-CONNECT", id); @@ -315,6 +321,22 @@ request_cb (const gchar *name, GHashTable *params) manage_display_number, display_class); } + + else if (strcmp (name, "SEND-KEEP-ALIVE") == 0) + { + const char *text; + guint32 session_id = xdmcp_session_id; + guint16 keep_alive_display_number = display_number; + + text = g_hash_table_lookup (params, "DISPLAY-NUMBER"); + if (text) + keep_alive_display_number = atoi (text); + text = g_hash_table_lookup (params, "SESSION-ID"); + if (text) + session_id = atoi (text); + + xdmcp_client_send_keep_alive (xdmcp_client, keep_alive_display_number, session_id); + } } static int @@ -594,6 +616,7 @@ main (int argc, char **argv) g_signal_connect (xdmcp_client, XDMCP_CLIENT_SIGNAL_ACCEPT, G_CALLBACK (xdmcp_accept_cb), NULL); g_signal_connect (xdmcp_client, XDMCP_CLIENT_SIGNAL_DECLINE, G_CALLBACK (xdmcp_decline_cb), NULL); g_signal_connect (xdmcp_client, XDMCP_CLIENT_SIGNAL_FAILED, G_CALLBACK (xdmcp_failed_cb), NULL); + g_signal_connect (xdmcp_client, XDMCP_CLIENT_SIGNAL_ALIVE, G_CALLBACK (xdmcp_alive_cb), NULL); } g_main_loop_run (loop); diff --git a/tests/src/xdmcp-client.c b/tests/src/xdmcp-client.c index e81bfad3..84b0b599 100644 --- a/tests/src/xdmcp-client.c +++ b/tests/src/xdmcp-client.c @@ -48,6 +48,7 @@ enum { XDMCP_CLIENT_ACCEPT, XDMCP_CLIENT_DECLINE, XDMCP_CLIENT_FAILED, + XDMCP_CLIENT_ALIVE, XDMCP_CLIENT_LAST_SIGNAL }; static guint xdmcp_client_signals[XDMCP_CLIENT_LAST_SIGNAL] = { 0 }; @@ -133,6 +134,7 @@ decode_accept (XDMCPClient *client, const guint8 *buffer, gssize buffer_length) g_signal_emit (client, xdmcp_client_signals[XDMCP_CLIENT_ACCEPT], 0, message); g_free (message->authentication_name); + g_free (message->authentication_data); g_free (message->authorization_name); g_free (message->authorization_data); g_free (message); @@ -158,6 +160,7 @@ decode_decline (XDMCPClient *client, const guint8 *buffer, gssize buffer_length) g_free (message->status); g_free (message->authentication_name); + g_free (message->authentication_data); g_free (message); } @@ -180,6 +183,22 @@ decode_failed (XDMCPClient *client, const guint8 *buffer, gssize buffer_length) g_free (message); } +static void +decode_alive (XDMCPClient *client, const guint8 *buffer, gssize buffer_length) +{ + XDMCPAlive *message; + gsize offset = 0; + + message = g_malloc0 (sizeof (XDMCPAlive)); + + message->session_running = read_card8 (buffer, buffer_length, &offset) != 0 ? TRUE : FALSE; + message->session_id = read_card32 (buffer, buffer_length, X_BYTE_ORDER_MSB, &offset); + + g_signal_emit (client, xdmcp_client_signals[XDMCP_CLIENT_ALIVE], 0, message); + + g_free (message); +} + static gboolean xdmcp_data_cb (GIOChannel *channel, GIOCondition condition, gpointer data) { @@ -236,6 +255,10 @@ xdmcp_data_cb (GIOChannel *channel, GIOCondition condition, gpointer data) decode_failed (client, buffer + offset, n_read - offset); break; + case XDMCP_Alive: + decode_alive (client, buffer + offset, n_read - offset); + break; + default: g_debug ("Ignoring unknown XDMCP opcode %d", opcode); break; @@ -457,6 +480,22 @@ xdmcp_client_send_manage (XDMCPClient *client, guint32 session_id, guint16 displ xdmcp_write (client, buffer, offset); } +void +xdmcp_client_send_keep_alive (XDMCPClient *client, guint16 display_number, guint32 session_id) +{ + guint8 buffer[MAXIMUM_REQUEST_LENGTH]; + gsize offset = 0; + + write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, XDMCP_VERSION, &offset); + write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, XDMCP_KeepAlive, &offset); + write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, 6, &offset); + + write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, display_number, &offset); + write_card32 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, session_id, &offset); + + xdmcp_write (client, buffer, offset); +} + static void xdmcp_client_finalize (GObject *object) { @@ -514,4 +553,12 @@ xdmcp_client_class_init (XDMCPClientClass *klass) NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_POINTER); + xdmcp_client_signals[XDMCP_CLIENT_ALIVE] = + g_signal_new (XDMCP_CLIENT_SIGNAL_ALIVE, + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XDMCPClientClass, alive), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, G_TYPE_POINTER); } diff --git a/tests/src/xdmcp-client.h b/tests/src/xdmcp-client.h index 7d13fca5..89e97b7b 100644 --- a/tests/src/xdmcp-client.h +++ b/tests/src/xdmcp-client.h @@ -12,6 +12,7 @@ #define XDMCP_CLIENT_SIGNAL_ACCEPT "accept" #define XDMCP_CLIENT_SIGNAL_DECLINE "decline" #define XDMCP_CLIENT_SIGNAL_FAILED "failed" +#define XDMCP_CLIENT_SIGNAL_ALIVE "alive" typedef struct { @@ -51,6 +52,12 @@ typedef struct gchar *status; } XDMCPFailed; +typedef struct +{ + gboolean session_running; + guint32 session_id; +} XDMCPAlive; + typedef struct XDMCPClientPrivate XDMCPClientPrivate; typedef struct @@ -67,6 +74,7 @@ typedef struct void (*accept)(XDMCPClient *client, XDMCPAccept *message); void (*decline)(XDMCPClient *client, XDMCPDecline *message); void (*failed)(XDMCPClient *client, XDMCPFailed *message); + void (*alive)(XDMCPClient *client, XDMCPAlive *message); } XDMCPClientClass; GType xdmcp_client_get_type (void); @@ -96,6 +104,8 @@ void xdmcp_client_send_request (XDMCPClient *client, void xdmcp_client_send_manage (XDMCPClient *client, guint32 session_id, guint16 display_number, const gchar *display_class); +void xdmcp_client_send_keep_alive (XDMCPClient *client, guint16 display_number, guint32 session_id); + G_END_DECLS #endif /* XDMCP_CLIENT_H_ */ |