summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValery Febvre <vfebvre at easter-eggs.com>2004-07-29 21:58:18 +0000
committerValery Febvre <vfebvre at easter-eggs.com>2004-07-29 21:58:18 +0000
commitd774ddaccdb9b3148630981b98bbe697e90d3979 (patch)
tree78d8f3286319a4d5fa284e7f8efd373ea913e5c7
parentf4082214af8244800f9f64b029d0c03dc1d2ad39 (diff)
downloadlasso-d774ddaccdb9b3148630981b98bbe697e90d3979.tar.gz
lasso-d774ddaccdb9b3148630981b98bbe697e90d3979.tar.xz
lasso-d774ddaccdb9b3148630981b98bbe697e90d3979.zip
Renamed LassoIdentity class into LassoFederation and
LassoUser class into LassoIdentity lasso/protocols/federation.c replace lasso/protocols/identity.c lasso/environs/identity.c replace lasso/environs/user.c
-rw-r--r--lasso/Attic/protocols/Makefile.am4
-rw-r--r--lasso/Attic/protocols/federation.c281
-rw-r--r--lasso/Attic/protocols/federation.h101
-rw-r--r--lasso/id-ff/Makefile.am8
-rw-r--r--lasso/id-ff/identity.c424
-rw-r--r--lasso/id-ff/identity.h90
6 files changed, 902 insertions, 6 deletions
diff --git a/lasso/Attic/protocols/Makefile.am b/lasso/Attic/protocols/Makefile.am
index 5820548a..96aaef78 100644
--- a/lasso/Attic/protocols/Makefile.am
+++ b/lasso/Attic/protocols/Makefile.am
@@ -22,8 +22,8 @@ liblasso_protocols_la_SOURCES = \
authn_request_envelope.c \
authn_response.c \
authn_response_envelope.c \
+ federation.c \
federation_termination_notification.c \
- identity.c \
logout_request.c \
logout_response.c \
name_identifier_mapping_request.c \
@@ -41,8 +41,8 @@ liblassoinclude_HEADERS = \
authn_request_envelope.h \
authn_response.h \
authn_response_envelope.h \
+ federation.h \
federation_termination_notification.h \
- identity.h \
logout_request.h \
logout_response.h \
name_identifier_mapping_request.h \
diff --git a/lasso/Attic/protocols/federation.c b/lasso/Attic/protocols/federation.c
new file mode 100644
index 00000000..5900eae7
--- /dev/null
+++ b/lasso/Attic/protocols/federation.c
@@ -0,0 +1,281 @@
+/* $Id$
+ *
+ * Lasso - A free implementation of the Liberty Alliance specifications.
+ *
+ * Copyright (C) 2004 Entr'ouvert
+ * http://lasso.entrouvert.org
+ *
+ * Authors: Nicolas Clapies <nclapies@entrouvert.com>
+ * Valery Febvre <vfebvre@easter-eggs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <lasso/protocols/federation.h>
+
+struct _LassoFederationPrivate
+{
+ gboolean dispose_has_run;
+};
+
+static GObjectClass *parent_class = NULL;
+
+/*****************************************************************************/
+/* public methods */
+/*****************************************************************************/
+
+LassoFederation*
+lasso_federation_copy(LassoFederation *federation)
+{
+ LassoFederation *copy;
+
+ g_return_val_if_fail(LASSO_IS_FEDERATION(federation), NULL);
+
+ copy = LASSO_FEDERATION(g_object_new(LASSO_TYPE_FEDERATION, NULL));
+ copy->remote_providerID = g_strdup(federation->remote_providerID);
+ copy->local_nameIdentifier = lasso_node_copy(federation->local_nameIdentifier);
+ copy->remote_nameIdentifier = lasso_node_copy(federation->remote_nameIdentifier);
+
+ return(copy);
+}
+
+void
+lasso_federation_destroy(LassoFederation *federation)
+{
+ g_object_unref(G_OBJECT(federation));
+}
+
+xmlChar *
+lasso_federation_dump(LassoFederation *federation)
+{
+ LassoNode *federation_node, *nameIdentifier;
+ LassoNode *local_nameIdentifier, *remote_nameIdentifier;
+ LassoNodeClass *federation_class, *class;
+ gchar *dump;
+
+ federation_node = lasso_node_new();
+ federation_class = LASSO_NODE_GET_CLASS(federation_node);
+ federation_class->set_name(federation_node, LASSO_FEDERATION_NODE);
+
+ /* set the remote providerID */
+ federation_class->set_prop(federation_node, LASSO_FEDERATION_REMOTE_PROVIDERID_NODE,
+ federation->remote_providerID);
+
+ /* add the remote name identifier */
+ if(federation->remote_nameIdentifier) {
+ nameIdentifier = lasso_node_new();
+ class = LASSO_NODE_GET_CLASS(nameIdentifier);
+ class->set_name(nameIdentifier, LASSO_FEDERATION_REMOTE_NAME_IDENTIFIER_NODE);
+ remote_nameIdentifier = lasso_node_copy(federation->remote_nameIdentifier);
+ class->add_child(nameIdentifier, remote_nameIdentifier, FALSE);
+ lasso_node_destroy(remote_nameIdentifier);
+ federation_class->add_child(federation_node, nameIdentifier, FALSE);
+ lasso_node_destroy(nameIdentifier);
+ }
+
+ /* add the local name identifier */
+ if(federation->local_nameIdentifier) {
+ nameIdentifier = lasso_node_new();
+ class = LASSO_NODE_GET_CLASS(nameIdentifier);
+ class->set_name(nameIdentifier, LASSO_FEDERATION_LOCAL_NAME_IDENTIFIER_NODE);
+ local_nameIdentifier = lasso_node_copy(federation->local_nameIdentifier);
+ class->add_child(nameIdentifier, local_nameIdentifier, FALSE);
+ lasso_node_destroy(local_nameIdentifier);
+ federation_class->add_child(federation_node, nameIdentifier, FALSE);
+ lasso_node_destroy(nameIdentifier);
+ }
+
+ dump = lasso_node_export(federation_node);
+ lasso_node_destroy(federation_node);
+
+ return(dump);
+}
+
+LassoNode *
+lasso_federation_get_local_nameIdentifier(LassoFederation *federation)
+{
+ return(lasso_node_copy(federation->local_nameIdentifier));
+}
+
+LassoNode *
+lasso_federation_get_remote_nameIdentifier(LassoFederation *federation)
+{
+ return(lasso_node_copy(federation->remote_nameIdentifier));
+}
+
+void
+lasso_federation_remove_local_nameIdentifier(LassoFederation *federation)
+{
+ if(federation->local_nameIdentifier != NULL) {
+ lasso_node_destroy(federation->local_nameIdentifier);
+ }
+}
+
+void
+lasso_federation_remove_remote_nameIdentifier(LassoFederation *federation)
+{
+ if(federation->remote_nameIdentifier != NULL){
+ lasso_node_destroy(federation->remote_nameIdentifier);
+ }
+}
+
+void
+lasso_federation_set_local_nameIdentifier(LassoFederation *federation,
+ LassoNode *nameIdentifier)
+{
+ federation->local_nameIdentifier = lasso_node_copy(nameIdentifier);
+}
+
+void
+lasso_federation_set_remote_nameIdentifier(LassoFederation *federation,
+ LassoNode *nameIdentifier)
+{
+ federation->remote_nameIdentifier = lasso_node_copy(nameIdentifier);
+}
+
+gboolean
+lasso_federation_verify_nameIdentifier(LassoFederation *federation,
+ LassoNode *nameIdentifier)
+{
+ gchar *federation_content, *nameIdentifier_content;
+
+ nameIdentifier_content = lasso_node_get_content(nameIdentifier);
+ if(federation->local_nameIdentifier != NULL) {
+ federation_content = lasso_node_get_content(federation->local_nameIdentifier);
+ if(xmlStrEqual(federation_content, nameIdentifier_content)) {
+ xmlFree(federation_content);
+ return(TRUE);
+ }
+ xmlFree(federation_content);
+ }
+ if(federation->remote_nameIdentifier != NULL) {
+ federation_content = lasso_node_get_content(federation->remote_nameIdentifier);
+ if(xmlStrEqual(federation_content, nameIdentifier_content)) {
+ xmlFree(federation_content);
+ return(TRUE);
+ }
+ xmlFree(federation_content);
+ }
+ xmlFree(nameIdentifier_content);
+
+ return(FALSE);
+}
+
+/*****************************************************************************/
+/* overrided parent class methods */
+/*****************************************************************************/
+
+static void
+lasso_federation_dispose(LassoFederation *federation)
+{
+ if (federation->private->dispose_has_run) {
+ return;
+ }
+ federation->private->dispose_has_run = TRUE;
+
+ debug("Federation object 0x%x disposed ...\n", federation);
+
+ /* unref reference counted objects */
+ lasso_node_destroy(federation->local_nameIdentifier);
+ lasso_node_destroy(federation->remote_nameIdentifier);
+
+ parent_class->dispose(G_OBJECT(federation));
+}
+
+static void
+lasso_federation_finalize(LassoFederation *federation)
+{
+ debug("Federation object 0x%x finalized ...\n", federation);
+
+ g_free(federation->remote_providerID);
+ g_free(federation->private);
+
+ parent_class->finalize(G_OBJECT(federation));
+}
+
+/*****************************************************************************/
+/* instance and class init functions */
+/*****************************************************************************/
+
+static void
+lasso_federation_instance_init(LassoFederation *federation)
+{
+ federation->private = g_new (LassoFederationPrivate, 1);
+ federation->private->dispose_has_run = FALSE;
+
+ federation->remote_providerID = NULL;
+ federation->local_nameIdentifier = NULL;
+ federation->remote_nameIdentifier = NULL;
+}
+
+static void
+lasso_federation_class_init(LassoFederationClass *g_class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
+
+ parent_class = g_type_class_peek_parent(g_class);
+ /* override parent class methods */
+ gobject_class->dispose = (void *)lasso_federation_dispose;
+ gobject_class->finalize = (void *)lasso_federation_finalize;
+}
+
+GType lasso_federation_get_type() {
+ static GType this_type = 0;
+
+ if (!this_type) {
+ static const GTypeInfo this_info = {
+ sizeof (LassoFederationClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) lasso_federation_class_init,
+ NULL,
+ NULL,
+ sizeof(LassoFederation),
+ 0,
+ (GInstanceInitFunc) lasso_federation_instance_init,
+ };
+
+ this_type = g_type_register_static(G_TYPE_OBJECT,
+ "LassoFederation",
+ &this_info, 0);
+ }
+ return this_type;
+}
+
+LassoFederation*
+lasso_federation_new(gchar *remote_providerID)
+{
+ LassoFederation *federation;
+
+ g_return_val_if_fail(remote_providerID != NULL, NULL);
+
+ federation = LASSO_FEDERATION(g_object_new(LASSO_TYPE_FEDERATION, NULL));
+
+ federation->remote_providerID = g_strdup(remote_providerID);
+
+ return(federation);
+}
+
+LassoFederation*
+lasso_federation_new_from_dump(xmlChar *dump)
+{
+ LassoFederation *federation;
+
+ g_return_val_if_fail(dump != NULL, NULL);
+
+ federation = LASSO_FEDERATION(g_object_new(LASSO_TYPE_FEDERATION, NULL));
+
+ return(federation);
+}
diff --git a/lasso/Attic/protocols/federation.h b/lasso/Attic/protocols/federation.h
new file mode 100644
index 00000000..201f6644
--- /dev/null
+++ b/lasso/Attic/protocols/federation.h
@@ -0,0 +1,101 @@
+/* $Id$
+ *
+ * Lasso - A free implementation of the Liberty Alliance specifications.
+ *
+ * Copyright (C) 2004 Entr'ouvert
+ * http://lasso.entrouvert.org
+ *
+ * Authors: Nicolas Clapies <nclapies@entrouvert.com>
+ * Valery Febvre <vfebvre@easter-eggs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __LASSO_FEDERATION_H__
+#define __LASSO_FEDERATION_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <lasso/xml/xml.h>
+#include <lasso/xml/saml_name_identifier.h>
+
+#define LASSO_TYPE_FEDERATION (lasso_federation_get_type())
+#define LASSO_FEDERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), LASSO_TYPE_FEDERATION, LassoFederation))
+#define LASSO_FEDERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), LASSO_TYPE_FEDERATION, LassoFederationClass))
+#define LASSO_IS_FEDERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), LASSO_TYPE_FEDERATION))
+#define LASSO_IS_FEDERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LASSO_TYPE_FEDERATION))
+#define LASSO_FEDERATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), LASSO_TYPE_FEDERATION, LassoFederationClass))
+
+#define LASSO_FEDERATION_NODE "LassoFederation"
+#define LASSO_FEDERATION_REMOTE_PROVIDERID_NODE "RemoteProviderID"
+#define LASSO_FEDERATION_LOCAL_NAME_IDENTIFIER_NODE "LassoLocalNameIdentifier"
+#define LASSO_FEDERATION_REMOTE_NAME_IDENTIFIER_NODE "LassoRemoteNameIdentifier"
+
+typedef struct _LassoFederation LassoFederation;
+typedef struct _LassoFederationClass LassoFederationClass;
+typedef struct _LassoFederationPrivate LassoFederationPrivate;
+
+struct _LassoFederation {
+ GObject parent;
+
+ gchar *remote_providerID;
+
+ LassoNode *local_nameIdentifier;
+ LassoNode *remote_nameIdentifier;
+
+ /*< private >*/
+ LassoFederationPrivate *private;
+};
+
+struct _LassoFederationClass {
+ GObjectClass parent;
+};
+
+LASSO_EXPORT GType lasso_federation_get_type (void);
+
+LASSO_EXPORT LassoFederation* lasso_federation_new (gchar *remote_providerID);
+
+LASSO_EXPORT LassoFederation* lasso_federation_new_from_dump (xmlChar *dump);
+
+LASSO_EXPORT LassoFederation* lasso_federation_copy (LassoFederation *federation);
+
+LASSO_EXPORT void lasso_federation_destroy (LassoFederation *federation);
+
+LASSO_EXPORT xmlChar* lasso_federation_dump (LassoFederation *federation);
+
+LASSO_EXPORT LassoNode* lasso_federation_get_remote_nameIdentifier (LassoFederation *federation);
+
+LASSO_EXPORT LassoNode* lasso_federation_get_local_nameIdentifier (LassoFederation *federation);
+
+LASSO_EXPORT void lasso_federation_remove_local_nameIdentifier (LassoFederation *federation);
+
+LASSO_EXPORT void lasso_federation_remove_remote_nameIdentifier (LassoFederation *federation);
+
+LASSO_EXPORT void lasso_federation_set_local_nameIdentifier (LassoFederation *federation,
+ LassoNode *nameIdentifier);
+
+LASSO_EXPORT void lasso_federation_set_remote_nameIdentifier (LassoFederation *federation,
+ LassoNode *nameIdentifier);
+
+LASSO_EXPORT gboolean lasso_federation_verify_nameIdentifier (LassoFederation *federation,
+ LassoNode *nameIdentifier);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __LASSO_FEDERATION_H__ */
diff --git a/lasso/id-ff/Makefile.am b/lasso/id-ff/Makefile.am
index 700a6842..f8ddf94e 100644
--- a/lasso/id-ff/Makefile.am
+++ b/lasso/id-ff/Makefile.am
@@ -13,6 +13,7 @@ noinst_LTLIBRARIES = liblasso-environs.la
liblasso_environs_la_SOURCES = \
federation_termination.c \
+ identity.c \
lecp.c \
login.c \
logout.c \
@@ -20,11 +21,11 @@ liblasso_environs_la_SOURCES = \
profile_context.c \
register_name_identifier.c \
server.c \
- session.c \
- user.c
+ session.c
liblassoinclude_HEADERS = \
federation_termination.h \
+ identity.h \
lecp.h \
login.h \
logout.h \
@@ -32,5 +33,4 @@ liblassoinclude_HEADERS = \
profile_context.h \
register_name_identifier.h \
server.h \
- session.h \
- user.h
+ session.h
diff --git a/lasso/id-ff/identity.c b/lasso/id-ff/identity.c
new file mode 100644
index 00000000..ed4af134
--- /dev/null
+++ b/lasso/id-ff/identity.c
@@ -0,0 +1,424 @@
+/* $Id$
+ *
+ * Lasso - A free implementation of the Liberty Alliance specifications.
+ *
+ * Copyright (C) 2004 Entr'ouvert
+ * http://lasso.entrouvert.org
+ *
+ * Authors: Nicolas Clapies <nclapies@entrouvert.com>
+ * Valery Febvre <vfebvre@easter-eggs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <lasso/environs/identity.h>
+
+#define LASSO_IDENTITY_NODE "LassoIdentity"
+#define LASSO_IDENTITY_FEDERATIONS_NODE "LassoFederations"
+#define LASSO_IDENTITY_FEDERATION_NODE "LassoFederation"
+#define LASSO_IDENTITY_REMOTE_PROVIDERID_ATTR "RemoteProviderID"
+
+struct _LassoIdentityPrivate
+{
+ gboolean dispose_has_run;
+};
+
+static GObjectClass *parent_class = NULL;
+
+/*****************************************************************************/
+/* private functions */
+/*****************************************************************************/
+
+static void
+lasso_identity_copy_federation(gpointer key,
+ gpointer value,
+ gpointer federations)
+{
+ g_hash_table_insert((GHashTable *)federations, g_strdup((gchar *)key),
+ lasso_federation_copy(LASSO_FEDERATION(value)));
+}
+
+static void
+lasso_identity_dump_federation(gpointer key,
+ gpointer value,
+ LassoNode *federations)
+{
+ LassoNode *federation_node;
+ LassoNodeClass *federation_class;
+ xmlChar *dump;
+
+ dump = lasso_federation_dump(LASSO_FEDERATION(value));
+ federation_node = lasso_node_new_from_dump(dump);
+ xmlFree(dump);
+ federation_class = LASSO_NODE_GET_CLASS(federation_node);
+ federation_class->add_child(federations, federation_node, TRUE);
+ lasso_node_destroy(federation_node);
+}
+
+/*****************************************************************************/
+/* public methods */
+/*****************************************************************************/
+
+gint
+lasso_identity_add_federation(LassoIdentity *identity,
+ gchar *remote_providerID,
+ LassoFederation *federation)
+{
+ LassoFederation *old_federation;
+ gboolean found;
+ int i;
+
+ g_return_val_if_fail(identity != NULL, -1);
+ g_return_val_if_fail(remote_providerID != NULL, -2);
+ g_return_val_if_fail(federation != NULL, -3);
+
+ /* add the remote provider id if not already saved */
+ found = FALSE;
+ for(i = 0; i<identity->providerIDs->len; i++){
+ if(xmlStrEqual(remote_providerID, g_ptr_array_index(identity->providerIDs, i)))
+ found = TRUE;
+ }
+ if(found == FALSE){
+ g_ptr_array_add(identity->providerIDs, g_strdup(remote_providerID));
+ }
+
+ /* add the federation, replace if one already exists */
+ old_federation = lasso_identity_get_federation(identity, remote_providerID);
+ if (old_federation != NULL) {
+ lasso_identity_remove_federation(identity, remote_providerID);
+ /* BEWARE: Don't destroy old_federation here.
+ It's not a copy. But it must change */
+ }
+ g_hash_table_insert(identity->federations, g_strdup(remote_providerID), federation);
+
+ return(0);
+}
+
+LassoIdentity*
+lasso_identity_copy(LassoIdentity *identity)
+{
+ LassoIdentity *copy;
+ guint i;
+
+ if (identity == NULL) {
+ return(NULL);
+ }
+
+ copy = LASSO_IDENTITY(g_object_new(LASSO_TYPE_IDENTITY, NULL));
+
+ copy->providerIDs = g_ptr_array_new();
+ for(i=0; i<identity->providerIDs->len; i++) {
+ g_ptr_array_add(copy->providerIDs,
+ g_strdup(g_ptr_array_index(identity->providerIDs, i)));
+ }
+ copy->federations = g_hash_table_new_full(g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)lasso_node_destroy);
+ g_hash_table_foreach(copy->federations, (GHFunc)lasso_identity_copy_federation,
+ (gpointer)copy->federations);
+
+ return(copy);
+}
+
+void
+lasso_identity_destroy(LassoIdentity *identity)
+{
+ if (LASSO_IS_IDENTITY(identity)) {
+ g_object_unref(G_OBJECT(identity));
+ }
+}
+
+gchar*
+lasso_identity_dump(LassoIdentity *identity)
+{
+ LassoNode *identity_node, *federations_node;
+ int table_size;
+ xmlChar *dump;
+
+ g_return_val_if_fail(identity != NULL, NULL);
+
+ identity_node = lasso_node_new();
+ LASSO_NODE_GET_CLASS(identity_node)->set_name(identity_node, LASSO_IDENTITY_NODE);
+
+ /* dump the federations */
+ table_size = g_hash_table_size(identity->federations);
+ if (table_size > 0) {
+ federations_node = lasso_node_new();
+ LASSO_NODE_GET_CLASS(federations_node)->set_name(federations_node,
+ LASSO_IDENTITY_FEDERATIONS_NODE);
+ g_hash_table_foreach(identity->federations, (GHFunc)lasso_identity_dump_federation,
+ federations_node);
+ LASSO_NODE_GET_CLASS(identity_node)->add_child(identity_node, federations_node, FALSE);
+ lasso_node_destroy(federations_node);
+ }
+
+ dump = lasso_node_export(identity_node);
+
+ lasso_node_destroy(identity_node);
+
+ return(dump);
+}
+
+LassoFederation*
+lasso_identity_get_federation(LassoIdentity *identity,
+ gchar *remote_providerID)
+{
+ g_return_val_if_fail(identity!=NULL, NULL);
+ g_return_val_if_fail(remote_providerID!=NULL, NULL);
+
+ LassoFederation *federation;
+
+ federation = (LassoFederation *)g_hash_table_lookup(identity->federations,
+ remote_providerID);
+ if (federation == NULL) {
+ debug("No Federation found with remote ProviderID = %s\n", remote_providerID);
+ }
+
+ /* FIXME: federation should be a copy (fix lasso_identity_add_federation too) */
+ return(federation);
+}
+
+gchar*
+lasso_identity_get_next_federation_remote_providerID(LassoIdentity *identity)
+{
+ gchar *remote_providerID;
+
+ g_return_val_if_fail(identity!=NULL, NULL);
+
+ if(identity->providerIDs->len == 0) {
+ return(NULL);
+ }
+
+ remote_providerID = g_strdup(g_ptr_array_index(identity->providerIDs, 0));
+
+ return(remote_providerID);
+}
+
+gint
+lasso_identity_remove_federation(LassoIdentity *identity,
+ gchar *remote_providerID)
+{
+ LassoFederation *federation;
+ int i;
+
+ g_return_val_if_fail(identity != NULL, -1);
+ g_return_val_if_fail(remote_providerID != NULL, -2);
+
+ /* remove the federation */
+ federation = lasso_identity_get_federation(identity, remote_providerID);
+ if (federation != NULL) {
+ g_hash_table_remove(identity->federations, remote_providerID);
+ }
+ else {
+ debug("Failed to remove federation for remote Provider %s\n", remote_providerID);
+ }
+
+ /* remove the federation remote provider id */
+ for(i = 0; i<identity->providerIDs->len; i++){
+ if(xmlStrEqual(remote_providerID, g_ptr_array_index(identity->providerIDs, i))) {
+ debug("Remove federation of %s\n", remote_providerID);
+ g_ptr_array_remove_index(identity->providerIDs, i);
+ break;
+ }
+ }
+
+ return(0);
+}
+
+/*****************************************************************************/
+/* overrided parent class methods */
+/*****************************************************************************/
+
+static void
+lasso_identity_dispose(LassoIdentity *identity)
+{
+ if (identity->private->dispose_has_run == TRUE) {
+ return;
+ }
+ identity->private->dispose_has_run = TRUE;
+
+ debug("Identity object 0x%x disposed ...\n", identity);
+
+ g_hash_table_destroy(identity->federations);
+ identity->federations = NULL;
+
+ parent_class->dispose(G_OBJECT(identity));
+}
+
+static void
+lasso_identity_finalize(LassoIdentity *identity)
+{
+ gint i;
+
+ debug("Identity object 0x%x finalized ...\n", identity);
+
+ /* free allocated memory for providerIDs array */
+ for (i=0; i<identity->providerIDs->len; i++) {
+ g_free(identity->providerIDs->pdata[i]);
+ identity->providerIDs->pdata[i] = NULL;
+ }
+ g_ptr_array_free(identity->providerIDs, TRUE);
+ identity->providerIDs = NULL;
+
+ g_free(identity->private);
+ identity->private = NULL;
+
+ parent_class->finalize(G_OBJECT(identity));
+}
+
+/*****************************************************************************/
+/* instance and class init functions */
+/*****************************************************************************/
+
+static void
+lasso_identity_instance_init(LassoIdentity *identity)
+{
+ identity->private = g_new (LassoIdentityPrivate, 1);
+ identity->private->dispose_has_run = FALSE;
+
+ identity->providerIDs = g_ptr_array_new();
+ identity->federations = g_hash_table_new_full(g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)lasso_federation_destroy);
+}
+
+static void
+lasso_identity_class_init(LassoIdentityClass *class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(class);
+
+ parent_class = g_type_class_peek_parent(class);
+ /* override parent class methods */
+ gobject_class->dispose = (void *)lasso_identity_dispose;
+ gobject_class->finalize = (void *)lasso_identity_finalize;
+}
+
+GType lasso_identity_get_type() {
+ static GType this_type = 0;
+
+ if (!this_type) {
+ static const GTypeInfo this_info = {
+ sizeof (LassoIdentityClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) lasso_identity_class_init,
+ NULL,
+ NULL,
+ sizeof(LassoIdentity),
+ 0,
+ (GInstanceInitFunc) lasso_identity_instance_init,
+ };
+
+ this_type = g_type_register_static(G_TYPE_OBJECT,
+ "LassoIdentity",
+ &this_info, 0);
+ }
+ return this_type;
+}
+
+LassoIdentity*
+lasso_identity_new()
+{
+ LassoIdentity *identity;
+
+ identity = LASSO_IDENTITY(g_object_new(LASSO_TYPE_IDENTITY, NULL));
+
+ return(identity);
+}
+
+LassoIdentity*
+lasso_identity_new_from_dump(gchar *dump)
+{
+ LassoNode *identity_node;
+ LassoNode *federations_node, *federation_node;
+ LassoNode *nameIdentifier_node, *local_nameIdentifier_node, *remote_nameIdentifier_node;
+
+ LassoNodeClass *federations_class;
+
+ xmlNodePtr federations_xmlNode, federation_xmlNode;
+
+ LassoIdentity *identity;
+
+ LassoFederation *federation;
+
+ xmlChar *remote_providerID;
+
+ g_return_val_if_fail(dump != NULL, NULL);
+
+ /* new object */
+ identity = LASSO_IDENTITY(g_object_new(LASSO_TYPE_IDENTITY, NULL));
+
+ /* get identity */
+ identity_node = lasso_node_new_from_dump(dump);
+ if (identity_node == NULL) {
+ message(G_LOG_LEVEL_WARNING, "Can't create a identity from dump\n");
+ return (NULL);
+ }
+
+ /* federations */
+ federations_node = lasso_node_get_child(identity_node,
+ LASSO_IDENTITY_FEDERATIONS_NODE, NULL);
+ if (federations_node != NULL) {
+ federations_class = LASSO_NODE_GET_CLASS(federations_node);
+ federations_xmlNode = federations_class->get_xmlNode(federations_node);
+ federation_xmlNode = federations_xmlNode->children;
+
+ while (federation_xmlNode != NULL) {
+ if (federation_xmlNode->type==XML_ELEMENT_NODE && \
+ xmlStrEqual(federation_xmlNode->name, LASSO_IDENTITY_FEDERATION_NODE)) {
+ federation_node = lasso_node_new_from_xmlNode(federation_xmlNode);
+ remote_providerID = lasso_node_get_attr_value(federation_node,
+ LASSO_FEDERATION_REMOTE_PROVIDERID_NODE, NULL);
+ /* new federation */
+ federation = lasso_federation_new(remote_providerID);
+
+ /* local name identifier */
+ local_nameIdentifier_node = lasso_node_get_child(federation_node,
+ LASSO_FEDERATION_LOCAL_NAME_IDENTIFIER_NODE, NULL);
+ if (local_nameIdentifier_node != NULL) {
+ nameIdentifier_node = lasso_node_get_child(local_nameIdentifier_node, "NameIdentifier", NULL);
+ lasso_federation_set_local_nameIdentifier(federation, nameIdentifier_node);
+ debug(" ... add local name identifier %s\n", lasso_node_get_content(nameIdentifier_node));
+ lasso_node_destroy(nameIdentifier_node);
+ lasso_node_destroy(local_nameIdentifier_node);
+ }
+
+ /* remote name identifier */
+ remote_nameIdentifier_node = lasso_node_get_child(federation_node,
+ LASSO_FEDERATION_REMOTE_NAME_IDENTIFIER_NODE, NULL);
+ if (remote_nameIdentifier_node != NULL) {
+ nameIdentifier_node = lasso_node_get_child(remote_nameIdentifier_node, "NameIdentifier", NULL);
+ lasso_federation_set_remote_nameIdentifier(federation, nameIdentifier_node);
+ debug(" ... add remote name identifier %s\n", lasso_node_get_content(nameIdentifier_node));
+ lasso_node_destroy(nameIdentifier_node);
+ lasso_node_destroy(remote_nameIdentifier_node);
+ }
+ debug("Add federation for %s\n", remote_providerID);
+ lasso_identity_add_federation(identity, remote_providerID, federation);
+
+ xmlFree(remote_providerID);
+ lasso_node_destroy(federation_node);
+ }
+
+ federation_xmlNode = federation_xmlNode->next;
+ }
+
+ lasso_node_destroy(federations_node);
+ }
+
+ lasso_node_destroy(identity_node);
+
+ return (identity);
+}
diff --git a/lasso/id-ff/identity.h b/lasso/id-ff/identity.h
new file mode 100644
index 00000000..2f85cca5
--- /dev/null
+++ b/lasso/id-ff/identity.h
@@ -0,0 +1,90 @@
+/* $Id$
+ *
+ * Lasso - A free implementation of the Liberty Alliance specifications.
+ *
+ * Copyright (C) 2004 Entr'ouvert
+ * http://lasso.entrouvert.org
+ *
+ * Authors: Nicolas Clapies <nclapies@entrouvert.com>
+ * Valery Febvre <vfebvre@easter-eggs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __LASSO_IDENTITY_H__
+#define __LASSO_IDENTITY_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <lasso/xml/xml.h>
+#include <lasso/protocols/federation.h>
+
+#define LASSO_TYPE_IDENTITY (lasso_identity_get_type())
+#define LASSO_IDENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), LASSO_TYPE_IDENTITY, LassoIdentity))
+#define LASSO_IDENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), LASSO_TYPE_IDENTITY, LassoIdentityClass))
+#define LASSO_IS_IDENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), LASSO_TYPE_IDENTITY))
+#define LASSO_IS_IDENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LASSO_TYPE_IDENTITY))
+#define LASSO_IDENTITY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), LASSO_TYPE_IDENTITY, LassoIdentityClass))
+
+typedef struct _LassoIdentity LassoIdentity;
+typedef struct _LassoIdentityClass LassoIdentityClass;
+typedef struct _LassoIdentityPrivate LassoIdentityPrivate;
+
+struct _LassoIdentity {
+ GObject parent;
+
+ /*< public >*/
+ GPtrArray *providerIDs; /* list of the remote provider ids for federations hash table */
+ GHashTable *federations; /* hash for federations with remote ProviderID as key */
+
+ /*< private >*/
+ LassoIdentityPrivate *private;
+};
+
+struct _LassoIdentityClass {
+ GObjectClass parent;
+};
+
+LASSO_EXPORT GType lasso_identity_get_type (void);
+
+LASSO_EXPORT LassoIdentity* lasso_identity_new (void);
+
+LASSO_EXPORT LassoIdentity* lasso_identity_new_from_dump (gchar *dump);
+
+LASSO_EXPORT gint lasso_identity_add_federation (LassoIdentity *identity,
+ gchar *remote_providerID,
+ LassoFederation *federation);
+
+LASSO_EXPORT LassoIdentity* lasso_identity_copy (LassoIdentity *identity);
+
+LASSO_EXPORT void lasso_identity_destroy (LassoIdentity *identity);
+
+LASSO_EXPORT gchar* lasso_identity_dump (LassoIdentity *identity);
+
+LASSO_EXPORT LassoFederation* lasso_identity_get_federation (LassoIdentity *identity,
+ gchar *remote_providerID);
+
+LASSO_EXPORT gchar* lasso_identity_get_next_federation_remote_providerID (LassoIdentity *identity);
+
+LASSO_EXPORT gint lasso_identity_remove_federation (LassoIdentity *identity,
+ gchar *remote_providerID);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __LASSO_IDENTITY_H__ */