summaryrefslogtreecommitdiff
path: root/tests/src/x-authority.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/x-authority.c')
-rw-r--r--tests/src/x-authority.c91
1 files changed, 55 insertions, 36 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