summaryrefslogtreecommitdiff
path: root/tests
diff options
authorRobert Ancell <robert.ancell@canonical.com>2018-08-30 14:12:54 +1200
committerRobert Ancell <robert.ancell@canonical.com>2018-08-30 14:12:54 +1200
commit816e36cf5d34930e2e6cba24ad2828026547b2d7 (patch)
treef5cf4115fd488913d8eb68f031b0dd06c15183a8 /tests
parent84ce7787adf90721241d7bb1bccd87e1fb118039 (diff)
Use more modern *_get_instance_private() method for storing private data
Diffstat (limited to 'tests')
-rw-r--r--tests/src/x-authority.c91
-rw-r--r--tests/src/x-authority.h6
-rw-r--r--tests/src/x-server.c76
-rw-r--r--tests/src/x-server.h13
-rw-r--r--tests/src/xdmcp-client.c52
-rw-r--r--tests/src/xdmcp-client.h10
6 files changed, 141 insertions, 107 deletions
diff --git a/tests/src/x-authority.c b/tests/src/x-authority.c
index 8c0aa508..e63a051f 100644
--- a/tests/src/x-authority.c
+++ b/tests/src/x-authority.c
@@ -3,12 +3,12 @@
#include "x-authority.h"
#include "x-common.h"
-struct XAuthorityPrivate
+typedef struct
{
GList *records;
-};
+} XAuthorityPrivate;
-struct XAuthorityRecordPrivate
+typedef struct
{
guint16 family;
guint16 address_length;
@@ -17,7 +17,7 @@ struct XAuthorityRecordPrivate
gchar *authorization_name;
guint16 authorization_data_length;
guint8 *authorization_data;
-};
+} XAuthorityRecordPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (XAuthority, x_authority, G_TYPE_OBJECT)
G_DEFINE_TYPE_WITH_PRIVATE (XAuthorityRecord, x_authority_record, G_TYPE_OBJECT)
@@ -31,6 +31,8 @@ x_authority_new (void)
gboolean
x_authority_load (XAuthority *authority, const gchar *filename, GError **error)
{
+ XAuthorityPrivate *priv = x_authority_get_instance_private (authority);
+
guint8 *xauth_data;
gsize xauth_length;
if (!g_file_get_contents (filename, (gchar **) &xauth_data, &xauth_length, error))
@@ -40,17 +42,19 @@ x_authority_load (XAuthority *authority, const gchar *filename, GError **error)
while (offset < xauth_length)
{
XAuthorityRecord *record = g_object_new (x_authority_record_get_type (), NULL);
- record->priv->family = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
- record->priv->address_length = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
- record->priv->address = read_string8 (xauth_data, xauth_length, record->priv->address_length, &offset);
+ XAuthorityRecordPrivate *r_priv = x_authority_record_get_instance_private (record);
+
+ r_priv->family = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
+ r_priv->address_length = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
+ r_priv->address = read_string8 (xauth_data, xauth_length, r_priv->address_length, &offset);
guint16 length = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
- record->priv->number = (gchar *) read_string8 (xauth_data, xauth_length, length, &offset);
+ r_priv->number = (gchar *) read_string8 (xauth_data, xauth_length, length, &offset);
length = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
- record->priv->authorization_name = (gchar *) read_string8 (xauth_data, xauth_length, length, &offset);
- record->priv->authorization_data_length = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
- record->priv->authorization_data = read_string8 (xauth_data, xauth_length, record->priv->authorization_data_length, &offset);
+ r_priv->authorization_name = (gchar *) read_string8 (xauth_data, xauth_length, length, &offset);
+ r_priv->authorization_data_length = read_card16 (xauth_data, xauth_length, X_BYTE_ORDER_MSB, &offset);
+ r_priv->authorization_data = read_string8 (xauth_data, xauth_length, r_priv->authorization_data_length, &offset);
- authority->priv->records = g_list_append (authority->priv->records, record);
+ priv->records = g_list_append (priv->records, record);
}
return TRUE;
@@ -59,14 +63,17 @@ x_authority_load (XAuthority *authority, const gchar *filename, GError **error)
XAuthorityRecord *
x_authority_match_local (XAuthority *authority, const gchar *authorization_name)
{
- for (GList *link = authority->priv->records; link; link = link->next)
+ XAuthorityPrivate *priv = x_authority_get_instance_private (authority);
+
+ for (GList *link = priv->records; link; link = link->next)
{
XAuthorityRecord *record = link->data;
+ XAuthorityRecordPrivate *r_priv = x_authority_record_get_instance_private (record);
- if (strcmp (record->priv->authorization_name, authorization_name) != 0)
+ if (strcmp (r_priv->authorization_name, authorization_name) != 0)
continue;
- if (record->priv->family == XAUTH_FAMILY_WILD || record->priv->family == XAUTH_FAMILY_LOCAL)
+ if (r_priv->family == XAUTH_FAMILY_WILD || r_priv->family == XAUTH_FAMILY_LOCAL)
return record;
}
@@ -76,14 +83,17 @@ x_authority_match_local (XAuthority *authority, const gchar *authorization_name)
XAuthorityRecord *
x_authority_match_localhost (XAuthority *authority, const gchar *authorization_name)
{
- for (GList *link = authority->priv->records; link; link = link->next)
+ XAuthorityPrivate *priv = x_authority_get_instance_private (authority);
+
+ for (GList *link = priv->records; link; link = link->next)
{
XAuthorityRecord *record = link->data;
+ XAuthorityRecordPrivate *r_priv = x_authority_record_get_instance_private (record);
- if (strcmp (record->priv->authorization_name, authorization_name) != 0)
+ if (strcmp (r_priv->authorization_name, authorization_name) != 0)
continue;
- if (record->priv->family == XAUTH_FAMILY_WILD || record->priv->family == XAUTH_FAMILY_LOCALHOST)
+ if (r_priv->family == XAUTH_FAMILY_WILD || r_priv->family == XAUTH_FAMILY_LOCALHOST)
return record;
}
@@ -93,6 +103,8 @@ x_authority_match_localhost (XAuthority *authority, const gchar *authorization_n
XAuthorityRecord *
x_authority_match_inet (XAuthority *authority, GInetAddress *address, const gchar *authorization_name)
{
+ XAuthorityPrivate *priv = x_authority_get_instance_private (authority);
+
guint16 family;
switch (g_inet_address_get_family (address))
{
@@ -108,26 +120,27 @@ x_authority_match_inet (XAuthority *authority, GInetAddress *address, const gcha
gssize address_data_length = g_inet_address_get_native_size (address);
const guint8 *address_data = g_inet_address_to_bytes (address);
- for (GList *link = authority->priv->records; link; link = link->next)
+ for (GList *link = priv->records; link; link = link->next)
{
XAuthorityRecord *record = link->data;
+ XAuthorityRecordPrivate *r_priv = x_authority_record_get_instance_private (record);
- if (strcmp (record->priv->authorization_name, authorization_name) != 0)
+ if (strcmp (r_priv->authorization_name, authorization_name) != 0)
continue;
- if (record->priv->family == XAUTH_FAMILY_WILD)
+ if (r_priv->family == XAUTH_FAMILY_WILD)
return record;
- if (record->priv->family != family)
+ if (r_priv->family != family)
continue;
- if (record->priv->address_length != address_data_length)
+ if (r_priv->address_length != address_data_length)
continue;
gboolean matches = TRUE;
for (int i = 0; i < address_data_length; i++)
{
- if (address_data[i] != record->priv->address[i])
+ if (address_data[i] != r_priv->address[i])
{
matches = FALSE;
break;
@@ -143,14 +156,15 @@ x_authority_match_inet (XAuthority *authority, GInetAddress *address, const gcha
static void
x_authority_init (XAuthority *authority)
{
- authority->priv = G_TYPE_INSTANCE_GET_PRIVATE (authority, x_authority_get_type (), XAuthorityPrivate);
}
static void
x_authority_finalize (GObject *object)
{
XAuthority *authority = (XAuthority *) object;
- g_list_free_full (authority->priv->records, g_object_unref);
+ XAuthorityPrivate *priv = x_authority_get_instance_private (authority);
+
+ g_list_free_full (priv->records, g_object_unref);
}
static void
@@ -163,26 +177,30 @@ x_authority_class_init (XAuthorityClass *klass)
guint16
x_authority_record_get_authorization_data_length (XAuthorityRecord *record)
{
- return record->priv->authorization_data_length;
+ XAuthorityRecordPrivate *priv = x_authority_record_get_instance_private (record);
+ return priv->authorization_data_length;
}
const guint8 *
x_authority_record_get_authorization_data (XAuthorityRecord *record)
{
- return record->priv->authorization_data;
+ XAuthorityRecordPrivate *priv = x_authority_record_get_instance_private (record);
+ return priv->authorization_data;
}
gboolean
x_authority_record_check_cookie (XAuthorityRecord *record, const guint8 *cookie_data, guint16 cookie_data_length)
{
- if (strcmp (record->priv->authorization_name, "MIT-MAGIC-COOKIE-1") != 0)
+ XAuthorityRecordPrivate *priv = x_authority_record_get_instance_private (record);
+
+ if (strcmp (priv->authorization_name, "MIT-MAGIC-COOKIE-1") != 0)
return FALSE;
- if (cookie_data_length != record->priv->authorization_data_length)
+ if (cookie_data_length != priv->authorization_data_length)
return FALSE;
for (guint16 i = 0; i < cookie_data_length; i++)
- if (cookie_data[i] != record->priv->authorization_data[i])
+ if (cookie_data[i] != priv->authorization_data[i])
return FALSE;
return TRUE;
@@ -191,17 +209,18 @@ x_authority_record_check_cookie (XAuthorityRecord *record, const guint8 *cookie_
static void
x_authority_record_init (XAuthorityRecord *record)
{
- record->priv = G_TYPE_INSTANCE_GET_PRIVATE (record, x_authority_record_get_type (), XAuthorityRecordPrivate);
}
static void
x_authority_record_finalize (GObject *object)
{
XAuthorityRecord *record = (XAuthorityRecord *) object;
- g_free (record->priv->address);
- g_free (record->priv->number);
- g_free (record->priv->authorization_name);
- g_free (record->priv->authorization_data);
+ XAuthorityRecordPrivate *priv = x_authority_record_get_instance_private (record);
+
+ g_free (priv->address);
+ g_free (priv->number);
+ g_free (priv->authorization_name);
+ g_free (priv->authorization_data);
}
static void
diff --git a/tests/src/x-authority.h b/tests/src/x-authority.h
index 9f329f31..f3a57e83 100644
--- a/tests/src/x-authority.h
+++ b/tests/src/x-authority.h
@@ -20,12 +20,9 @@ enum
XAUTH_FAMILY_WILD = 65535
};
-typedef struct XAuthorityPrivate XAuthorityPrivate;
-
typedef struct
{
GObjectClass parent_instance;
- XAuthorityPrivate *priv;
} XAuthority;
typedef struct
@@ -33,12 +30,9 @@ typedef struct
GObjectClass parent_class;
} XAuthorityClass;
-typedef struct XAuthorityRecordPrivate XAuthorityRecordPrivate;
-
typedef struct
{
GObjectClass parent_instance;
- XAuthorityRecordPrivate *priv;
} XAuthorityRecord;
typedef struct
diff --git a/tests/src/x-server.c b/tests/src/x-server.c
index e603fc03..cdfcbd32 100644
--- a/tests/src/x-server.c
+++ b/tests/src/x-server.c
@@ -22,7 +22,7 @@ enum {
};
static guint x_server_signals[X_SERVER_LAST_SIGNAL] = { 0 };
-struct XServerPrivate
+typedef struct
{
gint display_number;
@@ -30,16 +30,16 @@ struct XServerPrivate
GSocket *socket;
GIOChannel *channel;
GHashTable *clients;
-};
+} XServerPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (XServer, x_server, G_TYPE_OBJECT)
-struct XClientPrivate
+typedef struct
{
XServer *server;
GSocket *socket;
GIOChannel *channel;
-};
+} XClientPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (XClient, x_client, G_TYPE_OBJECT)
@@ -53,31 +53,33 @@ static guint x_client_signals[X_CLIENT_LAST_SIGNAL] = { 0 };
void
x_client_send_failed (XClient *client, const gchar *reason)
{
+ XClientPrivate *priv = x_client_get_instance_private (client);
g_autofree gchar *message = g_strdup_printf ("FAILED:%s", reason);
errno = 0;
- if (send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0) != strlen (message))
+ if (send (g_io_channel_unix_get_fd (priv->channel), message, strlen (message), 0) != strlen (message))
g_printerr ("Failed to send FAILED: %s\n", strerror (errno));
}
void
x_client_send_success (XClient *client)
{
+ XClientPrivate *priv = x_client_get_instance_private (client);
g_autofree gchar *message = g_strdup ("SUCCESS");
errno = 0;
- if (send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0) != strlen (message))
+ if (send (g_io_channel_unix_get_fd (priv->channel), message, strlen (message), 0) != strlen (message))
g_printerr ("Failed to send SUCCESS: %s\n", strerror (errno));
}
void
x_client_disconnect (XClient *client)
{
- g_io_channel_shutdown (client->priv->channel, TRUE, NULL);
+ XClientPrivate *priv = x_client_get_instance_private (client);
+ g_io_channel_shutdown (priv->channel, TRUE, NULL);
}
static void
x_client_init (XClient *client)
{
- client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client, x_client_get_type (), XClientPrivate);
}
static void
@@ -97,7 +99,8 @@ XServer *
x_server_new (gint display_number)
{
XServer *server = g_object_new (x_server_get_type (), NULL);
- server->priv->display_number = display_number;
+ XServerPrivate *priv = x_server_get_instance_private (server);
+ priv->display_number = display_number;
return server;
}
@@ -105,19 +108,21 @@ static gboolean
client_read_cb (GIOChannel *channel, GIOCondition condition, gpointer data)
{
XClient *client = data;
+ XClientPrivate *priv = x_client_get_instance_private (client);
g_autofree gchar *d = NULL;
gsize d_length;
if (g_io_channel_read_to_end (channel, &d, &d_length, NULL) == G_IO_STATUS_NORMAL && d_length == 0)
{
- XServer *server = client->priv->server;
+ XServer *server = priv->server;
+ XServerPrivate *s_priv = x_server_get_instance_private (server);
g_signal_emit (client, x_client_signals[X_CLIENT_DISCONNECTED], 0);
g_signal_emit (server, x_server_signals[X_SERVER_CLIENT_DISCONNECTED], 0, client);
- g_hash_table_remove (server->priv->clients, client->priv->channel);
+ g_hash_table_remove (s_priv->clients, priv->channel);
- if (g_hash_table_size (server->priv->clients) == 0)
+ if (g_hash_table_size (s_priv->clients) == 0)
g_signal_emit (server, x_server_signals[X_SERVER_RESET], 0);
return G_SOURCE_REMOVE;
@@ -130,20 +135,22 @@ static gboolean
socket_connect_cb (GIOChannel *channel, GIOCondition condition, gpointer data)
{
XServer *server = data;
+ XServerPrivate *priv = x_server_get_instance_private (server);
g_autoptr(GError) error = NULL;
- g_autoptr(GSocket) data_socket = g_socket_accept (server->priv->socket, NULL, &error);
+ g_autoptr(GSocket) data_socket = g_socket_accept (priv->socket, NULL, &error);
if (error)
g_warning ("Error accepting connection: %s", strerror (errno));
if (!data_socket)
return FALSE;
XClient *client = g_object_new (x_client_get_type (), NULL);
- client->priv->server = server;
- client->priv->socket = g_steal_pointer (&data_socket);
- client->priv->channel = g_io_channel_unix_new (g_socket_get_fd (client->priv->socket));
- g_io_add_watch (client->priv->channel, G_IO_IN | G_IO_HUP, client_read_cb, client);
- g_hash_table_insert (server->priv->clients, client->priv->channel, client);
+ XClientPrivate *c_priv = x_client_get_instance_private (client);
+ c_priv->server = server;
+ c_priv->socket = g_steal_pointer (&data_socket);
+ c_priv->channel = g_io_channel_unix_new (g_socket_get_fd (c_priv->socket));
+ g_io_add_watch (c_priv->channel, G_IO_IN | G_IO_HUP, client_read_cb, client);
+ g_hash_table_insert (priv->clients, c_priv->channel, client);
g_signal_emit (server, x_server_signals[X_SERVER_CLIENT_CONNECTED], 0, client);
@@ -153,20 +160,22 @@ socket_connect_cb (GIOChannel *channel, GIOCondition condition, gpointer data)
gboolean
x_server_start (XServer *server)
{
- g_autofree gchar *name = g_strdup_printf (".x:%d", server->priv->display_number);
- server->priv->socket_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), name, NULL);
+ XServerPrivate *priv = x_server_get_instance_private (server);
+
+ g_autofree gchar *name = g_strdup_printf (".x:%d", priv->display_number);
+ priv->socket_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), name, NULL);
g_autoptr(GError) error = NULL;
- server->priv->socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, &error);
- if (!server->priv->socket ||
- !g_socket_bind (server->priv->socket, g_unix_socket_address_new (server->priv->socket_path), TRUE, &error) ||
- !g_socket_listen (server->priv->socket, &error))
+ priv->socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, &error);
+ if (!priv->socket ||
+ !g_socket_bind (priv->socket, g_unix_socket_address_new (priv->socket_path), TRUE, &error) ||
+ !g_socket_listen (priv->socket, &error))
{
g_warning ("Error creating Unix X socket: %s", error->message);
return FALSE;
}
- server->priv->channel = g_io_channel_unix_new (g_socket_get_fd (server->priv->socket));
- g_io_add_watch (server->priv->channel, G_IO_IN, socket_connect_cb, server);
+ priv->channel = g_io_channel_unix_new (g_socket_get_fd (priv->socket));
+ g_io_add_watch (priv->channel, G_IO_IN, socket_connect_cb, server);
return TRUE;
}
@@ -174,22 +183,25 @@ x_server_start (XServer *server)
gsize
x_server_get_n_clients (XServer *server)
{
- return g_hash_table_size (server->priv->clients);
+ XServerPrivate *priv = x_server_get_instance_private (server);
+ return g_hash_table_size (priv->clients);
}
static void
x_server_init (XServer *server)
{
- server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, x_server_get_type (), XServerPrivate);
- server->priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify) g_io_channel_unref, g_object_unref);
+ XServerPrivate *priv = x_server_get_instance_private (server);
+ priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify) g_io_channel_unref, g_object_unref);
}
static void
x_server_finalize (GObject *object)
{
- XServer *server = (XServer *) object;
- if (server->priv->socket_path)
- unlink (server->priv->socket_path);
+ XServer *server = X_SERVER (object);
+ XServerPrivate *priv = x_server_get_instance_private (server);
+
+ if (priv->socket_path)
+ unlink (priv->socket_path);
G_OBJECT_CLASS (x_server_parent_class)->finalize (object);
}
diff --git a/tests/src/x-server.h b/tests/src/x-server.h
index 32f00da9..46fcc35a 100644
--- a/tests/src/x-server.h
+++ b/tests/src/x-server.h
@@ -6,18 +6,18 @@
G_BEGIN_DECLS
+#define X_SERVER_TYPE (x_server_get_type())
+#define X_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), X_SERVER_TYPE, XServer))
+
#define X_CLIENT_SIGNAL_DISCONNECTED "disconnected"
#define X_SERVER_SIGNAL_CLIENT_CONNECTED "client-connected"
#define X_SERVER_SIGNAL_CLIENT_DISCONNECTED "client-disconnected"
#define X_SERVER_SIGNAL_RESET "reset"
-typedef struct XClientPrivate XClientPrivate;
-
typedef struct
{
- GObject parent_instance;
- XClientPrivate *priv;
+ GObject parent_instance;
} XClient;
typedef struct
@@ -26,12 +26,9 @@ typedef struct
void (*disconnected)(XClient *client);
} XClientClass;
-typedef struct XServerPrivate XServerPrivate;
-
typedef struct
{
- GObject parent_instance;
- XServerPrivate *priv;
+ GObject parent_instance;
} XServer;
typedef struct
diff --git a/tests/src/xdmcp-client.c b/tests/src/xdmcp-client.c
index de40702b..49040e05 100644
--- a/tests/src/xdmcp-client.c
+++ b/tests/src/xdmcp-client.c
@@ -29,7 +29,7 @@ typedef enum
XDMCP_Alive = 14
} XDMCPOpcode;
-struct XDMCPClientPrivate
+typedef struct
{
gchar *host;
gint port;
@@ -38,7 +38,7 @@ struct XDMCPClientPrivate
gchar *authorization_name;
gint authorization_data_length;
guint8 *authorization_data;
-};
+} XDMCPClientPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (XDMCPClient, xdmcp_client, G_TYPE_OBJECT)
@@ -56,8 +56,10 @@ static guint xdmcp_client_signals[XDMCP_CLIENT_LAST_SIGNAL] = { 0 };
static void
xdmcp_write (XDMCPClient *client, const guint8 *buffer, gssize buffer_length)
{
+ XDMCPClientPrivate *priv = xdmcp_client_get_instance_private (client);
+
g_autoptr(GError) error = NULL;
- gssize n_written = g_socket_send (client->priv->socket, (const gchar *) buffer, buffer_length, NULL, &error);
+ gssize n_written = g_socket_send (priv->socket, (const gchar *) buffer, buffer_length, NULL, &error);
if (n_written < 0)
g_warning ("Failed to send XDMCP request: %s", error->message);
else if (n_written != buffer_length)
@@ -256,30 +258,34 @@ xdmcp_client_new (void)
void
xdmcp_client_set_hostname (XDMCPClient *client, const gchar *hostname)
{
- g_free (client->priv->host);
- client->priv->host = g_strdup (hostname);
+ XDMCPClientPrivate *priv = xdmcp_client_get_instance_private (client);
+ g_free (priv->host);
+ priv->host = g_strdup (hostname);
}
void
xdmcp_client_set_port (XDMCPClient *client, guint16 port)
{
- client->priv->port = port;
+ XDMCPClientPrivate *priv = xdmcp_client_get_instance_private (client);
+ priv->port = port;
}
gboolean
xdmcp_client_start (XDMCPClient *client)
{
- if (client->priv->socket)
+ XDMCPClientPrivate *priv = xdmcp_client_get_instance_private (client);
+
+ if (priv->socket)
return TRUE;
g_autoptr(GError) error = NULL;
- client->priv->socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &error);
+ priv->socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &error);
if (error)
g_warning ("Error creating XDMCP socket: %s", error->message);
- if (!client->priv->socket)
+ if (!priv->socket)
return FALSE;
- GSocketConnectable *address = g_network_address_new (client->priv->host, client->priv->port);
+ GSocketConnectable *address = g_network_address_new (priv->host, priv->port);
GSocketAddressEnumerator *enumerator = g_socket_connectable_enumerate (address);
while (TRUE)
{
@@ -290,13 +296,13 @@ xdmcp_client_start (XDMCPClient *client)
if (!socket_address)
return FALSE;
- if (!g_socket_connect (client->priv->socket, socket_address, NULL, &e))
+ if (!g_socket_connect (priv->socket, socket_address, NULL, &e))
{
g_warning ("Unable to connect XDMCP socket: %s", error->message);
continue;
}
- g_io_add_watch (g_io_channel_unix_new (g_socket_get_fd (client->priv->socket)), G_IO_IN, xdmcp_data_cb, client);
+ g_io_add_watch (g_io_channel_unix_new (g_socket_get_fd (priv->socket)), G_IO_IN, xdmcp_data_cb, client);
return TRUE;
}
@@ -305,18 +311,20 @@ xdmcp_client_start (XDMCPClient *client)
GInetAddress *
xdmcp_client_get_local_address (XDMCPClient *client)
{
- if (!client->priv->socket)
+ XDMCPClientPrivate *priv = xdmcp_client_get_instance_private (client);
+
+ if (!priv->socket)
return NULL;
- GSocketAddress *socket_address = g_socket_get_local_address (client->priv->socket, NULL);
+ GSocketAddress *socket_address = g_socket_get_local_address (priv->socket, NULL);
return g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (socket_address));
}
static void
xdmcp_client_init (XDMCPClient *client)
{
- client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client, xdmcp_client_get_type (), XDMCPClientPrivate);
- client->priv->port = XDMCP_PORT;
+ XDMCPClientPrivate *priv = xdmcp_client_get_instance_private (client);
+ priv->port = XDMCP_PORT;
}
static void
@@ -458,11 +466,13 @@ xdmcp_client_send_keep_alive (XDMCPClient *client, guint16 display_number, guint
static void
xdmcp_client_finalize (GObject *object)
{
- XDMCPClient *client = (XDMCPClient *) object;
- g_clear_pointer (&client->priv->host, g_free);
- g_clear_object (&client->priv->socket);
- g_clear_pointer (&client->priv->authorization_name, g_free);
- g_clear_pointer (&client->priv->authorization_data, g_free);
+ XDMCPClient *self = XDMCP_CLIENT (object);
+ XDMCPClientPrivate *priv = xdmcp_client_get_instance_private (self);
+
+ g_clear_pointer (&priv->host, g_free);
+ g_clear_object (&priv->socket);
+ g_clear_pointer (&priv->authorization_name, g_free);
+ g_clear_pointer (&priv->authorization_data, g_free);
}
static void
diff --git a/tests/src/xdmcp-client.h b/tests/src/xdmcp-client.h
index 89e97b7b..44f1f387 100644
--- a/tests/src/xdmcp-client.h
+++ b/tests/src/xdmcp-client.h
@@ -4,6 +4,11 @@
#include <glib-object.h>
#include <gio/gio.h>
+G_BEGIN_DECLS
+
+#define XDMCP_CLIENT_TYPE (xdmcp_client_get_type())
+#define XDMCP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XDMCP_CLIENT_TYPE, XDMCPClient))
+
#define XDMCP_VERSION 1
#define XDMCP_PORT 177
@@ -58,12 +63,9 @@ typedef struct
guint32 session_id;
} XDMCPAlive;
-typedef struct XDMCPClientPrivate XDMCPClientPrivate;
-
typedef struct
{
- GObject parent_instance;
- XDMCPClientPrivate *priv;
+ GObject parent_instance;
} XDMCPClient;
typedef struct