daemon: add/remove refrerece signals replace by daemon methods
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Wed, 3 Apr 2013 09:05:43 +0000 (12:05 +0300)
committerAmarnath Valluri <amarnath.valluri@linux.intel.com>
Wed, 3 Apr 2013 13:42:25 +0000 (16:42 +0300)
src/daemon/gsignond-daemon.c
src/daemon/gsignond-daemon.h
src/daemon/gsignond-identity.c
src/daemon/gsignond-identity.h

index 3d49a2f..4846461 100644 (file)
@@ -347,6 +347,22 @@ gsignond_daemon_remove_identity (GSignondDaemon *daemon, guint32 id)
     return gsignond_db_credentials_database_remove_identity(daemon->priv->db, id);
 }
 
+guint32
+gsignond_daemon_add_identity_reference (GSignondDaemon *daemon, guint32 identity_id, const GSignondSecurityContext *owner, const gchar *reference)
+{
+    g_return_val_if_fail (daemon && GSIGNOND_IS_DAEMON (daemon), 0);
+
+    return gsignond_db_credentials_database_insert_reference (daemon->priv->db, identity_id, owner, reference);
+}
+
+gboolean
+gsignond_daemon_remove_identity_reference (GSignondDaemon *daemon, guint32 identity_id, const GSignondSecurityContext *owner, const gchar *reference)
+{
+    g_return_val_if_fail (daemon && GSIGNOND_IS_DAEMON (daemon), FALSE);
+
+    return gsignond_db_credentials_database_remove_reference (daemon->priv->db, identity_id, owner, reference);
+}
+
 GSignondIdentity *
 gsignond_daemon_register_new_identity (GSignondDaemon *daemon,
                                        const GSignondSecurityContext *ctx,
index ee01c11..bd80eab 100644 (file)
@@ -96,6 +96,12 @@ gsignond_daemon_store_identity (GSignondDaemon *daemon, GSignondIdentity *identi
 gboolean
 gsignond_daemon_remove_identity (GSignondDaemon *daemon, guint32 id);
 
+guint32
+gsignond_daemon_add_identity_reference (GSignondDaemon *daemon, guint32 identity_id, const GSignondSecurityContext *owner, const gchar *ref);
+
+gboolean
+gsignond_daemon_remove_identity_reference (GSignondDaemon *daemon, guint32 identity_id, const GSignondSecurityContext *owner, const gchar *ref);
+
 guint
 gsignond_daemon_get_timeout (GSignondDaemon *self) G_GNUC_CONST;
 
index 4a551d7..1ad4925 100644 (file)
@@ -47,8 +47,6 @@ enum
 enum {
     SIG_VERIFY_USER,
     SIG_VERIFY_SECRET,
-    SIG_ADD_REFERENCE,
-    SIG_REMOVE_REFERENCE,
     SIG_SIGNOUT,
     SIG_USER_VERIFIED,
     SIG_SECRET_VERIFIED,
@@ -239,24 +237,6 @@ gsignond_identity_class_init (GSignondIdentityClass *klass)
 
     g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 
-    signals[SIG_ADD_REFERENCE] = g_signal_new ("add-reference",
-                  GSIGNOND_TYPE_IDENTITY,
-                  G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                  0,
-                  NULL, NULL,
-                  NULL,
-                  G_TYPE_INT,
-                  1,
-                  G_TYPE_STRING);
-    signals[SIG_REMOVE_REFERENCE] = g_signal_new ("remove-reference",
-                  GSIGNOND_TYPE_IDENTITY,
-                  G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                  0,
-                  NULL, NULL,
-                  NULL,
-                  G_TYPE_INT,
-                  1,
-                  G_TYPE_STRING);
     signals[SIG_SIGNOUT] = g_signal_new ("signout",
                   GSIGNOND_TYPE_IDENTITY,
                   G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
@@ -835,7 +815,7 @@ gsignond_identity_remove (GSignondIdentity *identity,
     return is_removed;
 }
 
-gint32
+guint32
 gsignond_identity_add_reference (GSignondIdentity *identity,
                                  const gchar *reference,
                                  const GSignondSecurityContext *ctx,
@@ -846,15 +826,17 @@ gsignond_identity_add_reference (GSignondIdentity *identity,
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return 0;
     }
-    gint32 res = 0;
-    
+    guint32 res = 0;
+    guint32 identity_id = 0;
+
     VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, 0);
 
-    g_signal_emit (identity,
-                   signals[SIG_ADD_REFERENCE],
-                   0,
-                   reference,
-                   &res);
+    identity_id = gsignond_identity_info_get_id (identity->priv->info);
+    if (!identity_id) {
+        if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_STORE_FAILED, "Cannot add reference to unsaved identity");
+        return 0;
+    }
+    res = gsignond_daemon_add_identity_reference (identity->priv->owner, identity_id, ctx, reference);
 
     if (res == 0) {
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
@@ -863,7 +845,7 @@ gsignond_identity_add_reference (GSignondIdentity *identity,
     return res;
 }
 
-gint32
+guint32
 gsignond_identity_remove_reference (GSignondIdentity *identity,
                                     const gchar *reference,
                                     const GSignondSecurityContext *ctx,
@@ -875,21 +857,23 @@ gsignond_identity_remove_reference (GSignondIdentity *identity,
         return 0;
     }
 
-    gint32 res = 0;
+    gboolean res = 0;
+    guint32 identity_id = 0;
 
     VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, 0);
 
-    g_signal_emit (identity,
-            signals[SIG_REMOVE_REFERENCE],
-            0,
-            reference,
-            &res);
+    identity_id = gsignond_identity_info_get_id (identity->priv->info);
+    if (!identity_id) {
+        if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_REFERENCE_NOT_FOUND, "reference not '%s' found", reference);
+        return 0;
+    }
 
-    if (res == 0) {
+    res = gsignond_daemon_remove_identity_reference (identity->priv->owner, identity_id, ctx, reference);
+    if (res == FALSE) {
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_REFERENCE_NOT_FOUND,
                                                         "reference '%s' not found", reference);
     }
-    return res;
+    return identity_id;
 }
 
 GSignondAccessControlManager *
index 01885fd..e0f570b 100644 (file)
@@ -121,13 +121,13 @@ gsignond_identity_sign_out (GSignondIdentity *identity,
                             const GSignondSecurityContext *ctx,
                             GError **error);
 
-gint32
+guint32
 gsignond_identity_add_reference (GSignondIdentity *identity,
                                  const gchar *reference,
                                  const GSignondSecurityContext *ctx,
                                  GError **error);
 
-gint32
+guint32
 gsignond_identity_remove_reference (GSignondIdentity *identity,
                                     const gchar *reference,
                                     const GSignondSecurityContext *ctx,