diff options
| author | Nicolas Clapies <nclapies@entrouvert.com> | 2004-07-09 15:49:37 +0000 |
|---|---|---|
| committer | Nicolas Clapies <nclapies@entrouvert.com> | 2004-07-09 15:49:37 +0000 |
| commit | 32b13e03dce0109b3445fda6b8d895a053353b6b (patch) | |
| tree | 0bd251e5af80047cd6f38210aab9d0f666600b52 | |
| parent | 02280779752e70cb21e59f0b1606b0653c2b036b (diff) | |
| download | lasso-32b13e03dce0109b3445fda6b8d895a053353b6b.tar.gz lasso-32b13e03dce0109b3445fda6b8d895a053353b6b.tar.xz lasso-32b13e03dce0109b3445fda6b8d895a053353b6b.zip | |
update of user dump methods
| -rw-r--r-- | lasso/Attic/protocols/identity.c | 48 | ||||
| -rw-r--r-- | lasso/Attic/protocols/identity.h | 8 | ||||
| -rw-r--r-- | lasso/id-ff/user.c | 142 | ||||
| -rw-r--r-- | lasso/id-ff/user.h | 27 |
4 files changed, 167 insertions, 58 deletions
diff --git a/lasso/Attic/protocols/identity.c b/lasso/Attic/protocols/identity.c index dce69443..d0ce3ded 100644 --- a/lasso/Attic/protocols/identity.c +++ b/lasso/Attic/protocols/identity.c @@ -36,16 +36,16 @@ lasso_identity_dump(LassoIdentity *identity) identity_node = lasso_node_new(); identity_class = LASSO_NODE_GET_CLASS(identity_node); - identity_class->set_name(identity_node, "Identity"); + identity_class->set_name(identity_node, LASSO_IDENTITY_NODE); /* set the remote providerID */ - identity_class->set_prop(identity_node, "RemoteProviderID", identity->remote_providerID); + identity_class->set_prop(identity_node, LASSO_IDENTITY_REMOTE_PROVIDERID_NODE, identity->remote_providerID); /* add the remote name identifier */ if(identity->remote_nameIdentifier){ nameIdentifier = lasso_node_new(); class = LASSO_NODE_GET_CLASS(nameIdentifier); - class->set_name(nameIdentifier, "RemoteNameIdentifier"); + class->set_name(nameIdentifier, LASSO_IDENTITY_REMOTE_NAME_IDENTIFIER_NODE); class->add_child(nameIdentifier, identity->remote_nameIdentifier, FALSE); identity_class->add_child(identity_node, nameIdentifier, FALSE); } @@ -54,7 +54,7 @@ lasso_identity_dump(LassoIdentity *identity) if(identity->local_nameIdentifier){ nameIdentifier = lasso_node_new(); class = LASSO_NODE_GET_CLASS(nameIdentifier); - class->set_name(nameIdentifier, "LocalNameIdentifier"); + class->set_name(nameIdentifier, LASSO_IDENTITY_LOCAL_NAME_IDENTIFIER_NODE); class->add_child(nameIdentifier, identity->local_nameIdentifier, FALSE); identity_class->add_child(identity_node, nameIdentifier, FALSE); } @@ -62,6 +62,18 @@ lasso_identity_dump(LassoIdentity *identity) return(lasso_node_export(identity_node)); } +LassoNode * +lasso_identity_get_local_nameIdentifier(LassoIdentity *identity) +{ + return(identity->local_nameIdentifier); +} + +LassoNode * +lasso_identity_get_remote_nameIdentifier(LassoIdentity *identity) +{ + return(identity->remote_nameIdentifier); +} + void lasso_identity_set_local_nameIdentifier(LassoIdentity *identity, LassoNode *nameIdentifier) @@ -76,18 +88,28 @@ lasso_identity_set_remote_nameIdentifier(LassoIdentity *identity, identity->remote_nameIdentifier = nameIdentifier; } -LassoNode * -lasso_identity_get_local_nameIdentifier(LassoIdentity *identity) +gboolean +lasso_identity_verify_nameIdentifier(LassoIdentity *identity, + LassoNode *nameIdentifier) { - return(identity->local_nameIdentifier); -} + gchar *identity_content, *nameIdentifier_content; -LassoNode * -lasso_identity_get_remote_nameIdentifier(LassoIdentity *identity) -{ - return(identity->remote_nameIdentifier); -} + nameIdentifier_content = lasso_node_get_content(nameIdentifier); + if(identity->local_nameIdentifier){ + identity_content = lasso_node_get_content(identity->local_nameIdentifier); + if(xmlStrEqual(identity_content, nameIdentifier_content)){ + return(TRUE); + } + } + if(identity->remote_nameIdentifier){ + identity_content = lasso_node_get_content(identity->remote_nameIdentifier); + if(xmlStrEqual(identity_content, nameIdentifier_content)){ + return(TRUE); + } + } + return(FALSE); +} /*****************************************************************************/ /* instance and class init functions */ diff --git a/lasso/Attic/protocols/identity.h b/lasso/Attic/protocols/identity.h index 9f5eb7cd..7c0f65cc 100644 --- a/lasso/Attic/protocols/identity.h +++ b/lasso/Attic/protocols/identity.h @@ -40,6 +40,11 @@ extern "C" { #define LASSP_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)) +#define LASSO_IDENTITY_NODE "LassoIdentity" +#define LASSO_IDENTITY_REMOTE_PROVIDERID_NODE "LassoRemoteProviderID" +#define LASSO_IDENTITY_LOCAL_NAME_IDENTIFIER_NODE "LassoLocalNameIdentifier" +#define LASSO_IDENTITY_REMOTE_NAME_IDENTIFIER_NODE "LassoRemoteNameIdentifier" + typedef struct _LassoIdentity LassoIdentity; typedef struct _LassoIdentityClass LassoIdentityClass; @@ -71,6 +76,9 @@ LASSO_EXPORT void lasso_identity_set_local_nameIdentifier (LassoIdent LASSO_EXPORT void lasso_identity_set_remote_nameIdentifier (LassoIdentity *identity, LassoNode *nameIdentifier); +LASSO_EXPORT gboolean lasso_identity_verify_nameIdentifier (LassoIdentity *identity, + LassoNode *nameIdentifier); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lasso/id-ff/user.c b/lasso/id-ff/user.c index dc393270..af3f5afd 100644 --- a/lasso/id-ff/user.c +++ b/lasso/id-ff/user.c @@ -28,6 +28,37 @@ /* public methods */ /*****************************************************************************/ +void +lasso_user_add_assertion(LassoUser *user, + gchar *remote_providerID, + LassoNode *assertion) +{ + gchar *providerId; + int i; + gboolean found; + + /* add the remote provider id */ + found = FALSE; + for(i = 0; i<user->assertion_providerIDs->len; i++){ + if(xmlStrEqual(remote_providerID, g_ptr_array_index(user->assertion_providerIDs, i))) + found = TRUE; + } + if(found==FALSE){ + g_ptr_array_add(user->assertion_providerIDs, g_strdup(remote_providerID)); + } + + /* add the assertion */ + g_hash_table_insert(user->assertions, g_strdup(remote_providerID), assertion); +} + +void +lasso_user_add_identity(LassoUser *user, + gchar *remote_providerID, + LassoIdentity *identity) +{ + g_hash_table_insert(user->identities, g_strdup(remote_providerID), identity); +} + static void lasso_user_dump_assertion(gpointer key, gpointer value, @@ -66,7 +97,7 @@ lasso_user_dump_identity(gpointer key, identity_class->add_child(identities, identity_node, TRUE); } -xmlChar * +gchar* lasso_user_dump(LassoUser *user) { LassoNode *user_node, *assertions_node, *identities_node; @@ -93,37 +124,46 @@ lasso_user_dump(LassoUser *user) return(lasso_node_export(user_node)); } -void -lasso_user_add_assertion(LassoUser *user, - xmlChar *remote_providerID, - LassoNode *assertion) -{ - g_hash_table_insert(user->assertions, g_strdup(remote_providerID), assertion); -} - -LassoNode * +LassoNode* lasso_user_get_assertion(LassoUser *user, - xmlChar *remote_providerID) + gchar *remote_providerID) { return(g_hash_table_lookup(user->assertions, remote_providerID)); } - -void -lasso_user_add_identity(LassoUser *user, - xmlChar *remote_providerID, - LassoIdentity *identity) +gchar* +lasso_user_get_next_providerID(LassoUser *user) { - g_hash_table_insert(user->identities, g_strdup(remote_providerID), identity); + return(g_ptr_array_index(user->assertion_providerIDs, 0)); } LassoIdentity* lasso_user_get_identity(LassoUser *user, - xmlChar *remote_providerID) + gchar *remote_providerID) { return(g_hash_table_lookup(user->identities, remote_providerID)); } +void +lasso_user_remove_assertion(LassoUser *user, + gchar *remote_providerID) +{ + LassoNode *assertion; + int i; + + /* remove the assertion */ + assertion = lasso_user_get_assertion(user->assertions, remote_providerID); + g_hash_table_steal(user->assertions, remote_providerID); + + /* remove the remote provider id */ + for(i = 0; i<user->assertion_providerIDs->len; i++){ + if(xmlStrEqual(remote_providerID, g_ptr_array_index(user->assertion_providerIDs, i))){ + g_ptr_array_remove_index(user->assertion_providerIDs, i); + break; + } + } +} + /*****************************************************************************/ /* instance and class init functions */ @@ -132,6 +172,7 @@ lasso_user_get_identity(LassoUser *user, static void lasso_user_instance_init(LassoUser *user) { + user->assertion_providerIDs = g_ptr_array_new(); user->identities = g_hash_table_new(g_str_hash, g_str_equal); user->assertions = g_hash_table_new(g_str_hash, g_str_equal); } @@ -176,12 +217,12 @@ lasso_user_new() } LassoUser* -lasso_user_new_from_dump(xmlChar *dump) +lasso_user_new_from_dump(gchar *dump) { - LassoNode *user_node, *identities_node, *assertions_node, *assertion_node; + LassoNode *user_node, *identities_node, *assertions_node, *assertion_node, *local_nameIdentifier, *remote_nameIdentifier; LassoNodeClass *identities_class, *assertions_class; LassoIdentity *identity; - xmlNodePtr xmlNode, assertion_xmlNode; + xmlNodePtr identities_xmlNode, identity_xmlNode, assertions_xmlNode, assertion_xmlNode, nameIdentifier_xmlNode; LassoUser *user; xmlChar *remote_providerID; @@ -189,16 +230,20 @@ lasso_user_new_from_dump(xmlChar *dump) user = LASSO_USER(g_object_new(LASSO_TYPE_USER, NULL)); /* get user */ + debug(DEBUG, "LassoUser node\n"); user_node = lasso_node_new_from_dump(dump); - /* get lasso assertion */ + /* get assertions */ assertions_node = lasso_node_get_child(user_node, LASSO_USER_ASSERTIONS_NODE, NULL); if(assertions_node){ - assertions_class = LASSO_NODE_GET_CLASS(identities_node); - xmlNode = assertions_class->get_xmlNode(assertions_node); - assertion_xmlNode = xmlNode->children; + debug(DEBUG, "LassoAssertions node found\n"); + assertions_class = LASSO_NODE_GET_CLASS(assertions_node); + assertions_xmlNode = assertions_class->get_xmlNode(assertions_node); + assertion_xmlNode = assertions_xmlNode->children; while(assertion_xmlNode){ + /* get only element node with name LassoAssertion */ if(assertion_xmlNode->type==XML_ELEMENT_NODE && xmlStrEqual(assertion_xmlNode->name, LASSO_USER_ASSERTION_NODE)){ + debug(DEBUG, "LassoAssertion found\n"); remote_providerID = xmlGetProp(assertion_xmlNode, LASSO_USER_REMOTE_PROVIDERID_NODE); assertion_node = lasso_node_new_from_xmlNode(assertion_xmlNode); lasso_user_add_assertion(user, remote_providerID, assertion_node); @@ -207,19 +252,46 @@ lasso_user_new_from_dump(xmlChar *dump) } } - /* get the lasso identities */ + /* set lasso identities */ identities_node = lasso_node_get_child(user_node, LASSO_USER_IDENTITIES_NODE, NULL); identities_class = LASSO_NODE_GET_CLASS(identities_node); - xmlNode = identities_class->get_xmlNode(identities_node); - if(xmlNode){ - xmlNode = xmlNode->children; - while(xmlNode){ - if(xmlNode->type==XML_ELEMENT_NODE && xmlStrEqual(xmlNode->name, LASSO_USER_IDENTITY_NODE)){ - identity = lasso_identity_new(xmlGetProp(xmlNode, LASSO_USER_REMOTE_PROVIDERID_NODE)); - lasso_identity_set_local_nameIdentifier(user, identity); - xmlNode = xmlNode->next; + identities_xmlNode = identities_class->get_xmlNode(identities_node); + if(identities_xmlNode){ + /* get the identities */ + debug(DEBUG, "LassoIdentities node found\n"); + identity_xmlNode = identities_xmlNode->children; + while(identity_xmlNode){ + if(identity_xmlNode->type==XML_ELEMENT_NODE && xmlStrEqual(identity_xmlNode->name, LASSO_USER_IDENTITY_NODE)){ + /* a new identity */ + debug(DEBUG, "LassoIdentity found\n"); + identity = lasso_identity_new(xmlGetProp(identity_xmlNode, LASSO_USER_REMOTE_PROVIDERID_NODE)); + nameIdentifier_xmlNode = identity_xmlNode->children; + while(nameIdentifier_xmlNode){ + if(nameIdentifier_xmlNode->type==XML_ELEMENT_NODE){ + if(xmlStrEqual(nameIdentifier_xmlNode->name, LASSO_IDENTITY_LOCAL_NAME_IDENTIFIER_NODE)){ + /* a new local name identifier */ + debug(DEBUG, "LassoLocalNameIdentifier found\n"); + local_nameIdentifier = lasso_node_new_from_xmlNode(nameIdentifier_xmlNode); + lasso_identity_set_local_nameIdentifier(identity, local_nameIdentifier); + } + else if(xmlStrEqual(nameIdentifier_xmlNode->name, LASSO_IDENTITY_REMOTE_NAME_IDENTIFIER_NODE)){ + /* a new remote name identifier */ + debug(DEBUG, "LassoRemoteNameIdentifier found\n"); + remote_nameIdentifier = lasso_node_new_from_xmlNode(nameIdentifier_xmlNode); + lasso_identity_set_local_nameIdentifier(identity, remote_nameIdentifier); + + } /* end if */ + + } /* end if */ + + nameIdentifier_xmlNode = nameIdentifier_xmlNode->next; + } /* end while */ + } - } + + identity_xmlNode = identity_xmlNode->next; + } /* end while */ + } return(user); diff --git a/lasso/id-ff/user.h b/lasso/id-ff/user.h index 0db5714f..14195ac4 100644 --- a/lasso/id-ff/user.h +++ b/lasso/id-ff/user.h @@ -54,8 +54,9 @@ struct _LassoUser { GObject parent; /*< public >*/ - GHashTable *assertions; /* hash for assertions with remote providerID as key */ - GHashTable *identities; /* hash for identities with remote ProviderID as key */ + GPtrArray *assertion_providerIDs; /* list of the remote provider ids for assertions hash table */ + GHashTable *assertions; /* hash for assertions with remote providerID as key */ + GHashTable *identities; /* hash for identities with remote ProviderID as key */ /*< private >*/ }; @@ -65,25 +66,31 @@ struct _LassoUserClass { }; LASSO_EXPORT GType lasso_user_get_type (void); + LASSO_EXPORT LassoUser *lasso_user_new (void); -LASSO_EXPORT LassoUser *lasso_user_new_from_dump (xmlChar *dump); -LASSO_EXPORT xmlChar *lasso_user_dump (LassoUser *user); +LASSO_EXPORT LassoUser *lasso_user_new_from_dump (gchar *dump); + +LASSO_EXPORT gchar *lasso_user_dump (LassoUser *user); LASSO_EXPORT void lasso_user_add_assertion (LassoUser *user, - xmlChar *remote_providerID, + gchar *remote_providerID, LassoNode *assertion); -LASSO_EXPORT LassoNode *lasso_user_get_assertion (LassoUser *user, - xmlChar *nameIdentifier); - LASSO_EXPORT void lasso_user_add_identity (LassoUser *user, - xmlChar *remote_providerID, + gchar *remote_providerID, LassoIdentity *identity); +LASSO_EXPORT LassoNode *lasso_user_get_assertion (LassoUser *user, + gchar *remote_providerID); + LASSO_EXPORT LassoIdentity *lasso_user_get_identity (LassoUser *user, - xmlChar *remote_providerID); + gchar *remote_providerID); + +LASSO_EXPORT gchar *lasso_user_get_next_providerID (LassoUser *user); +LASSO_EXPORT void lasso_user_remove_assertion (LassoUser *user, + gchar *remote_providerID); #ifdef __cplusplus } #endif /* __cplusplus */ |
