AuthSession: bring back libsignon-glib -compatible constructor
authorAlberto Mardegan <alberto.mardegan@canonical.com>
Fri, 31 Jan 2014 10:13:11 +0000 (12:13 +0200)
committerAlberto Mardegan <alberto.mardegan@canonical.com>
Fri, 31 Jan 2014 10:13:11 +0000 (12:13 +0200)
Reintroduce the constructor which takes an integer parameter, to
increase compatibility with libsignon-glib, and rename the existing
constructor to signon_auth_session_new_for_identity().
Also, declare a couple of types in signon-types.h, so that the signature
of the signon_auth_session_new_for_identity() can now properly accept a
SignonIdentity * (same trick used in libaccounts-glib).

libgsignon-glib/signon-auth-session.c
libgsignon-glib/signon-auth-session.h
libgsignon-glib/signon-identity.c
libgsignon-glib/signon-identity.h
libgsignon-glib/signon-types.h
tests/check_signon.c

index fa85632..cc3065d 100644 (file)
@@ -403,7 +403,8 @@ signon_auth_session_class_init (SignonAuthSessionClass *klass)
 
 /**
  * signon_auth_session_new:
- * @parent: #SignonIdentity parent object.
+ * @id: the id of the #SignonIdentity to be used. Can be 0, if this session is
+ * not bound to any stored identity.
  * @method_name: the name of the authentication method to be used.
  * @err: a pointer to a location which will contain the error, in case this
  * function fails.
@@ -414,19 +415,54 @@ signon_auth_session_class_init (SignonAuthSessionClass *klass)
  * Returns: a new #SignonAuthSession.
  */
 SignonAuthSession *
-signon_auth_session_new (GObject *parent,
+signon_auth_session_new (gint id,
                          const gchar *method_name,
                          GError **err)
 {
-    if (!SIGNON_IS_IDENTITY(parent))
+    DEBUG ("%s %d", G_STRFUNC, __LINE__);
+
+    SignonIdentity *identity = (id == 0) ?
+        signon_identity_new () : signon_identity_new_from_db (id);
+
+    SignonAuthSession *self = SIGNON_AUTH_SESSION(g_object_new (
+                                     SIGNON_TYPE_AUTH_SESSION,
+                                     "identity", identity,
+                                     NULL));
+    g_return_val_if_fail (self != NULL, NULL);
+    /* This will not destroy the identity, as long as it's used by the
+     * SignonAuthSession. */
+    g_object_unref (identity);
+
+    if (!auth_session_priv_init(self, method_name, err))
     {
-        g_set_error (err,
-                     signon_error_quark(),
-                     SIGNON_ERROR_UNKNOWN,
-                     "Parent object is wrong type");
+        if (*err)
+            g_warning ("%s returned error: %s", G_STRFUNC, (*err)->message);
+
+        g_object_unref (self);
         return NULL;
     }
-    SignonIdentity *identity = SIGNON_IDENTITY(parent);
+
+    return self;
+}
+
+/**
+ * signon_auth_session_new_for_identity:
+ * @identity: #SignonIdentity parent object.
+ * @method_name: the name of the authentication method to be used.
+ * @err: a pointer to a location which will contain the error, in case this
+ * function fails.
+ *
+ * Creates a new #SignonAuthSession, which can be used to authenticate using
+ * the specified method.
+ *
+ * Returns: a new #SignonAuthSession.
+ */
+SignonAuthSession *
+signon_auth_session_new_for_identity (SignonIdentity *identity,
+                                      const gchar *method_name,
+                                      GError **err)
+{
+    g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL);
 
     DEBUG ("%s %d", G_STRFUNC, __LINE__);
 
index 21097ea..3483bcd 100644 (file)
@@ -118,7 +118,6 @@ typedef enum {
 #define SIGNON_IS_AUTH_SESSION_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), SIGNON_TYPE_AUTH_SESSION))
 #define SIGNON_AUTH_SESSION_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), SIGNON_TYPE_AUTH_SESSION, SignonAuthSessionClass))
 
-typedef struct _SignonAuthSession        SignonAuthSession;
 typedef struct _SignonAuthSessionPrivate SignonAuthSessionPrivate;
 typedef struct _SignonAuthSessionClass   SignonAuthSessionClass;
 
@@ -145,10 +144,15 @@ struct _SignonAuthSessionClass {
 
 GType signon_auth_session_get_type (void) G_GNUC_CONST;
 
-SignonAuthSession *signon_auth_session_new(GObject *parent,
+SignonAuthSession *signon_auth_session_new(gint id,
                                            const gchar *method_name,
                                            GError **err);
 
+SignonAuthSession *
+signon_auth_session_new_for_identity(SignonIdentity *identity,
+                                     const gchar *method_name,
+                                     GError **err);
+
 const gchar *signon_auth_session_get_method (SignonAuthSession *self);
 
 typedef void (*SignonAuthSessionQueryAvailableMechanismsCb) (
index 74ac7ee..12b8fed 100644 (file)
@@ -851,9 +851,10 @@ signon_identity_create_session(SignonIdentity *self,
         list = list->next;
     }
 
-    SignonAuthSession *session = signon_auth_session_new (G_OBJECT(self),
-                                                          method,
-                                                          error);
+    SignonAuthSession *session =
+        signon_auth_session_new_for_identity (self,
+                                              method,
+                                              error);
     if (session)
     {
         DEBUG ("%s %d - success", G_STRFUNC, __LINE__);
index 211ffb6..1aa70ea 100644 (file)
@@ -42,7 +42,6 @@ G_BEGIN_DECLS
 
 typedef struct _SignonIdentityClass SignonIdentityClass;
 typedef struct _SignonIdentityPrivate SignonIdentityPrivate;
-typedef struct _SignonIdentity SignonIdentity;
 
 /**
  * SignonIdentityClass:
index cc2de90..c50a21c 100644 (file)
@@ -29,6 +29,9 @@
 
 G_BEGIN_DECLS
 
+typedef struct _SignonAuthSession SignonAuthSession;
+typedef struct _SignonIdentity SignonIdentity;
+
 #ifdef SIGNON_DISABLE_DEPRECATION_WARNINGS
 #define SIGNON_DEPRECATED
 #define SIGNON_DEPRECATED_FOR(x)
index 7e3457b..f6b9260 100644 (file)
@@ -650,9 +650,9 @@ START_TEST(test_auth_session_process_failure)
     idty = signon_identity_new_from_db (id);
 
     fail_unless (idty != NULL, "Cannot create Identity object");
-    auth_session = signon_auth_session_new (G_OBJECT (idty),
-                                            "ssotest",
-                                            &error);
+    auth_session = signon_auth_session_new_for_identity (idty,
+                                                         "ssotest",
+                                                         &error);
     fail_unless (auth_session != NULL, "Cannot create AuthSession object");
     fail_unless (error == NULL);
 
@@ -1429,8 +1429,8 @@ START_TEST(test_regression_unref)
     idty = signon_identity_new_from_db (id);
 
     fail_unless (idty != NULL);
-    auth_session = signon_auth_session_new (G_OBJECT (idty), "ssotest",
-            &error);
+    auth_session = signon_auth_session_new_for_identity (idty, "ssotest",
+                                                         &error);
     fail_unless (auth_session != NULL);
 
     session_data = g_hash_table_new (g_str_hash, g_str_equal);