Commit 29c0a3d5 authored by Corentin Noël's avatar Corentin Noël

Refine the whole API

parent e6c7b3db
Identity.signout#signal name="signed_out"
*.*.cancellable default=null
......@@ -100,7 +100,6 @@ _signon_auth_service_finish_query_methods (GObject *source_object,
SsoAuthService *proxy = NULL;
GTask *task = (GTask *)user_data;
gchar **methods_array = NULL;
GList *methods_list = NULL;
GError *error = NULL;
g_return_if_fail (SSO_IS_AUTH_SERVICE (source_object));
......@@ -110,13 +109,7 @@ _signon_auth_service_finish_query_methods (GObject *source_object,
proxy = SSO_AUTH_SERVICE (source_object);
if (sso_auth_service_call_query_methods_finish (proxy, &methods_array, res, &error))
{
int i;
for (i = 0; methods_array[i] != NULL; i++)
{
methods_list = g_list_append (methods_list, methods_array[i]);
}
g_task_return_pointer (task, methods_list, NULL);
g_task_return_pointer (task, methods_array, NULL);
} else {
g_task_return_error (task, error);
}
......@@ -130,7 +123,6 @@ _signon_auth_service_finish_query_mechanisms (GObject *source_object,
SsoAuthService *proxy = NULL;
GTask *task = (GTask *)user_data;
gchar **mechanisms_array = NULL;
GList *mechanisms_list = NULL;
GError *error = NULL;
g_return_if_fail (SSO_IS_AUTH_SERVICE (source_object));
......@@ -140,13 +132,7 @@ _signon_auth_service_finish_query_mechanisms (GObject *source_object,
proxy = SSO_AUTH_SERVICE (source_object);
if (sso_auth_service_call_query_mechanisms_finish (proxy, &mechanisms_array, res, &error))
{
int i;
for (i = 0; mechanisms_array[i] != NULL; i++)
{
mechanisms_list = g_list_append (mechanisms_list, mechanisms_array[i]);
}
g_task_return_pointer (task, mechanisms_list, NULL);
g_task_return_pointer (task, mechanisms_array, NULL);
} else {
g_task_return_error (task, error);
}
......@@ -199,11 +185,13 @@ void signon_auth_service_get_methods (SignonAuthService *auth_service,
*
* Completes an asynchronous request to signon_auth_service_get_methods().
*
* Returns: (element-type utf8) (transfer full): A list of available methods.
* Returns: (array zero-terminated=1) (transfer full): A list of available
* methods.
*/
GList *signon_auth_service_get_methods_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error)
gchar **
signon_auth_service_get_methods_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service), NULL);
......@@ -219,31 +207,25 @@ GList *signon_auth_service_get_methods_finish (SignonAuthService *auth_service,
* Lists all the available methods.
* This is a blocking version of signon_auth_service_get_methods().
*
* Returns: (element-type utf8) (transfer full): A list of available methods.
* Returns: (array zero-terminated=1) (transfer full): A list of available
* methods.
*
* Since: 2.0
*/
GList *signon_auth_service_get_methods_sync (SignonAuthService *auth_service,
GCancellable *cancellable,
GError **error)
gchar **
signon_auth_service_get_methods_sync (SignonAuthService *auth_service,
GCancellable *cancellable,
GError **error)
{
SignonAuthServicePrivate *priv;
gchar **methods_array = NULL;
GList *methods_list = NULL;
g_return_val_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service), NULL);
priv = SIGNON_AUTH_SERVICE_PRIV (auth_service);
if (sso_auth_service_call_query_methods_sync (priv->proxy, &methods_array, cancellable, error))
{
int i;
for (i = 0; methods_array[i] != NULL; i++)
{
methods_list = g_list_append (methods_list, methods_array[i]);
}
}
sso_auth_service_call_query_methods_sync (priv->proxy, &methods_array, cancellable, error);
return methods_list;
return methods_array;
}
/**
......@@ -258,11 +240,12 @@ GList *signon_auth_service_get_methods_sync (SignonAuthService *auth_service,
*
* Since: 2.0
*/
void signon_auth_service_get_mechanisms (SignonAuthService *auth_service,
const gchar *method,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
void
signon_auth_service_get_mechanisms (SignonAuthService *auth_service,
const gchar *method,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
SignonAuthServicePrivate *priv = NULL;
GTask *task = NULL;
......@@ -282,11 +265,13 @@ void signon_auth_service_get_mechanisms (SignonAuthService *auth_service,
*
* Completes an asynchronous request to signon_auth_service_get_mechanisms().
*
* Returns: (element-type utf8) (transfer full): A list of available mechanisms.
* Returns: (array zero-terminated=1) (transfer full): A list of available
* mechanisms.
*/
GList *signon_auth_service_get_mechanisms_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error)
gchar **
signon_auth_service_get_mechanisms_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service), NULL);
......@@ -303,30 +288,24 @@ GList *signon_auth_service_get_mechanisms_finish (SignonAuthService *auth_servic
* Lists all the available mechanisms.
* This is a blocking version of signon_auth_service_get_mechanisms().
*
* Returns: (element-type utf8) (transfer full): A list of available mechanisms.
* Returns: (array zero-terminated=1) (transfer full): A list of available
* mechanisms.
*
* Since: 2.0
*/
GList *signon_auth_service_get_mechanisms_sync (SignonAuthService *auth_service,
const gchar *method,
GCancellable *cancellable,
GError **error)
gchar **
signon_auth_service_get_mechanisms_sync (SignonAuthService *auth_service,
const gchar *method,
GCancellable *cancellable,
GError **error)
{
SignonAuthServicePrivate *priv;
gchar **mechanisms_array = NULL;
GList *mechanisms_list = NULL;
g_return_val_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service), NULL);
priv = SIGNON_AUTH_SERVICE_PRIV (auth_service);
if (sso_auth_service_call_query_mechanisms_sync (priv->proxy, method, &mechanisms_array, cancellable, error))
{
int i;
for (i = 0; mechanisms_array[i] != NULL; i++)
{
mechanisms_list = g_list_append (mechanisms_list, mechanisms_array[i]);
}
}
sso_auth_service_call_query_mechanisms_sync (priv->proxy, method, &mechanisms_array, cancellable, error);
return mechanisms_list;
return mechanisms_array;
}
......@@ -71,10 +71,10 @@ void signon_auth_service_get_methods (SignonAuthService *auth_service,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GList *signon_auth_service_get_methods_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error);
GList *signon_auth_service_get_methods_sync (SignonAuthService *auth_service,
gchar **signon_auth_service_get_methods_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error);
gchar **signon_auth_service_get_methods_sync (SignonAuthService *auth_service,
GCancellable *cancellable,
GError **error);
......@@ -83,13 +83,13 @@ void signon_auth_service_get_mechanisms (SignonAuthService *auth_service,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GList *signon_auth_service_get_mechanisms_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error);
GList *signon_auth_service_get_mechanisms_sync (SignonAuthService *auth_service,
const gchar *method,
GCancellable *cancellable,
GError **error);
gchar **signon_auth_service_get_mechanisms_finish (SignonAuthService *auth_service,
GAsyncResult *result,
GError **error);
gchar **signon_auth_service_get_mechanisms_sync (SignonAuthService *auth_service,
const gchar *method,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* _SIGNON_AUTH_SERVICE_H_ */
......@@ -41,6 +41,7 @@
#include "sso-identity-gen.h"
static void signon_identity_proxy_if_init (SignonProxyInterface *iface);
static void signon_identity_set_id (SignonIdentity *identity, guint32 id);
G_DEFINE_TYPE_WITH_CODE (SignonIdentity, signon_identity, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (SIGNON_TYPE_PROXY,
......@@ -143,7 +144,7 @@ signon_identity_set_property (GObject *object,
switch (property_id)
{
case PROP_ID:
self->priv->id = g_value_get_uint (value);
signon_identity_set_id (self, g_value_get_uint (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
......@@ -246,7 +247,7 @@ signon_identity_class_init (SignonIdentityClass *klass)
0,
G_MAXUINT,
0,
G_PARAM_READWRITE);
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class,
PROP_ID,
......@@ -445,7 +446,8 @@ identity_registered (SignonIdentity *identity,
*
* Since: 2.0
*
* Returns: the id of the #SignonIdentity, or 0 if the identity has not being registered.
* Returns: the id of the #SignonIdentity, or 0 if the identity has not being
* registered.
*/
guint32
signon_identity_get_id (SignonIdentity *identity)
......@@ -456,6 +458,19 @@ signon_identity_get_id (SignonIdentity *identity)
return identity->priv->id;
}
static void
signon_identity_set_id (SignonIdentity *identity, guint32 id)
{
g_return_if_fail (SIGNON_IS_IDENTITY (identity));
g_return_if_fail (identity->priv != NULL);
if (identity->priv->id != id)
{
identity->priv->id = id;
g_object_notify (G_OBJECT (identity), "id");
}
}
/**
* signon_identity_get_last_error:
* @identity: the #SignonIdentity.
......@@ -565,7 +580,6 @@ signon_identity_new_from_db (guint32 id)
g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL);
g_return_val_if_fail (identity->priv != NULL, NULL);
identity->priv->id = id;
identity_check_remote_registration (identity);
return identity;
......@@ -799,7 +813,7 @@ identity_store_info_reply (GObject *object,
slist = g_slist_next (slist);
}
g_object_set (self, "id", id, NULL);
signon_identity_set_id (self, id);
/*
* if the previous state was REMOVED
......@@ -969,8 +983,7 @@ identity_process_removed (SignonIdentity *self)
signon_identity_info_free (priv->identity_info);
priv->identity_info = NULL;
g_object_set (self, "id", 0, NULL);
priv->id = 0;
signon_identity_set_id (self, 0);
}
static void
......@@ -1248,7 +1261,7 @@ identity_query_info_reply (GObject *object,
priv->identity_info = signon_identity_info_new_from_variant (identity_data);
g_variant_unref (identity_data);
g_object_set (self, "id", signon_identity_info_get_id (priv->identity_info), NULL);
signon_identity_set_id (self, signon_identity_info_get_id (priv->identity_info));
priv->updated = TRUE;
g_task_return_pointer (task, signon_identity_info_copy (priv->identity_info), (GDestroyNotify)signon_identity_info_free);
......
......@@ -118,7 +118,7 @@ signon_query_methods_cb (GObject *source_object,
{
SignonAuthService *auth_service = SIGNON_AUTH_SERVICE (source_object);
GError *error = NULL;
GList *methods = signon_auth_service_get_methods_finish (auth_service, res, &error);
gchar **methods = signon_auth_service_get_methods_finish (auth_service, res, &error);
if (error)
{
g_warning ("%s: %s", G_STRFUNC, error->message);
......@@ -132,9 +132,10 @@ signon_query_methods_cb (GObject *source_object,
fail_unless (g_strcmp0 (user_data, "Hello") == 0, "Got wrong string");
fail_unless (methods != NULL, "The methods does not exist");
for (; methods != NULL; methods = methods->next)
for (gint i = 0; methods[i] != NULL; i++)
{
if (g_strcmp0 (methods->data, "ssotest") == 0)
const gchar *method = methods[i];
if (g_strcmp0 (method, "ssotest") == 0)
{
has_ssotest = TRUE;
break;
......@@ -169,7 +170,7 @@ signon_query_mechanisms_cb (GObject *source_object,
{
SignonAuthService *auth_service = SIGNON_AUTH_SERVICE (source_object);
GError *error = NULL;
GList *mechanisms = signon_auth_service_get_mechanisms_finish (auth_service, res, &error);
gchar **mechanisms = signon_auth_service_get_mechanisms_finish (auth_service, res, &error);
if (error)
{
g_warning ("%s: %s", G_STRFUNC, error->message);
......@@ -185,15 +186,16 @@ signon_query_mechanisms_cb (GObject *source_object,
fail_unless (strcmp (user_data, "Hello") == 0, "Got wrong string");
fail_unless (mechanisms != NULL, "The mechanisms does not exist");
for (; mechanisms != NULL; mechanisms = mechanisms->next)
for (gint i = 0; mechanisms[i] != NULL; i++)
{
if (g_strcmp0 (mechanisms->data, "mech1") == 0)
const gchar *mechanism = mechanisms[i];
if (g_strcmp0 (mechanism, "mech1") == 0)
has_mech1 = TRUE;
if (g_strcmp0 (mechanisms->data, "mech2") == 0)
if (g_strcmp0 (mechanism, "mech2") == 0)
has_mech2 = TRUE;
if (g_strcmp0 (mechanisms->data, "mech3") == 0)
if (g_strcmp0 (mechanism, "mech3") == 0)
has_mech3 = TRUE;
}
......@@ -211,7 +213,7 @@ signon_query_mechanisms_cb_fail (GObject *source_object,
{
SignonAuthService *auth_service = SIGNON_AUTH_SERVICE (source_object);
GError *error = NULL;
GList *mechanisms = signon_auth_service_get_mechanisms_finish (auth_service, res, &error);
gchar **mechanisms = signon_auth_service_get_mechanisms_finish (auth_service, res, &error);
fail_unless (error != NULL);
fail_unless (mechanisms == NULL);
fail_unless (error->domain == SIGNON_ERROR);
......
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