daemon/dbus : Peer to peer dbus support for daemon.
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Mon, 25 Mar 2013 07:52:31 +0000 (09:52 +0200)
committerAmarnath Valluri <amarnath.valluri@linux.intel.com>
Mon, 1 Apr 2013 14:58:48 +0000 (17:58 +0300)
Now build time option(--enable-dbus-type) supported for daemon to use session,
system and p2p(peer-to-peer). Dbus objects made disposable.

33 files changed:
configure.ac
src/daemon/Makefile.am
src/daemon/dbus/Makefile.am
src/daemon/dbus/gsignond-dbus-auth-service-adapter.c
src/daemon/dbus/gsignond-dbus-auth-service-adapter.h
src/daemon/dbus/gsignond-dbus-auth-session-adapter.c
src/daemon/dbus/gsignond-dbus-auth-session-adapter.h
src/daemon/dbus/gsignond-dbus-identity-adapter.c
src/daemon/dbus/gsignond-dbus-identity-adapter.h
src/daemon/dbus/gsignond-dbus-server.c [new file with mode: 0644]
src/daemon/dbus/gsignond-dbus-server.h [new file with mode: 0644]
src/daemon/dbus/gsignond-dbus-signonui-adapter.c
src/daemon/dbus/gsignond-dbus-signonui-adapter.h
src/daemon/dbus/gsignond-dbus.h
src/daemon/dbus/gsignond-disposable.c [moved from src/daemon/gsignond-disposable.c with 100% similarity]
src/daemon/dbus/gsignond-disposable.h [moved from src/daemon/gsignond-disposable.h with 100% similarity]
src/daemon/gsignond-auth-service-iface.c [deleted file]
src/daemon/gsignond-auth-service-iface.h [deleted file]
src/daemon/gsignond-auth-session-iface.c [deleted file]
src/daemon/gsignond-auth-session-iface.h [deleted file]
src/daemon/gsignond-auth-session.c
src/daemon/gsignond-auth-session.h
src/daemon/gsignond-daemon.c
src/daemon/gsignond-daemon.h
src/daemon/gsignond-identity-iface.c [deleted file]
src/daemon/gsignond-identity-iface.h [deleted file]
src/daemon/gsignond-identity.c
src/daemon/gsignond-identity.h
src/daemon/main.c
src/daemon/plugins/gsignond-plugin-proxy-factory.c
src/daemon/plugins/gsignond-plugin-proxy-factory.h
src/daemon/plugins/gsignond-plugin-proxy.c
src/daemon/plugins/gsignond-plugin-proxy.h

index 0bac4ad..bb8b79c 100644 (file)
@@ -42,7 +42,26 @@ fi
 
 AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
 
-DBUS_SERVICES_DIR="`pkg-config --variable session_bus_services_dir dbus-1`"
+AC_ARG_ENABLE(dbus-type,
+              [--enable-dbus-type=dbus-type specify daemon dbus type:
+                                 p2p(default): uses peer to peer dbus
+                                 session: uses session message bus
+                                 system: uses system message bus],
+              [enable_dbus_type=$enableval], [enable_dbus_type=p2p])
+
+echo "----------------------"
+echo " DBUS TYPE : '$enable_dbus_type'"
+echo "-----------------------"
+if test "x$enable_dbus_type" = "xp2p" ; then
+    AC_DEFINE(USE_P2P, [1], [Use peer to peer dbus])
+elif test "x$enable_dbus_type" = "xsession" ; then
+    AC_DEFINE(GSIGNOND_BUS_TYPE, [G_BUS_TYPE_SESSION], [Use session bus])
+    DBUS_SERVICES_DIR="`pkg-config --variable session_bus_services_dir dbus-1`"
+elif test "x$enable_dbus_type" = "xsystem" ; then
+    AC_DEFINE(GSIGNOND_BUS_TYPE, [G_BUS_TYPE_SYSTEM], [Use system bus])
+    DBUS_SERVICES_DIR="`pkg-config --variable system_bus_services_dir dbus-1`"
+fi
+
 AC_SUBST(DBUS_SERVICES_DIR)
 DBUS_INTERFACES_DIR="`pkg-config --variable interfaces_dir dbus-1`"
 AC_SUBST(DBUS_INTERFACES_DIR)
@@ -55,7 +74,7 @@ AC_CHECK_HEADERS([string.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 GSIGNOND_CFLAGS="$GSIGNOND_CFLAGS -Wall -DG_LOG_DOMAIN=\\\"gsignond\\\""
-#GSIGNOND_LIBS="$GSIGNOND_LIBS -lduma"
+GSIGNOND_LIBS="$GSIGNOND_LIBS -lduma"
 
 # Checks for library functions.
 
index a0fd15a..3534bbc 100644 (file)
@@ -8,35 +8,27 @@ BUILT_SOURCES = \
     gsignond-identity-enum-types.c \
     $(NULL)
 
-gsignond-identity-enum-types.h: $(top_srcdir)/src/common/gsignond-enum.h.template gsignond-identity-iface.h
+gsignond-identity-enum-types.h: $(top_srcdir)/src/common/gsignond-enum.h.template gsignond-identity.h
        $(GLIB_MKENUMS) --template $(top_srcdir)/src/common/gsignond-enum.h.template \
                     --fhead "#ifndef GSIGNOND_IDENTITY_ENUM_TYPES_H_\n#define GSIGNOND_IDENTITY_ENUM_TYPES_H_\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS" \
                     --identifier-prefix gsignond \
                     --ftail "\nG_END_DECLS\n\n#endif\n" \
-                    gsignond-identity-iface.h > $@
+                    gsignond-identity.h > $@
 
-gsignond-identity-enum-types.c: $(top_srcdir)/src/common/gsignond-enum.c.template gsignond-identity-iface.h
+gsignond-identity-enum-types.c: $(top_srcdir)/src/common/gsignond-enum.c.template gsignond-identity.h
        $(GLIB_MKENUMS) --template $(top_srcdir)/src/common/gsignond-enum.c.template \
                     --fhead "#include \"gsignond-identity-enum-types.h\"\n" \
                     --identifier-prefix gsignond \
-                    gsignond-identity-iface.h > $@
+                    gsignond-identity.h > $@
 
 gsignond_SOURCES = \
     main.c \
     gsignond-auth-session.c \
     gsignond-auth-session.h \
-    gsignond-auth-service-iface.c \
-    gsignond-auth-service-iface.h \
-    gsignond-auth-session-iface.c \
-    gsignond-auth-session-iface.h \
     gsignond-daemon.c \
     gsignond-daemon.h \
-    gsignond-identity-iface.c \
-    gsignond-identity-iface.h \
     gsignond-identity.c \
     gsignond-identity.h \
-    gsignond-disposable.c \
-    gsignond-disposable.h \
     gsignond-signonui-proxy.c \
     gsignond-signonui-proxy.h \
     $(BUILT_SOURCES) \
index ce8dc23..005ffb3 100644 (file)
@@ -59,7 +59,7 @@ libgsignond_dbus_glue_la_CPPFLAGS = \
     $(GSIGNOND_CFLAGS) \
     $(NULL)
 
-libgsignond_dbus_glue_la_LIBS = \
+libgsignond_dbus_glue_la_LIBADD = \
     $(GSIGNOND_LIBS) \
     $(NULL)
 
@@ -74,14 +74,18 @@ libgsignond_dbus_la_CPPFLAGS = \
     $(GSIGNOND_CFLAGS) \
     $(NULL)
 
-libgsignond_dbus_la_LIBS = \
-    $(top_srcdir)/src/daemon/dbus/libgsignond_dbus_glue.so \
+libgsignond_dbus_la_LIBADD = \
+    $(top_srcdir)/src/daemon/dbus/libgsignond-dbus-glue.la \
     $(GSIGNOND_LIBS) \
     $(NULL)
 
 libgsignond_dbus_la_SOURCES = \
    $(DBUS_BUILT_SOURCES) \
+   gsignond-disposable.h \
+   gsignond-disposable.c \
    gsignond-dbus.h \
+   gsignond-dbus-server.c \
+   gsignond-dbus-server.h \
    gsignond-dbus-auth-service-adapter.c \
    gsignond-dbus-auth-service-adapter.h \
    gsignond-dbus-auth-session-adapter.c \
index 71f0f49..40bc974 100644 (file)
  * 02110-1301 USA
  */
 
-#include "gsignond/gsignond-log.h"
+#include <config.h>
 #include "gsignond-dbus-auth-service-adapter.h"
+#include "gsignond-dbus-identity-adapter.h"
 #include "gsignond-dbus.h"
+#include "gsignond/gsignond-log.h"
 
 enum
 {
     PROP_0,
 
-    PROP_IMPL,
+    PROP_CONNECTION,
+    PROP_AUTH_SERVICE,
     N_PROPERTIES
 };
 
@@ -39,14 +42,16 @@ static GParamSpec *properties[N_PROPERTIES];
 
 struct _GSignondDbusAuthServiceAdapterPrivate
 {
-    GDBusConnection     *connection;
-    GSignondAuthServiceIface *parent;
+    GDBusConnection *connection;
+    GSignondDbusAuthService *dbus_auth_service;
+    GSignondDaemon  *auth_service;
+    GList *identities;
 };
 
-G_DEFINE_TYPE (GSignondDbusAuthServiceAdapter, gsignond_dbus_auth_service_adapter, GSIGNOND_DBUS_TYPE_AUTH_SERVICE_SKELETON)
-
+G_DEFINE_TYPE (GSignondDbusAuthServiceAdapter, gsignond_dbus_auth_service_adapter, GSIGNOND_TYPE_DISPOSABLE)
 
-#define GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER_GET_PRIV(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER, GSignondDbusAuthServiceAdapterPrivate)
+#define GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER, GSignondDbusAuthServiceAdapterPrivate)
 
 static gboolean _handle_register_new_identity (GSignondDbusAuthServiceAdapter *, GDBusMethodInvocation *, 
                                            const gchar *, gpointer);
@@ -60,52 +65,77 @@ static gboolean _handle_query_mechanisms (GSignondDbusAuthServiceAdapter *,
                                       const gchar *, gpointer);
 static gboolean _handle_query_identities (GSignondDbusAuthServiceAdapter *,
                                       GDBusMethodInvocation *,
-                                      const GVariant*, gpointer);
+                                      GVariant*, gpointer);
 static gboolean _handle_clear (GSignondDbusAuthServiceAdapter *, GDBusMethodInvocation *, gpointer);
 
 static void
-gsignond_dbus_auth_service_adapter_set_property (GObject *object,
-        guint property_id,
-        const GValue *value, GParamSpec *pspec)
+_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
     GSignondDbusAuthServiceAdapter *self = GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER (object);
 
     switch (property_id) {
-        case PROP_IMPL: {
-            gpointer iface = g_value_get_pointer (value);
-            if (iface) {
-                self->priv->parent = GSIGNOND_AUTH_SERVICE_IFACE (iface);
+        case PROP_AUTH_SERVICE: {
+            GObject *auth_service = g_value_get_object (value);
+            if (auth_service) {
+                if (self->priv->auth_service) g_object_unref (self->priv->auth_service);
+                self->priv->auth_service = GSIGNOND_DAEMON (auth_service);
             }
             break;
         }
+        case PROP_CONNECTION:
+            self->priv->connection = g_value_get_object(value);
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
 }
 
 static void
-gsignond_dbus_auth_service_adapter_get_property (GObject *object,
-        guint property_id,
-        GValue *value, 
-        GParamSpec *pspec)
+_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 {
     GSignondDbusAuthServiceAdapter *self = GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER (object);
 
     switch (property_id) {
-        case PROP_IMPL: {
-            g_value_set_pointer (value, self->priv->parent);
+        case PROP_AUTH_SERVICE: {
+            g_value_set_object (value, self->priv->auth_service);
             break;
         }
+        case PROP_CONNECTION:
+            g_value_set_object (value, self->priv->connection);
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
 }
 
 static void
-gsignond_dbus_auth_service_adapter_dispose (GObject *object)
+_identity_unref (gpointer data, gpointer user_data)
+{
+    if (data) g_object_unref (data);
+}
+
+static void
+_dispose (GObject *object)
 {
     GSignondDbusAuthServiceAdapter *self = GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER (object);
 
+    DBG("- unregistering dubs auth service. %d", G_OBJECT (self->priv->auth_service)->ref_count);
+
+    if (self->priv->identities) {
+        g_list_foreach (self->priv->identities, _identity_unref, NULL);
+    }
+
+    if (self->priv->auth_service) {
+        g_object_unref (self->priv->auth_service);
+        self->priv->auth_service = NULL;
+    }
+
+    if (self->priv->dbus_auth_service) {
+        g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->priv->dbus_auth_service));
+        g_object_unref (self->priv->dbus_auth_service);
+        self->priv->dbus_auth_service = NULL;
+    }
+
     if (self->priv->connection) {
         g_object_unref (self->priv->connection);
         self->priv->connection = NULL;
@@ -115,14 +145,13 @@ gsignond_dbus_auth_service_adapter_dispose (GObject *object)
 }
 
 static void
-gsignond_dbus_auth_service_adapter_finalize (GObject *object)
+_finalize (GObject *object)
 {
     GSignondDbusAuthServiceAdapter *self = GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER (object);
 
-    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
-
-    if (self->priv->parent) {
-        self->priv->parent = NULL;
+    if (self->priv->identities) {
+        g_list_free (self->priv->identities);
+        self->priv->identities = NULL;
     }
 
     G_OBJECT_CLASS (gsignond_dbus_auth_service_adapter_parent_class)->finalize (object);
@@ -135,16 +164,22 @@ gsignond_dbus_auth_service_adapter_class_init (GSignondDbusAuthServiceAdapterCla
 
     g_type_class_add_private (object_class, sizeof (GSignondDbusAuthServiceAdapterPrivate));
 
-    object_class->get_property = gsignond_dbus_auth_service_adapter_get_property;
-    object_class->set_property = gsignond_dbus_auth_service_adapter_set_property;
-    object_class->dispose = gsignond_dbus_auth_service_adapter_dispose;
-    object_class->finalize = gsignond_dbus_auth_service_adapter_finalize;
+    object_class->get_property = _get_property;
+    object_class->set_property = _set_property;
+    object_class->dispose = _dispose;
+    object_class->finalize = _finalize;
+
+    properties[PROP_AUTH_SERVICE] = g_param_spec_object ("auth-service",
+                                                  "Core auth service",
+                                                  "AuthService core object",
+                                                  GSIGNOND_TYPE_DAEMON,
+                                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
-    properties[PROP_IMPL] = g_param_spec_pointer ("auth-session-impl",
-                                                  "Auth session impl",
-                                                  "AuthSessionIface implementation object",
-                                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
-                                                  G_PARAM_STATIC_STRINGS);
+    properties[PROP_CONNECTION] = g_param_spec_object ("connection",
+                                                  "Bus connection",
+                                                  "DBus connection used",
+                                                  G_TYPE_DBUS_CONNECTION,
+                                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
     g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
@@ -152,48 +187,47 @@ gsignond_dbus_auth_service_adapter_class_init (GSignondDbusAuthServiceAdapterCla
 static void
 gsignond_dbus_auth_service_adapter_init (GSignondDbusAuthServiceAdapter *self)
 {
-    GError *err = 0;
-
     self->priv = GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER_GET_PRIV(self);
 
     self->priv->connection = 0;
-    self->priv->parent = 0;
-
-    self->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &err);
-    if (err) {
-        ERR ("Error getting session bus :%s", err->message);
-        g_error_free (err);
-        return;
-    }
-
-    if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self),
-                                           self->priv->connection,
-                                           GSIGNOND_DAEMON_OBJECTPATH,
-                                           &err)) {
-        ERR ("failed to register object: %s", err->message);
-        g_error_free (err);
-        return ;
-    }
-
-    g_signal_connect (self, "handle-register-new-identity", G_CALLBACK (_handle_register_new_identity), NULL);
-    g_signal_connect (self, "handle-get-identity", G_CALLBACK(_handle_get_identity), NULL);
-    g_signal_connect (self, "handle-query-methods", G_CALLBACK(_handle_query_methods), NULL);
-    g_signal_connect (self, "handle-query-mechanisms", G_CALLBACK(_handle_query_mechanisms), NULL);
-    g_signal_connect (self, "handle-query-identities", G_CALLBACK(_handle_query_identities), NULL);
-    g_signal_connect (self, "handle-clear", G_CALLBACK(_handle_clear), NULL);
-
+    self->priv->auth_service = 0;
+    self->priv->dbus_auth_service = gsignond_dbus_auth_service_skeleton_new ();
+
+    g_signal_connect_swapped (self->priv->dbus_auth_service,
+        "handle-register-new-identity", G_CALLBACK (_handle_register_new_identity), self);
+    g_signal_connect_swapped (self->priv->dbus_auth_service,
+        "handle-get-identity", G_CALLBACK(_handle_get_identity), self);
+    g_signal_connect_swapped (self->priv->dbus_auth_service,
+        "handle-query-methods", G_CALLBACK(_handle_query_methods), self);
+    g_signal_connect_swapped (self->priv->dbus_auth_service,
+        "handle-query-mechanisms", G_CALLBACK(_handle_query_mechanisms), self);
+    g_signal_connect_swapped (self->priv->dbus_auth_service,
+        "handle-query-identities", G_CALLBACK(_handle_query_identities), self);
+    g_signal_connect_swapped (self->priv->dbus_auth_service,
+        "handle-clear", G_CALLBACK(_handle_clear), self);
 }
 
+#ifndef USE_P2P
+static void
+_on_connnection_lost (GDBusConnection *conn, const char *peer_name, gpointer user_data)
+{
+    (void) conn;
+    DBG ("(-)peer disappeared : %s, disposing identity object '%p'", peer_name, user_data);
+    g_object_unref (G_OBJECT (user_data));
+}
+#endif
 static void
-_on_connnection_lost (GDBusConnection *conn,
-                  const char *peer_name,
-                  gpointer user_data)
+_on_identity_disposed (gpointer data, GObject *object)
 {
-    DBG ("peer disappeared : %s", peer_name);
-    /*
-     * FIXME; inform upper layer that peer closed so free objects
-     * referenced by that peer.
-     */
+    GSignondDbusAuthServiceAdapter *self = GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER (data);
+
+    DBG ("identity object %p disposed", object);
+    self->priv->identities = g_list_remove (self->priv->identities, object);
+
+    if (g_list_length (self->priv->identities) == 0) {
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
+    }
 }
 
 static gboolean
@@ -202,37 +236,56 @@ _handle_register_new_identity (GSignondDbusAuthServiceAdapter *self,
                                const gchar *app_context,
                                gpointer user_data)
 {
-    GSignondDbusAuthService *iface = GSIGNOND_DBUS_AUTH_SERVICE (self);
-    GDBusConnection *connection = g_dbus_method_invocation_get_connection (invocation);
-    const gchar *sender = g_dbus_method_invocation_get_sender (invocation); 
-    GSignondAccessControlManager *acm = gsignond_auth_service_iface_get_acm (self->priv->parent); 
     GSignondSecurityContext sec_context = {0, 0};
-    const gchar *object_path = NULL;
+    GSignondIdentity *identity = NULL;
     GError *error = NULL;
+    GDBusConnection *connection = NULL;
+    const gchar *sender = NULL;
+    int fd = -1;
+
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_AUTH_SERVICE_ADAPTER(self), FALSE);
+
+    connection = g_dbus_method_invocation_get_connection (invocation);
+#ifdef USE_P2P
+    fd = g_socket_get_fd (g_socket_connection_get_socket (G_SOCKET_CONNECTION (g_dbus_connection_get_stream(connection))));
+#else
+    sender = g_dbus_method_invocation_get_sender (invocation);
+#endif
 
     gsignond_access_control_manager_security_context_of_peer(
-            acm,
+            gsignond_daemon_get_access_control_manager (self->priv->auth_service),
             &sec_context,
-            -1,
+            fd,
             sender,
             app_context);
 
-    object_path = gsignond_auth_service_iface_register_new_identity (self->priv->parent, &sec_context, &error);
+    identity = gsignond_daemon_register_new_identity (self->priv->auth_service, &sec_context, &error);
+
+    if (identity) {
+        GSignondDbusIdentityAdapter *dbus_identity = NULL;
+        guint identity_timeout = gsignond_daemon_get_identity_timeout (self->priv->auth_service);
+        dbus_identity = gsignond_dbus_identity_adapter_new_with_connection (
+                            g_object_ref (connection), identity, identity_timeout);
+#ifndef USE_P2P
+        g_bus_watch_name_on_connection (connection, sender, G_BUS_NAME_WATCHER_FLAGS_NONE, 
+                                        NULL, _on_connnection_lost, dbus_identity, NULL);
+#endif
+
+        self->priv->identities = g_list_append (self->priv->identities, dbus_identity);
+        g_object_weak_ref (G_OBJECT (dbus_identity), _on_identity_disposed, self);
 
-    if (object_path) {
-        g_bus_watch_name_on_connection (connection, 
-                                    sender, 
-                                    G_BUS_NAME_WATCHER_FLAGS_NONE, 
-                                    NULL, 
-                                    _on_connnection_lost, 
-                                    iface,
-                                    NULL);
+        /* keep alive till this identity object gets disposed */
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
 
-        gsignond_dbus_auth_service_complete_register_new_identity (iface, invocation, object_path);
+        gsignond_dbus_auth_service_complete_register_new_identity (self->priv->dbus_auth_service,
+            invocation, gsignond_dbus_identity_adapter_get_object_path (dbus_identity));
     }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
+        
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     }
 
     return TRUE;
@@ -245,38 +298,56 @@ _handle_get_identity (GSignondDbusAuthServiceAdapter *self,
                       const gchar *app_context,
                       gpointer user_data)
 {
-    GVariant *identity_data = 0;
-    GSignondDbusAuthService *iface = GSIGNOND_DBUS_AUTH_SERVICE (self);
-    GDBusConnection *connection = g_dbus_method_invocation_get_connection (invocation);
-    const gchar *sender =  g_dbus_method_invocation_get_sender (invocation);
-    GSignondAccessControlManager *acm = gsignond_auth_service_iface_get_acm (self->priv->parent); 
     GSignondSecurityContext sec_context = {0, 0};
-    const gchar *object_path = NULL;
+    GSignondIdentity *identity = NULL;
     GError *error = NULL;
-
+    GDBusConnection *connection = NULL;
+    const gchar *sender =  NULL;
+    int fd = -1;
+
+    connection = g_dbus_method_invocation_get_connection (invocation);
+#ifdef USE_P2P
+    fd = g_socket_get_fd (g_socket_connection_get_socket (G_SOCKET_CONNECTION (g_dbus_connection_get_stream(connection))));
+#else
+    sender = g_dbus_method_invocation_get_sender (invocation);
+#endif
     gsignond_access_control_manager_security_context_of_peer(
-            acm,
+            gsignond_daemon_get_access_control_manager (self->priv->auth_service),
             &sec_context,
-            -1,
+            fd,
             sender,
             app_context);
 
-    object_path = gsignond_auth_service_iface_get_identity (self->priv->parent, id, &sec_context, &identity_data, &error);
-
-    if (object_path) {
-        g_bus_watch_name_on_connection (connection, 
-                                    sender, 
-                                    G_BUS_NAME_WATCHER_FLAGS_NONE, 
-                                    NULL, 
-                                    _on_connnection_lost, 
-                                    iface,
-                                    NULL);
-
-        gsignond_dbus_auth_service_complete_get_identity (iface, invocation, object_path, identity_data);
+    identity = gsignond_daemon_get_identity (self->priv->auth_service, id, &sec_context, &error);
+
+    if (identity) {
+        GSignondDbusIdentityAdapter *dbus_identity = NULL;
+        GSignondIdentityInfo *info = NULL;
+        guint identity_timeout = 0;
+
+        identity_timeout = gsignond_daemon_get_identity_timeout (self->priv->auth_service);
+        dbus_identity = gsignond_dbus_identity_adapter_new_with_connection (
+                            g_object_ref(connection), identity, identity_timeout);
+        info = gsignond_identity_get_identity_info (identity);
+#ifndef USE_P2P
+        g_bus_watch_name_on_connection (connection, sender, G_BUS_NAME_WATCHER_FLAGS_NONE, 
+                                        NULL, _on_connnection_lost, dbus_identity, NULL);
+#endif
+        self->priv->identities = g_list_append (self->priv->identities, dbus_identity);
+        g_object_weak_ref (G_OBJECT (dbus_identity), _on_identity_disposed, self);
+
+        /* keep alive till this identity object gets disposed */
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
+
+        gsignond_dbus_auth_service_complete_get_identity (self->priv->dbus_auth_service,
+            invocation, gsignond_dbus_identity_adapter_get_object_path (dbus_identity),
+            gsignond_dictionary_to_variant (info));
     }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
+
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     }
 
     return TRUE;
@@ -287,19 +358,21 @@ _handle_query_methods (GSignondDbusAuthServiceAdapter   *self,
                        GDBusMethodInvocation *invocation,
                        gpointer               user_data)
 {
-    GSignondDbusAuthService *iface = GSIGNOND_DBUS_AUTH_SERVICE (self);
     const gchar **methods = NULL;
     GError *error = NULL;
     
-    methods = gsignond_auth_service_iface_query_methods (self->priv->parent, &error);
+    methods = gsignond_daemon_query_methods (self->priv->auth_service, &error);
 
     if (methods)
-        gsignond_dbus_auth_service_complete_query_methods (iface, invocation, (const gchar * const*)methods);
+        gsignond_dbus_auth_service_complete_query_methods (
+            self->priv->dbus_auth_service, invocation, (const gchar * const*)methods);
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+
     return TRUE;
 }
 
@@ -309,40 +382,66 @@ _handle_query_mechanisms (GSignondDbusAuthServiceAdapter *self,
                           const gchar *method,
                           gpointer user_data)
 {
-    GSignondDbusAuthService *iface = GSIGNOND_DBUS_AUTH_SERVICE (self);    
     const gchar **mechanisms = 0;
     GError *error = NULL;
 
-    mechanisms = gsignond_auth_service_iface_query_mechanisms (self->priv->parent, method, &error);
+    mechanisms = gsignond_daemon_query_mechanisms (self->priv->auth_service, method, &error);
 
     if (mechanisms)
-        gsignond_dbus_auth_service_complete_query_mechanisms (iface, invocation, (const gchar* const*)mechanisms);
+        gsignond_dbus_auth_service_complete_query_mechanisms (
+            self->priv->dbus_auth_service, invocation, (const gchar* const*)mechanisms);
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     return TRUE;
 }
 
+static void
+_append_identity_info (gpointer data, gpointer user_data)
+{
+    GVariantBuilder *builder = (GVariantBuilder *)user_data;
+    GSignondIdentity *identity = GSIGNOND_IDENTITY (data);
+    GSignondIdentityInfo *info = gsignond_identity_get_identity_info (identity);
+
+    g_variant_builder_add (builder, "@a{sv}", gsignond_dictionary_to_variant (info));
+}
+
 static gboolean
 _handle_query_identities (GSignondDbusAuthServiceAdapter *self,
                           GDBusMethodInvocation *invocation,
-                          const GVariant *filter,
+                          GVariant *filter,
                           gpointer user_data)
 {
-    GSignondDbusAuthService *iface = GSIGNOND_DBUS_AUTH_SERVICE (self);
-    GVariant *identities = NULL;
+    GList *identities = NULL;
     GError *error = NULL;
-    
-    identities = gsignond_auth_service_iface_query_identities (self->priv->parent, filter, &error);
 
-    if (!error) gsignond_dbus_auth_service_complete_query_identities (iface, invocation, identities);
+    identities = gsignond_daemon_query_identities (self->priv->auth_service, filter, &error);
+
+    if (identities) {
+        GVariantBuilder builder;
+        
+        g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+
+        g_list_foreach(identities, _append_identity_info, &builder);
+
+        g_list_free (identities);
+
+        gsignond_dbus_auth_service_complete_query_identities (
+            self->priv->dbus_auth_service, invocation,
+            g_variant_builder_end(&builder));
+
+        g_variant_builder_clear (&builder);
+    }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+    
     return TRUE;
 }
 
@@ -351,22 +450,62 @@ _handle_clear (GSignondDbusAuthServiceAdapter *self,
                GDBusMethodInvocation *invocation,
                gpointer user_data)
 {
-    GSignondDbusAuthService *iface = GSIGNOND_DBUS_AUTH_SERVICE (self);
     gboolean res ;
     GError *error = NULL;
 
-    res = gsignond_auth_service_iface_clear (self->priv->parent, &error);
+    res = gsignond_daemon_clear (self->priv->auth_service, &error);
 
-    if (!error) gsignond_dbus_auth_service_complete_clear (iface, invocation, res);
+    if (!error)
+        gsignond_dbus_auth_service_complete_clear (self->priv->dbus_auth_service, invocation, res);
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+    
     return TRUE;
 }
 
-GSignondDbusAuthServiceAdapter * gsignond_dbus_auth_service_adapter_new (GSignondAuthServiceIface *impl)
+GSignondDbusAuthServiceAdapter *
+gsignond_dbus_auth_service_adapter_new_with_connection (GDBusConnection *bus_connection, GSignondDaemon *daemon)
 {
-    return GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER (g_object_new (GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER, "auth-session-impl", impl, NULL));
+    GError *err = NULL;
+    guint timeout = 0;
+    GSignondDbusAuthServiceAdapter *adapter = GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER (
+        g_object_new (GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER, 
+            "auth-service", daemon, 
+            "connection", bus_connection,
+            NULL));
+
+    if (!g_dbus_interface_skeleton_export (
+            G_DBUS_INTERFACE_SKELETON(adapter->priv->dbus_auth_service),
+            adapter->priv->connection, GSIGNOND_DAEMON_OBJECTPATH, &err)) {
+        ERR ("failed to register object: %s", err->message);
+        g_error_free (err);
+        g_object_unref (adapter);
+        return NULL;
+    }
+    DBG("(+) started auth service '%p' at path '%s' on conneciton '%p'", adapter, GSIGNOND_DAEMON_OBJECTPATH, bus_connection);
+
+    timeout = gsignond_daemon_get_timeout (adapter->priv->auth_service);
+    if (timeout) {
+        gsignond_disposable_set_timeout (GSIGNOND_DISPOSABLE (adapter), timeout);
+    }
+    return adapter;
+}
+#ifndef USE_P2P
+GSignondDbusAuthServiceAdapter * gsignond_dbus_auth_service_adapter_new (GSignondDaemon *daemon)
+{
+    GError *error = NULL;
+    GDBusConnection *connection = g_bus_get_sync (GSIGNOND_BUS_TYPE, NULL, &error);
+
+    if (error) {
+        ERR("failed to connect to session bus : %s", error->message);
+        g_error_free (error);
+        return NULL;
+    }
+
+    return gsignond_dbus_auth_service_adapter_new_with_connection (connection, daemon);
 }
+#endif
index 27fac39..ab032ce 100644 (file)
 #ifndef __GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER_H_
 #define __GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER_H_
 
+#include <config.h>
 #include <glib.h>
-#include <daemon/gsignond-auth-service-iface.h>
+#include <daemon/gsignond-daemon.h>
+#include "gsignond-disposable.h"
 #include "gsignond-dbus-auth-service-gen.h"
 
 G_BEGIN_DECLS
@@ -35,8 +37,8 @@ G_BEGIN_DECLS
 #define GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER            (gsignond_dbus_auth_service_adapter_get_type())
 #define GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER, GSignondDbusAuthServiceAdapter))
 #define GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER, GSignondDbusAuthServiceAdapterClass))
-#define GSIGNOND_IS_AUTH_SERVICE_ADAPTER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER))
-#define GSIGNOND_IS_AUTH_SERVICE_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER))
+#define GSIGNOND_IS_DBUS_AUTH_SERVICE_ADAPTER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER))
+#define GSIGNOND_IS_DBUS_AUTH_SERVICE_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER))
 #define GSIGNOND_DBUS_AUTH_SERVICE_ADAPTER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GSIGNOND_TYPE_AUTH_SERVICE_ADAPTER, GSignondDbusAuthServiceAdapterClass))
 
 typedef struct _GSignondDbusAuthServiceAdapter GSignondDbusAuthServiceAdapter;
@@ -45,7 +47,7 @@ typedef struct _GSignondDbusAuthServiceAdapterPrivate GSignondDbusAuthServiceAda
 
 struct _GSignondDbusAuthServiceAdapter
 {
-    GSignondDbusAuthServiceSkeleton parent;
+    GSignondDisposable parent;
 
     /* priv */
     GSignondDbusAuthServiceAdapterPrivate *priv;
@@ -53,12 +55,19 @@ struct _GSignondDbusAuthServiceAdapter
 
 struct _GSignondDbusAuthServiceAdapterClass
 {
-    GSignondDbusAuthServiceSkeletonClass parent_class;
+    GSignondDisposableClass parent_class;
 };
 
 GType gsignond_dbus_auth_service_adapter_get_type (void) G_GNUC_CONST;
 
-GSignondDbusAuthServiceAdapter * gsignond_dbus_auth_service_adapter_new (GSignondAuthServiceIface *parent);
+GSignondDbusAuthServiceAdapter *
+gsignond_dbus_auth_service_adapter_new_with_connection (GDBusConnection *conneciton,
+                                                        GSignondDaemon *daemon);
+
+#ifndef USE_P2P
+GSignondDbusAuthServiceAdapter *
+gsignond_dbus_auth_service_adapter_new (GSignondDaemon *daemon);
+#endif
 
 G_END_DECLS
 
index 4da44de..5742c39 100644 (file)
  * 02110-1301 USA
  */
 
-#include "gsignond/gsignond-log.h"
+#include <config.h>
 #include "gsignond-dbus-auth-session-adapter.h"
+#include "gsignond/gsignond-log.h"
 #include "gsignond-dbus.h"
 
 enum
 {
     PROP_0,
-    PROP_IMPL,
-    PROP_APP_CONTEXT,
+    PROP_SESSION,
+    PROP_CONNECTION,
     N_PROPERTIES
 };
 
@@ -40,16 +41,16 @@ static GParamSpec *properties[N_PROPERTIES];
 struct _GSignondDbusAuthSessionAdapterPrivate
 {
     GDBusConnection     *connection;
-    gchar *app_context;
+    GSignondDbusAuthSession *dbus_auth_session;
     GSignondSecurityContext ctx;
-    GSignondAuthSessionIface *parent;
+    GSignondAuthSession *session;
     /* signal handlers */
     guint state_changed_handler_id;
     guint process_result_handler_id;
-    guint process_error_handler_id;
+    guint process_erroror_handler_id;
 };
 
-G_DEFINE_TYPE (GSignondDbusAuthSessionAdapter, gsignond_dbus_auth_session_adapter, GSIGNOND_DBUS_TYPE_AUTH_SESSION_SKELETON)
+G_DEFINE_TYPE (GSignondDbusAuthSessionAdapter, gsignond_dbus_auth_session_adapter, GSIGNOND_TYPE_DISPOSABLE)
 
 
 #define GSIGNOND_DBUS_AUTH_SESSION_ADAPTER_GET_PRIV(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER, GSignondDbusAuthSessionAdapterPrivate)
@@ -57,21 +58,28 @@ G_DEFINE_TYPE (GSignondDbusAuthSessionAdapter, gsignond_dbus_auth_session_adapte
 #define PREPARE_SECURITY_CONTEXT(dbus_object, invocation) \
 { \
     GSignondDbusAuthSessionAdapterPrivate *priv = dbus_object->priv; \
-    const gchar *sender = g_dbus_method_invocation_get_sender (invocation); \
-    GSignondAccessControlManager *acm = gsignond_auth_session_iface_get_acm (priv->parent); \
+    GSignondAccessControlManager *acm = gsignond_auth_session_get_acm (priv->session); \
+    const gchar *sender = NULL; \
+    int fd = -1; \
+    sender = g_dbus_method_invocation_get_sender (invocation); \
+    if (!sender) {\
+        GDBusConnection *connection = g_dbus_method_invocation_get_connection (invocation);\
+        fd = g_socket_get_fd(g_socket_connection_get_socket(G_SOCKET_CONNECTION(g_dbus_connection_get_stream (connection))));\
+    }\
     gsignond_access_control_manager_security_context_of_peer( \
             acm, \
             &priv->ctx, \
-            -1, \
+            fd, \
             sender, \
-            priv->app_context); \
+            gsignond_auth_session_get_context (priv->session)); \
 }
+
 static gboolean _handle_query_available_mechanisms (GSignondDbusAuthSessionAdapter *, GDBusMethodInvocation *, const gchar **, gpointer);
 static gboolean _handle_process (GSignondDbusAuthSessionAdapter *, GDBusMethodInvocation *, const GVariant *, const gchar *, gpointer);
 static gboolean _handle_cancel (GSignondDbusAuthSessionAdapter *, GDBusMethodInvocation *, gpointer);
 
 /* signals */
-static void _emit_state_changed (GSignondAuthSessionIface *session, gint state, const gchar *message, gpointer user_data);
+static void _emit_state_changed (GSignondDbusAuthSessionAdapter *self, gint state, const gchar *message, gpointer user_data);
 
 static void
 gsignond_dbus_auth_session_adapter_set_property (GObject *object,
@@ -81,22 +89,22 @@ gsignond_dbus_auth_session_adapter_set_property (GObject *object,
     GSignondDbusAuthSessionAdapter *self = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (object);
 
     switch (property_id) {
-        case PROP_IMPL: {
-            gpointer iface = g_value_get_pointer (value);
-            if (iface) {
-                if (self->priv->parent) {
-                    g_signal_handler_disconnect (self->priv->parent, self->priv->state_changed_handler_id);
+        case PROP_SESSION: {
+            gpointer object = g_value_get_object (value);
+            if (object) {
+                if (self->priv->session) {
+                    g_signal_handler_disconnect (self->priv->session, self->priv->state_changed_handler_id);
                 }
-                self->priv->parent = GSIGNOND_AUTH_SESSION_IFACE (iface);
+                self->priv->session = GSIGNOND_AUTH_SESSION ((object));
                 self->priv->state_changed_handler_id = 
-                       g_signal_connect (self->priv->parent, "state-changed", 
+                       g_signal_connect_swapped (self->priv->session, "state-changed", 
                                          G_CALLBACK (_emit_state_changed), self);
             }
             break;
         }
-        case PROP_APP_CONTEXT: {
-            if (self->priv->app_context) g_free (self->priv->app_context);
-            self->priv->app_context = g_strdup (g_value_get_string (value));
+        case PROP_CONNECTION: {
+            if (self->priv->connection) g_object_unref (self->priv->connection);
+            self->priv->connection = G_DBUS_CONNECTION (g_value_get_object (value));
             break;
         }
         default:
@@ -113,12 +121,12 @@ gsignond_dbus_auth_session_adapter_get_property (GObject *object,
     GSignondDbusAuthSessionAdapter *self = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (object);
 
     switch (property_id) {
-        case PROP_IMPL: {
-            g_value_set_pointer (value, self->priv->parent);
+        case PROP_SESSION: {
+            g_value_set_object (value, self->priv->session);
             break;
         }
-        case PROP_APP_CONTEXT:
-            g_value_set_string (value, self->priv->app_context);
+        case PROP_CONNECTION:
+            g_value_set_object (value, self->priv->connection);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -130,15 +138,33 @@ gsignond_dbus_auth_session_adapter_dispose (GObject *object)
 {
     GSignondDbusAuthSessionAdapter *self = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (object);
 
-    gsignond_dbus_auth_session_emit_unregistered (GSIGNOND_DBUS_AUTH_SESSION (object));
+    if (self->priv->session) {
+        if (self->priv->state_changed_handler_id) {
+            g_signal_handler_disconnect (self->priv->session, self->priv->state_changed_handler_id);
+            self->priv->state_changed_handler_id = 0;
+        }
+        if (self->priv->process_erroror_handler_id) {
+            g_signal_handler_disconnect (self->priv->session, self->priv->process_erroror_handler_id);
+            self->priv->process_erroror_handler_id = 0;
+        }
+        if (self->priv->process_result_handler_id) {
+            g_signal_handler_disconnect (self->priv->session, self->priv->process_result_handler_id);
+            self->priv->process_result_handler_id = 0;
+
+            gsignond_auth_session_abort_process (self->priv->session);
+        }
 
-    if (self->priv->parent) {
-        if (self->priv->state_changed_handler_id)
-            g_signal_handler_disconnect (self->priv->parent, self->priv->state_changed_handler_id);
-        if (self->priv->process_error_handler_id)
-            g_signal_handler_disconnect (self->priv->parent, self->priv->process_error_handler_id);
-        if (self->priv->process_result_handler_id)
-            g_signal_handler_disconnect (self->priv->parent, self->priv->process_result_handler_id);
+        g_object_unref (self->priv->session);
+        self->priv->session = NULL;
+    }
+
+    if (self->priv->dbus_auth_session) {
+        gsignond_dbus_auth_session_emit_unregistered (self->priv->dbus_auth_session);
+        DBG("(-)'%s' object unexported", g_dbus_interface_skeleton_get_object_path (
+            G_DBUS_INTERFACE_SKELETON(self->priv->dbus_auth_session)));
+        g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON(self->priv->dbus_auth_session));
+        g_object_unref (self->priv->dbus_auth_session);
+        self->priv->dbus_auth_session = NULL;
     }
 
     if (self->priv->connection) {
@@ -152,19 +178,6 @@ gsignond_dbus_auth_session_adapter_dispose (GObject *object)
 static void
 gsignond_dbus_auth_session_adapter_finalize (GObject *object)
 {
-    GSignondDbusAuthSessionAdapter *self = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (object);
-
-    if (self->priv->parent) {
-        self->priv->parent = NULL;
-    }
-
-    if (self->priv->app_context) {
-        g_free (self->priv->app_context);
-        self->priv->app_context = NULL;
-    }
-
-    DBG("(-)'%s' object unexported", g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON(object)));
-    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
 
     G_OBJECT_CLASS (gsignond_dbus_auth_session_adapter_parent_class)->finalize (object);
 }
@@ -181,56 +194,42 @@ gsignond_dbus_auth_session_adapter_class_init (GSignondDbusAuthSessionAdapterCla
     object_class->dispose = gsignond_dbus_auth_session_adapter_dispose;
     object_class->finalize = gsignond_dbus_auth_session_adapter_finalize;
 
-    properties[PROP_IMPL] = g_param_spec_pointer ("auth-session-impl",
-                                                  "Auth session impl",
-                                                  "AuthSessionIface implementation object",
-                                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
-                                                  G_PARAM_STATIC_STRINGS);
-    properties[PROP_APP_CONTEXT] = g_param_spec_string (
-                "app-context",
-                "application security context",
-                "Application security context of the identity object creater",
-                NULL,
-                G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+    properties[PROP_SESSION] = g_param_spec_object ("auth-session",
+                                                    "Core auth session object",
+                                                    "Core AuthSession Object",
+                                                    GSIGNOND_TYPE_AUTH_SESSION,
+                                                    G_PARAM_READWRITE |
+                                                    G_PARAM_CONSTRUCT_ONLY |
+                                                    G_PARAM_STATIC_STRINGS);
+
+    properties[PROP_CONNECTION] = g_param_spec_object ("connection",
+                                                       "Dbus connection used",
+                                                       "Dbus connection used",
+                                                       G_TYPE_DBUS_CONNECTION,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT_ONLY | 
+                                                       G_PARAM_STATIC_STRINGS);
+
     g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
 
 static void
 gsignond_dbus_auth_session_adapter_init (GSignondDbusAuthSessionAdapter *self)
 {
-    static guint32 object_counter;
-    char *object_path = NULL;
-    GError *err = 0;
-
     self->priv = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER_GET_PRIV(self);
 
     self->priv->connection = 0;
-    self->priv->parent = 0;
-
-
-    self->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &err);
-    if (err) {
-        ERR ("Error getting session bus :%s", err->message);
-        g_error_free (err);
-        return;
-    }
-
-    object_path = g_strdup_printf ("%s/AuthSession_%d", GSIGNOND_DAEMON_OBJECTPATH, object_counter++);
-    if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self),
-                                           self->priv->connection,
-                                           object_path,
-                                           &err)) {
-        ERR ("failed to register object: %s", err->message);
-        g_error_free (err);
-        g_free (object_path);
-        return ;
-    }
-    DBG("(+) '%s' object exported", object_path);
-    g_free (object_path);
-
-    g_signal_connect (self, "handle-query-available-mechanisms", G_CALLBACK (_handle_query_available_mechanisms), NULL);
-    g_signal_connect (self, "handle-process", G_CALLBACK(_handle_process), NULL);
-    g_signal_connect (self, "handle-cancel", G_CALLBACK(_handle_cancel), NULL);
+    self->priv->session = 0;
+    self->priv->state_changed_handler_id = 0;
+    self->priv->process_result_handler_id = 0;
+    self->priv->process_erroror_handler_id = 0;
+    self->priv->dbus_auth_session = gsignond_dbus_auth_session_skeleton_new ();
+
+    g_signal_connect_swapped (self->priv->dbus_auth_session,
+        "handle-query-available-mechanisms", 
+        G_CALLBACK (_handle_query_available_mechanisms), self);
+    g_signal_connect_swapped (self->priv->dbus_auth_session, "handle-process", G_CALLBACK(_handle_process), self);
+    g_signal_connect_swapped (self->priv->dbus_auth_session, "handle-cancel", G_CALLBACK(_handle_cancel), self);
 }
 
 static gboolean
@@ -239,36 +238,60 @@ _handle_query_available_mechanisms (GSignondDbusAuthSessionAdapter *self,
                                     const gchar **wanted_mechanisms,
                                     gpointer user_data)
 {
-    GSignondDbusAuthSession *iface = GSIGNOND_DBUS_AUTH_SESSION (self);
     gchar **mechanisms = NULL;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_AUTH_SESSION_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    mechanisms = gsignond_auth_session_iface_query_available_mechanisms (
-        self->priv->parent, wanted_mechanisms, &self->priv->ctx, &error);
+    mechanisms = gsignond_auth_session_query_available_mechanisms (
+        self->priv->session, wanted_mechanisms, &self->priv->ctx, &error);
 
     if (mechanisms) {
-        gsignond_dbus_auth_session_complete_query_available_mechanisms (iface, invocation, (const gchar * const *)mechanisms);
+        gsignond_dbus_auth_session_complete_query_available_mechanisms (
+            self->priv->dbus_auth_session, invocation, (const gchar * const *)mechanisms);
         g_free (mechanisms);
     }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
+
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     return TRUE;
 }
 
 typedef struct {
     GSignondDbusAuthSessionAdapter *adapter;
     GDBusMethodInvocation *invocation;
-    gpointer user_data;
 } _AuthSessionDbusInfo;
 
+static _AuthSessionDbusInfo*
+_auth_session_dbus_info_new (GSignondDbusAuthSessionAdapter *self, GDBusMethodInvocation *invocation)
+{
+    _AuthSessionDbusInfo *info = g_new0 (_AuthSessionDbusInfo, 1);
+
+    info->adapter = g_object_ref (self);
+    info->invocation = g_object_ref (invocation);
+
+    return info;
+}
+
+static void
+_auth_session_dbus_info_free (_AuthSessionDbusInfo *info)
+{
+    if (!info) return;
+
+    g_object_unref (info->adapter);
+    g_object_unref (info->invocation);
+
+    g_free (info);
+}
+
 static void
-_on_process_result (GSignondAuthSessionIface *auth_session, const GSignondSessionData *data, gpointer user_data)
+_on_process_result (_AuthSessionDbusInfo *info, const GSignondSessionData *data, gpointer user_data)
 {
-    _AuthSessionDbusInfo *info = (_AuthSessionDbusInfo *) user_data;
     GSignondDbusAuthSessionAdapter *self = NULL;
     GVariant *result = NULL;
     
@@ -277,32 +300,36 @@ _on_process_result (GSignondAuthSessionIface *auth_session, const GSignondSessio
     self = info->adapter;
     result = gsignond_dictionary_to_variant ((GSignondDictionary *)data);
 
+    g_signal_handler_disconnect (self->priv->session, self->priv->process_erroror_handler_id);
+    g_signal_handler_disconnect (self->priv->session, self->priv->process_result_handler_id);
+    self->priv->process_erroror_handler_id = self->priv->process_result_handler_id = 0;
+
     gsignond_dbus_auth_session_complete_process (
-        GSIGNOND_DBUS_AUTH_SESSION(self),
-        info->invocation, result);
+        self->priv->dbus_auth_session, info->invocation, result);
 
-    g_signal_handler_disconnect (self->priv->parent, self->priv->process_error_handler_id);
-    g_signal_handler_disconnect (self->priv->parent, self->priv->process_result_handler_id);
+    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
 
-    g_free (info);
+    _auth_session_dbus_info_free (info);
 }
 
 static void
-_on_process_error (GSignondAuthSessionIface *auth_session, const GError *error, gpointer user_data)
+_on_process_error (_AuthSessionDbusInfo *info, const GError *error, gpointer user_data)
 {
-    _AuthSessionDbusInfo *info = (_AuthSessionDbusInfo *) user_data;
     GSignondDbusAuthSessionAdapter *self = NULL;
 
     if (!info) return ;
 
     self = info->adapter;
 
+    g_signal_handler_disconnect (self->priv->session, self->priv->process_erroror_handler_id);
+    g_signal_handler_disconnect (self->priv->session, self->priv->process_result_handler_id);
+    self->priv->process_erroror_handler_id = self->priv->process_result_handler_id = 0;
+
     g_dbus_method_invocation_return_gerror (info->invocation, error);
 
-    g_signal_handler_disconnect (self->priv->parent, self->priv->process_error_handler_id);
-    g_signal_handler_disconnect (self->priv->parent, self->priv->process_result_handler_id);
+    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
 
-    g_free (info);
+    _auth_session_dbus_info_free (info);
 }
 
 static gboolean
@@ -314,27 +341,35 @@ _handle_process (GSignondDbusAuthSessionAdapter *self,
 {
     _AuthSessionDbusInfo *info = 0;
     GError *error = NULL;
-    GSignondSessionData *data = (GSignondSessionData *)gsignond_dictionary_new_from_variant ((GVariant *)session_data);
+    GSignondSessionData *data = NULL;
 
-    info = g_new0 (_AuthSessionDbusInfo, 1);
-    info->adapter = self;
-    info->invocation = invocation;
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_AUTH_SESSION_ADAPTER (self), FALSE);
 
-    self->priv->process_error_handler_id = 
-        g_signal_connect (self->priv->parent, "process-error", G_CALLBACK(_on_process_error), info);
+    info = _auth_session_dbus_info_new (self, invocation);
+
+    self->priv->process_erroror_handler_id = 
+        g_signal_connect_swapped (self->priv->session, "process-error", G_CALLBACK(_on_process_error), info);
     self->priv->process_result_handler_id = 
-        g_signal_connect (self->priv->parent, "process-result", G_CALLBACK (_on_process_result), info);
+        g_signal_connect_swapped (self->priv->session, "process-result", G_CALLBACK (_on_process_result), info);
 
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    if (!gsignond_auth_session_iface_process (self->priv->parent, data, mechanisms, &self->priv->ctx, &error)) {
+    data = (GSignondSessionData *)gsignond_dictionary_new_from_variant ((GVariant *)session_data);
+    if (!gsignond_auth_session_process (self->priv->session, data, mechanisms, &self->priv->ctx, &error)) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
-    
-        g_signal_handler_disconnect (self->priv->parent, self->priv->process_error_handler_id);
-        g_signal_handler_disconnect (self->priv->parent, self->priv->process_result_handler_id);
+        g_signal_handler_disconnect (self->priv->session, self->priv->process_erroror_handler_id);
+        g_signal_handler_disconnect (self->priv->session, self->priv->process_result_handler_id);
 
-        self->priv->process_error_handler_id = self->priv->process_result_handler_id = 0;
+        self->priv->process_erroror_handler_id = self->priv->process_result_handler_id = 0;
+
+        _auth_session_dbus_info_free (info);
+
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
+    }
+    else {
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
     }
 
     gsignond_dictionary_unref (data);
@@ -347,34 +382,85 @@ _handle_cancel (GSignondDbusAuthSessionAdapter *self,
                 GDBusMethodInvocation *invocation,
                 gpointer user_data)
 {
-    GSignondDbusAuthSession *iface = GSIGNOND_DBUS_AUTH_SESSION (self);
     GError *error = NULL;
+
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_AUTH_SESSION_ADAPTER (self), FALSE);
     
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    if (gsignond_auth_session_iface_cancel (self->priv->parent, &self->priv->ctx, &error))
-        gsignond_dbus_auth_session_complete_cancel (iface, invocation);
+    if (gsignond_auth_session_cancel (self->priv->session, &self->priv->ctx, &error))
+        gsignond_dbus_auth_session_complete_cancel (self->priv->dbus_auth_session, invocation);
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
+
     return TRUE;
 }
 
 static void
-_emit_state_changed (GSignondAuthSessionIface *session, gint state, const gchar *message, gpointer user_data)
+_emit_state_changed (GSignondDbusAuthSessionAdapter *self, gint state, const gchar *message, gpointer user_data)
 {
-    g_return_if_fail (user_data && GSIGNOND_DBUS_IS_AUTH_SESSION (user_data));
+    gsignond_dbus_auth_session_emit_state_changed (self->priv->dbus_auth_session, state, message);
+}
 
-    GSignondDbusAuthSession *self = GSIGNOND_DBUS_AUTH_SESSION (user_data);
+const gchar *
+gsignond_dbus_auth_session_adapter_get_object_path (GSignondDbusAuthSessionAdapter *self)
+{
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_AUTH_SESSION_ADAPTER(self), NULL);
 
-    gsignond_dbus_auth_session_emit_state_changed (self, state, message);
+    return g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON(self->priv->dbus_auth_session));
 }
 
 GSignondDbusAuthSessionAdapter *
-gsignond_dbus_auth_session_adapter_new (GSignondAuthSessionIface *impl)
+gsignond_dbus_auth_session_adapter_new_with_connection (GDBusConnection *connection, 
+                                                        GSignondAuthSession *session,
+                                                        guint timeout)
 {
-    return g_object_new (GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER, "auth-session-impl", impl, NULL);
+    static guint32 object_counter;
+    gchar *object_path = NULL;
+    GSignondDbusAuthSessionAdapter *adapter = NULL;
+    GError *error = NULL;
+    
+    adapter = GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (
+        g_object_new (GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER, 
+            "connection", connection, "auth-session", session, NULL));
+
+    if (!adapter) return NULL;
+
+    object_path = g_strdup_printf ("%s/AuthSession_%d", GSIGNOND_DAEMON_OBJECTPATH, object_counter++);
+    if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (adapter->priv->dbus_auth_session),
+                                           adapter->priv->connection,
+                                           object_path,
+                                           &error)) {
+        ERR ("failed to register object: %s", error->message);
+        g_error_free (error);
+        g_free (object_path);
+        g_object_unref (adapter);
+        return NULL;
+    }
+    DBG("(+) '%s' object exported", object_path);
+    g_free (object_path);
+
+    gsignond_disposable_set_timeout (GSIGNOND_DISPOSABLE(adapter), timeout);
+
+    return adapter;
 }
 
+#ifndef USE_P2P
+GSignondDbusAuthSessionAdapter *
+gsignond_dbus_auth_session_adapter_new (GSignondAuthSession *session, guint timeout)
+{
+    GError *error = NULL;
+    GDBusConnection *connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+    if (error) {
+        ERR ("Error getting session bus :%s", error->message);
+        g_error_free (error);
+        return NULL;
+    }
+
+    return gsignond_dbus_auth_session_adapter_new_with_connection (connection, session, timeout);
+}
+#endif
index 3c3ad24..805b7c5 100644 (file)
 #ifndef __GSIGNOND_DBUS_AUTH_SESSION_ADAPTER_H_
 #define __GSIGNOND_DBUS_AUTH_SESSION_ADAPTER_H_
 
+#include <config.h>
 #include <glib.h>
-#include <daemon/gsignond-auth-session-iface.h>
+#include <daemon/gsignond-auth-session.h>
+#include "gsignond-disposable.h"
 #include "gsignond-dbus-auth-session-gen.h"
 
 G_BEGIN_DECLS
@@ -35,8 +37,8 @@ G_BEGIN_DECLS
 #define GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER            (gsignond_dbus_auth_session_adapter_get_type())
 #define GSIGNOND_DBUS_AUTH_SESSION_ADAPTER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER, GSignondDbusAuthSessionAdapter))
 #define GSIGNOND_DBUS_AUTH_SESSION_ADAPTER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER, GSignondDbusAuthSessionAdapterClass))
-#define GSIGNOND_IS_AUTH_SESSION_ADAPTER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER))
-#define GSIGNOND_IS_AUTH_SESSION_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER))
+#define GSIGNOND_IS_DBUS_AUTH_SESSION_ADAPTER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER))
+#define GSIGNOND_IS_DBUS_AUTH_SESSION_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER))
 #define GSIGNOND_DBUS_AUTH_SESSION_ADAPTER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GSIGNOND_TYPE_DBUS_AUTH_SESSION_ADAPTER, GSignondDbusAuthSessionAdapterClass))
 
 typedef struct _GSignondDbusAuthSessionAdapter GSignondDbusAuthSessionAdapter;
@@ -45,7 +47,7 @@ typedef struct _GSignondDbusAuthSessionAdapterPrivate GSignondDbusAuthSessionAda
 
 struct _GSignondDbusAuthSessionAdapter
 {
-    GSignondDbusAuthSessionSkeleton parent;
+    GSignondDisposable parent;
 
     /* priv */
     GSignondDbusAuthSessionAdapterPrivate *priv;
@@ -53,15 +55,25 @@ struct _GSignondDbusAuthSessionAdapter
 
 struct _GSignondDbusAuthSessionAdapterClass
 {
-    GSignondDbusAuthSessionSkeletonClass parent_class;
+    GSignondDisposableClass parent_class;
 };
 
 GType gsignond_dbus_auth_session_adapter_get_type (void) G_GNUC_CONST;
 
-#define gsignond_dbus_auth_session_adapter_get_object_path(adapter) \
-    g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (adapter))
+GSignondDbusAuthSessionAdapter *
+gsignond_dbus_auth_session_adapter_new_with_connection (GDBusConnection *connection,
+                                                        GSignondAuthSession *session,
+                                                        guint timeout);
 
-GSignondDbusAuthSessionAdapter * gsignond_dbus_auth_session_adapter_new (GSignondAuthSessionIface *parent);
+#ifndef USE_P2P
+GSignondDbusAuthSessionAdapter *
+gsignond_dbus_auth_session_adapter_new (GSignondAuthSession *session,
+                                        guint timeout);
+#endif
+
+const gchar *
+gsignond_dbus_auth_session_adapter_get_object_path (
+        GSignondDbusAuthSessionAdapter *dbus_session) G_GNUC_CONST;
 
 G_END_DECLS
 
index 8552f4c..7786719 100644 (file)
  * 02110-1301 USA
  */
 
+#include <config.h>
 #include "gsignond/gsignond-log.h"
 #include "gsignond-dbus-identity-adapter.h"
+#include "gsignond-dbus-auth-session-adapter.h"
 #include "gsignond-dbus.h"
 
 enum
 {
     PROP_0,
 
-    PROP_IMPL,
-    PROP_APP_CONTEXT,
+    PROP_CONNECTION,
+    PROP_IDENTITY,
     N_PROPERTIES
 };
 
@@ -44,33 +46,65 @@ typedef struct {
     gpointer user_data;
 } _IdentityDbusInfo;
 
+static _IdentityDbusInfo*
+_identity_dbus_info_new (GSignondDbusIdentityAdapter *self, GDBusMethodInvocation *invocation, gpointer userdata)
+{
+    _IdentityDbusInfo *info = g_new0(_IdentityDbusInfo, 1);
+
+    info->adapter = g_object_ref (self);
+    info->invocation = g_object_ref (invocation);
+    info->user_data = userdata;
+
+    return info;
+}
+
+static void
+_identity_dbus_info_free (_IdentityDbusInfo *info)
+{
+    if (!info) return ;
+
+    if (info->adapter) g_object_unref (info->adapter);
+    if (info->invocation) g_object_unref (info->invocation);
+
+    g_free (info);
+}
+
 struct _GSignondDbusIdentityAdapterPrivate
 {
-    GDBusConnection       *connection;
-    GSignondIdentityIface *identity;
-    gchar *app_context;
+    GDBusConnection   *connection;
+    GSignondDbusIdentity *dbus_identity;
+    GSignondIdentity  *identity;
     GSignondSecurityContext sec_context;
+    GList *sessions;
     /* signal handler ids */
     guint info_updated_handler_id;
     guint verify_user_handler_id;
     guint verify_secret_handler_id;
+    guint credentials_update_handler_id;
 };
 
-G_DEFINE_TYPE (GSignondDbusIdentityAdapter, gsignond_dbus_identity_adapter, GSIGNOND_DBUS_TYPE_IDENTITY_SKELETON)
+G_DEFINE_TYPE (GSignondDbusIdentityAdapter, gsignond_dbus_identity_adapter, GSIGNOND_TYPE_DISPOSABLE)
 
-#define GSIGNOND_DBUS_IDENTITY_ADAPTER_GET_PRIV(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_DBUS_IDENTITY_ADAPTER, GSignondDbusIdentityAdapterPrivate)
+#define GSIGNOND_DBUS_IDENTITY_ADAPTER_GET_PRIV(obj) \
+        G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_DBUS_IDENTITY_ADAPTER, GSignondDbusIdentityAdapterPrivate)
 
 #define PREPARE_SECURITY_CONTEXT(dbus_object, invocation) \
 { \
-    GSignondDbusIdentityAdapterPrivate *priv = dbus_object->priv; \
-    const gchar *sender = g_dbus_method_invocation_get_sender (invocation); \
-    GSignondAccessControlManager *acm = gsignond_identity_iface_get_acm (priv->identity); \
+    GSignondDbusIdentityAdapterPrivate *priv = dbus_object->priv;\
+    GSignondAccessControlManager *acm = gsignond_identity_get_acm (priv->identity);\
+    const gchar *sender = NULL; \
+    int fd = -1; \
+    sender = g_dbus_method_invocation_get_sender (invocation);\
+    if (!sender) {\
+        GDBusConnection *connection = g_dbus_method_invocation_get_connection (invocation);\
+        fd = g_socket_get_fd (g_socket_connection_get_socket (G_SOCKET_CONNECTION (g_dbus_connection_get_stream(connection))));\
+    }\
     gsignond_access_control_manager_security_context_of_peer( \
             acm, \
             &priv->sec_context, \
-            -1, \
+            fd, \
             sender, \
-            priv->app_context); \
+            gsignond_identity_get_app_context(priv->identity)); \
 }
 
 static gboolean _handle_request_credentials_update (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const gchar*, gpointer);
@@ -83,7 +117,7 @@ static gboolean _handle_sign_out (GSignondDbusIdentityAdapter *, GDBusMethodInvo
 static gboolean _handle_store (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const GVariant *, gpointer);
 static gboolean _handle_add_reference (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const gchar *, gpointer);
 static gboolean _handle_remove_reference (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const gchar *, gpointer);
-static void _emit_info_updated (GSignondIdentityIface *identity, GSignondIdentityChangeType change, gpointer userdata);
+static void _emit_info_updated (GSignondIdentity *identity, GSignondIdentityChangeType change, gpointer userdata);
 
 static void
 gsignond_dbus_identity_adapter_set_property (GObject *object,
@@ -93,9 +127,13 @@ gsignond_dbus_identity_adapter_set_property (GObject *object,
     GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
 
     switch (property_id) {
-        case PROP_IMPL: {
-            gpointer iface = g_value_get_pointer (value);
-            if (iface) {
+        case PROP_CONNECTION: {
+            self->priv->connection = g_value_get_object (value);
+            break;
+        }
+        case PROP_IDENTITY: {
+            gpointer identity = g_value_get_object (value);
+            if (identity) {
                 if (self->priv->identity) {
                     if (self->priv->info_updated_handler_id) {
                         g_signal_handler_disconnect (self->priv->identity, self->priv->info_updated_handler_id);
@@ -109,18 +147,19 @@ gsignond_dbus_identity_adapter_set_property (GObject *object,
                         g_signal_handler_disconnect (self->priv->identity, self->priv->verify_secret_handler_id);
                         self->priv->verify_secret_handler_id = 0;
                     }
+                    if (self->priv->credentials_update_handler_id) {
+                        g_signal_handler_disconnect (self->priv->identity, self->priv->credentials_update_handler_id);
+                        self->priv->credentials_update_handler_id = 0;
+                    }
+                    g_object_unref (self->priv->identity);
+                    self->priv->identity = NULL;
                 }
-                self->priv->identity = GSIGNOND_IDENTITY_IFACE (iface);
+                self->priv->identity = GSIGNOND_IDENTITY(identity);
                 self->priv->info_updated_handler_id = g_signal_connect (
                         self->priv->identity, "info-updated", G_CALLBACK (_emit_info_updated), self);
             }
             break;
         }
-        case PROP_APP_CONTEXT: {
-            if (self->priv->app_context) g_free (self->priv->app_context);
-            self->priv->app_context = g_strdup (g_value_get_string (value));
-            break;
-        }
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -135,30 +174,31 @@ gsignond_dbus_identity_adapter_get_property (GObject *object,
     GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
 
     switch (property_id) {
-        case PROP_IMPL: {
-            g_value_set_pointer (value, self->priv->identity);
+        case PROP_IDENTITY:{
+            g_value_set_object (value, self->priv->identity);
             break;
         }
-        case PROP_APP_CONTEXT:
-            g_value_set_string (value, self->priv->app_context);
+        case PROP_CONNECTION: {
+            g_value_set_object (value, self->priv->connection);
             break;
+        }
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
 }
 
 static void
+_destroy_session (gpointer data, gpointer user_data)
+{
+    (void)user_data;
+    if (data) g_object_unref (G_OBJECT(data));
+}
+
+static void
 gsignond_dbus_identity_adapter_dispose (GObject *object)
 {
     GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
 
-    gsignond_dbus_identity_emit_unregistered (GSIGNOND_DBUS_IDENTITY (object));
-
-    if (self->priv->connection) {
-        g_object_unref (self->priv->connection);
-        self->priv->connection = NULL;
-    }
-    
     if (self->priv->identity) {
         if (self->priv->info_updated_handler_id) {
             g_signal_handler_disconnect (self->priv->identity, self->priv->info_updated_handler_id);
@@ -172,6 +212,32 @@ gsignond_dbus_identity_adapter_dispose (GObject *object)
             g_signal_handler_disconnect (self->priv->identity, self->priv->verify_secret_handler_id);
             self->priv->verify_secret_handler_id = 0;
         }
+
+        if (self->priv->credentials_update_handler_id) {
+            g_signal_handler_disconnect (self->priv->identity, self->priv->credentials_update_handler_id);
+            self->priv->credentials_update_handler_id = 0;
+        }
+
+        g_object_unref (self->priv->identity);
+        self->priv->identity = NULL;
+    }
+
+    if (self->priv->sessions) {
+        g_list_foreach (self->priv->sessions, _destroy_session, NULL);
+    }
+
+    if (self->priv->dbus_identity) {
+        GDBusInterfaceSkeleton *iface = G_DBUS_INTERFACE_SKELETON(self->priv->dbus_identity);
+        gsignond_dbus_identity_emit_unregistered (self->priv->dbus_identity);
+        DBG("(-)'%s' object unexported", g_dbus_interface_skeleton_get_object_path (iface));
+        g_dbus_interface_skeleton_unexport (iface);
+        g_object_unref (self->priv->dbus_identity);
+        self->priv->dbus_identity = NULL;
+    }
+
+    if (self->priv->connection) {
+        g_object_unref (self->priv->connection);
+        self->priv->connection = NULL;
     }
 
     G_OBJECT_CLASS (gsignond_dbus_identity_adapter_parent_class)->dispose (object);
@@ -182,18 +248,11 @@ gsignond_dbus_identity_adapter_finalize (GObject *object)
 {
     GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
 
-    if (self->priv->app_context) {
-        g_free (self->priv->app_context);
-        self->priv->app_context = NULL;
+    if (self->priv->sessions) {
+        g_list_free (self->priv->sessions);
+        self->priv->sessions = NULL;
     }
 
-    if (self->priv->identity) {
-        self->priv->identity = NULL;
-    }
-
-    DBG("(-)'%s' object unexported", g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON(object)));
-    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object));
-
     G_OBJECT_CLASS (gsignond_dbus_identity_adapter_parent_class)->finalize (object);
 }
 
@@ -209,17 +268,20 @@ gsignond_dbus_identity_adapter_class_init (GSignondDbusIdentityAdapterClass *kla
     object_class->dispose = gsignond_dbus_identity_adapter_dispose;
     object_class->finalize = gsignond_dbus_identity_adapter_finalize;
 
-    properties[PROP_IMPL] = g_param_spec_pointer ("identity-impl",
-                                                  "Identity Iface implementation",
-                                                  "IdentityIface implementation object",
-                                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
-                                                  G_PARAM_STATIC_STRINGS);
-    properties[PROP_APP_CONTEXT] = g_param_spec_string (
-                "app-context",
-                "application security context",
-                "Application security context of the identity object creater",
-                NULL,
-                G_PARAM_READWRITE |G_PARAM_STATIC_STRINGS);
+    properties[PROP_IDENTITY] = g_param_spec_object ("identity",
+                                                     "Core identity object",
+                                                     "Core Identity Object",
+                                                     GSIGNOND_TYPE_IDENTITY,
+                                                     G_PARAM_READWRITE |
+                                                     G_PARAM_CONSTRUCT_ONLY | 
+                                                     G_PARAM_STATIC_STRINGS);
+    properties[PROP_CONNECTION] = g_param_spec_object ("connection",
+                                                       "bus connection used",
+                                                       "Bus connection",
+                                                       G_TYPE_DBUS_CONNECTION,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT_ONLY |
+                                                       G_PARAM_STATIC_STRINGS);
     
     g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
@@ -227,68 +289,81 @@ gsignond_dbus_identity_adapter_class_init (GSignondDbusIdentityAdapterClass *kla
 static void
 gsignond_dbus_identity_adapter_init (GSignondDbusIdentityAdapter *self)
 {
-    static guint32 object_counter;
-    GError *err = 0;
-    gchar *object_path = 0;
-
     self->priv = GSIGNOND_DBUS_IDENTITY_ADAPTER_GET_PRIV(self);
 
     self->priv->connection = 0;
     self->priv->identity = 0;
-    self->priv->app_context = 0;
+    self->priv->dbus_identity = gsignond_dbus_identity_skeleton_new();
+
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-request-credentials-update", G_CALLBACK (_handle_request_credentials_update), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-get-info", G_CALLBACK(_handle_get_info), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-get-auth-session", G_CALLBACK(_handle_get_auth_session), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-verify-user", G_CALLBACK(_handle_verify_user), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-verify-secret", G_CALLBACK(_handle_verify_secret), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-remove", G_CALLBACK(_handle_remove), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-sign-out", G_CALLBACK(_handle_sign_out), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-store", G_CALLBACK(_handle_store), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-add-reference", G_CALLBACK(_handle_add_reference), self);
+    g_signal_connect_swapped (self->priv->dbus_identity,
+            "handle-remove-reference", G_CALLBACK(_handle_remove_reference), self);
+}
 
-    self->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &err);
-    if (err) {
-        ERR ("Error getting session bus :%s", err->message);
-        g_error_free (err);
-        return;
-    }
+static void
+_on_credentials_updated (_IdentityDbusInfo *info, guint32 updated_id, GError *error, gpointer userdata)
+{
+    g_assert (info);
+    
+    GSignondDbusIdentityAdapter *self = info->adapter;
+    GDBusMethodInvocation *invocation = info->invocation;
 
-    object_path = g_strdup_printf ("%s/Identity_%d", GSIGNOND_DAEMON_OBJECTPATH, object_counter++);
-    if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self),
-                                           self->priv->connection,
-                                           object_path,
-                                           &err)) {
-        ERR ("failed to register object: %s", err->message);
-        g_error_free (err);
-        g_free (object_path);
-        return ;
+    g_signal_handler_disconnect (userdata, self->priv->credentials_update_handler_id);
+    self->priv->credentials_update_handler_id = 0;
+    if (error) {
+        g_dbus_method_invocation_return_gerror (invocation, error);
+        g_error_free (error);
+    }
+    else
+    {
+        gsignond_dbus_identity_complete_request_credentials_update (
+                self->priv->dbus_identity, invocation, updated_id);
     }
-    DBG("(+)'%s' object exported", object_path);
-    g_free (object_path);
 
-    g_signal_connect (self, "handle-request-credentials-update", G_CALLBACK (_handle_request_credentials_update), NULL);
-    g_signal_connect (self, "handle-get-info", G_CALLBACK(_handle_get_info), NULL);
-    g_signal_connect (self, "handle-get-auth-session", G_CALLBACK(_handle_get_auth_session), NULL);
-    g_signal_connect (self, "handle-verify-user", G_CALLBACK(_handle_verify_user), NULL);
-    g_signal_connect (self, "handle-verify-secret", G_CALLBACK(_handle_verify_secret), NULL);
-    g_signal_connect (self, "handle-remove", G_CALLBACK(_handle_remove), NULL);
-    g_signal_connect (self, "handle-sign-out", G_CALLBACK(_handle_sign_out), NULL);
-    g_signal_connect (self, "handle-store", G_CALLBACK(_handle_store), NULL);
-    g_signal_connect (self, "handle-add-reference", G_CALLBACK(_handle_add_reference), NULL);
-    g_signal_connect (self, "handle-remove-reference", G_CALLBACK(_handle_remove_reference), NULL);
+    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
 
+    _identity_dbus_info_free (info);
 }
-
 static gboolean
 _handle_request_credentials_update (GSignondDbusIdentityAdapter *self,
                                     GDBusMethodInvocation *invocation,
                                     const gchar *message,
                                     gpointer user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
-    guint32 id;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
     
-    id = gsignond_identity_iface_request_credentials_update (self->priv->identity, message, &self->priv->sec_context, &error);
-    if (id) {
-        gsignond_dbus_identity_complete_request_credentials_update (iface, invocation, id);
-    }
-    else {
+    gsignond_identity_request_credentials_update (self->priv->identity, message, &self->priv->sec_context, &error);
+    if (error) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
+        
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+    }
+    else {
+        self->priv->credentials_update_handler_id = g_signal_connect_swapped (self->priv->identity,
+            "credentials-updated", G_CALLBACK (_on_credentials_updated), self);
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
     }
 
     return TRUE;
@@ -299,71 +374,106 @@ _handle_get_info (GSignondDbusIdentityAdapter *self,
                   GDBusMethodInvocation *invocation,
                   gpointer user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
     GVariant *identity_data = 0;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
-    identity_data = gsignond_identity_iface_get_info (self->priv->identity, &self->priv->sec_context, &error);
+    
+    identity_data = gsignond_identity_get_info (self->priv->identity, 
+        &self->priv->sec_context, &error);
 
     if (identity_data) {
-        gsignond_dbus_identity_complete_get_info (iface, invocation, identity_data);
+        gsignond_dbus_identity_complete_get_info (
+            self->priv->dbus_identity, invocation, identity_data);
     }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+
     return TRUE;
 }
 
+static void
+_on_session_disposed (gpointer data, GObject *session)
+{
+    GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (data);
+
+    if (!self) return;
+
+    self->priv->sessions = g_list_remove (self->priv->sessions, session);
+
+    if (g_list_length (self->priv->sessions) == 0){
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), TRUE);
+    }
+}
+
 static gboolean
 _handle_get_auth_session (GSignondDbusIdentityAdapter *self,
                           GDBusMethodInvocation *invocation,
                           const gchar *method,
                           gpointer user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
-    const gchar *object_path = NULL;
+    GSignondAuthSession *session = NULL;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    object_path = gsignond_identity_iface_get_auth_session (self->priv->identity, method, &self->priv->sec_context, &error);
+    session = gsignond_identity_get_auth_session (self->priv->identity, method, &self->priv->sec_context, &error);
+
+    if (session) {
+        guint timeout =gsignond_identity_get_auth_session_timeout (self->priv->identity);
+        GSignondDbusAuthSessionAdapter *dbus_session = gsignond_dbus_auth_session_adapter_new_with_connection (
+            g_object_ref (self->priv->connection), session, timeout);
+
+        self->priv->sessions = g_list_append (self->priv->sessions, dbus_session);
 
-    if (object_path) {
-        gsignond_dbus_identity_complete_get_auth_session (iface, invocation, object_path);
+        g_object_weak_ref (G_OBJECT (dbus_session), _on_session_disposed, self);
+
+        gsignond_dbus_identity_complete_get_auth_session (
+            self->priv->dbus_identity, invocation, 
+            gsignond_dbus_auth_session_adapter_get_object_path (dbus_session));
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), TRUE);
     }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
+
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
     }
 
     return TRUE;
 }
 
 static void
-_on_user_verfied (GSignondIdentityIface *identity, gboolean res, const GError *error, gpointer user_data)
+_on_user_verfied (_IdentityDbusInfo *info, gboolean res, const GError *error, gpointer user_data)
 {
-    _IdentityDbusInfo *info = (_IdentityDbusInfo *)user_data;
-   
     if (G_UNLIKELY (info)) {
         WARN ("assertion G_UNLIKELY (info) fialed");
         return ;
     }
 
-    g_signal_handler_disconnect (identity, info->adapter->priv->verify_user_handler_id);
-    info->adapter->priv->verify_user_handler_id = 0;
+    GSignondDbusIdentityAdapter *self = info->adapter;
+    GDBusMethodInvocation *invocation = info->invocation;
+
+    g_signal_handler_disconnect (user_data, self->priv->verify_user_handler_id);
+    self->priv->verify_user_handler_id = 0;
 
     if (error) {
-        g_dbus_method_invocation_return_gerror (info->invocation, error);
+        g_dbus_method_invocation_return_gerror (invocation, error);
     }
     else {
         gsignond_dbus_identity_complete_verify_user (
-            GSIGNOND_DBUS_IDENTITY (info->adapter), info->invocation, res);
+            self->priv->dbus_identity, invocation, res);
     }
 
-    g_free (info);
+    _identity_dbus_info_free (info);
 }
 
 static gboolean
@@ -372,53 +482,55 @@ _handle_verify_user (GSignondDbusIdentityAdapter *self,
                      GVariant *params,
                      gpointer user_data)
 {
-    gboolean res = FALSE;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    res = gsignond_identity_iface_verify_user (self->priv->identity, params, &self->priv->sec_context, &error);
+    gsignond_identity_verify_user (self->priv->identity, params, &self->priv->sec_context, &error);
 
-    if (!res) {
+    if (error) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
+
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     }
     else {
-        _IdentityDbusInfo *info = g_new0(_IdentityDbusInfo, 1);
-
-        info->adapter = self;
-        info->invocation = invocation;
-        info->user_data = NULL;
+        _IdentityDbusInfo *info = _identity_dbus_info_new (self, invocation, NULL);
 
         /* FIXME: Do we allow multiple calls at a given point of time */
-        self->priv->verify_user_handler_id = g_signal_connect (self->priv->identity, 
+        self->priv->verify_user_handler_id = g_signal_connect_swapped (self->priv->identity, 
                     "user-verified", G_CALLBACK (_on_user_verfied), (gpointer)info);
+
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), FALSE);
     }
 
     return TRUE;
 }
 
 static void
-_on_secret_verfied (GSignondIdentityIface *identity, gboolean res, const GError *error, gpointer user_data)
+_on_secret_verfied (_IdentityDbusInfo *info, gboolean res, const GError *error, gpointer user_data)
 {
-    _IdentityDbusInfo *info = (_IdentityDbusInfo *)user_data;
+    g_assert (info);
 
-    g_signal_handler_disconnect (identity, info->adapter->priv->verify_secret_handler_id);
-    info->adapter->priv->verify_secret_handler_id = 0;
+    GSignondDbusIdentityAdapter *self = info->adapter;
+    GDBusMethodInvocation *invocation = info->invocation;
+
+    g_signal_handler_disconnect (user_data, self->priv->verify_secret_handler_id);
+    self->priv->verify_secret_handler_id = 0;
 
-    if (G_UNLIKELY (info)) {
-        WARN ("assertion G_UNLIKELY (info) fialed");
-        return ;
-    }
     if (error) {
         g_dbus_method_invocation_return_gerror (info->invocation, error);
     }
     else {
         gsignond_dbus_identity_complete_verify_secret (
-            GSIGNOND_DBUS_IDENTITY (info->adapter), info->invocation, res);
+            self->priv->dbus_identity, invocation, res);
     }
 
-    g_free (info);
+    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), TRUE);
+
+    _identity_dbus_info_free (info);
 }
 
 static gboolean
@@ -427,27 +539,26 @@ _handle_verify_secret (GSignondDbusIdentityAdapter *self,
                       const gchar *secret,
                       gpointer user_data)
 {
-    gboolean res = FALSE;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
     
-    res = gsignond_identity_iface_verify_secret (self->priv->identity, secret, &self->priv->sec_context, &error);
+    gsignond_identity_verify_secret (self->priv->identity, secret, &self->priv->sec_context, &error);
 
-    if (!res) {
+    if (error) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
     }
     else {
-        _IdentityDbusInfo *info = g_new0(_IdentityDbusInfo, 1);
+        _IdentityDbusInfo *info = _identity_dbus_info_new (self, invocation, NULL);
 
-        info->adapter = self;
-        info->invocation = invocation;
-        info->user_data = NULL;
-
-        /* FIXME: Do we allow multiple calls at a given point of time */
-        self->priv->verify_secret_handler_id = g_signal_connect (self->priv->identity, 
+        self->priv->verify_secret_handler_id = g_signal_connect_swapped (self->priv->identity, 
                 "secret-verified", G_CALLBACK (_on_secret_verfied), (gpointer)info);
+
+        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), FALSE);
     }
 
     return TRUE;
@@ -458,17 +569,22 @@ _handle_remove (GSignondDbusIdentityAdapter   *self,
                 GDBusMethodInvocation *invocation,
                 gpointer               user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
     GError *error = NULL;
-    
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    if (!gsignond_identity_iface_remove (self->priv->identity, &self->priv->sec_context, &error)) {
+    if (!gsignond_identity_remove (self->priv->identity, &self->priv->sec_context, &error)) {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
+
+        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
     }
     else {
-        gsignond_dbus_identity_complete_remove (iface, invocation);
+        gsignond_dbus_identity_complete_remove (self->priv->dbus_identity, invocation);
+
+        gsignond_disposable_delete_later (GSIGNOND_DISPOSABLE (self));
     }
 
     return TRUE;
@@ -479,21 +595,24 @@ _handle_sign_out (GSignondDbusIdentityAdapter *self,
                   GDBusMethodInvocation *invocation,
                   gpointer user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
-    gboolean res = FALSE;
     GError *error = NULL;
-    
+    gboolean res;
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    res = gsignond_identity_iface_sign_out (self->priv->identity, &self->priv->sec_context, &error);
+    res = gsignond_identity_sign_out (self->priv->identity, &self->priv->sec_context, &error);
 
-    if (res) {
-        gsignond_dbus_identity_complete_sign_out (iface, invocation, res);
+    if (!error) {
+        gsignond_dbus_identity_complete_sign_out (self->priv->dbus_identity, invocation, res);
     }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
+        
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
 
     return TRUE;
 }
@@ -504,21 +623,24 @@ _handle_store (GSignondDbusIdentityAdapter *self,
                const GVariant *info,
                gpointer user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
     guint id = 0;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    id = gsignond_identity_iface_store (self->priv->identity, info, &self->priv->sec_context, &error);
+    id = gsignond_identity_store (self->priv->identity, info, &self->priv->sec_context, &error);
 
     if (id) {
-        gsignond_dbus_identity_complete_store (iface, invocation, id);
+        gsignond_dbus_identity_complete_store (self->priv->dbus_identity, invocation, id);
     } else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
+
     return TRUE;
 }
 
@@ -528,22 +650,25 @@ _handle_add_reference (GSignondDbusIdentityAdapter *self,
                        const gchar *reference,
                        gpointer user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
     gint32 id = 0;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    id = gsignond_identity_iface_add_reference (self->priv->identity, reference, &self->priv->sec_context, &error);
+    id = gsignond_identity_add_reference (self->priv->identity, reference, &self->priv->sec_context, &error);
 
     if (id) {
-        gsignond_dbus_identity_complete_add_reference (iface, invocation, id);
+        gsignond_dbus_identity_complete_add_reference (self->priv->dbus_identity, invocation, id);
     }
     else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
+
     return TRUE;
 }
 
@@ -553,34 +678,80 @@ _handle_remove_reference (GSignondDbusIdentityAdapter *self,
                           const gchar *reference,
                           gpointer user_data)
 {
-    GSignondDbusIdentity *iface = GSIGNOND_DBUS_IDENTITY (self);
     gint32 id = 0;
     GError *error = NULL;
 
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
+
     PREPARE_SECURITY_CONTEXT (self, invocation);
 
-    id = gsignond_identity_iface_remove_reference (self->priv->identity, reference, &self->priv->sec_context, &error);
+    id = gsignond_identity_remove_reference (self->priv->identity, reference, &self->priv->sec_context, &error);
 
     if (id) {
-        gsignond_dbus_identity_complete_remove_reference (iface, invocation, id);
+        gsignond_dbus_identity_complete_remove_reference (self->priv->dbus_identity, invocation, id);
     } else {
         g_dbus_method_invocation_return_gerror (invocation, error);
         g_error_free (error);
     }
 
+    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE(self));
+
     return TRUE;
 }
 
 static void
-_emit_info_updated (GSignondIdentityIface *identity,
+_emit_info_updated (GSignondIdentity *identity,
                    GSignondIdentityChangeType change,
                    gpointer userdata)
 {
-    GSignondDbusIdentity *self = GSIGNOND_DBUS_IDENTITY (userdata);
+    GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (userdata);
+
+    gsignond_dbus_identity_emit_info_updated (self->priv->dbus_identity, change);
+}
+
+const gchar *
+gsignond_dbus_identity_adapter_get_object_path(GSignondDbusIdentityAdapter *self)
+{
+    g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), NULL);
+
+    return g_dbus_interface_skeleton_get_object_path (
+                G_DBUS_INTERFACE_SKELETON (self->priv->dbus_identity));
+}
+
+GSignondDbusIdentityAdapter *
+gsignond_dbus_identity_adapter_new_with_connection (GDBusConnection *connection,
+                                                    GSignondIdentity *identity,
+                                                    guint timeout)
+{
+    static guint32 object_counter;
+    gchar *object_path = NULL;
+    GError *err = NULL;
+    GSignondDbusIdentityAdapter *adapter = GSIGNOND_DBUS_IDENTITY_ADAPTER (
+        g_object_new (GSIGNOND_TYPE_DBUS_IDENTITY_ADAPTER, 
+            "identity", identity, "connection", connection, NULL));
+
+    if (!adapter) return NULL;
+
+    object_path = g_strdup_printf ("%s/Identity_%d", GSIGNOND_DAEMON_OBJECTPATH, object_counter++);
+    if (!g_dbus_interface_skeleton_export (
+            G_DBUS_INTERFACE_SKELETON (adapter->priv->dbus_identity),
+            adapter->priv->connection, object_path, &err)) {
+        ERR ("failed to register object: %s", err->message);
+        g_error_free (err);
+        g_free (object_path);
+        g_object_unref (adapter);
+
+        return NULL;
+    }
+    DBG("(+)'%s' object exported(%p)", object_path, adapter);
+    g_free (object_path);
+
+    gsignond_disposable_set_timeout (GSIGNOND_DISPOSABLE (adapter), timeout);
 
-    gsignond_dbus_identity_emit_info_updated (self, change);
+    return adapter;
 }
 
+#ifndef USE_P2P
 /**
  * gsignond_dbus_identity_adapter_new:
  * @impl: Instance of #GSignondDbusIdentityAdapter
@@ -590,9 +761,19 @@ _emit_info_updated (GSignondIdentityIface *identity,
  * Retrurns: (transfer full) new instance of #GSignondDbusIdentityAdapter
  */
 GSignondDbusIdentityAdapter * 
-gsignond_dbus_identity_adapter_new (GSignondIdentityIface *impl)
+gsignond_dbus_identity_adapter_new (GSignondIdentity *identity, guint timeout)
 {
-    return GSIGNOND_DBUS_IDENTITY_ADAPTER (g_object_new (GSIGNOND_TYPE_DBUS_IDENTITY_ADAPTER, "identity-impl", impl, NULL));
+    GError *error = NULL;
+    GDBusConnection *connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+    if (error) {
+        ERR("failed to connect to session bus : %s", error->message);
+        g_error_free (error);
+        return NULL;
+    }
+
+    return gsignond_dbus_identity_adapter_new_with_connection (connection, identity, timeout);
 }
 
+#endif
 #undef PREPARE_SECURITY_CONTEXT
index 9cf56f0..fc6528d 100644 (file)
 #ifndef __GSIGNOND_IDENTITY_ADAPTER_H_
 #define __GSIGNOND_IDENTITY_ADAPTER_H_
 
+#include <config.h>
 #include <glib.h>
-#include <daemon/gsignond-identity-iface.h>
+#include <daemon/gsignond-identity.h>
+#include "gsignond-disposable.h"
 #include "gsignond-dbus-identity-gen.h"
 
 G_BEGIN_DECLS
@@ -45,7 +47,7 @@ typedef struct _GSignondDbusIdentityAdapterPrivate GSignondDbusIdentityAdapterPr
 
 struct _GSignondDbusIdentityAdapter
 {
-    GSignondDbusIdentitySkeleton parent;
+    GSignondDisposable parent;
 
     /* priv */
     GSignondDbusIdentityAdapterPrivate *priv;
@@ -53,15 +55,24 @@ struct _GSignondDbusIdentityAdapter
 
 struct _GSignondDbusIdentityAdapterClass
 {
-    GSignondDbusIdentitySkeletonClass parent_class;
+    GSignondDisposableClass parent_class;
 };
 
 GType gsignond_dbus_identity_adapter_get_type (void) G_GNUC_CONST;
 
-#define gsignond_dbus_identity_adapter_get_object_path(adapter) \
-    g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (adapter))
+GSignondDbusIdentityAdapter * 
+gsignond_dbus_identity_adapter_new_with_connection (GDBusConnection *connection,
+                                                    GSignondIdentity *identity,
+                                                    guint timeout);
 
-GSignondDbusIdentityAdapter * gsignond_dbus_identity_adapter_new (GSignondIdentityIface *parent);
+#ifndef USE_P2P
+GSignondDbusIdentityAdapter *
+gsignond_dbus_identity_adapter_new (GSignondIdentity *identity,
+                                    guint timeout);
+#endif
+
+const gchar*
+gsignond_dbus_identity_adapter_get_object_path (GSignondDbusIdentityAdapter *self) G_GNUC_CONST;
 
 G_END_DECLS
 
diff --git a/src/daemon/dbus/gsignond-dbus-server.c b/src/daemon/dbus/gsignond-dbus-server.c
new file mode 100644 (file)
index 0000000..aae22b7
--- /dev/null
@@ -0,0 +1,337 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of gsignond
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <config.h>
+#include "gsignond-dbus-server.h"
+#include "gsignond-dbus-auth-service-adapter.h"
+#include "gsignond-dbus.h"
+#include "gsignond/gsignond-log.h"
+#include <daemon/gsignond-daemon.h>
+
+enum
+{
+    PROP_0,
+
+    PROP_ADDRESS,
+    N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES];
+
+struct _GSignondDbusServerPrivate
+{
+    GSignondDaemon *daemon;
+    GHashTable *auth_services;
+#ifdef USE_P2P
+    GDBusServer *bus_server;
+    gchar *address;
+#else
+    GDBusConnection *connection;
+    guint name_owner_id;
+#endif
+};
+
+G_DEFINE_TYPE (GSignondDbusServer, gsignond_dbus_server, G_TYPE_OBJECT)
+
+
+#define GSIGNOND_DBUS_SERVER_GET_PRIV(obj) \
+    G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_DBUS_SERVER, GSignondDbusServerPrivate)
+
+static void
+_set_property (GObject *object,
+        guint property_id,
+        const GValue *value, GParamSpec *pspec)
+{
+    GSignondDbusServer *self = GSIGNOND_DBUS_SERVER (object);
+
+    switch (property_id) {
+        case PROP_ADDRESS: {
+#ifdef USE_P2P
+            self->priv->address = g_value_dup_string (value);
+#else
+            (void)self;
+#endif
+            break;
+        }
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+_get_property (GObject *object,
+        guint property_id,
+        GValue *value, 
+        GParamSpec *pspec)
+{
+    GSignondDbusServer *self = GSIGNOND_DBUS_SERVER (object);
+
+    switch (property_id) {
+        case PROP_ADDRESS: {
+#ifdef USE_P2P
+            g_value_set_string (value, g_dbus_server_get_client_address (
+                    self->priv->bus_server));
+#else
+            g_object_get_property (G_OBJECT (self->priv->connection), "address", value);
+#endif
+            break;
+        }
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+_dispose (GObject *object)
+{
+    GSignondDbusServer *self = GSIGNOND_DBUS_SERVER (object);
+
+    if (self->priv->auth_services) {
+        g_hash_table_unref (self->priv->auth_services);
+        self->priv->auth_services = NULL;
+    }
+#ifdef USE_P2P
+    if (self->priv->bus_server) {
+        if (g_dbus_server_is_active (self->priv->bus_server))
+            g_dbus_server_stop (self->priv->bus_server);
+        g_object_unref (self->priv->bus_server);
+        self->priv->bus_server = NULL;
+    }
+#else 
+    if (self->priv->name_owner_id) {
+        g_bus_unown_name (self->priv->name_owner_id);
+        self->priv->name_owner_id = 0;
+    }
+
+    if (self->priv->connection) {
+        g_object_unref (self->priv->connection);
+        self->priv->connection = NULL;
+    }
+
+    if (self->priv->daemon) {
+        g_object_unref (self->priv->daemon);
+        self->priv->daemon = NULL;
+    }
+#endif
+    G_OBJECT_CLASS (gsignond_dbus_server_parent_class)->dispose (object);
+}
+
+static void
+_finalize (GObject *object)
+{
+#ifdef USE_P2P
+    GSignondDbusServer *self = GSIGNOND_DBUS_SERVER (object);
+    if (self->priv->address) {
+        g_free (self->priv->address);
+        self->priv->address = NULL;
+    }
+#endif
+    G_OBJECT_CLASS (gsignond_dbus_server_parent_class)->finalize (object);
+}
+
+static void
+gsignond_dbus_server_class_init (GSignondDbusServerClass *klass)
+{
+    GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+    g_type_class_add_private (object_class, sizeof (GSignondDbusServerPrivate));
+
+    object_class->get_property = _get_property;
+    object_class->set_property = _set_property;
+    object_class->dispose = _dispose;
+    object_class->finalize = _finalize;
+
+    properties[PROP_ADDRESS] = g_param_spec_string ("address",
+                                                    "server address",
+                                                    "Server socket address",
+                                                    NULL,
+                                                    G_PARAM_READWRITE | 
+                                                    G_PARAM_CONSTRUCT_ONLY | 
+                                                    G_PARAM_STATIC_STRINGS);
+
+    g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+gsignond_dbus_server_init (GSignondDbusServer *self)
+{
+    self->priv = GSIGNOND_DBUS_SERVER_GET_PRIV(self);
+#ifdef USE_P2P
+    self->priv->bus_server = NULL;
+    self->priv->address = NULL;
+#else
+    self->priv->connection = NULL;
+    self->priv->name_owner_id = 0;
+#endif
+    self->priv->daemon = gsignond_daemon_new ();
+    self->priv->auth_services = g_hash_table_new_full (
+        g_direct_hash, g_direct_equal, NULL, g_object_unref);
+}
+
+static void
+_on_connection_closed (GDBusConnection *connection,
+                       gboolean         remote_peer_vanished,
+                       GError          *error,
+                       gpointer         user_data)
+{
+    GSignondDbusServer *server = GSIGNOND_DBUS_SERVER (user_data);
+
+    g_signal_handlers_disconnect_by_func (connection, _on_connection_closed, user_data);
+    DBG("dbus connection(%p) closed (peer vanished : %d)", connection, remote_peer_vanished);
+    if (error) {
+       INFO("...reason : %s", error->message);
+    }
+    g_hash_table_remove (server->priv->auth_services, connection);
+}
+
+void
+gsignond_dbus_server_start_auth_service (GSignondDbusServer *server, GDBusConnection *connection)
+{
+    GSignondDbusAuthServiceAdapter *auth_service = NULL;
+
+    DBG("Starting authentication service on connection %p", connection);
+
+    auth_service = gsignond_dbus_auth_service_adapter_new_with_connection (
+        connection, g_object_ref (server->priv->daemon));
+
+    g_hash_table_insert (server->priv->auth_services, g_object_ref(connection), auth_service);
+
+    g_signal_connect (connection, "closed", G_CALLBACK(_on_connection_closed), server);
+}
+
+const gchar *
+gsignond_dbus_server_get_address (GSignondDbusServer *server)
+{
+    g_return_val_if_fail (server || GSIGNOND_IS_DBUS_SERVER (server), NULL);
+#ifdef USE_P2P
+    return g_dbus_server_get_client_address (server->priv->bus_server);
+#else
+    return NULL;
+#endif
+}
+
+#ifdef USE_P2P
+static gboolean
+_on_client_request (GDBusServer *dbus_server, GDBusConnection *connection, gpointer userdata)
+{
+    GSignondDbusServer *server = GSIGNOND_DBUS_SERVER(userdata);
+
+    if (!server) {
+        ERR ("memory currpotion");
+        return TRUE;
+    }
+
+    gsignond_dbus_server_start_auth_service (server, connection);
+
+    return TRUE;
+}
+
+GSignondDbusServer * gsignond_dbus_server_new_with_address (const gchar *address)
+{
+    GError *err = NULL;
+    gchar *guid = 0;
+    GSignondDbusServer *server = GSIGNOND_DBUS_SERVER (
+        g_object_new (GSIGNOND_TYPE_DBUS_SERVER, "address", address, NULL));
+
+    if (!server) return NULL;
+
+    guid = g_dbus_generate_guid ();
+
+    server->priv->bus_server = g_dbus_server_new_sync (server->priv->address,
+            G_DBUS_SERVER_FLAGS_NONE, guid, NULL, NULL, &err);
+
+    g_free (guid);
+
+    if (!server->priv->bus_server) {
+        ERR ("failed to start server at address '%s':%s", server->priv->address,
+                 err->message);
+        g_error_free (err);
+        
+        g_object_unref (server);
+     
+        return NULL;
+    }
+
+    g_dbus_server_start (server->priv->bus_server);
+
+    g_signal_connect (server->priv->bus_server, "new-connection", G_CALLBACK(_on_client_request), server);
+
+    g_dbus_server_start (server->priv->bus_server);
+
+    return server;
+}
+
+GSignondDbusServer * gsignond_dbus_server_new () {
+    return gsignond_dbus_server_new_with_address (GSIGNOND_DBUS_ADDRESS);
+}
+#else
+
+static void
+_on_bus_acquired (GDBusConnection *connection,
+                  const gchar     *name,
+                  gpointer         user_data)
+{
+    GSignondDbusServer *server = GSIGNOND_DBUS_SERVER (user_data);
+    INFO ("bus aquired on connection '%p'", connection);
+    if (connection != NULL) {
+        server->priv->connection = g_object_ref (connection);
+    }
+}
+
+static void
+_on_name_lost (GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+    INFO ("Lost (or failed to acquire) the name '%s' on the on bus connection '%p'", name, connection);
+    if (user_data) g_object_unref (G_OBJECT (user_data));
+}
+
+static void
+_on_name_acquired (GDBusConnection *connection,
+                   const gchar     *name,
+                   gpointer         user_data)
+{
+    GSignondDbusServer *server = GSIGNOND_DBUS_SERVER (user_data);
+    INFO ("Acquired the name %s on connection '%p'", name, connection);
+    gsignond_dbus_server_start_auth_service (server, connection);
+}
+
+GSignondDbusServer * gsignond_dbus_server_new () {
+    GSignondDbusServer *server = GSIGNOND_DBUS_SERVER (
+            g_object_new (GSIGNOND_TYPE_DBUS_SERVER, NULL));
+
+    server->priv->name_owner_id = g_bus_own_name (GSIGNOND_BUS_TYPE,
+            GSIGNOND_SERVICE, 
+            G_BUS_NAME_OWNER_FLAGS_REPLACE,
+            _on_bus_acquired,
+            _on_name_acquired,
+            _on_name_lost,
+            server, NULL);
+
+    return server;
+}
+#endif
diff --git a/src/daemon/dbus/gsignond-dbus-server.h b/src/daemon/dbus/gsignond-dbus-server.h
new file mode 100644 (file)
index 0000000..d8e4d52
--- /dev/null
@@ -0,0 +1,70 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of gsignond
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef __GSIGNOND_DBUS_SERVER_H_
+#define __GSIGNOND_DBUS_SERVER_H_
+
+#include <config.h>
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GSIGNOND_TYPE_DBUS_SERVER            (gsignond_dbus_server_get_type())
+#define GSIGNOND_DBUS_SERVER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GSIGNOND_TYPE_DBUS_SERVER, GSignondDbusServer))
+#define GSIGNOND_DBUS_SERVER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GSIGNOND_TYPE_DBUS_SERVER, GSignondDbusServerClass))
+#define GSIGNOND_IS_DBUS_SERVER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GSIGNOND_TYPE_DBUS_SERVER))
+#define GSIGNOND_IS_DBUS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GSIGNOND_TYPE_DBUS_SERVER))
+#define GSIGNOND_DBUS_SERVER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GSIGNOND_TYPE_DBUS_SERVER, GSignondDbusServerClass))
+
+typedef struct _GSignondDbusServer GSignondDbusServer;
+typedef struct _GSignondDbusServerClass GSignondDbusServerClass;
+typedef struct _GSignondDbusServerPrivate GSignondDbusServerPrivate;
+
+struct _GSignondDbusServer
+{
+    GObject parent;
+
+    /* priv */
+    GSignondDbusServerPrivate *priv;
+};
+
+struct _GSignondDbusServerClass
+{
+    GObjectClass parent_class;
+};
+
+GType gsignond_dbus_server_get_type();
+
+#ifdef USE_P2P
+GSignondDbusServer * gsignond_dbus_server_new_with_address (const gchar *address);
+
+const gchar *
+gsignond_dbus_server_get_address (GSignondDbusServer *server) G_GNUC_CONST;
+
+#endif
+GSignondDbusServer * gsignond_dbus_server_new ();
+
+#endif /* __GSIGNOND_DBUS_SERVER_H_ */
index 4777055..db3398f 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "gsignond-dbus-signonui-adapter.h"
+#include "gsignond-dbus-signonui-gen.h"
 #include "gsignond/gsignond-log.h"
 #include "gsignond-dbus.h"
 
@@ -101,7 +102,6 @@ static void
 gsignond_dbus_signonui_adapter_init (GSignondDbusSignonuiAdapter *self)
 {
     self->priv = GSIGNOND_DBUS_SIGNONUI_ADAPTER_GET_PRIV(self);
-
     self->priv->connection = 0;
     self->priv->proxy = 0;
 }
index 7aca6b0..b12d6bb 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <glib.h>
 #include <gio/gio.h>
-#include "gsignond-dbus-signonui-gen.h"
 
 G_BEGIN_DECLS
 
index 4c5e828..3decf61 100644 (file)
@@ -29,6 +29,7 @@
 /*
  * Common DBUS definitions
  */
+#define GSIGNOND_DBUS_ADDRESS            "unix:abstract=gsignond"
 #define GSIGNOND_SERVICE_PREFIX          "com.google.code.AccountsSSO.gSingleSignOn"
 #define GSIGNOND_SERVICE                 GSIGNOND_SERVICE_PREFIX
 #define GSIGNOND_DAEMON_OBJECTPATH       "/com/google/code/AccountsSSO/gSingleSignOn"
diff --git a/src/daemon/gsignond-auth-service-iface.c b/src/daemon/gsignond-auth-service-iface.c
deleted file mode 100644 (file)
index 734b423..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include "gsignond-auth-service-iface.h"
-
-G_DEFINE_INTERFACE (GSignondAuthServiceIface, gsignond_auth_service_iface, G_TYPE_OBJECT)
-
-static const gchar * 
-_dummy_register_new_identity (GSignondAuthServiceIface *self,
-                              const GSignondSecurityContext *ctx,
-                              GError **error)
-{
-    (void) self;
-    (void) ctx;
-    (void) error;
-    return NULL;
-}
-
-static const gchar *
-_dummy_get_identity (GSignondAuthServiceIface *self, 
-                     guint32 id,
-                     const GSignondSecurityContext *ctx, 
-                     GVariant **identity_data,
-                     GError **error)
-{
-    (void) self;
-    (void) id;
-    (void) ctx;
-    (void) identity_data;
-    (void) error;
-    return NULL;
-}
-
-static const gchar **
-_dummy_query_methods (GSignondAuthServiceIface *self,
-                      GError **error)
-{
-    (void) self;
-    (void) error;
-    return NULL;
-}
-
-static const gchar **
-_dummy_query_mechanisms (GSignondAuthServiceIface *self, 
-                         const gchar *method,
-                         GError **error)
-{
-    (void) self;
-    (void) method;
-    (void) error;
-    return NULL;
-}
-
-static GVariant *
-_dummy_query_identities (GSignondAuthServiceIface *self, 
-                         const GVariant *filter,
-                         GError **error)
-{
-    (void) self;
-    (void) filter;
-    (void) error;
-    return NULL;
-}
-
-static gboolean
-_dummy_clear (GSignondAuthServiceIface *self,
-              GError **error)
-{
-    (void) self;
-    (void) error;
-    return FALSE;
-}
-
-static GSignondAccessControlManager *
-_dummy_get_acm (GSignondAuthServiceIface *self)
-{
-    (void) self;
-
-    return NULL;
-}
-
-static void
-gsignond_auth_service_iface_default_init (
-                                        GSignondAuthServiceIfaceInterface *self)
-{
-    self->register_new_identity = _dummy_register_new_identity;
-    self->get_identity = _dummy_get_identity;
-    self->query_methods = _dummy_query_methods;
-    self->query_mechanisms = _dummy_query_mechanisms;
-    self->query_identities = _dummy_query_identities;
-    self->clear = _dummy_clear;
-    self->get_acm = _dummy_get_acm;
-}
-
-/**
- * gsignond_auth_service_iface_register_new_identity:
- * @self: instance of #GSignondAuthServiceIfacea
- * @ctx: security context
- * @error: return location for error
- *
- *
- * Returns: (transfer none) object path of newly created identity.
- */
-const gchar *
-gsignond_auth_service_iface_register_new_identity (
-                                                 GSignondAuthServiceIface *self,
-                                                 const GSignondSecurityContext *ctx,
-                                                 GError **error)
-{
-    return GSIGNOND_AUTH_SERVICE_GET_INTERFACE (self)->
-        register_new_identity (self, ctx, error);
-}
-
-/**
- * gsignond_auth_service_iface_get_identity:
- * @self: instance of #GSignondAuthServiceIface
- * @id: id of the identity to lookup
- * @ctx: security context
- * @object_path:  return location for object path of the identity
- * @identity_data: return location for identity data
- * @error: return location for error
- *
- * Retrives object path and identity info stored for the given @id.
- *
- * Returns: (transfer none): object path of the identity on success, @NULL otherwise.
- */
-const gchar *
-gsignond_auth_service_iface_get_identity (GSignondAuthServiceIface *self,
-                                          guint32 id,
-                                          const GSignondSecurityContext *ctx,
-                                          GVariant **identity_data,
-                                          GError **error)
-{
-    return GSIGNOND_AUTH_SERVICE_GET_INTERFACE(self)->
-        get_identity (self, id, ctx, identity_data, error);
-}
-
-/**
- * gsignond_auth_service_iface_query_methods:
- * @self: instance of #GSignondAuthServiceIface
- * @error: return location for error
- *
- * Retrieves the available authentication methods. 
- *
- * Returns: (transfer none): list of methods
- */
-const gchar **
-gsignond_auth_service_iface_query_methods (GSignondAuthServiceIface *self,
-                                           GError **error)
-{
-    return GSIGNOND_AUTH_SERVICE_GET_INTERFACE (self)->query_methods (self, error);
-}
-
-/**
- * gsignond_auth_service_iface_query_mechanisms:
- * @self: instance of #GSignondAuthServiceIface
- * @method: method to query
- * @error: return location for error
- *
- * Retrieves the available mechanisms for authentication method @method.
- *
- * Returns: (transfer none): list of mechanisms
- */
-const gchar **
-gsignond_auth_service_iface_query_mechanisms (GSignondAuthServiceIface *self,
-                                              const gchar *method,
-                                              GError **error)
-{
-    return GSIGNOND_AUTH_SERVICE_GET_INTERFACE (self)->
-        query_mechanisms (self, method, error);
-}
-
-/**
- * gsignond_auth_service_iface_query_identities:
- * @self: instance of #GSignondAuthServiceIface
- * @filter: filter should be applited
- * @error: return location for error
- *
- * Retrieves the identities that satisifies the filter @filter.
- *
- * Returns: (transfer full): list of identities
- */
-GVariant *
-gsignond_auth_service_iface_query_identities (GSignondAuthServiceIface *self,
-                                              const GVariant *filter,
-                                              GError **error)
-{
-    return GSIGNOND_AUTH_SERVICE_GET_INTERFACE (self)->
-        query_identities (self, filter, error);
-}
-
-/**
- * gsignond_auth_service_iface_clear:
- * @self: instance of #GSignondAuthServiceIface
- * @error: return location for error
- *  
- * Clears the cache.
- *
- * Returns: TRUE on successful, FALSE otherwise
- */
-gboolean
-gsignond_auth_service_iface_clear (GSignondAuthServiceIface *self,
-                                   GError **error)
-{
-    return GSIGNOND_AUTH_SERVICE_GET_INTERFACE (self)->clear(self, error);
-}
-
-GSignondAccessControlManager *
-gsignond_auth_service_iface_get_acm (GSignondAuthServiceIface *self)
-{
-    return GSIGNOND_AUTH_SERVICE_GET_INTERFACE (self)->get_acm (self);
-}
diff --git a/src/daemon/gsignond-auth-service-iface.h b/src/daemon/gsignond-auth-service-iface.h
deleted file mode 100644 (file)
index 65ffbf1..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifndef __GSIGNOND_AUTH_SERVICE_IFACE_H_
-#define __GSIGNOND_AUTH_SERVICE_IFACE_H_
-
-#include <glib.h>
-#include <glib-object.h>
-#include <gsignond/gsignond-access-control-manager.h>
-#include <gsignond/gsignond-security-context.h>
-
-G_BEGIN_DECLS
-
-#define GSIGNOND_TYPE_AUTH_SERVICE_IFACE          (gsignond_auth_service_iface_get_type ())
-#define GSIGNOND_AUTH_SERVICE_IFACE(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSIGNOND_TYPE_AUTH_SERVICE_IFACE, GSignondAuthServiceIface))
-#define GSIGNOND_IS_AUTH_SERVICE_IFACE(obj)       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSIGNOND_TYPE_AUTH_SERVICE_IFACE))
-#define GSIGNOND_AUTH_SERVICE_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GSIGNOND_TYPE_AUTH_SERVICE_IFACE, GSignondAuthServiceIfaceInterface))
-
-typedef struct _GSignondAuthServiceIface GSignondAuthServiceIface; /* dummy */
-typedef struct _GSignondAuthServiceIfaceInterface GSignondAuthServiceIfaceInterface;
-
-struct _GSignondAuthServiceIfaceInterface {
-    GTypeInterface parent;
-
-    /**
-     * register_new_identity:
-     * @auth_service: An instance of #GSignondAuthServiceIface
-     * @ctx: Security context
-     * @error: return location for error
-     *
-     * Creates new identity object and registers it on the DBus. Returns the
-     * dbus object of the newly created identity.
-     *
-     * Returns: (transfer null) object of the newly created identity if success, @NULL otherwise.
-     */
-    const gchar * (*register_new_identity) (GSignondAuthServiceIface *auth_service, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * get_identity:
-     * @auth_service: An instance of #GSignondAuthServiceIface
-     * @id: id to query
-     * @ctx: Security context
-     * @object_path: (transfers full) holds the object path of the identity
-     * @identity_data: (transfers full) holds the identity data
-     * @error: return location for error
-     *
-     * Retrives idnetity information stored and object path on DBus with the given id @id.
-     *
-     * Returns: (transfer null) object of the newly created identity if success, @NULL otherwise.
-     */
-    const gchar* (*get_identity) (GSignondAuthServiceIface *auth_service, guint32 id, const GSignondSecurityContext *ctx, GVariant **identity_data, GError **error);
-
-    /**
-     * query_methods:
-     * @auth_service: An instance of #GSignondAuthServiceIface
-     * @error: return location for error
-     *
-     * Retrieves the supported authentication methods on this service object.
-     *
-     * Returns: (transfer none): list of authentication methods. 
-     */
-    const gchar ** (*query_methods) (GSignondAuthServiceIface *auth_service, GError **error);
-
-    /**
-     * query_mechanisms:
-     * @auth_service: An instance of #GSignondAuthServiceIface
-     * @method: authentication method
-     * @error: return location for error
-     *
-     * Retrieves the supported authentication mechanisms for given @method on this service object.
-     *
-     * Returns: (transfer full): list of authentication mechanisms.
-     */
-    const gchar ** (*query_mechanisms) (GSignondAuthServiceIface *auth_service, const gchar *method, GError **error);
-
-    /**
-     * query_identities:
-     * @auth_service: An instance of #GSignondAuthServiceIface
-     * @filter: filter to be applied
-     * @error: return location for error
-     *
-     * Query for stored identities which satisifies the given filter @filter.
-     *
-     * Returns: (transfers full) identity list
-     */
-    GVariant * (*query_identities) (GSignondAuthServiceIface *auth_service, const GVariant *filter, GError **error);
-
-    /**
-     * clear:
-     * @auth_service: An instance of #GSignondAuthServiceIface
-     * @error: return location for error
-     *
-     * Clears all the identity information stored.
-     *
-     * Retruns: @TRUE on success, @FALSE otherwise
-     */
-    gboolean (*clear) (GSignondAuthServiceIface *auth_service, GError **error);
-
-    /**
-     * get_acm
-     * @auth_service: An instance of #GSignondAuthServiceIface
-     *
-     * Retrives access control manager used by #auth_service.
-     *
-     * Returns: (transfers none): access control manager
-     */
-    GSignondAccessControlManager * (*get_acm) (GSignondAuthServiceIface *auth_service);
-};
-
-GType gsignond_auth_service_iface_get_type (void);
-
-const gchar * 
-gsignond_auth_service_iface_register_new_identity (
-                                                GSignondAuthServiceIface *self,
-                                                const GSignondSecurityContext *ctx,
-                                                GError **error);
-const gchar *
-gsignond_auth_service_iface_get_identity (GSignondAuthServiceIface *self,
-                                          guint32 id,
-                                          const GSignondSecurityContext *ctx,
-                                          GVariant **identity_data,
-                                          GError **error);
-const gchar **
-gsignond_auth_service_iface_query_methods (GSignondAuthServiceIface *self,
-                                           GError **error);
-const gchar **
-gsignond_auth_service_iface_query_mechanisms (GSignondAuthServiceIface *self,
-                                              const gchar *method,
-                                              GError **error);
-GVariant *
-gsignond_auth_service_iface_query_identities (GSignondAuthServiceIface *self,
-                                              const GVariant *filter,
-                                              GError **error);
-gboolean
-gsignond_auth_service_iface_clear (GSignondAuthServiceIface *self,
-                                   GError **error);
-
-GSignondAccessControlManager *
-gsignond_auth_service_iface_get_acm (GSignondAuthServiceIface *self);
-
-G_END_DECLS
-
-#endif /* __GSIGNOND_AUTH_SERVICE_IFACE_H_ */
diff --git a/src/daemon/gsignond-auth-session-iface.c b/src/daemon/gsignond-auth-session-iface.c
deleted file mode 100644 (file)
index b721dc4..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include "gsignond-auth-session-iface.h"
-
-G_DEFINE_INTERFACE (GSignondAuthSessionIface, gsignond_auth_session_iface, 0)
-
-enum {
-    SIG_PROCESS_RESULT,
-    SIG_PROCESS_ERROR,
-    SIG_PROCESS_STORE,
-    SIG_PROCESS_USER_ACTION_REQUIRED,
-    SIG_PROCESS_REFRESHED,
-    SIG_PROCESS_STATE_CHANGED,
-    
-    SIG_MAX
-};
-
-static guint signals[SIG_MAX] = { 0 };
-
-static void
-gsignond_auth_session_iface_default_init (
-                                        GSignondAuthSessionIfaceInterface *self)
-{
-    /**
-     * GSignondAuthSessionIfaceInterface::process:
-     * @object: A #GSignondAuthServiceIface.
-     * @results:
-     *
-     * Signal emitted when a processing is done.
-     *
-     */
-    signals[SIG_PROCESS_RESULT] =  g_signal_new ("process-result",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            1,
-            GSIGNOND_TYPE_SESSION_DATA);
-
-    signals[SIG_PROCESS_ERROR] = g_signal_new ("process-error",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            1,
-            G_TYPE_ERROR);
-
-    signals[SIG_PROCESS_STORE] =  g_signal_new ("process-store",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            1,
-            GSIGNOND_TYPE_SESSION_DATA);
-    
-    signals[SIG_PROCESS_USER_ACTION_REQUIRED] =  g_signal_new (
-            "process-user-action-required",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            1,
-            GSIGNOND_TYPE_SIGNONUI_DATA);
-
-    signals[SIG_PROCESS_REFRESHED] =  g_signal_new (
-            "process-refreshed",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            1,
-            GSIGNOND_TYPE_SIGNONUI_DATA);
-
-    signals[SIG_PROCESS_STATE_CHANGED] =  g_signal_new (
-            "state-changed",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            2,
-            G_TYPE_INT, G_TYPE_STRING);
-}
-
-gchar **
-gsignond_auth_session_iface_query_available_mechanisms (
-                                                GSignondAuthSessionIface *self,
-                                                const gchar **wanted_mechanisms,
-                                                const GSignondSecurityContext *ctx,
-                                                GError **error)
-{
-    return GSIGNOND_AUTH_SESSION_GET_INTERFACE (self)->
-        query_available_mechanisms (self, wanted_mechanisms, ctx, error);
-}
-
-gboolean
-gsignond_auth_session_iface_process (GSignondAuthSessionIface *self,
-                                     GSignondSessionData *session_data,
-                                     const gchar *mechanism,
-                                     const GSignondSecurityContext *ctx,
-                                     GError **error)
-{
-    return GSIGNOND_AUTH_SESSION_GET_INTERFACE (self)->
-        process (self, session_data, mechanism, ctx, error);
-}
-
-gboolean
-gsignond_auth_session_iface_cancel (GSignondAuthSessionIface *self,
-                                    const GSignondSecurityContext *ctx,
-                                    GError **error)
-{
-    return GSIGNOND_AUTH_SESSION_GET_INTERFACE (self)->cancel (self, ctx, error);
-}
-
-GSignondAccessControlManager *
-gsignond_auth_session_iface_get_acm (GSignondAuthSessionIface *self)
-{
-    return GSIGNOND_AUTH_SESSION_GET_INTERFACE (self)->get_acm (self);
-}
-
-void 
-gsignond_auth_session_iface_user_action_finished (GSignondAuthSessionIface *self, 
-                                                  GSignondSignonuiData *ui_data)
-{
-    return GSIGNOND_AUTH_SESSION_GET_INTERFACE (self)->
-        user_action_finished (self, ui_data);
-}
-
-void 
-gsignond_auth_session_iface_refresh (GSignondAuthSessionIface *self, 
-                                     GSignondSignonuiData *ui_data)
-{
-    GSIGNOND_AUTH_SESSION_GET_INTERFACE (self)->
-        refresh (self, ui_data);
-}
-
-void
-gsignond_auth_session_iface_notify_process_result (GSignondAuthSessionIface *iface,
-                                                   GSignondSessionData *result)
-{
-    g_signal_emit (iface, signals[SIG_PROCESS_RESULT], 0, result);
-}
-
-void
-gsignond_auth_session_iface_notify_process_error (GSignondAuthSessionIface *iface,
-                                                  const GError *error)
-{
-    g_signal_emit (iface, signals[SIG_PROCESS_ERROR], 0, error);
-}
-
-void 
-gsignond_auth_session_iface_notify_store (GSignondAuthSessionIface *self, 
-                                          GSignondSessionData *session_data)
-{
-    g_signal_emit (self, signals[SIG_PROCESS_STORE], 0, session_data);
-}
-
-void 
-gsignond_auth_session_iface_notify_user_action_required (GSignondAuthSessionIface *self, 
-                                                         GSignondSignonuiData *ui_data)
-{
-    g_signal_emit (self, signals[SIG_PROCESS_USER_ACTION_REQUIRED], 0, ui_data);
-}
-
-void 
-gsignond_auth_session_iface_notify_refreshed (GSignondAuthSessionIface *self, 
-                                            GSignondSignonuiData *ui_data)
-{
-    g_signal_emit (self, signals[SIG_PROCESS_REFRESHED], 0, ui_data);
-}
-
-void 
-gsignond_auth_session_iface_notify_state_changed (GSignondAuthSessionIface *self,
-                                                  gint state,
-                                                  const gchar *message)
-{
-    g_signal_emit (self, signals[SIG_PROCESS_STATE_CHANGED], 0, state,
-        message);
-}
diff --git a/src/daemon/gsignond-auth-session-iface.h b/src/daemon/gsignond-auth-session-iface.h
deleted file mode 100644 (file)
index df51988..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifndef __GSIGNOND_AUTH_SESSION_IFACE_H_
-#define __GSIGNOND_AUTH_SESSION_IFACE_H_
-
-#include <glib.h>
-#include <glib-object.h>
-#include <gsignond/gsignond-session-data.h>
-#include <gsignond/gsignond-signonui-data.h>
-#include <gsignond/gsignond-access-control-manager.h>
-#include <gsignond/gsignond-security-context.h>
-
-G_BEGIN_DECLS
-
-#define GSIGNOND_TYPE_AUTH_SESSION_IFACE          (gsignond_auth_session_iface_get_type ())
-#define GSIGNOND_AUTH_SESSION_IFACE(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSIGNOND_TYPE_AUTH_SESSION_IFACE, GSignondAuthSessionIface))
-#define GSIGNOND_IS_AUTH_SESSION_IFACE(obj)       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSIGNOND_TYPE_AUTH_SESSION_IFACE))
-#define GSIGNOND_AUTH_SESSION_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GSIGNOND_TYPE_AUTH_SESSION_IFACE, GSignondAuthSessionIfaceInterface))
-
-typedef struct _GSignondAuthSessionIface GSignondAuthSessionIface; /* dummy */
-typedef struct _GSignondAuthSessionIfaceInterface GSignondAuthSessionIfaceInterface;
-
-struct _GSignondAuthSessionIfaceInterface {
-    GTypeInterface parent;
-
-    /**
-     * query_available_mechanisms:
-     * @session: instance of #GSignondAuthSessionIface
-     * @desired_mechanisms: desired authentication mechanisms
-     * @ctx: security context of the caller
-     * @error: return location for error
-     *
-     * Checks for support of desired authentication mechanisms #desired_mechanisms for this
-     * authentication session, The result will be interseciton of desired authenticaiton mechansims 
-     * and available authenticaiton mechansims.
-     *
-     * Returns: (transfer full) list of supported authentication mechansims out of #desired_mechanisms
-     * Caller should use g_strfreev() when done with return value.
-     */
-    gchar **   (*query_available_mechanisms) (GSignondAuthSessionIface *session,
-                                              const gchar **desired_mechanisms,
-                                              const GSignondSecurityContext *ctx,
-                                              GError **error);
-
-    /**
-     * process:
-     * @session: instance of #GSignondAuthSessionIface
-     * @session_data: authentication session data to use
-     * @mechansims: authentication mechanism to use
-     * @ctx: security context of the caller
-     * @error: return location for error
-     *
-     * Initiates authentication process on #session, On successful authentication #gsignond_auth_session_iface_notify_process_result will be called.
-     * In case failure occured in authentication process, the error is informed via #gsignond_auth_session_iface_notify_process_error.
-
-     * Returns: @TRUE if authentication process was started successfully, @FALSE otherwise
-     */
-    gboolean   (*process) (GSignondAuthSessionIface *session,
-                           GSignondSessionData *session_data,
-                           const gchar *mechanism,
-                           const GSignondSecurityContext *ctx,
-                           GError **error);
-
-    /**
-     * cancel:
-     * @session: instance of #GSignondAuthSessionIface
-     * @ctx: security context of the caller
-     * @error: return location for error
-     *
-     */
-    gboolean   (*cancel) (GSignondAuthSessionIface *session,
-                          const GSignondSecurityContext *ctx,
-                          GError **error);
-
-    GSignondAccessControlManager * (*get_acm) (GSignondAuthSessionIface *session);
-
-    void (*user_action_finished) (GSignondAuthSessionIface *session, 
-                                  GSignondSignonuiData *ui_data);
-
-    void (*refresh) (GSignondAuthSessionIface *session, 
-                     GSignondSignonuiData *ui_data);
-
-};
-
-GType gsignond_auth_session_iface_get_type (void);
-
-gchar ** 
-gsignond_auth_session_iface_query_available_mechanisms (GSignondAuthSessionIface *self,
-                                                        const gchar **wanted_mechanisms,
-                                                        const GSignondSecurityContext *ctx,
-                                                        GError **error);
-gboolean 
-gsignond_auth_session_iface_process (GSignondAuthSessionIface *self,
-                                     GSignondSessionData *session_data,
-                                     const gchar *mechanism,
-                                     const GSignondSecurityContext *ctx,
-                                     GError **error);
-gboolean
-gsignond_auth_session_iface_cancel (GSignondAuthSessionIface *self,
-                                    const GSignondSecurityContext *ctx,
-                                    GError **error);
-void 
-gsignond_auth_session_iface_user_action_finished (GSignondAuthSessionIface *self, 
-                                                  GSignondSignonuiData *ui_data);
-void 
-gsignond_auth_session_iface_refresh (GSignondAuthSessionIface *self, 
-                                     GSignondSignonuiData *ui_data);
-
-
-/* handlers */
-/**
-  * process_reply:
-  * @session: instance of #GSignondAuthSessionIface
-  * @results: authentication process results
-  *
-  * Function to be called with #results on authentication process success.
-  */
-void
-gsignond_auth_session_iface_notify_process_result (GSignondAuthSessionIface *iface,
-                                                   GSignondSessionData *result);
-
-/**
-  * process_error:
-  * @session: instance of #GSignondAuthSessionIface
-  * @error: error of type #GError, occured during authentication process
-  *
-  * Function to be called with #error on authentication process failure.
-  */
-void
-gsignond_auth_session_iface_notify_process_error (GSignondAuthSessionIface *iface,
-                                                  const GError *error);
-
-GSignondAccessControlManager *
-gsignond_auth_session_iface_get_acm (GSignondAuthSessionIface *self);
-
-void 
-gsignond_auth_session_iface_notify_store (GSignondAuthSessionIface *self, 
-                                          GSignondSessionData *session_data);
-void 
-gsignond_auth_session_iface_notify_user_action_required (GSignondAuthSessionIface *self, 
-                                                         GSignondSignonuiData *ui_data);
-void 
-gsignond_auth_session_iface_notify_refreshed (GSignondAuthSessionIface *self, 
-                                              GSignondSignonuiData *ui_data);
-void 
-gsignond_auth_session_iface_notify_state_changed (GSignondAuthSessionIface *self, 
-                                                  gint state,
-                                                  const gchar *message);
-
-G_END_DECLS
-
-#endif /* __GSIGNOND_AUTH_SESSION_IFACE_H_ */
index baae69d..3584ecb 100644 (file)
  * 02110-1301 USA
  */
 
-#include "gsignond-auth-session-iface.h"
+#include "gsignond-auth-session.h"
 #include "gsignond/gsignond-error.h"
 #include "gsignond/gsignond-log.h"
 #include "gsignond/gsignond-session-data.h"
 #include "gsignond/gsignond-identity-info.h"
-#include "dbus/gsignond-dbus.h"
-#include "dbus/gsignond-dbus-auth-session-adapter.h"
-#include "gsignond-auth-session.h"
 #include "plugins/gsignond-plugin-proxy-factory.h"
 #include "gsignond-daemon.h"
 
@@ -44,21 +41,29 @@ enum
 
 static GParamSpec *properties[N_PROPERTIES];
 
+enum {
+    SIG_PROCESS_RESULT,
+    SIG_PROCESS_ERROR,
+    SIG_PROCESS_STORE,
+    SIG_PROCESS_USER_ACTION_REQUIRED,
+    SIG_PROCESS_REFRESHED,
+    SIG_PROCESS_STATE_CHANGED,
+    
+    SIG_MAX
+};
+
+static guint signals[SIG_MAX] = { 0 };
+
 struct _GSignondAuthSessionPrivate
 {
     gchar *method;
-    GSignondDbusAuthSessionAdapter *session_adapter;
+    gchar *app_context;
     GSignondPluginProxy *proxy;
     GSequence *available_mechanisms;
     GSignondIdentityInfo *identity_info;
 };
 
-static void gsignond_auth_session_iface_init (gpointer g_iface);
-
-G_DEFINE_TYPE_WITH_CODE (GSignondAuthSession, gsignond_auth_session,
-                        GSIGNOND_TYPE_DISPOSABLE,
-                        G_IMPLEMENT_INTERFACE (GSIGNOND_TYPE_AUTH_SESSION_IFACE,
-                                               gsignond_auth_session_iface_init));
+G_DEFINE_TYPE (GSignondAuthSession, gsignond_auth_session, G_TYPE_OBJECT)
 
 #define GSIGNOND_AUTH_SESSION_PRIV(obj) \
     G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_AUTH_SESSION, \
@@ -148,18 +153,17 @@ _create_mechanism_cache (GSignondAuthSession *self)
     g_free (mechanisms);
 }
 
-static gchar **
-_query_available_mechanisms (GSignondAuthSessionIface *iface,
-                             const gchar **wanted_mechanisms,
-                             const GSignondSecurityContext *ctx,
-                             GError **error)
+gchar **
+gsignond_auth_session_query_available_mechanisms (GSignondAuthSession *self,
+                                                  const gchar **wanted_mechanisms,
+                                                  const GSignondSecurityContext *ctx,
+                                                  GError **error)
 {
-    if (!iface || !GSIGNOND_IS_AUTH_SESSION (iface)) {
-        WARN ("assertion (iface && GSIGNOND_IS_AUTH_SESSION (iface)) failed");
+    if (!self || !GSIGNOND_IS_AUTH_SESSION (self)) {
+        WARN ("assertion (iself && GSIGNOND_IS_AUTH_SESSION (self)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return NULL;
     }
-    GSignondAuthSession *self = GSIGNOND_AUTH_SESSION (iface);
 
     VALIDATE_READ_ACCESS (self->priv->identity_info, ctx, NULL);
 
@@ -187,19 +191,18 @@ _query_available_mechanisms (GSignondAuthSessionIface *iface,
     return mechanisms;
 }
 
-static gboolean
-_process (GSignondAuthSessionIface *iface, 
-          GSignondSessionData *session_data,
-          const gchar *mechanism,
-          const GSignondSecurityContext *ctx,
-          GError **error)
+gboolean
+gsignond_auth_session_process (GSignondAuthSession *self,
+                               GSignondSessionData *session_data,
+                               const gchar *mechanism,
+                               const GSignondSecurityContext *ctx,
+                               GError **error)
 {
-    if (!iface || !GSIGNOND_IS_AUTH_SESSION (iface)) {
-        WARN ("assertion (iface && GSIGNOND_IS_AUTH_SESSION (iface))failed");
+    if (!self || !GSIGNOND_IS_AUTH_SESSION (self)) {
+        WARN ("assertion (seöf && GSIGNOND_IS_AUTH_SESSION (self))failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
-    GSignondAuthSession *self = GSIGNOND_AUTH_SESSION (iface);
 
     VALIDATE_READ_ACCESS (self->priv->identity_info, ctx, FALSE);
 
@@ -222,51 +225,53 @@ _process (GSignondAuthSessionIface *iface,
         }
     }
 
-    gsignond_plugin_proxy_process(self->priv->proxy, iface, session_data,
+    gsignond_plugin_proxy_process(self->priv->proxy, self, session_data,
                                   mechanism);
 
     return TRUE;
 }
 
-static gboolean
-_cancel (GSignondAuthSessionIface *iface,
-         const GSignondSecurityContext *ctx,
-         GError **error)
+gboolean
+gsignond_auth_session_cancel (GSignondAuthSession *self,
+                              const GSignondSecurityContext *ctx,
+                              GError **error)
 {
-    if (!iface || !GSIGNOND_IS_AUTH_SESSION (iface)) {
-        WARN ("assertion (iface && GSIGNOND_IS_AUTH_SESSION (iface)) failed");
+    if (!self || !GSIGNOND_IS_AUTH_SESSION (self)) {
+        WARN ("assertion (self && GSIGNOND_IS_AUTH_SESSION (self)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
-    GSignondAuthSession *self = GSIGNOND_AUTH_SESSION (iface);
-
     VALIDATE_READ_ACCESS (self->priv->identity_info, ctx, FALSE);
 
-    gsignond_plugin_proxy_cancel(self->priv->proxy, iface);
+    gsignond_plugin_proxy_cancel(self->priv->proxy, self);
 
     return TRUE;
 }
 
-void 
-_user_action_finished (GSignondAuthSessionIface *iface, 
-                       GSignondSignonuiData *ui_data)
+void
+gsignond_auth_session_abort_process (GSignondAuthSession *self)
 {
-    GSignondAuthSession *self = GSIGNOND_AUTH_SESSION (iface);
+    g_return_if_fail (self && GSIGNOND_IS_AUTH_SESSION (self));
 
-    gsignond_plugin_proxy_user_action_finished(self->priv->proxy, ui_data);
+    gsignond_plugin_proxy_cancel (self->priv->proxy, self);
 }
 
 void 
-_refresh (GSignondAuthSessionIface *iface, 
-            GSignondSignonuiData *ui_data)
+gsignond_auth_session_user_action_finished (GSignondAuthSession *self,
+                                            GSignondSignonuiData *ui_data)
 {
-    GSignondAuthSession *self = GSIGNOND_AUTH_SESSION (iface);
+    gsignond_plugin_proxy_user_action_finished(self->priv->proxy, ui_data);
+}
 
+void
+gsignond_auth_session_refresh (GSignondAuthSession *self, 
+                               GSignondSignonuiData *ui_data)
+{
     gsignond_plugin_proxy_refresh(self->priv->proxy, ui_data);
 }
 
 GSignondAccessControlManager *
-_get_acm (GSignondAuthSessionIface *iface)
+gsignond_auth_session_get_acm (GSignondAuthSession *session)
 {
     return gsignond_get_access_control_manager ();
 }
@@ -283,7 +288,7 @@ _get_property (GObject *object, guint property_id, GValue *value,
             g_value_set_string (value, self->priv->method);
             break;
         case PROP_APP_CONTEXT:
-            g_object_get_property (G_OBJECT (self->priv->session_adapter), "app-context", value);
+            g_value_set_string (value, self->priv->app_context);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -302,7 +307,7 @@ _set_property (GObject *object, guint property_id, const GValue *value,
             self->priv->method = g_value_dup_string (value);
             break;
         case PROP_APP_CONTEXT:
-            g_object_set_property (G_OBJECT (self->priv->session_adapter), "app-context", value);
+            self->priv->app_context = g_value_dup_string (value);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -314,11 +319,6 @@ _dispose (GObject *object)
 {
     GSignondAuthSession *self = GSIGNOND_AUTH_SESSION (object);
 
-    if (self->priv->session_adapter) {
-        g_object_unref (self->priv->session_adapter);
-        self->priv->session_adapter = NULL;
-    }
-
     if (self->priv->proxy) {
         g_object_unref (self->priv->proxy);
         self->priv->proxy = NULL;
@@ -355,9 +355,10 @@ gsignond_auth_session_init (GSignondAuthSession *self)
 {
     self->priv = GSIGNOND_AUTH_SESSION_PRIV (self);
 
-    self->priv->session_adapter =
-        gsignond_dbus_auth_session_adapter_new (
-                                             GSIGNOND_AUTH_SESSION_IFACE(self));
+    self->priv->method = NULL;
+    self->priv->proxy = NULL;
+    self->priv->identity_info = NULL;
+    self->priv->available_mechanisms = NULL;
 }
 
 static void
@@ -389,20 +390,74 @@ gsignond_auth_session_class_init (GSignondAuthSessionClass *klass)
                               | G_PARAM_STATIC_STRINGS);
 
     g_object_class_install_properties (object_class, N_PROPERTIES, properties);
-}
 
-static void
-gsignond_auth_session_iface_init (gpointer g_iface)
-{
-    GSignondAuthSessionIfaceInterface *auth_session_iface =
-        (GSignondAuthSessionIfaceInterface *) g_iface;
-
-    auth_session_iface->process = _process;
-    auth_session_iface->query_available_mechanisms = _query_available_mechanisms;
-    auth_session_iface->cancel = _cancel;
-    auth_session_iface->user_action_finished = _user_action_finished;
-    auth_session_iface->refresh = _refresh;
-    auth_session_iface->get_acm = _get_acm;
+    signals[SIG_PROCESS_RESULT] =  g_signal_new ("process-result",
+            GSIGNOND_TYPE_AUTH_SESSION,
+            G_SIGNAL_RUN_LAST,
+            0,
+            NULL,
+            NULL,
+            NULL,
+            G_TYPE_NONE,
+            1,
+            GSIGNOND_TYPE_SESSION_DATA);
+
+    signals[SIG_PROCESS_ERROR] = g_signal_new ("process-error",
+            GSIGNOND_TYPE_AUTH_SESSION,
+            G_SIGNAL_RUN_LAST,
+            0,
+            NULL,
+            NULL,
+            NULL,
+            G_TYPE_NONE,
+            1,
+            G_TYPE_ERROR);
+
+    signals[SIG_PROCESS_STORE] =  g_signal_new ("process-store",
+            GSIGNOND_TYPE_AUTH_SESSION,
+            G_SIGNAL_RUN_LAST,
+            0,
+            NULL,
+            NULL,
+            NULL,
+            G_TYPE_NONE,
+            1,
+            GSIGNOND_TYPE_SESSION_DATA);
+    
+    signals[SIG_PROCESS_USER_ACTION_REQUIRED] =  g_signal_new ("process-user-action-required",
+            GSIGNOND_TYPE_AUTH_SESSION,
+            G_SIGNAL_RUN_LAST,
+            0,
+            NULL,
+            NULL,
+            NULL,
+            G_TYPE_NONE,
+            1,
+            GSIGNOND_TYPE_SIGNONUI_DATA);
+
+    signals[SIG_PROCESS_REFRESHED] =  g_signal_new ("process-refreshed",
+            GSIGNOND_TYPE_AUTH_SESSION,
+            G_SIGNAL_RUN_LAST,
+            0,
+            NULL,
+            NULL,
+            NULL,
+            G_TYPE_NONE,
+            1,
+            GSIGNOND_TYPE_SIGNONUI_DATA);
+
+    signals[SIG_PROCESS_STATE_CHANGED] =  g_signal_new (
+            "state-changed",
+            GSIGNOND_TYPE_AUTH_SESSION,
+            G_SIGNAL_RUN_LAST,
+            0,
+            NULL,
+            NULL,
+            NULL,
+            G_TYPE_NONE,
+            2,
+            G_TYPE_INT, G_TYPE_STRING);
+
 }
 
 /**
@@ -421,27 +476,55 @@ gsignond_auth_session_get_method (GSignondAuthSession *session)
     return session->priv->method;
 }
 
-/**
- * gsignond_auth_session_get_object_path:
- * @session: instance of #GSignondAuthSession
- *
- * Retrieves dbus object path used by #session object.
- *
- * Returns: (transfer none) dbus object path if success, NULL otherwise
- */
 const gchar *
-gsignond_auth_session_get_object_path (GSignondAuthSession *session)
+gsignond_auth_session_get_context (GSignondAuthSession *session)
 {
     g_return_val_if_fail (session && GSIGNOND_IS_AUTH_SESSION (session), NULL);
-    
-    return gsignond_dbus_auth_session_adapter_get_object_path (
-        session->priv->session_adapter);
+
+    return session->priv->app_context;
 }
 
-gboolean gsignond_auth_session_set_id(GSignondAuthSession *session, gint id)
+void
+gsignond_auth_session_notify_process_result (GSignondAuthSession *iface,
+                                             GSignondSessionData *result)
+{
+    g_signal_emit (iface, signals[SIG_PROCESS_RESULT], 0, result);
+}
+
+void
+gsignond_auth_session_notify_process_error (GSignondAuthSession *iface,
+                                            const GError *error)
+{
+    g_signal_emit (iface, signals[SIG_PROCESS_ERROR], 0, error);
+}
+
+void 
+gsignond_auth_session_notify_store (GSignondAuthSession *self, 
+                                    GSignondSessionData *session_data)
+{
+    g_signal_emit (self, signals[SIG_PROCESS_STORE], 0, session_data);
+}
+
+void 
+gsignond_auth_session_notify_user_action_required (GSignondAuthSession *self, 
+                                                   GSignondSignonuiData *ui_data)
 {
-    return gsignond_plugin_proxy_factory_add_plugin(
-        gsignond_get_plugin_proxy_factory(), id, session->priv->proxy);
+    g_signal_emit (self, signals[SIG_PROCESS_USER_ACTION_REQUIRED], 0, ui_data);
+}
+
+void 
+gsignond_auth_session_notify_refreshed (GSignondAuthSession *self, 
+                                        GSignondSignonuiData *ui_data)
+{
+    g_signal_emit (self, signals[SIG_PROCESS_REFRESHED], 0, ui_data);
+}
+
+void 
+gsignond_auth_session_notify_state_changed (GSignondAuthSession *self,
+                                            gint state,
+                                            const gchar *message)
+{
+    g_signal_emit (self, signals[SIG_PROCESS_STATE_CHANGED], 0, state, message);
 }
 
 /**
@@ -455,28 +538,20 @@ gboolean gsignond_auth_session_set_id(GSignondAuthSession *session, gint id)
  * Returns: (transfer full) newly created object 
  */
 GSignondAuthSession * 
-gsignond_auth_session_new (GSignondIdentityInfo *info, const gchar *app_context, const gchar *method, gint timeout)
+gsignond_auth_session_new (GSignondIdentityInfo *info, const gchar *app_context, const gchar *method)
 {
     GSignondPluginProxy* proxy = NULL;
-    guint id;
 
-    id = gsignond_identity_info_get_id (info);
-    
-    if (gsignond_identity_info_get_is_identity_new (info)) {
-        proxy = gsignond_plugin_proxy_new(gsignond_get_config(), method);
-        if (!proxy) return NULL;
-    } else {
-        proxy = gsignond_plugin_proxy_factory_get_plugin(
-            gsignond_get_plugin_proxy_factory(), id, method);
-        if (!proxy) return NULL;
-    }
+    g_return_val_if_fail (method, NULL);
+
+    proxy = gsignond_plugin_proxy_factory_get_plugin(
+    gsignond_get_plugin_proxy_factory(), method);
+    if (!proxy) return NULL;
 
     GSignondAuthSession *auth_session =
         g_object_new (GSIGNOND_TYPE_AUTH_SESSION,
                       "method", method,
-                      "app-context", app_context,
-                      "timeout", timeout, 
-                      NULL);
+                      "app-context", app_context, NULL);
     auth_session->priv->proxy = proxy;
     auth_session->priv->identity_info = g_hash_table_ref ((GHashTable *)info);
 
index ecbbaa8..3953a08 100644 (file)
@@ -29,7 +29,9 @@
 #include <glib-object.h>
 
 #include <gsignond/gsignond-identity-info.h>
-#include "gsignond-disposable.h"
+#include <gsignond/gsignond-signonui-data.h>
+#include <gsignond/gsignond-session-data.h>
+#include <gsignond/gsignond-access-control-manager.h>
 
 G_BEGIN_DECLS
 
@@ -55,7 +57,7 @@ typedef struct _GSignondAuthSessionPrivate GSignondAuthSessionPrivate;
 
 struct _GSignondAuthSession
 {
-    GSignondDisposable parent;
+    GObject parent;
 
     /* private */
     GSignondAuthSessionPrivate *priv;
@@ -63,24 +65,80 @@ struct _GSignondAuthSession
 
 struct _GSignondAuthSessionClass
 {
-    GSignondDisposableClass parent_class;
+    GObjectClass parent_class;
 };
 
 GType gsignond_auth_session_get_type (void);
 
+gchar **
+gsignond_auth_session_query_available_mechanisms (GSignondAuthSession *self,
+                                                  const gchar **wanted_mechanisms,
+                                                  const GSignondSecurityContext *ctx,
+                                                  GError **error);
+
+gboolean
+gsignond_auth_session_process (GSignondAuthSession *self,
+                               GSignondSessionData *session_data,
+                               const gchar *mechanism,
+                               const GSignondSecurityContext *ctx,
+                               GError **error);
+gboolean
+gsignond_auth_session_cancel (GSignondAuthSession *self,
+                              const GSignondSecurityContext *ctx,
+                              GError **error);
+
+void
+gsignond_auth_session_abort_process (GSignondAuthSession *self);
+
+void 
+gsignond_auth_session_user_action_finished (GSignondAuthSession *self,
+                                            GSignondSignonuiData *ui_data);
+
+void
+gsignond_auth_session_refresh (GSignondAuthSession *self, 
+                               GSignondSignonuiData *ui_data);
+
 const gchar *
 gsignond_auth_session_get_method (GSignondAuthSession *session);
 
 const gchar *
-gsignond_auth_session_get_object_path (GSignondAuthSession *session);
+gsignond_auth_session_get_context (GSignondAuthSession *session);
+
+GSignondAccessControlManager *
+gsignond_auth_session_get_acm (GSignondAuthSession *session);
+
+gboolean 
+gsignond_auth_session_set_id(GSignondAuthSession *session, gint id);
+
+void
+gsignond_auth_session_notify_process_result (GSignondAuthSession *iface,
+                                             GSignondSessionData *result);
+
+void
+gsignond_auth_session_notify_process_error (GSignondAuthSession *iface,
+                                            const GError *error);
+
+void 
+gsignond_auth_session_notify_store (GSignondAuthSession *self, 
+                                    GSignondSessionData *session_data);
+
+void 
+gsignond_auth_session_notify_user_action_required (GSignondAuthSession *self, 
+                                                   GSignondSignonuiData *ui_data);
+
+void 
+gsignond_auth_session_notify_refreshed (GSignondAuthSession *self, 
+                                        GSignondSignonuiData *ui_data);
 
-gboolean gsignond_auth_session_set_id(GSignondAuthSession *session, gint id);
+void 
+gsignond_auth_session_notify_state_changed (GSignondAuthSession *self, 
+                                            gint state,
+                                            const gchar *message);
 
 GSignondAuthSession * 
 gsignond_auth_session_new (GSignondIdentityInfo *info,
                            const gchar *app_context,
-                           const gchar *method,
-                           gint timeout);
+                           const gchar *method);
 
 G_END_DECLS
 
index 55245b1..3d49a2f 100644 (file)
  * 02110-1301 USA
  */
 
+#include "gsignond-daemon.h"
+
+#include <gmodule.h>
+
 #include "gsignond/gsignond-config.h"
 #include "gsignond/gsignond-log.h"
 #include "gsignond/gsignond-error.h"
 #include "gsignond/gsignond-extension-interface.h"
 #include "daemon/gsignond-identity.h"
-#include "daemon/dbus/gsignond-dbus-auth-service-adapter.h"
 #include "daemon/db/gsignond-db-credentials-database.h"
 
-#include "gsignond-auth-service-iface.h"
-#include "gsignond-daemon.h"
-
 struct _GSignondDaemonPrivate
 {
     GSignondConfig      *config;
-    GList               *identities;
+    GHashTable          *identities;
     GModule             *extension_module;
     GSignondExtension   *extension;
     GSignondStorageManager *storage_manager;
     GSignondSecretStorage *secret_storage;
     GSignondDbCredentialsDatabase *db;
     GSignondAccessControlManager *acm;
-    GSignondDbusAuthServiceAdapter *auth_service;
     GSignondPluginProxyFactory *plugin_proxy_factory;
     GSignondSignonuiProxy *ui;
 };
 
-static void gsignond_daemon_auth_service_iface_init (gpointer g_iface,
-                                                     gpointer iface_data);
-
-G_DEFINE_TYPE_EXTENDED (GSignondDaemon, gsignond_daemon, GSIGNOND_TYPE_DISPOSABLE, 0,
-                        G_IMPLEMENT_INTERFACE (GSIGNOND_TYPE_AUTH_SERVICE_IFACE, 
-                                               gsignond_daemon_auth_service_iface_init));
+G_DEFINE_TYPE (GSignondDaemon, gsignond_daemon, G_TYPE_OBJECT)
 
 
 #define GSIGNOND_DAEMON_PRIV(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_DAEMON, GSignondDaemonPrivate)
@@ -69,11 +63,9 @@ _constructor (GType type,
     /*
      * Signleton daemon
      */
-
     if (!self) {
         self = G_OBJECT_CLASS (gsignond_daemon_parent_class)->constructor (
                   type, n_construct_params, construct_params);
-        
         g_object_add_weak_pointer (self, (gpointer) &self);
     }
     else {
@@ -83,20 +75,6 @@ _constructor (GType type,
     return self;
 }
 
-static void
-_get_property (GObject *object, guint property_id, GValue *value,
-               GParamSpec *pspec)
-{
-    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
-_set_property (GObject *object, guint property_id, const GValue *value,
-               GParamSpec *pspec)
-{
-    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
 void
 _free_identity (gpointer data, gpointer user_data)
 {
@@ -122,11 +100,6 @@ _dispose (GObject *object)
         self->priv->config = NULL;
     }
 
-    if (self->priv->auth_service) {
-        g_object_unref (self->priv->auth_service);
-        self->priv->auth_service = NULL;
-    }
-
     if (self->priv->db) {
  
         if (!gsignond_db_credentials_database_close_secret_storage (
@@ -159,7 +132,8 @@ _dispose (GObject *object)
     }
 
     if (self->priv->identities) {
-        g_list_foreach (self->priv->identities, _free_identity, NULL);
+        g_hash_table_unref (self->priv->identities);
+        self->priv->identities = NULL;
     }
 
     if (self->priv->ui) {
@@ -173,13 +147,6 @@ _dispose (GObject *object)
 static void
 _finalize (GObject *object)
 {
-    GSignondDaemon *self = GSIGNOND_DAEMON(object);
-
-    if (self->priv->identities) {
-        g_list_free (self->priv->identities);
-        self->priv->identities = NULL;
-    }
-
     G_OBJECT_CLASS (gsignond_daemon_parent_class)->finalize (object);
 }
 
@@ -303,7 +270,8 @@ gsignond_daemon_init (GSignondDaemon *self)
     self->priv = GSIGNOND_DAEMON_PRIV(self);
 
     self->priv->config = gsignond_config_new ();
-    self->priv->identities = NULL;
+    self->priv->identities = g_hash_table_new_full (
+            g_direct_hash, g_direct_equal, NULL, NULL);
     self->priv->plugin_proxy_factory = gsignond_plugin_proxy_factory_new(
         self->priv->config);
     
@@ -315,10 +283,6 @@ gsignond_daemon_init (GSignondDaemon *self)
     if (!_open_database (self))
         ERR("gisgnond_daemon_open_database() failed");
 
-    self->priv->auth_service =
-        gsignond_dbus_auth_service_adapter_new (
-                                            GSIGNOND_AUTH_SERVICE_IFACE (self));
-
     self->priv->ui = gsignond_signonui_proxy_new ();
 }
 
@@ -330,58 +294,71 @@ gsignond_daemon_class_init (GSignondDaemonClass *klass)
     g_type_class_add_private (object_class, sizeof (GSignondDaemonPrivate));
 
     object_class->constructor = _constructor;
-    object_class->get_property = _get_property;
-    object_class->set_property = _set_property;
     object_class->dispose = _dispose;
     object_class->finalize = _finalize;
 }
 
+static gboolean
+_compare_identity_by_pointer (gpointer key, gpointer value, gpointer dead_object)
+{
+    return value == dead_object;
+}
+
 static void
 _on_identity_disposed (gpointer data, GObject *object)
 {
     GSignondDaemon *daemon = GSIGNOND_DAEMON (data);
 
     DBG ("daemon %p identity %p disposed", daemon, object);
-    daemon->priv->identities = g_list_remove (daemon->priv->identities, object);
-
-    if (g_list_length (daemon->priv->identities) == 0) {
-        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (daemon));
-        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (daemon), TRUE);
-    }
+    g_hash_table_foreach_remove (daemon->priv->identities,
+                _compare_identity_by_pointer, object);
 }
 
-static void
-_catch_identity (GSignondDaemon *daemon, GSignondIdentity *identity)
+guint32
+gsignond_daemon_store_identity (GSignondDaemon *daemon, GSignondIdentity *identity)
 {
-    daemon->priv->identities = g_list_append (daemon->priv->identities, 
-                                              (gpointer) identity);
+    g_return_val_if_fail (daemon && GSIGNOND_IS_DAEMON (daemon), 0);
+    g_return_val_if_fail (identity && GSIGNOND_IS_IDENTITY(identity), 0);
 
-    g_object_weak_ref (G_OBJECT (identity), _on_identity_disposed, daemon); 
+    GSignondIdentityInfo *info = NULL;
+    guint32 id = 0;
+    gboolean was_new_identity = FALSE;
+    
+    info = gsignond_identity_get_identity_info(identity);
+    if (!info) return 0;
+    
+    was_new_identity = (gsignond_identity_info_get_id (info) == 0);
 
-    /* keep alive till this identity object gets disposed */
-    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
+    id = gsignond_db_credentials_database_update_identity (daemon->priv->db, info);
 
-    g_signal_connect_swapped (identity, "store", 
-        G_CALLBACK (gsignond_db_credentials_database_update_identity), daemon->priv->db);
-    g_signal_connect_swapped (identity, "remove", 
-        G_CALLBACK (gsignond_db_credentials_database_remove_identity), daemon->priv->db);
-    
+    if (was_new_identity && id) {
+        g_hash_table_insert (daemon->priv->identities, GINT_TO_POINTER(id), identity);
+        g_object_weak_ref (G_OBJECT (identity), _on_identity_disposed, daemon);
+    }
+
+    return id;
 }
 
-static const gchar * 
-_register_new_identity (GSignondAuthServiceIface *self,
-                        const GSignondSecurityContext *ctx,
-                        GError **error) 
+gboolean
+gsignond_daemon_remove_identity (GSignondDaemon *daemon, guint32 id)
 {
-    if (!self || !GSIGNOND_IS_DAEMON (self)) {
-        WARN ("assertion failed (self && GSIGNOND_IS_DAEMON (self)) failed");
+    g_return_val_if_fail (daemon && GSIGNOND_IS_DAEMON (daemon), FALSE);
+
+    return gsignond_db_credentials_database_remove_identity(daemon->priv->db, id);
+}
+
+GSignondIdentity *
+gsignond_daemon_register_new_identity (GSignondDaemon *daemon,
+                                       const GSignondSecurityContext *ctx,
+                                       GError **error) 
+{
+    if (!daemon || !GSIGNOND_IS_DAEMON (daemon)) {
+        WARN ("assertion failed (daemon && GSIGNOND_IS_DAEMON (daemon)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return NULL;
     }
 
-    GSignondDaemon *daemon = GSIGNOND_DAEMON (self);
     const gchar *app_context = ctx ? gsignond_security_context_get_application_context (ctx) : "";
-    gint timeout = gsignond_config_get_integer (daemon->priv->config, GSIGNOND_CONFIG_DBUS_IDENTITY_TIMEOUT);
     GSignondIdentityInfo *info = gsignond_identity_info_new ();
     GSignondIdentity *identity = NULL;
     GSignondSecurityContext *owner = NULL;
@@ -397,49 +374,42 @@ _register_new_identity (GSignondAuthServiceIface *self,
     gsignond_security_context_free (owner);
     g_list_free (acl);
 
-    identity = gsignond_identity_new (self, info, app_context, timeout);
+    DBG("register_new_identity: cache size : %d", g_hash_table_size(daemon->priv->identities));
+    identity = gsignond_identity_new (daemon, info, app_context);
     if (identity == NULL) {
         gsignond_dictionary_unref (info);
         ERR("Unable to register new identity");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_INTERNAL_SERVER, "Internal server error");
         return NULL;
     }
-
-    _catch_identity (daemon, identity);
-
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
-
-    return gsignond_identity_get_object_path (identity);
+    DBG(" --- registered new identity : %p", identity);
+    return identity;
 }
 
-static const gchar *
-_get_identity (GSignondAuthServiceIface *iface,
-               const guint32 id,
-               const GSignondSecurityContext *ctx,
-               GVariant **identity_data,
-               GError **error)
+GSignondIdentity *
+gsignond_daemon_get_identity (GSignondDaemon *daemon,
+                              const guint32 id,
+                              const GSignondSecurityContext *ctx,
+                              GError **error)
 {
-    if (!iface || !GSIGNOND_IS_DAEMON (iface)) {
-        WARN ("assertion (iface && GSIGNOND_IS_DAEMON (iface)) failed");
+    if (!daemon || !GSIGNOND_IS_DAEMON (daemon)) {
+        WARN ("assertion (daemon && GSIGNOND_IS_DAEMON (daemon)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return NULL;
     }
-    if (id == 0 || id == -1) {
+    if (id <= 0) {
         WARN ("client provided invalid identity id");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_IDENTITY_ERR, "Invalid identity id");
         return NULL;
     }
 
-    GSignondDaemon *self = GSIGNOND_DAEMON (iface);
-    GList *liter;
     GSignondIdentity *identity = NULL;
     GSignondIdentityInfo *identity_info = NULL;
     const gchar *app_context = ctx ? gsignond_security_context_get_application_context (ctx) : "" ;
-    gint timeout = 0;
 
 #define VALIDATE_IDENTITY_READ_ACCESS(info, ctx, ret) \
 { \
-    GSignondAccessControlManager *acm = self->priv->acm; \
+    GSignondAccessControlManager *acm = daemon->priv->acm; \
     GSignondSecurityContextList *acl = gsignond_identity_info_get_access_control_list (info); \
     gboolean valid = gsignond_access_control_manager_peer_is_allowed_to_use_identity (acm, ctx, acl); \
     gsignond_security_context_list_free (acl); \
@@ -452,26 +422,22 @@ _get_identity (GSignondAuthServiceIface *iface,
         return ret; \
     } \
 }
+    DBG("Get identity for id '%d'\n cache size : %d", id, g_hash_table_size(daemon->priv->identities));
+    identity = GSIGNOND_IDENTITY(g_hash_table_lookup (daemon->priv->identities, GINT_TO_POINTER(id)));
+    if (identity) {
+        identity_info = gsignond_identity_get_identity_info (identity);
+        VALIDATE_IDENTITY_READ_ACCESS (identity_info, ctx, NULL);
+        DBG ("using cased Identity '%p' for id %d", identity, id);
 
-    if (identity_data) *identity_data = NULL;
-
-    for (liter = self->priv->identities;
-         liter != NULL;
-         liter = g_list_next(liter)) {
-        if (gsignond_identity_get_id (liter->data) == id)
-        {
-            identity_info = gsignond_identity_get_identity_info (liter->data);
-            gsignond_identity_info_ref (identity_info);
-            DBG ("use cached IdentityInfo=(%u, %p)", id, identity_info);
-            break;
-        }
+        return GSIGNOND_IDENTITY (g_object_ref (identity));
     }
-    if (!identity_info)
-        identity_info = gsignond_db_credentials_database_load_identity (
-                            self->priv->db, id, TRUE);
+
+    /* identity not found in cache, so try to load form db */
+    identity_info = gsignond_db_credentials_database_load_identity (
+                            daemon->priv->db, id, TRUE);
     if (!identity_info) {
         if (error)  {
-            const GError *err = gsignond_db_credentials_database_get_last_error (self->priv->db);
+            const GError *err = gsignond_db_credentials_database_get_last_error (daemon->priv->db);
             *error = err ? g_error_copy (err) : gsignond_get_gerror_for_id (
                         GSIGNOND_ERROR_IDENTITY_NOT_FOUND, "identity not found with id '%d'", id);
         }
@@ -480,51 +446,45 @@ _get_identity (GSignondAuthServiceIface *iface,
 
     VALIDATE_IDENTITY_READ_ACCESS (identity_info, ctx, NULL);
 
-    timeout = gsignond_config_get_integer (self->priv->config, GSIGNOND_CONFIG_DBUS_IDENTITY_TIMEOUT);
-    identity = gsignond_identity_new (iface, identity_info, app_context, timeout);
+    identity = gsignond_identity_new (daemon, identity_info, app_context);
     if (!identity) {
         gsignond_identity_info_unref (identity_info);
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_INTERNAL_SERVER, "Internal server error");
         return NULL;
     }
 
-    if (identity_data) *identity_data = gsignond_dictionary_to_variant (identity_info);
-
-    _catch_identity (self, identity);
+    g_hash_table_insert (daemon->priv->identities, GINT_TO_POINTER(id), identity);
+    g_object_weak_ref (G_OBJECT (identity), _on_identity_disposed, daemon);
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+    DBG("created new identity '%p' for id '%d'", identity, id);
 
-    return gsignond_identity_get_object_path (identity);
+    return identity;
 
 #undef VALIDATE_IDENTITY_READ_ACCESS
 }
 
-static const gchar ** 
-_query_methods (GSignondAuthServiceIface *self, GError **error)
+const gchar ** 
+gsignond_daemon_query_methods (GSignondDaemon *daemon, GError **error)
 {
-    if (!self || !GSIGNOND_IS_DAEMON (self)) {
-        WARN ("assertion (self && GSIGNOND_IS_DAEMON(self)) failed");
+    if (!daemon || !GSIGNOND_IS_DAEMON (daemon)) {
+        WARN ("assertion (daemon && GSIGNOND_IS_DAEMON(daemon)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return NULL;
     }
 
-    GSignondDaemon *daemon = GSIGNOND_DAEMON (self);
-
     return gsignond_plugin_proxy_factory_get_plugin_types (
             daemon->priv->plugin_proxy_factory);
 }
 
-static const gchar ** 
-_query_mechanisms (GSignondAuthServiceIface *self, const gchar *method, GError **error) 
+const gchar ** 
+gsignond_daemon_query_mechanisms (GSignondDaemon *daemon, const gchar *method, GError **error) 
 {
-    if (!self || !GSIGNOND_IS_DAEMON (self)) {
-        WARN ("assertion (self && GSIGNOND_IS_DAEMON(self)) failed");
+    if (!daemon || !GSIGNOND_IS_DAEMON (daemon)) {
+        WARN ("assertion (daemon && GSIGNOND_IS_DAEMON(daemon)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return NULL;
     }
 
-    GSignondDaemon *daemon = GSIGNOND_DAEMON (self);
-
     const gchar **mechanisms = gsignond_plugin_proxy_factory_get_plugin_mechanisms (
             daemon->priv->plugin_proxy_factory, method);
 
@@ -536,8 +496,8 @@ _query_mechanisms (GSignondAuthServiceIface *self, const gchar *method, GError *
     return mechanisms;
 }
 
-static GVariant * 
-_query_identities (GSignondAuthServiceIface *self, const GVariant *filter, GError **error)
+GList *
+gsignond_daemon_query_identities (GSignondDaemon *self, GVariant *filter, GError **error)
 {
     if (!self || !GSIGNOND_IS_DAEMON (self)) {
         WARN ("assertion (self && GSIGNOND_IS_DAEMON(self)) failed");
@@ -546,13 +506,13 @@ _query_identities (GSignondAuthServiceIface *self, const GVariant *filter, GErro
     }
     (void)filter;
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
+    if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Not supported");
 
     return NULL;
 }
 
-static gboolean 
-_clear (GSignondAuthServiceIface *self, GError **error)
+gboolean 
+gsignond_daemon_clear (GSignondDaemon *self, GError **error)
 {
     if (!self || !GSIGNOND_IS_DAEMON (self)) {
         WARN ("assertion (self && GSIGNOND_IS_DAEMON(self)) failed");
@@ -560,38 +520,9 @@ _clear (GSignondAuthServiceIface *self, GError **error)
         return FALSE;
     }
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (self));
-
     return FALSE;
 }
 
-static GSignondAccessControlManager *
-_get_acm (GSignondAuthServiceIface *iface)
-{
-    GSignondDaemon *self = GSIGNOND_DAEMON (iface);
-
-    g_return_val_if_fail (self != NULL, NULL);
-
-    return self->priv->acm;
-}
-
-static void
-gsignond_daemon_auth_service_iface_init (gpointer g_iface, gpointer iface_data)
-{
-    GSignondAuthServiceIfaceInterface *auth_service_iface =
-        (GSignondAuthServiceIfaceInterface *) g_iface;
-
-    (void) iface_data;
-
-    auth_service_iface->register_new_identity = _register_new_identity;
-    auth_service_iface->get_identity = _get_identity;
-    auth_service_iface->query_identities = _query_identities;
-    auth_service_iface->query_methods = _query_methods;
-    auth_service_iface->query_mechanisms = _query_mechanisms;
-    auth_service_iface->clear = _clear;
-    auth_service_iface->get_acm = _get_acm;
-}
-
 /**
  * gsignond_daemon_new:
  *
@@ -600,24 +531,25 @@ gsignond_daemon_auth_service_iface_init (gpointer g_iface, gpointer iface_data)
 GSignondDaemon *
 gsignond_daemon_new ()
 {
-    GSignondDaemon *self = GSIGNOND_DAEMON(g_object_new (GSIGNOND_TYPE_DAEMON, NULL));
-    guint timeout = gsignond_config_get_integer (self->priv->config, GSIGNOND_CONFIG_DBUS_DAEMON_TIMEOUT);
-    if (timeout) {
-        gsignond_disposable_set_timeout (GSIGNOND_DISPOSABLE (self), timeout);
-    }
+    return  GSIGNOND_DAEMON(g_object_new (GSIGNOND_TYPE_DAEMON, NULL));
+}
 
-    return self;
+guint
+gsignond_daemon_get_timeout (GSignondDaemon *self)
+{
+    return gsignond_config_get_integer (self->priv->config,
+        GSIGNOND_CONFIG_DBUS_DAEMON_TIMEOUT);
 }
 
 guint
-gsignond_daemon_identity_timeout (GSignondDaemon *self)
+gsignond_daemon_get_identity_timeout (GSignondDaemon *self)
 {
     return gsignond_config_get_integer (self->priv->config,
         GSIGNOND_CONFIG_DBUS_IDENTITY_TIMEOUT);
 }
 
 guint
-gsignond_daemon_auth_session_timeout (GSignondDaemon *self)
+gsignond_daemon_get_auth_session_timeout (GSignondDaemon *self)
 {
     return gsignond_config_get_integer (self->priv->config,
         GSIGNOND_CONFIG_DBUS_AUTH_SESSION_TIMEOUT);
index 47c97dd..ee01c11 100644 (file)
@@ -29,9 +29,9 @@
 #include <glib-object.h>
 
 #include <gsignond/gsignond-access-control-manager.h>
-#include "gsignond-disposable.h"
-#include "plugins/gsignond-plugin-proxy-factory.h"
+#include "gsignond-identity.h"
 #include "gsignond-signonui-proxy.h"
+#include "plugins/gsignond-plugin-proxy-factory.h"
 
 G_BEGIN_DECLS
 
@@ -48,7 +48,7 @@ typedef struct _GSignondDaemonPrivate GSignondDaemonPrivate;
 
 struct _GSignondDaemon
 {
-    GSignondDisposable parent;
+    GObject parent;
 
     /* priv */
     GSignondDaemonPrivate *priv;
@@ -56,25 +56,63 @@ struct _GSignondDaemon
 
 struct _GSignondDaemonClass
 {
-    GSignondDisposableClass parent_class;
+    GObjectClass parent_class;
 };
 
 GType gsignond_daemon_get_type (void) G_GNUC_CONST;
 
 GSignondDaemon * gsignond_daemon_new ();
 
-guint gsignond_daemon_identity_timeout (GSignondDaemon *self);
+GSignondIdentity *
+gsignond_daemon_register_new_identity (GSignondDaemon *daemon,
+                                       const GSignondSecurityContext *ctx,
+                                       GError **error) ;
+
+GSignondIdentity *
+gsignond_daemon_get_identity (GSignondDaemon *daemon,
+                              const guint32 id,
+                              const GSignondSecurityContext *ctx,
+                              GError **error);
+
+const gchar ** 
+gsignond_daemon_query_methods (GSignondDaemon *daemon, GError **error);
+
+const gchar ** 
+gsignond_daemon_query_mechanisms (GSignondDaemon *daemon,
+                                  const gchar *method,
+                                  GError **error);
+
+GList *
+gsignond_daemon_query_identities (GSignondDaemon *daemon,
+                                  GVariant *filter,
+                                  GError **error);
+
+gboolean 
+gsignond_daemon_clear (GSignondDaemon *daemon, GError **error);
+
+guint32
+gsignond_daemon_store_identity (GSignondDaemon *daemon, GSignondIdentity *identity);
+
+gboolean
+gsignond_daemon_remove_identity (GSignondDaemon *daemon, guint32 id);
+
+guint
+gsignond_daemon_get_timeout (GSignondDaemon *self) G_GNUC_CONST;
+
+guint
+gsignond_daemon_get_identity_timeout (GSignondDaemon *self) G_GNUC_CONST;
 
-guint gsignond_daemon_auth_session_timeout (GSignondDaemon *self);
+guint
+gsignond_daemon_get_auth_session_timeout (GSignondDaemon *self) G_GNUC_CONST;
 
 GSignondAccessControlManager *
-gsignond_daemon_get_access_control_manager (GSignondDaemon *self);
+gsignond_daemon_get_access_control_manager (GSignondDaemon *self) G_GNUC_CONST;
 
 GSignondPluginProxyFactory *
-gsignond_daemon_get_plugin_proxy_factory (GSignondDaemon *self);
+gsignond_daemon_get_plugin_proxy_factory (GSignondDaemon *self) G_GNUC_CONST;
 
 GSignondConfig *
-gsignond_daemon_get_config (GSignondDaemon *self);
+gsignond_daemon_get_config (GSignondDaemon *self) G_GNUC_CONST;
 
 gboolean
 gsignond_daemon_show_dialog (GSignondDaemon *self,
diff --git a/src/daemon/gsignond-identity-iface.c b/src/daemon/gsignond-identity-iface.c
deleted file mode 100644 (file)
index e531144..0000000
+++ /dev/null
@@ -1,483 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include "gsignond-identity-iface.h"
-#include "gsignond-identity-enum-types.h"
-
-enum 
-{
-    SIG_USER_VERIFIED,
-    SIG_SECRET_VERIFIED,
-    SIG_CREDENTIALS_UPDATED,
-    SIG_INFO_UPDATED,
-    SIG_MAX
-};
-
-static guint signals[SIG_MAX];
-
-G_DEFINE_INTERFACE (GSignondIdentityIface, gsignond_identity_iface, G_TYPE_OBJECT)
-
-static gboolean
-_dummy_request_credentials_update (GSignondIdentityIface *self,
-                                   const gchar *message,
-                                   const GSignondSecurityContext *ctx,
-                                   GError **error)
-{
-    (void) self;
-    (void) message;
-    (void) ctx;
-    (void) error;
-
-    return FALSE;
-}
-
-static GVariant *
-_dummy_get_info (GSignondIdentityIface *self, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) ctx;
-    (void) error;
-
-    return 0;
-}
-
-static const gchar *
-_dummy_get_auth_session (GSignondIdentityIface *self, const gchar *method, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) method;
-    (void) ctx;
-    (void) error;
-
-    return NULL;
-}
-
-static gboolean
-_dummy_verify_user (GSignondIdentityIface *self, GVariant *params, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) params;
-    (void) ctx;
-    (void) error;
-
-    return FALSE;
-}
-
-static gboolean
-_dummy_verify_secret (GSignondIdentityIface *self, const gchar *secret, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) secret;
-    (void) ctx;
-    (void) error;
-
-    return FALSE;
-}
-
-static gboolean
-_dummy_remove (GSignondIdentityIface *self, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) ctx;
-    (void) error;
-
-    return FALSE;
-}
-
-static gboolean
-_dummy_sign_out (GSignondIdentityIface *self, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) ctx;
-    (void) error;
-
-    return FALSE;
-}
-
-static guint32
-_dummy_store (GSignondIdentityIface *self, const GVariant *info, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) info;
-    (void) ctx;
-    (void) error;
-
-    return 0;
-}
-
-static gint32
-_dummy_add_reference (GSignondIdentityIface *self, const gchar *reference, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) reference;
-    (void) ctx;
-    (void) error;
-
-    return 0;
-}
-
-static gint32
-_dummy_remove_reference (GSignondIdentityIface *self, const gchar *reference, const GSignondSecurityContext *ctx, GError **error)
-{
-    (void) self;
-    (void) reference;
-    (void) ctx;
-    (void) error;
-
-    return 0;
-}
-
-static void
-gsignond_identity_iface_default_init (GSignondIdentityIfaceInterface *self)
-{
-    self->request_credentials_update = _dummy_request_credentials_update;
-    self->get_info = _dummy_get_info;
-    self->get_auth_session = _dummy_get_auth_session;
-    self->verify_user = _dummy_verify_user;
-    self->verify_secret = _dummy_verify_secret;
-    self->remove = _dummy_remove;
-    self->sign_out = _dummy_sign_out;
-    self->store = _dummy_store;
-    self->add_reference = _dummy_add_reference;
-    self->remove_reference = _dummy_remove_reference;
-
-    signals[SIG_USER_VERIFIED] =  g_signal_new ("user-verified",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            2,
-            G_TYPE_BOOLEAN,
-            G_TYPE_ERROR);
-
-    signals[SIG_SECRET_VERIFIED] = g_signal_new ("secret-verified",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            2,
-            G_TYPE_BOOLEAN,
-            G_TYPE_ERROR);
-
-    signals[SIG_CREDENTIALS_UPDATED] = g_signal_new ("credentials-updated",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            2,
-            G_TYPE_UINT,
-            G_TYPE_ERROR);
-
-    signals[SIG_INFO_UPDATED] = g_signal_new ("info-updated",
-            G_TYPE_FROM_INTERFACE (self),
-            G_SIGNAL_RUN_LAST,
-            0,
-            NULL,
-            NULL,
-            NULL,
-            G_TYPE_NONE,
-            1,
-            GSIGNOND_TYPE_IDENTITY_CHANGE_TYPE);
-}
-
-/**
- * gsignond_identity_iface_request_credentials_update:
- * @self: instance of #GSignondIdentityIface
- * @message: message to be shown to user
- * @ctx: security context of the caller
- * @error: return location for error or @NULL.
- *
- * Requests user to update username and password for this identity @identity.
- * Once the process is done, emits "credentials-updated" signal
- *
- * Returns: @TRUE on success, @FALSE otherwise
- */
-gboolean
-gsignond_identity_iface_request_credentials_update (GSignondIdentityIface *self,
-                                                    const gchar *message,
-                                                    const GSignondSecurityContext *ctx,
-                                                    GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->
-        request_credentials_update (self, message, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_get_info:
- * @self: instance of #GSignondIdentityIface
- * @message: message to be shown to user
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Retrieves the identity information for this identity, in the form of key, value pairs.
- *
- * Returns: (transfers full): identity info
- */
-GVariant *
-gsignond_identity_iface_get_info (GSignondIdentityIface *self, const GSignondSecurityContext *ctx, GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->get_info (self, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_get_info:
- * @self: instance of #GSignondIdentityIface
- * @method: authentication method to use
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Creates new authentication process on #identity using #method, and returns
- * dbus object path for newly created object.
- *
- * Returns: (transfers none): object path if success, NULL otherwise
- */
-const gchar *
-gsignond_identity_iface_get_auth_session (GSignondIdentityIface *self,
-                                          const gchar *method,
-                                          const GSignondSecurityContext *ctx,
-                                          GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->
-        get_auth_session (self, method, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_verify_user:
- * @self: instance of #GSignondIdentityIface
- * @params: authentication parameters to be verified
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Initiates user verification process.
- *
- * Returns: @TRUE if success, @FALSE otherwise
- */
-gboolean
-gsignond_identity_iface_verify_user (GSignondIdentityIface *self,
-                                     GVariant *params,
-                                     const GSignondSecurityContext *ctx,
-                                     GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->
-        verify_user (self, params, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_verify_secret:
- * @self: instance of #GSignondIdentityIface
- * @secret: secret to be verified
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Initiates secret verification process.
- *
- * Returns: @TRUE if success, @FALSE otherwise
- */
-gboolean
-gsignond_identity_iface_verify_secret (GSignondIdentityIface *self,
-                                       const gchar *secret,
-                                       const GSignondSecurityContext *ctx,
-                                       GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->
-        verify_secret (self, secret, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_remove:
- * @self: instance of #GSignondIdentityIface
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Removes identity information from underlined database
- *
- * Returns: @TRUE if success, @FALSE otherwise
- */
-gboolean
-gsignond_identity_iface_remove (GSignondIdentityIface *self,
-                                const GSignondSecurityContext *ctx,
-                                GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->remove (self, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_sign_out:
- * @self: instance of #GSignondIdentityIface
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * TODO: add description
- *
- * Returns: @TRUE if success, @FALSE otherwise
- */
-gboolean
-gsignond_identity_iface_sign_out (GSignondIdentityIface *self,
-                                  const GSignondSecurityContext *ctx,
-                                  GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->sign_out (self, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_store:
- * @self: instance of #GSignondIdentityIface
- * @info: identity information to store
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Saves given identity information #info to database
- *
- * Returns: identity id
- */
-guint32
-gsignond_identity_iface_store (GSignondIdentityIface *self,
-                               const GVariant *info,
-                               const GSignondSecurityContext *ctx,
-                               GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->store (self, info, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_add_reference:
- * @self: instance of #GSignondIdentityIface
- * @reference: reference name
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Adds a named reference #reference to identity
- *
- * Returns: identity id
- */
-gint32
-gsignond_identity_iface_add_reference (GSignondIdentityIface *self,
-                                       const gchar *reference,
-                                       const GSignondSecurityContext *ctx,
-                                       GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->
-        add_reference (self, reference, ctx, error);
-}
-
-/**
- * gsignond_identity_iface_remove_reference:
- * @self: instance of #GSignondIdentityIface
- * @reference: reference name
- * @ctx: security context of the caller
- * @error: Return location for error or @NULL.
- *
- * Removes a named reference #reference to identity
- *
- * Returns: identity id
- */
-gint32
-gsignond_identity_iface_remove_reference (GSignondIdentityIface *self,
-                                          const gchar *reference,
-                                          const GSignondSecurityContext *ctx,
-                                          GError **error)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->
-        add_reference (self, reference, ctx, error);
-}
-
-GSignondAccessControlManager *
-gsignond_identity_iface_get_acm (GSignondIdentityIface *self)
-{
-    return GSIGNOND_IDENTITY_IFACE_GET_INTERFACE (self)->
-        get_acm (self);
-}
-
-/**
- * gsignond_identity_iface_notify_user_verified:
- * @self: instance of #GSignondIdentityIface
- * @result: verification result
- * @error: instance of #GError, error if any, that was occured in user verification process, otherwise NULL
- *
- * Emits "user-verified" signal
- */
-void
-gsignond_identity_iface_notify_user_verified (GSignondIdentityIface *self,
-                                              gboolean result,
-                                              const GError *error)
-{
-    g_signal_emit (self, signals[SIG_USER_VERIFIED], 0, result, error);
-}
-
-/**
- * gsignond_identity_iface_notify_secret_verified:
- * @self: instance of #GSignondIdentityIface
- * @result: verfication result
- * @error: instance of #GError, error if any, that was occured in secret verification process, otherwise NULL
- *
- * Emits "secret-verified" signal
- */
-void
-gsignond_identity_iface_notify_secret_verified (GSignondIdentityIface *self,
-                                                gboolean result,
-                                                const GError *error)
-{
-    g_signal_emit (self, signals[SIG_SECRET_VERIFIED], 0, result, error);
-}
-
-/**
- * gsignond_identity_iface_notify_credentials_updated:
- * @self: instance of #GSignondIdentityIface
- * @identity_id: id of the identity for which credentials updated
- * @error: instance of #GError, error if any, that was occured in updating credentials, otherwise NULL
- *
- * Emits "credentials-updated" signal along with identity id.
- */
-void
-gsignond_identity_iface_notify_credentials_updated (GSignondIdentityIface *self,
-                                                    guint32 identity_id,
-                                                    const GError *error)
-{
-    g_signal_emit (self, signals[SIG_CREDENTIALS_UPDATED], 0 , identity_id, error);
-}
-
-/**
- * gsignond_identity_iface_notify_info_updated:
- * @self: instance of #GSignondIdentityIface
- * @ichange: type of chagne 
- *
- * Emits "info-updated" signal along with type of change. This should be called by implementes
- * when identity info updated.
- */
-void
-gsignond_identity_iface_notify_info_updated (GSignondIdentityIface *self,
-                                             GSignondIdentityChangeType change)
-{
-    g_signal_emit (self, signals[SIG_INFO_UPDATED], 0, change);
-}
diff --git a/src/daemon/gsignond-identity-iface.h b/src/daemon/gsignond-identity-iface.h
deleted file mode 100644 (file)
index 57a0b5c..0000000
+++ /dev/null
@@ -1,276 +0,0 @@
-/* vi: set et sw=4 ts=4 cino=t0,(0: */
-/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of gsignond
- *
- * Copyright (C) 2012 Intel Corporation.
- *
- * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifndef __GSIGNOND_IDENTITY_IFACE_H_
-#define __GSIGNOND_IDENTITY_IFACE_H_
-
-#include <glib.h>
-#include <glib-object.h>
-#include <gsignond/gsignond-access-control-manager.h>
-#include <gsignond/gsignond-security-context.h>
-
-G_BEGIN_DECLS
-
-#define GSIGNOND_TYPE_IDENTITY_IFACE          (gsignond_identity_iface_get_type ())
-#define GSIGNOND_IDENTITY_IFACE(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSIGNOND_TYPE_IDENTITY_IFACE, GSignondIdentityIface))
-#define GSIGNOND_IS_IDENTITY_IFACE(obj)       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSIGNOND_TYPE_IDENTITY_IFACE))
-#define GSIGNOND_IDENTITY_IFACE_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GSIGNOND_TYPE_IDENTITY_IFACE, GSignondIdentityIfaceInterface))
-
-typedef struct _GSignondIdentityIface GSignondIdentityIface; /* dummy */
-typedef struct _GSignondIdentityIfaceInterface GSignondIdentityIfaceInterface;
-
-typedef enum {
-    GSIGNOND_IDENTITY_DATA_UPDATED = 0,
-    GSIGNOND_IDENTITY_REMOVED,
-    GSIGNOND_IDENTITY_SIGNED_OUT
-} IdentityChangeType;
-typedef IdentityChangeType GSignondIdentityChangeType;
-
-struct _GSignondIdentityIfaceInterface {
-    GTypeInterface parent;
-    
-   /**
-     * request_credentials_update:
-     * @identity: Instance of #GSignondIdentityIface
-     * @message: message to be shown to user
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Requests user to update username and password for this identity @identity.
-     * Once the process is done, emits "credentials-updated" signal
-     *
-     * Returns: @TRUE on success, @FALSE otherwise
-     */
-    gboolean (*request_credentials_update) (GSignondIdentityIface *identity, const gchar *message, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * get_info:
-     * @identity: Instance of #GSignondIdentityIface
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Retrives identity information stroed for this identity.
-     *
-     * Returns: (transfer full)identity information
-     */
-    GVariant *(*get_info) (GSignondIdentityIface *identity, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * get_auth_session:
-     * @identity: Instance of #GSignondIdentityIface
-     * @method: authentication method to use
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Opens an authentication session for #identity using authentication method #method.
-     *
-     * Returns: (transfers none) Dbus object path of the session object
-     */
-    const gchar * (*get_auth_session) (GSignondIdentityIface *identity, const gchar *method, const GSignondSecurityContext *ctx, GError **error);
-    /**
-     * verify_user:
-     * @identity: Instance of #GSignondIdentityIface
-     * @params:
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Starts user verification process. Once the verification process completed
-     * that is informed via #user_verified.
-     *
-     * Returns: @TRUE on success, @FALSE otherwise
-     */
-    gboolean  (*verify_user) (GSignondIdentityIface *identity, GVariant *params, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * verify_secret:
-     * @identity: Instance of #GSignondIdentityIface
-     * @secret: secret to verify
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Starts secret verification process. Once the verification process completed
-     * that is informed via #secret_verified
-     *
-     * Returns: @TRUE on success, @FALSE otherwise
-     */
-    gboolean  (*verify_secret) (GSignondIdentityIface *identity, const gchar *secret, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * remove:
-     * @identity: Instance of #GSignondIdentityIface
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Removes identity from database
-     *
-     * Returns: @TRUE on success, @FALSE otherwise
-     */
-    gboolean  (*remove) (GSignondIdentityIface *identity, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * store:
-     * @identity: Instance of #GSignondIdentityIface
-     * @info: information to be stored
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Stores the given identity information @info to database.
-     *
-     * Returns: id of the identity
-     */
-    guint32   (*store) (GSignondIdentityIface *identity, const GVariant *info, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * sign_out:
-     * @identity: Instance of #GSignondIdentityIface
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Returns: @TRUE on success, @FALSE otherwise.
-     */
-    gboolean  (*sign_out) (GSignondIdentityIface *identity, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * add_reference:
-     * @identity: Instance of #GSignondIdentityIface
-     * @reference: named referece
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Adds a named referece to identity.
-     *
-     * Returns: identity id
-     */
-    gint32    (*add_reference) (GSignondIdentityIface *identity, const gchar *reference, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * remove_reference:
-     * @identity: Instance of #GSignondIdentityIface
-     * @reference: name of the reference to be removed
-     * @ctx: security context of the caller
-     * @error: Return location for error or @NULL.
-     *
-     * Removes named reference @reference form list of references of identity @identity.
-     *
-     * Returns: identity id
-     */
-    gint32    (*remove_reference) (GSignondIdentityIface *identity, const gchar *reference, const GSignondSecurityContext *ctx, GError **error);
-
-    /**
-     * get_acm:
-     * @identity: Instance of #GSignondIdentityIface
-     *
-     * Retrieves pointer to access control manager.
-     *
-     * Returns: (transfer none): 
-     */
-    GSignondAccessControlManager * (*get_acm) (GSignondIdentityIface *identity);
-};
-
-GType gsignond_identity_iface_get_type (void);
-
-gboolean
-gsignond_identity_iface_request_credentials_update (
-                                                    GSignondIdentityIface *self,
-                                                    const gchar *message,
-                                                    const GSignondSecurityContext *ctx,
-                                                    GError **error);
-GVariant * 
-gsignond_identity_iface_get_info (GSignondIdentityIface *self,
-                                  const GSignondSecurityContext *ctx,
-                                  GError **error);
-
-const gchar *
-gsignond_identity_iface_get_auth_session (GSignondIdentityIface *iface,
-                                          const gchar *method,
-                                          const GSignondSecurityContext *ctx,
-                                          GError **error);
-
-gboolean 
-gsignond_identity_iface_verify_user (GSignondIdentityIface *self,
-                                     GVariant *params,
-                                     const GSignondSecurityContext *ctx,
-                                     GError **error);
-
-gboolean 
-gsignond_identity_iface_verify_secret (GSignondIdentityIface *self,
-                                       const gchar *secret,
-                                       const GSignondSecurityContext *ctx,
-                                       GError **error);
-
-gboolean
-gsignond_identity_iface_remove (GSignondIdentityIface *self,
-                                const GSignondSecurityContext *ctx,
-                                GError **error);
-
-gboolean 
-gsignond_identity_iface_sign_out (GSignondIdentityIface *self,
-                                  const GSignondSecurityContext *ctx,
-                                  GError **error);
-
-guint32 
-gsignond_identity_iface_store (GSignondIdentityIface *self,
-                               const GVariant *info,
-                               const GSignondSecurityContext *ctx,
-                               GError **error);
-
-gint32 
-gsignond_identity_iface_add_reference (GSignondIdentityIface *self,
-                                       const gchar *reference,
-                                       const GSignondSecurityContext *ctx,
-                                       GError **error);
-
-gint32 
-gsignond_identity_iface_remove_reference (GSignondIdentityIface *self,
-                                          const gchar *reference,
-                                          const GSignondSecurityContext *ctx,
-                                          GError **error);
-
-GSignondAccessControlManager *
-gsignond_identity_iface_get_acm (GSignondIdentityIface *self);
-
-void 
-gsignond_identity_iface_notify_user_verified (GSignondIdentityIface *identity,
-                                              gboolean res,
-                                              const GError *error);
-
-void
-gsignond_identity_iface_notify_secret_verified (GSignondIdentityIface *identity, 
-                                                gboolean res,
-                                                const GError *error);
-
-void
-gsignond_identity_iface_notify_credentials_updated (GSignondIdentityIface *identity,
-                                                    guint32 identity_id,
-                                                    const GError *error);
-
-void
-gsignond_identity_iface_notify_info_updated (GSignondIdentityIface *self,
-                                             GSignondIdentityChangeType change);
-
-G_END_DECLS
-
-#endif /* __GSIGNOND_IDENTITY_IFACE_H_ */
index fb1138f..4a551d7 100644 (file)
  */
 
 #include "gsignond-identity.h"
-
 #include <string.h>
 
-#include "gsignond-daemon.h"
-#include "gsignond-identity-iface.h"
-#include "gsignond-auth-session.h"
 #include "gsignond/gsignond-log.h"
 #include "gsignond/gsignond-error.h"
+#include "gsignond-daemon.h"
+#include "gsignond-identity-enum-types.h"
+#include "gsignond-auth-session.h"
 #include "gsignond/gsignond-config-dbus.h"
 #include "gsignond/gsignond-signonui.h"
-#include "dbus/gsignond-dbus.h"
-#include "dbus/gsignond-dbus-identity-adapter.h"
 #include "plugins/gsignond-plugin-proxy-factory.h"
 
 enum 
@@ -48,13 +45,16 @@ enum
 };
 
 enum {
-    SIG_STORE,
-    SIG_REMOVE,
     SIG_VERIFY_USER,
     SIG_VERIFY_SECRET,
     SIG_ADD_REFERENCE,
     SIG_REMOVE_REFERENCE,
     SIG_SIGNOUT,
+    SIG_USER_VERIFIED,
+    SIG_SECRET_VERIFIED,
+    SIG_CREDENTIALS_UPDATED,
+    SIG_INFO_UPDATED,
     SIG_MAX
 };
 
@@ -64,24 +64,21 @@ static guint signals[SIG_MAX];
 struct _GSignondIdentityPrivate
 {
     GSignondIdentityInfo *info;
-    GSignondAuthServiceIface *owner;
-    GSignondDbusIdentityAdapter *identity_adapter;
-    GList *auth_sessions;
+    gchar *app_context;
+    GSignondDaemon *owner;
+    GHashTable *auth_sessions; // (auth_method,auth_session) table
 };
 
-static void
-gsignond_identity_iface_init (gpointer g_iface, gpointer iface_data);
+G_DEFINE_TYPE (GSignondIdentity, gsignond_identity, G_TYPE_OBJECT);
 
-G_DEFINE_TYPE_EXTENDED (GSignondIdentity, gsignond_identity, GSIGNOND_TYPE_DISPOSABLE, 0,
-                        G_IMPLEMENT_INTERFACE (GSIGNOND_TYPE_IDENTITY_IFACE, 
-                                               gsignond_identity_iface_init));
 
+static void _on_session_close (gpointer data, GObject *session);
 
 #define GSIGNOND_IDENTITY_PRIV(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_IDENTITY, GSignondIdentityPrivate)
 
 #define VALIDATE_IDENTITY_READ_ACCESS(identity, ctx, ret) \
 { \
-    GSignondAccessControlManager *acm = gsignond_auth_service_iface_get_acm (identity->priv->owner); \
+    GSignondAccessControlManager *acm = gsignond_daemon_get_access_control_manager (identity->priv->owner); \
     GSignondSecurityContextList *acl = gsignond_identity_info_get_access_control_list (identity->priv->info); \
     gboolean valid = gsignond_access_control_manager_peer_is_allowed_to_use_identity (acm, ctx, acl); \
     gsignond_security_context_list_free (acl); \
@@ -94,7 +91,7 @@ G_DEFINE_TYPE_EXTENDED (GSignondIdentity, gsignond_identity, GSIGNOND_TYPE_DISPO
 
 #define VALIDATE_IDENTITY_WRITE_ACCESS(identity, ctx, ret) \
 { \
-    GSignondAccessControlManager *acm = gsignond_auth_service_iface_get_acm (identity->priv->owner); \
+    GSignondAccessControlManager *acm = gsignond_daemon_get_access_control_manager (identity->priv->owner); \
     GSignondSecurityContext *owner = gsignond_identity_info_get_owner (identity->priv->info); \
     gboolean valid = gsignond_access_control_manager_peer_is_owner_of_identity (acm, ctx, owner); \
     gsignond_security_context_free (owner); \
@@ -107,7 +104,7 @@ G_DEFINE_TYPE_EXTENDED (GSignondIdentity, gsignond_identity, GSIGNOND_TYPE_DISPO
 
 #define VALIDATE_IDENTITY_WRITE_ACL(identity, ctx, ret) \
 { \
-    GSignondAccessControlManager *acm = gsignond_auth_service_iface_get_acm (identity->priv->owner); \
+    GSignondAccessControlManager *acm = gsignond_daemon_get_access_control_manager (identity->priv->owner); \
     GSignondSecurityContextList *acl = gsignond_identity_info_get_access_control_list (identity->priv->info); \
     gboolean valid = gsignond_access_control_manager_acl_is_valid (acm, ctx, acl); \
     gsignond_security_context_list_free (acl); \
@@ -139,7 +136,7 @@ _get_property (GObject *object, guint property_id, GValue *value,
             g_value_set_boxed (value, self->priv->info);
             break;
         case PROP_APP_CONTEXT:
-            g_object_get_property (G_OBJECT (self->priv->identity_adapter), "app-context", value);
+            g_value_set_string (value, self->priv->app_context);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -159,7 +156,7 @@ _set_property (GObject *object, guint property_id, const GValue *value,
                (GSignondIdentityInfo *)g_value_get_boxed (value);
             break;
         case PROP_APP_CONTEXT:
-            g_object_set_property (G_OBJECT (self->priv->identity_adapter), "app-context", value);
+            self->priv->app_context = g_value_dup_string (value);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -167,12 +164,9 @@ _set_property (GObject *object, guint property_id, const GValue *value,
 }
 
 static void
-_finalize_session (gpointer data, gpointer user_data)
+_release_weak_ref_on_session (gpointer key, gpointer value, gpointer data)
 {
-    (void) user_data;
-
-    DBG("finalize session %p", user_data);
-    g_object_unref (G_OBJECT (data));
+    g_object_weak_unref (G_OBJECT (value), _on_session_close, data);
 }
 
 static void
@@ -180,9 +174,10 @@ _dispose (GObject *object)
 {
     GSignondIdentity *self = GSIGNOND_IDENTITY(object);
 
-    if (self->priv->identity_adapter) {
-        g_object_unref (self->priv->identity_adapter);
-        self->priv->identity_adapter = NULL;
+    if (self->priv->auth_sessions) {
+        g_hash_table_foreach (self->priv->auth_sessions, _release_weak_ref_on_session, self);
+        g_hash_table_unref (self->priv->auth_sessions);
+        self->priv->auth_sessions = NULL;
     }
 
     if (self->priv->owner) {
@@ -196,23 +191,12 @@ _dispose (GObject *object)
         self->priv->info = NULL;
     }
 
-    if (self->priv->auth_sessions) {
-        g_list_foreach (self->priv->auth_sessions, _finalize_session, NULL);
-    }
-
     G_OBJECT_CLASS (gsignond_identity_parent_class)->dispose (object);
 }
 
 static void
 _finalize (GObject *object)
 {
-    GSignondIdentity *self = GSIGNOND_IDENTITY(object);
-
-    if (self->priv->auth_sessions) {
-        g_list_free (self->priv->auth_sessions);
-        self->priv->auth_sessions = NULL;
-    }
-
     G_OBJECT_CLASS (gsignond_identity_parent_class)->finalize (object);
 }
 
@@ -221,9 +205,7 @@ gsignond_identity_init (GSignondIdentity *self)
 {
     self->priv = GSIGNOND_IDENTITY_PRIV(self);
 
-    self->priv->identity_adapter =
-        gsignond_dbus_identity_adapter_new (GSIGNOND_IDENTITY_IFACE (self));
-    self->priv->auth_sessions = NULL;
+    self->priv->auth_sessions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 }
 
 static void
@@ -257,24 +239,6 @@ gsignond_identity_class_init (GSignondIdentityClass *klass)
 
     g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 
-    signals[SIG_REMOVE] = g_signal_new ("remove",
-                  GSIGNOND_TYPE_IDENTITY,
-                  G_SIGNAL_RUN_FIRST| G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                  0,
-                  NULL, NULL,
-                  NULL,
-                  G_TYPE_BOOLEAN,
-                  0,
-                  G_TYPE_NONE);
-    signals[SIG_STORE] = g_signal_new ("store",
-                  GSIGNOND_TYPE_IDENTITY,
-                  G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                  0,
-                  NULL, NULL,
-                  NULL,
-                  G_TYPE_UINT,
-                  1,
-                  GSIGNOND_TYPE_IDENTITY_INFO);
     signals[SIG_ADD_REFERENCE] = g_signal_new ("add-reference",
                   GSIGNOND_TYPE_IDENTITY,
                   G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
@@ -302,18 +266,64 @@ gsignond_identity_class_init (GSignondIdentityClass *klass)
                   G_TYPE_BOOLEAN,
                   0,
                   G_TYPE_NONE);
+    signals[SIG_USER_VERIFIED] =  g_signal_new ("user-verified",
+                GSIGNOND_TYPE_IDENTITY,
+                G_SIGNAL_RUN_LAST,
+                0,
+                NULL,
+                NULL,
+                NULL,
+                G_TYPE_NONE,
+                2,
+                G_TYPE_BOOLEAN,
+                G_TYPE_ERROR);
+
+    signals[SIG_SECRET_VERIFIED] = g_signal_new ("secret-verified",
+                GSIGNOND_TYPE_IDENTITY,
+                G_SIGNAL_RUN_LAST,
+                0,
+                NULL,
+                NULL,
+                NULL,
+                G_TYPE_NONE,
+                2,
+                G_TYPE_BOOLEAN,
+                G_TYPE_ERROR);
+
+    signals[SIG_CREDENTIALS_UPDATED] = g_signal_new ("credentials-updated",
+                GSIGNOND_TYPE_IDENTITY,
+                G_SIGNAL_RUN_LAST,
+                0,
+                NULL,
+                NULL,
+                NULL,
+                G_TYPE_NONE,
+                2,
+                G_TYPE_UINT,
+                G_TYPE_ERROR);
+
+    signals[SIG_INFO_UPDATED] = g_signal_new ("info-updated",
+                GSIGNOND_TYPE_IDENTITY,
+                G_SIGNAL_RUN_LAST,
+                0,
+                NULL,
+                NULL,
+                NULL,
+                G_TYPE_NONE,
+                1,
+                GSIGNOND_TYPE_IDENTITY_CHANGE_TYPE);
+
 }
 
-static GVariant * 
-_get_info (GSignondIdentityIface *iface, const GSignondSecurityContext *ctx, GError **error)
+GVariant * 
+gsignond_identity_get_info (GSignondIdentity *identity, const GSignondSecurityContext *ctx, GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
 
-    GSignondIdentity *identity = GSIGNOND_IDENTITY (iface);
     GSignondIdentityInfo *info = NULL;
     GVariant *vinfo = NULL;
 
@@ -343,15 +353,13 @@ _get_info (GSignondIdentityIface *iface, const GSignondSecurityContext *ctx, GEr
         return NULL;
     }
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
-
     return vinfo;
 }
 
 static void
 _on_dialog_refreshed (GError *error, gpointer user_data)
 {
-    GSignondAuthSessionIface *session = GSIGNOND_AUTH_SESSION_IFACE (user_data);
+    GSignondAuthSession *session = GSIGNOND_AUTH_SESSION (user_data);
 
     if (error) {
         WARN ("Error : %s", error->message);
@@ -366,7 +374,7 @@ _on_dialog_refreshed (GError *error, gpointer user_data)
 }
 
 static void
-_on_refresh_dialog (GSignondAuthSessionIface *session, GSignondSignonuiData *ui_data, gpointer userdata)
+_on_refresh_dialog (GSignondAuthSession *session, GSignondSignonuiData *ui_data, gpointer userdata)
 {
     GSignondIdentity *identity = GSIGNOND_IDENTITY (userdata);
 
@@ -377,27 +385,27 @@ _on_refresh_dialog (GSignondAuthSessionIface *session, GSignondSignonuiData *ui_
 static void
 _on_refresh_requested (GSignondSignonuiData *ui_data, gpointer user_data)
 {
-    GSignondAuthSessionIface *session = GSIGNOND_AUTH_SESSION_IFACE (user_data);
-    gsignond_auth_session_iface_refresh (session, ui_data);
+    GSignondAuthSession *session = GSIGNOND_AUTH_SESSION (user_data);
+    gsignond_auth_session_refresh (session, ui_data);
 }
 
 static void
 _on_user_action_completed (GSignondSignonuiData *reply, GError *error, gpointer user_data)
 {
-    GSignondAuthSessionIface *session = GSIGNOND_AUTH_SESSION_IFACE (user_data);
+    GSignondAuthSession *session = GSIGNOND_AUTH_SESSION (user_data);
     if (error) {
         WARN ("UI-Error: %s", error->message);
         g_error_free (error);
         return;
     }
     if (session) {
-        gsignond_auth_session_iface_user_action_finished (session, reply);
+        gsignond_auth_session_user_action_finished (session, reply);
     }
     else if (reply) gsignond_signonui_data_unref (reply);
 }
 
 static void
-_on_user_action_required (GSignondAuthSessionIface *session, GSignondSignonuiData *ui_data, gpointer userdata)
+_on_user_action_required (GSignondAuthSession *session, GSignondSignonuiData *ui_data, gpointer userdata)
 {
     GSignondIdentity *identity = GSIGNOND_IDENTITY (userdata);
 
@@ -405,35 +413,39 @@ _on_user_action_required (GSignondAuthSessionIface *session, GSignondSignonuiDat
             ui_data, _on_user_action_completed, _on_refresh_requested, session);
 }
 
+static gboolean
+_compare_session_by_pointer (gpointer key, gpointer value, gpointer dead_object)
+{
+    return value == dead_object;
+}
+
 static void
 _on_session_close (gpointer data, GObject *session)
 {
     GSignondIdentity *identity = GSIGNOND_IDENTITY (data);
 
     DBG ("identity %p session %p disposed", identity, session);
-    identity->priv->auth_sessions = g_list_remove (identity->priv->auth_sessions, session);
     
-    if (g_list_length (identity->priv->auth_sessions) == 0) {
-        gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
-        gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (identity), TRUE);
-    }
+    g_hash_table_foreach_remove (identity->priv->auth_sessions,
+            _compare_session_by_pointer, session);   
 }
 
-static const gchar *
-_get_auth_session (GSignondIdentityIface *iface, const gchar *method, const GSignondSecurityContext *ctx, GError **error)
+GSignondAuthSession *
+gsignond_identity_get_auth_session (GSignondIdentity *identity,
+                                    const gchar *method,
+                                    const GSignondSecurityContext *ctx,
+                                    GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
-    GSignondIdentity *identity = GSIGNOND_IDENTITY (iface);
     GSignondAuthSession *session = NULL;
-    const gchar *object_path = NULL;
     GHashTable *supported_methods = NULL;
     gboolean method_available = FALSE;
-    gchar *app_context = NULL;
-    gint timeout = 0;
+
+    VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, NULL);
 
     if (!method) {
         WARN ("assertion (method) failed");
@@ -441,10 +453,16 @@ _get_auth_session (GSignondIdentityIface *iface, const gchar *method, const GSig
                       "authentication method not provided");
         return NULL;
     }
-    DBG ("create auth session for method %s", method);
 
-    if (!gsignond_plugin_proxy_factory_get_plugin_mechanisms (
-                                                              gsignond_get_plugin_proxy_factory (),
+    DBG ("get auth session for method '%s'", method);
+    session = g_hash_table_lookup (identity->priv->auth_sessions, method);
+
+    if (session && GSIGNOND_IS_AUTH_SESSION (session)) {
+        DBG("using cashed auth session '%p' for method '%s'", session, method);
+        return GSIGNOND_AUTH_SESSION(g_object_ref (session));
+    }
+
+    if (!gsignond_plugin_proxy_factory_get_plugin_mechanisms (gsignond_get_plugin_proxy_factory (),
                                                               method)) {
         WARN ("method '%s' doesn't exist", method);
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_METHOD_NOT_KNOWN,
@@ -472,36 +490,25 @@ _get_auth_session (GSignondIdentityIface *iface, const gchar *method, const GSig
         return NULL;
     }
 
-    VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, NULL);
-
-    timeout = gsignond_config_get_integer (gsignond_get_config(), GSIGNOND_CONFIG_DBUS_AUTH_SESSION_TIMEOUT);
-    g_object_get (identity->priv->identity_adapter, "app-context", &app_context, NULL);
     session = gsignond_auth_session_new (identity->priv->info,
-                                         app_context, 
-                                         method,
-                                         timeout);
-    g_free (app_context);
+                                         identity->priv->app_context,
+                                         method);
 
     if (!session) {
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return NULL;
     }
+
     /* Handle 'ui' signanls on session */
     g_signal_connect (session, "process-user-action-required", G_CALLBACK (_on_user_action_required), identity);
     g_signal_connect (session, "process-refreshed", G_CALLBACK (_on_refresh_dialog), identity);
 
-    object_path = gsignond_auth_session_get_object_path (session);
-
-    identity->priv->auth_sessions = g_list_append (identity->priv->auth_sessions, session);
-
+    g_hash_table_insert (identity->priv->auth_sessions, g_strdup (method), session);
     g_object_weak_ref (G_OBJECT (session), _on_session_close, identity);
 
-    /* Keep live till all active sessions closes */
-    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (identity), FALSE);
+    DBG ("session %p creation for method '%s' complete", session, method);
 
-    DBG ("session %p creation for method %s complete", session, method);
-
-    return object_path;
+    return session;
 }
 
 static void
@@ -521,7 +528,7 @@ _on_query_dialog_done (GSignondSignonuiData *reply, GError *error, gpointer user
 
     gboolean res = gsignond_signonui_data_get_query_error (reply, &err_id);
     g_assert (res == TRUE);
-    
+
     if (err_id != SIGNONUI_ERROR_NONE) {
         switch (err_id) {
             case SIGNONUI_ERROR_CANCELED:
@@ -544,35 +551,34 @@ _on_query_dialog_done (GSignondSignonuiData *reply, GError *error, gpointer user
             gsignond_identity_info_set_secret (identity->priv->info, secret) ;
 
             /* Save new secret in db */
-            g_signal_emit (identity, signals[SIG_STORE], 0, identity->priv->info, &id);
+            id = gsignond_daemon_store_identity (identity->priv->owner, identity);
             if (!id) err = gsignond_get_gerror_for_id (GSIGNOND_ERROR_STORE_FAILED, "Failed to store secret");
         }
     }
 
     gsignond_signonui_data_unref (reply);
 
-    gsignond_identity_iface_notify_credentials_updated (GSIGNOND_IDENTITY_IFACE (identity), id, err);
+    g_signal_emit (identity, signals[SIG_CREDENTIALS_UPDATED], 0 , id, err);
 
     if (err) g_error_free (err);
-
-    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (identity), TRUE);
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
 }
 
-static gboolean
-_request_credentials_update (GSignondIdentityIface *iface, const gchar *message, const GSignondSecurityContext *ctx, GError **error)
+gboolean
+gsignond_identity_request_credentials_update (GSignondIdentity *identity,
+                                              const gchar *message,
+                                              const GSignondSecurityContext *ctx,
+                                              GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    GSignondSignonuiData *ui_data = NULL;
+
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
 
-    GSignondIdentity *identity = GSIGNOND_IDENTITY (iface);
-    GSignondSignonuiData *ui_data = NULL;
-
-    if (!(identity && identity->priv->info)) {
-        WARN ("assertion (identity && identity->priv->info) failed");
+    if (!identity->priv->info) {
+        WARN ("assertion (identity->priv->info) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_IDENTITY_ERR, "Identity not found.");
         return FALSE;
     }
@@ -596,8 +602,6 @@ _request_credentials_update (GSignondIdentityIface *iface, const gchar *message,
 
     gsignond_signonui_data_unref (ui_data);
 
-    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (identity), FALSE);
-
     return TRUE;
 }
 
@@ -618,7 +622,7 @@ _on_user_verfied (GSignondSignonuiData *reply, GError *error, gpointer user_data
 
     gboolean query_res = gsignond_signonui_data_get_query_error (reply, &err_id);
     g_assert (query_res == TRUE);
-    
+
     if (err_id != SIGNONUI_ERROR_NONE) {
         switch (err_id) {
             case SIGNONUI_ERROR_CANCELED:
@@ -648,23 +652,22 @@ _on_user_verfied (GSignondSignonuiData *reply, GError *error, gpointer user_data
 
     gsignond_signonui_data_unref (reply);
 
-    gsignond_identity_iface_notify_user_verified (GSIGNOND_IDENTITY_IFACE (identity), res, err);
+    g_signal_emit (identity, signals[SIG_USER_VERIFIED], 0, res, error);
 
     if (err) g_error_free (err);
-
-    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (identity), TRUE);
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
 }
 
-static gboolean 
-_verify_user (GSignondIdentityIface *iface, GVariant *params, const GSignondSecurityContext *ctx, GError **error)
+gboolean 
+gsignond_identity_verify_user (GSignondIdentity *identity,
+                               GVariant *params,
+                               const GSignondSecurityContext *ctx,
+                               GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) == 0) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) == 0) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
-    GSignondIdentity *identity = GSIGNOND_IDENTITY (iface);
     const gchar *passwd = 0;
     GSignondSignonuiData *ui_data = NULL;
 
@@ -694,39 +697,38 @@ _verify_user (GSignondIdentityIface *iface, GVariant *params, const GSignondSecu
 
     gsignond_signonui_data_unref (ui_data);
 
-    gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (identity), FALSE);
-
     return TRUE;
 }
 
-static gboolean
-_verify_secret (GSignondIdentityIface *iface, const gchar *secret, const GSignondSecurityContext *ctx, GError **error)
+gboolean
+gsignond_identity_verify_secret (GSignondIdentity *identity,
+                                 const gchar *secret,
+                                 const GSignondSecurityContext *ctx,
+                                 GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
-    GSignondIdentity *identity = GSIGNOND_IDENTITY(iface);
 
     VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, FALSE);
 
     if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Not supported");
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
-
     return FALSE;
 }
 
-static gboolean 
-_sign_out (GSignondIdentityIface *iface, const GSignondSecurityContext *ctx, GError **error)
+gboolean
+gsignond_identity_sign_out (GSignondIdentity *identity,
+                            const GSignondSecurityContext *ctx,
+                            GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return FALSE;
     }
-    GSignondIdentity *identity = GSIGNOND_IDENTITY(iface);
     gboolean success = FALSE;
 
     VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, FALSE);
@@ -734,33 +736,34 @@ _sign_out (GSignondIdentityIface *iface, const GSignondSecurityContext *ctx, GEr
     /*
      * TODO: close all auth_sessions and emit "identity-signed-out"
      */
-    g_signal_emit (iface,
+    g_signal_emit (identity,
                    signals[SIG_SIGNOUT],
                    0,
                    &success);
 
     if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Not supported");
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
-
     return success;
 }
 
-static guint32
-_store (GSignondIdentityIface *iface, const GVariant *info, const GSignondSecurityContext *ctx, GError **error)
+guint32
+gsignond_identity_store (GSignondIdentity *identity, 
+                         const GVariant *info,
+                         const GSignondSecurityContext *ctx,
+                         GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
-        if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
-        return 0;
-    }
-    GSignondIdentity *identity = GSIGNOND_IDENTITY(iface);
     GSignondIdentityInfo *identity_info = NULL;
     gboolean was_new_identity = FALSE;
     GSignondSecurityContextList *contexts = NULL;
     GSignondSecurityContext *owner = NULL;
     guint32 id;
 
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
+        if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
+        return 0;
+    }
+    
     VALIDATE_IDENTITY_WRITE_ACCESS (identity, ctx, 0);
 
     identity_info = gsignond_dictionary_new_from_variant ((GVariant *)info);
@@ -792,12 +795,7 @@ _store (GSignondIdentityIface *iface, const GVariant *info, const GSignondSecuri
     identity->priv->info = identity_info;
 
     /* Ask daemon to store identity info to db */
-    g_signal_emit (identity,
-                   signals[SIG_STORE],
-                   0,
-                   identity_info, 
-                   &id);
-
+    id = gsignond_daemon_store_identity (identity->priv->owner, identity);
     if (!id) {
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_STORE_FAILED,
                                                         "Failed to store identity");
@@ -806,63 +804,58 @@ _store (GSignondIdentityIface *iface, const GVariant *info, const GSignondSecuri
         if (was_new_identity) 
             _set_id (identity, id);
 
-        gsignond_identity_iface_notify_info_updated (iface, GSIGNOND_IDENTITY_DATA_UPDATED);
+        g_signal_emit (identity, signals[SIG_INFO_UPDATED], 0, GSIGNOND_IDENTITY_DATA_UPDATED);
     }
  
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
-
     return id;
 }
 
-static gboolean
-_remove (GSignondIdentityIface *iface, const GSignondSecurityContext *ctx, GError **error)
+gboolean
+gsignond_identity_remove (GSignondIdentity *identity, 
+                          const GSignondSecurityContext *ctx,
+                          GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return 0;
     }
-    GSignondIdentity *identity = GSIGNOND_IDENTITY(iface);
     gboolean is_removed = FALSE;
     
     VALIDATE_IDENTITY_WRITE_ACCESS (identity, ctx, FALSE);
 
-    g_signal_emit (identity,
-                   signals[SIG_REMOVE],
-                   0,
-                   &is_removed);
+    is_removed = gsignond_daemon_remove_identity (identity->priv->owner, 
+                    gsignond_identity_info_get_id (identity->priv->info));
 
     if (is_removed)
-        gsignond_identity_iface_notify_info_updated (iface, GSIGNOND_IDENTITY_REMOVED);
+        g_signal_emit (identity, signals[SIG_INFO_UPDATED], 0, GSIGNOND_IDENTITY_REMOVED);
     else if (error)
         *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_REMOVE_FAILED, "failed to remove identity");
 
-    gsignond_disposable_delete_later (GSIGNOND_DISPOSABLE (identity));
-
     return is_removed;
 }
 
-static gint32
-_add_reference (GSignondIdentityIface *iface, const gchar *reference, const GSignondSecurityContext *ctx, GError **error)
+gint32
+gsignond_identity_add_reference (GSignondIdentity *identity,
+                                 const gchar *reference,
+                                 const GSignondSecurityContext *ctx,
+                                 GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return 0;
     }
-    GSignondIdentity *identity = GSIGNOND_IDENTITY(iface);
     gint32 res = 0;
     
     VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, 0);
 
-    g_signal_emit (iface,
+    g_signal_emit (identity,
                    signals[SIG_ADD_REFERENCE],
                    0,
                    reference,
                    &res);
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
-
     if (res == 0) {
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
     }
@@ -870,28 +863,28 @@ _add_reference (GSignondIdentityIface *iface, const gchar *reference, const GSig
     return res;
 }
 
-static gint32
-_remove_reference (GSignondIdentityIface *iface, const gchar *reference, const GSignondSecurityContext *ctx, GError **error)
+gint32
+gsignond_identity_remove_reference (GSignondIdentity *identity,
+                                    const gchar *reference,
+                                    const GSignondSecurityContext *ctx,
+                                    GError **error)
 {
-    if (!(iface && GSIGNOND_IS_IDENTITY (iface))) {
-        WARN ("assertion (iface && GSIGNOND_IS_IDENTITY(iface)) failed");
+    if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
+        WARN ("assertion (identity && GSIGNOND_IS_IDENTITY(identity)) failed");
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_UNKNOWN, "Unknown error");
         return 0;
     }
 
-    GSignondIdentity *identity = GSIGNOND_IDENTITY(iface);
     gint32 res = 0;
 
     VALIDATE_IDENTITY_READ_ACCESS (identity, ctx, 0);
 
-    g_signal_emit (iface,
+    g_signal_emit (identity,
             signals[SIG_REMOVE_REFERENCE],
             0,
             reference,
             &res);
 
-    gsignond_disposable_set_keep_in_use (GSIGNOND_DISPOSABLE (identity));
-
     if (res == 0) {
         if (error) *error = gsignond_get_gerror_for_id (GSIGNOND_ERROR_REFERENCE_NOT_FOUND,
                                                         "reference '%s' not found", reference);
@@ -899,35 +892,28 @@ _remove_reference (GSignondIdentityIface *iface, const gchar *reference, const G
     return res;
 }
 
-static GSignondAccessControlManager *
-_get_acm (GSignondIdentityIface *iface)
+GSignondAccessControlManager *
+gsignond_identity_get_acm (GSignondIdentity *identity)
 {
-    GSignondIdentity *identity = GSIGNOND_IDENTITY (iface);
-
-    g_return_val_if_fail (identity, NULL);
+    g_return_val_if_fail (identity && GSIGNOND_IS_IDENTITY(identity), NULL);
 
-    return gsignond_auth_service_iface_get_acm (identity->priv->owner);
+    return gsignond_daemon_get_access_control_manager (identity->priv->owner);
 }
 
-static void
-gsignond_identity_iface_init (gpointer g_iface, gpointer iface_data)
+const gchar *
+gsignond_identity_get_app_context (GSignondIdentity *identity)
 {
-    GSignondIdentityIfaceInterface *identity_iface =
-        (GSignondIdentityIfaceInterface *) g_iface;
+    g_return_val_if_fail (identity && GSIGNOND_IS_IDENTITY(identity), NULL);
 
-    (void)iface_data;
+    return identity->priv->app_context;
+}
 
-    identity_iface->request_credentials_update = _request_credentials_update;
-    identity_iface->get_info = _get_info;
-    identity_iface->get_auth_session = _get_auth_session;
-    identity_iface->verify_user = _verify_user;
-    identity_iface->verify_secret = _verify_secret;
-    identity_iface->remove = _remove;
-    identity_iface->sign_out = _sign_out;
-    identity_iface->store = _store;
-    identity_iface->add_reference = _add_reference;
-    identity_iface->remove_reference = _remove_reference;
-    identity_iface->get_acm = _get_acm;
+guint
+gsignond_identity_get_auth_session_timeout (GSignondIdentity *identity)
+{
+    g_return_val_if_fail (identity && GSIGNOND_IS_IDENTITY(identity), 0);
+
+    return gsignond_daemon_get_auth_session_timeout (identity->priv->owner);
 }
 
 /**
@@ -964,20 +950,6 @@ gsignond_identity_get_identity_info (GSignondIdentity *identity)
 }
 
 /**
- * gsignond_identity_get_object_path:
- * @identity: instance of #GSignondIdentity
- * 
- * Retrieves the dbus object path of the identity.
- *
- * Returns[transfer null]: Dbus object path used by this identity.
- */
-const gchar *
-gsignond_identity_get_object_path (GSignondIdentity *identity)
-{
-    return gsignond_dbus_identity_adapter_get_object_path (identity->priv->identity_adapter);
-}
-
-/**
  * gsignond_identity_new:
  * @owner: Owner of this object, instance of #GSignondAuthServiceIface
  * @info (transfer full): Identity info, instance of #GSignondIdentityInfo
@@ -987,16 +959,14 @@ gsignond_identity_get_object_path (GSignondIdentity *identity)
  *
  * Returns[transfer full]: new instance of #GSignondIdentity
  */
-GSignondIdentity * gsignond_identity_new (GSignondAuthServiceIface *owner,
+GSignondIdentity * gsignond_identity_new (GSignondDaemon *owner,
                                           GSignondIdentityInfo *info,
-                                          const gchar *app_context,
-                                          gint timeout)
+                                          const gchar *app_context)
 {
     GSignondIdentity *identity =
         GSIGNOND_IDENTITY(g_object_new (GSIGNOND_TYPE_IDENTITY,
                                         "info", info,
                                         "app-context", app_context,
-                                        "timeout", timeout,
                                         NULL));
 
     identity->priv->owner = g_object_ref (owner);
index 2b37b44..01885fd 100644 (file)
@@ -30,9 +30,7 @@
 #include <glib-object.h>
 
 #include <gsignond/gsignond-identity-info.h>
-
-#include "gsignond-auth-service-iface.h"
-#include "gsignond-disposable.h"
+#include <gsignond/gsignond-access-control-manager.h>
 
 G_BEGIN_DECLS
 
@@ -47,9 +45,19 @@ typedef struct _GSignondIdentity GSignondIdentity;
 typedef struct _GSignondIdentityClass GSignondIdentityClass;
 typedef struct _GSignondIdentityPrivate GSignondIdentityPrivate;
 
+typedef struct _GSignondDaemon GSignondDaemon;
+typedef struct _GSignondAuthSession GSignondAuthSession;
+
+typedef enum {
+    GSIGNOND_IDENTITY_DATA_UPDATED = 0,
+    GSIGNOND_IDENTITY_REMOVED,
+    GSIGNOND_IDENTITY_SIGNED_OUT
+} IdentityChangeType;
+typedef IdentityChangeType GSignondIdentityChangeType;
+
 struct _GSignondIdentity
 {
-    GSignondDisposable parent;
+    GObject parent;
 
     /* priv */
     GSignondIdentityPrivate *priv;
@@ -57,17 +65,79 @@ struct _GSignondIdentity
 
 struct _GSignondIdentityClass
 {
-    GSignondDisposableClass parent_class;
+    GObjectClass parent_class;
 };
 
 GType
 gsignond_identity_get_type (void) G_GNUC_CONST;
 
 GSignondIdentity *
-gsignond_identity_new (GSignondAuthServiceIface *owner,
+gsignond_identity_new (GSignondDaemon *owner,
                        GSignondIdentityInfo *info,
-                       const gchar *app_context,
-                       gint timeout);
+                       const gchar *app_context);
+
+GVariant * 
+gsignond_identity_get_info (GSignondIdentity *identity,
+                            const GSignondSecurityContext *ctx,
+                            GError **error);
+
+
+GSignondAuthSession *
+gsignond_identity_get_auth_session (GSignondIdentity *identity,
+                                    const gchar *method,
+                                    const GSignondSecurityContext *ctx,
+                                    GError **error);
+
+gboolean
+gsignond_identity_request_credentials_update (GSignondIdentity *identity,
+                                              const gchar *message,
+                                              const GSignondSecurityContext *ctx,
+                                              GError **error);
+
+gboolean 
+gsignond_identity_verify_user (GSignondIdentity *identity,
+                               GVariant *params,
+                               const GSignondSecurityContext *ctx,
+                               GError **error);
+
+gboolean
+gsignond_identity_verify_secret (GSignondIdentity *identity,
+                                 const gchar *secret,
+                                 const GSignondSecurityContext *ctx,
+                                 GError **error);
+
+guint32
+gsignond_identity_store (GSignondIdentity *identity, 
+                         const GVariant *info,
+                         const GSignondSecurityContext *ctx,
+                         GError **error);
+gboolean
+gsignond_identity_remove (GSignondIdentity *identity, 
+                          const GSignondSecurityContext *ctx,
+                          GError **error);
+
+gboolean
+gsignond_identity_sign_out (GSignondIdentity *identity,
+                            const GSignondSecurityContext *ctx,
+                            GError **error);
+
+gint32
+gsignond_identity_add_reference (GSignondIdentity *identity,
+                                 const gchar *reference,
+                                 const GSignondSecurityContext *ctx,
+                                 GError **error);
+
+gint32
+gsignond_identity_remove_reference (GSignondIdentity *identity,
+                                    const gchar *reference,
+                                    const GSignondSecurityContext *ctx,
+                                    GError **error);
+
+guint
+gsignond_identity_get_auth_session_timeout (GSignondIdentity *identity);
+
+GSignondAccessControlManager *
+gsignond_identity_get_acm (GSignondIdentity *identity);
 
 guint32
 gsignond_identity_get_id (GSignondIdentity *identity);
@@ -76,7 +146,7 @@ GSignondIdentityInfo *
 gsignond_identity_get_identity_info (GSignondIdentity *identity);
 
 const gchar *
-gsignond_identity_get_object_path (GSignondIdentity *identity);
+gsignond_identity_get_app_context (GSignondIdentity *identity);
 
 G_END_DECLS
 
index a5b42ee..a530966 100644 (file)
@@ -23,6 +23,7 @@
  * 02110-1301 USA
  */
 
+#include <config.h>
 #include <errno.h>
 #include <signal.h>
 #include <string.h>
 #include <gio/gio.h>
 
 #include "gsignond/gsignond-log.h"
-#include "daemon/gsignond-daemon.h"
 #include "daemon/dbus/gsignond-dbus.h"
+#include "daemon/dbus/gsignond-dbus-server.h"
 
-static GSignondDaemon *_daemon = NULL;
+static GSignondDbusServer *_server = NULL;
 static guint           _sig_source_id[3];
 
+static void
+_on_server_closed (gpointer data, GObject *server)
+{
+    _server = NULL;
+    if (data) g_main_loop_quit ((GMainLoop *)data);
+}
+
 static gboolean
 _handle_quit_signal (gpointer user_data)
 {
@@ -53,14 +61,16 @@ _handle_quit_signal (gpointer user_data)
 static gboolean
 _handle_reload_signal (gpointer user_data)
 {
-    GSignondDaemon **daemon = (GSignondDaemon **) user_data;
+    GMainLoop *ml = (GMainLoop *) user_data;
 
     DBG ("Received reload signal");
-    g_return_val_if_fail (daemon != NULL, FALSE);
-    if (*daemon) {
-        g_object_unref (*daemon);
+    g_return_val_if_fail (ml != NULL, FALSE);
+    if (_server) {
+        g_object_weak_unref (G_OBJECT(_server), _on_server_closed, ml);
+        g_object_unref (_server);
         DBG ("Restarting daemon ....");
-        *daemon = gsignond_daemon_new ();
+        _server = gsignond_dbus_server_new ();
+        g_object_weak_ref (G_OBJECT(_server), _on_server_closed, ml);
     }
 
     return TRUE;
@@ -75,7 +85,7 @@ _install_sighandlers (GMainLoop *main_loop)
     source = g_unix_signal_source_new (SIGHUP);
     g_source_set_callback (source,
                            _handle_reload_signal,
-                           &_daemon,
+                           main_loop,
                            NULL);
     _sig_source_id[0] = g_source_attach (source, ctx);
     source = g_unix_signal_source_new (SIGTERM);
@@ -92,40 +102,11 @@ _install_sighandlers (GMainLoop *main_loop)
     _sig_source_id[2] = g_source_attach (source, ctx);
 }
 
-static void
-_on_bus_acquired (GDBusConnection *connection,
-                  const gchar     *name,
-                  gpointer         user_data)
-{
-    INFO ("Connected to the session bus");
-    if (connection != NULL) 
-        _daemon = gsignond_daemon_new ();
-}
-
-static void
-_on_name_lost (GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-    GMainLoop *ml = (GMainLoop *) user_data;
-    INFO ("Lost (or failed to acquire) the name '%s' on the session message bus", name);
-    if (ml) g_main_loop_quit (ml);
-}
-
-static void
-_on_name_acquired (GDBusConnection *connection,
-                   const gchar     *name,
-                   gpointer         user_data)
-{
-    INFO ("Acquired the name %s on the session message bus", name);
-}
-
 int main (int argc, char **argv)
 {
     GError *error = NULL;
     GMainLoop *main_loop = NULL;
     GOptionContext *opt_context = NULL;
-    guint name_owner_id = 0;
     GOptionEntry opt_entries[] = {
         {NULL }
     };
@@ -141,24 +122,23 @@ int main (int argc, char **argv)
     }
 
     main_loop = g_main_loop_new (NULL, FALSE);
-    _install_sighandlers(main_loop);
-
-    name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
-            GSIGNOND_SERVICE, // "com.google.code.AccountsSSO.SingleSignOn",
-            G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
-            G_BUS_NAME_OWNER_FLAGS_REPLACE,
-            _on_bus_acquired,
-            _on_name_acquired,
-            _on_name_lost,
-            main_loop, NULL);
 
+    _server = gsignond_dbus_server_new ();
+    if (!_server) {
+        g_option_context_free (opt_context);
+        return -1;
+    }
+    g_object_weak_ref (G_OBJECT (_server), _on_server_closed, main_loop);
+    _install_sighandlers(main_loop);
+#ifdef USE_P2P
+    INFO ("server started at : %s", gsignond_dbus_server_get_address (_server));
+#endif
     INFO ("Entering main event loop");
 
     g_main_loop_run (main_loop);
 
-    g_bus_unown_name (name_owner_id);
-
-    if (_daemon) g_object_unref (G_OBJECT (_daemon));
+    if(_server) g_object_unref (_server);
     if (main_loop) g_main_loop_unref (main_loop);
 
     return 0;
index 654fdbb..fe2e37c 100644 (file)
@@ -245,7 +245,6 @@ gsignond_plugin_proxy_factory_new(GSignondConfig *config)
 
 GSignondPluginProxy*
 gsignond_plugin_proxy_factory_get_plugin(GSignondPluginProxyFactory* factory,
-                                         guint32 identity_id,
                                          const gchar* plugin_type)
 {
     g_return_val_if_fail (factory && GSIGNOND_IS_PLUGIN_PROXY_FACTORY(factory), NULL);
@@ -253,55 +252,39 @@ gsignond_plugin_proxy_factory_get_plugin(GSignondPluginProxyFactory* factory,
 
     GSignondPluginProxy* proxy = NULL;
 
-    if (identity_id == -1) {
-        DBG("invalid identity id");
-        return NULL;
-    }
-    if (!identity_id) {
-        proxy = gsignond_plugin_proxy_new(factory->config, plugin_type);
-        DBG("get plugin for new identity %s -> %p", plugin_type, proxy);
-        return proxy;
-    }
-
-    gchar* key = g_strdup_printf("%d %s", identity_id, plugin_type);
-    proxy = g_hash_table_lookup(factory->plugins, key);
+    proxy = g_hash_table_lookup(factory->plugins, plugin_type);
     if (proxy != NULL) {
-        DBG("get existing plugin %s -> %p", key, proxy);
-        g_free(key);
+        DBG("get existing plugin %s -> %p", plugin_type, proxy);
         g_object_ref(proxy);
         return proxy;
     }
     proxy = gsignond_plugin_proxy_new(factory->config, plugin_type);
     if (proxy == NULL) {
-        g_free(key);
         return NULL;
     }
-    g_hash_table_insert(factory->plugins, key, proxy);
-    DBG("get new plugin %s -> %p", key, proxy);
+    g_hash_table_insert(factory->plugins, g_strdup (plugin_type), proxy);
+    DBG("get new plugin %s -> %p", plugin_type, proxy);
     g_object_ref(proxy);
     return proxy;
 }
 
 gboolean gsignond_plugin_proxy_factory_add_plugin(
     GSignondPluginProxyFactory* factory,
-    guint32 identity_id,
     GSignondPluginProxy* proxy)
 {
     g_return_val_if_fail (factory && GSIGNOND_IS_PLUGIN_PROXY_FACTORY(factory), FALSE);
     g_return_val_if_fail (proxy && GSIGNOND_IS_PLUGIN_PROXY(proxy), FALSE);
     
-    gchar* plugin_type;
+    gchar* plugin_type = NULL;
     g_object_get (proxy, "type", &plugin_type, NULL);
-    gchar* key = g_strdup_printf("%d %s", identity_id, plugin_type);
-    g_free(plugin_type);
 
-    if (g_hash_table_contains(factory->plugins, key)) {
-        g_free(key);
+    if (g_hash_table_contains(factory->plugins, plugin_type)) {
+        g_free(plugin_type);
         return FALSE;
     }
     g_object_ref(proxy);
-    DBG("add plugin %s -> %p", key, proxy);
-    g_hash_table_insert(factory->plugins, key, proxy);
+    DBG("add plugin %s -> %p", plugin_type, proxy);
+    g_hash_table_insert(factory->plugins, plugin_type, proxy);
 
     return TRUE;
 }
index 9c960d8..bed020c 100644 (file)
@@ -65,12 +65,10 @@ gsignond_plugin_proxy_factory_new(GSignondConfig *config);
 
 GSignondPluginProxy*
 gsignond_plugin_proxy_factory_get_plugin(GSignondPluginProxyFactory* factory,
-                                         guint32 identity_id,
                                          const gchar* plugin_type);
 
 gboolean gsignond_plugin_proxy_factory_add_plugin(
     GSignondPluginProxyFactory* factory,
-    guint32 identity_id,
     GSignondPluginProxy* proxy);
     
 const gchar** 
index c4c64ae..ab668fb 100644 (file)
@@ -27,6 +27,7 @@
 #include <gsignond/gsignond-plugin-loader.h>
 #include <gsignond/gsignond-error.h>
 #include <gsignond/gsignond-log.h>
+#include "../gsignond-auth-session.h"
 
 #define GSIGNOND_PLUGIN_PROXY_PRIV(obj) \
     G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
@@ -50,12 +51,12 @@ struct _GSignondPluginProxyPrivate
     gchar* plugin_type;
     GSignondPlugin* plugin;
     GQueue* session_queue;
-    GSignondAuthSessionIface* active_session;
+    GSignondAuthSession* active_session;
     gboolean expecting_request;
 };
 
 typedef struct {
-    GSignondAuthSessionIface* auth_session;
+    GSignondAuthSession* auth_session;
     GSignondSessionData* session_data;
     gchar* mechanism;
 } GSignondProcessData;
@@ -89,7 +90,7 @@ static void gsignond_plugin_proxy_status_changed_callback(GSignondPlugin* plugin
                                                   gpointer user_data);
 
 static GSignondProcessData* 
-gsignond_process_data_new (GSignondAuthSessionIface* auth_session,
+gsignond_process_data_new (GSignondAuthSession* auth_session,
                            GSignondSessionData *session_data,
                            const gchar* mechanism) 
 {
@@ -343,7 +344,7 @@ gsignond_plugin_proxy_process_queue (GSignondPluginProxy *self)
         priv->expecting_request = FALSE;
         priv->active_session = next_data->auth_session;
         g_object_ref (priv->active_session);
-        gsignond_auth_session_iface_notify_state_changed (
+        gsignond_auth_session_notify_state_changed (
                                             priv->active_session,
                                             GSIGNOND_PLUGIN_STATE_STARTED,
                                             "The request is being processed.");
@@ -355,12 +356,12 @@ gsignond_plugin_proxy_process_queue (GSignondPluginProxy *self)
 }
 
 void gsignond_plugin_proxy_process (GSignondPluginProxy *self, 
-                                    GSignondAuthSessionIface *session,
+                                    GSignondAuthSession *session,
                                     GSignondSessionData *session_data, 
                                     const gchar *mechanism)
 {
     g_assert (GSIGNOND_IS_PLUGIN_PROXY (self));
-    g_assert (GSIGNOND_IS_AUTH_SESSION_IFACE (session));
+    g_assert (GSIGNOND_IS_AUTH_SESSION (session));
 
     GSignondPluginProxyPrivate *priv = self->priv;
 
@@ -375,7 +376,7 @@ void gsignond_plugin_proxy_process (GSignondPluginProxy *self,
                        gsignond_process_data_new (session,
                                                   session_data,
                                                   mechanism));
-    gsignond_auth_session_iface_notify_state_changed (
+    gsignond_auth_session_notify_state_changed (
                                          session,
                                          GSIGNOND_PLUGIN_STATE_PROCESS_PENDING,
                                          "The request has been queued.");
@@ -398,7 +399,7 @@ gsignond_plugin_proxy_compare_process_data (gconstpointer process_data,
 
 static GSignondProcessData*
 gsignond_plugin_proxy_find_by_session_iface (GSignondPluginProxy *self, 
-                                             GSignondAuthSessionIface *session)
+                                             GSignondAuthSession *session)
 {
     g_assert (GSIGNOND_IS_PLUGIN_PROXY (self));
 
@@ -410,10 +411,10 @@ gsignond_plugin_proxy_find_by_session_iface (GSignondPluginProxy *self,
 
 void 
 gsignond_plugin_proxy_cancel (GSignondPluginProxy *self, 
-                              GSignondAuthSessionIface *session)
+                              GSignondAuthSession *session)
 {
     g_assert (GSIGNOND_IS_PLUGIN_PROXY (self));
-    g_assert (GSIGNOND_IS_AUTH_SESSION_IFACE (session));
+    g_assert (GSIGNOND_IS_AUTH_SESSION (session));
 
     GSignondPluginProxyPrivate *priv = self->priv;
 
@@ -430,7 +431,7 @@ gsignond_plugin_proxy_cancel (GSignondPluginProxy *self,
             GError* error = g_error_new (GSIGNOND_ERROR, 
                                          GSIGNOND_ERROR_WRONG_STATE,
                                          "Canceling an unknown session");
-            gsignond_auth_session_iface_notify_process_error (session, error);
+            gsignond_auth_session_notify_process_error (session, error);
             g_error_free (error);
             return;
         }
@@ -481,9 +482,9 @@ gsignond_plugin_proxy_response_final_callback (GSignondPlugin *plugin,
         return;
     }
     // This avoids problems if cancel() is called from AuthSession handler
-    GSignondAuthSessionIface* active_session = priv->active_session;
+    GSignondAuthSession* active_session = priv->active_session;
     priv->active_session = NULL;
-    gsignond_auth_session_iface_notify_process_result (active_session, result);
+    gsignond_auth_session_notify_process_result (active_session, result);
     g_object_unref (active_session);
     gsignond_plugin_proxy_process_queue (self);
 }
@@ -502,7 +503,7 @@ gsignond_plugin_proxy_response_callback(GSignondPlugin *plugin,
         return;
     }
     priv->expecting_request = TRUE;
-    gsignond_auth_session_iface_notify_process_result (priv->active_session,
+    gsignond_auth_session_notify_process_result (priv->active_session,
                                                        result);
 }
 
@@ -519,7 +520,7 @@ gsignond_plugin_proxy_store_callback (GSignondPlugin *plugin,
             in plugin proxy", priv->plugin_type);
         return;
     }
-    gsignond_auth_session_iface_notify_store (priv->active_session, result);
+    gsignond_auth_session_notify_store (priv->active_session, result);
 }
 
 static void
@@ -535,7 +536,7 @@ gsignond_plugin_proxy_refreshed_callback (GSignondPlugin *plugin,
             in plugin proxy", priv->plugin_type);
         return;
     }
-    gsignond_auth_session_iface_notify_refreshed (priv->active_session, ui_result);
+    gsignond_auth_session_notify_refreshed (priv->active_session, ui_result);
 }
 
 static void
@@ -552,7 +553,7 @@ gsignond_plugin_proxy_user_action_required_callback (
             in plugin proxy", priv->plugin_type);
         return;
     }
-    gsignond_auth_session_iface_notify_user_action_required(
+    gsignond_auth_session_notify_user_action_required(
         priv->active_session, ui_request);
 }
 
@@ -570,9 +571,9 @@ gsignond_plugin_proxy_error_callback (GSignondPlugin* plugin,
         return;
     }
     // This avoids problems if cancel() is called from AuthSession handler
-    GSignondAuthSessionIface *active_session = priv->active_session;
+    GSignondAuthSession *active_session = priv->active_session;
     priv->active_session = NULL;
-    gsignond_auth_session_iface_notify_process_error (active_session, error);
+    gsignond_auth_session_notify_process_error (active_session, error);
     g_object_unref (active_session);
     gsignond_plugin_proxy_process_queue (self);
 }
@@ -592,7 +593,7 @@ gsignond_plugin_proxy_status_changed_callback (GSignondPlugin *plugin,
             message);
         return;
     }
-    gsignond_auth_session_iface_notify_state_changed (priv->active_session,
+    gsignond_auth_session_notify_state_changed (priv->active_session,
                                                       (gint) state, message);
 }
 
index 3a37b6e..6e39ffd 100644 (file)
@@ -29,7 +29,6 @@
 #include <glib-object.h>
 #include <gsignond/gsignond-plugin-interface.h>
 #include <gsignond/gsignond-config.h>
-#include "../gsignond-auth-session-iface.h"
 
 #define GSIGNOND_TYPE_PLUGIN_PROXY             (gsignond_plugin_proxy_get_type ())
 #define GSIGNOND_PLUGIN_PROXY(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSIGNOND_TYPE_PLUGIN_PROXY, GSignondPluginProxy))
@@ -42,6 +41,7 @@
 typedef struct _GSignondPluginProxy        GSignondPluginProxy;
 typedef struct _GSignondPluginProxyClass   GSignondPluginProxyClass;
 typedef struct _GSignondPluginProxyPrivate GSignondPluginProxyPrivate;
+typedef struct _GSignondAuthSession        GSignondAuthSession;
 
 struct _GSignondPluginProxy
 {
@@ -64,9 +64,9 @@ gsignond_plugin_proxy_new(GSignondConfig *config, const gchar* plugin_type);
 
 void 
 gsignond_plugin_proxy_cancel (GSignondPluginProxy *self, 
-                        GSignondAuthSessionIface* session);
+                        GSignondAuthSession* session);
 void gsignond_plugin_proxy_process (GSignondPluginProxy *self, 
-                              GSignondAuthSessionIface* session,
+                              GSignondAuthSession* session,
                               GSignondSessionData *session_data, 
                               const gchar *mechanism);
 void gsignond_plugin_proxy_user_action_finished (GSignondPluginProxy *self,